We currently detect EFI-stubbed Linux images for ARM64 and RISC-V as normal kernel images and would boot them that way. As these images additionally start with MZ like normal PE executables, lets have new filetypes for them. No functional change yet, but we can use a different bootm handler for them in the future when boot is configured to be EFI-enabled. Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx> --- arch/arm/lib64/armlinux.c | 7 +++++++ arch/riscv/lib/bootm.c | 7 +++++++ common/filetype.c | 13 ++++++++++--- include/filetype.h | 2 ++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/arch/arm/lib64/armlinux.c b/arch/arm/lib64/armlinux.c index 8382ffdf1b04..40fea37f53a7 100644 --- a/arch/arm/lib64/armlinux.c +++ b/arch/arm/lib64/armlinux.c @@ -37,6 +37,12 @@ static struct image_handler aarch64_linux_handler = { .filetype = filetype_arm64_linux_image, }; +static struct image_handler aarch64_linux_efi_handler = { + .name = "ARM aarch64 Linux/EFI image", + .bootm = do_bootm_linux, + .filetype = filetype_arm64_efi_linux_image, +}; + static struct image_handler aarch64_fit_handler = { .name = "FIT image", .bootm = do_bootm_linux, @@ -83,6 +89,7 @@ static struct image_handler aarch64_barebox_handler = { static int aarch64_register_image_handler(void) { + register_image_handler(&aarch64_linux_efi_handler); register_image_handler(&aarch64_linux_handler); register_image_handler(&aarch64_barebox_handler); diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c index 6984f282be4d..6bbf7bd156d8 100644 --- a/arch/riscv/lib/bootm.c +++ b/arch/riscv/lib/bootm.c @@ -36,6 +36,12 @@ static struct image_handler riscv_linux_handler = { .filetype = filetype_riscv_linux_image, }; +static struct image_handler riscv_linux_efi_handler = { + .name = "RISC-V Linux/EFI image", + .bootm = do_bootm_linux, + .filetype = filetype_riscv_linux_efi_image, +}; + static struct image_handler riscv_fit_handler = { .name = "FIT image", .bootm = do_bootm_linux, @@ -51,6 +57,7 @@ static struct image_handler riscv_barebox_handler = { static int riscv_register_image_handler(void) { register_image_handler(&riscv_linux_handler); + register_image_handler(&riscv_linux_efi_handler); register_image_handler(&riscv_barebox_handler); if (IS_ENABLED(CONFIG_FITIMAGE)) diff --git a/common/filetype.c b/common/filetype.c index f726a933d245..5bf531b107ff 100644 --- a/common/filetype.c +++ b/common/filetype.c @@ -62,7 +62,9 @@ static const struct filetype_str filetype_str[] = { [filetype_kwbimage_v1] = { "MVEBU kwbimage (v1)", "kwb1" }, [filetype_android_sparse] = { "Android sparse image", "sparse" }, [filetype_arm64_linux_image] = { "ARM aarch64 Linux image", "aarch64-linux" }, + [filetype_arm64_efi_linux_image] = { "ARM aarch64 Linux/EFI image", "aarch64-efi-linux" }, [filetype_riscv_linux_image] = { "RISC-V Linux image", "riscv-linux" }, + [filetype_riscv_efi_linux_image] = { "RISC-V Linux/EFI image", "riscv-efi-linux" }, [filetype_riscv_barebox_image] = { "RISC-V barebox image", "riscv-barebox" }, [filetype_elf] = { "ELF", "elf" }, [filetype_imx_image_v1] = { "i.MX image (v1)", "imx-image-v1" }, @@ -249,6 +251,11 @@ enum filetype file_detect_partition_table(const void *_buf, size_t bufsize) return filetype_unknown; } +static bool is_dos_exe(const u8 *buf8) +{ + return buf8[0] == 'M' && buf8[1] == 'Z'; +} + #define CH_TOC_section_name 0x14 enum filetype file_detect_type(const void *_buf, size_t bufsize) @@ -311,9 +318,9 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize) if (buf[0] == be32_to_cpu(0x534F4659)) return filetype_bpk; if (le32_to_cpu(buf[14]) == 0x644d5241) - return filetype_arm64_linux_image; + return is_dos_exe(buf8) ? filetype_arm64_efi_linux_image : filetype_arm64_linux_image; if (le32_to_cpu(buf[14]) == 0x05435352) - return filetype_riscv_linux_image; + return is_dos_exe(buf8) ? filetype_riscv_efi_linux_image : filetype_riscv_linux_image; if (le32_to_cpu(buf[14]) == 0x56435352 && !memcmp(&buf[12], "barebox", 8)) return filetype_riscv_barebox_image; if (strncmp(buf8, "RKNS", 4) == 0) @@ -367,7 +374,7 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize) if (buf[9] == 0x016f2818 || buf[9] == 0x18286f01) return filetype_arm_zimage; - if (buf8[0] == 'M' && buf8[1] == 'Z') + if (is_dos_exe(buf8)) return filetype_exe; if (bufsize < 256) diff --git a/include/filetype.h b/include/filetype.h index 4e646aec9d6f..125e81fee7f4 100644 --- a/include/filetype.h +++ b/include/filetype.h @@ -44,7 +44,9 @@ enum filetype { filetype_kwbimage_v1, filetype_android_sparse, filetype_arm64_linux_image, + filetype_arm64_efi_linux_image, filetype_riscv_linux_image, + filetype_riscv_efi_linux_image, filetype_riscv_barebox_image, filetype_elf, filetype_imx_image_v1, -- 2.39.2