system: introduce new attribute board_name
authorDaniel Golle <daniel@makrotopia.org>
Thu, 8 Jun 2017 20:21:27 +0000 (22:21 +0200)
committerDaniel Golle <daniel@makrotopia.org>
Tue, 20 Jun 2017 14:48:43 +0000 (16:48 +0200)
The system board call returns the verbose model string instead of the
board name. Unfortunately we have not yet estabkushed clear convention
regarding device-tree 'compatible' or 'model' property and sysupgrade
image name (same accounts for scraping /proc/cpuinfo on legacy
targets). This is odd as the idea was to return information needed to
identify the right sysupgrade image. On most targets we got a large
shell-script which translates either /proc/cpuinfo or the 'model'
property back into the board name used here.
Hence introduce a new attribute board_name to return either
/tmp/sysinfo/board_name or /proc/device-tree/compatible.

This combines commit 79bbe6d (system: return legacy board name) and
commit 453116e (system: introduce new attribute board_name) from the
master branch into a single commit.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
system.c

index 1e31ce6859cd760fb07e43266ab62a1f07db09e8..c4d67a6dd4eefad3a931aed538c620a1e5080d11 100644 (file)
--- a/system.c
+++ b/system.c
@@ -115,6 +115,40 @@ static int system_board(struct ubus_context *ctx, struct ubus_object *obj,
                fclose(f);
        }
 
+       if ((f = fopen("/tmp/sysinfo/board_name", "r")) != NULL)
+       {
+               if (fgets(line, sizeof(line), f))
+               {
+                       val = strtok(line, "\t\n");
+
+                       if (val)
+                               blobmsg_add_string(&b, "board_name", val);
+               }
+
+               fclose(f);
+       }
+       else if ((f = fopen("/proc/device-tree/compatible", "r")) != NULL)
+       {
+               if (fgets(line, sizeof(line), f))
+               {
+                       val = strtok(line, "\t\n");
+
+                       if (val)
+                       {
+                               next = val;
+                               while ((next = strchr(next, ',')) != NULL)
+                               {
+                                       *next = '-';
+                                       next++;
+                               }
+
+                               blobmsg_add_string(&b, "board_name", val);
+                       }
+               }
+
+               fclose(f);
+       }
+
        if ((f = fopen("/etc/openwrt_release", "r")) != NULL)
        {
                c = blobmsg_open_table(&b, "release");