Skip to contentSkip to conversation

efi: Add a test for EFI bootmeth

PATCH Superseded Simon Glass 2 participants 15 messages Nov 7, 2024 – Nov 11, 2024 Kbuild

lore
Share & tools
lore
#0 lore raw

v10 cover 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
- Rebase to -master
- Specify the bootdev order, to avoid including cros device

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 (10):
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                |  76 ++++++++++++++++++++++++++--
 test/py/tests/bootstd/flash1.img.xz | Bin 0 -> 4924 bytes
 test/py/tests/test_ut.py            |  53 ++++++++++++++++---
 17 files changed, 366 insertions(+), 97 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
Signature · 1 line
2.34.1
#1 lore raw

PATCH v10 1/10 efi_loader: Add a test app

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.

---

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
lib/efi_loader/Kconfig +10 -0
index 066f0ca0da7..58d49789f12 100644
@@ -567,6 +567,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"
lib/efi_loader/Makefile +1 -0
index 00d18966f9e..87131ab911d 100644
@@ -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
lib/efi_loader/testapp.c new file +64 -0

64 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw

PATCH v10 2/10 sandbox: Add a -N flag to control on-host behaviour

In reply to Simon Glass

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.

---

(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(+)
arch/sandbox/cpu/start.c +10 -0
index 81752edc9f8..2940768cd1c 100644
@@ -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;
arch/sandbox/include/asm/state.h +1 -0
index e7dc01759e8..dc21a623106 100644
@@ -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]
Signature · 1 line
2.34.1
#3 lore raw

PATCH v10 3/10 efi: Move default filename to a function

In reply to Simon Glass

Use a function to obtain the device EFI filename, so that we can control how sandbox behaves.

---

(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
boot/bootmeth_efi.c +2 -2
index 2ad6d3b4ace..371b36d550b 100644
@@ -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);
include/efi.h +9 -0
index 84640cf7b25..ecdf7210750 100644
@@ -669,4 +669,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 */
include/efi_default_filename.h deleted +0 -56

56 lines not on this page · raw message

lib/efi_loader/efi_bootmgr.c +7 -3
index f9b5988a06e..8c51a6ef2ed 100644
@@ -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);
 		}
lib/efi_loader/efi_helper.c +45 -0

63 lines not on this page · raw message

test/boot/bootflow.c +4 -3
index 2f859c40adb..372bbab6b8d 100644
@@ -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(
Signature · 1 line
2.34.1
#4 lore raw

PATCH v10 4/10 efi_loader: Move get_efi_pxe_arch() to efi_helper

In reply to Simon Glass

Move this function from the EFI bootmeth to the common efi_helper file. No functional change is intended.

---

(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(-)
boot/bootmeth_efi.c +2 -23
index 371b36d550b..f836aa655f5 100644
@@ -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;
include/efi.h +10 -0
index ecdf7210750..789a64eda9d 100644
@@ -678,4 +678,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 */
lib/efi_loader/efi_helper.c +23 -0
index 51e0c4852c5..b8ece1c2e0c 100644
@@ -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
Signature · 1 line
2.34.1
#5 lore raw

PATCH v10 5/10 efi_loader: Allow reporting the host defaults

In reply to Simon Glass

Add an 'efidebug filename' command to report the default filename and PXE architecture.

---

(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(+)
cmd/efidebug.c +25 -0
index e040fe75fa1..02f1e080e88 100644
@@ -511,6 +511,27 @@ static int do_efi_show_images(struct cmd_tbl *cmdtp, int flag,
 	return CMD_RET_SUCCESS;
 }
 
+/**
+ * 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;
+}
+
 static const char * const efi_mem_type_string[] = {
 	[EFI_RESERVED_MEMORY_TYPE] = "RESERVED",
 	[EFI_LOADER_CODE] = "LOADER CODE",
@@ -1561,6 +1582,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(memmap, CONFIG_SYS_MAXARGS, 1, do_efi_show_memmap,
@@ -1653,6 +1676,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 memmap\n"
Signature · 1 line
2.34.1
#6 lore raw

PATCH v10 6/10 sandbox: Report host default-filename in native mode

In reply to Simon Glass

When the --native flag is given, pretend to be running the host architecture rather than sandbox.

Allow the same control for PXE too.

---

(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(-)
include/efi.h +15 -0
index 789a64eda9d..c559fda3004 100644
@@ -678,6 +678,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
  *
lib/efi_loader/efi_helper.c +20 -15
index b8ece1c2e0c..ab5678eb66c 100644
@@ -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;
Signature · 1 line
2.34.1
#7 lore raw

Re: [PATCH v10 06/10] sandbox: Report host default-filename in native mode

Hi Simon,

Quoted 5 lines · Simon Glass

When the --native flag is given, pretend to be running the host architecture rather than sandbox.

Allow the same control for PXE too.

Commit 7506c1566998 ("sandbox: Report host default-filename in native mode") breaks building jaguar-rk3588_defconfig, I believe it's this patch?

Reverting it makes the build pass again.

HOST_ARCH is empty in include/generated/version_autogenerated.h for some reason. Though it was also empty before.

The error is:

"""
lib/efi_loader/efi_helper.c:26:15: error: operator '==' has no left operand
26 | #if HOST_ARCH == HOST_ARCH_X86_64
| ^~
lib/efi_loader/efi_helper.c:29:17: error: operator '==' has no left operand
29 | #elif HOST_ARCH == HOST_ARCH_X86
| ^~
lib/efi_loader/efi_helper.c:32:17: error: operator '==' has no left operand
32 | #elif HOST_ARCH == HOST_ARCH_AARCH64
| ^~
lib/efi_loader/efi_helper.c:35:17: error: operator '==' has no left operand
35 | #elif HOST_ARCH == HOST_ARCH_ARM
| ^~
lib/efi_loader/efi_helper.c:38:17: error: operator '==' has no left operand
38 | #elif HOST_ARCH == HOST_ARCH_RISCV32
| ^~
lib/efi_loader/efi_helper.c:41:17: error: operator '==' has no left operand
41 | #elif HOST_ARCH == HOST_ARCH_RISCV64
| ^~
lib/efi_loader/efi_helper.c:45:2: error: #error Unsupported Host architecture
45 | #error Unsupported Host architecture

      |  ^~~~~
lib/efi_loader/efi_helper.c: In function ‘efi_get_basename’:
lib/efi_loader/efi_helper.c:73:38: error: ‘HOST_BOOTEFI_NAME’ undeclared (first use in this function); did you mean ‘BOOTEFI_NAME’?
   73 |         return efi_use_host_arch() ? HOST_BOOTEFI_NAME : 
BOOTEFI_NAME;
      |                                      ^~~~~~~~~~~~~~~~~
      |                                      BOOTEFI_NAME
lib/efi_loader/efi_helper.c:73:38: note: each undeclared identifier is reported only once for each function it appears in
lib/efi_loader/efi_helper.c: In function ‘efi_get_pxe_arch’:
lib/efi_loader/efi_helper.c:79:24: error: ‘HOST_PXE_ARCH’ undeclared (first use in this function); did you mean ‘HOST_ARCH’?
   79 |                 return HOST_PXE_ARCH;
      |                        ^~~~~~~~~~~~~
      |                        HOST_ARCH
lib/efi_loader/efi_helper.c: In function ‘efi_get_basename’:
lib/efi_loader/efi_helper.c:74:1: warning: control reaches end of non-void function [-Wreturn-type]
   74 | }
      | ^

make[2]: *** [scripts/Makefile.build:256: lib/efi_loader/efi_helper.o] Error 1 make[1]: *** [scripts/Makefile.build:398: lib/efi_loader] Error 2
make: *** [Makefile:1914: lib] Error 2
make: *** Waiting for unfinished jobs....
"""

The build host for me is Fedora 41.

Cheers,
Quentin

#8 lore raw

Re: [PATCH v10 06/10] sandbox: Report host default-filename in native mode

Hi Quentin,

Quoted 63 lines · Quentin Schulz

Hi Simon,

Quoted 5 lines · Simon Glass

When the --native flag is given, pretend to be running the host architecture rather than sandbox.

Allow the same control for PXE too.

Commit 7506c1566998 ("sandbox: Report host default-filename in native mode") breaks building jaguar-rk3588_defconfig, I believe it's this patch?

Reverting it makes the build pass again.

HOST_ARCH is empty in include/generated/version_autogenerated.h for some reason. Though it was also empty before.

The error is:

"""
lib/efi_loader/efi_helper.c:26:15: error: operator '==' has no left operand

    26 | #if HOST_ARCH == HOST_ARCH_X86_64
       |               ^~
lib/efi_loader/efi_helper.c:29:17: error: operator '==' has no left operand
    29 | #elif HOST_ARCH == HOST_ARCH_X86
       |                 ^~
lib/efi_loader/efi_helper.c:32:17: error: operator '==' has no left operand
    32 | #elif HOST_ARCH == HOST_ARCH_AARCH64
       |                 ^~
lib/efi_loader/efi_helper.c:35:17: error: operator '==' has no left operand
    35 | #elif HOST_ARCH == HOST_ARCH_ARM
       |                 ^~
lib/efi_loader/efi_helper.c:38:17: error: operator '==' has no left operand
    38 | #elif HOST_ARCH == HOST_ARCH_RISCV32
       |                 ^~
lib/efi_loader/efi_helper.c:41:17: error: operator '==' has no left operand
    41 | #elif HOST_ARCH == HOST_ARCH_RISCV64
       |                 ^~

lib/efi_loader/efi_helper.c:45:2: error: #error Unsupported Host architecture
45 | #error Unsupported Host architecture
| ^~~~~
lib/efi_loader/efi_helper.c: In function ‘efi_get_basename’:
lib/efi_loader/efi_helper.c:73:38: error: ‘HOST_BOOTEFI_NAME’ undeclared (first use in this function); did you mean ‘BOOTEFI_NAME’?
73 | return efi_use_host_arch() ? HOST_BOOTEFI_NAME :

BOOTEFI_NAME;
       |                                      ^~~~~~~~~~~~~~~~~
       |                                      BOOTEFI_NAME

lib/efi_loader/efi_helper.c:73:38: note: each undeclared identifier is reported only once for each function it appears in lib/efi_loader/efi_helper.c: In function ‘efi_get_pxe_arch’:
lib/efi_loader/efi_helper.c:79:24: error: ‘HOST_PXE_ARCH’ undeclared (first use in this function); did you mean ‘HOST_ARCH’?

    79 |                 return HOST_PXE_ARCH;
       |                        ^~~~~~~~~~~~~
       |                        HOST_ARCH
lib/efi_loader/efi_helper.c: In function ‘efi_get_basename’:
lib/efi_loader/efi_helper.c:74:1: warning: control reaches end of
non-void function [-Wreturn-type]
    74 | }
       | ^
Quoted 8 lines

make[2]: *** [scripts/Makefile.build:256: lib/efi_loader/efi_helper.o] Error 1
make[1]: *** [scripts/Makefile.build:398: lib/efi_loader] Error 2
make: *** [Makefile:1914: lib] Error 2
make: *** Waiting for unfinished jobs....
"""

The build host for me is Fedora 41.

Which cross-toolchain are you using? That variable is set at the top of Makefile so it would be worth seeing what MK_ARCH is returning.

Regards,
Simon

#9 lore raw

Re: [PATCH v10 06/10] sandbox: Report host default-filename in native mode

Hi Simon,

Quoted 73 lines · Simon Glass

Hi Quentin,

Quoted 70 lines · Quentin Schulz

Hi Simon,

Quoted 5 lines · Simon Glass

When the --native flag is given, pretend to be running the host architecture rather than sandbox.

Allow the same control for PXE too.

Commit 7506c1566998 ("sandbox: Report host default-filename in native mode") breaks building jaguar-rk3588_defconfig, I believe it's this patch?

Reverting it makes the build pass again.

HOST_ARCH is empty in include/generated/version_autogenerated.h for some reason. Though it was also empty before.

The error is:

"""
lib/efi_loader/efi_helper.c:26:15: error: operator '==' has no left operand

     26 | #if HOST_ARCH == HOST_ARCH_X86_64
        |               ^~
lib/efi_loader/efi_helper.c:29:17: error: operator '==' has no left operand
     29 | #elif HOST_ARCH == HOST_ARCH_X86
        |                 ^~
lib/efi_loader/efi_helper.c:32:17: error: operator '==' has no left operand
     32 | #elif HOST_ARCH == HOST_ARCH_AARCH64
        |                 ^~
lib/efi_loader/efi_helper.c:35:17: error: operator '==' has no left operand
     35 | #elif HOST_ARCH == HOST_ARCH_ARM
        |                 ^~
lib/efi_loader/efi_helper.c:38:17: error: operator '==' has no left operand
     38 | #elif HOST_ARCH == HOST_ARCH_RISCV32
        |                 ^~
lib/efi_loader/efi_helper.c:41:17: error: operator '==' has no left operand
     41 | #elif HOST_ARCH == HOST_ARCH_RISCV64
        |                 ^~

lib/efi_loader/efi_helper.c:45:2: error: #error Unsupported Host architecture
45 | #error Unsupported Host architecture
| ^~~~~
lib/efi_loader/efi_helper.c: In function ‘efi_get_basename’:
lib/efi_loader/efi_helper.c:73:38: error: ‘HOST_BOOTEFI_NAME’ undeclared (first use in this function); did you mean ‘BOOTEFI_NAME’?
73 | return efi_use_host_arch() ? HOST_BOOTEFI_NAME :

BOOTEFI_NAME;
        |                                      ^~~~~~~~~~~~~~~~~
        |                                      BOOTEFI_NAME

lib/efi_loader/efi_helper.c:73:38: note: each undeclared identifier is reported only once for each function it appears in lib/efi_loader/efi_helper.c: In function ‘efi_get_pxe_arch’:
lib/efi_loader/efi_helper.c:79:24: error: ‘HOST_PXE_ARCH’ undeclared (first use in this function); did you mean ‘HOST_ARCH’?

     79 |                 return HOST_PXE_ARCH;
        |                        ^~~~~~~~~~~~~
        |                        HOST_ARCH
lib/efi_loader/efi_helper.c: In function ‘efi_get_basename’:
lib/efi_loader/efi_helper.c:74:1: warning: control reaches end of
non-void function [-Wreturn-type]
     74 | }
        | ^

make[2]: *** [scripts/Makefile.build:256: lib/efi_loader/efi_helper.o] Error 1
make[1]: *** [scripts/Makefile.build:398: lib/efi_loader] Error 2
make: *** [Makefile:1914: lib] Error 2
make: *** Waiting for unfinished jobs....
"""

Quoted 5 lines
Quoted 1 line

The build host for me is Fedora 41.

Which cross-toolchain are you using? That variable is set at the top of Makefile so it would be worth seeing what MK_ARCH is returning.

Ahah! I had forgotten I use ccache so my CROSS_COMPILE is "ccache aarch64-linux-gnu-", without "ccache" in there it works.

I can suggest:
"""

Makefile +1 -1
index 7275a02f24c..2aa115f2097 100644
@@ -21,7 +21,7 @@ include include/host_arch.h
 ifeq ("", "$(CROSS_COMPILE)")
   MK_ARCH="${shell uname -m}"
 else
-  MK_ARCH="${shell echo $(CROSS_COMPILE) | sed -n 's/^[[:space:]]*\([^\/]*\/\)*\([^-]*\)-[^[:space:]]*/\2/p'}"
+  MK_ARCH="${shell echo $(CROSS_COMPILE) | sed -n 's/^\(ccache \)\?[[:space:]]*\([^\/]*\/\)*\([^-]*\)-[^[:space:]]*/\3/p'}"
 endif
 unexport HOST_ARCH
 ifeq ("x86_64", $(MK_ARCH))

"""

an opinion on this or do I just send this as a patch and it can be discussed on the ML?

This works for me both with and without ccache in CROSS_COMILE.

Cheers,
Quentin

#10 lore raw

Re: [PATCH v10 06/10] sandbox: Report host default-filename in native mode

Hi Quentin,

Quoted 105 lines · Quentin Schulz

Hi Simon,

Quoted 73 lines · Simon Glass

Hi Quentin,

Quoted 70 lines · Quentin Schulz

Hi Simon,

Quoted 5 lines · Simon Glass

When the --native flag is given, pretend to be running the host architecture rather than sandbox.

Allow the same control for PXE too.

Commit 7506c1566998 ("sandbox: Report host default-filename in native mode") breaks building jaguar-rk3588_defconfig, I believe it's this patch?

Reverting it makes the build pass again.

HOST_ARCH is empty in include/generated/version_autogenerated.h for some reason. Though it was also empty before.

The error is:

"""
lib/efi_loader/efi_helper.c:26:15: error: operator '==' has no left operand

     26 | #if HOST_ARCH == HOST_ARCH_X86_64
        |               ^~
lib/efi_loader/efi_helper.c:29:17: error: operator '==' has no left operand
     29 | #elif HOST_ARCH == HOST_ARCH_X86
        |                 ^~
lib/efi_loader/efi_helper.c:32:17: error: operator '==' has no left operand
     32 | #elif HOST_ARCH == HOST_ARCH_AARCH64
        |                 ^~
lib/efi_loader/efi_helper.c:35:17: error: operator '==' has no left operand
     35 | #elif HOST_ARCH == HOST_ARCH_ARM
        |                 ^~
lib/efi_loader/efi_helper.c:38:17: error: operator '==' has no left operand
     38 | #elif HOST_ARCH == HOST_ARCH_RISCV32
        |                 ^~
lib/efi_loader/efi_helper.c:41:17: error: operator '==' has no left operand
     41 | #elif HOST_ARCH == HOST_ARCH_RISCV64
        |                 ^~

lib/efi_loader/efi_helper.c:45:2: error: #error Unsupported Host architecture
45 | #error Unsupported Host architecture
| ^~~~~
lib/efi_loader/efi_helper.c: In function ‘efi_get_basename’:
lib/efi_loader/efi_helper.c:73:38: error: ‘HOST_BOOTEFI_NAME’ undeclared (first use in this function); did you mean ‘BOOTEFI_NAME’?
73 | return efi_use_host_arch() ? HOST_BOOTEFI_NAME :

BOOTEFI_NAME;
        |                                      ^~~~~~~~~~~~~~~~~
        |                                      BOOTEFI_NAME

lib/efi_loader/efi_helper.c:73:38: note: each undeclared identifier is reported only once for each function it appears in lib/efi_loader/efi_helper.c: In function ‘efi_get_pxe_arch’:
lib/efi_loader/efi_helper.c:79:24: error: ‘HOST_PXE_ARCH’ undeclared (first use in this function); did you mean ‘HOST_ARCH’?

     79 |                 return HOST_PXE_ARCH;
        |                        ^~~~~~~~~~~~~
        |                        HOST_ARCH
lib/efi_loader/efi_helper.c: In function ‘efi_get_basename’:
lib/efi_loader/efi_helper.c:74:1: warning: control reaches end of
non-void function [-Wreturn-type]
     74 | }
        | ^

make[2]: *** [scripts/Makefile.build:256: lib/efi_loader/efi_helper.o] Error 1
make[1]: *** [scripts/Makefile.build:398: lib/efi_loader] Error 2
make: *** [Makefile:1914: lib] Error 2
make: *** Waiting for unfinished jobs....
"""

Quoted 5 lines
Quoted 1 line

The build host for me is Fedora 41.

Which cross-toolchain are you using? That variable is set at the top of Makefile so it would be worth seeing what MK_ARCH is returning.

Ahah! I had forgotten I use ccache so my CROSS_COMPILE is "ccache aarch64-linux-gnu-", without "ccache" in there it works.

I can suggest:
"""

Makefile +0 -1
index 7275a02f24c..2aa115f2097 100644
@@ -21,7 +21,7 @@ include include/host_arch.h
  ifeq ("", "$(CROSS_COMPILE)")
    MK_ARCH="${shell uname -m}"
  else
-  MK_ARCH="${shell echo $(CROSS_COMPILE) | sed -n

's/^[[:space:]]*\([^\/]*\/\)*\([^-]*\)-[^[:space:]]*/\2/p'}"
+ MK_ARCH="${shell echo $(CROSS_COMPILE) | sed -n 's/^\(ccache \)\?[[:space:]]*\([^\/]*\/\)*\([^-]*\)-[^[:space:]]*/\3/p'}" endif
unexport HOST_ARCH
ifeq ("x86_64", $(MK_ARCH))
"""

Quoted 4 lines

an opinion on this or do I just send this as a patch and it can be discussed on the ML?

This works for me both with and without ccache in CROSS_COMILE.

Yes, please send as a patch, looks OK to me.

I often wonder if we could have tests for the Makefile logic...

Regards,
Simon

#11 lore raw

PATCH v10 7/10 efi_loader: Drop sandbox PXE architecture

In reply to Simon Glass

Rather than returning 0, just return an error, since sandbox is not used with PXE at present.

---

(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(-)
lib/efi_loader/efi_helper.c +0 -2
index ab5678eb66c..bf96f61d3d0 100644
@@ -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;
 }
Signature · 1 line
2.34.1
#12 lore raw

PATCH v10 8/10 sandbox: virtio: Disable the sandbox virtio blk device

In reply to Simon Glass

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.

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(-)
arch/Kconfig +2 -1
index 8f1f4667012..c39efb4d0a2 100644
@@ -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
Signature · 1 line
2.34.1
#13 lore raw

PATCH v10 9/10 test: efi: boot: Set up an image suitable for EFI testing

In reply to Simon Glass

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.

---
Here is the patch to avoid sudo and CI fallback:

[1] https://patchwork.ozlabs.org/project/uboot/patch/
[email protected]/

(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
arch/sandbox/dts/test.dts +1 -1
index 3017b33d67b..dee280184b1 100644
@@ -1515,7 +1515,7 @@
 				flash-stick@1 {
 					reg = <1>;
 					compatible = "sandbox,usb-flash";
-					sandbox,filepath = "testflash1.bin";
+					sandbox,filepath = "flash1.img";
 				};
 
 				flash-stick@2 {
test/boot/bootdev.c +17 -1
index 369c611d924..8c44afd9297 100644
@@ -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",
test/boot/bootflow.c +1 -1
index 372bbab6b8d..ac548e78ceb 100644
@@ -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));
test/py/tests/bootstd/flash1.img.xz new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..29b78c62a9bf264fa8b795b82b432bf3ab4e2765
GIT binary patch
test/py/tests/test_ut.py +47 -6

96 lines not on this page · raw message

Signature · 1 line
2.34.1
#14 lore raw

PATCH v10 10/10 test: efi: boot: Add a test for the efi bootmeth

In reply to Simon Glass

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.

---
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/

    [email protected]/

Changes in v10:
- Rebase to -master
- Specify the bootdev order, to avoid including cros device

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 | 67 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)
test/boot/bootflow.c +67 -0
index ac548e78ceb..9397328609d 100644
@@ -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,66 @@ 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)
+{
+	static const char *order[] = {"mmc1", "usb", NULL};
+	struct bootstd_priv *std;
+	struct udevice *bootstd;
+	const char **old_order;
+
+	ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd));
+	std = dev_get_priv(bootstd);
+	old_order = std->bootdev_order;
+	std->bootdev_order = order;
+
+	/* 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(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();
+
+	ut_assertok(bootstd_test_drop_bootdev_order(uts));
+
+	return 0;
+}
+BOOTSTD_TEST(bootflow_efi, UTF_CONSOLE);
Signature · 1 line
2.34.1