mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Alexander Shiyan <eagle.alexander923@gmail.com>,
	Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 3/3] bootm: append automatic parameters after all other linux.bootargs
Date: Tue,  5 May 2026 11:51:00 +0200	[thread overview]
Message-ID: <20260505095137.1123867-4-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20260505095137.1123867-1-a.fatoum@pengutronix.de>

bootm can be configured to determine suitable values for a number of
kernel command line options that will automatically be fixed up.

Currently, these options are concatenated into the kernel command line
interleaved with all other options in the lexicographical order of the
linux.bootargs. parameter name.

For the root= option, this means that any root= in a blspec file for
example will override barebox' own root=, because:

  global.linux.bootargs.bootm.root < global.linux.bootargs.dyn.bootentries

The other way makes more sense however, especially as there is always a
device parameter or Kconfig option to control whether the fixup should
happen at all.

With the new order, it's now possible to set global.bootm.appendroot=1
and have barebox append a new root= and have it take precedence over a
bootloader spec provided root=. To reflect that this has occurred, the
kernel command-line will continue to list two root='s, which greatly
simplifies debugging if issues happen (e.g. because there was a
rootfstype that is no longer accurate).

This commit doesn't add any LINUX_BOOTARGS_BOOTM_EARLY as it's not yet
needed. Still it lays out how it could look like in future.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 .../migration-guides/migration-master.rst     |  9 +++++++
 Documentation/user/booting-linux.rst          | 24 +++++++++++++++--
 common/bootm.c                                | 26 ++++++++++++++-----
 3 files changed, 50 insertions(+), 9 deletions(-)

diff --git a/Documentation/migration-guides/migration-master.rst b/Documentation/migration-guides/migration-master.rst
index 5be4659d5b3d..f6d193417f1d 100644
--- a/Documentation/migration-guides/migration-master.rst
+++ b/Documentation/migration-guides/migration-master.rst
@@ -31,3 +31,12 @@ Scripts that **read** the parameter will now receive ``"disabled"`` or
 ``"enabled"`` instead of ``"0"`` or ``"1"``.
 
 Scripts that **write** ``"0"`` or ``"1"`` continue to work.
+
+global.linux.bootargs.* appending order
+---------------------------------------
+
+If barebox was configured to automatically generate any of the ``root``,
+``rootwait``, ``earlycon``, ``systemd.machine_id``, ``systemd.hostname``
+or ``barebox.security.policy`` kernel command line options, they will be
+appended onto the final kernel command line
+:ref:`**after** all other options <bootargs_concat_order>`.
diff --git a/Documentation/user/booting-linux.rst b/Documentation/user/booting-linux.rst
index cc0bdb4661ca..7bbb79ecdfc2 100644
--- a/Documentation/user/booting-linux.rst
+++ b/Documentation/user/booting-linux.rst
@@ -89,14 +89,34 @@ with ``global.linux.bootargs.`` will be concatenated to the bootargs:
 
 .. code-block:: sh
 
+  global linux.bootargs.Loglevel="ignore_loglevel"
   global linux.bootargs.base="console=ttyO0,115200"
-  global linux.bootargs.debug="earlyprintk ignore_loglevel"
+  global linux.bootargs.debug="earlyprintk"
 
   bootm zImage
 
   ...
 
-  Kernel command line: console=ttymxc0,115200n8 earlyprintk ignore_loglevel
+  Kernel command line: ignore_loglevel console=ttyO0,115200 earlyprintk
+
+.. _bootargs_concat_order:
+
+Concatenation order
+"""""""""""""""""""
+
+The kernel command line arguments are concatenated in lexicographical order of
+their ``linux.bootargs.``-prefixed parameter names.
+
+Kernel command line arguments that barebox generates internally are not
+interleaved with externally provided command-line arguments:
+
+* Following arguments will be concatenated **after** all other options:
+  * ``root=`` and ``rootwait=`` controlled by :ref:`global.bootm.appendroot <magicvar_global_bootm_appendroot>`
+    :ref:`global.linux.rootwait <magicvar_global_linux_rootwait>`
+  * ``earlycon=`` controlled by :ref:`global.bootm.earlycon <magicvar_global_bootm_earlycon>`
+  * ``systemd.machine_id=`` controlled by :ref:`global.bootm.provide_machine_id <magicvar_global_bootm_provide_machine_id>`
+  * ``systemd.hostname=`` controlled by :ref:`global.bootm.provide_hostname <magicvar_global_bootm_provide_hostname>`
+  * ``barebox.security.policy=`` controlled by :ref:`global.bootm.provide_policy <magicvar_global_bootm_provide_policy>`
 
 Creating root= options for the Kernel
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/common/bootm.c b/common/bootm.c
index c7bf414effa4..26465875ad94 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -22,6 +22,19 @@
 #include <security/config.h>
 #include <security/policy.h>
 
+/*
+ * All device parameter iteration happens in lexicographical order.
+ * To ensure that bootm options are consistently applied before or after
+ * other options from the environment or boot configuration files, we
+ * employ following convention for the prefix:
+ *
+ *   !		0x21 is less than any non-space printable character
+ *   ~		0x7e is greater than any printable character
+ *
+ * Users will never see those as bootm_boot_cleanup() will delete them again.
+ */
+#define LINUX_BOOTARGS_BOOTM_LATE	"linux.bootargs.~bootm."
+
 static LIST_HEAD(handler_list);
 static struct sconfig_notifier_block sconfig_notifier;
 
@@ -650,7 +663,7 @@ struct image_data *bootm_boot_prep(const struct bootm_data *bootm_data)
 
 			rootarg = format_root_bootarg(bootm_data->root_param, root, rootopts);
 			pr_info("Adding \"%s\" to Kernel commandline\n", rootarg);
-			globalvar_add_simple("linux.bootargs.bootm.appendroot",
+			globalvar_add_simple(LINUX_BOOTARGS_BOOTM_LATE "appendroot",
 					     rootarg);
 			free(rootarg);
 		}
@@ -672,7 +685,7 @@ struct image_data *bootm_boot_prep(const struct bootm_data *bootm_data)
 			earlycon = "earlycon";
 
 		pr_info("Adding \"%s\" to Kernel commandline\n", earlycon);
-		globalvar_add_simple("linux.bootargs.bootm.earlycon", earlycon);
+		globalvar_add_simple(LINUX_BOOTARGS_BOOTM_LATE "earlycon", earlycon);
 	}
 
 	if (bootm_data->provide_machine_id) {
@@ -686,7 +699,7 @@ struct image_data *bootm_boot_prep(const struct bootm_data *bootm_data)
 		}
 
 		machine_id_bootarg = basprintf("systemd.machine_id=%s", machine_id);
-		globalvar_add_simple("linux.bootargs.machine_id", machine_id_bootarg);
+		globalvar_add_simple(LINUX_BOOTARGS_BOOTM_LATE "machine_id", machine_id_bootarg);
 		free(machine_id_bootarg);
 	}
 
@@ -714,7 +727,7 @@ struct image_data *bootm_boot_prep(const struct bootm_data *bootm_data)
 					     hostname, suffix ? "-" : "",
 					     suffix ?: "");
 
-		globalvar_add_simple("linux.bootargs.hostname", hostname_bootarg);
+		globalvar_add_simple(LINUX_BOOTARGS_BOOTM_LATE "hostname", hostname_bootarg);
 		free(hostname_bootarg);
 	}
 
@@ -729,7 +742,7 @@ struct image_data *bootm_boot_prep(const struct bootm_data *bootm_data)
 		}
 
 		policy_bootargs = basprintf("barebox.security.policy=%s", active_policy->name);
-		globalvar_add_simple("linux.bootargs.dyn.policy", policy_bootargs);
+		globalvar_add_simple(LINUX_BOOTARGS_BOOTM_LATE "policy", policy_bootargs);
 		free(policy_bootargs);
 	}
 
@@ -792,8 +805,7 @@ void bootm_boot_cleanup(struct image_data *data)
 	if (data->of_root_node)
 		of_delete_node(data->of_root_node);
 
-	globalvar_remove("linux.bootargs.bootm.earlycon");
-	globalvar_remove("linux.bootargs.bootm.appendroot");
+	globalvar_remove(LINUX_BOOTARGS_BOOTM_LATE  "*");
 	free(data->os_header);
 	free(data->os_file);
 	free(data->oftree_file);
-- 
2.47.3




  parent reply	other threads:[~2026-05-05  9:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-05  9:50 [PATCH 0/3] " Ahmad Fatoum
2026-05-05  9:50 ` [PATCH 1/3] common: fix help text reference to internal imagicvars Ahmad Fatoum
2026-05-05  9:50 ` [PATCH 2/3] Documentation: user: booting-linux: split off mtdparts fixup section Ahmad Fatoum
2026-05-05  9:51 ` Ahmad Fatoum [this message]
2026-05-05 12:45   ` [PATCH 3/3] bootm: append automatic parameters after all other linux.bootargs Alexander Shiyan
2026-05-07 11:17   ` (subset) " Sascha Hauer

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=20260505095137.1123867-4-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=eagle.alexander923@gmail.com \
    /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