summaryrefslogtreecommitdiffstats
path: root/common/oftree.c
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2021-04-14 15:00:44 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2021-05-26 07:52:50 +0200
commit6596a182cacba78d2f2346a083b1f6d72f707700 (patch)
tree512215bf58e88f0799a27eca56e661ad78990c41 /common/oftree.c
parente56c6a21bc9ef22762c47aacd1bf582a46750c1e (diff)
downloadbarebox-6596a182cacba78d2f2346a083b1f6d72f707700.tar.gz
barebox-6596a182cacba78d2f2346a083b1f6d72f707700.tar.xz
of: introduce global.linux.bootargs_append
By default, barebox overwrites the bootargs in the oftree if it itself has any. Make this behavior configurable by adding a new global variable. The new global variable allows either appending barebox' bootargs to the original oftree bootargs (global.linux.bootargs_append=1) or overwriting the original oftree bootargs (global.linux.bootargs_append=0) as before. The default is to overwrite the original bootargs. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> [bst: dropped a new line removal, extend commit message] Signed-off-by: Bastian Krause <bst@pengutronix.de> Link: https://lore.barebox.org/20210414130044.6910-2-bst@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/oftree.c')
-rw-r--r--common/oftree.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/common/oftree.c b/common/oftree.c
index 8b6d1755ac..5eaa63ad7e 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -16,6 +16,7 @@
#include <reset_source.h>
#include <watchdog.h>
#include <globalvar.h>
+#include <magicvar.h>
#define MAX_LEVEL 32 /* how deeply nested we will go */
@@ -161,9 +162,14 @@ static void watchdog_build_bootargs(struct watchdog *watchdog, struct device_nod
free(buf);
}
+static int bootargs_append = 0;
+BAREBOX_MAGICVAR(global.linux.bootargs_append, "append to original oftree bootargs");
+
static int of_write_bootargs(struct device_node *node)
{
const char *str;
+ char *buf = NULL;
+ int ret;
if (IS_ENABLED(CONFIG_SYSTEMD_OF_WATCHDOG))
watchdog_build_bootargs(boot_get_enabled_watchdog(), of_get_parent(node));
@@ -176,7 +182,20 @@ static int of_write_bootargs(struct device_node *node)
if (strlen(str) == 0)
return 0;
- return of_property_write_string(node, "bootargs", str);
+ if (bootargs_append) {
+ const char *oldstr;
+
+ ret = of_property_read_string(node, "bootargs", &oldstr);
+ if (!ret) {
+ str = buf = basprintf("%s %s", oldstr, str);
+ if (!buf)
+ return -ENOMEM;
+ }
+ }
+
+ ret = of_property_write_string(node, "bootargs", str);
+ free(buf);
+ return ret;
}
static int of_fixup_bootargs(struct device_node *root, void *unused)
@@ -218,6 +237,7 @@ static int of_fixup_bootargs(struct device_node *root, void *unused)
static int of_register_bootargs_fixup(void)
{
+ globalvar_add_simple_bool("linux.bootargs_append", &bootargs_append);
return of_register_fixup(of_fixup_bootargs, NULL);
}
late_initcall(of_register_bootargs_fixup);