Change board to use /proc/cpuinfo 38/259338/3 accepted/tizen/unified/20210607.011712 submit/tizen/20210604.100157
authorHyotaek Shim <hyotaek.shim@samsung.com>
Fri, 4 Jun 2021 09:56:13 +0000 (18:56 +0900)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Fri, 4 Jun 2021 10:00:09 +0000 (19:00 +0900)
Change-Id: Ib295ff76ba4031190adb8410e7302b1cc1d8f113
Signed-off-by: Hyotaek Shim <hyotaek.shim@samsung.com>
hw/board/board.c
hw/display/display.c
hw/haptic/gpio.c
hw/memory/memory.c
hw/thermal/thermal.c
hw/touchscreen/touchscreen.c
hw/usb_gadget/usb_gadget.c

index 56a2d7dae3428a6cd2b4a11eeee6cc4abcc4ede4..0487abdb57e817c548329eb0586d038f36f100fa 100644 (file)
 
 #include </hal/include/device/hal-backend-common.h>
 
-#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,
index 1f1172617548cadae1e8a2466733080ad4e2982e..6140400caf9286f4b90137a67909d50ae27bcf23 100644 (file)
@@ -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,
index 3d4b20c0739fb2d4cfdfec4415ee778264691617..921c53cd89460374b478da3670d467e181830855 100644 (file)
@@ -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,
index 90157abc290deee464f7495a3c9612952c399e3e..95a9745c773ef3c9f1f10c3c51c27cad3e423699 100644 (file)
@@ -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,
index 903e7d2426e2c4bbe38e4290cda41f38f3726797..832a426cafd124fb39e4a32a5d1ed8dd356ee03e 100644 (file)
@@ -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,
index ff4e9b82214c6e80e9e69b07ab3c8d4ec681f77e..91a8895e66d2841de74bfab9d217ba69b01acb9e 100644 (file)
@@ -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,
index 3a35e4f120691e5215143a31f869697e13d8cbec..23ec0c1639f3e2c28e423b4e7e6e69c6b594fa83 100644 (file)
@@ -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,