[U-Boot] [PATCH v3 5/8] arm: efi: Add a hello world test program

Simon Glass sjg at chromium.org
Tue Oct 18 04:29:11 CEST 2016


It is useful to have a basic sanity check for EFI loader support. Add a
'bootefi hello' command which loads HelloWord.efi and runs it under U-Boot.

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

Changes in v3:
- Include a link to the program instead of adding it to the tree
- Fix several typos
- Align backslashes to the same column

Changes in v2: None

 arch/arm/lib/Makefile          |  7 +++++++
 cmd/Kconfig                    |  9 +++++++++
 cmd/bootefi.c                  | 26 ++++++++++++++++++++------
 doc/README.efi                 | 22 ++++++++++++++++++++++
 include/asm-generic/sections.h |  2 ++
 scripts/Makefile.lib           | 19 +++++++++++++++++++
 6 files changed, 79 insertions(+), 6 deletions(-)

diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index caa62c6..64378e1 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -30,6 +30,13 @@ obj-$(CONFIG_CMD_BOOTI) += bootm.o
 obj-$(CONFIG_CMD_BOOTM) += bootm.o
 obj-$(CONFIG_CMD_BOOTZ) += bootm.o zimage.o
 obj-$(CONFIG_SYS_L2_PL310) += cache-pl310.o
+ifdef CONFIG_ARM64
+# This option does not work for arm64, as there is no binary.
+# TODO(sjg at chromium.org): Add this once it is possible to build one
+obj-$(CONFIG_CMD_BOOTEFI_HELLO) += HelloWorld64.o
+else
+obj-$(CONFIG_CMD_BOOTEFI_HELLO) += HelloWorld32.o
+endif
 obj-$(CONFIG_USE_ARCH_MEMSET) += memset.o
 obj-$(CONFIG_USE_ARCH_MEMCPY) += memcpy.o
 else
diff --git a/cmd/Kconfig b/cmd/Kconfig
index e339d86..a5d030b 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -181,6 +181,15 @@ config CMD_BOOTEFI
 	help
 	  Boot an EFI image from memory.
 
+config CMD_BOOTEFI_HELLO
+	bool "Allow booting a standard EFI hello world for testing"
+	depends on CMD_BOOTEFI
+	help
+	  This adds a standard EFI hello world application to U-Boot so that
+	  it can be used with the 'bootefi hello' command. This is useful
+	  for testing that EFI is working at a basic level, and for bringing
+	  up EFI support on a new architecture.
+
 config CMD_ELF
 	bool "bootelf, bootvx"
 	default y
diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index 7b2e0b5..7c2d9fc 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -230,13 +230,22 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 	if (argc < 2)
 		return CMD_RET_USAGE;
-	saddr = argv[1];
+#ifdef CONFIG_CMD_BOOTEFI_HELLO
+	if (!strcmp(argv[1], "hello")) {
+		addr = CONFIG_SYS_LOAD_ADDR;
+		memcpy((char *)addr, __efi_hello_world_begin,
+		       __efi_hello_world_end - __efi_hello_world_begin);
+	} else
+#endif
+	{
+		saddr = argv[1];
 
-	addr = simple_strtoul(saddr, NULL, 16);
+		addr = simple_strtoul(saddr, NULL, 16);
 
-	if (argc > 2) {
-		sfdt = argv[2];
-		fdt_addr = simple_strtoul(sfdt, NULL, 16);
+		if (argc > 2) {
+			sfdt = argv[2];
+			fdt_addr = simple_strtoul(sfdt, NULL, 16);
+		}
 	}
 
 	printf("## Starting EFI application at 0x%08lx ...\n", addr);
@@ -254,7 +263,12 @@ static char bootefi_help_text[] =
 	"<image address> [fdt address]\n"
 	"  - boot EFI payload stored at address <image address>.\n"
 	"    If specified, the device tree located at <fdt address> gets\n"
-	"    exposed as EFI configuration table.\n";
+	"    exposed as EFI configuration table.\n"
+#ifdef CONFIG_CMD_BOOTEFI_HELLO
+	"hello\n"
+	"  - boot a sample Hello World application stored within U-Boot"
+#endif
+	;
 #endif
 
 U_BOOT_CMD(
diff --git a/doc/README.efi b/doc/README.efi
index 1fd3f00..6e76310 100644
--- a/doc/README.efi
+++ b/doc/README.efi
@@ -310,6 +310,28 @@ Removable media booting (search for /efi/boot/boota{a64,arm}.efi) is supported.
 Simple use cases like "Plug this SD card into my ARM device and it just
 boots into grub which boots into Linux", work very well.
 
+
+Running HelloWord.efi
+---------------------
+
+You can run a simple 'hello world' EFI program in U-Boot. This is not
+distributed in the U-Boot source, but you can download this patch:
+
+   https://goo.gl/vihiZS
+
+Then apply it, e.g.:
+
+   $ git am ~/Downloads/0001-efi-Add-test-program-binaries.patch
+
+and enable the option CONFIG_CMD_BOOTEFI_HELLO
+
+Then you can boot into U-Boot and type:
+
+   > bootefi hello
+
+The 'hello world EFI' program will then run, print a message and exit.
+
+
 Future work
 -----------
 
diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index d69bc60..daf021b 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -22,6 +22,8 @@ extern char __kprobes_text_start[], __kprobes_text_end[];
 extern char __entry_text_start[], __entry_text_end[];
 extern char __initdata_begin[], __initdata_end[];
 extern char __start_rodata[], __end_rodata[];
+extern char __efi_hello_world_begin[];
+extern char __efi_hello_world_end[];
 
 /* Start and end of .ctors section - used for constructor calls. */
 extern char __ctors_start[], __ctors_end[];
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 45a0e1d..1f534b7 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -321,6 +321,25 @@ cmd_S_ttf=						\
 $(obj)/%.S: $(src)/%.ttf
 	$(call cmd,S_ttf)
 
+# EFI Hello World application
+# ---------------------------------------------------------------------------
+
+# Generate an assembly file to wrap the EFI app
+cmd_S_efi=						\
+(							\
+	echo '.section .rodata.efi.init,"a"';		\
+	echo '.balign 16';				\
+	echo '.global __efi_hello_world_begin';		\
+	echo '__efi_hello_world_begin:';		\
+	echo '.incbin "$<" ';				\
+	echo '__efi_hello_world_end:';			\
+	echo '.global __efi_hello_world_end';		\
+	echo '.balign 16';				\
+) > $@
+
+$(obj)/%.S: $(src)/%.efi
+	$(call cmd,S_efi)
+
 # ACPI
 # ---------------------------------------------------------------------------
 quiet_cmd_acpi_c_asl= ASL     $<
-- 
2.8.0.rc3.226.g39d4020



More information about the U-Boot mailing list