[PATCH 5/7] WIP: efi: Add a test for the EFI bootmeth

Simon Glass sjg at chromium.org
Tue Nov 21 12:35:51 CET 2023


Add a simple test which checks that we can run an EFI app and that the
call to exit boot services works OK.

This is intended to catch the recent bootflow bug fixed by:

  https://patchwork.ozlabs.org/project/uboot/patch/
  20231115183522.1.I4cbfd34d576c0ad66a74c6ec3e8024adabc73573 at changeid/

TODO:
- change it to use USB instead of mmc
- drop the hacks in test.dts

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 arch/sandbox/dts/test.dts | 10 +++++++-
 test/boot/bootflow.c      | 53 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 6fd62fcdf8d7..559292cc2f7a 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -43,6 +43,7 @@
 		mmc4 = "/mmc4";
 		mmc5 = "/mmc5";
 		mmc6 = "/mmc6";
+		mmc7 = "/mmc7";
 		pci0 = &pci0;
 		pci1 = &pci1;
 		pci2 = &pci2;
@@ -108,7 +109,7 @@
 		compatible = "u-boot,boot-std";
 
 		filename-prefixes = "/", "/boot/";
-		bootdev-order = "mmc2", "mmc1";
+		/*bootdev-order = "mmc2", "mmc1";*/
 
 		extlinux {
 			compatible = "u-boot,extlinux";
@@ -1127,6 +1128,13 @@
 		filename = "mmc6.img";
 	};
 
+	/* This is used for EFI tests */
+	mmc7 {
+/*		status = "disabled";*/
+		compatible = "sandbox,mmc";
+		filename = "mmc7.img";
+	};
+
 	pch {
 		compatible = "sandbox,pch";
 	};
diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index b97c566f000b..ad54ef6eaabc 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -13,6 +13,7 @@
 #include <bootstd.h>
 #include <cli.h>
 #include <dm.h>
+#include <efi_loader.h>
 #include <expo.h>
 #ifdef CONFIG_SANDBOX
 #include <asm/test.h>
@@ -30,6 +31,9 @@ DECLARE_GLOBAL_DATA_PTR;
 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)
 {
 	/*
@@ -1059,3 +1063,52 @@ static int bootflow_cros(struct unit_test_state *uts)
 	return 0;
 }
 BOOTSTD_TEST(bootflow_cros, 0);
+
+/* Test EFI bootmeth */
+static int bootflow_efi(struct unit_test_state *uts)
+{
+	ut_assertok(scan_mmc_bootdev(uts, "mmc7", true));
+	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   mmc          1  mmc7.bootdev.part_1       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 'mmc7.bootdev.part_1' with efi");
+	ut_assert_nextline("No EFI system partition");
+	ut_assert_nextline("No EFI system partition");
+	ut_assert_nextline("Failed to persist EFI variables");
+	ut_assert_nextline("EFI using ACPI tables at 8ef8000");
+	ut_assert_nextline("WARNING: Can't have ACPI table and device tree - ignoring DT.");
+	ut_assert_nextline("Booting /efi\\boot\\bootsbox.efi");
+
+	/* TODO: Why the \r ? */
+	ut_assert_nextline("Hello, world!\r");
+	ut_assert_nextline("Running on UEFI 2.10\r");
+	ut_assert_nextline("Have ACPI 2.0 table\r");
+	ut_assert_nextline("Have SMBIOS table\r");
+	ut_assert_nextline("Load options: <none>\r");
+	ut_assert_nextline("File path: /efi\\boot\\bootsbox.efi\r");
+	ut_assert_nextline("Missing device handle\r");
+	ut_assert_nextline("Exiting boot sevices");
+
+	ut_assert_console_end();
+
+	ut_assert_console_end();
+
+	return 0;
+}
+BOOTSTD_TEST(bootflow_efi, 0);
-- 
2.43.0.rc1.413.gea7ed67945-goog



More information about the U-Boot mailing list