* [PATCH 1/2] globalvar: propagate dev_set_param return value from globalvar_set @ 2026-03-12 14:43 Ahmad Fatoum 2026-03-12 14:43 ` [PATCH 2/2] globalvar: add helpers for stashing global variables Ahmad Fatoum 0 siblings, 1 reply; 4+ messages in thread From: Ahmad Fatoum @ 2026-03-12 14:43 UTC (permalink / raw) To: barebox; +Cc: Ahmad Fatoum dev_set_param() already returns an error code, which can be useful for non-simple globalvars. Propagate it out of globalvar_set as well. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> --- common/globalvar.c | 4 ++-- include/globalvar.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common/globalvar.c b/common/globalvar.c index 876379b2538e..c2b0d5b4bbad 100644 --- a/common/globalvar.c +++ b/common/globalvar.c @@ -456,9 +456,9 @@ void globalvar_set_match(const char *match, const char *val) } } -void globalvar_set(const char *name, const char *val) +int globalvar_set(const char *name, const char *val) { - dev_set_param(&global_device, name, val); + return dev_set_param(&global_device, name, val); } static int globalvar_simple_set(struct bobject *bobj, struct param_d *p, diff --git a/include/globalvar.h b/include/globalvar.h index e369616c632a..413cf72002a0 100644 --- a/include/globalvar.h +++ b/include/globalvar.h @@ -22,7 +22,7 @@ int globalvar_add_simple(const char *name, const char *value); void globalvar_remove(const char *name); char *globalvar_get_match(const char *match, const char *separator); void globalvar_set_match(const char *match, const char *val); -void globalvar_set(const char *name, const char *val); +int globalvar_set(const char *name, const char *val); int globalvar_add_simple_string(const char *name, char **value); int globalvar_add_simple_int(const char *name, int *value, @@ -124,7 +124,7 @@ static inline char *globalvar_get_match(const char *match, const char *separator static inline void globalvar_set_match(const char *match, const char *val) {} -static inline void globalvar_set(const char *name, const char *val) {} +static inline int globalvar_set(const char *name, const char *val) { return 0; } static inline int nvvar_load(void) { -- 2.47.3 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] globalvar: add helpers for stashing global variables 2026-03-12 14:43 [PATCH 1/2] globalvar: propagate dev_set_param return value from globalvar_set Ahmad Fatoum @ 2026-03-12 14:43 ` Ahmad Fatoum 2026-03-18 8:12 ` Sascha Hauer 0 siblings, 1 reply; 4+ messages in thread From: Ahmad Fatoum @ 2026-03-12 14:43 UTC (permalink / raw) To: barebox; +Cc: Ahmad Fatoum Configuring a FIT image boot with overlays involves setting not only global.bootm.* variables, but also global.of.overlay.* variables. For use in custom boot entry functions, provide functions for stashing and restoring a set of variables. This allows dry run and boot fallback behavior to not affect later boot attempts. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> --- common/globalvar.c | 77 +++++++++++++++++++++++++++++++++++++++++++++ include/globalvar.h | 3 ++ 2 files changed, 80 insertions(+) diff --git a/common/globalvar.c b/common/globalvar.c index c2b0d5b4bbad..e168d6055347 100644 --- a/common/globalvar.c +++ b/common/globalvar.c @@ -461,6 +461,83 @@ int globalvar_set(const char *name, const char *val) return dev_set_param(&global_device, name, val); } +struct globalvar_stashed { + const char *key; + const char *value; + struct list_head list; +}; + +static void globalvar_stashed_free(struct globalvar_stashed *elem) +{ + list_del(&elem->list); + free_const(elem->key); + free_const(elem->value); + free(elem); +} + +int globalvar_stash_push(struct list_head *stash, ...) +{ + struct globalvar_stashed *elem, *safe; + const char *name; + int ret = -ENOMEM; + va_list args; + LIST_HEAD(tmp); + + va_start(args, stash); + + while ((name = va_arg(args, const char *))) { + const char *value; + + elem = calloc(1, sizeof(*elem)); + if (!elem) + goto out; + + list_add_tail(&elem->list, &tmp); + + elem->key = strdup_const(name); + if (!elem->key) + goto out; + + value = globalvar_get(name); + if (!value) { + ret = -EINVAL; + goto out; + } + + elem->value = strdup_const(value); + if (!elem->value) + goto out; + } + + list_splice_tail(&tmp, stash); + + ret = 0; +out: + va_end(args); + + if (ret) { + list_for_each_entry_safe(elem, safe, &tmp, list) + globalvar_stashed_free(elem); + } + + return ret; +} + +int globalvar_stash_pop(struct list_head *stash) +{ + struct globalvar_stashed *elem, *tmp; + int err = 0; + + list_for_each_entry_safe(elem, tmp, stash, list) { + int ret = globalvar_set(elem->key, elem->value); + if (ret) + err = ret; + globalvar_stashed_free(elem); + } + + return err; +} + static int globalvar_simple_set(struct bobject *bobj, struct param_d *p, const char *val) { diff --git a/include/globalvar.h b/include/globalvar.h index 413cf72002a0..1d39849ddbab 100644 --- a/include/globalvar.h +++ b/include/globalvar.h @@ -24,6 +24,9 @@ char *globalvar_get_match(const char *match, const char *separator); void globalvar_set_match(const char *match, const char *val); int globalvar_set(const char *name, const char *val); +int globalvar_stash_push(struct list_head *stash, ...) __attribute__((sentinel)); +int globalvar_stash_pop(struct list_head *stash); + int globalvar_add_simple_string(const char *name, char **value); int globalvar_add_simple_int(const char *name, int *value, const char *format); -- 2.47.3 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] globalvar: add helpers for stashing global variables 2026-03-12 14:43 ` [PATCH 2/2] globalvar: add helpers for stashing global variables Ahmad Fatoum @ 2026-03-18 8:12 ` Sascha Hauer 2026-03-18 9:22 ` Ahmad Fatoum 0 siblings, 1 reply; 4+ messages in thread From: Sascha Hauer @ 2026-03-18 8:12 UTC (permalink / raw) To: Ahmad Fatoum; +Cc: barebox On Thu, Mar 12, 2026 at 03:43:16PM +0100, Ahmad Fatoum wrote: > Configuring a FIT image boot with overlays involves setting not only > global.bootm.* variables, but also global.of.overlay.* variables. > > For use in custom boot entry functions, provide functions for stashing > and restoring a set of variables. This allows dry run and boot fallback > behavior to not affect later boot attempts. Looks generally good. I assume this is to replace the .dyn. type variables, right? Can we the a user before applying this? Sascha > > Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> > --- > common/globalvar.c | 77 +++++++++++++++++++++++++++++++++++++++++++++ > include/globalvar.h | 3 ++ > 2 files changed, 80 insertions(+) > > diff --git a/common/globalvar.c b/common/globalvar.c > index c2b0d5b4bbad..e168d6055347 100644 > --- a/common/globalvar.c > +++ b/common/globalvar.c > @@ -461,6 +461,83 @@ int globalvar_set(const char *name, const char *val) > return dev_set_param(&global_device, name, val); > } > > +struct globalvar_stashed { > + const char *key; > + const char *value; > + struct list_head list; > +}; > + > +static void globalvar_stashed_free(struct globalvar_stashed *elem) > +{ > + list_del(&elem->list); > + free_const(elem->key); > + free_const(elem->value); > + free(elem); > +} > + > +int globalvar_stash_push(struct list_head *stash, ...) > +{ > + struct globalvar_stashed *elem, *safe; > + const char *name; > + int ret = -ENOMEM; > + va_list args; > + LIST_HEAD(tmp); > + > + va_start(args, stash); > + > + while ((name = va_arg(args, const char *))) { > + const char *value; > + > + elem = calloc(1, sizeof(*elem)); > + if (!elem) > + goto out; > + > + list_add_tail(&elem->list, &tmp); > + > + elem->key = strdup_const(name); > + if (!elem->key) > + goto out; > + > + value = globalvar_get(name); > + if (!value) { > + ret = -EINVAL; > + goto out; > + } > + > + elem->value = strdup_const(value); > + if (!elem->value) > + goto out; > + } > + > + list_splice_tail(&tmp, stash); > + > + ret = 0; > +out: > + va_end(args); > + > + if (ret) { > + list_for_each_entry_safe(elem, safe, &tmp, list) > + globalvar_stashed_free(elem); > + } > + > + return ret; > +} > + > +int globalvar_stash_pop(struct list_head *stash) > +{ > + struct globalvar_stashed *elem, *tmp; > + int err = 0; > + > + list_for_each_entry_safe(elem, tmp, stash, list) { > + int ret = globalvar_set(elem->key, elem->value); > + if (ret) > + err = ret; > + globalvar_stashed_free(elem); > + } > + > + return err; > +} > + > static int globalvar_simple_set(struct bobject *bobj, struct param_d *p, > const char *val) > { > diff --git a/include/globalvar.h b/include/globalvar.h > index 413cf72002a0..1d39849ddbab 100644 > --- a/include/globalvar.h > +++ b/include/globalvar.h > @@ -24,6 +24,9 @@ char *globalvar_get_match(const char *match, const char *separator); > void globalvar_set_match(const char *match, const char *val); > int globalvar_set(const char *name, const char *val); > > +int globalvar_stash_push(struct list_head *stash, ...) __attribute__((sentinel)); > +int globalvar_stash_pop(struct list_head *stash); > + > int globalvar_add_simple_string(const char *name, char **value); > int globalvar_add_simple_int(const char *name, int *value, > const char *format); > -- > 2.47.3 > > > -- 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 | ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] globalvar: add helpers for stashing global variables 2026-03-18 8:12 ` Sascha Hauer @ 2026-03-18 9:22 ` Ahmad Fatoum 0 siblings, 0 replies; 4+ messages in thread From: Ahmad Fatoum @ 2026-03-18 9:22 UTC (permalink / raw) To: Sascha Hauer; +Cc: barebox Hello Sascha, On 3/18/26 09:12, Sascha Hauer wrote: > On Thu, Mar 12, 2026 at 03:43:16PM +0100, Ahmad Fatoum wrote: >> Configuring a FIT image boot with overlays involves setting not only >> global.bootm.* variables, but also global.of.overlay.* variables. >> >> For use in custom boot entry functions, provide functions for stashing >> and restoring a set of variables. This allows dry run and boot fallback >> behavior to not affect later boot attempts. > > Looks generally good. I assume this is to replace the .dyn. type > variables, right? Not on its own, because there is no means to use this from scripts. For the .dyn. case I was thinking about a locally scope bootm bobject that can be modified in the boot script and then discarded afterwards. > Can we the a user before applying this? The single user on my side is out-of-tree board code that uses it scope use of global.of.overlay.filter Here's an excerpt: LIST_HEAD(stash); globalvar_stash_push(stash, "of.overlay.pattern", "of.overlay.filter", "of.overlay.path", NULL); globalvar_set("of.overlay.path", kernel); globalvar_set("of.overlay.filter", "pattern"); globalvar_set("of.overlay.pattern", pattern); ret = bootm_entry(entry, &bootm_data); globalvar_stash_pop(&stash); Thanks, Ahmad > > Sascha > >> >> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> >> --- >> common/globalvar.c | 77 +++++++++++++++++++++++++++++++++++++++++++++ >> include/globalvar.h | 3 ++ >> 2 files changed, 80 insertions(+) >> >> diff --git a/common/globalvar.c b/common/globalvar.c >> index c2b0d5b4bbad..e168d6055347 100644 >> --- a/common/globalvar.c >> +++ b/common/globalvar.c >> @@ -461,6 +461,83 @@ int globalvar_set(const char *name, const char *val) >> return dev_set_param(&global_device, name, val); >> } >> >> +struct globalvar_stashed { >> + const char *key; >> + const char *value; >> + struct list_head list; >> +}; >> + >> +static void globalvar_stashed_free(struct globalvar_stashed *elem) >> +{ >> + list_del(&elem->list); >> + free_const(elem->key); >> + free_const(elem->value); >> + free(elem); >> +} >> + >> +int globalvar_stash_push(struct list_head *stash, ...) >> +{ >> + struct globalvar_stashed *elem, *safe; >> + const char *name; >> + int ret = -ENOMEM; >> + va_list args; >> + LIST_HEAD(tmp); >> + >> + va_start(args, stash); >> + >> + while ((name = va_arg(args, const char *))) { >> + const char *value; >> + >> + elem = calloc(1, sizeof(*elem)); >> + if (!elem) >> + goto out; >> + >> + list_add_tail(&elem->list, &tmp); >> + >> + elem->key = strdup_const(name); >> + if (!elem->key) >> + goto out; >> + >> + value = globalvar_get(name); >> + if (!value) { >> + ret = -EINVAL; >> + goto out; >> + } >> + >> + elem->value = strdup_const(value); >> + if (!elem->value) >> + goto out; >> + } >> + >> + list_splice_tail(&tmp, stash); >> + >> + ret = 0; >> +out: >> + va_end(args); >> + >> + if (ret) { >> + list_for_each_entry_safe(elem, safe, &tmp, list) >> + globalvar_stashed_free(elem); >> + } >> + >> + return ret; >> +} >> + >> +int globalvar_stash_pop(struct list_head *stash) >> +{ >> + struct globalvar_stashed *elem, *tmp; >> + int err = 0; >> + >> + list_for_each_entry_safe(elem, tmp, stash, list) { >> + int ret = globalvar_set(elem->key, elem->value); >> + if (ret) >> + err = ret; >> + globalvar_stashed_free(elem); >> + } >> + >> + return err; >> +} >> + >> static int globalvar_simple_set(struct bobject *bobj, struct param_d *p, >> const char *val) >> { >> diff --git a/include/globalvar.h b/include/globalvar.h >> index 413cf72002a0..1d39849ddbab 100644 >> --- a/include/globalvar.h >> +++ b/include/globalvar.h >> @@ -24,6 +24,9 @@ char *globalvar_get_match(const char *match, const char *separator); >> void globalvar_set_match(const char *match, const char *val); >> int globalvar_set(const char *name, const char *val); >> >> +int globalvar_stash_push(struct list_head *stash, ...) __attribute__((sentinel)); >> +int globalvar_stash_pop(struct list_head *stash); >> + >> int globalvar_add_simple_string(const char *name, char **value); >> int globalvar_add_simple_int(const char *name, int *value, >> const char *format); >> -- >> 2.47.3 >> >> >> > -- 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 | ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-03-18 9:22 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-03-12 14:43 [PATCH 1/2] globalvar: propagate dev_set_param return value from globalvar_set Ahmad Fatoum 2026-03-12 14:43 ` [PATCH 2/2] globalvar: add helpers for stashing global variables Ahmad Fatoum 2026-03-18 8:12 ` Sascha Hauer 2026-03-18 9:22 ` Ahmad Fatoum
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox