diff --git a/README.md b/README.md index eb2e667..8ded45d 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ * LEC-ALN/ASL * cExpress-TL , cExpress-EL, cExpress-AR * Express-ID7, Express-ADP, Express-TL, Express-RLP -* COM-HPC-cADP, COM-HPC-sIDH +* COM-HPC-cRLS, COM-HPC-sIDH * LEC-EL * nanoX-EL * Q7-EL @@ -17,8 +17,9 @@ ### Supported Operating System: * Ubuntu 18.04, 20.04, 22.04, 24.04 * Debian all versions -* CentOS (except that Voltage Monitoring and GPIO Support) -* Red Hat ((except that Voltage Monitoring and GPIO Support) +* CentOS +* SuSE Linux +* Red Hat 9.0/9.4 ### Developer's Guide (how to use EAPI and Sysfs): @@ -27,5 +28,5 @@ ### Other information: * branch name: SEMA_4.0_Linux_SandBox/ACPI-EC -* the internal latest commit ID: 7fdf2e158dc6013d85ded6e2d41d18e79ce5a7ed +* the internal latest commit ID: 554fd8e94c9ee76228ed7b1ede9176076dd5d986 diff --git a/app/main.c b/app/main.c index 2315305..e05ac30 100644 --- a/app/main.c +++ b/app/main.c @@ -26,11 +26,11 @@ #include #include -#define Version "ADLINK-SEMA-EC-LINUX-V4_R3_4_24_08_27" +#define Version "ADLINK-SEMA-EC-LINUX-V4_R3_5_24_12_10" char* ExeName; uint8_t SetWatchdog, TriggerWatchdog, StopWatchdog, WatchDogCap,IsPwrUpWDogStart, IsPwrUpWDogStop; -uint8_t StorageCap, StorageAreaRead, StorageAreaWrite, StorageAreaLock, StorageAreaUnLock,StorageHexWrite, StorgeHexRead,GUIDWrite, GUIDRead; +uint8_t StorageCap, StorageAreaRead, StorageAreaWrite, StorageAreaLock, StorageAreaUnLock,StorageHexWrite, StorgeHexRead,GUIDWrite, GUIDRead,ODM_write; uint8_t SmartFanTempSet, SmartFanTempGet, SmartFanTempSetSrc, SmartFanTempGetSrc, SmartFanPWMSet; uint8_t SmartFanModeGet, SmartFanModeSet, SmartFanPWMGet; uint8_t GetStringA, GetValue, GetVoltageMonitor,GetVoltageMonitorCap, GetSEMAVersion; @@ -85,29 +85,43 @@ void ShowHelp(int condition) printf(" 3. semautil /w trigger\n"); printf(" 4. semautil /w stop\n"); printf(" 5. semautil /w pwrup_enable [sec (60-65535)]\n"); - printf(" Note:\n Start time will be different for the different platforms.\n Please go to BIOS meun to check it\n"); + printf(" Note:\n Start time will be different for the different platforms.\n Please go to BIOS menu to check it\n"); printf(" 6. semautil /w pwrup_disable\n\n"); } if (condition == 2 || condition == 0) { printf("- Storage:\n"); - printf(" 1. semautil /s get_cap\n"); + printf(" 1. semautil /s get_cap [Region]\n"); printf(" 2. semautil /s read [Region] [Address] [Length] \n"); - printf(" 3. semautil /s write [Region] [Address] [string/value] [Length] \n"); + printf(" 3. semautil /s write [Region] [Address] [string/value] \n"); printf(" 4. semautil /s hex_write [Region] [Address] [value] \n"); printf(" 5. semautil /s hex_read [Region] [Address] [Length] \n"); printf(" 6. semautil /s lock [Region]\n"); - printf(" 7. semautil /s unlock [Region] [Permission] [passcode]\n\n"); + printf(" 7. semautil /s unlock [Region] [Permission] [passcode]\n"); + printf(" 8. semautil /s odm_write [ODM Id] [string/value]\n\n"); + printf(" Region:\n"); printf(" 1.User\n"); - printf(" 2.Secure\n\n"); + printf(" 2.Secure\n"); + printf(" 3.ODM\n\n"); + printf(" Permission:\n"); printf(" 1.Read only\n"); printf(" 2.Read/Write\n\n"); + + printf(" ODM Id:\n"); + printf(" 1.Hardware Revision\n"); + printf(" 2.Serial Number\n"); + printf(" 3.Last Repair date\n"); + printf(" 4.Manufacturing date\n"); + printf(" 5.2nd Hardware Revision\n"); + printf(" 6.2nd Serial Number\n"); + printf(" 7.MAC Id\n"); + printf(" 8.MAC Id 2\n\n"); + printf(" Example: semautil /s write 1020 Aaaa 4\n It will be written to 1020, 1021, 1022, 1023\n\n"); //printf("\n Note: Hexa decimal values are not valid\n Note: Locking of ODM region will only make ODM is read-only.\n lock function will not protect User region.\n read and write function will not work on ODM region\n"); - printf(" Note : hex_write operation should be provided as below\n Example: semautil /s hex_write 1 128 aa bb c d \n"); - + printf(" Note : Unlock the ODM region to perform odm_write operation\n hex_write operation should be provided as below\n Example: semautil /s hex_write 1 128 aa bb c d \n"); } if (condition == 3 || condition == 0) { @@ -267,29 +281,29 @@ void ShowHelp(int condition) printf(" 3\tEAPI_I2C_ENC_EXT_CMD\tExtended standard 16 bits CMD\n\n"); } - if(condition == 12 || condition == 0) - { - printf("\n- Get BIOS Source:\n"); - printf(" 1. semautil /src get_src\n"); - printf(" 2. semautil /src set_src value[0-3]\n"); + if (condition == 12 || condition == 0) + { + printf("\n- Get BIOS Source:\n"); + printf(" 1. semautil /src get_src\n"); + printf(" 2. semautil /src set_src value[0-3]\n"); printf(" 3. semautil /src get_bios_status\n"); - printf(" \n Value :\n"); - printf(" 0 - By hardware configuration of currently selected BIOS\n"); - printf(" 1 - Switch to Fail-Safe BIOS\n"); - printf(" 2 - Switch to External BIOS (SPI0 on carrier)\n"); - printf(" 3 - Switch to Internal BIOS (SPI0 on module)\n"); + printf(" \n Value :\n"); + printf(" 0 - By hardware configuration of currently selected BIOS\n"); + printf(" 1 - Switch to Fail-Safe BIOS\n"); + printf(" 2 - Switch to External BIOS (SPI0 on carrier)\n"); + printf(" 3 - Switch to Internal BIOS (SPI0 on module)\n"); printf("\n"); printf(" BIOS select status information.\n"); printf(" Bit2 Bit1 Bit0\n"); - printf(" 0 0 0 - Module SPI0/ Carrier SPI1 (Standard BIOS)\n"); - printf(" 0 0 1 - Carrier SPI0/ Module SPI1 (Fail - Safe BIOS)\n"); - printf(" 0 1 0 - Unknown\n"); - printf(" 0 1 1 - Module SPI0/Module SPI1 (Standard BIOS)\n"); + printf(" 0 0 0 - Module SPI0/ Carrier SPI1 (Standard BIOS)\n"); + printf(" 0 0 1 - Carrier SPI0/ Module SPI1 (Fail - Safe BIOS)\n"); + printf(" 0 1 0 - Unknown\n"); + printf(" 0 1 1 - Module SPI0/Module SPI1 (Standard BIOS)\n"); printf(" 1 0 0 - Unknown\n"); - printf(" 1 0 1 - Switch to Fail-Safe BIOS\n"); - printf(" 1 1 0 - Switch to External BIOS\n"); - printf(" 1 1 1 - Switch to Internal BIOS \n\n"); + printf(" 1 0 1 - Switch to Fail-Safe BIOS\n"); + printf(" 1 1 0 - Switch to External BIOS\n"); + printf(" 1 1 1 - Switch to Internal BIOS \n\n"); printf(" If Bit 2 is OFF : PICMG BIOS selected\n"); printf(" If Bit 2 is ON : Dual BIOS selected\n"); @@ -306,7 +320,7 @@ int DispatchCMDToSEMA(int argc,char *argv[]) { int ret = 0; /* Board information*/ - uint32_t Id, Size,region,permission, Value = 0; + uint32_t Id, Size,permission, Value, ODM_Id= 0; char *passcode; char BoardInfo[64]; char ExcepDesc[1024]; @@ -722,12 +736,12 @@ int DispatchCMDToSEMA(int argc,char *argv[]) if (StorageCap) { - if (argc != 3) { + if (argc != 4) { printf("Wrong arguments\n"); exit(-1); } - Id = EAPI_ID_STORAGE_STD; + Id = atoi(argv[3]); ret = EApiStorageCap(Id, &Storagesize, &BlockLength); if (ret) { printf("Get EApi information failed\n"); @@ -744,13 +758,12 @@ int DispatchCMDToSEMA(int argc,char *argv[]) printf("Wrong arguments\n"); exit(-1); } - Id = EAPI_ID_STORAGE_STD; memset(memcap, 0, sizeof(memcap)); - region= atoi(argv[3]); + Id= atoi(argv[3]); Offset = atoi(argv[4]); ByteCnt = atoi(argv[5]); BufLen = sizeof(memcap); - ret = EApiStorageAreaRead(Id,region, Offset, memcap, BufLen, ByteCnt); + ret = EApiStorageAreaRead(Id, Offset, memcap, BufLen, ByteCnt); if (ret) { printf("Get EApi information failed\n"); errno_exit("EApiStorageAreaRead"); @@ -770,16 +783,15 @@ int DispatchCMDToSEMA(int argc,char *argv[]) if (StorageAreaWrite) { - if (argc != 7) { + if (argc != 6) { printf("Wrong arguments\n"); exit(-1); } - Id = EAPI_ID_STORAGE_STD; - region = atoi(argv[3]); + Id = atoi(argv[3]); Offset = atoi(argv[4]); Buffer = argv[5]; - ByteCnt = atoi(argv[6]); - ret = EApiStorageAreaWrite(Id,region, Offset, Buffer, ByteCnt); + ByteCnt = strlen(Buffer); + ret = EApiStorageAreaWrite(Id,Offset, Buffer, ByteCnt); if (ret) { printf("Get EApi information failed\n"); errno_exit("EApiStorageAreaWrite"); @@ -800,51 +812,48 @@ int DispatchCMDToSEMA(int argc,char *argv[]) int i,j=0; for(i=5;i16){ + printf("\nString should not exceed 16 characters"); + exit(-1); + } + ret = EApiStorageAreaWrite(Id,Offset, Buffer, ByteCnt); + if (ret) { + printf("Get EApi information failed\n"); + errno_exit("EApiStorageAreaWrite"); + } + printf("Data Written Successfully\n"); + } if (GPIOGetDirectionCaps) @@ -1615,7 +1672,7 @@ signed int ParseArgs(int argc, char* argv[]) } else if (strcasecmp(argv[1], "/s") == 0) { - if (argc == 3 && (strcasecmp(argv[2], "get_cap") == 0)) + if (argc == 4 && (strcasecmp(argv[2], "get_cap") == 0)) { StorageCap = TRUE; } @@ -1623,7 +1680,7 @@ signed int ParseArgs(int argc, char* argv[]) { StorageAreaRead = TRUE; } - else if (argc == 7 && (strcasecmp(argv[2], "write") == 0)) + else if (argc == 6 && (strcasecmp(argv[2], "write") == 0)) { StorageAreaWrite = TRUE; } @@ -1643,6 +1700,10 @@ signed int ParseArgs(int argc, char* argv[]) { StorageAreaUnLock = TRUE; } + else if (argc == 5 && (strcasecmp(argv[2], "odm_write") == 0)) + { + ODM_write = TRUE; + } else { printf("Wrong arguments \n"); diff --git a/driver/adl-ec-gpio.c b/driver/adl-ec-gpio.c index 06d0d05..92ad40e 100755 --- a/driver/adl-ec-gpio.c +++ b/driver/adl-ec-gpio.c @@ -8,6 +8,10 @@ #include #include "adl-ec.h" +#if __has_include("/etc/redhat-release") + #define CONFIG_REDHAT +#endif + #define ADL_BMC_OFS_GPIO_IN_PORT 0x88 #define ADL_BMC_OFS_GPIO_OUT_PORT 0x86 #define ADL_BMC_OFS_GPIO_DIR 0x84 @@ -23,6 +27,10 @@ #define SET_GPIO_INT _IOWR('a','2',uint32_t *) #define GET_GPIO_INT _IOWR('a','3',uint32_t *) #define CLR_GPIO_INT _IOWR('a','4',uint32_t *) +#define GET_LEVEL _IOR('a', 'b', int32_t *) +#define SET_LEVEL _IOWR('a', 'c', struct gpiostruct *) +#define OP_DIRECTION _IOWR('a', 'd', struct gpiostruct *) +#define IN_DIRECTION _IOWR('a', 'e', int32_t *) dev_t devdrv; struct class *class_adl_gpio; @@ -33,7 +41,14 @@ struct adl_bmc_gpio { struct gpio_chip gp; }; +struct gpiostruct{ + unsigned int gpio; + int val; +}; + int flag; +struct gpiostruct data; +int gpio_ret,gpionum; static int adl_gpio_get(struct gpio_chip *chip, unsigned int offset) { @@ -297,11 +312,12 @@ int release(struct inode *inode, struct file *file) static long int ioctl (struct file *file, unsigned cmd, unsigned long arg) { int RetVal; - uint32_t gpio_dir,trigger,value; + uint32_t gpio_dir, trigger,value; switch(cmd) { case GET_GPIO_DIR: { + if((RetVal = copy_from_user(&gpio_dir,(uint32_t *)arg,sizeof(gpio_dir)))!=0) { return -EFAULT; @@ -315,6 +331,46 @@ static long int ioctl (struct file *file, unsigned cmd, unsigned long arg) } } break; + case GET_LEVEL: + { + if((RetVal = copy_from_user(&gpionum, (int32_t *) arg, sizeof(gpionum)))!=0) + { + return -EFAULT; + } + gpio_ret =adl_gpio_get(NULL,gpionum); + if((RetVal=copy_to_user((int32_t *) arg, &gpio_ret, sizeof(gpio_ret)))!=0) + { + return -EFAULT; + } + } + break; + case SET_LEVEL: + { + if((RetVal = copy_from_user(&data, (struct gpiostruct *) arg, sizeof(data)))!=0) + { + return -EFAULT; + } + adl_gpio_set(NULL,data.gpio ,data.val); + } + break; + case OP_DIRECTION : + { + if((RetVal = copy_from_user(&data, (struct gpiostruct *) arg, sizeof(data)))!=0) + { + return -EFAULT; + } + adl_gpio_direction_output(NULL,data.gpio, data.val); + } + break; + case IN_DIRECTION : + { + if((RetVal = copy_from_user(&gpionum, (int32_t *) arg, sizeof(gpionum)))!=0) + { + return -EFAULT; + } + adl_gpio_direction_input(NULL,gpionum); + } + break; case SET_GPIO_INT: { if((RetVal = copy_from_user(&trigger,(uint32_t *)arg,sizeof(trigger)))!=0) @@ -376,7 +432,9 @@ static int adl_ec_gpio_probe(struct platform_device *pdev) return -1; } -#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,4,0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,14,0) && defined(CONFIG_REDHAT) + class_adl_gpio = class_create("gpio_adl"); +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6,4,0) class_adl_gpio = class_create("gpio_adl"); #else class_adl_gpio = class_create(THIS_MODULE, "gpio_adl"); diff --git a/driver/adl-ec-i2c.c b/driver/adl-ec-i2c.c index 7c0e35a..1ddb16e 100755 --- a/driver/adl-ec-i2c.c +++ b/driver/adl-ec-i2c.c @@ -27,6 +27,10 @@ #include "adl-ec.h" +#if __has_include("/etc/redhat-release") + #define CONFIG_REDHAT +#endif + #define SEMA_C_I2C1 0x00010000 ///< Bit 16: Ext. I2C bus #1 available #define SEMA_C_I2C2 0x00020000 ///< Bit 17: Ext. I2C bus #2 available #define SEMA_C_I2C3 0x20000000 ///< Group 0 bit 29: Ext. I2C bus #3 available @@ -1239,21 +1243,19 @@ static int adl_bmc_i2c_probe(struct platform_device *pdev) return -1; } -#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,4,0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,14,0) && defined(CONFIG_REDHAT) + adlink->class = class_create("adl-ec-i2c-eapi"); +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6,4,0) adlink->class = class_create("adl-ec-i2c-eapi"); - if(adlink->class == NULL) - { - unregister_chrdev_region(adlink->ldev, 1); - return -1; - } #else adlink->class = class_create(THIS_MODULE, "adl-ec-i2c-eapi"); +#endif + if(adlink->class == NULL) { unregister_chrdev_region(adlink->ldev, 1); return -1; } -#endif if(device_create(adlink->class, NULL, adlink->ldev, NULL, "ec-i2c-eapi") == NULL) { diff --git a/driver/adl-ec-nvmem-sec.c b/driver/adl-ec-nvmem-sec.c index 8640cc6..ebb831f 100755 --- a/driver/adl-ec-nvmem-sec.c +++ b/driver/adl-ec-nvmem-sec.c @@ -14,6 +14,11 @@ #include #include #include "adl-ec.h" + +#if __has_include("/etc/redhat-release") + #define CONFIG_REDHAT +#endif + #define EAPI_STOR_LOCK _IOWR('a', 1, unsigned long) #define EAPI_STOR_UNLOCK _IOWR('a', 2, unsigned long) #define EAPI_STOR_REGION _IOWR('a', 3, unsigned long) @@ -580,7 +585,9 @@ static int adl_bmc_nvmem_probe(struct platform_device *pdev) return -1; } -# if LINUX_VERSION_CODE >= KERNEL_VERSION(6,4,0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,14,0) && defined(CONFIG_REDHAT) + adlink->class = class_create("adl-ec-nvmem-eapi"); +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6,4,0) adlink->class = class_create("adl-ec-nvmem-eapi"); #else adlink->class = class_create(THIS_MODULE, "adl-ec-nvmem-eapi"); diff --git a/driver/adl-ec-vm.c b/driver/adl-ec-vm.c index ab71e4c..bdce472 100755 --- a/driver/adl-ec-vm.c +++ b/driver/adl-ec-vm.c @@ -15,6 +15,10 @@ #include #include "adl-ec.h" +#if __has_include("/etc/redhat-release") + #define CONFIG_REDHAT +#endif + #define GET_VOLT_AND_DESC _IOR('a','1',struct data *) #define GET_VOLT_MONITOR_CAP _IOR('a','2',uint8_t *) @@ -143,7 +147,9 @@ static int adl_bmc_vm_probe(struct platform_device *pdev) return -1; } -#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,4,0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,14,0) && defined(CONFIG_REDHAT) + class_adl_vm = class_create("adl_vm"); +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6,4,0) class_adl_vm = class_create("adl_vm"); #else class_adl_vm = class_create(THIS_MODULE, "adl_vm"); diff --git a/driver/adl-ec-wdt.c b/driver/adl-ec-wdt.c index 227288d..11d9a3f 100755 --- a/driver/adl-ec-wdt.c +++ b/driver/adl-ec-wdt.c @@ -11,6 +11,9 @@ #include "adl-ec.h" +#if __has_include("/etc/redhat-release") + #define CONFIG_REDHAT +#endif #define WDT_TIMEOUT 10 #define WDT_MIN_TIMEOUT 1 @@ -265,7 +268,9 @@ static int adl_bmc_wdt_probe(struct platform_device *pdev) return -1; } -#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,4,0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,14,0) && defined(CONFIG_REDHAT) + class_adl_wdt = class_create("watchdog_adl"); +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6,4,0) class_adl_wdt = class_create("watchdog_adl"); #else class_adl_wdt = class_create(THIS_MODULE, "watchdog_adl"); diff --git a/driver/adl-ec.c b/driver/adl-ec.c index 97aab18..ec23c93 100755 --- a/driver/adl-ec.c +++ b/driver/adl-ec.c @@ -16,6 +16,10 @@ #include "adl-ec.h" +#if __has_include("/etc/redhat-release") + #define CONFIG_REDHAT +#endif + struct adl_bmc_dev *adl_bmc_dev; static const struct mfd_cell adl_bmc_devs[] = { @@ -455,19 +459,17 @@ static int adl_ec_acpi_probe(struct platform_device *pdev) return -ENODEV; } -#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,4,0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,14,0) && defined(CONFIG_REDHAT) + if((cl = class_create("sema")) == NULL) +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6,4,0) if((cl = class_create("sema")) == NULL) - { - unregister_chrdev_region(sema, 1); - return -ENODEV; - } #else if((cl = class_create(THIS_MODULE, "sema")) == NULL) +#endif { unregister_chrdev_region(sema, 1); return -ENODEV; } -#endif if(device_create(cl, NULL, sema, NULL, "sema") == NULL) { diff --git a/lib/eapi.h b/lib/eapi.h index 06117ea..c7d0992 100644 --- a/lib/eapi.h +++ b/lib/eapi.h @@ -40,7 +40,22 @@ #define EAPI_VERSION EAPI_VER_CREATE(EAPI_VER, EAPI_REVISION, 0) -#define EAPI_ID_STORAGE_STD EAPI_UINT32_C(0) + /* + * + * S T O R A G E + * + */ + /* IDs */ +#define EAPI_ID_USER_STORAGE EAPI_UINT32_C(1) +#define EAPI_ID_SCRE_STORAGE EAPI_UINT32_C(2) +#define EAPI_ID_ODM_STORAGE EAPI_UINT32_C(3) +#define EAPI_ID_FP_STORAGE EAPI_UINT32_C(5) + +#define EAPI_ID_STORAGE_STD EAPI_ID_USER_STORAGE +#define EAPI_ID_STORAGE_SCR EAPI_ID_SCRE_STORAGE +#define EAPI_ID_STORAGE_ODM EAPI_ID_ODM_STORAGE +#define EAPI_ID_STORAGE_FP EAPI_ID_FP_STORAGE + #define TRUE 1 #define FALSE 0 @@ -229,10 +244,10 @@ uint32_t EApiStorageCap(uint32_t Id, uint32_t *pStorageSize, uint32_t *pBlockLen * @brief Function To Read data to the selected user data area. * @param Offset storage area start address offset in bytes. This value must be a multiple of block length. * @param Size Number of bytes to read. - * @param pBuf Pointer to buffer that receives the reda data. + * @param pBuf Pointer to buffer that receives the read data. * @return 0 on success -1 on failure */ -uint32_t EApiStorageAreaRead(uint32_t Id,uint32_t Region, uint32_t Offset, void *pBuffer, uint32_t BufLen, uint32_t Bytecnt); +uint32_t EApiStorageAreaRead(uint32_t Id, uint32_t Offset, void *pBuffer, uint32_t BufLen, uint32_t ByteCnt); /** * @brief Function To Read data to the selected user data area. @@ -241,32 +256,25 @@ uint32_t EApiStorageAreaRead(uint32_t Id,uint32_t Region, uint32_t Offset, void * @param Length Number of bytes to write. * @return 0 on success -1 on failure */ -uint32_t EApiStorageAreaWrite(uint32_t Id,uint32_t Region, uint32_t Offset, char *pBuf, uint32_t Length); +uint32_t EApiStorageAreaWrite(uint32_t Id, uint32_t Offset, void *pBuffer, uint32_t ByteCnt); /** * @brief Function to Clear the User Region. * @return 0 on success */ -uint32_t EApiStorageHexWrite(uint32_t Id,uint32_t Region, uint32_t Offset, char* Buf, uint32_t Len); - -uint32_t EApiStorageHexRead(uint32_t Id,uint32_t Region, uint32_t Offset, void *pBuffer, uint32_t BufLen, uint32_t Bytecnt); - - - -uint32_t EApiStorageAreaClear(uint32_t Id,uint32_t Region); - - - +uint32_t EApiStorageHexWrite(uint32_t Id, uint32_t Offset, void* pBuffer, uint32_t ByteCnt); -uint32_t EApiStorageLock(uint32_t Id,uint32_t Region); +uint32_t EApiStorageHexRead(uint32_t Id, uint32_t Offset, void* pBuffer, uint32_t BufLen, uint32_t ByteCnt); +uint32_t EApiStorageAreaClear(uint32_t Id); +uint32_t EApiStorageLock(uint32_t Id); -uint32_t EApiStorageUnLock(uint32_t Id,uint32_t Region,uint32_t Permission, char *passcode); +uint32_t EApiStorageUnLock(uint32_t Id,uint32_t Permission, char *passcode); -uint32_t EApiGUIDWrite(uint32_t Id, uint32_t Region, uint32_t Offset, char* Buf, uint32_t Len); +uint32_t EApiGUIDWrite(uint32_t Id, uint32_t Offset, void* pBuffer, uint32_t ByteCnt); /* diff --git a/lib/gpio.c b/lib/gpio.c index 49b6514..dfbafce 100644 --- a/lib/gpio.c +++ b/lib/gpio.c @@ -44,11 +44,19 @@ static int ngpio = -1; #define SET_GPIO_INT _IOWR('a','2',uint32_t *) #define GET_GPIO_INT _IOWR('a','3',uint32_t *) #define CLR_GPIO_INT _IOWR('a','4',uint32_t *) +#define GET_LEVEL _IOR('a', 'b', int32_t *) +#define SET_LEVEL _IOWR('a', 'c', struct gpiostruct *) +#define OP_DIRECTION _IOWR('a', 'd', struct gpiostruct *) +#define IN_DIRECTION _IOWR('a', 'e', int32_t *) + +int gpio_handle; +int cdev_gpio = 0; struct gpiostruct{ int gpio; int val; -}; +}data; + static int get_gpio_base(int *gpiobase, int *ngpio) { @@ -100,15 +108,23 @@ int initialize_gpio(void) int gpio,ret,fd; uint16_t bit = 0; uint32_t value = 0; - if((gpiobase == -1) || (ngpio == -1)) { - ret = get_gpio_base(&gpiobase, &ngpio); - if(ret < 0) { - return -1; - } + DIR *gpio_dir = opendir("/sys/class/gpio"); + + if(gpio_dir == NULL) + { + cdev_gpio=1; } - if((fd=open("/dev/gpio_adl",O_RDONLY)) >= 0) + else { - for(gpio = gpiobase; gpio < (gpiobase + ngpio); gpio++) { + if((gpiobase == -1) || (ngpio == -1)) { + ret = get_gpio_base(&gpiobase, &ngpio); + if(ret < 0) { + return -1; + } + } + if((fd=open("/dev/gpio_adl",O_RDONLY)) >= 0) + { + for(gpio = gpiobase; gpio < (gpiobase + ngpio); gpio++) { char export[256],path[100]; struct stat stats; sprintf(path, "/sys/class/gpio/gpio%d" , gpio); @@ -126,14 +142,13 @@ int initialize_gpio(void) value = 0; system(export); } + } } close(fd); } - return 0; } - uint32_t adjustBitMask(uint32_t id, uint32_t *Bitmask) { @@ -255,8 +270,11 @@ uint32_t EApiGPIOGetDirection(uint32_t Id, uint32_t Bitmask, uint32_t *pDirectio char value[5]; char label[256]; char boardname[11]; - *pDirection=0; - + *pDirection = 0; + + //status = adjustBitMask(Bitmask, &Bitmask); + //if (status) + // return status; if (Bitmask > 0xff) { sprintf(label, "/sys/bus/platform/devices/adl-ec-boardinfo/information/board_name"); @@ -272,16 +290,36 @@ uint32_t EApiGPIOGetDirection(uint32_t Id, uint32_t Bitmask, uint32_t *pDirectio return EAPI_STATUS_INVALID_PARAMETER; - for(gpio = gpiobase, bit = 0; gpio < (gpiobase + ngpio); gpio++, bit++) { - if(Bitmask & (1 << bit)) { - sprintf(sysfile, "/sys/class/gpio/gpio%d/direction", gpio); - if(read_sysfs_file(sysfile, value, sizeof(value)) < 0) { - return EAPI_STATUS_READ_ERROR; - } - if(strncmp(value, "in", strlen("in")) == 0) { - *pDirection |= (1 << bit); - } + if(cdev_gpio == 1) + { + int mask,bit_ext; + + gpio_handle = open("/dev/gpio_adl",O_RDONLY); + if(gpio_handle < 0) + { + return -1 ; } + + for(bit_ext=0,mask=0;(bit_ext=Bitmask&(1< /sys/class/gpio/gpio%d/direction", gpio); - }else{ - sprintf(sysfile, "echo \"out\" > /sys/class/gpio/gpio%d/direction", gpio); - } - if(system(sysfile) != 0) - { - return EAPI_STATUS_WRITE_ERROR; + + if(cdev_gpio ==1) + { + int mask,bit_ext; + + gpio_handle = open("/dev/gpio_adl",O_RDONLY); + if(gpio_handle < 0) + { + return -1 ; + } + + for(bit_ext=0,mask=0;(bit_ext=Bitmask&(1< /sys/class/gpio/gpio%d/direction", gpio); + }else{ + sprintf(sysfile, "echo \"out\" > /sys/class/gpio/gpio%d/direction", gpio); + } + if(system(sysfile) != 0) + { + return EAPI_STATUS_WRITE_ERROR; + } } } } @@ -333,7 +406,7 @@ uint32_t EApiGPIOGetLevel(uint32_t Id, uint32_t Bitmask, uint32_t *pLevel) char value; char label[256]; char boardname[11]; - *pLevel=0; + *pLevel = 0; if (Bitmask > 0xff) { @@ -346,17 +419,44 @@ uint32_t EApiGPIOGetLevel(uint32_t Id, uint32_t Bitmask, uint32_t *pLevel) } } - for(gpio = gpiobase, bit = 0; gpio < (gpiobase + ngpio); gpio++, bit++) { - if(Bitmask & (1 << bit)) { - sprintf(sysfile, "/sys/class/gpio/gpio%d/value", gpio); - if(read_sysfs_file(sysfile, &value, 1) < 0) { - return EAPI_STATUS_UNSUPPORTED; - } - if ((value - '0') > 0) - *pLevel |= (1 << bit); + if(cdev_gpio ==1) + { + int mask,bit_ext; + + gpio_handle = open("/dev/gpio_adl",O_RDONLY); + if(gpio_handle < 0) + { + return -1 ; } + for(bit_ext=0,mask=0;(bit_ext=Bitmask&(1< 0) + *pLevel |= (1 << bit); + } + + } } return status; @@ -383,20 +483,56 @@ uint32_t EApiGPIOSetLevel(uint32_t Id, uint32_t Bitmask, uint32_t Level) } - for(gpio = gpiobase, bit = 0; gpio < (gpiobase + ngpio); gpio++, bit++) { - if(Bitmask & (1 << bit)) { - if(Level & (1 << bit)) - { - sprintf(sysfile, "echo \"1\" > /sys/class/gpio/gpio%d/value", gpio); - }else{ - sprintf(sysfile, "echo \"0\" > /sys/class/gpio/gpio%d/value", gpio); - } - if(system(sysfile) != 0) - { - return EAPI_STATUS_WRITE_ERROR; - } - } + if(cdev_gpio ==1) + { + int mask,bit_ext; + + gpio_handle = open("/dev/gpio_adl",O_RDONLY); + if(gpio_handle < 0) + { + return -1 ; + } + + for(bit_ext=0,mask=0;(bit_ext=Bitmask&(1<> mask) & 0x01; + if(Bitmask == 1) + { + close(gpio_handle); + return EAPI_STATUS_WRITE_ERROR; + } + if(Level != 0) + { + Level=1; + } + data.gpio=mask; + data.val=Level; + if(ioctl(gpio_handle,SET_LEVEL,&data)<0) + { + close(gpio_handle); + return EAPI_STATUS_WRITE_ERROR; + } + close(gpio_handle); + } + else + { + for(gpio = gpiobase, bit = 0; gpio < (gpiobase + ngpio); gpio++, bit++) { + if(Bitmask & (1 << bit)) { + if(Level & (1 << bit)) + { + sprintf(sysfile, "echo \"1\" > /sys/class/gpio/gpio%d/value", gpio); + }else{ + sprintf(sysfile, "echo \"0\" > /sys/class/gpio/gpio%d/value", gpio); + } + if(system(sysfile) != 0) + { + return EAPI_STATUS_WRITE_ERROR; + } + } + + } } return status; diff --git a/lib/storage.c b/lib/storage.c index 9a41f31..1a8cddb 100644 --- a/lib/storage.c +++ b/lib/storage.c @@ -29,8 +29,13 @@ #define SMC_FLASH_ALIGNMENT 4 #define EAPI_STOR_LOCK _IOWR('a', 1, unsigned long) -#define EAPI_STOR_UNLOCK _IOWR('a', 2, unsigned long) -#define EAPI_STOR_REGION _IOWR('a', 3, unsigned long) +#define EAPI_STOR_UNLOCK _IOWR('a', 2, unsigned long) +#define EAPI_STOR_REGION _IOWR('a', 3, unsigned long) + +#define BLOCK_SIZE 4 +#define EEPROM_USER_SIZE 1024 +#define EEPROM_SCRE_SIZE 2048 +#define EEPROM_ODM_SIZE 1024 struct secure { uint8_t Region; @@ -38,163 +43,181 @@ struct secure { char passcode[8]; }; static char NVMEM_DEVICE[285]; -//static char NVMEM_SEC_DEVICE[285]; static int initialize_nvmem() { struct dirent *de; - DIR *dr = opendir("/sys/bus/platform/devices/adl-ec-nvmem"); + DIR *dr = opendir("/sys/bus/platform/devices/adl-ec-nvmem"); - if (dr == NULL) // opendir returns NULL if couldn't open directory - return -1; + if (dr == NULL) // opendir returns NULL if couldn't open directory + return -1; memset(NVMEM_DEVICE, 0, sizeof(NVMEM_DEVICE)); - while ((de = readdir(dr)) != NULL) { - if(strncmp(de->d_name, "nvmem", strlen("nvmem")) == 0) { - sprintf(NVMEM_DEVICE, "/sys/bus/nvmem/devices/%s/nvmem", de->d_name); - closedir(dr); - return 0; - } + while ((de = readdir(dr)) != NULL) { + if(strncmp(de->d_name, "nvmem", strlen("nvmem")) == 0) { + sprintf(NVMEM_DEVICE, "/sys/bus/nvmem/devices/%s/nvmem", de->d_name); + closedir(dr); + return 0; } - closedir(dr); + } + closedir(dr); - return -1; + return -1; } -#define NVMEM_INIT() if(initialize_nvmem() < 0) return EAPI_STATUS_UNSUPPORTED; +#define NVMEM_INIT() if(initialize_nvmem() < 0) return EAPI_STATUS_NOT_INITIALIZED; static int initialize_nvmem_sec() { - struct dirent *de; - DIR *dr = opendir("/sys/bus/platform/devices/adl-ec-nvmem-sec"); - - if (dr == NULL) // opendir returns NULL if couldn't open directory - return -1; - memset(NVMEM_DEVICE, 0, sizeof(NVMEM_DEVICE)); - while ((de = readdir(dr)) != NULL) { - if(strncmp(de->d_name, "nvmem-sec", strlen("nvmem-sec")) == 0) { + struct dirent *de; + DIR *dr = opendir("/sys/bus/platform/devices/adl-ec-nvmem-sec"); + + if (dr == NULL) // opendir returns NULL if couldn't open directory + return -1; + memset(NVMEM_DEVICE, 0, sizeof(NVMEM_DEVICE)); + while ((de = readdir(dr)) != NULL) { + if(strncmp(de->d_name, "nvmem-sec", strlen("nvmem-sec")) == 0) { - sprintf(NVMEM_DEVICE, "/sys/bus/nvmem/devices/%s/nvmem", de->d_name); + sprintf(NVMEM_DEVICE, "/sys/bus/nvmem/devices/%s/nvmem", de->d_name); - closedir(dr); - return 0; - } + closedir(dr); + return 0; } - closedir(dr); + } + closedir(dr); - return -1; + return -1; } -#define NVMEM_SEC_INIT() if(initialize_nvmem_sec() < 0) return EAPI_STATUS_UNSUPPORTED; +#define NVMEM_SEC_INIT() if(initialize_nvmem_sec() < 0) return EAPI_STATUS_NOT_INITIALIZED; uint32_t EApiStorageCap(uint32_t Id, uint32_t *pStorageSize, uint32_t *pBlockLength) { uint32_t status = EAPI_STATUS_SUCCESS; char sysfile[256]; - char buf[128]; - - if(pStorageSize == NULL && pBlockLength == NULL){ - return EAPI_STATUS_INVALID_PARAMETER; - } - - if(Id > 1 && Id < 0) - return EAPI_STATUS_UNSUPPORTED; - - sprintf(sysfile, "/sys/bus/platform/devices/adl-ec-nvmem/capabilities/nvmemcap"); + char buf[128] = { 0 }; - status = read_sysfs_file(sysfile, buf, sizeof(buf)); - if (status) - return EAPI_STATUS_READ_ERROR; - - char* token = strtok(buf, " "); - if (strstr(token, "StorageSize")){ - token = strtok(NULL, " "); + if (pStorageSize == NULL && pBlockLength == NULL) + { + return EAPI_STATUS_INVALID_PARAMETER; } - *pStorageSize = atoi(token); + if (Id == EAPI_ID_STORAGE_STD) + { + sprintf(sysfile, "/sys/bus/platform/devices/adl-ec-nvmem/capabilities/nvmemcap"); + status = read_sysfs_file(sysfile, buf, sizeof(buf)); + if (status) + return EAPI_STATUS_READ_ERROR; - token = strtok(NULL, " "); - if (strstr(token, "\nBlockLength")){ - token = strtok(NULL, " "); - } + char* token = strtok(buf, " "); + if (strstr(token, "StorageSize")) { + token = strtok(NULL, " "); + } - *pBlockLength = atoi(token); + *pStorageSize = atoi(token); + token = strtok(NULL, " "); + if (strstr(token, "\nBlockLength")) { + token = strtok(NULL, " "); + } + *pBlockLength = atoi(token); + } + else if (Id == EAPI_ID_STORAGE_SCR) + { + *pStorageSize = EEPROM_SCRE_SIZE; + *pBlockLength = BLOCK_SIZE; + } + else if (Id == EAPI_ID_STORAGE_ODM) + { + *pStorageSize = EEPROM_ODM_SIZE; + *pBlockLength = BLOCK_SIZE; + } + else + { + return EAPI_STATUS_UNSUPPORTED; + } return status; } -uint32_t EApiStorageAreaRead(uint32_t Id,uint32_t Region, uint32_t Offset, void *pBuffer, uint32_t BufLen, uint32_t Bytecnt) +uint32_t EApiStorageAreaRead(uint32_t Id, uint32_t Offset, void* pBuffer, uint32_t BufLen, uint32_t ByteCnt) { uint32_t status = EAPI_STATUS_SUCCESS; int ret = 0; int fd; - uint32_t BytecntTemp=Bytecnt; - uint8_t pBufferTemp[(Bytecnt%4)?Bytecnt+4-(Bytecnt%4):Bytecnt]; - struct secure data; - - if(Region==1) + uint32_t BytecntTemp = ByteCnt; + uint32_t temp = (ByteCnt % 4) ? ByteCnt + 4 - (ByteCnt % 4) : ByteCnt; + uint8_t pBufferTemp[temp]; + struct secure data; + if (Id == EAPI_ID_STORAGE_STD) { NVMEM_INIT(); + if (Offset + ByteCnt > EEPROM_USER_SIZE) + { + return EAPI_STATUS_INVALID_BLOCK_LENGTH; + } } - else if(Region==2) + else if (Id == EAPI_ID_STORAGE_SCR ) { NVMEM_SEC_INIT(); + if (Offset + ByteCnt > EEPROM_SCRE_SIZE) + { + return EAPI_STATUS_INVALID_BLOCK_LENGTH; + } } - else if(Region==3) + else if ( Id == EAPI_ID_STORAGE_ODM) { NVMEM_SEC_INIT(); + if (Offset + ByteCnt > EEPROM_ODM_SIZE) + { + return EAPI_STATUS_INVALID_BLOCK_LENGTH; + } } else - { - return EAPI_STATUS_INVALID_PARAMETER; - } - - if(Id > 1 && Id < 0) { return EAPI_STATUS_UNSUPPORTED; } - if (pBuffer == NULL || Bytecnt == 0 || BufLen == 0) + + if (pBuffer == NULL || ByteCnt == 0 || BufLen == 0) { return EAPI_STATUS_INVALID_PARAMETER; } - if (Bytecnt > BufLen) + if (ByteCnt > BufLen) { return EAPI_STATUS_MORE_DATA; } - - data.Region=Region; - if((fd = open("/dev/ec-nvmem-eapi", O_RDWR)) < 0) + data.Region = Id; + + if ((fd = open("/dev/ec-nvmem-eapi", O_RDWR)) < 0) { - return -1; } - if(ioctl(fd, EAPI_STOR_REGION, &data ) < 0) - { - close(fd); - return EAPI_STATUS_UNSUPPORTED; + if (ioctl(fd, EAPI_STOR_REGION, &data) < 0) + { + close(fd); + return EAPI_STATUS_READ_ERROR; } else - close(fd); - + close(fd); + fd = open(NVMEM_DEVICE, O_RDONLY); - + if (fd < 0) { return EAPI_STATUS_READ_ERROR; } - - lseek(fd,Offset,SEEK_SET); - - if(Bytecnt % 4 != 0) + memset(pBufferTemp, 0, sizeof(pBufferTemp)); + lseek(fd, Offset, SEEK_SET); + + if (ByteCnt % 4 != 0) { - Bytecnt += 4 - (Bytecnt % 4); + ByteCnt += 4 - (ByteCnt % 4); } pBufferTemp[sizeof(pBufferTemp)]='\0'; - ret = read(fd, pBufferTemp, Bytecnt); + ret = read(fd, pBufferTemp, ByteCnt); memcpy(pBuffer, pBufferTemp, BytecntTemp); @@ -208,65 +231,73 @@ uint32_t EApiStorageAreaRead(uint32_t Id,uint32_t Region, uint32_t Offset, void return status; } -uint32_t EApiStorageAreaWrite(uint32_t Id,uint32_t Region, uint32_t Offset, char* Buf, uint32_t Len) +uint32_t EApiStorageAreaWrite(uint32_t Id, uint32_t Offset, void* pBuffer, uint32_t ByteCnt) { uint32_t status = EAPI_STATUS_SUCCESS; - int ret,fd; - struct secure data; - - if(Region==1) + int ret, fd; + struct secure data = { 0 }; + unsigned char* buffer = NULL; + + if (Id == EAPI_ID_STORAGE_STD) { NVMEM_INIT(); + if (Offset + ByteCnt > EEPROM_USER_SIZE) + { + return EAPI_STATUS_INVALID_BLOCK_LENGTH; + } } - else if(Region==2) + else if (Id == EAPI_ID_STORAGE_SCR) { NVMEM_SEC_INIT(); + if (Offset + ByteCnt > EEPROM_SCRE_SIZE) + { + return EAPI_STATUS_INVALID_BLOCK_LENGTH; + } } - else if(Region==3) + else if (Id == EAPI_ID_STORAGE_ODM) { NVMEM_SEC_INIT(); + if (Offset + ByteCnt > EEPROM_ODM_SIZE) + { + return EAPI_STATUS_INVALID_BLOCK_LENGTH; + } } else - { - return EAPI_STATUS_INVALID_PARAMETER; - } - - if(Id > 1 && Id < 0) { return EAPI_STATUS_UNSUPPORTED; } - if(Offset + Len > 2048) + + if(ByteCnt == 0 || pBuffer == NULL) { - return EAPI_STATUS_MORE_DATA; + return EAPI_STATUS_INVALID_PARAMETER; } - unsigned char *buffer; - if((Len % 4) != 0) + if ((ByteCnt % 4) != 0) { - int rem = 4 - (Len % 4); - Len = Len + rem; - buffer = calloc(Len, sizeof(char)); + int rem = 4 - (ByteCnt % 4); + ByteCnt = ByteCnt + rem; + buffer = calloc(ByteCnt, sizeof(char)); if(buffer == NULL) { return EAPI_STATUS_READ_ERROR; } - memcpy(buffer, Buf, Len); - EApiStorageAreaRead(Id,Region, Offset + (Len - rem), buffer + (Len - rem), rem, rem); + memcpy(buffer, pBuffer, ByteCnt); + EApiStorageAreaRead(Id, Offset + (ByteCnt - rem), buffer + (ByteCnt - rem), rem, rem); } else { - buffer = (unsigned char*)Buf; + buffer = (unsigned char*)pBuffer; } - data.Region=Region; - - if((fd = open("/dev/ec-nvmem-eapi", O_RDWR)) < 0) + data.Region = Id; + + if ((fd = open("/dev/ec-nvmem-eapi", O_RDWR)) < 0) { return -1; } if(ioctl(fd, EAPI_STOR_REGION, &data ) < 0) - { - close(fd); + { + close(fd); return EAPI_STATUS_UNSUPPORTED; } else @@ -277,11 +308,11 @@ uint32_t EApiStorageAreaWrite(uint32_t Id,uint32_t Region, uint32_t Offset, char if (fd < 0) { - return EAPI_STATUS_WRITE_ERROR; + return EAPI_STATUS_WRITE_ERROR; } lseek(fd,Offset,SEEK_SET); - ret = write(fd,buffer,Len); + ret = write(fd,buffer,ByteCnt); if (ret > 0) { close(fd); @@ -295,196 +326,186 @@ uint32_t EApiStorageAreaWrite(uint32_t Id,uint32_t Region, uint32_t Offset, char return status; } -uint32_t EApiStorageHexRead(uint32_t Id,uint32_t Region, uint32_t Offset, void *pBuffer, uint32_t BufLen, uint32_t Bytecnt) +uint32_t EApiStorageHexRead(uint32_t Id, uint32_t Offset, void* pBuffer, uint32_t BufLen, uint32_t ByteCnt) { - int ret = 0; - ret = EApiStorageAreaRead(Id,Region,Offset,pBuffer,BufLen,Bytecnt); - - if(ret) + int ret = 0; + ret = EApiStorageAreaRead(Id,Offset, pBuffer, BufLen, ByteCnt); + + if (ret) return ret; else return EAPI_STATUS_SUCCESS; } -uint32_t EApiStorageHexWrite(uint32_t Id,uint32_t Region, uint32_t Offset, char* Buf, uint32_t Len) +uint32_t EApiStorageHexWrite(uint32_t Id, uint32_t Offset, void* pBuffer, uint32_t ByteCnt) { - uint32_t status = EAPI_STATUS_SUCCESS; - int ret,i,fd; - struct secure data; - char *hex_buf; - char result[2048]; + uint32_t status = EAPI_STATUS_SUCCESS; + int ret = 0, i = 0, fd = 0; + struct secure data = { 0 }; + char* hex_buf = NULL; + unsigned char* buf=pBuffer; + char result[2048] = { 0 }; // Initialize to ensure no uninitialized use - for(i=0;i 1 && Id < 0) - { - return EAPI_STATUS_UNSUPPORTED; - } - - if(Region == 2) + if (Id == EAPI_ID_STORAGE_STD) + { + NVMEM_INIT(); + if (Offset + ByteCnt > EEPROM_USER_SIZE) + { + return EAPI_STATUS_INVALID_BLOCK_LENGTH; + } + } + else if (Id == EAPI_ID_STORAGE_SCR) + { + NVMEM_SEC_INIT(); + if (Offset + ByteCnt > EEPROM_SCRE_SIZE) + { + return EAPI_STATUS_INVALID_BLOCK_LENGTH; + } + } + else if (Id == EAPI_ID_STORAGE_ODM) { - if(Offset + Len > 2048) - { - printf("The maximum byte length for hex_write is 2048\n"); - return EAPI_STATUS_MORE_DATA; - } + NVMEM_SEC_INIT(); + if (Offset + ByteCnt > EEPROM_ODM_SIZE) + { + return EAPI_STATUS_INVALID_BLOCK_LENGTH; + } } else { - - if(Offset + Len > 1024) - { - printf("The maximum byte length for hex_write is 1024\n"); - return EAPI_STATUS_MORE_DATA; - } + return EAPI_STATUS_UNSUPPORTED; } - unsigned char *buffer; + unsigned char *buffer; buffer = (unsigned char*)hex_buf; - data.Region=Region; + data.Region = Id; - if((fd = open("/dev/ec-nvmem-eapi", O_RDWR)) < 0) - { - return -1; - } - if(ioctl(fd, EAPI_STOR_REGION, &data ) < 0) - { - close(fd); - return EAPI_STATUS_UNSUPPORTED; - } - else - { - close(fd); - } + if((fd = open("/dev/ec-nvmem-eapi", O_RDWR)) < 0) + { + return -1; + } + if(ioctl(fd, EAPI_STOR_REGION, &data ) < 0) + { + close(fd); + return EAPI_STATUS_UNSUPPORTED; + } + else + { + close(fd); + } fd = open(NVMEM_DEVICE, O_WRONLY); - if (fd < 0) - { - return EAPI_STATUS_WRITE_ERROR; - } - lseek(fd,Offset,SEEK_SET); + if (fd < 0) + { + return EAPI_STATUS_WRITE_ERROR; + } + lseek(fd,Offset,SEEK_SET); - ret = write(fd,buffer,Len); - if (ret > 0) - { - close(fd); - } - else - { - close(fd); - return EAPI_STATUS_WRITE_ERROR; - } - - return status; + ret = write(fd,buffer,ByteCnt); + if (ret > 0) + { + close(fd); + } + else + { + close(fd); + return EAPI_STATUS_WRITE_ERROR; + } + + return status; } -uint32_t EApiGUIDWrite(uint32_t Id,uint32_t Region, uint32_t Offset, char* Buf, uint32_t Len) +uint32_t EApiGUIDWrite(uint32_t Id, uint32_t Offset, void* pBuffer, uint32_t ByteCnt) { - uint32_t status = EAPI_STATUS_SUCCESS; - int ret,fd; + uint32_t status = EAPI_STATUS_SUCCESS; + int ret, fd; struct secure data; - char *hex_buf; - char result[2048]; - + char* hex_buf; + char result[2048]; + NVMEM_SEC_INIT(); - if(Offset + Len > 1024) - { - printf("The maximum byte length for GUIDWrite is 1024\n"); - return EAPI_STATUS_MORE_DATA; - } - Conv_String2HexByte(Buf,result); - hex_buf = result; + if (Offset + ByteCnt > EEPROM_ODM_SIZE) + { + return EAPI_STATUS_INVALID_BLOCK_LENGTH; + } - data.Region=Region; + Conv_String2HexByte(pBuffer,result); + hex_buf = result; - if((fd = open("/dev/ec-nvmem-eapi", O_RDWR)) < 0) - { - return -1; - } - if(ioctl(fd, EAPI_STOR_REGION, &data ) < 0) - { - close(fd); - return EAPI_STATUS_UNSUPPORTED; - } - else - { - close(fd); - } + data.Region = Id; + + if((fd = open("/dev/ec-nvmem-eapi", O_RDWR)) < 0) + { + return -1; + } + if(ioctl(fd, EAPI_STOR_REGION, &data ) < 0) + { + close(fd); + return EAPI_STATUS_UNSUPPORTED; + } + else + { + close(fd); + } fd = open(NVMEM_DEVICE, O_WRONLY); - if (fd < 0) - { - return EAPI_STATUS_WRITE_ERROR; - } - - lseek(fd,Offset,SEEK_SET); - ret = write(fd,hex_buf,Len); - if (ret > 0) - { - close(fd); - } - else - { - close(fd); - return EAPI_STATUS_WRITE_ERROR; - } - - return status; + if (fd < 0) + { + return EAPI_STATUS_WRITE_ERROR; + } + + lseek(fd,Offset,SEEK_SET); + ret = write(fd,hex_buf,ByteCnt); + if (ret > 0) + { + close(fd); + } + else + { + close(fd); + return EAPI_STATUS_WRITE_ERROR; + } + + return status; } -uint32_t EApiStorageAreaClear(uint32_t Id,uint32_t Region) +uint32_t EApiStorageAreaClear(uint32_t Id) { return EAPI_STATUS_UNSUPPORTED; } -uint32_t EApiStorageLock(uint32_t Id,uint32_t Region) +uint32_t EApiStorageLock(uint32_t Id) { uint32_t status = EAPI_STATUS_SUCCESS; int fd; struct secure data; - if(Region!=2 && Region!=3 ) + if (Id != EAPI_ID_STORAGE_SCR && Id != EAPI_ID_STORAGE_ODM) { return EAPI_STATUS_INVALID_PARAMETER; } - data.Region=Region; + data.Region=Id; - if((fd = open("/dev/ec-nvmem-eapi", O_RDWR)) < 0) + if((fd = open("/dev/ec-nvmem-eapi", O_RDWR)) < 0) { return -1; } if(ioctl(fd, EAPI_STOR_LOCK, &data ) < 0) - { + { close(fd); return EAPI_STATUS_UNSUPPORTED; } @@ -493,32 +514,34 @@ uint32_t EApiStorageLock(uint32_t Id,uint32_t Region) return status; } -uint32_t EApiStorageUnLock(uint32_t Id,uint32_t Region,uint32_t Permission, char *passcode) +uint32_t EApiStorageUnLock(uint32_t Id, uint32_t Permission, char* passcode) { uint32_t status = EAPI_STATUS_SUCCESS; int fd; - struct secure data; - if(Region!=2 && Region!=3 ) + struct secure data; + + if (Id != EAPI_ID_STORAGE_SCR && Id != EAPI_ID_STORAGE_ODM) { return EAPI_STATUS_INVALID_PARAMETER; } - data.Region=Region; - data.permission=Permission; + + data.Region = Id; + data.permission = Permission; memset(data.passcode,0,sizeof(data.passcode)); memcpy(data.passcode,passcode,strlen(passcode)); - if((fd = open("/dev/ec-nvmem-eapi", O_RDWR)) < 0) - { - return -1; - } + if((fd = open("/dev/ec-nvmem-eapi", O_RDWR)) < 0) + { + return -1; + } - if(ioctl(fd, EAPI_STOR_UNLOCK,&data ) < 0) - { - close(fd); - return EAPI_STATUS_UNSUPPORTED; - } + if(ioctl(fd, EAPI_STOR_UNLOCK,&data ) < 0) + { + close(fd); + return EAPI_STATUS_UNSUPPORTED; + } - close(fd); - return status; + close(fd); + return status; }