of: fix up /chosen node even when there are no bootargs
PATCH 1/2 of: fix up /chosen node even when there are no bootargs
From: Ahmad Fatoum <[email protected]>
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.
--- common/oftree.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
common/oftree.c +13 -7
@@ -161,16 +161,12 @@ static void watchdog_build_bootargs(struct watchdog *watchdog, struct device_nodfree (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;
Signature · 7 lines
2.29.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 2/2 of: introduce global.linux.bootargs_overwrite
From: Ahmad Fatoum <[email protected]>
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).
--- common/oftree.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
common/oftree.c +21 -1
@@ -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_nodfree (buf); } +static int bootargs_overwrite =1 ; +BAREBOX_MAGICVAR (global.linux.bootargs_overwrite,"overwrite 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_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);
Signature · 7 lines
2.29.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 2/2] of: introduce global.linux.bootargs_overwrite
Quoted 28 lines · Bastian Krause
From: Ahmad Fatoum <[email protected]>
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 <[email protected]>[bst: dropped a new line removal, extend commit message]Signed-off-by Bastian Krause <[email protected]>--- common/oftree.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)common/oftree.c +1
-0@@ -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 */
common/oftree.c static void watchdog_build_bootargs(struct watchdog *watchdog, struct device_nod · line 166
Quoted 5 lines
common/oftree.c +2
-0@@ -161,9 +162,14 @@ static void watchdog_build_bootargs(struct watchdog *watchdog, struct device_nodfree (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
Quoted 48 lines
common/oftree.c +18
-1+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);Signature · 7 lines
2.29.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
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 [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 2/2] of: introduce global.linux.bootargs_overwrite
Quoted 32 lines · Sascha Hauer
Quoted 31 lines · Bastian Krause
From: Ahmad Fatoum <[email protected]>
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 <[email protected]>[bst: dropped a new line removal, extend commit message]Signed-off-by Bastian Krause <[email protected]>--- common/oftree.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)common/oftree.c +1
-0@@ -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_nodfree (buf); }
Quoted 7 lines
common/oftree.c static void watchdog_build_bootargs(struct watchdog *watchdog, struct device_nod · line 166
Quoted 2 lines
common/oftree.c +2
-0+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.
That's fine with me.
Can you change that or should I send a v2?
Bastian
Quoted 50 lines
Quoted 49 lines
common/oftree.c +18
-1+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);Signature · 7 lines
2.29.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
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 [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 2/2] of: introduce global.linux.bootargs_overwrite
Quoted 41 lines · Bastian Krause
Quoted 32 lines · Sascha Hauer
Quoted 31 lines · Bastian Krause
From: Ahmad Fatoum <[email protected]>
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 <[email protected]>[bst: dropped a new line removal, extend commit message]Signed-off-by Bastian Krause <[email protected]>--- common/oftree.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)common/oftree.c +1
-0@@ -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_nodfree (buf); }Quoted 7 lines
common/oftree.c static void watchdog_build_bootargs(struct watchdog *watchdog, struct device_nod · line 166
Quoted 2 lines
common/oftree.c +2
-0+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.
Quoted 3 lines
That's fine with me.
Can you change that or should I send a v2?
Please send a v2
Thanks
Sascha
Signature · 9 lines
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 [email protected] http://lists.infradead.org/mailman/listinfo/barebox