From: Hyotaek Shim Date: Fri, 4 Jun 2021 09:56:13 +0000 (+0900) Subject: Change board to use /proc/cpuinfo X-Git-Tag: submit/tizen/20210604.100157^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=83eb9c231ca2f5eddd7d0f5337fa4d3182a27cd7;p=platform%2Fhal%2Fbackend%2Fvim3%2Fdevice-vim3.git Change board to use /proc/cpuinfo Change-Id: Ib295ff76ba4031190adb8410e7302b1cc1d8f113 Signed-off-by: Hyotaek Shim --- diff --git a/hw/board/board.c b/hw/board/board.c index 56a2d7d..0487abd 100644 --- a/hw/board/board.c +++ b/hw/board/board.c @@ -25,28 +25,85 @@ #include -#define SERIAL_FILE_PATH "/sys/firmware/devicetree/base/serial-number" -#define LINE_LEN 64 +#define DATA_BUFF_MAX 256 +#define CPUINFO_PATH "/proc/cpuinfo" +#define SERIAL_TAG "Serial" +#define LINE_LEN 64 + +struct board_info { + char serial[DATA_BUFF_MAX]; + int serial_len; + int revision; +}; -static int get_device_serial(char **out) +static struct board_info info; + +static int get_serialno_from_cpuinfo(void) { FILE *fp; - char *line, *p; + char line[LINE_LEN], *p, *q; + int len; + + fp = fopen(CPUINFO_PATH, "r"); + if (!fp) { + _E("Failed to open %s.", CPUINFO_PATH); + return -ENOENT; + } - fp = fopen(SERIAL_FILE_PATH, "r"); - if (!fp) - return -1; + while ((p = fgets(line, sizeof(line), fp)) != NULL) { + p = strchr(p, '\t'); + if (!p) + continue; + + *p = '\0'; + if (strncmp(line, SERIAL_TAG, sizeof(line)) != 0) + continue; + + ++p; + p = strchr(p, ':'); + if (!p) + continue; + p += 2; + q = strchrnul(p, '\n'); + *q = '\0'; + + len = strlen(p) > DATA_BUFF_MAX-1 ? DATA_BUFF_MAX-1 : strlen(p); + memcpy(info.serial, p, len); + info.serial[len] = '\0'; + info.serial_len = strlen(p); + + fclose(fp); + return 0; + } - line = malloc(LINE_LEN); - p = fgets(line, LINE_LEN, fp); + _E("Failed to find serial number from cpuinfo."); fclose(fp); - if (p == NULL) { - free(line); - return -1; + return -EIO; +} + +static int get_device_serial(char **out) +{ + int ret; + if (info.serial_len > 0 && strlen(info.serial) == info.serial_len) { + *out = strdup(info.serial); + if (!out) { + _E("Out of memory, strdup failed."); + return -ENOMEM; + } + return 0; } - *out = p; - return 0; + ret = get_serialno_from_cpuinfo(); + if (ret < 0) { + _E("Failed to find serial number."); + return ret; + } + + *out = strdup(info.serial); + if (!out) + _E("Out of memory, strdup failed."); + + return ret; } static int board_init(void **data) @@ -75,7 +132,7 @@ static int board_exit(void *data) hal_backend EXPORT hal_backend_device_board_data = { .name = "board", - .vendor = "RPI", + .vendor = "VIM3", .abi_version = HAL_ABI_VERSION_TIZEN_6_5, .init = board_init, .exit = board_exit, diff --git a/hw/display/display.c b/hw/display/display.c index 1f11726..6140400 100644 --- a/hw/display/display.c +++ b/hw/display/display.c @@ -122,7 +122,7 @@ static int display_exit(void *data) hal_backend EXPORT hal_backend_device_display_data = { .name = "display", - .vendor = "RPI", + .vendor = "VIM3", .abi_version = HAL_ABI_VERSION_TIZEN_6_5, .init = display_init, .exit = display_exit, diff --git a/hw/haptic/gpio.c b/hw/haptic/gpio.c index 3d4b20c..921c53c 100644 --- a/hw/haptic/gpio.c +++ b/hw/haptic/gpio.c @@ -345,7 +345,7 @@ static int haptic_exit(void *data) hal_backend EXPORT hal_backend_device_haptic_data = { .name = "haptic", - .vendor = "RPI", + .vendor = "VIM3", .abi_version = HAL_ABI_VERSION_TIZEN_6_5, .init = haptic_init, .exit = haptic_exit, diff --git a/hw/memory/memory.c b/hw/memory/memory.c index 90157ab..95a9745 100644 --- a/hw/memory/memory.c +++ b/hw/memory/memory.c @@ -107,7 +107,7 @@ static int memory_exit(void *data) hal_backend EXPORT hal_backend_device_memory_data = { .name = "memory", - .vendor = "RPI", + .vendor = "VIM3", .abi_version = HAL_ABI_VERSION_TIZEN_6_5, .init = memory_init, .exit = memory_exit, diff --git a/hw/thermal/thermal.c b/hw/thermal/thermal.c index 903e7d2..832a426 100644 --- a/hw/thermal/thermal.c +++ b/hw/thermal/thermal.c @@ -142,7 +142,7 @@ static int thermal_exit(void *data) hal_backend EXPORT hal_backend_device_thermal_data = { .name = "thermal", - .vendor = "RPI", + .vendor = "VIM3", .abi_version = HAL_ABI_VERSION_TIZEN_6_5, .init = thermal_init, .exit = thermal_exit, diff --git a/hw/touchscreen/touchscreen.c b/hw/touchscreen/touchscreen.c index ff4e9b8..91a8895 100644 --- a/hw/touchscreen/touchscreen.c +++ b/hw/touchscreen/touchscreen.c @@ -115,7 +115,7 @@ static int touchscreen_exit(void *data) hal_backend EXPORT hal_backend_device_touchscreen_data = { .name = "touchscreen", - .vendor = "RPI", + .vendor = "VIM3", .abi_version = HAL_ABI_VERSION_TIZEN_6_5, .init = touchscreen_init, .exit = touchscreen_exit, diff --git a/hw/usb_gadget/usb_gadget.c b/hw/usb_gadget/usb_gadget.c index 3a35e4f..23ec0c1 100644 --- a/hw/usb_gadget/usb_gadget.c +++ b/hw/usb_gadget/usb_gadget.c @@ -74,7 +74,7 @@ static int usb_gadget_exit(void *data) hal_backend EXPORT hal_backend_device_usb_gadget_data = { .name = "usb_gadget", - .vendor = "RPI", + .vendor = "VIM3", .abi_version = HAL_ABI_VERSION_TIZEN_6_5, .init = usb_gadget_init, .exit = usb_gadget_exit,