Skip to contentSkip to conversation

boot: pxe: support booting PE/COFF EFI applications

PATCH In review Sumit Singh Dhami 2 participants 2 messages Nov 4 – Nov 6

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 boot: pxe: support booting PE/COFF EFI applications

From: Aswin Murugan <[email protected]>

PXE assumes that a downloaded image is a Linux Image, uImage, or FIT image and dispatches it through bootm, booti, or bootz. However, PXE may download an EFI stub kernel or another UEFI application in PE/COFF format. These images contain a DOS/PE header instead of the ARM64 Image magic, so genimg_get_format() reports them as invalid. The legacy bootm/booti/bootz path then fails with "Bad Linux ARM64 Image magic!".

Detect PE/COFF images downloaded by PXE and execute them with efi_binary_run(). Track the downloaded image size so it can be validated, and pass the selected device tree blob to the EFI application.

---
 boot/pxe_utils.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
boot/pxe_utils.c +18 -2
index 8ec48a43bfa..c60429a5e12 100644
@@ -9,6 +9,7 @@
 #include <bootflow.h>
 #include <command.h>
 #include <dm.h>
+#include <efi_loader.h>
 #include <env.h>
 #include <extension_board.h>
 #include <image.h>
@@ -536,6 +537,7 @@ int label_boot(struct pxe_context *ctx, struct pxe_label *label)
 	int zboot_argc = 3;
 	int len = 0;
 	ulong kernel_addr_r;
+	ulong kernel_size = 0;
 	void *buf;
 
 	label_print(label);
@@ -555,7 +557,8 @@ int label_boot(struct pxe_context *ctx, struct pxe_label *label)
 	}
 
 	if (get_relfile_envaddr(ctx, label->kernel, "kernel_addr_r",
-				(enum bootflow_img_t)IH_TYPE_KERNEL, NULL)
+				(enum bootflow_img_t)IH_TYPE_KERNEL,
+				&kernel_size)
 				< 0) {
 		printf("Skipping %s for failure retrieving kernel\n",
 		       label->name);
@@ -800,8 +803,21 @@ int label_boot(struct pxe_context *ctx, struct pxe_label *label)
 		bootm_argc = 4;
 	}
 
+	/* Run PE-COFF images as EFI applications */
+	if (IS_ENABLED(CONFIG_CMD_BOOTEFI) &&
+	    efi_check_pe(buf, kernel_size, NULL) == EFI_SUCCESS) {
+		void *fdt = EFI_FDT_USE_INTERNAL;
+		efi_status_t efi_ret;
+
+		log_debug("using bootefi\n");
+		if (bootm_argv[3])
+			fdt = map_sysmem(hextoul(bootm_argv[3], NULL), 0);
+
+		efi_ret = efi_binary_run(buf, kernel_size, fdt, NULL, 0);
+		if (efi_ret != EFI_SUCCESS)
+			log_err("efi_binary_run failed (ret=%lu)\n", efi_ret);
 	/* Try bootm for legacy and FIT format image */
-	if (genimg_get_format(buf) != IMAGE_FORMAT_INVALID &&
+	} else if (genimg_get_format(buf) != IMAGE_FORMAT_INVALID &&
 	    IS_ENABLED(CONFIG_CMD_BOOTM)) {
 		log_debug("using bootm\n");
 		do_bootm(ctx->cmdtp, 0, bootm_argc, bootm_argv);

base-commit: 3973f3c4d24df75ca90d7c0a9f03e5e5c9b48f32

Signature · 2 lines
Best regards
Sumit Singh Dhami
#1 lore raw
Quoted 15 lines

From: Aswin Murugan <[email protected]>

PXE assumes that a downloaded image is a Linux Image, uImage, or FIT image and dispatches it through bootm, booti, or bootz. However, PXE may download an EFI stub kernel or another UEFI application in PE/COFF format. These images contain a DOS/PE header instead of the ARM64 Image magic, so genimg_get_format() reports them as invalid. The legacy bootm/booti/bootz path then fails with "Bad Linux ARM64 Image magic!".

Detect PE/COFF images downloaded by PXE and execute them with efi_binary_run(). Track the downloaded image size so it can be validated, and pass the selected device tree blob to the EFI application.

Quoted 5 lines
---
 boot/pxe_utils.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

Applied to u-boot-net branch for-main [1], thanks!

[1] https://git.u-boot-project.org/u-boot/custodians/u-boot-net/-/commits/for-main

[1/1] boot: pxe: support booting PE/COFF EFI applications

      commit: e0b7e1d9c06fa33657838dda6a93a696b0c90fa9

Best regards,

Signature · 1 line
Jerome Forissier <[email protected]>