]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
bootstd: Read the Operating System name for distro/scripts
authorSimon Glass <sjg@chromium.org>
Fri, 6 Jan 2023 14:52:33 +0000 (08:52 -0600)
committerTom Rini <trini@konsulko.com>
Mon, 16 Jan 2023 23:26:50 +0000 (18:26 -0500)
Add the concept of an OS name to the bootflow. This typically includes the
OS name, version and kernel version.

Implement this for the distro and script bootmeths so that it works with
Armbian and older version of Fedora.

Signed-off-by: Simon Glass <sjg@chromium.org>
boot/bootflow.c
boot/bootmeth_distro.c
boot/bootmeth_script.c
cmd/bootflow.c
include/bootflow.h
test/boot/bootflow.c

index f9ad40992442b211adc04a7b208fbf39744b6e8e..163cd4953ddb5b4211dd2c29febbf6a7a5156600 100644 (file)
@@ -354,6 +354,7 @@ void bootflow_free(struct bootflow *bflow)
        free(bflow->subdir);
        free(bflow->fname);
        free(bflow->buf);
+       free(bflow->os_name);
 }
 
 void bootflow_remove(struct bootflow *bflow)
index 5c6c687f0a64a81b2aff32c30a8ac5dec36bfebb..6ef0fa1f2c906da6bb2be2bec83caaa6a37404c1 100644 (file)
@@ -66,6 +66,38 @@ static int distro_check(struct udevice *dev, struct bootflow_iter *iter)
        return 0;
 }
 
+/**
+ * distro_fill_info() - Decode the extlinux file to find out distro info
+ *
+ * @bflow: Bootflow to process
+ * @return 0 if OK, -ve on error
+ */
+static int distro_fill_info(struct bootflow *bflow)
+{
+       struct membuff mb;
+       char line[200];
+       char *data;
+       int len;
+
+       log_debug("parsing bflow file size %x\n", bflow->size);
+       membuff_init(&mb, bflow->buf, bflow->size);
+       membuff_putraw(&mb, bflow->size, true, &data);
+       while (len = membuff_readline(&mb, line, sizeof(line) - 1, ' '), len) {
+               char *tok, *p = line;
+
+               tok = strsep(&p, " ");
+               if (p) {
+                       if (!strcmp("label", tok)) {
+                               bflow->os_name = strdup(p);
+                               if (!bflow->os_name)
+                                       return log_msg_ret("os", -ENOMEM);
+                       }
+               }
+       }
+
+       return 0;
+}
+
 static int distro_read_bootflow(struct udevice *dev, struct bootflow *bflow)
 {
        struct blk_desc *desc;
@@ -99,6 +131,10 @@ static int distro_read_bootflow(struct udevice *dev, struct bootflow *bflow)
        if (ret)
                return log_msg_ret("read", ret);
 
+       ret = distro_fill_info(bflow);
+       if (ret)
+               return log_msg_ret("inf", ret);
+
        return 0;
 }
 
index 5799c89a466ba87a2f2bc4b4e8c8a6d45a0384d6..ba8e5d0438a8f3968a801ceb3960b7661755ff83 100644 (file)
@@ -35,6 +35,36 @@ static int script_check(struct udevice *dev, struct bootflow_iter *iter)
        return 0;
 }
 
+/**
+ * script_fill_info() - Decode the U-Boot script to find out distro info
+ *
+ * @bflow: Bootflow to process
+ * @return 0 if OK, -ve on error
+ */
+static int script_fill_info(struct bootflow *bflow)
+{
+       char *name = NULL;
+       char *data;
+       uint len;
+       int ret;
+
+       log_debug("parsing bflow file size %x\n", bflow->size);
+
+       ret = image_locate_script(bflow->buf, bflow->size, NULL, NULL, &data, &len);
+       if (!ret) {
+               if (strstr(data, "armbianEnv"))
+                       name = "Armbian";
+       }
+
+       if (name) {
+               bflow->os_name = strdup(name);
+               if (!bflow->os_name)
+                       return log_msg_ret("os", -ENOMEM);
+       }
+
+       return 0;
+}
+
 static int script_read_bootflow(struct udevice *dev, struct bootflow *bflow)
 {
        struct blk_desc *desc = NULL;
@@ -75,6 +105,10 @@ static int script_read_bootflow(struct udevice *dev, struct bootflow *bflow)
        if (ret)
                return log_msg_ret("read", ret);
 
+       ret = script_fill_info(bflow);
+       if (ret)
+               return log_msg_ret("inf", ret);
+
        return 0;
 }
 
index 313103d277545f8454d435feec555d6721ef4205..6b8ac8c85048d9044775990df923eee1b3c11a5c 100644 (file)
@@ -337,6 +337,7 @@ static int do_bootflow_info(struct cmd_tbl *cmdtp, int flag, int argc,
        printf("Filename:  %s\n", bflow->fname);
        printf("Buffer:    %lx\n", (ulong)map_to_sysmem(bflow->buf));
        printf("Size:      %x (%d bytes)\n", bflow->size, bflow->size);
+       printf("OS:        %s\n", bflow->os_name ? bflow->os_name : "(none)");
        printf("Error:     %d\n", bflow->err);
        if (dump && bflow->buf) {
                /* Set some sort of maximum on the size */
index 32dbbbbe26133a8ce758b7c4ccbaf3e891672f79..776158c65df59c60a2535cd01802563a47164ce6 100644 (file)
@@ -52,6 +52,8 @@ enum bootflow_state_t {
  * @buf: Bootflow file contents (allocated)
  * @size: Size of bootflow file in bytes
  * @err: Error number received (0 if OK)
+ * @os_name: Name of the OS / distro being booted, or NULL if not known
+ *     (allocated)
  */
 struct bootflow {
        struct list_head bm_node;
@@ -68,6 +70,7 @@ struct bootflow {
        char *buf;
        int size;
        int err;
+       char *os_name;
 };
 
 /**
index e1e07082105f596ff71d0fd090e1c769f9f6cd99..3296316cf0dc39bbdb6a0d91c17e6a0e2ce0c6a5 100644 (file)
@@ -188,6 +188,7 @@ static int bootflow_cmd_info(struct unit_test_state *uts)
        ut_assert_nextline("Filename:  /extlinux/extlinux.conf");
        ut_assert_nextlinen("Buffer:    ");
        ut_assert_nextline("Size:      253 (595 bytes)");
+       ut_assert_nextline("OS:        Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl)");
        ut_assert_nextline("Error:     0");
        ut_assert_console_end();