mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
	BAREBOX <barebox@lists.infradead.org>
Subject: Re: [PATCH 02/10] bootm: revert globalvar changes in bootm_boot_cleanup()
Date: Thu, 12 Nov 2026 08:48:16 +0100	[thread overview]
Message-ID: <17320307-410c-46ba-893a-542ca0393ede@pengutronix.de> (raw)
In-Reply-To: <20261030-boot-globalvar-stack-v1-2-a03803e1100c@pengutronix.de>

On 10/30/26 11:54, Sascha Hauer wrote:
> bootm adds the Kernel command line options it generates itself as
> global.linux.bootargs.!bootm.* and global.linux.bootargs.~bootm.*
> variables and removes them again in bootm_boot_cleanup(). Anything else
> bootm or the image handlers change in the global namespace while booting
> stays, for example global.linux.bootargs.dyn.watchdog which is added by
> the devicetree fixups and only cleared again when booting through the
> boot command.
> 
> Add boot_globalvar_scope_push() which snapshots the globalvars that
> configure booting, take a snapshot in bootm_boot_prep() and restore it in
> bootm_boot_cleanup(). This covers the variables bootm removed so far, so
> drop the explicit removal.
> 
> Besides global.bootm.* and global.linux.bootargs.*, the scope covers the
> rest of global.linux.*, like global.linux.bootargs_append, which
> global.linux.bootargs.* doesn't match, or global.linux.rootwait, then
> global.of.*, which includes the global.of.overlay.* variables selecting
> the overlays applied to the Kernel device tree, and
> global.boot.watchdog_timeout.
> 
> It deliberately doesn't cover all globalvars: booting legitimately
> changes others, which must persist. For example DHCP sets
> global.net.server, global.net.gateway and global.hostname, and reverting
> them while the interface stays up would leave the network unusable, as a
> later ifup doesn't run DHCP again.
> 
> Assisted-by: Claude:claude-opus-5-5
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

> ---
>  common/bootm.c  |  6 ++++--
>  include/boot.h  | 16 ++++++++++++++++
>  include/bootm.h |  8 +++++++-
>  3 files changed, 27 insertions(+), 3 deletions(-)
> 
> diff --git a/common/bootm.c b/common/bootm.c
> index bcd557d679..22f2ca4081 100644
> --- a/common/bootm.c
> +++ b/common/bootm.c
> @@ -2,6 +2,7 @@
>  
>  #include <common.h>
>  #include <bootargs.h>
> +#include <boot.h>
>  #include <bootm.h>
>  #include <fs.h>
>  #include <fcntl.h>
> @@ -533,6 +534,8 @@ struct image_data *bootm_boot_prep(const struct bootm_data *bootm_data)
>  
>  	data = xzalloc(sizeof(*data));
>  
> +	data->globalvar_scope = boot_globalvar_scope_push();
> +
>  	bootm_image_name_and_part(bootm_data->os_file, &data->os_file, &data->os_part);
>  	bootm_image_name_and_part(bootm_data->oftree_file, &data->oftree_file, &data->oftree_part);
>  	bootm_image_name_and_part(bootm_data->initrd_file, &data->initrd_file, &data->initrd_part);
> @@ -792,8 +795,7 @@ void bootm_boot_cleanup(struct image_data *data)
>  	if (data->of_root_node)
>  		of_delete_node(data->of_root_node);
>  
> -	globalvar_remove(LINUX_BOOTARGS_BOOTM_EARLY "*");
> -	globalvar_remove(LINUX_BOOTARGS_BOOTM_LATE  "*");
> +	globalvar_scope_pop(data->globalvar_scope);
>  	free(data->os_header);
>  	free(data->os_file);
>  	free(data->oftree_file);
> diff --git a/include/boot.h b/include/boot.h
> index 57f9cb409b..b30cdd314a 100644
> --- a/include/boot.h
> +++ b/include/boot.h
> @@ -7,6 +7,7 @@
>  #include <environment.h>
>  #include <bootm-overrides.h>
>  #include <bootargs.h>
> +#include <globalvar.h>
>  
>  struct bootentries {
>  	struct list_head entries;
> @@ -58,4 +59,19 @@ int boot_entry(struct bootentry *be, int verbose, int dryrun);
>  struct bootm_data;
>  int bootm_entry(struct bootentry *be, const struct bootm_data *data);
>  
> +/*
> + * Snapshot all globalvars that configure booting. Whatever a boot script,
> + * a boot entry or bootm itself changes there is reverted again by
> + * globalvar_scope_pop(), so it doesn't leak into the next boot attempt.
> + *
> + * This deliberately doesn't cover all globalvars: booting may change
> + * others that must persist, e.g. DHCP sets global.net.* and
> + * global.hostname while the interface stays up.
> + */
> +static inline struct globalvar_scope *boot_globalvar_scope_push(void)
> +{
> +	return globalvar_scope_push("bootm.", "linux.", "of.",
> +				    "boot.watchdog_timeout");
> +}
> +
>  #endif /* __BOOT_H */
> diff --git a/include/bootm.h b/include/bootm.h
> index 8e574040f4..bbdbb8e69d 100644
> --- a/include/bootm.h
> +++ b/include/bootm.h
> @@ -16,7 +16,8 @@
>   *   !		0x21 is less than any non-space printable character
>   *   ~		0x7e is greater than any printable character
>   *
> - * Users will never see those as bootm_boot_cleanup() will delete them again.
> + * Users will never see those as bootm_boot_cleanup() reverts the globalvars
> + * to the state before bootm_boot_prep().
>   */
>  #define LINUX_BOOTARGS_BOOTM_EARLY	"linux.bootargs.!bootm."
>  #define LINUX_BOOTARGS_BOOTM_LATE	"linux.bootargs.~bootm."
> @@ -80,7 +81,12 @@ int bootm_open_os_compressed(struct image_data *data);
>  int bootm_boot_handler(struct image_data *data);
>  void bootm_boot_cleanup(struct image_data *data);
>  
> +struct globalvar_scope;
> +
>  struct image_data {
> +	/* globalvars to restore in bootm_boot_cleanup() */
> +	struct globalvar_scope *globalvar_scope;
> +
>  	/* simplest case. barebox has already loaded the os here */
>  	struct resource *os_res;
>  
> 


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



  reply	other threads:[~2026-11-12  7:49 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-30 10:53 [PATCH 00/10] boot: revert boot related globalvars after booting Sascha Hauer
2026-10-30 10:53 ` [PATCH 01/10] globalvar: add scopes to snapshot and restore globalvars Sascha Hauer
2026-11-12  8:41   ` Ahmad Fatoum
2026-11-12 13:25     ` Sascha Hauer
2026-11-12 13:27       ` Ahmad Fatoum
2026-10-30 10:54 ` [PATCH 02/10] bootm: revert globalvar changes in bootm_boot_cleanup() Sascha Hauer
2026-11-12  7:48   ` Ahmad Fatoum [this message]
2026-10-30 10:54 ` [PATCH 03/10] boot: revert globalvar changes after each boot entry Sascha Hauer
2026-11-12  7:48   ` Ahmad Fatoum
2026-10-30 10:54 ` [PATCH 04/10] bootchooser: use a globalvar scope for its bootargs Sascha Hauer
2026-11-12  7:49   ` Ahmad Fatoum
2026-10-30 10:54 ` [PATCH 05/10] test: py: add test for reverting globalvars after boot Sascha Hauer
2026-11-12  7:51   ` Ahmad Fatoum
2026-10-30 10:54 ` [PATCH 06/10] bootargs: remove unused linux_bootargs_overwrite() Sascha Hauer
2026-11-12  7:52   ` Ahmad Fatoum
2026-10-30 10:54 ` [PATCH 07/10] of: add watchdog bootarg directly instead of via a globalvar Sascha Hauer
2026-11-12  7:59   ` Ahmad Fatoum
2026-10-30 10:54 ` [PATCH 08/10] boot: drop the dyn infix from the bootentries bootargs variable Sascha Hauer
2026-11-12  8:02   ` Ahmad Fatoum
2026-11-12 13:07     ` Sascha Hauer
2026-10-30 10:54 ` [PATCH 09/10] defaultenv: don't use global.linux.bootargs.dyn.* in boot entries Sascha Hauer
2026-11-12  8:19   ` Ahmad Fatoum
2026-10-30 10:54 ` [PATCH 10/10] Documentation: migration-guides: describe reverting boot globalvars Sascha Hauer
2026-11-12  8:21   ` Ahmad Fatoum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=17320307-410c-46ba-893a-542ca0393ede@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox