From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>,
Marco Felsch <m.felsch@pengutronix.de>
Subject: [PATCH v3 04/12] common: bootargs: drop legacy bootargs fallback with FLEXIBLE_BOOTARGS
Date: Mon, 26 Oct 2026 13:09:55 +0100 [thread overview]
Message-ID: <20261026121150.455510-5-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20261026121150.455510-1-a.fatoum@pengutronix.de>
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 <m.felsch@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
.../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
next prev parent reply other threads:[~2026-10-26 12:12 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-26 12:09 [PATCH v3 00/12] efi: payload: allow passing arguments to UKIs Ahmad Fatoum
2026-10-26 12:09 ` [PATCH v3 01/12] efi: treat EFI zboot Linux images like other EFI-stubbed kernels Ahmad Fatoum
2026-10-26 12:09 ` [PATCH v3 02/12] commands: devlookup: honour global.bootm.root_param for -k Ahmad Fatoum
2026-10-26 12:09 ` [PATCH v3 03/12] common: bootargs: don't leave linux_bootargs dangling after free Ahmad Fatoum
2026-10-26 12:09 ` Ahmad Fatoum [this message]
2026-10-26 12:09 ` [PATCH v3 05/12] globalvar: skip empty variables in globalvar_get_match() Ahmad Fatoum
2026-10-26 12:09 ` [PATCH v3 06/12] efi: payload: honour bootm dryrun in the EFI application handler Ahmad Fatoum
2026-10-26 12:09 ` [PATCH v3 07/12] efi: payload: always shutdown barebox when booting Ahmad Fatoum
2026-10-26 12:09 ` [PATCH v3 08/12] efi: payload: pass shell arguments as load options to executed images Ahmad Fatoum
2026-10-26 12:10 ` [PATCH v3 09/12] efi: add global.efi.bootargs for bootm'd EFI applications Ahmad Fatoum
2026-10-26 12:10 ` [PATCH v3 10/12] Documentation: efi: describe load options handling Ahmad Fatoum
2026-10-26 12:10 ` [PATCH v3 11/12] test: py: efiloader: check global.efi.bootargs reaches the kernel Ahmad Fatoum
2026-10-26 12:10 ` [PATCH v3 12/12] boot: report exit status of failing boot scripts Ahmad Fatoum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261026121150.455510-5-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=m.felsch@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox