Skip to contentSkip to conversation

efi: Add a test for EFI bootmeth

PATCH Superseded Simon Glass 4 participants 23 messages Oct 29, 2024 – Nov 1, 2024

v9 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v9 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 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            |  68 ++++++++++++++++++++++++++
 test/boot/bootdev.c                 |  18 ++++++-
 test/boot/bootflow.c                |  71 ++++++++++++++++++++++++++--
 test/py/tests/bootstd/flash1.img.xz | Bin 0 -> 4980 bytes
 test/py/tests/test_ut.py            |  53 ++++++++++++++++++---
 17 files changed, 364 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
Signature · 1 line
2.43.0
#1 lore raw

PATCH v9 1/11 test: boot: Update bootflow_iter() for console checking

This test checks console output so should have the UTF_CONSOLE flag. Add it.

---

(no changes since v1)

 test/boot/bootflow.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
test/boot/bootflow.c +1 -1
index 0d4e966892e..841729bd1ac 100644
@@ -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 */
Signature · 1 line
2.43.0
#2 lore raw

PATCH v9 2/11 efi_loader: Add a test app

In reply to Simon Glass

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. However, since this is a test, we need to check the results of running the app, so returning is necessary. It works correctly and it provides a nice model of how to test the EFI code in a simple way.

---

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 | 68 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+)
 create mode 100644 lib/efi_loader/testapp.c
lib/efi_loader/Kconfig +10 -0
index 37572c82f54..44319729bda 100644
@@ -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"
lib/efi_loader/Makefile +1 -0
index 8ec240cb864..7c8b2dd1ad6 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 +68 -0

68 lines not on this page · raw message

Signature · 1 line
2.43.0
#3 lore raw

Re: [PATCH v9 02/11] efi_loader: Add a test app

Quoted 12 lines · Simon Glass

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. However, since this is a test, we need to check the results of running the app, so returning is necessary. It works correctly and it provides a nice model of how to test the EFI code in a simple way.

Quoted 1 line

This approach has been specifically rejected with an explained
rationale: It breaks how UEFI applications work and you cannot run further UEFI tests in sandbox without resetting.

Since as you note, you can't reset in a C-based test, rework this to be a python test where we can safely reset the system and verify that. I believe Heinrich even noted that a test which checks ExitBootServices() working as expected would be helpful as we only have a watchdog test currently.

Signature · 1 line
Tom
#4 lore raw

Re: [PATCH v9 02/11] efi_loader: Add a test app

Hi Tom,

Quoted 21 lines · Tom Rini
Quoted 12 lines · Simon Glass

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. However, since this is a test, we need to check the results of running the app, so returning is necessary. It works correctly and it provides a nice model of how to test the EFI code in a simple way.

Quoted 1 line

This approach has been specifically rejected with an explained
rationale: It breaks how UEFI applications work and you cannot run further UEFI tests in sandbox without resetting.

Quoted 5 lines

Since as you note, you can't reset in a C-based test, rework this to be a python test where we can safely reset the system and verify that. I believe Heinrich even noted that a test which checks ExitBootServices() working as expected would be helpful as we only have a watchdog test currently.

Unfortunately I believe this is the wrong direction, as we are unable to check the state of anything once a reset has happened. Thus I cannot build on this test, e.g. to see what happened to the devices and whether they are still bound. It becomes just a 'black box' test. None of the other bootflow tests work this way, BTW.

Regards,
Simon

#5 lore raw

Re: [PATCH v9 02/11] efi_loader: Add a test app

Quoted 30 lines · Simon Glass

Hi Tom,

Quoted 21 lines · Tom Rini
Quoted 12 lines · Simon Glass

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. However, since this is a test, we need to check the results of running the app, so returning is necessary. It works correctly and it provides a nice model of how to test the EFI code in a simple way.

Quoted 1 line

This approach has been specifically rejected with an explained
rationale: It breaks how UEFI applications work and you cannot run further UEFI tests in sandbox without resetting.

Quoted 5 lines

Since as you note, you can't reset in a C-based test, rework this to be a python test where we can safely reset the system and verify that. I believe Heinrich even noted that a test which checks ExitBootServices() working as expected would be helpful as we only have a watchdog test currently.

Quoted 5 lines

Unfortunately I believe this is the wrong direction, as we are unable to check the state of anything once a reset has happened. Thus I cannot build on this test, e.g. to see what happened to the devices and whether they are still bound. It becomes just a 'black box' test. None of the other bootflow tests work this way, BTW.

That's unfortunate in a number of ways then really. It's good when we can test the state machine is still where we expect it. It's better when we can test that the functionality works for real. It would probably be generically useful to have some verification functions that can dump the state of DM before we finish ourselves up and hand things over to the OS. We could even make use of this in test/py/tests/test_net_boot.py when we're booting Linux to make sure it's working as expected.

Signature · 1 line
Tom
#6 lore raw

Re: [PATCH v9 02/11] efi_loader: Add a test app

In reply to Simon Glass
Quoted 118 lines · Simon Glass

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. However, since this is a test, we need to check the results of running the app, so returning is necessary. It works correctly and it provides a nice model of how to test the EFI code in a simple way.

---

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 | 68 ++++++++++++++++++++++++++++++++++++++++
  3 files changed, 79 insertions(+)

create mode 100644 lib/efi_loader/testapp.c

lib/efi_loader/Kconfig +10 -0
index 37572c82f54..44319729bda 100644
@@ -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"
lib/efi_loader/Makefile +1 -0
index 8ec240cb864..7c8b2dd1ad6 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 +51 -0
new file mode 100644
index 00000000000..a28fc17ce5b
@@ -0,0 +1,68 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Hello world EFI application
+ *
+ * Copyright 2024 Google LLC
+ * Written by Simon Glass <[email protected]>
+ *
+ * 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;
+	efi_uintn_t map_size;
+	efi_uintn_t map_key;
+	efi_uintn_t desc_size;
+	u32 desc_version;
+
+	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 */

lib/efi_loader/testapp.c line 61

Quoted 10 lines
lib/efi_loader/testapp.c new file +10 -0
+	con_out->output_string(con_out, u"U-Boot test app for EFI_LOADER\r\n");
+
+out:
+	map_size = 0;
+	ret = boottime->get_memory_map(&map_size, NULL, &map_key, &desc_size,
+				       &desc_version);
+	con_out->output_string(con_out, u"Exiting boot services\n");
+
+	/* exit boot services so that this part of U-Boot can be tested */
+	boottime->exit_boot_services(handle, map_key);

Hello Simon,

I am not NAKing this patch. But maybe you could rethink if this call tells us anything new about the correct function of ExitBootServices().

We already have a test of ExitBootServices() in lib/efi_selftest/ and maybe we should extend that test to check more.

By removing ExitBootServices() we could keep U-Boot in a well defined state which will allow us to run any number of bootmeth tests in sequence and keep the EFI sub-system in a consistent state.

Best regards

Heinrich

Quoted 7 lines
lib/efi_loader/testapp.c new file +7 -0
+
+	/* now exit for real */
+	ret = boottime->exit(handle, ret, 0, NULL);
+
+	/* We should never arrive here */
+	return ret;
+}
#7 lore raw

Re: [PATCH v9 02/11] efi_loader: Add a test app

Hi Heinrich

Quoted 136 lines · Heinrich Schuchardt
Quoted 118 lines · Simon Glass

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. However, since this is a test, we need to check the results of running the app, so returning is necessary. It works correctly and it provides a nice model of how to test the EFI code in a simple way.

---

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 | 68 ++++++++++++++++++++++++++++++++++++++++
  3 files changed, 79 insertions(+)

create mode 100644 lib/efi_loader/testapp.c

lib/efi_loader/Kconfig +10 -0
index 37572c82f54..44319729bda 100644
@@ -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"
lib/efi_loader/Makefile +1 -0
index 8ec240cb864..7c8b2dd1ad6 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 +51 -0
new file mode 100644
index 00000000000..a28fc17ce5b
@@ -0,0 +1,68 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Hello world EFI application
+ *
+ * Copyright 2024 Google LLC
+ * Written by Simon Glass <[email protected]>
+ *
+ * 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;
+     efi_uintn_t map_size;
+     efi_uintn_t map_key;
+     efi_uintn_t desc_size;
+     u32 desc_version;
+
+     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 */

lib/efi_loader/testapp.c line 61

Quoted 10 lines
lib/efi_loader/testapp.c new file +10 -0
+     con_out->output_string(con_out, u"U-Boot test app for EFI_LOADER\r\n");
+
+out:
+     map_size = 0;
+     ret = boottime->get_memory_map(&map_size, NULL, &map_key, &desc_size,
+                                    &desc_version);
+     con_out->output_string(con_out, u"Exiting boot services\n");
+
+     /* exit boot services so that this part of U-Boot can be tested */
+     boottime->exit_boot_services(handle, map_key);

Hello Simon,

I am not NAKing this patch. But maybe you could rethink if this call tells us anything new about the correct function of ExitBootServices().

Quoted 6 lines

We already have a test of ExitBootServices() in lib/efi_selftest/ and maybe we should extend that test to check more.

By removing ExitBootServices() we could keep U-Boot in a well defined state which will allow us to run any number of bootmeth tests in sequence and keep the EFI sub-system in a consistent state.

FWIW I proposed exactly the same in [0].

[0] https://lore.kernel.org/u-boot/CAC_iWjJYqrh6MS50d6MxdStJFGg2pWnf1PHwQ9muYDPmOBP7Lg@mail.gmail.com/

Thanks
/Ilias

Quoted 14 lines

Best regards

Heinrich

Quoted 7 lines
lib/efi_loader/testapp.c new file +7 -0
+
+     /* now exit for real */
+     ret = boottime->exit(handle, ret, 0, NULL);
+
+     /* We should never arrive here */
+     return ret;
+}
#8 lore raw

Re: [PATCH v9 02/11] efi_loader: Add a test app

Hi,

Quoted 148 lines · Ilias Apalodimas

Hi Heinrich

Quoted 142 lines · Heinrich Schuchardt
Quoted 118 lines · Simon Glass

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. However, since this is a test, we need to check the results of running the app, so returning is necessary. It works correctly and it provides a nice model of how to test the EFI code in a simple way.

---

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 | 68 ++++++++++++++++++++++++++++++++++++++++
  3 files changed, 79 insertions(+)

create mode 100644 lib/efi_loader/testapp.c

lib/efi_loader/Kconfig +10 -0
index 37572c82f54..44319729bda 100644
@@ -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"
lib/efi_loader/Makefile +1 -0
index 8ec240cb864..7c8b2dd1ad6 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 +51 -0
new file mode 100644
index 00000000000..a28fc17ce5b
@@ -0,0 +1,68 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Hello world EFI application
+ *
+ * Copyright 2024 Google LLC
+ * Written by Simon Glass <[email protected]>
+ *
+ * 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;
+     efi_uintn_t map_size;
+     efi_uintn_t map_key;
+     efi_uintn_t desc_size;
+     u32 desc_version;
+
+     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 */

lib/efi_loader/testapp.c line 61

Quoted 10 lines
lib/efi_loader/testapp.c new file +10 -0
+     con_out->output_string(con_out, u"U-Boot test app for EFI_LOADER\r\n");
+
+out:
+     map_size = 0;
+     ret = boottime->get_memory_map(&map_size, NULL, &map_key, &desc_size,
+                                    &desc_version);
+     con_out->output_string(con_out, u"Exiting boot services\n");
+
+     /* exit boot services so that this part of U-Boot can be tested */
+     boottime->exit_boot_services(handle, map_key);

Hello Simon,

I am not NAKing this patch. But maybe you could rethink if this call tells us anything new about the correct function of ExitBootServices().

We already have a test of ExitBootServices() in lib/efi_selftest/ and maybe we should extend that test to check more.

By removing ExitBootServices() we could keep U-Boot in a well defined state which will allow us to run any number of bootmeth tests in sequence and keep the EFI sub-system in a consistent state.

In the interests of trying to make some progress, I will drop that line and worry about it later, when we can come up with follow-on tests. It is exactly the 'exit-boot-services' call which was stopping Ubuntu from booting. But since I don't have any test pieces to check what happens in that situation, we can leave it for now.

Quoted 21 lines

FWIW I proposed exactly the same in [0].

[0] https://lore.kernel.org/u-boot/CAC_iWjJYqrh6MS50d6MxdStJFGg2pWnf1PHwQ9muYDPmOBP7Lg@mail.gmail.com/

Thanks
/Ilias

Quoted 14 lines

Best regards

Heinrich

Quoted 7 lines
lib/efi_loader/testapp.c new file +7 -0
+
+     /* now exit for real */
+     ret = boottime->exit(handle, ret, 0, NULL);
+
+     /* We should never arrive here */
+     return ret;
+}

Regards,
Simon

#9 lore raw

PATCH v9 3/11 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.43.0
#10 lore raw

Re: [PATCH v9 03/11] sandbox: Add a -N flag to control on-host behaviour

Quoted 10 lines · 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)

I believe Heinrich asked that you invert the logic here and add a flag for when you need the unexpected behavior.

Signature · 1 line
Tom
#11 lore raw

Re: [PATCH v9 03/11] sandbox: Add a -N flag to control on-host behaviour

Hi Tom,

Quoted 9 lines · Tom Rini
Quoted 6 lines · 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.

Quoted 7 lines
Quoted 4 lines

---

(no changes since v8)

I believe Heinrich asked that you invert the logic here and add a flag for when you need the unexpected behavior.

Yes, but that is not correct, unfortunately. The expected behaviour is for CI to use the same filename for its efi apps, no matter what host architecture it is happens to be running on.

The use case that Heinrich mentions seems to be broken on x86_64 now, as I mentioned on the other thread, perhaps due to a recently introduced bug in UEFI or QEMU. Just to be clear, this is not a problem with sandbox. I suspect Heinrich will figure that out at some point and then I will be able to try it too. I would also like to run it on sandbox.

I hope to get an ARM machine running CI eventually, but I need to get my lab running first.

Regards,
Simon

#12 lore raw

Re: [PATCH v9 03/11] sandbox: Add a -N flag to control on-host behaviour

Quoted 31 lines · Simon Glass

Hi Tom,

Quoted 9 lines · Tom Rini
Quoted 6 lines · 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.

Quoted 7 lines
Quoted 4 lines

---

(no changes since v8)

I believe Heinrich asked that you invert the logic here and add a flag for when you need the unexpected behavior.

Yes, but that is not correct, unfortunately. The expected behaviour is for CI to use the same filename for its efi apps, no matter what host architecture it is happens to be running on.

The use case that Heinrich mentions seems to be broken on x86_64 now, as I mentioned on the other thread, perhaps due to a recently introduced bug in UEFI or QEMU. Just to be clear, this is not a problem with sandbox. I suspect Heinrich will figure that out at some point and then I will be able to try it too. I would also like to run it on sandbox.

Quoted 2 lines

I hope to get an ARM machine running CI eventually, but I need to get my lab running first.

I talked with Heinrich about this in private and while neither of us understand why you want this behavior, we'll stop objecting to it.

Signature · 1 line
Tom
#13 lore raw

Re: [PATCH v9 03/11] sandbox: Add a -N flag to control on-host behaviour

Hi Tom,

Quoted 33 lines · Tom Rini
Quoted 31 lines · Simon Glass

Hi Tom,

Quoted 9 lines · Tom Rini
Quoted 6 lines · 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.

Quoted 7 lines
Quoted 4 lines

---

(no changes since v8)

I believe Heinrich asked that you invert the logic here and add a flag for when you need the unexpected behavior.

Yes, but that is not correct, unfortunately. The expected behaviour is for CI to use the same filename for its efi apps, no matter what host architecture it is happens to be running on.

The use case that Heinrich mentions seems to be broken on x86_64 now, as I mentioned on the other thread, perhaps due to a recently introduced bug in UEFI or QEMU. Just to be clear, this is not a problem with sandbox. I suspect Heinrich will figure that out at some point and then I will be able to try it too. I would also like to run it on sandbox.

Quoted 5 lines
Quoted 2 lines

I hope to get an ARM machine running CI eventually, but I need to get my lab running first.

I talked with Heinrich about this in private and while neither of us understand why you want this behavior, we'll stop objecting to it.

OK, good.

Heinrich mentioned that the RISC-V server did not work, for some reason. But eventually we might have one of those.

I know from my fiddling with 32-bit rpi that even *running* sandbox on ARM will be a challenge, let alone passing tests, but we'll see.

We should encourage ARM/Linux to set up an ARM runner at some point.

Regards,
Simon

#14 lore raw

PATCH v9 4/11 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.

---

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 f7419b80d4d..fef88e9c5d6 100644
@@ -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 */
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 431a38704e9..2ea20909491 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 841729bd1ac..7cfb217088e 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.43.0
#15 lore raw

PATCH v9 5/11 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.

---

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 fef88e9c5d6..633f5b4acb5 100644
@@ -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 */
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.43.0
#16 lore raw

PATCH v9 6/11 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.

---

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 bba984b2b75..ff6d118876d 100644
@@ -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"
Signature · 1 line
2.43.0
#17 lore raw

PATCH v9 7/11 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.

---

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 633f5b4acb5..817bc56c835 100644
@@ -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
  *
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.43.0
#18 lore raw

PATCH v9 8/11 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.

---

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.43.0
#20 lore raw

PATCH v9 9/11 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.43.0
#21 lore raw

PATCH v9 10/11 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]/

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 -> 4980 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 369105ca4cf..c892854b227 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 7cfb217088e..d7e94c8cc59 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..0efd9cbe146db6e8f422d9d66f11a772a493ce29
GIT binary patch
test/py/tests/test_ut.py +47 -6

96 lines not on this page · raw message

Signature · 1 line
2.43.0
#22 lore raw

PATCH v9 11/11 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 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 | 60 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)
test/boot/bootflow.c +60 -0
index d7e94c8cc59..8d4cbbb0702 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,59 @@ 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 boot services");
+	if (IS_ENABLED(CONFIG_LOGF_FUNC))
+		ut_assert_nextline("     do_bootefi_exec() ## Application failed, r = 5");
+	else
+		ut_assert_nextline("## Application failed, r = 5");
+	ut_assert_nextline("Boot failed (err=-22)");
+
+	ut_assert_console_end();
+
+	return 0;
+}
+BOOTSTD_TEST(bootflow_efi, UTF_CONSOLE);
Signature · 1 line
2.43.0