linux_bootargs_get() falls back to the legacy bootargs environment variable
whenever the concatenation of all global.linux.bootargs.* variables comes
out empty. That contradicts the documentation, which describes bootargs as
the CONFIG_FLEXIBLE_BOOTARGS=n way of passing a command line, and it only
worked until the first boot entry had run: bootscript_boot() registers
global.linux.bootargs.dyn.ip and .dyn.root, and the separator between the
two empty variables made the result non-empty, so the kernel got a command
line consisting of spaces instead.

The early return taking the fallback also skipped global.linux.mtdparts.*
and global.linux.blkdevparts.*, so these only reached the kernel if a
global.linux.bootargs.* variable had a value, or the separators above made
it look like one had.

Drop the fallback, append mtdparts= and blkdevparts= whenever they are set
and return NULL only when there is nothing to pass at all. All callers
already handle a NULL command line, as the fallback could return NULL as
well.

Assisted-by: Claude:opus-5
Reviewed-by: Marco Felsch <[email protected]>
Signed-off-by: Ahmad Fatoum <[email protected]>
---
 .../flexible-bootargs-legacy-fallback.rst     | 19 +++++++++++
 Documentation/user/booting-linux.rst          |  6 ++--
 common/bootargs.c                             | 33 ++++++++-----------
 3 files changed, 37 insertions(+), 21 deletions(-)
 create mode 100644 
Documentation/migration-guides/migration-master/flexible-bootargs-legacy-fallback.rst

diff --git 
a/Documentation/migration-guides/migration-master/flexible-bootargs-legacy-fallback.rst
 
b/Documentation/migration-guides/migration-master/flexible-bootargs-legacy-fallback.rst
new file mode 100644
index 000000000000..abb9a80d385b
--- /dev/null
+++ 
b/Documentation/migration-guides/migration-master/flexible-bootargs-legacy-fallback.rst
@@ -0,0 +1,19 @@
+Legacy bootargs variable ignored with CONFIG_FLEXIBLE_BOOTARGS
+--------------------------------------------------------------
+
+With ``CONFIG_FLEXIBLE_BOOTARGS`` enabled, the kernel command line used to
+fall back to the legacy ``bootargs`` environment variable whenever the
+concatenation of all ``global.linux.bootargs.*`` variables came out empty.
+This fallback is gone, only the global variables are used now.
+
+The fallback was already mostly unreachable: once a boot entry had run,
+``global.linux.bootargs.dyn.ip`` and ``global.linux.bootargs.dyn.root`` were
+registered and the separator between the two empty variables made the
+concatenation non-empty.
+
+Set ``global.linux.bootargs.base`` instead of ``bootargs``, or disable
+``CONFIG_FLEXIBLE_BOOTARGS`` to keep using the legacy variable.
+
+``global.linux.mtdparts.*`` and ``global.linux.blkdevparts.*`` are now
+passed to the kernel even if no ``global.linux.bootargs.*`` variable has a
+value. Previously, they were dropped along with taking the fallback.
diff --git a/Documentation/user/booting-linux.rst 
b/Documentation/user/booting-linux.rst
index afc705ac865b..534b27e2167b 100644
--- a/Documentation/user/booting-linux.rst
+++ b/Documentation/user/booting-linux.rst
@@ -86,8 +86,10 @@ The simple method to pass bootargs to the kernel is with
 takes the bootargs from the :ref:`bootargs <magicvar_bootargs>` environment 
variable.
 
 With ``CONFIG_FLEXIBLE_BOOTARGS`` enabled, the bootargs are composed
-from different :ref:`global device<global_device>` variables. All variables 
beginning
-with ``global.linux.bootargs.`` will be concatenated to the bootargs:
+from different :ref:`global device<global_device>` variables and the
+:ref:`bootargs <magicvar_bootargs>` environment variable is ignored.
+All variables beginning with ``global.linux.bootargs.`` will be concatenated
+to the bootargs:
 
 .. code-block:: sh
 
diff --git a/common/bootargs.c b/common/bootargs.c
index 6373d9ccb1f7..1008e5cfccc0 100644
--- a/common/bootargs.c
+++ b/common/bootargs.c
@@ -17,12 +17,10 @@ static int linux_bootargs_overwritten;
 /*
  * This returns the Linux bootargs
  *
- * There are two ways to handle bootargs. The old legacy way is to use the
- * 'bootargs' environment variable. The new and more flexible way is to use
- * global variables beginning with "global.linux.bootargs." and
- * "global.linux.mtdparts.". These variables will be concatenated together to
- * the resulting bootargs. If there are no "global.linux.bootargs." variables
- * we fall back to "bootargs"
+ * The bootargs are concatenated from the global variables beginning with
+ * "global.linux.bootargs.", "global.linux.mtdparts." and
+ * "global.linux.blkdevparts.". The legacy 'bootargs' environment variable
+ * is only used by the CONFIG_FLEXIBLE_BOOTARGS=n stub in <bootargs.h>.
  */
 const char *linux_bootargs_get(void)
 {
@@ -32,20 +30,12 @@ const char *linux_bootargs_get(void)
                return linux_bootargs;
 
        free(linux_bootargs);
-       linux_bootargs = NULL;
-
-       bootargs = globalvar_get_match("linux.bootargs.", " ");
-       if (!strlen(bootargs)) {
-               free(bootargs);
-               return getenv("bootargs");
-       }
-
-       linux_bootargs = bootargs;
+       linux_bootargs = globalvar_get_match("linux.bootargs.", " ");
 
        parts = globalvar_get_match("linux.mtdparts.", ";");
        if (strlen(parts)) {
-               bootargs = basprintf("%s mtdparts=%s", linux_bootargs,
-                                      parts);
+               bootargs = basprintf("%s%smtdparts=%s", linux_bootargs,
+                                    *linux_bootargs ? " " : "", parts);
                free(linux_bootargs);
                linux_bootargs = bootargs;
        }
@@ -54,14 +44,19 @@ const char *linux_bootargs_get(void)
 
        parts = globalvar_get_match("linux.blkdevparts.", ";");
        if (strlen(parts)) {
-               bootargs = basprintf("%s blkdevparts=%s", linux_bootargs,
-                                      parts);
+               bootargs = basprintf("%s%sblkdevparts=%s", linux_bootargs,
+                                    *linux_bootargs ? " " : "", parts);
                free(linux_bootargs);
                linux_bootargs = bootargs;
        }
 
        free(parts);
 
+       if (!*linux_bootargs) {
+               free(linux_bootargs);
+               linux_bootargs = NULL;
+       }
+
        return linux_bootargs;
 }
 
-- 
2.47.3


Reply via email to