[PATCH 2/2] of: introduce global.linux.bootargs_overwrite

Sascha Hauer sha at pengutronix.de
Tue Apr 13 06:16:13 BST 2021


On Fri, Apr 09, 2021 at 10:15:03AM +0200, Bastian Krause wrote:
> From: Ahmad Fatoum <a.fatoum at pengutronix.de>
> 
> By default, barebox overwrites the bootargs in the oftree if it itself
> has any. Make this behavior configurable by adding a new global
> variable. It allows either overwriting the oftree bootargs
> (global.linux.bootargs_overwrite=1) or appending barebox' bootargs to
> the oftree bootargs (global.linux.bootargs_overwrite=0).
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> [bst: dropped a new line removal, extend commit message]
> Signed-off-by: Bastian Krause <bst at pengutronix.de>
> ---
>  common/oftree.c | 22 +++++++++++++++++++++-
>  1 file changed, 21 insertions(+), 1 deletion(-)
> 
> diff --git a/common/oftree.c b/common/oftree.c
> index aaeb199a9e..f3a5d9c5d1 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_overwrite = 1;
> +BAREBOX_MAGICVAR(global.linux.bootargs_overwrite, "overwrite original oftree bootargs");

How about naming it global.linux.bootargs_append instead? It would make
it more clear that we are deviating from the default by setting the
variable to true.

Sascha

> +
>  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_overwrite) {
> +		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_overwrite", &bootargs_overwrite);
>  	return of_register_fixup(of_fixup_bootargs, NULL);
>  }
>  late_initcall(of_register_bootargs_fixup);
> -- 
> 2.29.2
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list