mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 5/7] bootm: don't clobber global.bootm. variables after script boot fails
Date: Fri, 14 Feb 2025 11:48:15 +0100	[thread overview]
Message-ID: <20250214104817.2975052-6-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20250214104817.2975052-1-a.fatoum@pengutronix.de>

While there is global.linux.bootargs.dyn to avoid boot script variables
contaminating later boot targets, there is no such thing for the
global.bootm. variables and as such it was up to the boot targets to
either ignore the variables or to override them.

The proper way would to expect the boot script boot callback to restore
the variables as they were before, so let's do that.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/boot.c   | 11 ++++++++---
 common/bootm.c  | 17 +++++++++++++++++
 include/bootm.h |  1 +
 3 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/common/boot.c b/common/boot.c
index 42818c6e2154..2530a5bbeeac 100644
--- a/common/boot.c
+++ b/common/boot.c
@@ -74,20 +74,22 @@ static int bootscript_boot(struct bootentry *entry, int verbose, int dryrun)
 	struct bootentry_script *bs = container_of(entry, struct bootentry_script, entry);
 	int ret;
 
-	struct bootm_data data = {};
+	struct bootm_data backup = {}, data = {};
 
 	if (dryrun == 1) {
 		printf("Would run %s\n", bs->scriptpath);
 		return 0;
 	}
 
+	bootm_data_init_defaults(&backup);
+
 	globalvar_add_simple("linux.bootargs.dyn.ip", NULL);
 	globalvar_add_simple("linux.bootargs.dyn.root", NULL);
 
 	ret = run_command(bs->scriptpath);
 	if (ret) {
 		pr_err("Running script '%s' failed: %s\n", bs->scriptpath, strerror(-ret));
-		return ret;
+		goto out;
 	}
 
 	bootm_data_init_defaults(&data);
@@ -97,7 +99,10 @@ static int bootscript_boot(struct bootentry *entry, int verbose, int dryrun)
 	if (dryrun >= 2)
 		data.dryrun = dryrun - 1;
 
-	return bootm_boot(&data);
+	ret = bootm_boot(&data);
+out:
+	bootm_data_restore_defaults(&backup);
+	return ret;
 }
 
 static unsigned int boot_watchdog_timeout;
diff --git a/common/bootm.c b/common/bootm.c
index d1dbf6890f6f..d24b18b41cb2 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -68,6 +68,23 @@ void bootm_data_init_defaults(struct bootm_data *data)
 	data->dryrun = bootm_dryrun;
 }
 
+void bootm_data_restore_defaults(const struct bootm_data *data)
+{
+	globalvar_set("bootm.oftree", data->oftree_file);
+	globalvar_set("bootm.tee", data->tee_file);
+	globalvar_set("bootm.image", data->os_file);
+	pr_setenv("global.bootm.image.loadaddr", "0x%lx", data->os_address);
+	pr_setenv("global.bootm.initrd.loadaddr", "0x%lx", data->initrd_address);
+	globalvar_set("bootm.initrd", data->initrd_file);
+	globalvar_set("bootm.root_dev", data->root_dev);
+	bootm_set_verify_mode(data->verify);
+	bootm_appendroot = data->appendroot;
+	bootm_provide_machine_id = data->provide_machine_id;
+	bootm_provide_hostname = data->provide_hostname;
+	bootm_verbosity = data->verbose;
+	bootm_dryrun = data->dryrun;
+}
+
 static enum bootm_verify bootm_verify_mode = BOOTM_VERIFY_HASH;
 
 enum bootm_verify bootm_get_verify_mode(void)
diff --git a/include/bootm.h b/include/bootm.h
index 98ac5e5a9374..fdec137771f0 100644
--- a/include/bootm.h
+++ b/include/bootm.h
@@ -138,6 +138,7 @@ static inline int bootm_verbose(struct image_data *data)
 #endif
 
 void bootm_data_init_defaults(struct bootm_data *data);
+void bootm_data_restore_defaults(const struct bootm_data *data);
 
 int bootm_load_os(struct image_data *data, unsigned long load_address);
 
-- 
2.39.5




  parent reply	other threads:[~2025-02-14 10:49 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-14 10:48 [PATCH 0/7] commands: boot: add support for overriding boot artifacts Ahmad Fatoum
2025-02-14 10:48 ` [PATCH 1/7] bootm: add helper functions for checking if FIT image is used Ahmad Fatoum
2025-02-14 10:48 ` [PATCH 2/7] boot: move global.linux.bootargs.dyn. to common code Ahmad Fatoum
2025-02-14 10:48 ` [PATCH 3/7] blspec: don't clobber bootm.image on boot attempt Ahmad Fatoum
2025-02-14 10:48 ` [PATCH 4/7] fastboot: drop useless bootm.image clobber Ahmad Fatoum
2025-02-14 10:48 ` Ahmad Fatoum [this message]
2025-02-14 10:48 ` [PATCH 6/7] bootm: retire bootm_has_initrd Ahmad Fatoum
2025-02-14 20:02   ` [PATCH] fixup! " Ahmad Fatoum
2025-02-14 10:48 ` [PATCH 7/7] commands: boot: add support for overriding boot artifacts Ahmad Fatoum
2025-02-15 12:29   ` [PATCH] fixup! " Ahmad Fatoum
2025-02-17  9:27 ` [PATCH 0/7] " Sascha Hauer

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=20250214104817.2975052-6-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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