From: Sascha Hauer <s.hauer@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>
Subject: [PATCH 07/10] of: add watchdog bootarg directly instead of via a globalvar
Date: Fri, 30 Oct 2026 11:54:05 +0100 [thread overview]
Message-ID: <20261030-boot-globalvar-stack-v1-7-a03803e1100c@pengutronix.de> (raw)
In-Reply-To: <20261030-boot-globalvar-stack-v1-0-a03803e1100c@pengutronix.de>
With CONFIG_SYSTEMD_OF_WATCHDOG, the device tree bootargs fixup puts
systemd.watchdog_device= into global.linux.bootargs.dyn.watchdog only to
read it back right away via linux_bootargs_get(). This has side effects
beyond the fixup:
- The variable is created whenever the fixup runs, so also for of_dump
-F, oftree -s or of_diff after a boot attempt has enabled the
watchdog, and stays around afterwards.
- Its mere existence makes linux_bootargs_get() ignore the legacy
bootargs environment variable, which is only used when no
global.linux.bootargs.* variables exist.
Return the option from watchdog_build_bootargs() and append it to the
bootargs in of_write_bootargs() instead. Note this moves the option to
the end of the command line, while it was previously sorted among the
global.linux.bootargs.* variables.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
Documentation/user/booting-linux.rst | 2 ++
common/Kconfig | 6 +++---
common/oftree.c | 41 ++++++++++++++++++++----------------
3 files changed, 28 insertions(+), 21 deletions(-)
diff --git a/Documentation/user/booting-linux.rst b/Documentation/user/booting-linux.rst
index 0fbdc52c68..158aa8b313 100644
--- a/Documentation/user/booting-linux.rst
+++ b/Documentation/user/booting-linux.rst
@@ -124,6 +124,8 @@ interleaved with externally provided command-line arguments:
* ``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>`
+ * ``systemd.watchdog_device=`` controlled by ``CONFIG_SYSTEMD_OF_WATCHDOG``,
+ only when booting with a device tree
Creating root= options for the Kernel
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/common/Kconfig b/common/Kconfig
index 9adecfd2e4..da4cc8a5c9 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -1443,9 +1443,9 @@ config SYSTEMD_OF_WATCHDOG
bool "inform devicetree-enabled kernel of used watchdog"
depends on WATCHDOG && OFTREE && FLEXIBLE_BOOTARGS
help
- Sets the linux.bootargs.dyn.watchdog global variable with a value of
- systemd.watchdog_device=/dev/WDOG if barebox succeeded in enabling
- the watchdog WDOG prior to boot. WDOG is the alias of the watchdog
+ Appends systemd.watchdog_device=/dev/WDOG to the Kernel command line
+ in the device tree if barebox succeeded in enabling the watchdog
+ WDOG prior to boot. WDOG is the alias of the watchdog
in the kernel device tree. If the kernel is booted without a device
tree or with one that lacks aliases, nothing is added.
diff --git a/common/oftree.c b/common/oftree.c
index 7aaed70e40..5f9b2e50cb 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -160,22 +160,18 @@ static int of_fixup_bootargs_reset_source(struct device_node *root,
return of_property_write_string(chosen, "reset-source-device", np->full_name);
}
-static void watchdog_build_bootargs(struct watchdog *watchdog, struct device_node *root)
+static char *watchdog_build_bootargs(struct watchdog *watchdog, struct device_node *root)
{
int alias_id;
- char *buf;
if (!watchdog)
- return;
+ return NULL;
alias_id = watchdog_get_alias_id_from(watchdog, root);
if (alias_id < 0)
- return;
-
- buf = xasprintf("systemd.watchdog_device=/dev/watchdog%d", alias_id);
+ return NULL;
- globalvar_add_simple("linux.bootargs.dyn.watchdog", buf);
- free(buf);
+ return xasprintf("systemd.watchdog_device=/dev/watchdog%d", alias_id);
}
static int bootargs_append = 0;
@@ -183,31 +179,40 @@ BAREBOX_MAGICVAR(global.linux.bootargs_append, "append to original oftree bootar
static int of_write_bootargs(struct device_node *node)
{
- const char *str;
+ const char *str, *oldstr;
+ char *watchdog = NULL;
char *buf = NULL;
int ret;
if (IS_ENABLED(CONFIG_SYSTEMD_OF_WATCHDOG))
- watchdog_build_bootargs(boot_get_enabled_watchdog(), of_get_parent(node));
+ watchdog = watchdog_build_bootargs(boot_get_enabled_watchdog(),
+ of_get_parent(node));
- str = linux_bootargs_get();
- if (!str)
- return 0;
+ str = skip_spaces(linux_bootargs_get() ?: "");
+
+ if (watchdog) {
+ if (*str)
+ str = buf = xasprintf("%s %s", str, watchdog);
+ else
+ str = watchdog;
+ }
- str = skip_spaces(str);
if (strlen(str) == 0)
return 0;
if (bootargs_append) {
- const char *oldstr;
-
ret = of_property_read_string(node, "bootargs", &oldstr);
- if (!ret)
- str = buf = xasprintf("%s %s", oldstr, str);
+ if (!ret) {
+ char *tmp = xasprintf("%s %s", oldstr, str);
+
+ free(buf);
+ str = buf = tmp;
+ }
}
ret = of_property_write_string(node, "bootargs", str);
free(buf);
+ free(watchdog);
return ret;
}
--
2.47.3
next prev parent reply other threads:[~2026-10-30 11:16 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-30 10:53 [PATCH 00/10] boot: revert boot related globalvars after booting Sascha Hauer
2026-10-30 10:53 ` [PATCH 01/10] globalvar: add scopes to snapshot and restore globalvars Sascha Hauer
2026-10-30 10:54 ` [PATCH 02/10] bootm: revert globalvar changes in bootm_boot_cleanup() Sascha Hauer
2026-10-30 10:54 ` [PATCH 03/10] boot: revert globalvar changes after each boot entry Sascha Hauer
2026-10-30 10:54 ` [PATCH 04/10] bootchooser: use a globalvar scope for its bootargs Sascha Hauer
2026-10-30 10:54 ` [PATCH 05/10] test: py: add test for reverting globalvars after boot Sascha Hauer
2026-10-30 10:54 ` [PATCH 06/10] bootargs: remove unused linux_bootargs_overwrite() Sascha Hauer
2026-10-30 10:54 ` Sascha Hauer [this message]
2026-10-30 10:54 ` [PATCH 08/10] boot: drop the dyn infix from the bootentries bootargs variable Sascha Hauer
2026-10-30 10:54 ` [PATCH 09/10] defaultenv: don't use global.linux.bootargs.dyn.* in boot entries Sascha Hauer
2026-10-30 10:54 ` [PATCH 10/10] Documentation: migration-guides: describe reverting boot globalvars 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=20261030-boot-globalvar-stack-v1-7-a03803e1100c@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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