mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2 1/2] of: fix up /chosen node even when there are no bootargs
@ 2021-04-14 13:00 Bastian Krause
  2021-04-14 13:00 ` [PATCH v2 2/2] of: introduce global.linux.bootargs_append Bastian Krause
  2021-05-25  8:53 ` [PATCH v2 1/2] of: fix up /chosen node even when there are no bootargs Bastian Krause
  0 siblings, 2 replies; 5+ messages in thread
From: Bastian Krause @ 2021-04-14 13:00 UTC (permalink / raw)
  To: barebox; +Cc: a.fatoum, Bastian Krause

From: Ahmad Fatoum <a.fatoum@pengutronix.de>

Currently the /chosen fixups of "reset-source",
"reset-source-instance", "reset-source-device" and "bootsource" do not
happen if no bootargs are available.

Fix that by moving the actual bootargs fixup to a dedicated function
of_write_bootargs() and only return there early on empty bootargs, but
still perform the /chosen fixups mentioned above.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
[bst: dropped new line deletions and modified string comparison, moved of_write_bootargs() call to original position, add commit message]
Signed-off-by: Bastian Krause <bst@pengutronix.de>
---
No changes since (implicit) v1.
---
 common/oftree.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/common/oftree.c b/common/oftree.c
index 075b9d6b8b..a8e6587a61 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -161,16 +161,12 @@ static void watchdog_build_bootargs(struct watchdog *watchdog, struct device_nod
 	free(buf);
 }
 
-static int of_fixup_bootargs(struct device_node *root, void *unused)
+static int of_write_bootargs(struct device_node *node)
 {
-	struct device_node *node;
 	const char *str;
-	int err;
-	int instance = reset_source_get_instance();
-	struct device_d *dev;
 
 	if (IS_ENABLED(CONFIG_SYSTEMD_OF_WATCHDOG))
-		watchdog_build_bootargs(boot_get_enabled_watchdog(), root);
+		watchdog_build_bootargs(boot_get_enabled_watchdog(), of_get_parent(node));
 
 	str = linux_bootargs_get();
 	if (!str)
@@ -180,13 +176,23 @@ static int of_fixup_bootargs(struct device_node *root, void *unused)
 	if (strlen(str) == 0)
 		return 0;
 
+	return of_property_write_string(node, "bootargs", str);
+}
+
+static int of_fixup_bootargs(struct device_node *root, void *unused)
+{
+	struct device_node *node;
+	int err;
+	int instance = reset_source_get_instance();
+	struct device_d *dev;
+
 	node = of_create_node(root, "/chosen");
 	if (!node)
 		return -ENOMEM;
 
 	of_property_write_string(node, "barebox-version", release_string);
 
-	err = of_property_write_string(node, "bootargs", str);
+	err = of_write_bootargs(node);
 	if (err)
 		return err;
 
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] of: introduce global.linux.bootargs_append
  2021-04-14 13:00 [PATCH v2 1/2] of: fix up /chosen node even when there are no bootargs Bastian Krause
@ 2021-04-14 13:00 ` Bastian Krause
  2021-05-25  8:53   ` Bastian Krause
  2021-05-25  8:53 ` [PATCH v2 1/2] of: fix up /chosen node even when there are no bootargs Bastian Krause
  1 sibling, 1 reply; 5+ messages in thread
From: Bastian Krause @ 2021-04-14 13:00 UTC (permalink / raw)
  To: barebox; +Cc: a.fatoum, Bastian Krause

From: Ahmad Fatoum <a.fatoum@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.

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>
---
Changes since (implicit) v1:
- use global.linux.bootargs_append instead of
  global.linux.bootargs_overwrite
- since the meaning is the other way around now, change the default and
  the check in of_write_bootargs()
---
 common/oftree.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/common/oftree.c b/common/oftree.c
index a8e6587a61..ad2eff362d 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);
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/2] of: fix up /chosen node even when there are no bootargs
  2021-04-14 13:00 [PATCH v2 1/2] of: fix up /chosen node even when there are no bootargs Bastian Krause
  2021-04-14 13:00 ` [PATCH v2 2/2] of: introduce global.linux.bootargs_append Bastian Krause
@ 2021-05-25  8:53 ` Bastian Krause
  2021-05-26  5:53   ` Sascha Hauer
  1 sibling, 1 reply; 5+ messages in thread
From: Bastian Krause @ 2021-05-25  8:53 UTC (permalink / raw)
  To: barebox; +Cc: a.fatoum

On 4/14/21 3:00 PM, Bastian Krause wrote:
> From: Ahmad Fatoum <a.fatoum@pengutronix.de>
> 
> Currently the /chosen fixups of "reset-source",
> "reset-source-instance", "reset-source-device" and "bootsource" do not
> happen if no bootargs are available.
> 
> Fix that by moving the actual bootargs fixup to a dedicated function
> of_write_bootargs() and only return there early on empty bootargs, but
> still perform the /chosen fixups mentioned above.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> [bst: dropped new line deletions and modified string comparison, moved of_write_bootargs() call to original position, add commit message]
> Signed-off-by: Bastian Krause <bst@pengutronix.de>
> ---
> No changes since (implicit) v1.
> ---
>  common/oftree.c | 20 +++++++++++++-------
>  1 file changed, 13 insertions(+), 7 deletions(-)

Gentle ping.

> 
> diff --git a/common/oftree.c b/common/oftree.c
> index 075b9d6b8b..a8e6587a61 100644
> --- a/common/oftree.c
> +++ b/common/oftree.c
> @@ -161,16 +161,12 @@ static void watchdog_build_bootargs(struct watchdog *watchdog, struct device_nod
>  	free(buf);
>  }
>  
> -static int of_fixup_bootargs(struct device_node *root, void *unused)
> +static int of_write_bootargs(struct device_node *node)
>  {
> -	struct device_node *node;
>  	const char *str;
> -	int err;
> -	int instance = reset_source_get_instance();
> -	struct device_d *dev;
>  
>  	if (IS_ENABLED(CONFIG_SYSTEMD_OF_WATCHDOG))
> -		watchdog_build_bootargs(boot_get_enabled_watchdog(), root);
> +		watchdog_build_bootargs(boot_get_enabled_watchdog(), of_get_parent(node));
>  
>  	str = linux_bootargs_get();
>  	if (!str)
> @@ -180,13 +176,23 @@ static int of_fixup_bootargs(struct device_node *root, void *unused)
>  	if (strlen(str) == 0)
>  		return 0;
>  
> +	return of_property_write_string(node, "bootargs", str);
> +}
> +
> +static int of_fixup_bootargs(struct device_node *root, void *unused)
> +{
> +	struct device_node *node;
> +	int err;
> +	int instance = reset_source_get_instance();
> +	struct device_d *dev;
> +
>  	node = of_create_node(root, "/chosen");
>  	if (!node)
>  		return -ENOMEM;
>  
>  	of_property_write_string(node, "barebox-version", release_string);
>  
> -	err = of_property_write_string(node, "bootargs", str);
> +	err = of_write_bootargs(node);
>  	if (err)
>  		return err;
>  
> 


-- 
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 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 2/2] of: introduce global.linux.bootargs_append
  2021-04-14 13:00 ` [PATCH v2 2/2] of: introduce global.linux.bootargs_append Bastian Krause
@ 2021-05-25  8:53   ` Bastian Krause
  0 siblings, 0 replies; 5+ messages in thread
From: Bastian Krause @ 2021-05-25  8:53 UTC (permalink / raw)
  To: barebox; +Cc: a.fatoum

On 4/14/21 3:00 PM, Bastian Krause wrote:
> From: Ahmad Fatoum <a.fatoum@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.
> 
> 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>
> ---
> Changes since (implicit) v1:
> - use global.linux.bootargs_append instead of
>   global.linux.bootargs_overwrite
> - since the meaning is the other way around now, change the default and
>   the check in of_write_bootargs()
> ---
>  common/oftree.c | 22 +++++++++++++++++++++-
>  1 file changed, 21 insertions(+), 1 deletion(-)

Gentle ping.

> 
> diff --git a/common/oftree.c b/common/oftree.c
> index a8e6587a61..ad2eff362d 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);
> 


-- 
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 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/2] of: fix up /chosen node even when there are no bootargs
  2021-05-25  8:53 ` [PATCH v2 1/2] of: fix up /chosen node even when there are no bootargs Bastian Krause
@ 2021-05-26  5:53   ` Sascha Hauer
  0 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2021-05-26  5:53 UTC (permalink / raw)
  To: Bastian Krause; +Cc: barebox, a.fatoum

On Tue, May 25, 2021 at 10:53:27AM +0200, Bastian Krause wrote:
> On 4/14/21 3:00 PM, Bastian Krause wrote:
> > From: Ahmad Fatoum <a.fatoum@pengutronix.de>
> > 
> > Currently the /chosen fixups of "reset-source",
> > "reset-source-instance", "reset-source-device" and "bootsource" do not
> > happen if no bootargs are available.
> > 
> > Fix that by moving the actual bootargs fixup to a dedicated function
> > of_write_bootargs() and only return there early on empty bootargs, but
> > still perform the /chosen fixups mentioned above.
> > 
> > Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> > [bst: dropped new line deletions and modified string comparison, moved of_write_bootargs() call to original position, add commit message]
> > Signed-off-by: Bastian Krause <bst@pengutronix.de>
> > ---
> > No changes since (implicit) v1.
> > ---
> >  common/oftree.c | 20 +++++++++++++-------
> >  1 file changed, 13 insertions(+), 7 deletions(-)
> 
> Gentle ping.

Sorry, missed these. Applied now, thanks

Sascha


-- 
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 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-05-26  5:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-14 13:00 [PATCH v2 1/2] of: fix up /chosen node even when there are no bootargs Bastian Krause
2021-04-14 13:00 ` [PATCH v2 2/2] of: introduce global.linux.bootargs_append Bastian Krause
2021-05-25  8:53   ` Bastian Krause
2021-05-25  8:53 ` [PATCH v2 1/2] of: fix up /chosen node even when there are no bootargs Bastian Krause
2021-05-26  5:53   ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox