Skip to contentSkip to conversation

efi: Add a test for EFI bootmeth

PATCH Superseded Simon Glass 4 participants 30 messages Aug 15, 2024 – Aug 26, 2024

Subsystems (3)

v4 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v4 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:

- ANSI output from the EFI loader confusing the unit-testing checker
- Hang in sandbox virtio due to EFI probing all block devices

Other necessary fixes have been split out into two other series.

Changes in v4:
- Add efi_loader tag to some patches
- Split out non-EFI patches into a different series

Changes in v3:
- Drop the extra- rules since scripts/Makefile.lib takes care of it
- Add new patch to drop crt0/relocal extra- rules
- Put back the Linaro copyright accidentally removed
- Add a Fixes tag
- Mention the issue created for this problem

Changes in v2:
- Fix 'use' typo
- Reword commit message
- Use 'Firmware vendor' instead of just 'Vendor'
- Add many new patches to resolve all the outstanding test issues

Simon Glass (14):
efi_loader: Use puts() in cout so that console recording works
efi_loader: Put back copyright message
efi_loader: Rename and move CMD_BOOTEFI_HELLO_COMPILE
efi: arm: x86: riscv: Drop crt0/relocal extra- rules
efi_loader: Shorten the app rules
efi_loader: Shorten the app rules further
efi_loader: Show the vendor in helloworld
efi: Use the same filename for all sandbox builds
bootstd: Add debugging for efi bootmeth
efi_loader: Disable ANSI output for tests
efi_loader: Add a test app
efi_loader: Avoid using sandbox virtio devices
test: efi: boot: Set up an image suitable for EFI testing
test: efi: boot: Add a test for the efi bootmeth

 arch/arm/lib/Makefile               |   8 ----
 arch/riscv/lib/Makefile             |   4 --
 arch/sandbox/dts/test.dts           |   2 +-
 arch/x86/lib/Makefile               |  16 -------
 boot/bootmeth_efi.c                 |  11 ++++-
 cmd/Kconfig                         |  14 +-----
 configs/octeontx2_95xx_defconfig    |   2 +-
 configs/octeontx2_96xx_defconfig    |   2 +-
 configs/octeontx_81xx_defconfig     |   2 +-
 configs/octeontx_83xx_defconfig     |   2 +-
 doc/develop/uefi/uefi.rst           |   2 +-
 include/efi_default_filename.h      |  24 +---------
 include/efi_loader.h                |  21 ++++++++-
 lib/efi_loader/Kconfig              |  22 +++++++++
 lib/efi_loader/Makefile             |  47 ++++++-------------
 lib/efi_loader/efi_console.c        |  28 ++++++++----
 lib/efi_loader/efi_disk.c           |  14 +++++-
 lib/efi_loader/helloworld.c         |   6 +++
 lib/efi_loader/testapp.c            |  68 ++++++++++++++++++++++++++++
 test/boot/bootdev.c                 |  18 +++++++-
 test/boot/bootflow.c                |  60 +++++++++++++++++++++++-
 test/py/tests/bootstd/flash1.img.xz | Bin 0 -> 5016 bytes
 test/py/tests/test_efi_fit.py       |   2 +-
 test/py/tests/test_efi_loader.py    |   2 +-
 test/py/tests/test_ut.py            |  52 ++++++++++++++++++---
 25 files changed, 304 insertions(+), 125 deletions(-)
 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 v4 1/14 efi_loader: Use puts() in cout so that console recording works

At present EFI output to the console uses fputs() which bypasses the console-recording feature. This makes it impossible for tests to check the output of an EFI app.

There doesn't seem to be any need to do this bypass, so adjust it to simply use the puts() function.

---

(no changes since v2)

Changes in v2:
- Fix 'use' typo

 lib/efi_loader/efi_console.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/efi_loader/efi_console.c +1 -1
index c944c10b216..cea50c748aa 100644
@@ -181,7 +181,7 @@ static efi_status_t EFIAPI efi_cout_output_string(
 	}
 	pos = buf;
 	utf16_utf8_strcpy(&pos, string);
-	fputs(stdout, buf);
+	puts(buf);
 	free(buf);
 
 	/*
Signature · 1 line
2.34.1
#2 lore raw

PATCH v4 2/14 efi_loader: Put back copyright message

In reply to Simon Glass

This was lost in a later commit, so add it back.

Fixes dd860b90ff4 ("efi_loader: print boot device and file path in")

---

(no changes since v1)

 lib/efi_loader/helloworld.c | 3 +++
 1 file changed, 3 insertions(+)
lib/efi_loader/helloworld.c +3 -0
index bd72822c0b7..586177de0c8 100644
@@ -2,6 +2,9 @@
 /*
  * Hello world EFI application
  *
+ * Copyright (c) 2016 Google, Inc
+ * Written by Simon Glass <[email protected]>
+ *
  * Copyright 2020, Heinrich Schuchardt <[email protected]>
  *
  * This test program is used to test the invocation of an EFI application.
Signature · 1 line
2.34.1
Reviewed-by on v4 2/14
#3 lore raw

Re: [PATCH v4 02/14] efi_loader: Put back copyright message

Hi Simon

Quoted 5 lines · Simon Glass

This was lost in a later commit, so add it back.

Fixes dd860b90ff4 ("efi_loader: print boot device and file path in")

I think we should drop the Fixes tag, but in any case

Quoted 24 lines

---

(no changes since v1)

 lib/efi_loader/helloworld.c | 3 +++
 1 file changed, 3 insertions(+)
lib/efi_loader/helloworld.c +3 -1
index bd72822c0b7..586177de0c8 100644
@@ -2,6 +2,9 @@
 /*
  * Hello world EFI application
  *
+ * Copyright (c) 2016 Google, Inc
+ * Written by Simon Glass <[email protected]>
+ *
  * Copyright 2020, Heinrich Schuchardt <[email protected]>
  *
  * This test program is used to test the invocation of an EFI application.
--

2.34.1

#4 lore raw

PATCH v4 3/14 efi_loader: Rename and move CMD_BOOTEFI_HELLO_COMPILE

In reply to Simon Glass

This is not actually a command so the name is confusing. Use BOOTEFI_HELLO_COMPILE instead. Put it in the efi_loader directory with the other such config options.

The link rule (for $(obj)/%_efi.so) in scripts/Makefile.lib handles pulling in efi_crt0.o and efi_reloc.o so drop the 'extra' rules.

---

(no changes since v3)

Changes in v3:
- Drop the extra- rules since scripts/Makefile.lib takes care of it

 arch/arm/lib/Makefile            |  1 -
 arch/riscv/lib/Makefile          |  1 -
 arch/x86/lib/Makefile            |  2 +-
 cmd/Kconfig                      | 14 +-------------
 configs/octeontx2_95xx_defconfig |  2 +-
 configs/octeontx2_96xx_defconfig |  2 +-
 configs/octeontx_81xx_defconfig  |  2 +-
 configs/octeontx_83xx_defconfig  |  2 +-
 doc/develop/uefi/uefi.rst        |  2 +-
 lib/efi_loader/Kconfig           | 12 ++++++++++++
 lib/efi_loader/Makefile          |  2 +-
 test/py/tests/test_efi_fit.py    |  2 +-
 test/py/tests/test_efi_loader.py |  2 +-
 13 files changed, 22 insertions(+), 24 deletions(-)
arch/arm/lib/Makefile +0 -1
index 67275fba616..4e54c577cc3 100644
@@ -130,7 +130,6 @@ CFLAGS_REMOVE_$(EFI_CRT0) := $(CFLAGS_NON_EFI)
 CFLAGS_$(EFI_RELOC) := $(CFLAGS_EFI)
 CFLAGS_REMOVE_$(EFI_RELOC) := $(CFLAGS_NON_EFI)
 
-extra-$(CONFIG_CMD_BOOTEFI_HELLO_COMPILE) += $(EFI_CRT0) $(EFI_RELOC)
 # TODO: As of v2019.01 the relocation code for the EFI application cannot
 # be built on ARMv7-M.
 ifndef CONFIG_CPU_V7M
arch/riscv/lib/Makefile +0 -1
index 65dc49f6fa5..4f6272aab6e 100644
@@ -36,7 +36,6 @@ CFLAGS_REMOVE_$(EFI_CRT0) := $(CFLAGS_NON_EFI)
 CFLAGS_$(EFI_RELOC) := $(CFLAGS_EFI)
 CFLAGS_REMOVE_$(EFI_RELOC) := $(CFLAGS_NON_EFI)
 
-extra-$(CONFIG_CMD_BOOTEFI_HELLO_COMPILE) += $(EFI_CRT0) $(EFI_RELOC)
 extra-$(CONFIG_CMD_BOOTEFI_SELFTEST) += $(EFI_CRT0) $(EFI_RELOC)
 extra-$(CONFIG_EFI) += $(EFI_CRT0) $(EFI_RELOC)
 
arch/x86/lib/Makefile +1 -1
index 8fc35e1b51e..8bc8d92172b 100644
@@ -97,7 +97,7 @@ endif
 else
 
 ifndef CONFIG_SPL_BUILD
-ifneq ($(CONFIG_CMD_BOOTEFI_SELFTEST)$(CONFIG_CMD_BOOTEFI_HELLO_COMPILE),)
+ifneq ($(CONFIG_CMD_BOOTEFI_SELFTEST),)
 extra-y += $(EFI_CRT0) $(EFI_RELOC)
 endif
 endif
cmd/Kconfig +1 -13
index 8af136d2bd4..f8a7e03400a 100644
@@ -438,21 +438,9 @@ config CMD_BOOTEFI_BOOTMGR
 	  This subcommand will allow you to select the UEFI binary to be booted
 	  via UEFI variables Boot####, BootOrder, and BootNext.
 
-config CMD_BOOTEFI_HELLO_COMPILE
-	bool "Compile a standard EFI hello world binary for testing"
-	default y
-	help
-	  This compiles a standard EFI hello world application with U-Boot so
-	  that it can be used with the test/py testing framework. This is useful
-	  for testing that EFI is working at a basic level, and for bringing
-	  up EFI support on a new architecture.
-
-	  No additional space will be required in the resulting U-Boot binary
-	  when this option is enabled.
-
 config CMD_BOOTEFI_HELLO
 	bool "Allow booting a standard EFI hello world for testing"
-	depends on CMD_BOOTEFI_BINARY && CMD_BOOTEFI_HELLO_COMPILE
+	depends on CMD_BOOTEFI_BINARY && BOOTEFI_HELLO_COMPILE
 	default y if CMD_BOOTEFI_SELFTEST
 	help
 	  This adds a standard EFI hello world application to U-Boot so that
configs/octeontx2_95xx_defconfig +1 -1
index c5dc4f4dfa6..23c313375ac 100644
@@ -38,7 +38,7 @@ CONFIG_SYS_PBSIZE=1050
 CONFIG_BOARD_EARLY_INIT_R=y
 CONFIG_HUSH_PARSER=y
 CONFIG_SYS_PROMPT="Marvell> "
-# CONFIG_CMD_BOOTEFI_HELLO_COMPILE is not set
+# CONFIG_BOOTEFI_HELLO_COMPILE is not set
 CONFIG_CMD_MD5SUM=y
 CONFIG_MD5SUM_VERIFY=y
 CONFIG_CMD_MX_CYCLIC=y
configs/octeontx2_96xx_defconfig +1 -1
index ad61b80300f..197e72acd1f 100644
@@ -38,7 +38,7 @@ CONFIG_SYS_PBSIZE=1050
 CONFIG_BOARD_EARLY_INIT_R=y
 CONFIG_HUSH_PARSER=y
 CONFIG_SYS_PROMPT="Marvell> "
-# CONFIG_CMD_BOOTEFI_HELLO_COMPILE is not set
+# CONFIG_BOOTEFI_HELLO_COMPILE is not set
 CONFIG_CMD_MD5SUM=y
 CONFIG_MD5SUM_VERIFY=y
 CONFIG_CMD_MX_CYCLIC=y
configs/octeontx_81xx_defconfig +1 -1
index 1d39bce6abd..b501d653c27 100644
@@ -39,7 +39,7 @@ CONFIG_SYS_PBSIZE=1050
 CONFIG_BOARD_EARLY_INIT_R=y
 CONFIG_HUSH_PARSER=y
 CONFIG_SYS_PROMPT="Marvell> "
-# CONFIG_CMD_BOOTEFI_HELLO_COMPILE is not set
+# CONFIG_BOOTEFI_HELLO_COMPILE is not set
 CONFIG_CMD_MD5SUM=y
 CONFIG_MD5SUM_VERIFY=y
 CONFIG_CMD_MX_CYCLIC=y
configs/octeontx_83xx_defconfig +1 -1
index ba9fc5f9553..4a537f5cbbe 100644
@@ -37,7 +37,7 @@ CONFIG_SYS_PBSIZE=1050
 CONFIG_BOARD_EARLY_INIT_R=y
 CONFIG_HUSH_PARSER=y
 CONFIG_SYS_PROMPT="Marvell> "
-# CONFIG_CMD_BOOTEFI_HELLO_COMPILE is not set
+# CONFIG_BOOTEFI_HELLO_COMPILE is not set
 CONFIG_CMD_MD5SUM=y
 CONFIG_MD5SUM_VERIFY=y
 CONFIG_CMD_MX_CYCLIC=y
doc/develop/uefi/uefi.rst +1 -1
index d450b12bf80..9aeee23a32e 100644
@@ -693,7 +693,7 @@ Executing the built in hello world application
 
 A hello world UEFI application can be built with::
 
-    CONFIG_CMD_BOOTEFI_HELLO_COMPILE=y
+    CONFIG_BOOTEFI_HELLO_COMPILE=y
 
 It can be embedded into the U-Boot binary with::
 
lib/efi_loader/Kconfig +12 -0
index 1179c31bb13..ab2c1c44364 100644
@@ -516,4 +516,16 @@ config EFI_HTTP_BOOT
 	  Enabling this option adds EFI HTTP Boot support. It allows to
 	  directly boot from network.
 
+config BOOTEFI_HELLO_COMPILE
+	bool "Compile a standard EFI hello world binary for testing"
+	default y
+	help
+	  This compiles a standard EFI hello world application with U-Boot so
+	  that it can be used with the test/py testing framework. This is useful
+	  for testing that EFI is working at a basic level, and for bringing
+	  up EFI support on a new architecture.
+
+	  No additional space will be required in the resulting U-Boot binary
+	  when this option is enabled.
+
 endif
lib/efi_loader/Makefile +1 -1
index 2af6f2066b5..27dbd9e760d 100644
@@ -27,7 +27,7 @@ always += boothart.efi
 targets += boothart.o
 endif
 
-ifneq ($(CONFIG_CMD_BOOTEFI_HELLO_COMPILE),)
+ifneq ($(CONFIG_BOOTEFI_HELLO_COMPILE),)
 always += helloworld.efi
 targets += helloworld.o
 endif
test/py/tests/test_efi_fit.py +1 -1
index 0ad483500f8..550058a30fd 100644
@@ -119,7 +119,7 @@ FDT_DATA = '''
 '''
 
 @pytest.mark.buildconfigspec('bootm_efi')
[email protected]('cmd_bootefi_hello_compile')
[email protected]('BOOTEFI_HELLO_COMPILE')
 @pytest.mark.buildconfigspec('fit')
 @pytest.mark.notbuildconfigspec('generate_acpi_table')
 @pytest.mark.requiredtool('dtc')
test/py/tests/test_efi_loader.py +1 -1
index 85473a9049b..ef1f1f1afb3 100644
@@ -148,7 +148,7 @@ def fetch_tftp_file(u_boot_console, env_conf):
     return addr
 
 @pytest.mark.buildconfigspec('of_control')
[email protected]('cmd_bootefi_hello_compile')
[email protected]('BOOTEFI_HELLO_COMPILE')
 def test_efi_helloworld_net(u_boot_console):
     """Run the helloworld.efi binary via TFTP.
 
Signature · 1 line
2.34.1
Reviewed-by on v4 3/14
#5 lore raw

Re: [PATCH v4 03/14] efi_loader: Rename and move CMD_BOOTEFI_HELLO_COMPILE

Quoted 221 lines · Simon Glass

This is not actually a command so the name is confusing. Use BOOTEFI_HELLO_COMPILE instead. Put it in the efi_loader directory with the other such config options.

The link rule (for $(obj)/%_efi.so) in scripts/Makefile.lib handles pulling in efi_crt0.o and efi_reloc.o so drop the 'extra' rules.

---

(no changes since v3)

Changes in v3:
- Drop the extra- rules since scripts/Makefile.lib takes care of it

 arch/arm/lib/Makefile            |  1 -
 arch/riscv/lib/Makefile          |  1 -
 arch/x86/lib/Makefile            |  2 +-
 cmd/Kconfig                      | 14 +-------------
 configs/octeontx2_95xx_defconfig |  2 +-
 configs/octeontx2_96xx_defconfig |  2 +-
 configs/octeontx_81xx_defconfig  |  2 +-
 configs/octeontx_83xx_defconfig  |  2 +-
 doc/develop/uefi/uefi.rst        |  2 +-
 lib/efi_loader/Kconfig           | 12 ++++++++++++
 lib/efi_loader/Makefile          |  2 +-
 test/py/tests/test_efi_fit.py    |  2 +-
 test/py/tests/test_efi_loader.py |  2 +-
 13 files changed, 22 insertions(+), 24 deletions(-)
arch/arm/lib/Makefile +0 -1
index 67275fba616..4e54c577cc3 100644
@@ -130,7 +130,6 @@ CFLAGS_REMOVE_$(EFI_CRT0) := $(CFLAGS_NON_EFI)
 CFLAGS_$(EFI_RELOC) := $(CFLAGS_EFI)
 CFLAGS_REMOVE_$(EFI_RELOC) := $(CFLAGS_NON_EFI)
 
-extra-$(CONFIG_CMD_BOOTEFI_HELLO_COMPILE) += $(EFI_CRT0) $(EFI_RELOC)
 # TODO: As of v2019.01 the relocation code for the EFI application cannot
 # be built on ARMv7-M.
 ifndef CONFIG_CPU_V7M
arch/riscv/lib/Makefile +0 -1
index 65dc49f6fa5..4f6272aab6e 100644
@@ -36,7 +36,6 @@ CFLAGS_REMOVE_$(EFI_CRT0) := $(CFLAGS_NON_EFI)
 CFLAGS_$(EFI_RELOC) := $(CFLAGS_EFI)
 CFLAGS_REMOVE_$(EFI_RELOC) := $(CFLAGS_NON_EFI)
 
-extra-$(CONFIG_CMD_BOOTEFI_HELLO_COMPILE) += $(EFI_CRT0) $(EFI_RELOC)
 extra-$(CONFIG_CMD_BOOTEFI_SELFTEST) += $(EFI_CRT0) $(EFI_RELOC)
 extra-$(CONFIG_EFI) += $(EFI_CRT0) $(EFI_RELOC)
 
arch/x86/lib/Makefile +1 -1
index 8fc35e1b51e..8bc8d92172b 100644
@@ -97,7 +97,7 @@ endif
 else
 
 ifndef CONFIG_SPL_BUILD
-ifneq ($(CONFIG_CMD_BOOTEFI_SELFTEST)$(CONFIG_CMD_BOOTEFI_HELLO_COMPILE),)
+ifneq ($(CONFIG_CMD_BOOTEFI_SELFTEST),)
 extra-y += $(EFI_CRT0) $(EFI_RELOC)
 endif
 endif
cmd/Kconfig +1 -13
index 8af136d2bd4..f8a7e03400a 100644
@@ -438,21 +438,9 @@ config CMD_BOOTEFI_BOOTMGR
          This subcommand will allow you to select the UEFI binary to be booted
          via UEFI variables Boot####, BootOrder, and BootNext.
 
-config CMD_BOOTEFI_HELLO_COMPILE
-       bool "Compile a standard EFI hello world binary for testing"
-       default y
-       help
-         This compiles a standard EFI hello world application with U-Boot so
-         that it can be used with the test/py testing framework. This is useful
-         for testing that EFI is working at a basic level, and for bringing
-         up EFI support on a new architecture.
-
-         No additional space will be required in the resulting U-Boot binary
-         when this option is enabled.
-
 config CMD_BOOTEFI_HELLO
        bool "Allow booting a standard EFI hello world for testing"
-       depends on CMD_BOOTEFI_BINARY && CMD_BOOTEFI_HELLO_COMPILE
+       depends on CMD_BOOTEFI_BINARY && BOOTEFI_HELLO_COMPILE
        default y if CMD_BOOTEFI_SELFTEST
        help
          This adds a standard EFI hello world application to U-Boot so that
configs/octeontx2_95xx_defconfig +1 -1
index c5dc4f4dfa6..23c313375ac 100644
@@ -38,7 +38,7 @@ CONFIG_SYS_PBSIZE=1050
 CONFIG_BOARD_EARLY_INIT_R=y
 CONFIG_HUSH_PARSER=y
 CONFIG_SYS_PROMPT="Marvell> "
-# CONFIG_CMD_BOOTEFI_HELLO_COMPILE is not set
+# CONFIG_BOOTEFI_HELLO_COMPILE is not set
 CONFIG_CMD_MD5SUM=y
 CONFIG_MD5SUM_VERIFY=y
 CONFIG_CMD_MX_CYCLIC=y
configs/octeontx2_96xx_defconfig +1 -1
index ad61b80300f..197e72acd1f 100644
@@ -38,7 +38,7 @@ CONFIG_SYS_PBSIZE=1050
 CONFIG_BOARD_EARLY_INIT_R=y
 CONFIG_HUSH_PARSER=y
 CONFIG_SYS_PROMPT="Marvell> "
-# CONFIG_CMD_BOOTEFI_HELLO_COMPILE is not set
+# CONFIG_BOOTEFI_HELLO_COMPILE is not set
 CONFIG_CMD_MD5SUM=y
 CONFIG_MD5SUM_VERIFY=y
 CONFIG_CMD_MX_CYCLIC=y
configs/octeontx_81xx_defconfig +1 -1
index 1d39bce6abd..b501d653c27 100644
@@ -39,7 +39,7 @@ CONFIG_SYS_PBSIZE=1050
 CONFIG_BOARD_EARLY_INIT_R=y
 CONFIG_HUSH_PARSER=y
 CONFIG_SYS_PROMPT="Marvell> "
-# CONFIG_CMD_BOOTEFI_HELLO_COMPILE is not set
+# CONFIG_BOOTEFI_HELLO_COMPILE is not set
 CONFIG_CMD_MD5SUM=y
 CONFIG_MD5SUM_VERIFY=y
 CONFIG_CMD_MX_CYCLIC=y
configs/octeontx_83xx_defconfig +1 -1
index ba9fc5f9553..4a537f5cbbe 100644
@@ -37,7 +37,7 @@ CONFIG_SYS_PBSIZE=1050
 CONFIG_BOARD_EARLY_INIT_R=y
 CONFIG_HUSH_PARSER=y
 CONFIG_SYS_PROMPT="Marvell> "
-# CONFIG_CMD_BOOTEFI_HELLO_COMPILE is not set
+# CONFIG_BOOTEFI_HELLO_COMPILE is not set
 CONFIG_CMD_MD5SUM=y
 CONFIG_MD5SUM_VERIFY=y
 CONFIG_CMD_MX_CYCLIC=y
doc/develop/uefi/uefi.rst +1 -1
index d450b12bf80..9aeee23a32e 100644
@@ -693,7 +693,7 @@ Executing the built in hello world application
 
 A hello world UEFI application can be built with::
 
-    CONFIG_CMD_BOOTEFI_HELLO_COMPILE=y
+    CONFIG_BOOTEFI_HELLO_COMPILE=y
 
 It can be embedded into the U-Boot binary with::
 
lib/efi_loader/Kconfig +12 -0
index 1179c31bb13..ab2c1c44364 100644
@@ -516,4 +516,16 @@ config EFI_HTTP_BOOT
          Enabling this option adds EFI HTTP Boot support. It allows to
          directly boot from network.
 
+config BOOTEFI_HELLO_COMPILE
+       bool "Compile a standard EFI hello world binary for testing"
+       default y
+       help
+         This compiles a standard EFI hello world application with U-Boot so
+         that it can be used with the test/py testing framework. This is useful
+         for testing that EFI is working at a basic level, and for bringing
+         up EFI support on a new architecture.
+
+         No additional space will be required in the resulting U-Boot binary
+         when this option is enabled.
+
 endif
lib/efi_loader/Makefile +1 -1
index 2af6f2066b5..27dbd9e760d 100644
@@ -27,7 +27,7 @@ always += boothart.efi
 targets += boothart.o
 endif
 
-ifneq ($(CONFIG_CMD_BOOTEFI_HELLO_COMPILE),)
+ifneq ($(CONFIG_BOOTEFI_HELLO_COMPILE),)
 always += helloworld.efi
 targets += helloworld.o
 endif
test/py/tests/test_efi_fit.py +1 -1
index 0ad483500f8..550058a30fd 100644
@@ -119,7 +119,7 @@ FDT_DATA = '''
 '''
 
 @pytest.mark.buildconfigspec('bootm_efi')
[email protected]('cmd_bootefi_hello_compile')
[email protected]('BOOTEFI_HELLO_COMPILE')
 @pytest.mark.buildconfigspec('fit')
 @pytest.mark.notbuildconfigspec('generate_acpi_table')
 @pytest.mark.requiredtool('dtc')
test/py/tests/test_efi_loader.py +1 -2
index 85473a9049b..ef1f1f1afb3 100644
@@ -148,7 +148,7 @@ def fetch_tftp_file(u_boot_console, env_conf):
     return addr
 
 @pytest.mark.buildconfigspec('of_control')
[email protected]('cmd_bootefi_hello_compile')
[email protected]('BOOTEFI_HELLO_COMPILE')
 def test_efi_helloworld_net(u_boot_console):
     """Run the helloworld.efi binary via TFTP.
 
--
Quoted 2 lines

2.34.1

#6 lore raw

PATCH v4 4/14 efi: arm: x86: riscv: Drop crt0/relocal extra- rules

In reply to Simon Glass

The link rule (for $(obj)/%_efi.so) in scripts/Makefile.lib handles pulling in efi_crt0.o and efi_reloc.o so drop the 'extra' rules.

---

(no changes since v3)

Changes in v3:
- Add new patch to drop crt0/relocal extra- rules

 arch/arm/lib/Makefile   |  7 -------
 arch/riscv/lib/Makefile |  3 ---
 arch/x86/lib/Makefile   | 16 ----------------
 3 files changed, 26 deletions(-)
arch/arm/lib/Makefile +0 -7
index 4e54c577cc3..87000d1609b 100644
@@ -129,10 +129,3 @@ CFLAGS_REMOVE_$(EFI_CRT0) := $(CFLAGS_NON_EFI)
 
 CFLAGS_$(EFI_RELOC) := $(CFLAGS_EFI)
 CFLAGS_REMOVE_$(EFI_RELOC) := $(CFLAGS_NON_EFI)
-
-# TODO: As of v2019.01 the relocation code for the EFI application cannot
-# be built on ARMv7-M.
-ifndef CONFIG_CPU_V7M
-#extra-$(CONFIG_CMD_BOOTEFI_SELFTEST) += $(EFI_CRT0) $(EFI_RELOC)
-endif
-extra-$(CONFIG_EFI) += $(EFI_CRT0) $(EFI_RELOC)
arch/riscv/lib/Makefile +0 -3
index 4f6272aab6e..bcfdb516b76 100644
@@ -36,9 +36,6 @@ CFLAGS_REMOVE_$(EFI_CRT0) := $(CFLAGS_NON_EFI)
 CFLAGS_$(EFI_RELOC) := $(CFLAGS_EFI)
 CFLAGS_REMOVE_$(EFI_RELOC) := $(CFLAGS_NON_EFI)
 
-extra-$(CONFIG_CMD_BOOTEFI_SELFTEST) += $(EFI_CRT0) $(EFI_RELOC)
-extra-$(CONFIG_EFI) += $(EFI_CRT0) $(EFI_RELOC)
-
 obj-$(CONFIG_$(SPL_TPL_)USE_ARCH_MEMSET) += memset.o
 obj-$(CONFIG_$(SPL_TPL_)USE_ARCH_MEMMOVE) += memmove.o
 obj-$(CONFIG_$(SPL_TPL_)USE_ARCH_MEMCPY) += memcpy.o
arch/x86/lib/Makefile +0 -16
index 8bc8d92172b..d6ea9c955f8 100644
@@ -87,19 +87,3 @@ extra-$(CONFIG_EFI_STUB_32BIT) += crt0_ia32_efi.o reloc_ia32_efi.o
 extra-$(CONFIG_EFI_STUB_64BIT) += crt0_x86_64_efi.o reloc_x86_64_efi.o
 
 endif
-
-ifdef CONFIG_EFI_STUB
-
-ifeq ($(CONFIG_$(SPL_)X86_64),)
-extra-y += $(EFI_CRT0) $(EFI_RELOC)
-endif
-
-else
-
-ifndef CONFIG_SPL_BUILD
-ifneq ($(CONFIG_CMD_BOOTEFI_SELFTEST),)
-extra-y += $(EFI_CRT0) $(EFI_RELOC)
-endif
-endif
-
-endif
Signature · 1 line
2.34.1
#7 lore raw

PATCH v4 5/14 efi_loader: Shorten the app rules

In reply to Simon Glass

We have quite a few apps now, so create a way to specify them as a list rather than repeating the same rules again and again.

---

(no changes since v1)

 lib/efi_loader/Makefile | 31 +++++++++----------------------
 1 file changed, 9 insertions(+), 22 deletions(-)
lib/efi_loader/Makefile +9 -22
index 27dbd9e760d..660368b9d8f 100644
@@ -22,29 +22,13 @@ CFLAGS_REMOVE_dtbdump.o := $(CFLAGS_NON_EFI)
 CFLAGS_initrddump.o := $(CFLAGS_EFI) -Os -ffreestanding
 CFLAGS_REMOVE_initrddump.o := $(CFLAGS_NON_EFI)
 
-ifdef CONFIG_RISCV
-always += boothart.efi
-targets += boothart.o
-endif
-
-ifneq ($(CONFIG_BOOTEFI_HELLO_COMPILE),)
-always += helloworld.efi
-targets += helloworld.o
-endif
-
-ifneq ($(CONFIG_GENERATE_SMBIOS_TABLE),)
-always += smbiosdump.efi
-targets += smbiosdump.o
-endif
-
+# These are the apps that are built
+apps-$(CONFIG_RISCV) += boothart
+apps-$(CONFIG_BOOTEFI_HELLO_COMPILE) += helloworld
+apps-$(CONFIG_GENERATE_SMBIOS_TABLE) += smbiosdump
+apps-$(CONFIG_EFI_LOAD_FILE2_INITRD) += initrddump
 ifeq ($(CONFIG_GENERATE_ACPI_TABLE),)
-always += dtbdump.efi
-targets += dtbdump.o
-endif
-
-ifdef CONFIG_EFI_LOAD_FILE2_INITRD
-always += initrddump.efi
-targets += initrddump.o
+apps-y += dtbdump
 endif
 
 obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o
@@ -95,3 +79,6 @@ obj-$(CONFIG_EFI_ECPT) += efi_conformance.o
 
 EFI_VAR_SEED_FILE := $(subst $\",,$(CONFIG_EFI_VAR_SEED_FILE))
 $(obj)/efi_var_seed.o: $(srctree)/$(EFI_VAR_SEED_FILE)
+
+always += $(foreach f,$(apps-y),$(f).efi)
+targets += $(foreach f,$(apps-y),$(f).o)
Signature · 1 line
2.34.1
Reviewed-by on v4 5/14
#8 lore raw

Re: [PATCH v4 05/14] efi_loader: Shorten the app rules

Quoted 61 lines · Simon Glass

We have quite a few apps now, so create a way to specify them as a list rather than repeating the same rules again and again.

---

(no changes since v1)

 lib/efi_loader/Makefile | 31 +++++++++----------------------
 1 file changed, 9 insertions(+), 22 deletions(-)
lib/efi_loader/Makefile +9 -23
index 27dbd9e760d..660368b9d8f 100644
@@ -22,29 +22,13 @@ CFLAGS_REMOVE_dtbdump.o := $(CFLAGS_NON_EFI)
 CFLAGS_initrddump.o := $(CFLAGS_EFI) -Os -ffreestanding
 CFLAGS_REMOVE_initrddump.o := $(CFLAGS_NON_EFI)
 
-ifdef CONFIG_RISCV
-always += boothart.efi
-targets += boothart.o
-endif
-
-ifneq ($(CONFIG_BOOTEFI_HELLO_COMPILE),)
-always += helloworld.efi
-targets += helloworld.o
-endif
-
-ifneq ($(CONFIG_GENERATE_SMBIOS_TABLE),)
-always += smbiosdump.efi
-targets += smbiosdump.o
-endif
-
+# These are the apps that are built
+apps-$(CONFIG_RISCV) += boothart
+apps-$(CONFIG_BOOTEFI_HELLO_COMPILE) += helloworld
+apps-$(CONFIG_GENERATE_SMBIOS_TABLE) += smbiosdump
+apps-$(CONFIG_EFI_LOAD_FILE2_INITRD) += initrddump
 ifeq ($(CONFIG_GENERATE_ACPI_TABLE),)
-always += dtbdump.efi
-targets += dtbdump.o
-endif
-
-ifdef CONFIG_EFI_LOAD_FILE2_INITRD
-always += initrddump.efi
-targets += initrddump.o
+apps-y += dtbdump
 endif
 
 obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o
@@ -95,3 +79,6 @@ obj-$(CONFIG_EFI_ECPT) += efi_conformance.o
 
 EFI_VAR_SEED_FILE := $(subst $\",,$(CONFIG_EFI_VAR_SEED_FILE))
 $(obj)/efi_var_seed.o: $(srctree)/$(EFI_VAR_SEED_FILE)
+
+always += $(foreach f,$(apps-y),$(f).efi)
+targets += $(foreach f,$(apps-y),$(f).o)
--
Quoted 2 lines

2.34.1

#9 lore raw

PATCH v4 6/14 efi_loader: Shorten the app rules further

In reply to Simon Glass

Add a way to factor out the CFLAGS changes for each app, since they are all the same.

---

(no changes since v1)

 lib/efi_loader/Makefile | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
lib/efi_loader/Makefile +5 -10
index 660368b9d8f..00d18966f9e 100644
@@ -11,16 +11,6 @@ asflags-y += -I.
 CFLAGS_efi_boottime.o += \
   -DFW_VERSION="0x$(VERSION)" \
   -DFW_PATCHLEVEL="0x$(PATCHLEVEL)"
-CFLAGS_boothart.o := $(CFLAGS_EFI) -Os -ffreestanding
-CFLAGS_REMOVE_boothart.o := $(CFLAGS_NON_EFI)
-CFLAGS_helloworld.o := $(CFLAGS_EFI) -Os -ffreestanding
-CFLAGS_REMOVE_helloworld.o := $(CFLAGS_NON_EFI)
-CFLAGS_smbiosdump.o := $(CFLAGS_EFI) -Os -ffreestanding
-CFLAGS_REMOVE_smbiosdump.o := $(CFLAGS_NON_EFI)
-CFLAGS_dtbdump.o := $(CFLAGS_EFI) -Os -ffreestanding
-CFLAGS_REMOVE_dtbdump.o := $(CFLAGS_NON_EFI)
-CFLAGS_initrddump.o := $(CFLAGS_EFI) -Os -ffreestanding
-CFLAGS_REMOVE_initrddump.o := $(CFLAGS_NON_EFI)
 
 # These are the apps that are built
 apps-$(CONFIG_RISCV) += boothart
@@ -80,5 +70,10 @@ obj-$(CONFIG_EFI_ECPT) += efi_conformance.o
 EFI_VAR_SEED_FILE := $(subst $\",,$(CONFIG_EFI_VAR_SEED_FILE))
 $(obj)/efi_var_seed.o: $(srctree)/$(EFI_VAR_SEED_FILE)
 
+# Set the C flags to add and remove for each app
+$(foreach f,$(apps-y),\
+	$(eval CFLAGS_$(f).o := $(CFLAGS_EFI) -Os -ffreestanding)\
+	$(eval CFLAGS_REMOVE_$(f).o := $(CFLAGS_NON_EFI)))
+
 always += $(foreach f,$(apps-y),$(f).efi)
 targets += $(foreach f,$(apps-y),$(f).o)
Signature · 1 line
2.34.1
#10 lore raw

PATCH v4 7/14 efi_loader: Show the vendor in helloworld

In reply to Simon Glass

Show the vendor name so it is clear which firmware is being used, e.g. whether U-Boot is providing the boot services.

---

(no changes since v2)

Changes in v2:
- Reword commit message
- Use 'Firmware vendor' instead of just 'Vendor'

 lib/efi_loader/helloworld.c | 3 +++
 1 file changed, 3 insertions(+)
lib/efi_loader/helloworld.c +3 -0
index 586177de0c8..c4d2afcb40a 100644
@@ -237,6 +237,9 @@ efi_status_t EFIAPI efi_main(efi_handle_t handle,
 			(con_out, u"Missing device path for device handle\r\n");
 		goto out;
 	}
+	con_out->output_string(con_out, u"Firmware vendor: ");
+	con_out->output_string(con_out, systab->fw_vendor);
+	con_out->output_string(con_out, u"\n");
 	con_out->output_string(con_out, u"Boot device: ");
 	ret = print_device_path(device_path, device_path_to_text);
 	if (ret != EFI_SUCCESS)
Signature · 1 line
2.34.1
#11 lore raw

PATCH v4 8/14 efi: Use the same filename for all sandbox builds

In reply to Simon Glass

Sandbox is not a real architecture, but within U-Boot it is real enough. We should not need to pretend it is x86 or ARM anywhere in the code.

Also we want to be able to locate the sandbox app using a single filename, 'bootsbox.efi', to avoid needing tests to produce different files on each host architecture.

Drop the confusing use of host architecture and just let sandbox be sandbox.

Fixes 3a0654ecd0d ("efi_loader: correctly identify binary name")

---

(no changes since v3)

Changes in v3:
- Put back the Linaro copyright accidentally removed

 include/efi_default_filename.h | 24 ++----------------------
 1 file changed, 2 insertions(+), 22 deletions(-)
include/efi_default_filename.h +2 -22
index 77932984b55..06ca8735002 100644
@@ -16,26 +16,8 @@
 #undef BOOTEFI_NAME
 
 #ifdef CONFIG_SANDBOX
-
-#if HOST_ARCH == HOST_ARCH_X86_64
-#define BOOTEFI_NAME "BOOTX64.EFI"
-#elif HOST_ARCH == HOST_ARCH_X86
-#define BOOTEFI_NAME "BOOTIA32.EFI"
-#elif HOST_ARCH == HOST_ARCH_AARCH64
-#define BOOTEFI_NAME "BOOTAA64.EFI"
-#elif HOST_ARCH == HOST_ARCH_ARM
-#define BOOTEFI_NAME "BOOTARM.EFI"
-#elif HOST_ARCH == HOST_ARCH_RISCV32
-#define BOOTEFI_NAME "BOOTRISCV32.EFI"
-#elif HOST_ARCH == HOST_ARCH_RISCV64
-#define BOOTEFI_NAME "BOOTRISCV64.EFI"
-#else
-#error Unsupported UEFI architecture
-#endif
-
-#else
-
-#if defined(CONFIG_ARM64)
+#define BOOTEFI_NAME "BOOTSBOX.EFI"
+#elif defined(CONFIG_ARM64)
 #define BOOTEFI_NAME "BOOTAA64.EFI"
 #elif defined(CONFIG_ARM)
 #define BOOTEFI_NAME "BOOTARM.EFI"
@@ -52,5 +34,3 @@
 #endif
 
 #endif
-
-#endif
Signature · 1 line
2.34.1
Reviewed-by on v4 8/14
#12 lore raw

Re: [PATCH v4 08/14] efi: Use the same filename for all sandbox builds

Hi Simon,

Quoted 8 lines · Simon Glass

Sandbox is not a real architecture, but within U-Boot it is real enough. We should not need to pretend it is x86 or ARM anywhere in the code.

Also we want to be able to locate the sandbox app using a single filename, 'bootsbox.efi', to avoid needing tests to produce different files on each host architecture.

Quoted 5 lines

Drop the confusing use of host architecture and just let sandbox be sandbox.

Fixes 3a0654ecd0d ("efi_loader: correctly identify binary name")

The reasoning here, was that sandbox is compiled for the host arch, that's why the name were preserved.
I don't mind changing that, but we don't need the fixes tag.

Without that

Quoted 52 lines

---

(no changes since v3)

Changes in v3:
- Put back the Linaro copyright accidentally removed

 include/efi_default_filename.h | 24 ++----------------------
 1 file changed, 2 insertions(+), 22 deletions(-)
include/efi_default_filename.h +2 -23
index 77932984b55..06ca8735002 100644
@@ -16,26 +16,8 @@
 #undef BOOTEFI_NAME
 
 #ifdef CONFIG_SANDBOX
-
-#if HOST_ARCH == HOST_ARCH_X86_64
-#define BOOTEFI_NAME "BOOTX64.EFI"
-#elif HOST_ARCH == HOST_ARCH_X86
-#define BOOTEFI_NAME "BOOTIA32.EFI"
-#elif HOST_ARCH == HOST_ARCH_AARCH64
-#define BOOTEFI_NAME "BOOTAA64.EFI"
-#elif HOST_ARCH == HOST_ARCH_ARM
-#define BOOTEFI_NAME "BOOTARM.EFI"
-#elif HOST_ARCH == HOST_ARCH_RISCV32
-#define BOOTEFI_NAME "BOOTRISCV32.EFI"
-#elif HOST_ARCH == HOST_ARCH_RISCV64
-#define BOOTEFI_NAME "BOOTRISCV64.EFI"
-#else
-#error Unsupported UEFI architecture
-#endif
-
-#else
-
-#if defined(CONFIG_ARM64)
+#define BOOTEFI_NAME "BOOTSBOX.EFI"
+#elif defined(CONFIG_ARM64)
 #define BOOTEFI_NAME "BOOTAA64.EFI"
 #elif defined(CONFIG_ARM)
 #define BOOTEFI_NAME "BOOTARM.EFI"
@@ -52,5 +34,3 @@
 #endif
 
 #endif
-
-#endif
--

2.34.1

#13 lore raw

PATCH v4 9/14 bootstd: Add debugging for efi bootmeth

In reply to Simon Glass

Add a little debugging so we can see what is happening.

---

(no changes since v1)

 boot/bootmeth_efi.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
boot/bootmeth_efi.c +9 -2
index 39232eb2e25..99887a89f02 100644
@@ -163,8 +163,10 @@ static int distro_efi_try_bootflow_files(struct udevice *dev,
 	int ret, seq;
 
 	/* We require a partition table */
-	if (!bflow->part)
+	if (!bflow->part) {
+		log_debug("no partitions\n");
 		return -ENOENT;
+	}
 
 	strcpy(fname, EFI_DIRNAME);
 	strcat(fname, BOOTEFI_NAME);
@@ -172,8 +174,10 @@ static int distro_efi_try_bootflow_files(struct udevice *dev,
 	if (bflow->blk)
 		 desc = dev_get_uclass_plat(bflow->blk);
 	ret = bootmeth_try_file(bflow, desc, NULL, fname);
-	if (ret)
+	if (ret) {
+		log_debug("no file\n");
 		return log_msg_ret("try", ret);
+	}
 
 	/* Since we can access the file, let's call it ready */
 	bflow->state = BOOTFLOWST_READY;
@@ -308,6 +312,8 @@ static int distro_efi_read_bootflow(struct udevice *dev, struct bootflow *bflow)
 {
 	int ret;
 
+	log_debug("dev='%s', part=%d\n", bflow->dev->name, bflow->part);
+
 	/*
 	 * bootmeth_efi doesn't allocate any buffer neither for blk nor net device
 	 * set flag to avoid freeing static buffer.
@@ -333,6 +339,7 @@ static int distro_efi_boot(struct udevice *dev, struct bootflow *bflow)
 	ulong kernel, fdt;
 	int ret;
 
+	log_debug("boot\n");
 	kernel = env_get_hex("kernel_addr_r", 0);
 	if (!bootmeth_uses_network(bflow)) {
 		ret = efiload_read_file(bflow, kernel);
Signature · 1 line
2.34.1
Reviewed-by on v4 9/14
#14 lore raw

Re: [PATCH v4 09/14] bootstd: Add debugging for efi bootmeth

Quoted 57 lines · Simon Glass

Add a little debugging so we can see what is happening.

---

(no changes since v1)

 boot/bootmeth_efi.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
boot/bootmeth_efi.c +9 -3
index 39232eb2e25..99887a89f02 100644
@@ -163,8 +163,10 @@ static int distro_efi_try_bootflow_files(struct udevice *dev,
        int ret, seq;
 
        /* We require a partition table */
-       if (!bflow->part)
+       if (!bflow->part) {
+               log_debug("no partitions\n");
                return -ENOENT;
+       }
 
        strcpy(fname, EFI_DIRNAME);
        strcat(fname, BOOTEFI_NAME);
@@ -172,8 +174,10 @@ static int distro_efi_try_bootflow_files(struct udevice *dev,
        if (bflow->blk)
                 desc = dev_get_uclass_plat(bflow->blk);
        ret = bootmeth_try_file(bflow, desc, NULL, fname);
-       if (ret)
+       if (ret) {
+               log_debug("no file\n");
                return log_msg_ret("try", ret);
+       }
 
        /* Since we can access the file, let's call it ready */
        bflow->state = BOOTFLOWST_READY;
@@ -308,6 +312,8 @@ static int distro_efi_read_bootflow(struct udevice *dev, struct bootflow *bflow)
 {
        int ret;
 
+       log_debug("dev='%s', part=%d\n", bflow->dev->name, bflow->part);
+
        /*
         * bootmeth_efi doesn't allocate any buffer neither for blk nor net device
         * set flag to avoid freeing static buffer.
@@ -333,6 +339,7 @@ static int distro_efi_boot(struct udevice *dev, struct bootflow *bflow)
        ulong kernel, fdt;
        int ret;
 
+       log_debug("boot\n");
        kernel = env_get_hex("kernel_addr_r", 0);
        if (!bootmeth_uses_network(bflow)) {
                ret = efiload_read_file(bflow, kernel);
--
Quoted 2 lines

2.34.1

#15 lore raw

PATCH v4 10/14 efi_loader: Disable ANSI output for tests

In reply to Simon Glass

We don't want ANSI characters written in tests since it is a pain to check the output with ut_assert_nextline() et al.

Provide a way to tests to request that ANSI characters not be sent.

Add a proper function comment while we are here, to encourage others.

---

(no changes since v1)

 include/efi_loader.h         | 21 ++++++++++++++++++++-
 lib/efi_loader/efi_console.c | 26 +++++++++++++++++---------
 2 files changed, 37 insertions(+), 10 deletions(-)
include/efi_loader.h +20 -1
index f84852e384f..82b90ee0f1d 100644
@@ -531,8 +531,27 @@ efi_status_t efi_bootmgr_delete_boot_option(u16 boot_index);
 efi_status_t efi_bootmgr_run(void *fdt);
 /* search the boot option index in BootOrder */
 bool efi_search_bootorder(u16 *bootorder, efi_uintn_t num, u32 target, u32 *index);
-/* Set up console modes */
+
+/**
+ * efi_setup_console_size() - update the mode table.
+ *
+ * By default the only mode available is 80x25. If the console has at least 50
+ * lines, enable mode 80x50. If we can query the console size and it is neither
+ * 80x25 nor 80x50, set it as an additional mode.
+ */
 void efi_setup_console_size(void);
+
+/**
+ * efi_console_set_ansi() - Set whether ANSI characters should be emitted
+ *
+ * These characters mess up tests which use ut_assert_nextline(). Call this
+ * function to tell efi_loader not to emit these characters when starting up the
+ * terminal
+ *
+ * @allow_ansi: Allow emitting ANSI characters
+ */
+void efi_console_set_ansi(bool allow_ansi);
+
 /* Set up load options from environment variable */
 efi_status_t efi_env_set_load_options(efi_handle_t handle, const char *env_var,
 				      u16 **load_options);
lib/efi_loader/efi_console.c +17 -9
index cea50c748aa..569fc9199bc 100644
@@ -30,6 +30,17 @@ struct cout_mode {
 
 __maybe_unused static struct efi_object uart_obj;
 
+/*
+ * suppress emission of ANSI codes for use by unit tests. Leave it as 0 for the
+ * default behaviour
+ */
+static bool no_ansi;
+
+void efi_console_set_ansi(bool allow_ansi)
+{
+	no_ansi = !allow_ansi;
+}
+
 static struct cout_mode efi_cout_modes[] = {
 	/* EFI Mode 0 is 80x25 and always present */
 	{
@@ -348,13 +359,6 @@ static int __maybe_unused query_vidconsole(int *rows, int *cols)
 	return 0;
 }
 
-/**
- * efi_setup_console_size() - update the mode table.
- *
- * By default the only mode available is 80x25. If the console has at least 50
- * lines, enable mode 80x50. If we can query the console size and it is neither
- * 80x25 nor 80x50, set it as an additional mode.
- */
 void efi_setup_console_size(void)
 {
 	int rows = 25, cols = 80;
@@ -362,8 +366,12 @@ void efi_setup_console_size(void)
 
 	if (IS_ENABLED(CONFIG_VIDEO))
 		ret = query_vidconsole(&rows, &cols);
-	if (ret)
-		ret = query_console_serial(&rows, &cols);
+	if (ret) {
+		if (no_ansi)
+			ret = 0;
+		else
+			ret = query_console_serial(&rows, &cols);
+	}
 	if (ret)
 		return;
 
Signature · 1 line
2.34.1
#16 lore raw

Re: [PATCH v4 10/14] efi_loader: Disable ANSI output for tests

Hi Simon,

Quoted 87 lines · Simon Glass

We don't want ANSI characters written in tests since it is a pain to check the output with ut_assert_nextline() et al.

Provide a way to tests to request that ANSI characters not be sent.

Add a proper function comment while we are here, to encourage others.

---

(no changes since v1)

 include/efi_loader.h         | 21 ++++++++++++++++++++-
 lib/efi_loader/efi_console.c | 26 +++++++++++++++++---------
 2 files changed, 37 insertions(+), 10 deletions(-)
include/efi_loader.h +20 -1
index f84852e384f..82b90ee0f1d 100644
@@ -531,8 +531,27 @@ efi_status_t efi_bootmgr_delete_boot_option(u16 boot_index);
 efi_status_t efi_bootmgr_run(void *fdt);
 /* search the boot option index in BootOrder */
 bool efi_search_bootorder(u16 *bootorder, efi_uintn_t num, u32 target, u32 *index);
-/* Set up console modes */
+
+/**
+ * efi_setup_console_size() - update the mode table.
+ *
+ * By default the only mode available is 80x25. If the console has at least 50
+ * lines, enable mode 80x50. If we can query the console size and it is neither
+ * 80x25 nor 80x50, set it as an additional mode.
+ */
 void efi_setup_console_size(void);
+
+/**
+ * efi_console_set_ansi() - Set whether ANSI characters should be emitted
+ *
+ * These characters mess up tests which use ut_assert_nextline(). Call this
+ * function to tell efi_loader not to emit these characters when starting up the
+ * terminal
+ *
+ * @allow_ansi: Allow emitting ANSI characters
+ */
+void efi_console_set_ansi(bool allow_ansi);
+
 /* Set up load options from environment variable */
 efi_status_t efi_env_set_load_options(efi_handle_t handle, const char *env_var,
                                      u16 **load_options);
lib/efi_loader/efi_console.c +11 -7
index cea50c748aa..569fc9199bc 100644
@@ -30,6 +30,17 @@ struct cout_mode {
 
 __maybe_unused static struct efi_object uart_obj;
 
+/*
+ * suppress emission of ANSI codes for use by unit tests. Leave it as 0 for the
+ * default behaviour
+ */
+static bool no_ansi;
+
+void efi_console_set_ansi(bool allow_ansi)
+{
+       no_ansi = !allow_ansi;
+}
+
 static struct cout_mode efi_cout_modes[] = {
        /* EFI Mode 0 is 80x25 and always present */
        {
@@ -348,13 +359,6 @@ static int __maybe_unused query_vidconsole(int *rows, int *cols)
        return 0;
 }
 
-/**
- * efi_setup_console_size() - update the mode table.
- *
- * By default the only mode available is 80x25. If the console has at least 50
- * lines, enable mode 80x50. If we can query the console size and it is neither
- * 80x25 nor 80x50, set it as an additional mode.
- */
 void efi_setup_console_size(void)
 {
        int rows = 25, cols = 80;

lib/efi_loader/efi_console.c void efi_setup_console_size(void) · line 370

Quoted 7 lines
lib/efi_loader/efi_console.c +2 -2
@@ -362,8 +366,12 @@ void efi_setup_console_size(void)
 
        if (IS_ENABLED(CONFIG_VIDEO))
                ret = query_vidconsole(&rows, &cols);
-       if (ret)
-               ret = query_console_serial(&rows, &cols);
+       if (ret) {
+               if (no_ansi)

What are you trying to do here? The function you are skipping just queries the number of columns and rows. The defaults on the function are 80x25, so the setup will continue

Thanks
/Ilias

Quoted 10 lines
lib/efi_loader/efi_console.c +4 -1
+                       ret = 0;
+               else
+                       ret = query_console_serial(&rows, &cols);
+       }
        if (ret)
                return;
 
--

2.34.1

#17 lore raw

Re: [PATCH v4 10/14] efi_loader: Disable ANSI output for tests

Hi Ilias,

Quoted 92 lines · Ilias Apalodimas

Hi Simon,

Quoted 88 lines · Simon Glass

We don't want ANSI characters written in tests since it is a pain to check the output with ut_assert_nextline() et al.

Provide a way to tests to request that ANSI characters not be sent.

Add a proper function comment while we are here, to encourage others.

---

(no changes since v1)

 include/efi_loader.h         | 21 ++++++++++++++++++++-
 lib/efi_loader/efi_console.c | 26 +++++++++++++++++---------
 2 files changed, 37 insertions(+), 10 deletions(-)
include/efi_loader.h +20 -1
index f84852e384f..82b90ee0f1d 100644
@@ -531,8 +531,27 @@ efi_status_t efi_bootmgr_delete_boot_option(u16 boot_index);
 efi_status_t efi_bootmgr_run(void *fdt);
 /* search the boot option index in BootOrder */
 bool efi_search_bootorder(u16 *bootorder, efi_uintn_t num, u32 target, u32 *index);
-/* Set up console modes */
+
+/**
+ * efi_setup_console_size() - update the mode table.
+ *
+ * By default the only mode available is 80x25. If the console has at least 50
+ * lines, enable mode 80x50. If we can query the console size and it is neither
+ * 80x25 nor 80x50, set it as an additional mode.
+ */
 void efi_setup_console_size(void);
+
+/**
+ * efi_console_set_ansi() - Set whether ANSI characters should be emitted
+ *
+ * These characters mess up tests which use ut_assert_nextline(). Call this
+ * function to tell efi_loader not to emit these characters when starting up the
+ * terminal
+ *
+ * @allow_ansi: Allow emitting ANSI characters
+ */
+void efi_console_set_ansi(bool allow_ansi);
+
 /* Set up load options from environment variable */
 efi_status_t efi_env_set_load_options(efi_handle_t handle, const char *env_var,
                                      u16 **load_options);
lib/efi_loader/efi_console.c +11 -7
index cea50c748aa..569fc9199bc 100644
@@ -30,6 +30,17 @@ struct cout_mode {
 
 __maybe_unused static struct efi_object uart_obj;
 
+/*
+ * suppress emission of ANSI codes for use by unit tests. Leave it as 0 for the
+ * default behaviour
+ */
+static bool no_ansi;
+
+void efi_console_set_ansi(bool allow_ansi)
+{
+       no_ansi = !allow_ansi;
+}
+
 static struct cout_mode efi_cout_modes[] = {
        /* EFI Mode 0 is 80x25 and always present */
        {
@@ -348,13 +359,6 @@ static int __maybe_unused query_vidconsole(int *rows, int *cols)
        return 0;
 }
 
-/**
- * efi_setup_console_size() - update the mode table.
- *
- * By default the only mode available is 80x25. If the console has at least 50
- * lines, enable mode 80x50. If we can query the console size and it is neither
- * 80x25 nor 80x50, set it as an additional mode.
- */
 void efi_setup_console_size(void)
 {
        int rows = 25, cols = 80;
@@ -362,8 +366,12 @@ void efi_setup_console_size(void)
 
Quoted 10 lines

lib/efi_loader/efi_console.c void efi_setup_console_size(void) · line 370

Quoted 6 lines
lib/efi_loader/efi_console.c +2 -2
        if (IS_ENABLED(CONFIG_VIDEO))
                ret = query_vidconsole(&rows, &cols);
-       if (ret)
-               ret = query_console_serial(&rows, &cols);
+       if (ret) {
+               if (no_ansi)

What are you trying to do here? The function you are skipping just queries the number of columns and rows. The defaults on the function are 80x25, so the setup will continue

Well, the query works by sending out some ANSI characters to the terminal, then checking the result. In a unit test, these characters are captured and the unit test fails when ut_assert_nextline() gets unexpected output.

Quoted 13 lines

Thanks
/Ilias

Quoted 10 lines
lib/efi_loader/efi_console.c +4 -1
+                       ret = 0;
+               else
+                       ret = query_console_serial(&rows, &cols);
+       }
        if (ret)
                return;
 
--

2.34.1

Regards,
Simon

#18 lore raw

Re: [PATCH v4 10/14] efi_loader: Disable ANSI output for tests

Quoted 107 lines · Simon Glass

Hi Ilias,

Quoted 92 lines · Ilias Apalodimas

Hi Simon,

Quoted 88 lines · Simon Glass

We don't want ANSI characters written in tests since it is a pain to check the output with ut_assert_nextline() et al.

Provide a way to tests to request that ANSI characters not be sent.

Add a proper function comment while we are here, to encourage others.

---

(no changes since v1)

  include/efi_loader.h         | 21 ++++++++++++++++++++-
  lib/efi_loader/efi_console.c | 26 +++++++++++++++++---------
  2 files changed, 37 insertions(+), 10 deletions(-)
include/efi_loader.h +20 -1
index f84852e384f..82b90ee0f1d 100644
@@ -531,8 +531,27 @@ efi_status_t efi_bootmgr_delete_boot_option(u16 boot_index);
  efi_status_t efi_bootmgr_run(void *fdt);
  /* search the boot option index in BootOrder */
  bool efi_search_bootorder(u16 *bootorder, efi_uintn_t num, u32 target, u32 *index);
-/* Set up console modes */
+
+/**
+ * efi_setup_console_size() - update the mode table.
+ *
+ * By default the only mode available is 80x25. If the console has at least 50
+ * lines, enable mode 80x50. If we can query the console size and it is neither
+ * 80x25 nor 80x50, set it as an additional mode.
+ */
  void efi_setup_console_size(void);
+
+/**
+ * efi_console_set_ansi() - Set whether ANSI characters should be emitted
+ *
+ * These characters mess up tests which use ut_assert_nextline(). Call this
+ * function to tell efi_loader not to emit these characters when starting up the
+ * terminal
+ *
+ * @allow_ansi: Allow emitting ANSI characters
+ */
+void efi_console_set_ansi(bool allow_ansi);
+
  /* Set up load options from environment variable */
  efi_status_t efi_env_set_load_options(efi_handle_t handle, const char *env_var,
                                       u16 **load_options);
lib/efi_loader/efi_console.c +11 -7
index cea50c748aa..569fc9199bc 100644
@@ -30,6 +30,17 @@ struct cout_mode {
 
  __maybe_unused static struct efi_object uart_obj;
 
+/*
+ * suppress emission of ANSI codes for use by unit tests. Leave it as 0 for the
+ * default behaviour
+ */
+static bool no_ansi;
+
+void efi_console_set_ansi(bool allow_ansi)
+{
+       no_ansi = !allow_ansi;
+}
+
  static struct cout_mode efi_cout_modes[] = {
         /* EFI Mode 0 is 80x25 and always present */
         {
@@ -348,13 +359,6 @@ static int __maybe_unused query_vidconsole(int *rows, int *cols)
         return 0;
  }
 
-/**
- * efi_setup_console_size() - update the mode table.
- *
- * By default the only mode available is 80x25. If the console has at least 50
- * lines, enable mode 80x50. If we can query the console size and it is neither
- * 80x25 nor 80x50, set it as an additional mode.
- */
  void efi_setup_console_size(void)
  {
         int rows = 25, cols = 80;
@@ -362,8 +366,12 @@ void efi_setup_console_size(void)
 
Quoted 10 lines

lib/efi_loader/efi_console.c void efi_setup_console_size(void) · line 370

Quoted 6 lines
lib/efi_loader/efi_console.c +2 -2
         if (IS_ENABLED(CONFIG_VIDEO))
                 ret = query_vidconsole(&rows, &cols);
-       if (ret)
-               ret = query_console_serial(&rows, &cols);
+       if (ret) {
+               if (no_ansi)

What are you trying to do here? The function you are skipping just queries the number of columns and rows. The defaults on the function are 80x25, so the setup will continue

Quoted 4 lines

Well, the query works by sending out some ANSI characters to the terminal, then checking the result. In a unit test, these characters are captured and the unit test fails when ut_assert_nextline() gets unexpected output.

We should be able to compile U-Boot with all tests enabled such that it is still usable on real hardware.

Your patch is not compatible with this.

Please, adjust readline_check() to strip out non-printing ANSI codes.

Best regards

Heinrich

Quoted 17 lines
Quoted 14 lines

Thanks
/Ilias

Quoted 10 lines
lib/efi_loader/efi_console.c +4 -1
+                       ret = 0;
+               else
+                       ret = query_console_serial(&rows, &cols);
+       }
         if (ret)
                 return;
 
--

2.34.1

Regards,
Simon

#19 lore raw

Re: [PATCH v4 10/14] efi_loader: Disable ANSI output for tests

Quoted 108 lines · Heinrich Schuchardt
Quoted 107 lines · Simon Glass

Hi Ilias,

Quoted 102 lines · Ilias Apalodimas

Hi Simon,

Quoted 87 lines · Simon Glass

We don't want ANSI characters written in tests since it is a pain to check the output with ut_assert_nextline() et al.

Provide a way to tests to request that ANSI characters not be sent.

Add a proper function comment while we are here, to encourage others.

---

(no changes since v1)

  include/efi_loader.h         | 21 ++++++++++++++++++++-
  lib/efi_loader/efi_console.c | 26 +++++++++++++++++---------
  2 files changed, 37 insertions(+), 10 deletions(-)
include/efi_loader.h +20 -1
index f84852e384f..82b90ee0f1d 100644
@@ -531,8 +531,27 @@ efi_status_t efi_bootmgr_delete_boot_option(u16 boot_index);
  efi_status_t efi_bootmgr_run(void *fdt);
  /* search the boot option index in BootOrder */
  bool efi_search_bootorder(u16 *bootorder, efi_uintn_t num, u32 target, u32 *index);
-/* Set up console modes */
+
+/**
+ * efi_setup_console_size() - update the mode table.
+ *
+ * By default the only mode available is 80x25. If the console has at least 50
+ * lines, enable mode 80x50. If we can query the console size and it is neither
+ * 80x25 nor 80x50, set it as an additional mode.
+ */
  void efi_setup_console_size(void);
+
+/**
+ * efi_console_set_ansi() - Set whether ANSI characters should be emitted
+ *
+ * These characters mess up tests which use ut_assert_nextline(). Call this
+ * function to tell efi_loader not to emit these characters when starting up the
+ * terminal
+ *
+ * @allow_ansi: Allow emitting ANSI characters
+ */
+void efi_console_set_ansi(bool allow_ansi);
+
  /* Set up load options from environment variable */
  efi_status_t efi_env_set_load_options(efi_handle_t handle, const char *env_var,
                                       u16 **load_options);
lib/efi_loader/efi_console.c +11 -7
index cea50c748aa..569fc9199bc 100644
@@ -30,6 +30,17 @@ struct cout_mode {
 
  __maybe_unused static struct efi_object uart_obj;
 
+/*
+ * suppress emission of ANSI codes for use by unit tests. Leave it as 0 for the
+ * default behaviour
+ */
+static bool no_ansi;
+
+void efi_console_set_ansi(bool allow_ansi)
+{
+       no_ansi = !allow_ansi;
+}
+
  static struct cout_mode efi_cout_modes[] = {
         /* EFI Mode 0 is 80x25 and always present */
         {
@@ -348,13 +359,6 @@ static int __maybe_unused query_vidconsole(int *rows, int *cols)
         return 0;
  }
 
-/**
- * efi_setup_console_size() - update the mode table.
- *
- * By default the only mode available is 80x25. If the console has at least 50
- * lines, enable mode 80x50. If we can query the console size and it is neither
- * 80x25 nor 80x50, set it as an additional mode.
- */
  void efi_setup_console_size(void)
  {
         int rows = 25, cols = 80;

lib/efi_loader/efi_console.c void efi_setup_console_size(void) · line 370

Quoted 7 lines
lib/efi_loader/efi_console.c +2 -2
@@ -362,8 +366,12 @@ void efi_setup_console_size(void)
 
         if (IS_ENABLED(CONFIG_VIDEO))
                 ret = query_vidconsole(&rows, &cols);
-       if (ret)
-               ret = query_console_serial(&rows, &cols);
+       if (ret) {
+               if (no_ansi)

What are you trying to do here? The function you are skipping just queries the number of columns and rows. The defaults on the function are 80x25, so the setup will continue

Quoted 7 lines
Quoted 4 lines

Well, the query works by sending out some ANSI characters to the terminal, then checking the result. In a unit test, these characters are captured and the unit test fails when ut_assert_nextline() gets unexpected output.

We should be able to compile U-Boot with all tests enabled such that it is still usable on real hardware.

Please keep in mind "real hardware" is where this is the biggest problem today. I don't run a bunch of the EFI tests on real hardware because the ANSI stuff leads to spurious failures, and so it's best to just turn that off rather than re-run the test and see if it passes the next time.

Signature · 1 line
Tom
#20 lore raw

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

---

(no changes since v1)

 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 ab2c1c44364..4de05c6f2d6 100644
@@ -528,4 +528,14 @@ 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
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 +68 -0

68 lines not on this page · raw message

Signature · 1 line
2.34.1
#21 lore raw

Re: [PATCH v4 11/14] efi_loader: Add a test app

Hi Simon,

Quoted 4 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.

We have tests in py and efi selftests, can you explain why you need another EFI app?
I'd rather skip this and add it when needed

Thanks
/Ilias

Quoted 120 lines

---

(no changes since v1)

 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 ab2c1c44364..4de05c6f2d6 100644
@@ -528,4 +528,14 @@ 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
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 +68 -1
new file mode 100644
index 00000000000..feb444c92e9
@@ -0,0 +1,68 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * 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 */
+       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 sevices\n");
+
+       /* exit boot services so that this part of U-Boot can be tested */
+       boottime->exit_boot_services(handle, map_key);
+
+       /* now exit for real */
+       ret = boottime->exit(handle, ret, 0, NULL);
+
+       /* We should never arrive here */
+       return ret;
+}
--

2.34.1

#22 lore raw

Re: [PATCH v4 11/14] efi_loader: Add a test app

Hi Ilias,

Quoted 5 lines · Ilias Apalodimas

Hi Simon,

Quoted 1 line · Simon Glass
Quoted 7 lines
Quoted 3 lines

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.

We have tests in py and efi selftests, can you explain why you need another EFI app?
I'd rather skip this and add it when needed

Well, I originally hacked the hello-world app but you and Heinrich both asked for a new one[1].

It does something strange in that it exits boot services, then exits back to sandbox, so that I can test that the EBS doesn't do anything odd. It was causing a hang booting Ubuntu due to a bug I later fixed.

Regards,
Simon

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

#23 lore raw

PATCH v4 12/14 efi_loader: Avoid using sandbox virtio devices

In reply to Simon Glass

While sandbox supports virtio it cannot support actually using the block devices to read files, since there is nothing on the other end of the 'virtqueue'.

A recent change makes EFI probe all block devices, whether used or not. This is apparently required by EFI, although it violates U-Boot's lazy-init principle.

We cannot just drop the virtio devices as they are used in sandbox tests.

So for now just add a special case to work around this.

The eventual fix is likely adding an implementation of virtio_sandbox_notify() to actually do the block read. That is tracked in [1].

Fixes d5391bf02b9 ("efi_loader: ensure all block devices are probed")

[1] https://source.denx.de/u-boot/u-boot/-/issues/37
---

(no changes since v3)

Changes in v3:
- Add a Fixes tag
- Mention the issue created for this problem

 lib/efi_loader/efi_disk.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
lib/efi_loader/efi_disk.c +13 -1
index 93a9a5ac025..2e1d37848fc 100644
@@ -838,8 +838,20 @@ efi_status_t efi_disk_get_device_name(const efi_handle_t handle, char *buf, int
 efi_status_t efi_disks_register(void)
 {
 	struct udevice *dev;
+	struct uclass *uc;
 
-	uclass_foreach_dev_probe(UCLASS_BLK, dev) {
+	uclass_id_foreach_dev(UCLASS_BLK, dev, uc) {
+		/*
+		 * The virtio block-device hangs on sandbox when accessed since
+		 * there is nothing listening to the mailbox
+		 */
+		if (IS_ENABLED(CONFIG_SANDBOX)) {
+			struct blk_desc *desc = dev_get_uclass_plat(dev);
+
+			if (desc->uclass_id == UCLASS_VIRTIO)
+				continue;
+		}
+		device_probe(dev);
 	}
 
 	return EFI_SUCCESS;
Signature · 1 line
2.34.1
Reviewed-by on v4 12/14
#24 lore raw

Re: [PATCH v4 12/14] efi_loader: Avoid using sandbox virtio devices

Quoted 8 lines · Simon Glass

While sandbox supports virtio it cannot support actually using the block devices to read files, since there is nothing on the other end of the 'virtqueue'.

A recent change makes EFI probe all block devices, whether used or not. This is apparently required by EFI, although it violates U-Boot's lazy-init principle.

I think the early scanning is due to CONFIG_EFI_CAPSULE_ON_DISK_EARLY. I also think we can get rid of this option, but I'll have to dig a bit deeper

In any case, I am fine with the workaround

Quoted 52 lines

We cannot just drop the virtio devices as they are used in sandbox tests.

So for now just add a special case to work around this.

The eventual fix is likely adding an implementation of virtio_sandbox_notify() to actually do the block read. That is tracked in [1].

Fixes d5391bf02b9 ("efi_loader: ensure all block devices are probed")

[1] https://source.denx.de/u-boot/u-boot/-/issues/37
---

(no changes since v3)

Changes in v3:
- Add a Fixes tag
- Mention the issue created for this problem

 lib/efi_loader/efi_disk.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
lib/efi_loader/efi_disk.c +13 -2
index 93a9a5ac025..2e1d37848fc 100644
@@ -838,8 +838,20 @@ efi_status_t efi_disk_get_device_name(const efi_handle_t handle, char *buf, int
 efi_status_t efi_disks_register(void)
 {
        struct udevice *dev;
+       struct uclass *uc;
 
-       uclass_foreach_dev_probe(UCLASS_BLK, dev) {
+       uclass_id_foreach_dev(UCLASS_BLK, dev, uc) {
+               /*
+                * The virtio block-device hangs on sandbox when accessed since
+                * there is nothing listening to the mailbox
+                */
+               if (IS_ENABLED(CONFIG_SANDBOX)) {
+                       struct blk_desc *desc = dev_get_uclass_plat(dev);
+
+                       if (desc->uclass_id == UCLASS_VIRTIO)
+                               continue;
+               }
+               device_probe(dev);
        }
 
        return EFI_SUCCESS;
--

2.34.1

#25 lore raw

Re: [PATCH v4 12/14] efi_loader: Avoid using sandbox virtio devices

Hi Ilias,

Quoted 11 lines · Ilias Apalodimas
Quoted 8 lines · Simon Glass

While sandbox supports virtio it cannot support actually using the block devices to read files, since there is nothing on the other end of the 'virtqueue'.

A recent change makes EFI probe all block devices, whether used or not. This is apparently required by EFI, although it violates U-Boot's lazy-init principle.

Quoted 7 lines

I think the early scanning is due to CONFIG_EFI_CAPSULE_ON_DISK_EARLY. I also think we can get rid of this option, but I'll have to dig a bit deeper

In any case, I am fine with the workaround

Thank you.

Regards,
Simon

#26 lore raw

PATCH v4 13/14 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.

---

(no changes since v1)

 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 -> 5016 bytes
 test/py/tests/test_ut.py            |  52 ++++++++++++++++++++++++----
 5 files changed, 65 insertions(+), 9 deletions(-)
 create mode 100644 test/py/tests/bootstd/flash1.img.xz
arch/sandbox/dts/test.dts +1 -1
index 5fb5eac862e..a99de6e62ce 100644
@@ -1507,7 +1507,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 de16a51956d..254fcd26a5c 100644
@@ -216,6 +216,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);
@@ -255,7 +259,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);
@@ -318,6 +326,10 @@ static int bootdev_test_prio(struct unit_test_state *uts)
 	/* 3 MMC and 3 USB bootdevs: MMC should come before USB */
 	console_record_reset_enable();
 	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);
@@ -335,6 +347,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 8ea091a36af..6d85cf20dd5 100644
@@ -537,7 +537,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..9148b91a20c1f0acb54449b124d1408961e92507
GIT binary patch
test/py/tests/test_ut.py +46 -6

95 lines not on this page · raw message

Signature · 1 line
2.34.1
#27 lore raw

Re: [PATCH v4 13/14] test: efi: boot: Set up an image suitable for EFI testing

Quoted 11 lines · 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.

[snip]

Quoted 11 lines
test/py/tests/test_ut.py +11 -0
+    try:
+        loop = mount_image(cons, fname, mnt, 'ext4')
+        mounted = True
+        efi_dir = os.path.join(mnt, 'EFI')
+        mkdir_cond(efi_dir)
+        bootdir = os.path.join(efi_dir, 'BOOT')
+        mkdir_cond(bootdir)
+        efi_src = os.path.join(cons.config.build_dir,
+                               f'lib/efi_loader/testapp.efi')
+        efi_dst = os.path.join(bootdir, 'BOOTSBOX.EFI')
+        with open(efi_src, 'rb') as inf:

test/py/tests/test_ut.py def test_ut_dm_init(u_boot_console): · line 585

Quoted 10 lines
test/py/tests/test_ut.py +10 -0
+            with open(efi_dst, 'wb') as outf:
+                outf.write(inf.read())
+    except ValueError as exc:
+        print(f'Falled to create image, failing back to prepared copy: {exc}')
+
+    finally:
+        if mounted:
+            u_boot_utils.run_and_log(cons, 'sudo umount --lazy %s' % mnt)
+        if loop:
+            u_boot_utils.run_and_log(cons, 'sudo losetup -d %s' % loop)

Please see
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
for inspiration on making this not require sudo.

Signature · 1 line
Tom
#28 lore raw

Re: [PATCH v4 13/14] test: efi: boot: Set up an image suitable for EFI testing

Hi Tom,

Quoted 36 lines · Tom Rini
Quoted 11 lines · 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.

[snip]

Quoted 11 lines
test/py/tests/test_ut.py +11 -0
+    try:
+        loop = mount_image(cons, fname, mnt, 'ext4')
+        mounted = True
+        efi_dir = os.path.join(mnt, 'EFI')
+        mkdir_cond(efi_dir)
+        bootdir = os.path.join(efi_dir, 'BOOT')
+        mkdir_cond(bootdir)
+        efi_src = os.path.join(cons.config.build_dir,
+                               f'lib/efi_loader/testapp.efi')
+        efi_dst = os.path.join(bootdir, 'BOOTSBOX.EFI')
+        with open(efi_src, 'rb') as inf:

test/py/tests/test_ut.py def test_ut_dm_init(u_boot_console): · line 585

Quoted 10 lines
test/py/tests/test_ut.py +10 -0
+            with open(efi_dst, 'wb') as outf:
+                outf.write(inf.read())
+    except ValueError as exc:
+        print(f'Falled to create image, failing back to prepared copy: {exc}')
+
+    finally:
+        if mounted:
+            u_boot_utils.run_and_log(cons, 'sudo umount --lazy %s' % mnt)
+        if loop:
+            u_boot_utils.run_and_log(cons, 'sudo losetup -d %s' % loop)
Quoted 3 lines

Please see
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
for inspiration on making this not require sudo.

It's optional, hence the fallback, but I'll need to wait until that stuff lands as we use common functions.

Regards,
Simon

#29 lore raw

PATCH v4 14/14 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.

---

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 | 58 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)
test/boot/bootflow.c +58 -0
index 6d85cf20dd5..8822dac8503 100644
@@ -13,6 +13,7 @@
 #include <cli.h>
 #include <dm.h>
 #include <efi_default_filename.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)
 {
 	/*
@@ -1225,3 +1229,57 @@ static int bootflow_android(struct unit_test_state *uts)
 	return 0;
 }
 BOOTSTD_TEST(bootflow_android, UT_TESTF_CONSOLE_REC);
+
+/* 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();
+
+	/* Avoid outputting ANSI characters which mess with our asserts */
+	efi_console_set_ansi(false);
+
+	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();
+
+	/* signal to helloworld to exit boot services */
+	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");
+	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 sevices");
+	ut_assert_nextline("## Application failed, r = 5");
+	ut_assert_nextline("Boot failed (err=-22)");
+
+	ut_assert_console_end();
+
+	return 0;
+}
+BOOTSTD_TEST(bootflow_efi, UT_TESTF_CONSOLE_REC);
Signature · 1 line
2.34.1