[PATCH 03/16] boot: add bootm_boot wrapper that takes struct bootentry

Ahmad Fatoum
2026-03-12T14:45:47Z

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