From 2058983689f0e42f639a5fbece26ecd9fed5fa41 Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Sun, 10 Apr 2022 16:05:55 -0500 Subject: [PATCH] cmd: bootefi: restore ability to boot arbitrary blob Up until commit 5f59518a7b1ae ("efi_loader: setting boot device"), we could boot an arbitrary blob with bootefi. Indeed, efi_run_image() even has a special case for missing device paths indicating a payload that was directly loaded via JTAG, for example. Restore the ability to inject a UEFI payload into memory and `bootefi` it. If the address passed isn't the last PE-COFF loaded, then we'll wipe out the pre-existing DP/Image information and let efi_run_image() synthesize a memory device path. An image size is required if we're booting an arbitrary payload, and the FDT argument has been changed to accept `-`. The size could be deduced from the image header, but it's required anyways as an explicit acknowledgment that one's trying to boot an arbitrary payload rather than accidentally using the wrong address in the single-addr form. Fixes: 5f59518a7b1a ("efi_loader: setting boot device") Signed-off-by: Kyle Evans Reviewed-by: Heinrich Schuchardt --- cmd/bootefi.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 53d9f0e0dc..d80353fa71 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -422,10 +422,11 @@ static int do_efibootmgr(void) * Set up memory image for the binary to be loaded, prepare device path, and * then call do_bootefi_exec() to execute it. * - * @image_opt: string of image start address + * @image_opt: string with image start address + * @size_opt: string with image size or NULL * Return: status code */ -static int do_bootefi_image(const char *image_opt) +static int do_bootefi_image(const char *image_opt, const char *size_opt) { void *image_buf; unsigned long addr, size; @@ -443,14 +444,21 @@ static int do_bootefi_image(const char *image_opt) /* Check that a numeric value was passed */ if (!addr) return CMD_RET_USAGE; - image_buf = map_sysmem(addr, 0); - if (image_buf != image_addr) { - log_err("No UEFI binary known at %s\n", image_opt); - return CMD_RET_FAILURE; + if (size_opt) { + size = strtoul(size_opt, NULL, 16); + if (!size) + return CMD_RET_USAGE; + efi_clear_bootdev(); + } else { + if (image_buf != image_addr) { + log_err("No UEFI binary known at %s\n", + image_opt); + return CMD_RET_FAILURE; + } + size = image_size; } - size = image_size; } ret = efi_run_image(image_buf, size); @@ -654,7 +662,7 @@ static int do_bootefi(struct cmd_tbl *cmdtp, int flag, int argc, return CMD_RET_FAILURE; } - if (argc > 2) { + if (argc > 2 && strcmp(argv[2], "-")) { uintptr_t fdt_addr; fdt_addr = hextoul(argv[2], NULL); @@ -677,15 +685,15 @@ static int do_bootefi(struct cmd_tbl *cmdtp, int flag, int argc, return do_efi_selftest(); #endif - return do_bootefi_image(argv[1]); + return do_bootefi_image(argv[1], argc > 3 ? argv[3] : NULL); } #ifdef CONFIG_SYS_LONGHELP static char bootefi_help_text[] = - " [fdt address]\n" - " - boot EFI payload stored at address .\n" - " If specified, the device tree located at gets\n" - " exposed as EFI configuration table.\n" + " [fdt address [image size]]\n" + " - boot EFI payload stored at \n" + " fdt address, address of device-tree or '-'\n" + " image size, required if image not preloaded\n" #ifdef CONFIG_CMD_BOOTEFI_HELLO "bootefi hello\n" " - boot a sample Hello World application stored within U-Boot\n" @@ -707,7 +715,7 @@ static char bootefi_help_text[] = #endif U_BOOT_CMD( - bootefi, 3, 0, do_bootefi, + bootefi, 4, 0, do_bootefi, "Boots an EFI payload from memory", bootefi_help_text ); -- 2.39.5