From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/3] efi: payload: fold setup_header.h into handover.c
Date: Fri, 28 Nov 2025 18:21:54 +0100 [thread overview]
Message-ID: <20251128172158.36324-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20251128172158.36324-1-a.fatoum@pengutronix.de>
The x86_setup_header is only used for x86 handover, so move it there and
replace is_linux_image by a helper that doesn't depend on it.
No functional change expected.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/filetype.c | 12 ++++++++
efi/payload/bootm.c | 1 -
efi/payload/handover.c | 57 +++++++++++++++++++++++++++++++++-
efi/payload/image.c | 15 +--------
| 63 --------------------------------------
include/filetype.h | 1 +
6 files changed, 70 insertions(+), 79 deletions(-)
delete mode 100644 efi/payload/setup_header.h
diff --git a/common/filetype.c b/common/filetype.c
index a1807d285258..3e3e18dae0b3 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -586,3 +586,15 @@ bool filetype_is_barebox_image(enum filetype ft)
return false;
}
}
+
+bool filetype_is_linux_efi_image(enum filetype ft)
+{
+ switch (ft) {
+ case filetype_arm64_efi_linux_image:
+ case filetype_riscv_efi_linux_image:
+ case filetype_x86_efi_linux_image:
+ return true;
+ default:
+ return false;
+ }
+}
diff --git a/efi/payload/bootm.c b/efi/payload/bootm.c
index 2e060762f238..c81211d896ad 100644
--- a/efi/payload/bootm.c
+++ b/efi/payload/bootm.c
@@ -33,7 +33,6 @@
#include <efi/efi-device.h>
#include "image.h"
-#include "setup_header.h"
static bool ramdisk_is_fit(struct image_data *data)
{
diff --git a/efi/payload/handover.c b/efi/payload/handover.c
index 8c6dd2896f47..68180d820e53 100644
--- a/efi/payload/handover.c
+++ b/efi/payload/handover.c
@@ -31,7 +31,62 @@
#include <efi/efi-device.h>
#include "image.h"
-#include "setup_header.h"
+
+struct x86_setup_header {
+ /* first sector of the image */
+ uint8_t code1[0x0020];
+ uint16_t cl_magic; /**< Magic number 0xA33F */
+ uint16_t cl_offset; /**< The offset of command line */
+ uint8_t code2[0x01F1 - 0x0020 - 2 - 2];
+ uint8_t setup_sects; /**< The size of the setup in sectors */
+ uint16_t root_flags; /**< If the root is mounted readonly */
+ uint16_t syssize; /**< obsolete */
+ uint16_t swap_dev; /**< obsolete */
+ uint16_t ram_size; /**< obsolete */
+ uint16_t vid_mode; /**< Video mode control */
+ uint16_t root_dev; /**< Default root device number */
+ uint16_t boot_flag; /**< 0xAA55 magic number */
+
+ /* second sector of the image */
+ uint16_t jump; /**< Jump instruction (this is code!) */
+ uint32_t header; /**< Magic signature "HdrS" */
+ uint16_t version; /**< Boot protocol version supported */
+ uint32_t realmode_swtch; /**< Boot loader hook */
+ uint16_t start_sys; /**< The load-low segment (obsolete) */
+ uint16_t kernel_version; /**< Points to kernel version string */
+ uint8_t type_of_loader; /**< Boot loader identifier */
+ uint8_t loadflags; /**< Boot protocol option flags */
+ uint16_t setup_move_size; /**< Move to high memory size */
+ uint32_t code32_start; /**< Boot loader hook */
+ uint32_t ramdisk_image; /**< initrd load address */
+ uint32_t ramdisk_size; /**< initrd size */
+ uint32_t bootsect_kludge; /**< obsolete */
+ uint16_t heap_end_ptr; /**< Free memory after setup end */
+ uint8_t ext_loader_ver; /**< boot loader's extension of the version number */
+ uint8_t ext_loader_type; /**< boot loader's extension of its type */
+ uint32_t cmd_line_ptr; /**< Points to the kernel command line */
+ uint32_t initrd_addr_max; /**< Highest address for initrd */
+ uint32_t kernel_alignment; /**< Alignment unit required by the kernel */
+ uint8_t relocatable_kernel; /** */
+ uint8_t min_alignment; /** */
+ uint16_t xloadflags; /** */
+ uint32_t cmdline_size; /** */
+ uint32_t hardware_subarch; /** */
+ uint64_t hardware_subarch_data; /** */
+ uint32_t payload_offset; /** */
+ uint32_t payload_length; /** */
+ uint64_t setup_data; /** */
+ uint64_t pref_address; /** */
+ uint32_t init_size; /** */
+ uint32_t handover_offset; /** */
+} __attribute__ ((packed));
+
+static inline bool is_x86_setup_header(const void *base)
+{
+ const struct x86_setup_header *hdr = base;
+
+ return hdr->boot_flag == 0xAA55 && hdr->header == 0x53726448;
+}
typedef void(*handover_fn)(void *image, struct efi_system_table *table,
struct x86_setup_header *header);
diff --git a/efi/payload/image.c b/efi/payload/image.c
index 5e268ed0ce35..ed4307aab909 100644
--- a/efi/payload/image.c
+++ b/efi/payload/image.c
@@ -29,7 +29,6 @@
#include <efi/efi-device.h>
#include "image.h"
-#include "setup_header.h"
static void *efi_read_file(const char *file, size_t *size)
{
@@ -96,18 +95,6 @@ int efi_load_image(const char *file, struct efi_loaded_image **loaded_image,
return -efi_errno(efiret);
}
-static bool is_linux_image(enum filetype filetype, const void *base)
-{
- if (IS_ENABLED(CONFIG_X86) && is_x86_setup_header(base))
- return true;
-
- if (IS_ENABLED(CONFIG_ARM64) &&
- filetype == filetype_arm64_efi_linux_image)
- return true;
-
- return false;
-}
-
int efi_execute_image(efi_handle_t handle,
struct efi_loaded_image *loaded_image,
enum filetype filetype)
@@ -119,7 +106,7 @@ int efi_execute_image(efi_handle_t handle,
is_driver = (loaded_image->image_code_type == EFI_BOOT_SERVICES_CODE) ||
(loaded_image->image_code_type == EFI_RUNTIME_SERVICES_CODE);
- if (is_linux_image(filetype, loaded_image->image_base)) {
+ if (filetype_is_linux_efi_image(filetype)) {
options = linux_bootargs_get();
printf("Booting kernel via StartImage");
if (options) {
diff --git a/efi/payload/setup_header.h b/efi/payload/setup_header.h
deleted file mode 100644
index 4f094b844415..000000000000
--- a/efi/payload/setup_header.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-#ifndef __EFI_PAYLOAD_SETUP_HEADER_H__
-#define __EFI_PAYLOAD_SETUP_HEADER_H__
-
-#include <linux/types.h>
-
-struct x86_setup_header {
- /* first sector of the image */
- uint8_t code1[0x0020];
- uint16_t cl_magic; /**< Magic number 0xA33F */
- uint16_t cl_offset; /**< The offset of command line */
- uint8_t code2[0x01F1 - 0x0020 - 2 - 2];
- uint8_t setup_sects; /**< The size of the setup in sectors */
- uint16_t root_flags; /**< If the root is mounted readonly */
- uint16_t syssize; /**< obsolete */
- uint16_t swap_dev; /**< obsolete */
- uint16_t ram_size; /**< obsolete */
- uint16_t vid_mode; /**< Video mode control */
- uint16_t root_dev; /**< Default root device number */
- uint16_t boot_flag; /**< 0xAA55 magic number */
-
- /* second sector of the image */
- uint16_t jump; /**< Jump instruction (this is code!) */
- uint32_t header; /**< Magic signature "HdrS" */
- uint16_t version; /**< Boot protocol version supported */
- uint32_t realmode_swtch; /**< Boot loader hook */
- uint16_t start_sys; /**< The load-low segment (obsolete) */
- uint16_t kernel_version; /**< Points to kernel version string */
- uint8_t type_of_loader; /**< Boot loader identifier */
- uint8_t loadflags; /**< Boot protocol option flags */
- uint16_t setup_move_size; /**< Move to high memory size */
- uint32_t code32_start; /**< Boot loader hook */
- uint32_t ramdisk_image; /**< initrd load address */
- uint32_t ramdisk_size; /**< initrd size */
- uint32_t bootsect_kludge; /**< obsolete */
- uint16_t heap_end_ptr; /**< Free memory after setup end */
- uint8_t ext_loader_ver; /**< boot loader's extension of the version number */
- uint8_t ext_loader_type; /**< boot loader's extension of its type */
- uint32_t cmd_line_ptr; /**< Points to the kernel command line */
- uint32_t initrd_addr_max; /**< Highest address for initrd */
- uint32_t kernel_alignment; /**< Alignment unit required by the kernel */
- uint8_t relocatable_kernel; /** */
- uint8_t min_alignment; /** */
- uint16_t xloadflags; /** */
- uint32_t cmdline_size; /** */
- uint32_t hardware_subarch; /** */
- uint64_t hardware_subarch_data; /** */
- uint32_t payload_offset; /** */
- uint32_t payload_length; /** */
- uint64_t setup_data; /** */
- uint64_t pref_address; /** */
- uint32_t init_size; /** */
- uint32_t handover_offset; /** */
-} __attribute__ ((packed));
-
-static inline bool is_x86_setup_header(const void *base)
-{
- const struct x86_setup_header *hdr = base;
-
- return hdr->boot_flag == 0xAA55 && hdr->header == 0x53726448;
-}
-
-#endif
diff --git a/include/filetype.h b/include/filetype.h
index ecbbd5873b00..440eb95bfb0c 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -89,6 +89,7 @@ int cdev_detect_type(struct cdev *cdev, enum filetype *type);
enum filetype is_fat_or_mbr(const unsigned char *sector, unsigned long *bootsec);
int is_fat_boot_sector(const void *_buf);
bool filetype_is_barebox_image(enum filetype ft);
+bool filetype_is_linux_efi_image(enum filetype ft);
static inline bool file_is_compressed_file(enum filetype ft)
{
--
2.47.3
next prev parent reply other threads:[~2025-11-28 17:22 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-28 17:21 [PATCH 1/3] efi: payload: image: set LoaderTimeExecUSec for kernel images Ahmad Fatoum
2025-11-28 17:21 ` Ahmad Fatoum [this message]
2025-11-28 17:21 ` [PATCH 3/3] efi: add option to generate vfat file for barebox.efi Ahmad Fatoum
2025-12-01 9:04 ` [PATCH 1/3] efi: payload: image: set LoaderTimeExecUSec for kernel images 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=20251128172158.36324-2-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