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 03/16] boot: add bootm_boot wrapper that takes struct bootentry
Date: Thu, 12 Mar 2026 15:44:46 +0100	[thread overview]
Message-ID: <20260312144505.2159816-3-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20260312144505.2159816-1-a.fatoum@pengutronix.de>

struct bootentry holds the overrides given to the boot command, but it's
not plumbed through to the end leading to storage of the overrides in
global variables, which is error prone with respect to nested bootm
handlers.

In preparation for passing the overrides via arguments throughout,
introduce the bootm_entry and switch users over to it.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/arm/boards/protonic-imx6/board.c |  2 +-
 common/blspec.c                       |  2 +-
 common/boot.c                         | 37 ++++++++++++++++++++++-----
 efi/loader/bootesp.c                  |  2 +-
 include/boot.h                        |  3 +++
 5 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
index c15a349c8a88..3bb2632693e5 100644
--- a/arch/arm/boards/protonic-imx6/board.c
+++ b/arch/arm/boards/protonic-imx6/board.c
@@ -406,7 +406,7 @@ static int prt_imx6_usb_boot(struct bootentry *entry, int verbose, int dryrun)
 	if (dryrun)
 		bootm_data.dryrun = dryrun;
 
-	ret = bootm_boot(&bootm_data);
+	ret = bootm_entry(entry, &bootm_data);
 	if (ret)
 		goto exit_usb_boot;
 
diff --git a/common/blspec.c b/common/blspec.c
index c07e3a2d672d..ef7490085c7f 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -156,7 +156,7 @@ static int blspec_boot(struct bootentry *be, int verbose, int dryrun)
 	firmware_set_searchpath(fws);
 	free(fws);
 
-	ret = bootm_boot(&data);
+	ret = bootm_entry(be, &data);
 	if (ret)
 		pr_err("Booting failed\n");
 
diff --git a/common/boot.c b/common/boot.c
index 0fa2022be1ac..b5a4205cd9e2 100644
--- a/common/boot.c
+++ b/common/boot.c
@@ -124,7 +124,7 @@ static int bootscript_boot(struct bootentry *entry, int verbose, int dryrun)
 	if (dryrun >= 2)
 		data.dryrun = dryrun - 1;
 
-	ret = bootm_boot(&data);
+	ret = bootm_entry(entry, &data);
 out:
 	bootm_data_restore_defaults(&backup);
 	return ret;
@@ -182,7 +182,6 @@ BAREBOX_MAGICVAR(global.boot.watchdog_timeout,
 
 int boot_entry(struct bootentry *be, int verbose, int dryrun)
 {
-	struct bootm_overrides old;
 	int ret;
 
 	pr_info("Booting entry '%s'\n", be->title);
@@ -197,14 +196,10 @@ int boot_entry(struct bootentry *be, int verbose, int dryrun)
 		}
 	}
 
-	old = bootm_save_overrides(be->overrides);
-
 	ret = be->boot(be, verbose, dryrun);
 	if (ret && ret != -ENOMEDIUM)
 		pr_err("Booting entry '%s' failed: %pe\n", be->title, ERR_PTR(ret));
 
-	bootm_restore_overrides(old);
-
 	globalvar_set_match("linux.bootargs.dyn.", "");
 
 	return ret;
@@ -555,3 +550,33 @@ void bootsources_list(struct bootentries *bootentries)
 }
 
 BAREBOX_MAGICVAR(global.boot.default, "default boot order");
+
+/**
+ * bootm_entry - invoke bootm while taking care of overrides
+ * @be: bootentry
+ * @bootm_data: prepopulated bootm data for bootm_boot()
+ *
+ * Compared to bootm_boot(), this takes an extra @be that allows
+ * applying boot entry specific info like overrides.
+ *
+ * Return: 0 on success, or negative error code otherwise
+ */
+int bootm_entry(struct bootentry *be, const struct bootm_data *bootm_data)
+{
+	struct bootm_overrides old;
+	struct image_data *data;
+	int ret;
+
+	data = bootm_boot_prep(bootm_data);
+	if (IS_ERR(data))
+		return PTR_ERR(data);
+
+	old = bootm_save_overrides(be->overrides);
+
+	ret = bootm_boot_handler(data);
+
+	bootm_restore_overrides(old);
+
+	bootm_boot_cleanup(data);
+	return ret;
+}
diff --git a/efi/loader/bootesp.c b/efi/loader/bootesp.c
index afce5118aa68..85de1e7e6350 100644
--- a/efi/loader/bootesp.c
+++ b/efi/loader/bootesp.c
@@ -55,7 +55,7 @@ static int esp_boot(struct bootentry *be, int verbose, int dryrun)
 	 * 2) implement device tree overlay patching protocol using it?
 	 */
 
-	ret = bootm_boot(&data);
+	ret = bootm_entry(be, &data);
 	if (ret)
 		pr_err("Booting failed\n");
 
diff --git a/include/boot.h b/include/boot.h
index 836a180a0c7b..57f9cb409bf3 100644
--- a/include/boot.h
+++ b/include/boot.h
@@ -55,4 +55,7 @@ void bootsources_menu(struct bootentries *bootentries, unsigned default_entry, i
 void bootsources_list(struct bootentries *bootentries);
 int boot_entry(struct bootentry *be, int verbose, int dryrun);
 
+struct bootm_data;
+int bootm_entry(struct bootentry *be, const struct bootm_data *data);
+
 #endif /* __BOOT_H */
-- 
2.47.3




  parent reply	other threads:[~2026-03-12 14:45 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-12 14:44 [PATCH 01/16] lib: add lazy loadable infrastructure for deferred boot component loading Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 02/16] bootm: split preparatory step from handler invocation Ahmad Fatoum
2026-03-12 14:44 ` Ahmad Fatoum [this message]
2026-03-12 14:44 ` [PATCH 04/16] bootchooser: pass along struct bootentry Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 05/16] bootm: switch plain file names case to loadable API Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 06/16] uimage: add offset parameter to uimage_load Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 07/16] bootm: uimage: switch to loadable API Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 08/16] bootm: fit: switch to new " Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 09/16] bootm: stash initial OS address/entry in image_data Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 10/16] bootm: support multiple entries for bootm.initrd Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 11/16] bootm: implement plain and FIT bootm.image override Ahmad Fatoum
2026-03-18  9:01   ` Sascha Hauer
2026-03-18  9:17     ` Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 12/16] bootm: overrides: add support for overlays Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 13/16] test: py: add test for initrd concatenation Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 14/16] defaultenv: base: add new devboot script Ahmad Fatoum
2026-03-18  9:50   ` Sascha Hauer
2026-03-18 10:50     ` Ahmad Fatoum
2026-03-18 14:49       ` Sascha Hauer
2026-03-12 14:44 ` [PATCH 15/16] Documentation: user: devboot: add section on forwarding build dirs Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 16/16] libfile: remove file_to_sdram Ahmad Fatoum
2026-03-18 10:06 ` [PATCH 01/16] lib: add lazy loadable infrastructure for deferred boot component loading 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=20260312144505.2159816-3-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