]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
bootstd: android: add the bootargs env to the commandline
authorNicolas Belin (TI.com) <nbelin@baylibre.com>
Fri, 24 Oct 2025 14:23:22 +0000 (16:23 +0200)
committerMattijs Korpershoek <mkorpershoek@kernel.org>
Thu, 6 Nov 2025 09:19:31 +0000 (10:19 +0100)
When previously using script based bootflows, the U-Boot
environment variable bootargs was used to customize the kernel
commandline at boot time.
In order to get the same behaviour, concatenate the bootflow
commandline with the contents the bootargs environment variable.

Signed-off-by: Nicolas Belin (TI.com) <nbelin@baylibre.com>
Signed-off-by: Guillaume La Roque (TI.com) <glaroque@baylibre.com>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@kernel.org>
Link: https://lore.kernel.org/r/20251024-botargsappend-v1-1-0b78f05f9132@baylibre.com
Signed-off-by: Mattijs Korpershoek <mkorpershoek@kernel.org>
boot/bootmeth_android.c

index 8c2bde10e171f2141cb544586bd6e1d34efb9959..1374551dbeb5e27703697772bc6fd56b44a609a1 100644 (file)
@@ -512,6 +512,37 @@ static int run_avb_verification(struct bootflow *bflow)
 }
 #endif /* AVB_VERIFY */
 
+static int append_bootargs_to_cmdline(struct bootflow *bflow)
+{
+       char *bootargs;
+       int len = 0;
+
+       /*
+        * Check any additionnal bootargs coming from U-Boot env. If any,
+        * merge them with the current cmdline
+        */
+       bootargs = env_get("bootargs");
+       if (bootargs) {
+               len += strlen(bootargs) + 1; /* Extra space character needed */
+               len += strlen(bflow->cmdline);
+
+               char *newcmdline = malloc(len + 1); /* +1 for the '\0' */
+
+               if (!newcmdline)
+                       return log_msg_ret("newcmdline malloc", -ENOMEM);
+
+               strcpy(newcmdline, bootargs);
+               strcat(newcmdline, " ");
+               strcat(newcmdline, bflow->cmdline);
+
+               /* Free the previous cmdline and replace it */
+               free(bflow->cmdline);
+               bflow->cmdline = newcmdline;
+       }
+
+       return 0;
+}
+
 static int boot_android_normal(struct bootflow *bflow)
 {
        struct blk_desc *desc = dev_get_uclass_plat(bflow->blk);
@@ -546,6 +577,10 @@ static int boot_android_normal(struct bootflow *bflow)
        if (priv->slot)
                free(priv->slot);
 
+       ret = append_bootargs_to_cmdline(bflow);
+       if (ret < 0)
+               return log_msg_ret("bootargs append", ret);
+
        ret = bootm_boot_start(loadaddr, bflow->cmdline);
 
        return log_msg_ret("boot", ret);