summaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2025-03-18 13:12:51 -0600
committerTom Rini <trini@konsulko.com>2025-03-18 13:12:51 -0600
commit8bc3542384e3a1219e5ffb62b79d16dddc1b1fb9 (patch)
tree8473478696b9a12d2db424afcec705dcce58c580 /arch
parent698edd63eca090a2e299cd3facf90a0b97bed677 (diff)
parent0f094b8b146679c3980cd2febde4e902bbc4405d (diff)
Merge patch series "pxe: Precursor series for supporting read_all() in extlinux / PXE"
Simon Glass <sjg@chromium.org> says: This series includes some patches related to allowing read_all() to be used with the extlinux / PXE bootmeths. These patches were split out from the stb4 series, since it will need to have additional patches for LWIP, to avoid breaking PXE booting when LWIP is used. Link: https://lore.kernel.org/r/20250306002533.2380866-1-sjg@chromium.org
Diffstat (limited to 'arch')
-rw-r--r--arch/arm/lib/image.c9
-rw-r--r--arch/riscv/lib/image.c9
-rw-r--r--arch/sandbox/lib/bootm.c5
-rw-r--r--arch/x86/include/asm/zimage.h57
-rw-r--r--arch/x86/lib/zimage.c102
5 files changed, 92 insertions, 90 deletions
diff --git a/arch/arm/lib/image.c b/arch/arm/lib/image.c
index 1f672eee2c8..d78d704cb58 100644
--- a/arch/arm/lib/image.c
+++ b/arch/arm/lib/image.c
@@ -28,6 +28,13 @@ struct Image_header {
uint32_t res5;
};
+bool booti_is_valid(const void *img)
+{
+ const struct Image_header *ih = img;
+
+ return ih->magic == le32_to_cpu(LINUX_ARM64_IMAGE_MAGIC);
+}
+
int booti_setup(ulong image, ulong *relocated_addr, ulong *size,
bool force_reloc)
{
@@ -39,7 +46,7 @@ int booti_setup(ulong image, ulong *relocated_addr, ulong *size,
ih = (struct Image_header *)map_sysmem(image, 0);
- if (ih->magic != le32_to_cpu(LINUX_ARM64_IMAGE_MAGIC)) {
+ if (!booti_is_valid(ih)) {
puts("Bad Linux ARM64 Image magic!\n");
return 1;
}
diff --git a/arch/riscv/lib/image.c b/arch/riscv/lib/image.c
index a82f48e9a50..859326cbac8 100644
--- a/arch/riscv/lib/image.c
+++ b/arch/riscv/lib/image.c
@@ -32,6 +32,13 @@ struct linux_image_h {
uint32_t res4; /* reserved */
};
+bool booti_is_valid(const void *img)
+{
+ const struct linux_image_h *lhdr = img;
+
+ return lhdr->magic == LINUX_RISCV_IMAGE_MAGIC;
+}
+
int booti_setup(ulong image, ulong *relocated_addr, ulong *size,
bool force_reloc)
{
@@ -39,7 +46,7 @@ int booti_setup(ulong image, ulong *relocated_addr, ulong *size,
lhdr = (struct linux_image_h *)map_sysmem(image, 0);
- if (lhdr->magic != LINUX_RISCV_IMAGE_MAGIC) {
+ if (!booti_is_valid(lhdr)) {
puts("Bad Linux RISCV Image magic!\n");
return -EINVAL;
}
diff --git a/arch/sandbox/lib/bootm.c b/arch/sandbox/lib/bootm.c
index 44ba8b52e13..8ed923750f4 100644
--- a/arch/sandbox/lib/bootm.c
+++ b/arch/sandbox/lib/bootm.c
@@ -89,3 +89,8 @@ int booti_setup(ulong image, ulong *relocated_addr, ulong *size,
return 1;
}
+
+bool booti_is_valid(const void *img)
+{
+ return false;
+}
diff --git a/arch/x86/include/asm/zimage.h b/arch/x86/include/asm/zimage.h
index 8b542605170..4ed6d8d5cc2 100644
--- a/arch/x86/include/asm/zimage.h
+++ b/arch/x86/include/asm/zimage.h
@@ -10,6 +10,8 @@
#include <asm/bootparam.h>
#include <asm/e820.h>
+struct bootm_info;
+
/* linux i386 zImage/bzImage header. Offsets relative to
* the start of the image */
@@ -43,64 +45,27 @@ enum {
};
/**
- * struct zboot_state - Current state of the boot
- *
- * @bzimage_addr: Address of the bzImage to boot, or 0 if the image has already
- * been loaded and does not exist (as a cohesive whole) in memory
- * @bzimage_size: Size of the bzImage, or 0 to detect this
- * @initrd_addr: Address of the initial ramdisk, or 0 if none
- * @initrd_size: Size of the initial ramdisk, or 0 if none
- * @load_address: Address where the bzImage is moved before booting, either
- * BZIMAGE_LOAD_ADDR or ZIMAGE_LOAD_ADDR
- * This is set up when loading the zimage
- * @base_ptr: Pointer to the boot parameters, typically at address
- * DEFAULT_SETUP_BASE
- * This is set up when loading the zimage
- * @cmdline: Environment variable containing the 'override' command line, or
- * NULL to use the one in the setup block
- */
-struct zboot_state {
- ulong bzimage_addr;
- ulong bzimage_size;
- ulong initrd_addr;
- ulong initrd_size;
- ulong load_address;
- struct boot_params *base_ptr;
- const char *cmdline;
-};
-
-extern struct zboot_state state;
-
-/**
- * zimage_dump() - Dump information about a zimage
- *
- * @base_ptr: Pointer to the boot parameters
- * @show_cmdline: true to show the kernel command line
- */
-void zimage_dump(struct boot_params *base_ptr, bool show_cmdline);
-
-/**
* zboot_load() - Load a zimage
*
* Load the zimage into the correct place
*
* Return: 0 if OK, -ve on error
*/
-int zboot_load(void);
+int zboot_load(struct bootm_info *bmi);
/**
* zboot_setup() - Set up the zboot image reeady for booting
*
* Return: 0 if OK, -ve on error
*/
-int zboot_setup(void);
+int zboot_setup(struct bootm_info *bmi);
/**
* zboot_go() - Start the image
*
* Return: 0 if OK, -ve on error
*/
-int zboot_go(void);
+int zboot_go(struct bootm_info *bmi);
/**
* load_zimage() - Load a zImage or bzImage
@@ -139,6 +104,7 @@ int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot,
*
* Record information about a zimage so it can be booted
*
+ * @bmi: Bootm information
* @bzimage_addr: Address of the bzImage to boot
* @bzimage_size: Size of the bzImage, or 0 to detect this
* @initrd_addr: Address of the initial ramdisk, or 0 if none
@@ -149,14 +115,17 @@ int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot,
* @cmdline: Environment variable containing the 'override' command line, or
* NULL to use the one in the setup block
*/
-void zboot_start(ulong bzimage_addr, ulong bzimage_size, ulong initrd_addr,
- ulong initrd_size, ulong base_addr, const char *cmdline);
+void zboot_start(struct bootm_info *bmi, ulong bzimage_addr, ulong bzimage_size,
+ ulong initrd_addr, ulong initrd_size, ulong base_addr,
+ const char *cmdline);
/**
* zboot_info() - Show simple info about a zimage
*
- * Shows wherer the kernel was loaded and also the setup base
+ * Shows where the kernel was loaded and also the setup base
+ *
+ * @bmi: Bootm information
*/
-void zboot_info(void);
+void zboot_info(struct bootm_info *bmi);
#endif
diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index 2eece34a073..ba7a008fec7 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -55,9 +55,6 @@ DECLARE_GLOBAL_DATA_PTR;
#define COMMAND_LINE_SIZE 2048
-/* Current state of the boot */
-struct zboot_state state;
-
static void build_command_line(char *command_line, int auto_boot)
{
char *env_command_line;
@@ -366,13 +363,13 @@ int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot,
return 0;
}
-int zboot_load(void)
+int zboot_load(struct bootm_info *bmi)
{
struct boot_params *base_ptr;
int ret;
- if (state.base_ptr) {
- struct boot_params *from = (struct boot_params *)state.base_ptr;
+ if (bmi->base_ptr) {
+ struct boot_params *from = (struct boot_params *)bmi->base_ptr;
base_ptr = (struct boot_params *)DEFAULT_SETUP_BASE;
log_debug("Building boot_params at 0x%8.8lx\n",
@@ -380,41 +377,41 @@ int zboot_load(void)
memset(base_ptr, '\0', sizeof(*base_ptr));
base_ptr->hdr = from->hdr;
} else {
- base_ptr = load_zimage((void *)state.bzimage_addr, state.bzimage_size,
- &state.load_address);
+ base_ptr = load_zimage((void *)bmi->bzimage_addr,
+ bmi->bzimage_size, &bmi->load_address);
if (!base_ptr) {
puts("## Kernel loading failed ...\n");
return -EINVAL;
}
}
- state.base_ptr = base_ptr;
+ bmi->base_ptr = base_ptr;
- ret = env_set_hex("zbootbase", map_to_sysmem(state.base_ptr));
+ ret = env_set_hex("zbootbase", map_to_sysmem(bmi->base_ptr));
if (!ret)
- ret = env_set_hex("zbootaddr", state.load_address);
+ ret = env_set_hex("zbootaddr", bmi->load_address);
if (ret)
return ret;
return 0;
}
-int zboot_setup(void)
+int zboot_setup(struct bootm_info *bmi)
{
- struct boot_params *base_ptr = state.base_ptr;
+ struct boot_params *base_ptr = bmi->base_ptr;
int ret;
ret = setup_zimage(base_ptr, (char *)base_ptr + COMMAND_LINE_OFFSET,
- 0, state.initrd_addr, state.initrd_size,
- (ulong)state.cmdline);
+ 0, bmi->initrd_addr, bmi->initrd_size,
+ (ulong)bmi->cmdline);
if (ret)
return -EINVAL;
return 0;
}
-int zboot_go(void)
+int zboot_go(struct bootm_info *bmi)
{
- struct boot_params *params = state.base_ptr;
+ struct boot_params *params = bmi->base_ptr;
struct setup_header *hdr = &params->hdr;
bool image_64bit;
ulong entry;
@@ -422,7 +419,7 @@ int zboot_go(void)
disable_interrupts();
- entry = state.load_address;
+ entry = bmi->load_address;
image_64bit = false;
if (IS_ENABLED(CONFIG_X86_RUN_64BIT) &&
(hdr->xloadflags & XLF_KERNEL_64)) {
@@ -430,30 +427,43 @@ int zboot_go(void)
}
/* we assume that the kernel is in place */
- ret = boot_linux_kernel((ulong)state.base_ptr, entry, image_64bit);
+ ret = boot_linux_kernel((ulong)bmi->base_ptr, entry, image_64bit);
return ret;
}
-int zboot_run(ulong addr, ulong size, ulong initrd, ulong initrd_size,
- ulong base, char *cmdline)
+int zboot_run(struct bootm_info *bmi)
{
int ret;
- zboot_start(addr, size, initrd, initrd_size, base, cmdline);
- ret = zboot_load();
+ ret = zboot_load(bmi);
if (ret)
return log_msg_ret("ld", ret);
- ret = zboot_setup();
+ ret = zboot_setup(bmi);
if (ret)
return log_msg_ret("set", ret);
- ret = zboot_go();
+ ret = zboot_go(bmi);
if (ret)
return log_msg_ret("go", ret);
return -EFAULT;
}
+int zboot_run_args(ulong addr, ulong size, ulong initrd, ulong initrd_size,
+ ulong base, char *cmdline)
+{
+ struct bootm_info bmi;
+ int ret;
+
+ bootm_init(&bmi);
+ zboot_start(&bmi, addr, size, initrd, initrd_size, base, cmdline);
+ ret = zboot_run(&bmi);
+ if (ret)
+ return log_msg_ret("zra", ret);
+
+ return 0;
+}
+
static void print_num(const char *name, ulong value)
{
printf("%-20s: %lx\n", name, value);
@@ -555,12 +565,13 @@ static void show_loader(struct setup_header *hdr)
printf("\n");
}
-void zimage_dump(struct boot_params *base_ptr, bool show_cmdline)
+void zimage_dump(struct bootm_info *bmi, bool show_cmdline)
{
+ struct boot_params *base_ptr;
struct setup_header *hdr;
- const char *version;
int i;
+ base_ptr = bmi->base_ptr;
printf("Setup located at %p:\n\n", base_ptr);
print_num64("ACPI RSDP addr", base_ptr->acpi_rsdp_addr);
@@ -595,10 +606,14 @@ void zimage_dump(struct boot_params *base_ptr, bool show_cmdline)
print_num("Real mode switch", hdr->realmode_swtch);
print_num("Start sys seg", hdr->start_sys_seg);
print_num("Kernel version", hdr->kernel_version);
- version = zimage_get_kernel_version(base_ptr,
- (void *)state.bzimage_addr);
- if (version)
- printf(" @%p: %s\n", version, version);
+ if (bmi->bzimage_addr) {
+ const char *version;
+
+ version = zimage_get_kernel_version(base_ptr,
+ (void *)bmi->bzimage_addr);
+ if (version)
+ printf(" @%p: %s\n", version, version);
+ }
print_num("Type of loader", hdr->type_of_loader);
show_loader(hdr);
print_num("Load flags", hdr->loadflags);
@@ -639,25 +654,24 @@ void zimage_dump(struct boot_params *base_ptr, bool show_cmdline)
print_num("Kernel info offset", hdr->kernel_info_offset);
}
-void zboot_start(ulong bzimage_addr, ulong bzimage_size, ulong initrd_addr,
- ulong initrd_size, ulong base_addr, const char *cmdline)
+void zboot_start(struct bootm_info *bmi, ulong bzimage_addr, ulong bzimage_size,
+ ulong initrd_addr, ulong initrd_size, ulong base_addr,
+ const char *cmdline)
{
- memset(&state, '\0', sizeof(state));
-
- state.bzimage_size = bzimage_size;
- state.initrd_addr = initrd_addr;
- state.initrd_size = initrd_size;
+ bmi->bzimage_size = bzimage_size;
+ bmi->initrd_addr = initrd_addr;
+ bmi->initrd_size = initrd_size;
if (base_addr) {
- state.base_ptr = map_sysmem(base_addr, 0);
- state.load_address = bzimage_addr;
+ bmi->base_ptr = map_sysmem(base_addr, 0);
+ bmi->load_address = bzimage_addr;
} else {
- state.bzimage_addr = bzimage_addr;
+ bmi->bzimage_addr = bzimage_addr;
}
- state.cmdline = cmdline;
+ bmi->cmdline = cmdline;
}
-void zboot_info(void)
+void zboot_info(struct bootm_info *bmi)
{
printf("Kernel loaded at %08lx, setup_base=%p\n",
- state.load_address, state.base_ptr);
+ bmi->load_address, bmi->base_ptr);
}