[PATCH v9 00/11] efi: Add a test for EFI bootmeth

The test coverage for the EFI bootmeth is incomplete since it does not actually boot the application.
This series creates a simple test for this purpose. It includes a few patches to make this work:
- Revert of an unreviewed patch to change the sandbox efi filename - Hang in sandbox virtio due to EFI probing all block devices
Other necessary fixes have already been applied.
Changes in v10: - Drop call to exit-boot-services
Changes in v9: - Update license - Fix 'sevices' typo - Move the function into efi_helper.c - Split out into a separate change - Split out into its own patch - Separate into separate patches - Add new patch to drop sandbox PXE architecture - Mark the image as complete after writing it - Fix 'sevices' typo
Changes in v8: - Add new patch to control on-host behaviour - Add new patch to move default filename to a function - Add new patch to report host default-filename in native mode - Add new patch to report host default-filename in native mode
Changes in v7: - Update commit message - Drop patches already applied - Drop patch 'Disable ANSI output for tests' - Rebase on -master
Changes in v6: - Drop the patch to disable sandbox virtio blk with EFI - Add new patch to disable the sandbox virtio blk device - Deal with sandbox CONFIG_LOGF_FUNC - Rebase on -next - Drop patches previously applied - Drop mention of helloworld since it is no-longer used by this test
Changes in v4: - Add efi_loader tag to some patches - Split out non-EFI patches into a different series
Changes in v2: - Add many new patches to resolve all the outstanding test issues
Simon Glass (11): test: boot: Update bootflow_iter() for console checking efi_loader: Add a test app sandbox: Add a -N flag to control on-host behaviour efi: Move default filename to a function efi_loader: Move get_efi_pxe_arch() to efi_helper efi_loader: Allow reporting the host defaults sandbox: Report host default-filename in native mode efi_loader: Drop sandbox PXE architecture sandbox: virtio: Disable the sandbox virtio blk device test: efi: boot: Set up an image suitable for EFI testing test: efi: boot: Add a test for the efi bootmeth
arch/Kconfig | 3 +- arch/sandbox/cpu/start.c | 10 ++++ arch/sandbox/dts/test.dts | 2 +- arch/sandbox/include/asm/state.h | 1 + boot/bootmeth_efi.c | 29 ++---------- cmd/efidebug.c | 25 ++++++++++ include/efi.h | 34 +++++++++++++ include/efi_default_filename.h | 56 ---------------------- lib/efi_loader/Kconfig | 10 ++++ lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_bootmgr.c | 10 ++-- lib/efi_loader/efi_helper.c | 71 ++++++++++++++++++++++++++++ lib/efi_loader/testapp.c | 64 +++++++++++++++++++++++++ test/boot/bootdev.c | 18 ++++++- test/boot/bootflow.c | 67 ++++++++++++++++++++++++-- test/py/tests/bootstd/flash1.img.xz | Bin 0 -> 4924 bytes test/py/tests/test_ut.py | 53 ++++++++++++++++++--- 17 files changed, 356 insertions(+), 98 deletions(-) delete mode 100644 include/efi_default_filename.h create mode 100644 lib/efi_loader/testapp.c create mode 100644 test/py/tests/bootstd/flash1.img.xz

This test checks console output so should have the UTF_CONSOLE flag. Add it.
Signed-off-by: Simon Glass sjg@chromium.org ---
(no changes since v1)
test/boot/bootflow.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c index 0d4e966892e..841729bd1ac 100644 --- a/test/boot/bootflow.c +++ b/test/boot/bootflow.c @@ -370,7 +370,7 @@ static int bootflow_iter(struct unit_test_state *uts)
return 0; } -BOOTSTD_TEST(bootflow_iter, UTF_DM | UTF_SCAN_FDT); +BOOTSTD_TEST(bootflow_iter, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE);
#if defined(CONFIG_SANDBOX) && defined(CONFIG_BOOTMETH_GLOBAL) /* Check using the system bootdev */

Add a simple app to use for testing. This is intended to do whatever it needs to for testing purposes. For now it just prints a message and exits boot services.
There was a considerable amount of discussion about whether it is OK to call exit-boot-services and then return to U-Boot. This is not normally done in a real application, since exit-boot-services is used to completely disconnect from U-Boot. For now, this part is skipped.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v10: - Drop call to exit-boot-services
Changes in v9: - Update license - Fix 'sevices' typo
Changes in v7: - Update commit message
lib/efi_loader/Kconfig | 10 +++++++ lib/efi_loader/Makefile | 1 + lib/efi_loader/testapp.c | 64 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 lib/efi_loader/testapp.c
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index 37572c82f54..44319729bda 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -584,6 +584,16 @@ config BOOTEFI_HELLO_COMPILE No additional space will be required in the resulting U-Boot binary when this option is enabled.
+config BOOTEFI_TESTAPP_COMPILE + bool "Compile an EFI test app for testing" + default y + help + This compiles an app designed for testing. It is packed into an image + by the test.py testing frame in the setup_efi_image() function. + + No additional space will be required in the resulting U-Boot binary + when this option is enabled. + endif
source "lib/efi/Kconfig" diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile index 8ec240cb864..7c8b2dd1ad6 100644 --- a/lib/efi_loader/Makefile +++ b/lib/efi_loader/Makefile @@ -20,6 +20,7 @@ apps-$(CONFIG_EFI_LOAD_FILE2_INITRD) += initrddump ifeq ($(CONFIG_GENERATE_ACPI_TABLE),) apps-y += dtbdump endif +apps-$(CONFIG_BOOTEFI_TESTAPP_COMPILE) += testapp
obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o obj-$(CONFIG_EFI_BOOTMGR) += efi_bootmgr.o diff --git a/lib/efi_loader/testapp.c b/lib/efi_loader/testapp.c new file mode 100644 index 00000000000..1a2f9ef9b6c --- /dev/null +++ b/lib/efi_loader/testapp.c @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Hello world EFI application + * + * Copyright 2024 Google LLC + * Written by Simon Glass sjg@chromium.org + * + * This test program is used to test the invocation of an EFI application. + * It writes a few messages to the console and then exits boot services + */ + +#include <efi_api.h> + +static const efi_guid_t loaded_image_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID; + +static struct efi_system_table *systable; +static struct efi_boot_services *boottime; +static struct efi_simple_text_output_protocol *con_out; + +/** + * efi_main() - entry point of the EFI application. + * + * @handle: handle of the loaded image + * @systab: system table + * Return: status code + */ +efi_status_t EFIAPI efi_main(efi_handle_t handle, + struct efi_system_table *systab) +{ + struct efi_loaded_image *loaded_image; + efi_status_t ret; + + systable = systab; + boottime = systable->boottime; + con_out = systable->con_out; + + /* Get the loaded image protocol */ + ret = boottime->open_protocol(handle, &loaded_image_guid, + (void **)&loaded_image, NULL, NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (ret != EFI_SUCCESS) { + con_out->output_string + (con_out, u"Cannot open loaded image protocol\r\n"); + goto out; + } + + /* UEFI requires CR LF */ + con_out->output_string(con_out, u"U-Boot test app for EFI_LOADER\r\n"); + +out: + /* + * TODO: exit boot services so that this part of U-Boot can be tested + * + * map_size = 0; + * ret = boottime->get_memory_map(&map_size, NULL, &map_key, &desc_size, + * &desc_version); + * boottime->exit_boot_services(handle, map_key); + */ + con_out->output_string(con_out, u"Exiting test app\n"); + ret = boottime->exit(handle, ret, 0, NULL); + + /* We should never arrive here */ + return ret; +}

Sandbox is its own architecture, but sometimes we want to mimic the host architecture, e.g. when running an EFI app not built by U-Boot.
Add a -N/--native flag which tells sandbox to reflect the architecture of the host.
Signed-off-by: Simon Glass sjg@chromium.org ---
(no changes since v8)
Changes in v8: - Add new patch to control on-host behaviour
arch/sandbox/cpu/start.c | 10 ++++++++++ arch/sandbox/include/asm/state.h | 1 + 2 files changed, 11 insertions(+)
diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c index 81752edc9f8..2940768cd1c 100644 --- a/arch/sandbox/cpu/start.c +++ b/arch/sandbox/cpu/start.c @@ -449,6 +449,16 @@ static void setup_ram_buf(struct sandbox_state *state) gd->ram_size = state->ram_size; }
+static int sandbox_cmdline_cb_native(struct sandbox_state *state, + const char *arg) +{ + state->native = true; + + return 0; +} +SANDBOX_CMDLINE_OPT_SHORT(native, 'N', 0, + "Use native mode (host-based EFI boot filename)"); + void state_show(struct sandbox_state *state) { char **p; diff --git a/arch/sandbox/include/asm/state.h b/arch/sandbox/include/asm/state.h index e7dc01759e8..dc21a623106 100644 --- a/arch/sandbox/include/asm/state.h +++ b/arch/sandbox/include/asm/state.h @@ -101,6 +101,7 @@ struct sandbox_state { bool disable_eth; /* Disable Ethernet devices */ bool disable_sf_bootdevs; /* Don't bind SPI flash bootdevs */ bool upl; /* Enable Universal Payload (UPL) */ + bool native; /* Adjust to reflect host arch */
/* Pointer to information for each SPI bus/cs */ struct sandbox_spi_info spi[CONFIG_SANDBOX_SPI_MAX_BUS]

Use a function to obtain the device EFI filename, so that we can control how sandbox behaves.
Signed-off-by: Simon Glass sjg@chromium.org ---
(no changes since v9)
Changes in v9: - Move the function into efi_helper.c
Changes in v8: - Add new patch to move default filename to a function
boot/bootmeth_efi.c | 4 +-- include/efi.h | 9 ++++++ include/efi_default_filename.h | 56 ---------------------------------- lib/efi_loader/efi_bootmgr.c | 10 ++++-- lib/efi_loader/efi_helper.c | 45 +++++++++++++++++++++++++++ test/boot/bootflow.c | 7 +++-- 6 files changed, 67 insertions(+), 64 deletions(-) delete mode 100644 include/efi_default_filename.h
diff --git a/boot/bootmeth_efi.c b/boot/bootmeth_efi.c index 2ad6d3b4ace..371b36d550b 100644 --- a/boot/bootmeth_efi.c +++ b/boot/bootmeth_efi.c @@ -13,7 +13,7 @@ #include <bootmeth.h> #include <command.h> #include <dm.h> -#include <efi_default_filename.h> +#include <efi.h> #include <efi_loader.h> #include <fs.h> #include <malloc.h> @@ -168,7 +168,7 @@ static int distro_efi_try_bootflow_files(struct udevice *dev, }
strcpy(fname, EFI_DIRNAME); - strcat(fname, BOOTEFI_NAME); + strcat(fname, efi_get_basename());
if (bflow->blk) desc = dev_get_uclass_plat(bflow->blk); diff --git a/include/efi.h b/include/efi.h index f7419b80d4d..fef88e9c5d6 100644 --- a/include/efi.h +++ b/include/efi.h @@ -670,4 +670,13 @@ int efi_get_mmap(struct efi_mem_desc **descp, int *sizep, uint *keyp, */ void efi_show_tables(struct efi_system_table *systab);
+/** + * efi_get_basename() - Get the default filename to use when loading + * + * E.g. this function returns BOOTAA64.EFI for an aarch target + * + * Return: Default EFI filename + */ +const char *efi_get_basename(void); + #endif /* _LINUX_EFI_H */ diff --git a/include/efi_default_filename.h b/include/efi_default_filename.h deleted file mode 100644 index 77932984b55..00000000000 --- a/include/efi_default_filename.h +++ /dev/null @@ -1,56 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * When a boot option does not provide a file path the EFI file to be - * booted is \EFI\BOOT$(BOOTEFI_NAME).EFI. The architecture specific - * file name is defined in this include. - * - * Copyright (c) 2022, Heinrich Schuchardt xypron.glpk@gmx.de - * Copyright (c) 2022, Linaro Limited - */ - -#ifndef _EFI_DEFAULT_FILENAME_H -#define _EFI_DEFAULT_FILENAME_H - -#include <host_arch.h> - -#undef BOOTEFI_NAME - -#ifdef CONFIG_SANDBOX - -#if HOST_ARCH == HOST_ARCH_X86_64 -#define BOOTEFI_NAME "BOOTX64.EFI" -#elif HOST_ARCH == HOST_ARCH_X86 -#define BOOTEFI_NAME "BOOTIA32.EFI" -#elif HOST_ARCH == HOST_ARCH_AARCH64 -#define BOOTEFI_NAME "BOOTAA64.EFI" -#elif HOST_ARCH == HOST_ARCH_ARM -#define BOOTEFI_NAME "BOOTARM.EFI" -#elif HOST_ARCH == HOST_ARCH_RISCV32 -#define BOOTEFI_NAME "BOOTRISCV32.EFI" -#elif HOST_ARCH == HOST_ARCH_RISCV64 -#define BOOTEFI_NAME "BOOTRISCV64.EFI" -#else -#error Unsupported UEFI architecture -#endif - -#else - -#if defined(CONFIG_ARM64) -#define BOOTEFI_NAME "BOOTAA64.EFI" -#elif defined(CONFIG_ARM) -#define BOOTEFI_NAME "BOOTARM.EFI" -#elif defined(CONFIG_X86_64) -#define BOOTEFI_NAME "BOOTX64.EFI" -#elif defined(CONFIG_X86) -#define BOOTEFI_NAME "BOOTIA32.EFI" -#elif defined(CONFIG_ARCH_RV32I) -#define BOOTEFI_NAME "BOOTRISCV32.EFI" -#elif defined(CONFIG_ARCH_RV64I) -#define BOOTEFI_NAME "BOOTRISCV64.EFI" -#else -#error Unsupported UEFI architecture -#endif - -#endif - -#endif diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index 431a38704e9..2ea20909491 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -11,10 +11,10 @@ #include <blkmap.h> #include <charset.h> #include <dm.h> +#include <efi.h> #include <log.h> #include <malloc.h> #include <net.h> -#include <efi_default_filename.h> #include <efi_loader.h> #include <efi_variable.h> #include <asm/unaligned.h> @@ -82,8 +82,12 @@ struct efi_device_path *expand_media_path(struct efi_device_path *device_path) &efi_simple_file_system_protocol_guid, &rem); if (handle) { if (rem->type == DEVICE_PATH_TYPE_END) { - full_path = efi_dp_from_file(device_path, - "/EFI/BOOT/" BOOTEFI_NAME); + char fname[30]; + + snprintf(fname, sizeof(fname), "/EFI/BOOT/%s", + efi_get_basename()); + full_path = efi_dp_from_file(device_path, fname); + } else { full_path = efi_dp_dup(device_path); } diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c index 00167bd2a10..51e0c4852c5 100644 --- a/lib/efi_loader/efi_helper.c +++ b/lib/efi_loader/efi_helper.c @@ -12,18 +12,63 @@ #include <mapmem.h> #include <dm.h> #include <fs.h> +#include <efi.h> #include <efi_api.h> #include <efi_load_initrd.h> #include <efi_loader.h> #include <efi_variable.h> +#include <host_arch.h> #include <linux/libfdt.h> #include <linux/list.h>
+#ifdef CONFIG_SANDBOX + +#if HOST_ARCH == HOST_ARCH_X86_64 +#define BOOTEFI_NAME "BOOTX64.EFI" +#elif HOST_ARCH == HOST_ARCH_X86 +#define BOOTEFI_NAME "BOOTIA32.EFI" +#elif HOST_ARCH == HOST_ARCH_AARCH64 +#define BOOTEFI_NAME "BOOTAA64.EFI" +#elif HOST_ARCH == HOST_ARCH_ARM +#define BOOTEFI_NAME "BOOTARM.EFI" +#elif HOST_ARCH == HOST_ARCH_RISCV32 +#define BOOTEFI_NAME "BOOTRISCV32.EFI" +#elif HOST_ARCH == HOST_ARCH_RISCV64 +#define BOOTEFI_NAME "BOOTRISCV64.EFI" +#else +#error Unsupported UEFI architecture +#endif + +#else + +#if defined(CONFIG_ARM64) +#define BOOTEFI_NAME "BOOTAA64.EFI" +#elif defined(CONFIG_ARM) +#define BOOTEFI_NAME "BOOTARM.EFI" +#elif defined(CONFIG_X86_64) +#define BOOTEFI_NAME "BOOTX64.EFI" +#elif defined(CONFIG_X86) +#define BOOTEFI_NAME "BOOTIA32.EFI" +#elif defined(CONFIG_ARCH_RV32I) +#define BOOTEFI_NAME "BOOTRISCV32.EFI" +#elif defined(CONFIG_ARCH_RV64I) +#define BOOTEFI_NAME "BOOTRISCV64.EFI" +#else +#error Unsupported UEFI architecture +#endif + +#endif + #if defined(CONFIG_CMD_EFIDEBUG) || defined(CONFIG_EFI_LOAD_FILE2_INITRD) /* GUID used by Linux to identify the LoadFile2 protocol with the initrd */ const efi_guid_t efi_lf2_initrd_guid = EFI_INITRD_MEDIA_GUID; #endif
+const char *efi_get_basename(void) +{ + return BOOTEFI_NAME; +} + /** * efi_create_current_boot_var() - Return Boot#### name were #### is replaced by * the value of BootCurrent diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c index 841729bd1ac..7cfb217088e 100644 --- a/test/boot/bootflow.c +++ b/test/boot/bootflow.c @@ -12,7 +12,7 @@ #include <bootstd.h> #include <cli.h> #include <dm.h> -#include <efi_default_filename.h> +#include <efi.h> #include <expo.h> #ifdef CONFIG_SANDBOX #include <asm/test.h> @@ -184,8 +184,9 @@ static int bootflow_cmd_scan_e(struct unit_test_state *uts) ut_assert_nextline(" 3 efi media mmc 0 mmc1.bootdev.whole "); ut_assert_nextline(" ** No partition found, err=-2: No such file or directory"); ut_assert_nextline(" 4 extlinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); - ut_assert_nextline(" 5 efi fs mmc 1 mmc1.bootdev.part_1 /EFI/BOOT/" - BOOTEFI_NAME); + ut_assert_nextline( + " 5 efi fs mmc 1 mmc1.bootdev.part_1 /EFI/BOOT/%s", + efi_get_basename());
ut_assert_skip_to_line("Scanning bootdev 'mmc0.bootdev':"); ut_assert_skip_to_line(

Move this function from the EFI bootmeth to the common efi_helper file. No functional change is intended.
Signed-off-by: Simon Glass sjg@chromium.org ---
(no changes since v9)
Changes in v9: - Split out into a separate change
boot/bootmeth_efi.c | 25 ++----------------------- include/efi.h | 10 ++++++++++ lib/efi_loader/efi_helper.c | 23 +++++++++++++++++++++++ 3 files changed, 35 insertions(+), 23 deletions(-)
diff --git a/boot/bootmeth_efi.c b/boot/bootmeth_efi.c index 371b36d550b..f836aa655f5 100644 --- a/boot/bootmeth_efi.c +++ b/boot/bootmeth_efi.c @@ -25,32 +25,11 @@
#define EFI_DIRNAME "/EFI/BOOT/"
-static int get_efi_pxe_arch(void) -{ - /* http://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xml */ - if (IS_ENABLED(CONFIG_ARM64)) - return 0xb; - else if (IS_ENABLED(CONFIG_ARM)) - return 0xa; - else if (IS_ENABLED(CONFIG_X86_64)) - return 0x6; - else if (IS_ENABLED(CONFIG_X86)) - return 0x7; - else if (IS_ENABLED(CONFIG_ARCH_RV32I)) - return 0x19; - else if (IS_ENABLED(CONFIG_ARCH_RV64I)) - return 0x1b; - else if (IS_ENABLED(CONFIG_SANDBOX)) - return 0; /* not used */ - - return -EINVAL; -} - static int get_efi_pxe_vci(char *str, int max_len) { int ret;
- ret = get_efi_pxe_arch(); + ret = efi_get_pxe_arch(); if (ret < 0) return ret;
@@ -239,7 +218,7 @@ static int distro_efi_read_bootflow_net(struct bootflow *bflow) ret = get_efi_pxe_vci(str, sizeof(str)); if (ret) return log_msg_ret("vci", ret); - ret = get_efi_pxe_arch(); + ret = efi_get_pxe_arch(); if (ret < 0) return log_msg_ret("arc", ret); arch = ret; diff --git a/include/efi.h b/include/efi.h index fef88e9c5d6..633f5b4acb5 100644 --- a/include/efi.h +++ b/include/efi.h @@ -679,4 +679,14 @@ void efi_show_tables(struct efi_system_table *systab); */ const char *efi_get_basename(void);
+/** + * efi_get_pxe_arch() - Get the architecture value for PXE + * + * See: + * http://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xml + * + * Return: Architecture value + */ +int efi_get_pxe_arch(void); + #endif /* _LINUX_EFI_H */ diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c index 51e0c4852c5..b8ece1c2e0c 100644 --- a/lib/efi_loader/efi_helper.c +++ b/lib/efi_loader/efi_helper.c @@ -21,6 +21,8 @@ #include <linux/libfdt.h> #include <linux/list.h>
+#undef BOOTEFI_NAME + #ifdef CONFIG_SANDBOX
#if HOST_ARCH == HOST_ARCH_X86_64 @@ -69,6 +71,27 @@ const char *efi_get_basename(void) return BOOTEFI_NAME; }
+int efi_get_pxe_arch(void) +{ + /* http://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xml */ + if (IS_ENABLED(CONFIG_ARM64)) + return 0xb; + else if (IS_ENABLED(CONFIG_ARM)) + return 0xa; + else if (IS_ENABLED(CONFIG_X86_64)) + return 0x6; + else if (IS_ENABLED(CONFIG_X86)) + return 0x7; + else if (IS_ENABLED(CONFIG_ARCH_RV32I)) + return 0x19; + else if (IS_ENABLED(CONFIG_ARCH_RV64I)) + return 0x1b; + else if (IS_ENABLED(CONFIG_SANDBOX)) + return 0; /* not used */ + + return -EINVAL; +} + /** * efi_create_current_boot_var() - Return Boot#### name were #### is replaced by * the value of BootCurrent

Add an 'efidebug filename' command to report the default filename and PXE architecture.
Signed-off-by: Simon Glass sjg@chromium.org ---
(no changes since v9)
Changes in v9: - Split out into its own patch
Changes in v8: - Add new patch to report host default-filename in native mode
cmd/efidebug.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
diff --git a/cmd/efidebug.c b/cmd/efidebug.c index bba984b2b75..ff6d118876d 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -536,6 +536,27 @@ static int do_efi_show_log(struct cmd_tbl *cmdtp, int flag, return CMD_RET_FAILURE; }
+ return 0; +} + +/** + * do_efi_show_defaults() - show UEFI default filename and PXE architecture + * + * @cmdtp: Command table + * @flag: Command flag + * @argc: Number of arguments + * @argv: Argument array + * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure + * + * Implement efidebug "defaults" sub-command. + * Shows the default EFI filename and PXE architecture + */ +static int do_efi_show_defaults(struct cmd_tbl *cmdtp, int flag, + int argc, char *const argv[]) +{ + printf("Default boot path: EFI\BOOT\%s\n", efi_get_basename()); + printf("PXE arch: 0x%02x\n", efi_get_pxe_arch()); + return CMD_RET_SUCCESS; }
@@ -1589,6 +1610,8 @@ static struct cmd_tbl cmd_efidebug_sub[] = { "", ""), U_BOOT_CMD_MKENT(dh, CONFIG_SYS_MAXARGS, 1, do_efi_show_handles, "", ""), + U_BOOT_CMD_MKENT(defaults, CONFIG_SYS_MAXARGS, 1, do_efi_show_defaults, + "", ""), U_BOOT_CMD_MKENT(images, CONFIG_SYS_MAXARGS, 1, do_efi_show_images, "", ""), U_BOOT_CMD_MKENT(log, CONFIG_SYS_MAXARGS, 1, do_efi_show_log, "", ""), @@ -1688,6 +1711,8 @@ U_BOOT_LONGHELP(efidebug, " - show UEFI drivers\n" "efidebug dh\n" " - show UEFI handles\n" + "efidebug defaults\n" + " - show default EFI filename and PXE architecture\n" "efidebug images\n" " - show loaded images\n" "efidebug log\n"

On 11/1/24 16:26, Simon Glass wrote:
Add an 'efidebug filename' command to report the default filename and PXE architecture.
Signed-off-by: Simon Glass sjg@chromium.org
(no changes since v9)
Changes in v9:
- Split out into its own patch
Changes in v8:
Add new patch to report host default-filename in native mode
cmd/efidebug.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
diff --git a/cmd/efidebug.c b/cmd/efidebug.c index bba984b2b75..ff6d118876d 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -536,6 +536,27 @@ static int do_efi_show_log(struct cmd_tbl *cmdtp, int flag, return CMD_RET_FAILURE; }
- return 0;
+}
+/**
- do_efi_show_defaults() - show UEFI default filename and PXE architecture
- @cmdtp: Command table
- @flag: Command flag
- @argc: Number of arguments
- @argv: Argument array
- Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
- Implement efidebug "defaults" sub-command.
- Shows the default EFI filename and PXE architecture
- */
+static int do_efi_show_defaults(struct cmd_tbl *cmdtp, int flag,
int argc, char *const argv[])
+{
- printf("Default boot path: EFI\BOOT\%s\n", efi_get_basename());
- printf("PXE arch: 0x%02x\n", efi_get_pxe_arch());
- return CMD_RET_SUCCESS; }
This should not be guarded by #ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT Otherwise build errors occur on some platforms.
I will move that function behind the corresponding #endif.
Best regards
Heinrich
@@ -1589,6 +1610,8 @@ static struct cmd_tbl cmd_efidebug_sub[] = { "", ""), U_BOOT_CMD_MKENT(dh, CONFIG_SYS_MAXARGS, 1, do_efi_show_handles, "", ""),
- U_BOOT_CMD_MKENT(defaults, CONFIG_SYS_MAXARGS, 1, do_efi_show_defaults,
U_BOOT_CMD_MKENT(images, CONFIG_SYS_MAXARGS, 1, do_efi_show_images, "", ""), U_BOOT_CMD_MKENT(log, CONFIG_SYS_MAXARGS, 1, do_efi_show_log, "", ""),"", ""),
@@ -1688,6 +1711,8 @@ U_BOOT_LONGHELP(efidebug, " - show UEFI drivers\n" "efidebug dh\n" " - show UEFI handles\n"
- "efidebug defaults\n"
- " - show default EFI filename and PXE architecture\n" "efidebug images\n" " - show loaded images\n" "efidebug log\n"

When the --native flag is given, pretend to be running the host architecture rather than sandbox.
Allow the same control for PXE too.
Signed-off-by: Simon Glass sjg@chromium.org ---
(no changes since v9)
Changes in v9: - Separate into separate patches
Changes in v8: - Add new patch to report host default-filename in native mode
include/efi.h | 15 +++++++++++++++ lib/efi_loader/efi_helper.c | 35 ++++++++++++++++++++--------------- 2 files changed, 35 insertions(+), 15 deletions(-)
diff --git a/include/efi.h b/include/efi.h index 633f5b4acb5..817bc56c835 100644 --- a/include/efi.h +++ b/include/efi.h @@ -679,6 +679,21 @@ void efi_show_tables(struct efi_system_table *systab); */ const char *efi_get_basename(void);
+#ifdef CONFIG_SANDBOX +#include <asm/state.h> +#endif + +static inline bool efi_use_host_arch(void) +{ +#ifdef CONFIG_SANDBOX + struct sandbox_state *state = state_get_current(); + + return state->native; +#else + return false; +#endif +} + /** * efi_get_pxe_arch() - Get the architecture value for PXE * diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c index b8ece1c2e0c..ab5678eb66c 100644 --- a/lib/efi_loader/efi_helper.c +++ b/lib/efi_loader/efi_helper.c @@ -23,27 +23,31 @@
#undef BOOTEFI_NAME
-#ifdef CONFIG_SANDBOX - #if HOST_ARCH == HOST_ARCH_X86_64 -#define BOOTEFI_NAME "BOOTX64.EFI" +#define HOST_BOOTEFI_NAME "BOOTX64.EFI" +#define HOST_PXE_ARCH 0x6 #elif HOST_ARCH == HOST_ARCH_X86 -#define BOOTEFI_NAME "BOOTIA32.EFI" +#define HOST_BOOTEFI_NAME "BOOTIA32.EFI" +#define HOST_PXE_ARCH 0x7 #elif HOST_ARCH == HOST_ARCH_AARCH64 -#define BOOTEFI_NAME "BOOTAA64.EFI" +#define HOST_BOOTEFI_NAME "BOOTAA64.EFI" +#define HOST_PXE_ARCH 0xb #elif HOST_ARCH == HOST_ARCH_ARM -#define BOOTEFI_NAME "BOOTARM.EFI" +#define HOST_BOOTEFI_NAME "BOOTARM.EFI" +#define HOST_PXE_ARCH 0xa #elif HOST_ARCH == HOST_ARCH_RISCV32 -#define BOOTEFI_NAME "BOOTRISCV32.EFI" +#define HOST_BOOTEFI_NAME "BOOTRISCV32.EFI" +#define HOST_PXE_ARCH 0x19 #elif HOST_ARCH == HOST_ARCH_RISCV64 -#define BOOTEFI_NAME "BOOTRISCV64.EFI" +#define HOST_BOOTEFI_NAME "BOOTRISCV64.EFI" +#define HOST_PXE_ARCH 0x1b #else -#error Unsupported UEFI architecture +#error Unsupported Host architecture #endif
-#else - -#if defined(CONFIG_ARM64) +#if defined(CONFIG_SANDBOX) +#define BOOTEFI_NAME "BOOTSBOX.EFI" +#elif defined(CONFIG_ARM64) #define BOOTEFI_NAME "BOOTAA64.EFI" #elif defined(CONFIG_ARM) #define BOOTEFI_NAME "BOOTARM.EFI" @@ -59,8 +63,6 @@ #error Unsupported UEFI architecture #endif
-#endif - #if defined(CONFIG_CMD_EFIDEBUG) || defined(CONFIG_EFI_LOAD_FILE2_INITRD) /* GUID used by Linux to identify the LoadFile2 protocol with the initrd */ const efi_guid_t efi_lf2_initrd_guid = EFI_INITRD_MEDIA_GUID; @@ -68,11 +70,14 @@ const efi_guid_t efi_lf2_initrd_guid = EFI_INITRD_MEDIA_GUID;
const char *efi_get_basename(void) { - return BOOTEFI_NAME; + return efi_use_host_arch() ? HOST_BOOTEFI_NAME : BOOTEFI_NAME; }
int efi_get_pxe_arch(void) { + if (efi_use_host_arch()) + return HOST_PXE_ARCH; + /* http://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xml */ if (IS_ENABLED(CONFIG_ARM64)) return 0xb;

Rather than returning 0, just return an error, since sandbox is not used with PXE at present.
Signed-off-by: Simon Glass sjg@chromium.org ---
(no changes since v9)
Changes in v9: - Add new patch to drop sandbox PXE architecture
lib/efi_loader/efi_helper.c | 2 -- 1 file changed, 2 deletions(-)
diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c index ab5678eb66c..bf96f61d3d0 100644 --- a/lib/efi_loader/efi_helper.c +++ b/lib/efi_loader/efi_helper.c @@ -91,8 +91,6 @@ int efi_get_pxe_arch(void) return 0x19; else if (IS_ENABLED(CONFIG_ARCH_RV64I)) return 0x1b; - else if (IS_ENABLED(CONFIG_SANDBOX)) - return 0; /* not used */
return -EINVAL; }

On Fri, Nov 01, 2024 at 04:26:06PM +0100, Simon Glass wrote:
Rather than returning 0, just return an error, since sandbox is not used with PXE at present.
Signed-off-by: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

This is not implemented so cannot actually be used to read blocks. Disable it until it is implemented, to avoid causing a hang with EFI, which probes every available BLK device.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com Issue: https://source.denx.de/u-boot/u-boot/-/issues/37 ---
(no changes since v6)
Changes in v6: - Drop the patch to disable sandbox virtio blk with EFI - Add new patch to disable the sandbox virtio blk device
arch/Kconfig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/Kconfig b/arch/Kconfig index 8f1f4667012..c39efb4d0a2 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -212,7 +212,8 @@ config SANDBOX imply VIRTIO_MMIO imply VIRTIO_PCI imply VIRTIO_SANDBOX - imply VIRTIO_BLK + # Re-enable this when fully implemented + # imply VIRTIO_BLK imply VIRTIO_NET imply DM_SOUND imply PCI_SANDBOX_EP

Create a new disk for use with tests, which contains the new 'testapp' EFI app specifically intended for testing the EFI loader.
Attach it to the USB device, since most testing is currently done with mmc.
Initially this image will be used to test the EFI bootmeth.
Fix a stale comment in prep_mmc_bootdev() while we are here.
For now this uses sudo and a compressed fallback file, like all the other bootstd tests. Once this series is in, the patch which moves this to use user-space tools will be cleaned up and re-submitted.
Signed-off-by: Simon Glass sjg@chromium.org
--- Here is the patch to avoid sudo and CI fallback:
[1] https://patchwork.ozlabs.org/project/uboot/patch/ 20240802093322.15240-1-richard@nod.at/
(no changes since v9)
Changes in v9: - Mark the image as complete after writing it
arch/sandbox/dts/test.dts | 2 +- test/boot/bootdev.c | 18 +++++++++- test/boot/bootflow.c | 2 +- test/py/tests/bootstd/flash1.img.xz | Bin 0 -> 4924 bytes test/py/tests/test_ut.py | 53 ++++++++++++++++++++++++---- 5 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 test/py/tests/bootstd/flash1.img.xz
diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 3017b33d67b..dee280184b1 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -1515,7 +1515,7 @@ flash-stick@1 { reg = <1>; compatible = "sandbox,usb-flash"; - sandbox,filepath = "testflash1.bin"; + sandbox,filepath = "flash1.img"; };
flash-stick@2 { diff --git a/test/boot/bootdev.c b/test/boot/bootdev.c index 369105ca4cf..c892854b227 100644 --- a/test/boot/bootdev.c +++ b/test/boot/bootdev.c @@ -221,6 +221,10 @@ static int bootdev_test_order(struct unit_test_state *uts) /* Use the environment variable to override it */ ut_assertok(env_set("boot_targets", "mmc1 mmc2 usb")); ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow)); + + /* get the usb device which has a backing file (flash1.img) */ + ut_asserteq(0, bootflow_scan_next(&iter, &bflow)); + ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow)); ut_asserteq(5, iter.num_devs); ut_asserteq_str("mmc1.bootdev", iter.dev_used[0]->name); @@ -260,7 +264,11 @@ static int bootdev_test_order(struct unit_test_state *uts) ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow)); ut_asserteq(2, iter.num_devs);
- /* Now scan past mmc1 and make sure that the 3 USB devices show up */ + /* + * Now scan past mmc1 and make sure that the 3 USB devices show up. The + * first one has a backing file so returns success + */ + ut_asserteq(0, bootflow_scan_next(&iter, &bflow)); ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow)); ut_asserteq(6, iter.num_devs); ut_asserteq_str("mmc2.bootdev", iter.dev_used[0]->name); @@ -322,6 +330,10 @@ static int bootdev_test_prio(struct unit_test_state *uts)
/* 3 MMC and 3 USB bootdevs: MMC should come before USB */ ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow)); + + /* get the usb device which has a backing file (flash1.img) */ + ut_asserteq(0, bootflow_scan_next(&iter, &bflow)); + ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow)); ut_asserteq(6, iter.num_devs); ut_asserteq_str("mmc2.bootdev", iter.dev_used[0]->name); @@ -339,6 +351,10 @@ static int bootdev_test_prio(struct unit_test_state *uts) bootflow_iter_uninit(&iter); ut_assertok(bootflow_scan_first(NULL, NULL, &iter, BOOTFLOWIF_HUNT, &bflow)); + + /* get the usb device which has a backing file (flash1.img) */ + ut_asserteq(0, bootflow_scan_next(&iter, &bflow)); + ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow)); ut_asserteq(7, iter.num_devs); ut_asserteq_str("usb_mass_storage.lun0.bootdev", diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c index 7cfb217088e..d7e94c8cc59 100644 --- a/test/boot/bootflow.c +++ b/test/boot/bootflow.c @@ -534,7 +534,7 @@ static int prep_mmc_bootdev(struct unit_test_state *uts, const char *mmc_dev,
order[2] = mmc_dev;
- /* Enable the mmc4 node since we need a second bootflow */ + /* Enable the requested mmc node since we need a second bootflow */ root = oftree_root(oftree_default()); node = ofnode_find_subnode(root, mmc_dev); ut_assert(ofnode_valid(node)); diff --git a/test/py/tests/bootstd/flash1.img.xz b/test/py/tests/bootstd/flash1.img.xz new file mode 100644 index 0000000000000000000000000000000000000000..29b78c62a9bf264fa8b795b82b432bf3ab4e2765 GIT binary patch literal 4924 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 YhlPdFIp0xdukLa_CjZAFrJ4EP0QdZp5dZ)H
literal 0 HcmV?d00001
diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index 39aa1035e34..9b54f941014 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -28,21 +28,22 @@ def mkdir_cond(dirname): if not os.path.exists(dirname): os.mkdir(dirname)
-def setup_image(cons, mmc_dev, part_type, second_part=False): +def setup_image(cons, devnum, part_type, second_part=False, basename='mmc'): """Create a 20MB disk image with a single partition
Args: cons (ConsoleBase): Console to use - mmc_dev (int): MMC device number to use, e.g. 1 + devnum (int): Device number to use, e.g. 1 part_type (int): Partition type, e.g. 0xc for FAT32 second_part (bool): True to contain a small second partition + basename (str): Base name to use in the filename, e.g. 'mmc'
Returns: tuple: str: Filename of MMC image str: Directory name of 'mnt' directory """ - fname = os.path.join(cons.config.source_dir, f'mmc{mmc_dev}.img') + fname = os.path.join(cons.config.source_dir, f'{basename}{devnum}.img') mnt = os.path.join(cons.config.persistent_data_dir, 'mnt') mkdir_cond(mnt)
@@ -78,16 +79,17 @@ def mount_image(cons, fname, mnt, fstype): u_boot_utils.run_and_log(cons, f'sudo chown {getpass.getuser()} {mnt}') return loop
-def copy_prepared_image(cons, mmc_dev, fname): +def copy_prepared_image(cons, devnum, fname, basename='mmc'): """Use a prepared image since we cannot create one
Args: cons (ConsoleBase): Console touse - mmc_dev (int): MMC device number + devnum (int): device number fname (str): Filename of MMC image + basename (str): Base name to use in the filename, e.g. 'mmc' """ infname = os.path.join(cons.config.source_dir, - f'test/py/tests/bootstd/mmc{mmc_dev}.img.xz') + f'test/py/tests/bootstd/{basename}{devnum}.img.xz') u_boot_utils.run_and_log(cons, ['sh', '-c', f'xz -dc {infname} >{fname}'])
def setup_bootmenu_image(cons): @@ -549,6 +551,44 @@ def test_ut_dm_init(u_boot_console): with open(fn, 'wb') as fh: fh.write(data)
+ +def setup_efi_image(cons): + """Create a 20MB disk image with an EFI app on it""" + devnum = 1 + basename = 'flash' + fname, mnt = setup_image(cons, devnum, 0xc, second_part=True, + basename=basename) + + loop = None + mounted = False + complete = False + try: + loop = mount_image(cons, fname, mnt, 'ext4') + mounted = True + efi_dir = os.path.join(mnt, 'EFI') + mkdir_cond(efi_dir) + bootdir = os.path.join(efi_dir, 'BOOT') + mkdir_cond(bootdir) + efi_src = os.path.join(cons.config.build_dir, + f'lib/efi_loader/testapp.efi') + efi_dst = os.path.join(bootdir, 'BOOTSBOX.EFI') + with open(efi_src, 'rb') as inf: + with open(efi_dst, 'wb') as outf: + outf.write(inf.read()) + complete = True + except ValueError as exc: + print(f'Falled to create image, failing back to prepared copy: {exc}') + + finally: + if mounted: + u_boot_utils.run_and_log(cons, 'sudo umount --lazy %s' % mnt) + if loop: + u_boot_utils.run_and_log(cons, 'sudo losetup -d %s' % loop) + + if not complete: + copy_prepared_image(cons, devnum, fname, basename) + + @pytest.mark.buildconfigspec('cmd_bootflow') @pytest.mark.buildconfigspec('sandbox') def test_ut_dm_init_bootstd(u_boot_console): @@ -559,6 +599,7 @@ def test_ut_dm_init_bootstd(u_boot_console): setup_cedit_file(u_boot_console) setup_cros_image(u_boot_console) setup_android_image(u_boot_console) + setup_efi_image(u_boot_console)
# Restart so that the new mmc1.img is picked up u_boot_console.restart_uboot()

Add a simple test of booting with the EFI bootmeth, which runs the app and checks that it can call 'exit boot-services' (to check that all the device-removal code doesn't break anything) and then exit back to U-Boot.
This uses a disk image containing the testapp, ready for execution by sandbox when needed.
Signed-off-by: Simon Glass sjg@chromium.org
--- Note that this uses the same mechanism as for the other images which are created. Once this series lands I will update[1] and revisit.
[1] https://patchwork.ozlabs.org/project/uboot/patch/ 20240802093322.15240-1-richard@nod.at/
(no changes since v9)
Changes in v9: - Fix 'sevices' typo
Changes in v7: - Drop patches already applied - Drop patch 'Disable ANSI output for tests' - Rebase on -master
Changes in v6: - Deal with sandbox CONFIG_LOGF_FUNC - Rebase on -next - Drop patches previously applied - Drop mention of helloworld since it is no-longer used by this test
Changes in v4: - Add efi_loader tag to some patches - Split out non-EFI patches into a different series
Changes in v2: - Add many new patches to resolve all the outstanding test issues
test/boot/bootflow.c | 56 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+)
diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c index d7e94c8cc59..df2caa91693 100644 --- a/test/boot/bootflow.c +++ b/test/boot/bootflow.c @@ -13,6 +13,7 @@ #include <cli.h> #include <dm.h> #include <efi.h> +#include <efi_loader.h> #include <expo.h> #ifdef CONFIG_SANDBOX #include <asm/test.h> @@ -31,6 +32,9 @@ extern U_BOOT_DRIVER(bootmeth_android); extern U_BOOT_DRIVER(bootmeth_cros); extern U_BOOT_DRIVER(bootmeth_2script);
+/* Use this as the vendor for EFI to tell the app to exit boot services */ +static u16 __efi_runtime_data test_vendor[] = u"U-Boot testing"; + static int inject_response(struct unit_test_state *uts) { /* @@ -1217,3 +1221,55 @@ static int bootflow_android(struct unit_test_state *uts) return 0; } BOOTSTD_TEST(bootflow_android, UTF_CONSOLE); + +/* Test EFI bootmeth */ +static int bootflow_efi(struct unit_test_state *uts) +{ + /* disable ethernet since the hunter will run dhcp */ + test_set_eth_enable(false); + + /* make USB scan without delays */ + test_set_skip_delays(true); + + bootstd_reset_usb(); + + ut_assertok(bootstd_test_drop_bootdev_order(uts)); + ut_assertok(run_command("bootflow scan", 0)); + ut_assert_skip_to_line( + "Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found"); + + ut_assertok(run_command("bootflow list", 0)); + + ut_assert_nextlinen("Showing all"); + ut_assert_nextlinen("Seq"); + ut_assert_nextlinen("---"); + ut_assert_nextlinen(" 0 extlinux"); + ut_assert_nextlinen( + " 1 efi ready usb_mass_ 1 usb_mass_storage.lun0.boo /EFI/BOOT/BOOTSBOX.EFI"); + ut_assert_nextlinen("---"); + ut_assert_skip_to_line("(2 bootflows, 2 valid)"); + ut_assert_console_end(); + + ut_assertok(run_command("bootflow select 1", 0)); + ut_assert_console_end(); + + systab.fw_vendor = test_vendor; + + ut_asserteq(1, run_command("bootflow boot", 0)); + ut_assert_nextline( + "** Booting bootflow 'usb_mass_storage.lun0.bootdev.part_1' with efi"); + if (IS_ENABLED(CONFIG_LOGF_FUNC)) + ut_assert_skip_to_line(" efi_run_image() Booting /\EFI\BOOT\BOOTSBOX.EFI"); + else + ut_assert_skip_to_line("Booting /\EFI\BOOT\BOOTSBOX.EFI"); + + /* TODO: Why the \r ? */ + ut_assert_nextline("U-Boot test app for EFI_LOADER\r"); + ut_assert_nextline("Exiting test app"); + ut_assert_nextline("Boot failed (err=-14)"); + + ut_assert_console_end(); + + return 0; +} +BOOTSTD_TEST(bootflow_efi, UTF_CONSOLE);

Hi all,
On Fri, 1 Nov 2024 at 16:26, Simon Glass sjg@chromium.org wrote:
The test coverage for the EFI bootmeth is incomplete since it does not actually boot the application.
This series creates a simple test for this purpose. It includes a few patches to make this work:
- Revert of an unreviewed patch to change the sandbox efi filename
- Hang in sandbox virtio due to EFI probing all block devices
Other necessary fixes have already been applied.
Changes in v10:
- Drop call to exit-boot-services
Changes in v9:
- Update license
- Fix 'sevices' typo
- Move the function into efi_helper.c
- Split out into a separate change
- Split out into its own patch
- Separate into separate patches
- Add new patch to drop sandbox PXE architecture
- Mark the image as complete after writing it
- Fix 'sevices' typo
Changes in v8:
- Add new patch to control on-host behaviour
- Add new patch to move default filename to a function
- Add new patch to report host default-filename in native mode
- Add new patch to report host default-filename in native mode
Changes in v7:
- Update commit message
- Drop patches already applied
- Drop patch 'Disable ANSI output for tests'
- Rebase on -master
Changes in v6:
- Drop the patch to disable sandbox virtio blk with EFI
- Add new patch to disable the sandbox virtio blk device
- Deal with sandbox CONFIG_LOGF_FUNC
- Rebase on -next
- Drop patches previously applied
- Drop mention of helloworld since it is no-longer used by this test
Changes in v4:
- Add efi_loader tag to some patches
- Split out non-EFI patches into a different series
Changes in v2:
- Add many new patches to resolve all the outstanding test issues
Simon Glass (11): test: boot: Update bootflow_iter() for console checking efi_loader: Add a test app sandbox: Add a -N flag to control on-host behaviour efi: Move default filename to a function efi_loader: Move get_efi_pxe_arch() to efi_helper efi_loader: Allow reporting the host defaults sandbox: Report host default-filename in native mode efi_loader: Drop sandbox PXE architecture sandbox: virtio: Disable the sandbox virtio blk device test: efi: boot: Set up an image suitable for EFI testing test: efi: boot: Add a test for the efi bootmeth
arch/Kconfig | 3 +- arch/sandbox/cpu/start.c | 10 ++++ arch/sandbox/dts/test.dts | 2 +- arch/sandbox/include/asm/state.h | 1 + boot/bootmeth_efi.c | 29 ++---------- cmd/efidebug.c | 25 ++++++++++ include/efi.h | 34 +++++++++++++ include/efi_default_filename.h | 56 ---------------------- lib/efi_loader/Kconfig | 10 ++++ lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_bootmgr.c | 10 ++-- lib/efi_loader/efi_helper.c | 71 ++++++++++++++++++++++++++++ lib/efi_loader/testapp.c | 64 +++++++++++++++++++++++++ test/boot/bootdev.c | 18 ++++++- test/boot/bootflow.c | 67 ++++++++++++++++++++++++-- test/py/tests/bootstd/flash1.img.xz | Bin 0 -> 4924 bytes test/py/tests/test_ut.py | 53 ++++++++++++++++++--- 17 files changed, 356 insertions(+), 98 deletions(-) delete mode 100644 include/efi_default_filename.h create mode 100644 lib/efi_loader/testapp.c create mode 100644 test/py/tests/bootstd/flash1.img.xz
I hope this series can meet with approval and go in. I know it isn't perfect, but we can then work on things from there. The first thing is to drop the various .xz files, which I'll look at once this lands.
Regards, Simon

Hi,
On Fri, 1 Nov 2024 at 09:32, Simon Glass sjg@chromium.org wrote:
Hi all,
On Fri, 1 Nov 2024 at 16:26, Simon Glass sjg@chromium.org wrote:
The test coverage for the EFI bootmeth is incomplete since it does not actually boot the application.
This series creates a simple test for this purpose. It includes a few patches to make this work:
- Revert of an unreviewed patch to change the sandbox efi filename
- Hang in sandbox virtio due to EFI probing all block devices
Other necessary fixes have already been applied.
Changes in v10:
- Drop call to exit-boot-services
Changes in v9:
- Update license
- Fix 'sevices' typo
- Move the function into efi_helper.c
- Split out into a separate change
- Split out into its own patch
- Separate into separate patches
- Add new patch to drop sandbox PXE architecture
- Mark the image as complete after writing it
- Fix 'sevices' typo
Changes in v8:
- Add new patch to control on-host behaviour
- Add new patch to move default filename to a function
- Add new patch to report host default-filename in native mode
- Add new patch to report host default-filename in native mode
Changes in v7:
- Update commit message
- Drop patches already applied
- Drop patch 'Disable ANSI output for tests'
- Rebase on -master
Changes in v6:
- Drop the patch to disable sandbox virtio blk with EFI
- Add new patch to disable the sandbox virtio blk device
- Deal with sandbox CONFIG_LOGF_FUNC
- Rebase on -next
- Drop patches previously applied
- Drop mention of helloworld since it is no-longer used by this test
Changes in v4:
- Add efi_loader tag to some patches
- Split out non-EFI patches into a different series
Changes in v2:
- Add many new patches to resolve all the outstanding test issues
Simon Glass (11): test: boot: Update bootflow_iter() for console checking efi_loader: Add a test app sandbox: Add a -N flag to control on-host behaviour efi: Move default filename to a function efi_loader: Move get_efi_pxe_arch() to efi_helper efi_loader: Allow reporting the host defaults sandbox: Report host default-filename in native mode efi_loader: Drop sandbox PXE architecture sandbox: virtio: Disable the sandbox virtio blk device test: efi: boot: Set up an image suitable for EFI testing test: efi: boot: Add a test for the efi bootmeth
arch/Kconfig | 3 +- arch/sandbox/cpu/start.c | 10 ++++ arch/sandbox/dts/test.dts | 2 +- arch/sandbox/include/asm/state.h | 1 + boot/bootmeth_efi.c | 29 ++---------- cmd/efidebug.c | 25 ++++++++++ include/efi.h | 34 +++++++++++++ include/efi_default_filename.h | 56 ---------------------- lib/efi_loader/Kconfig | 10 ++++ lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_bootmgr.c | 10 ++-- lib/efi_loader/efi_helper.c | 71 ++++++++++++++++++++++++++++ lib/efi_loader/testapp.c | 64 +++++++++++++++++++++++++ test/boot/bootdev.c | 18 ++++++- test/boot/bootflow.c | 67 ++++++++++++++++++++++++-- test/py/tests/bootstd/flash1.img.xz | Bin 0 -> 4924 bytes test/py/tests/test_ut.py | 53 ++++++++++++++++++--- 17 files changed, 356 insertions(+), 98 deletions(-) delete mode 100644 include/efi_default_filename.h create mode 100644 lib/efi_loader/testapp.c create mode 100644 test/py/tests/bootstd/flash1.img.xz
I hope this series can meet with approval and go in. I know it isn't perfect, but we can then work on things from there. The first thing is to drop the various .xz files, which I'll look at once this lands.
We are coming up on rc2 and I believe this should go in before that. Does anyone have any objections or changes? If not I will pull it.
Regards, Simon

On 11/1/24 16:32, Simon Glass wrote:
Hi all,
On Fri, 1 Nov 2024 at 16:26, Simon Glass sjg@chromium.org wrote:
The test coverage for the EFI bootmeth is incomplete since it does not actually boot the application.
This series creates a simple test for this purpose. It includes a few patches to make this work:
- Revert of an unreviewed patch to change the sandbox efi filename
- Hang in sandbox virtio due to EFI probing all block devices
Other necessary fixes have already been applied.
Changes in v10:
- Drop call to exit-boot-services
Changes in v9:
- Update license
- Fix 'sevices' typo
- Move the function into efi_helper.c
- Split out into a separate change
- Split out into its own patch
- Separate into separate patches
- Add new patch to drop sandbox PXE architecture
- Mark the image as complete after writing it
- Fix 'sevices' typo
Changes in v8:
- Add new patch to control on-host behaviour
- Add new patch to move default filename to a function
- Add new patch to report host default-filename in native mode
- Add new patch to report host default-filename in native mode
Changes in v7:
- Update commit message
- Drop patches already applied
- Drop patch 'Disable ANSI output for tests'
- Rebase on -master
Changes in v6:
- Drop the patch to disable sandbox virtio blk with EFI
- Add new patch to disable the sandbox virtio blk device
- Deal with sandbox CONFIG_LOGF_FUNC
- Rebase on -next
- Drop patches previously applied
- Drop mention of helloworld since it is no-longer used by this test
Changes in v4:
- Add efi_loader tag to some patches
- Split out non-EFI patches into a different series
Changes in v2:
- Add many new patches to resolve all the outstanding test issues
Simon Glass (11): test: boot: Update bootflow_iter() for console checking efi_loader: Add a test app sandbox: Add a -N flag to control on-host behaviour efi: Move default filename to a function efi_loader: Move get_efi_pxe_arch() to efi_helper efi_loader: Allow reporting the host defaults sandbox: Report host default-filename in native mode efi_loader: Drop sandbox PXE architecture sandbox: virtio: Disable the sandbox virtio blk device test: efi: boot: Set up an image suitable for EFI testing test: efi: boot: Add a test for the efi bootmeth
arch/Kconfig | 3 +- arch/sandbox/cpu/start.c | 10 ++++ arch/sandbox/dts/test.dts | 2 +- arch/sandbox/include/asm/state.h | 1 + boot/bootmeth_efi.c | 29 ++---------- cmd/efidebug.c | 25 ++++++++++ include/efi.h | 34 +++++++++++++ include/efi_default_filename.h | 56 ---------------------- lib/efi_loader/Kconfig | 10 ++++ lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_bootmgr.c | 10 ++-- lib/efi_loader/efi_helper.c | 71 ++++++++++++++++++++++++++++ lib/efi_loader/testapp.c | 64 +++++++++++++++++++++++++ test/boot/bootdev.c | 18 ++++++- test/boot/bootflow.c | 67 ++++++++++++++++++++++++-- test/py/tests/bootstd/flash1.img.xz | Bin 0 -> 4924 bytes test/py/tests/test_ut.py | 53 ++++++++++++++++++--- 17 files changed, 356 insertions(+), 98 deletions(-) delete mode 100644 include/efi_default_filename.h create mode 100644 lib/efi_loader/testapp.c create mode 100644 test/py/tests/bootstd/flash1.img.xz
I hope this series can meet with approval and go in. I know it isn't perfect, but we can then work on things from there. The first thing is to drop the various .xz files, which I'll look at once this lands.
Regards, Simon
I tried to apply the series. But it fails in the CI.
https://source.denx.de/u-boot/custodians/u-boot-efi/-/jobs/941546
Best regards
Heinrich

Hi Heinrich,
On Thu, 7 Nov 2024 at 04:29, Heinrich Schuchardt xypron.glpk@gmx.de wrote:
On 11/1/24 16:32, Simon Glass wrote:
Hi all,
On Fri, 1 Nov 2024 at 16:26, Simon Glass sjg@chromium.org wrote:
The test coverage for the EFI bootmeth is incomplete since it does not actually boot the application.
This series creates a simple test for this purpose. It includes a few patches to make this work:
- Revert of an unreviewed patch to change the sandbox efi filename
- Hang in sandbox virtio due to EFI probing all block devices
Other necessary fixes have already been applied.
Changes in v10:
- Drop call to exit-boot-services
Changes in v9:
- Update license
- Fix 'sevices' typo
- Move the function into efi_helper.c
- Split out into a separate change
- Split out into its own patch
- Separate into separate patches
- Add new patch to drop sandbox PXE architecture
- Mark the image as complete after writing it
- Fix 'sevices' typo
Changes in v8:
- Add new patch to control on-host behaviour
- Add new patch to move default filename to a function
- Add new patch to report host default-filename in native mode
- Add new patch to report host default-filename in native mode
Changes in v7:
- Update commit message
- Drop patches already applied
- Drop patch 'Disable ANSI output for tests'
- Rebase on -master
Changes in v6:
- Drop the patch to disable sandbox virtio blk with EFI
- Add new patch to disable the sandbox virtio blk device
- Deal with sandbox CONFIG_LOGF_FUNC
- Rebase on -next
- Drop patches previously applied
- Drop mention of helloworld since it is no-longer used by this test
Changes in v4:
- Add efi_loader tag to some patches
- Split out non-EFI patches into a different series
Changes in v2:
- Add many new patches to resolve all the outstanding test issues
Simon Glass (11): test: boot: Update bootflow_iter() for console checking efi_loader: Add a test app sandbox: Add a -N flag to control on-host behaviour efi: Move default filename to a function efi_loader: Move get_efi_pxe_arch() to efi_helper efi_loader: Allow reporting the host defaults sandbox: Report host default-filename in native mode efi_loader: Drop sandbox PXE architecture sandbox: virtio: Disable the sandbox virtio blk device test: efi: boot: Set up an image suitable for EFI testing test: efi: boot: Add a test for the efi bootmeth
arch/Kconfig | 3 +- arch/sandbox/cpu/start.c | 10 ++++ arch/sandbox/dts/test.dts | 2 +- arch/sandbox/include/asm/state.h | 1 + boot/bootmeth_efi.c | 29 ++---------- cmd/efidebug.c | 25 ++++++++++ include/efi.h | 34 +++++++++++++ include/efi_default_filename.h | 56 ---------------------- lib/efi_loader/Kconfig | 10 ++++ lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_bootmgr.c | 10 ++-- lib/efi_loader/efi_helper.c | 71 ++++++++++++++++++++++++++++ lib/efi_loader/testapp.c | 64 +++++++++++++++++++++++++ test/boot/bootdev.c | 18 ++++++- test/boot/bootflow.c | 67 ++++++++++++++++++++++++-- test/py/tests/bootstd/flash1.img.xz | Bin 0 -> 4924 bytes test/py/tests/test_ut.py | 53 ++++++++++++++++++--- 17 files changed, 356 insertions(+), 98 deletions(-) delete mode 100644 include/efi_default_filename.h create mode 100644 lib/efi_loader/testapp.c create mode 100644 test/py/tests/bootstd/flash1.img.xz
I hope this series can meet with approval and go in. I know it isn't perfect, but we can then work on things from there. The first thing is to drop the various .xz files, which I'll look at once this lands.
Regards, Simon
I tried to apply the series. But it fails in the CI.
https://source.denx.de/u-boot/custodians/u-boot-efi/-/jobs/941546
OK, thanks. The passing run was at [1] but I'll rebase and send a v10. I suspect there is a test-ordering issue.
Regards, Simon
[1] https://source.denx.de/u-boot/custodians/u-boot-dm/-/pipelines/23126
participants (3)
-
Heinrich Schuchardt
-
Simon Glass
-
Tom Rini