From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v3 07/12] efi: payload: always shutdown barebox when booting
Date: Mon, 26 Oct 2026 13:09:58 +0100 [thread overview]
Message-ID: <20261026121150.455510-8-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20261026121150.455510-1-a.fatoum@pengutronix.de>
When barebox is about to boot a kernel image, it calls shutdown_barebox
and then starts the image. When the kernel image is wrapped in a UKI,
barebox will not detect it as a kernel image and will thus not call
shutdown_barebox beforehand, which can mean that e.g. state is not
flushed.
We do not want to treat UKIs completely like kernels (e.g. we do not
want to override their built-in bootargs), but we still want to properly
shutdown barebox.
Resolve this by shutting down barebox whenever we are in a bootm handler,
no matter which kind of image is about to be started: bootm is the point
of no return. Images run from the shell via binfmt keep returning to
barebox afterwards, with the exception of EFI-stubbed kernels, which take
over the machine and thus continue to shut barebox down as before.
Assisted-by: Claude:opus-5
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
.../efi-payload-bootm-shutdown.rst | 10 +++++++++
efi/payload/bootm.c | 4 ++--
efi/payload/image.c | 21 +++++++++++++------
efi/payload/image.h | 1 +
4 files changed, 28 insertions(+), 8 deletions(-)
create mode 100644 Documentation/migration-guides/migration-master/efi-payload-bootm-shutdown.rst
diff --git a/Documentation/migration-guides/migration-master/efi-payload-bootm-shutdown.rst b/Documentation/migration-guides/migration-master/efi-payload-bootm-shutdown.rst
new file mode 100644
index 000000000000..2e0a84b536e6
--- /dev/null
+++ b/Documentation/migration-guides/migration-master/efi-payload-bootm-shutdown.rst
@@ -0,0 +1,10 @@
+EFI applications booted via bootm no longer return to barebox
+-------------------------------------------------------------
+
+When barebox runs as EFI payload, :ref:`command_bootm` now shuts down
+barebox before starting any EFI application, not only EFI-stubbed Linux
+kernels. If the application returns, barebox exits to the firmware instead
+of returning to the shell or trying the next boot entry.
+
+EFI applications that are expected to return, like an EFI shell, should be
+executed directly from the shell instead.
diff --git a/efi/payload/bootm.c b/efi/payload/bootm.c
index d6a79f0c7795..58b7dd5ea779 100644
--- a/efi/payload/bootm.c
+++ b/efi/payload/bootm.c
@@ -185,7 +185,7 @@ static int do_bootm_efi_stub(struct image_data *data)
if (data->dryrun)
goto unload_ramdisk;
- ret = efi_execute_image(handle, loaded_image, type);
+ ret = efi_execute_image(handle, loaded_image, true, type);
/* efi_execute_image takes care to unload the image on error,
* so we set image_freed and fall through to freeing ramdisk
@@ -225,7 +225,7 @@ static int efi_app_execute(struct image_data *data)
return 0;
}
- return efi_execute_image(handle, loaded_image, type);
+ return efi_execute_image(handle, loaded_image, true, type);
}
static int linux_efi_handover = true;
diff --git a/efi/payload/image.c b/efi/payload/image.c
index 76aca1c43cec..4e59c7b4ea10 100644
--- a/efi/payload/image.c
+++ b/efi/payload/image.c
@@ -100,17 +100,26 @@ int efi_load_image(const char *file, struct efi_loaded_image **loaded_image,
int efi_execute_image(efi_handle_t handle,
struct efi_loaded_image *loaded_image,
+ bool is_bootm,
enum filetype filetype)
{
efi_status_t efiret;
const char *options;
- bool is_driver, is_kernel = false;
+ bool is_driver;
+ bool no_return;
is_driver = (loaded_image->image_code_type == EFI_BOOT_SERVICES_CODE) ||
(loaded_image->image_code_type == EFI_RUNTIME_SERVICES_CODE);
efi_export_dtb();
+ /*
+ * A bootm handler is the point of no return, but an EFI-stubbed kernel
+ * started from the shell takes over the machine just the same, so
+ * barebox needs to be shut down in both cases.
+ */
+ no_return = is_bootm || filetype_is_linux_efi_image(filetype);
+
if (filetype_is_linux_efi_image(filetype)) {
options = linux_bootargs_get();
printf("Booting kernel via StartImage");
@@ -121,11 +130,11 @@ int efi_execute_image(efi_handle_t handle,
(strlen(options) + 1) * sizeof(wchar_t);
}
printf("...\n");
+ }
+ if (no_return) {
efi_set_variable_usec("LoaderTimeExecUSec", &efi_systemd_vendor_guid,
ktime_to_us(ktime_get()));
-
- is_kernel = true;
shutdown_barebox();
}
@@ -135,8 +144,8 @@ int efi_execute_image(efi_handle_t handle,
efi_continue_devices();
- if (is_kernel) {
- pr_emerg("Kernel image has unexpectedly returned\n");
+ if (no_return) {
+ pr_emerg("Boot image has unexpectedly returned\n");
BS->exit(efi_parent_image, efiret, 0, NULL);
}
@@ -162,7 +171,7 @@ static int efi_execute(struct binfmt_hook *b, char *file, int argc, char **argv)
if (ret)
return ret;
- return efi_execute_image(handle, loaded_image, b->type);
+ return efi_execute_image(handle, loaded_image, false, b->type);
}
static struct binfmt_hook binfmt_efi_hook = {
diff --git a/efi/payload/image.h b/efi/payload/image.h
index bab1be368c21..33f7e1a21b30 100644
--- a/efi/payload/image.h
+++ b/efi/payload/image.h
@@ -13,6 +13,7 @@ int efi_load_image(const char *file, struct efi_loaded_image **loaded_image,
int efi_execute_image(efi_handle_t handle,
struct efi_loaded_image *loaded_image,
+ bool is_bootm,
enum filetype filetype);
extern struct image_handler efi_x86_linux_handle_tr;
--
2.47.3
next prev parent reply other threads:[~2026-10-26 12:16 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-26 12:09 [PATCH v3 00/12] efi: payload: allow passing arguments to UKIs Ahmad Fatoum
2026-10-26 12:09 ` [PATCH v3 01/12] efi: treat EFI zboot Linux images like other EFI-stubbed kernels Ahmad Fatoum
2026-10-26 12:09 ` [PATCH v3 02/12] commands: devlookup: honour global.bootm.root_param for -k Ahmad Fatoum
2026-10-26 12:09 ` [PATCH v3 03/12] common: bootargs: don't leave linux_bootargs dangling after free Ahmad Fatoum
2026-10-26 12:09 ` [PATCH v3 04/12] common: bootargs: drop legacy bootargs fallback with FLEXIBLE_BOOTARGS Ahmad Fatoum
2026-10-26 12:09 ` [PATCH v3 05/12] globalvar: skip empty variables in globalvar_get_match() Ahmad Fatoum
2026-10-26 12:09 ` [PATCH v3 06/12] efi: payload: honour bootm dryrun in the EFI application handler Ahmad Fatoum
2026-10-26 12:09 ` Ahmad Fatoum [this message]
2026-10-26 12:09 ` [PATCH v3 08/12] efi: payload: pass shell arguments as load options to executed images Ahmad Fatoum
2026-10-26 12:10 ` [PATCH v3 09/12] efi: add global.efi.bootargs for bootm'd EFI applications Ahmad Fatoum
2026-10-26 12:10 ` [PATCH v3 10/12] Documentation: efi: describe load options handling Ahmad Fatoum
2026-10-26 12:10 ` [PATCH v3 11/12] test: py: efiloader: check global.efi.bootargs reaches the kernel Ahmad Fatoum
2026-10-26 12:10 ` [PATCH v3 12/12] boot: report exit status of failing boot scripts 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=20261026121150.455510-8-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