* [PATCH master 2/5] filetype: introduce separate filetype_x86_efi_linux_image
2025-11-07 14:17 [PATCH master 1/5] efi: payload: drop unreferenced efi_do_execute_image() Ahmad Fatoum
@ 2025-11-07 14:17 ` Ahmad Fatoum
2025-11-07 14:17 ` [PATCH master 3/5] efi: payload: handover: fix filetype match Ahmad Fatoum
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Ahmad Fatoum @ 2025-11-07 14:17 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
I originally suggested adding only filetype_x86_linux_image during
review, because I was eyeing removal of the EFI types for the other
architectures in favor of handling the EFI stub differently.
I am not pursuing this further, so let's add filetype_x86_efi_linux_image
as it will simplify code at a number of places in following commits.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/filetype.c | 3 ++-
efi/payload/bootm.c | 2 +-
efi/payload/image.c | 2 +-
include/filetype.h | 1 +
4 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/common/filetype.c b/common/filetype.c
index 72f84442cae9..a1807d285258 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -88,6 +88,7 @@ static const struct filetype_str filetype_str[] = {
[filetype_rockchip_rkss_image] = { "Rockchip signed boot image",
"rk-image" },
[filetype_x86_linux_image] = { "x86 Linux image", "x86-linux" },
+ [filetype_x86_efi_linux_image] = { "x86 Linux/EFI image", "x86-efi-linux" },
};
static const char *file_type_to_nr_string(enum filetype f)
@@ -437,7 +438,7 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
if (is_riscv_linux_bootimage(buf) && !memcmp(&buf[12], "barebox", 8))
return filetype_riscv_barebox_image;
if (bufsize > 0x206 && is_x86_linux_bootimage(buf))
- return filetype_x86_linux_image;
+ return is_dos_exe(buf8) ? filetype_x86_efi_linux_image : filetype_x86_linux_image;
if (le32_to_cpu(buf[5]) == 0x504d5453)
return filetype_mxs_bootstream;
diff --git a/efi/payload/bootm.c b/efi/payload/bootm.c
index 3e9ccd42bf7f..e205664b3262 100644
--- a/efi/payload/bootm.c
+++ b/efi/payload/bootm.c
@@ -276,7 +276,7 @@ static struct image_handler efi_app_handle_tr = {
static struct image_handler efi_x86_linux_handle_tr = {
.name = "EFI X86 Linux kernel",
.bootm = do_bootm_efi_stub,
- .filetype = filetype_x86_linux_image,
+ .filetype = filetype_x86_efi_linux_image,
};
static struct image_handler efi_arm64_handle_tr = {
diff --git a/efi/payload/image.c b/efi/payload/image.c
index 5d20221a135e..e4e2d26463da 100644
--- a/efi/payload/image.c
+++ b/efi/payload/image.c
@@ -191,7 +191,7 @@ static struct binfmt_hook binfmt_arm64_efi_hook = {
};
static struct binfmt_hook binfmt_x86_efi_hook = {
- .type = filetype_x86_linux_image,
+ .type = filetype_x86_efi_linux_image,
.hook = efi_execute,
};
diff --git a/include/filetype.h b/include/filetype.h
index ff4d54ee3c45..ecbbd5873b00 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -68,6 +68,7 @@ enum filetype {
filetype_zstd_compressed,
filetype_rockchip_rkss_image,
filetype_x86_linux_image,
+ filetype_x86_efi_linux_image,
filetype_max,
};
--
2.47.3
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH master 3/5] efi: payload: handover: fix filetype match
2025-11-07 14:17 [PATCH master 1/5] efi: payload: drop unreferenced efi_do_execute_image() Ahmad Fatoum
2025-11-07 14:17 ` [PATCH master 2/5] filetype: introduce separate filetype_x86_efi_linux_image Ahmad Fatoum
@ 2025-11-07 14:17 ` Ahmad Fatoum
2025-11-07 14:17 ` [PATCH master 4/5] efi: payload: reinstate error message when booting non-EFI stubbed kernel Ahmad Fatoum
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Ahmad Fatoum @ 2025-11-07 14:17 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
An EFI stubbed x86 Linux bzImage is no longer a filetype_exe due to the
introduction of filetype_x86_linux_image / filetype_x86_efi_linux_image.
Use the new filetype to fix the handover boot.
Fixes: 7b0cedb9ddb4 ("efi: payload: split image handling from legacy
handover boot and add linux x86 image filetype")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/payload/handover.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/efi/payload/handover.c b/efi/payload/handover.c
index 658f3600d6a6..12fd6d95c2e8 100644
--- a/efi/payload/handover.c
+++ b/efi/payload/handover.c
@@ -127,15 +127,15 @@ static int do_bootm_efi(struct image_data *data)
return 0;
}
-static struct image_handler efi_handle_tr = {
+static struct image_handler efi_x86_linux_handle_handover = {
.name = "EFI Application",
.bootm = do_bootm_efi,
- .filetype = filetype_exe,
+ .filetype = filetype_x86_efi_linux_image,
};
static int efi_register_handover_handler(void)
{
- register_image_handler(&efi_handle_tr);
+ register_image_handler(&efi_x86_linux_handle_handover);
return 0;
}
late_efi_initcall(efi_register_handover_handler);
--
2.47.3
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH master 4/5] efi: payload: reinstate error message when booting non-EFI stubbed kernel
2025-11-07 14:17 [PATCH master 1/5] efi: payload: drop unreferenced efi_do_execute_image() Ahmad Fatoum
2025-11-07 14:17 ` [PATCH master 2/5] filetype: introduce separate filetype_x86_efi_linux_image Ahmad Fatoum
2025-11-07 14:17 ` [PATCH master 3/5] efi: payload: handover: fix filetype match Ahmad Fatoum
@ 2025-11-07 14:17 ` Ahmad Fatoum
2025-11-07 14:17 ` [PATCH master 5/5] efi: payload: align kernel boot status messages Ahmad Fatoum
2025-11-10 8:20 ` [PATCH master 1/5] efi: payload: drop unreferenced efi_do_execute_image() Sascha Hauer
4 siblings, 0 replies; 6+ messages in thread
From: Ahmad Fatoum @ 2025-11-07 14:17 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
With the introduction of filetype_x86_linux_image, we never detect a
filetype_mbr, but instead filetype_x86_linux_image.
Now that we have filetype_x86_efi_linux_image, we can fix this handler
by matching against the distinct filetype_x86_linux_image.
Fixes: 7b0cedb9ddb4 ("efi: payload: split image handling from legacy
handover boot and add linux x86 image filetype")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/payload/image.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/efi/payload/image.c b/efi/payload/image.c
index e4e2d26463da..ea6033edc363 100644
--- a/efi/payload/image.c
+++ b/efi/payload/image.c
@@ -165,24 +165,24 @@ static struct binfmt_hook binfmt_efi_hook = {
.hook = efi_execute,
};
-static int do_bootm_mbr(struct image_data *data)
+static struct image_handler non_efi_handle_linux_x86;
+
+static int do_bootm_nonefi(struct image_data *data)
{
- /* On x86, Linux kernel images have a MBR magic at the end of
- * the first 512 byte sector and a PE magic if they're EFI-stubbed.
- * The PE magic has precedence over the MBR, so if we arrive in
- * this boot handler, the kernel has no EFI stub.
- *
- * Print a descriptive error message instead of "no image handler
- * found for image type MBR sector".
+ /* On x86, Linux kernel images have a bzImage header as well as
+ * a PE magic if they're EFI-stubbed.
+ * We have separate file types for x86 Linux images with and
+ * without PE.
*/
- pr_err("Can't boot MBR sector: Is CONFIG_EFI_STUB disabled in your Linux kernel config?\n");
+ pr_err("'%s' unsupported: CONFIG_EFI_STUB must be enabled in your Linux kernel config\n",
+ non_efi_handle_linux_x86.name);
return -ENOSYS;
}
static struct image_handler non_efi_handle_linux_x86 = {
.name = "non-EFI x86 Linux Image",
- .bootm = do_bootm_mbr,
- .filetype = filetype_mbr,
+ .bootm = do_bootm_nonefi,
+ .filetype = filetype_x86_linux_image,
};
static struct binfmt_hook binfmt_arm64_efi_hook = {
--
2.47.3
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH master 5/5] efi: payload: align kernel boot status messages
2025-11-07 14:17 [PATCH master 1/5] efi: payload: drop unreferenced efi_do_execute_image() Ahmad Fatoum
` (2 preceding siblings ...)
2025-11-07 14:17 ` [PATCH master 4/5] efi: payload: reinstate error message when booting non-EFI stubbed kernel Ahmad Fatoum
@ 2025-11-07 14:17 ` Ahmad Fatoum
2025-11-10 8:20 ` [PATCH master 1/5] efi: payload: drop unreferenced efi_do_execute_image() Sascha Hauer
4 siblings, 0 replies; 6+ messages in thread
From: Ahmad Fatoum @ 2025-11-07 14:17 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
To make debugging easier, let's explicitly call out if StartImage or
handover is used and on stdout as we do for other architectures.
While at it, we also skip printing the options if they are <NULL>.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/payload/handover.c | 5 +++--
efi/payload/image.c | 6 ++++--
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/efi/payload/handover.c b/efi/payload/handover.c
index 12fd6d95c2e8..f549568b6d03 100644
--- a/efi/payload/handover.c
+++ b/efi/payload/handover.c
@@ -103,13 +103,14 @@ static int do_bootm_efi(struct image_data *data)
boot_header->code32_start = efi_virt_to_phys(loaded_image->image_base +
(image_header->setup_sects+1) * 512);
+ printf("Booting kernel via handover");
if (bootm_verbose(data)) {
- printf("\nStarting kernel at 0x%p", loaded_image->image_base);
+ printf("at 0x%p", loaded_image->image_base);
if (data->initrd_file)
printf(", initrd at 0x%08x",
boot_header->ramdisk_image);
- printf("...\n");
}
+ printf("...\n");
if (data->dryrun) {
BS->unload_image(handle);
diff --git a/efi/payload/image.c b/efi/payload/image.c
index ea6033edc363..22ff5d27ced6 100644
--- a/efi/payload/image.c
+++ b/efi/payload/image.c
@@ -119,14 +119,16 @@ int efi_execute_image(efi_handle_t handle,
(loaded_image->image_code_type == EFI_RUNTIME_SERVICES_CODE);
if (is_linux_image(filetype, loaded_image->image_base)) {
- pr_debug("Linux kernel detected. Adding bootargs.");
options = linux_bootargs_get();
- pr_info("add linux options '%s'\n", options);
+ printf("Booting kernel via StartImage");
if (options) {
+ printf("with options '%s'", options);
loaded_image->load_options = xstrdup_char_to_wchar(options);
loaded_image->load_options_size =
(strlen(options) + 1) * sizeof(wchar_t);
}
+ printf("...\n");
+
shutdown_barebox();
}
--
2.47.3
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH master 1/5] efi: payload: drop unreferenced efi_do_execute_image()
2025-11-07 14:17 [PATCH master 1/5] efi: payload: drop unreferenced efi_do_execute_image() Ahmad Fatoum
` (3 preceding siblings ...)
2025-11-07 14:17 ` [PATCH master 5/5] efi: payload: align kernel boot status messages Ahmad Fatoum
@ 2025-11-10 8:20 ` Sascha Hauer
4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2025-11-10 8:20 UTC (permalink / raw)
To: barebox, Ahmad Fatoum
On Fri, 07 Nov 2025 15:17:18 +0100, Ahmad Fatoum wrote:
> This function exists in efi/payload/bootm.c as efi_execute(), where it's
> actually used, so drop this unused copy.
>
>
Applied, thanks!
[1/5] efi: payload: drop unreferenced efi_do_execute_image()
https://git.pengutronix.de/cgit/barebox/commit/?id=78932e01e492 (link may not be stable)
[2/5] filetype: introduce separate filetype_x86_efi_linux_image
https://git.pengutronix.de/cgit/barebox/commit/?id=a0459bb7a881 (link may not be stable)
[3/5] efi: payload: handover: fix filetype match
https://git.pengutronix.de/cgit/barebox/commit/?id=956a91bcb79c (link may not be stable)
[4/5] efi: payload: reinstate error message when booting non-EFI stubbed kernel
https://git.pengutronix.de/cgit/barebox/commit/?id=ba1aabfee4a6 (link may not be stable)
[5/5] efi: payload: align kernel boot status messages
https://git.pengutronix.de/cgit/barebox/commit/?id=0633a4db9d23 (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 6+ messages in thread