Skip to contentSkip to conversation

efi: x86: Add EFI hello world and loader support for x86

PATCH Superseded Simon Glass 2 participants 29 messages Nov 7, 2016 – Nov 14, 2016

Subsystems (5)
Arm (32-bit) x86 Kbuild Arm STM32 +1 more subsystems
lore
Share & tools
lore
#0 lore raw

v4 cover efi: x86: Add EFI hello world and loader support for x86

This series adds EFI loader support for x86. Since U-Boot already supports running as an EFI app (and as a payload) this is relatively straightforward, requiring just moving files into place and updating a few compiler flags.

One problem with the EFI loader is that it lacks even rudimentary test support within U-Boot. At present the only way to test it is to boot an EFI application. As a step towards correcting this, this series also adds support for a 'hello world' test program which can be used to make sure that EFI loader support works correctly on a supported architecture. It is only a very simple program (it makes just two API calls!) but it does provide a sanity check and can be expanded as needed.

No attempt is made to create a pytest with this, but it should be fairly straightforward to do so.

Changes in v4:
- Move hello world test program into new patch
- Add new patch to add EFI app support
- Add new patch to add EFI app support on aarch64
- Use the build-generated 'hello world' program instead of a binary blob
- Add new patch to adjust EFI files support efi_loader
- Drop the binary 'hello world' program

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:
- Add new patch to tidy up selection of building the EFI stub
- Remove EFI support from README.x86 TODO list

Simon Glass (14):
x86: Correct a build warning in x86 tables
efi: Correct cache flush alignment
efi: Fix debug message address format
x86: Tidy up selection of building the EFI stub
efi: Makefile: Export variables for use with EFI
efi: Add support for a hello world test program
elf: arm: Add a few ARM relocation types
efi: arm: Add EFI app support
efi: arm: Add aarch64 EFI app support
efi: arm: Enable the hello world test program
x86: Move efi .lds files into the 'lib' directory
x86: Move efi .S files into the 'lib' directory
efi: x86: Adjust EFI files support efi_loader
x86: Enable EFI loader support

 Makefile                                           |  11 +-
 arch/arm/config.mk                                 |   7 ++
 arch/arm/cpu/armv8/config.mk                       |   4 +
 arch/arm/lib/Makefile                              |  10 ++
 arch/arm/lib/crt0_aarch64_efi.S                    | 135 ++++++++++++++++++++
 arch/arm/lib/crt0_arm_efi.S                        | 138 +++++++++++++++++++++
 arch/arm/lib/elf_aarch64_efi.lds                   |  70 +++++++++++
 arch/arm/lib/elf_arm_efi.lds                       |  70 +++++++++++
 arch/arm/lib/reloc_aarch64_efi.c                   |  87 +++++++++++++
 arch/arm/lib/reloc_arm_efi.c                       |  66 ++++++++++
 arch/arm/lib/relocate.S                            |   3 +-
 arch/arm/lib/relocate_64.S                         |   3 +-
 arch/x86/config.mk                                 |  20 ++-
 arch/x86/lib/Makefile                              |  23 ++++
 .../lib/{efi/crt0-efi-ia32.S => crt0_ia32_efi.S}   |   0
 .../{efi/crt0-efi-x86_64.S => crt0_x86_64_efi.S}   |   0
 arch/x86/lib/efi/Makefile                          |  18 ---
 arch/x86/{cpu/efi => lib}/elf_ia32_efi.lds         |   2 -
 arch/x86/{cpu/efi => lib}/elf_x86_64_efi.lds       |   2 -
 .../x86/lib/{efi/reloc_ia32.c => reloc_ia32_efi.c} |   0
 .../lib/{efi/reloc_x86_64.c => reloc_x86_64_efi.c} |   0
 arch/x86/lib/tables.c                              |   2 +
 cmd/Kconfig                                        |  10 ++
 cmd/bootefi.c                                      |  29 +++--
 configs/efi-x86_defconfig                          |   1 +
 configs/qemu-x86_efi_payload64_defconfig           |   1 +
 configs/stm32f429-discovery_defconfig              |   1 +
 doc/README.efi                                     |  22 ++++
 doc/README.x86                                     |   1 -
 include/asm-generic/sections.h                     |   2 +
 include/efi.h                                      |   7 +-
 include/elf.h                                      |  13 ++
 lib/efi/Makefile                                   |   4 +-
 lib/efi_loader/Kconfig                             |   2 +-
 lib/efi_loader/Makefile                            |   4 +
 lib/efi_loader/efi_image_loader.c                  |   3 +-
 lib/efi_loader/helloworld.c                        |  24 ++++
 scripts/Makefile.lib                               |  33 +++++
 38 files changed, 787 insertions(+), 41 deletions(-)
 create mode 100644 arch/arm/lib/crt0_aarch64_efi.S
 create mode 100644 arch/arm/lib/crt0_arm_efi.S
 create mode 100644 arch/arm/lib/elf_aarch64_efi.lds
 create mode 100644 arch/arm/lib/elf_arm_efi.lds
 create mode 100644 arch/arm/lib/reloc_aarch64_efi.c
 create mode 100644 arch/arm/lib/reloc_arm_efi.c
 rename arch/x86/lib/{efi/crt0-efi-ia32.S => crt0_ia32_efi.S} (100%)
 rename arch/x86/lib/{efi/crt0-efi-x86_64.S => crt0_x86_64_efi.S} (100%)
 rename arch/x86/{cpu/efi => lib}/elf_ia32_efi.lds (98%)
 rename arch/x86/{cpu/efi => lib}/elf_x86_64_efi.lds (98%)
 rename arch/x86/lib/{efi/reloc_ia32.c => reloc_ia32_efi.c} (100%)
 rename arch/x86/lib/{efi/reloc_x86_64.c => reloc_x86_64_efi.c} (100%)
 create mode 100644 lib/efi_loader/helloworld.c
Signature · 1 line
2.8.0.rc3.226.g39d4020
#1 lore raw

PATCH v4 1/14 x86: Correct a build warning in x86 tables

There is a build warning for three x86 boards since write_smbios_table_wrapper() is not used. Fix it.

Fixes e824cf3f (smbios: Allow compilation on 64bit systems)

---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 arch/x86/lib/tables.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/lib/tables.c +2 -0
index 025b183..5966e58 100644
@@ -12,10 +12,12 @@
 #include <asm/acpi_table.h>
 #include <asm/coreboot_tables.h>
 
+#ifdef CONFIG_GENERATE_SMBIOS_TABLE
 static u32 write_smbios_table_wrapper(u32 addr)
 {
 	return write_smbios_table(addr);
 }
+#endif
 
 /**
  * Function prototype to write a specific configuration table
Signature · 1 line
2.8.0.rc3.226.g39d4020
#2 lore raw

PATCH v4 1/14 x86: Correct a build warning in x86 tables

Quoted 5 lines

There is a build warning for three x86 boards since write_smbios_table_wrapper() is not used. Fix it.

Fixes e824cf3f (smbios: Allow compilation on 64bit systems)

Thanks, applied to efi-next

Alex

#3 lore raw

PATCH v4 2/14 efi: Correct cache flush alignment

In reply to Simon Glass

Make sure that the cache flushes correctly by ensuring that the end address is correctly aligned.

---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 lib/efi_loader/efi_image_loader.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/efi_loader/efi_image_loader.c +2 -1
index 5165377..3262d76 100644
@@ -174,7 +174,8 @@ void *efi_load_pe(void *efi, struct efi_loaded_image *loaded_image_info)
 	efi_loader_relocate(rel, rel_size, efi_reloc);
 
 	/* Flush cache */
-	flush_cache((ulong)efi_reloc, virt_size);
+	flush_cache((ulong)efi_reloc,
+		    ALIGN(virt_size, CONFIG_SYS_CACHELINE_SIZE));
 	invalidate_icache_all();
 
 	/* Populate the loaded image interface bits */
Signature · 1 line
2.8.0.rc3.226.g39d4020
#4 lore raw

PATCH v4 2/14 efi: Correct cache flush alignment

Quoted 4 lines

Make sure that the cache flushes correctly by ensuring that the end address is correctly aligned.

Thanks, applied to efi-next

Alex

#5 lore raw

PATCH v4 3/14 efi: Fix debug message address format

In reply to Simon Glass

This should use U-Boot's standard format for hex address. Fix it.

---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 cmd/bootefi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
cmd/bootefi.c +1 -1
index c8079c4..3ab256e 100644
@@ -248,7 +248,7 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		fdt_addr = simple_strtoul(sfdt, NULL, 16);
 	}
 
-	printf("## Starting EFI application at 0x%08lx ...\n", addr);
+	printf("## Starting EFI application at %08lx ...\n", addr);
 	r = do_bootefi_exec((void *)addr, (void*)fdt_addr);
 	printf("## Application terminated, r = %d\n", r);
 
Signature · 1 line
2.8.0.rc3.226.g39d4020
#7 lore raw

PATCH v4 4/14 x86: Tidy up selection of building the EFI stub

In reply to Simon Glass

At present we use a CONFIG option in efi.h to determine whether we are building the EFI stub or not. This means that the same header cannot be used for EFI_LOADER support. The CONFIG option will be enabled for the whole build, even when not building the stub.

Use a different define instead, set up just for the files that make up the stub.

---

Changes in v4: None
Changes in v3: None
Changes in v2:
- Add new patch to tidy up selection of building the EFI stub

 include/efi.h    | 7 +++++--
 lib/efi/Makefile | 4 ++--
 2 files changed, 7 insertions(+), 4 deletions(-)
include/efi.h +5 -2
index d07187c..3d58780 100644
@@ -30,8 +30,11 @@ struct efi_device_path;
 
 #define EFI_BITS_PER_LONG	BITS_PER_LONG
 
-/* With 64-bit EFI stub, EFI_BITS_PER_LONG has to be 64 */
-#ifdef CONFIG_EFI_STUB_64BIT
+/*
+ * With 64-bit EFI stub, EFI_BITS_PER_LONG has to be 64. EFI_STUB is set
+ * in lib/efi/Makefile, when building the stub.
+ */
+#if defined(CONFIG_EFI_STUB_64BIT) && defined(EFI_STUB)
 #undef EFI_BITS_PER_LONG
 #define EFI_BITS_PER_LONG	64
 #endif
lib/efi/Makefile +2 -2
index e32dc14..9449600 100644
@@ -9,9 +9,9 @@ obj-$(CONFIG_EFI_STUB) += efi_info.o
 
 CFLAGS_REMOVE_efi_stub.o := -mregparm=3 \
 	$(if $(CONFIG_EFI_STUB_64BIT),-march=i386 -m32)
-CFLAGS_efi_stub.o := -fpic -fshort-wchar
+CFLAGS_efi_stub.o := -fpic -fshort-wchar -DEFI_STUB
 CFLAGS_REMOVE_efi.o := -mregparm=3 \
 	$(if $(CONFIG_EFI_STUB_64BIT),-march=i386 -m32)
-CFLAGS_efi.o := -fpic -fshort-wchar
+CFLAGS_efi.o := -fpic -fshort-wchar -DEFI_STUB
 
 extra-$(CONFIG_EFI_STUB) += efi_stub.o efi.o
Signature · 1 line
2.8.0.rc3.226.g39d4020
#8 lore raw

PATCH v4 4/14 x86: Tidy up selection of building the EFI stub

Quoted 10 lines

At present we use a CONFIG option in efi.h to determine whether we are building the EFI stub or not. This means that the same header cannot be used for EFI_LOADER support. The CONFIG option will be enabled for the whole build, even when not building the stub.

Use a different define instead, set up just for the files that make up the stub.

Thanks, applied to efi-next

Alex

#9 lore raw

PATCH v4 5/14 efi: Makefile: Export variables for use with EFI

In reply to Simon Glass

When building an EFI app we need three things:

- start-up code
- relocation code
- link script

These are all different for each architecture. We also need special compiler flags in some cases.

Add top-level Makefile variables for these along with documentation.

---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 Makefile | 9 +++++++++
 1 file changed, 9 insertions(+)
Makefile +9 -0
index 37cbcb2..d3a6a12 100644
@@ -527,6 +527,15 @@ endif
 endif
 endif
 
+# These are set by the arch-specific config.mk. Make sure they are exported
+# so they can be used when building an EFI application.
+export EFI_LDS		# Filename of EFI link script in arch/$(ARCH)/lib
+export EFI_CRT0		# Filename of EFI CRT0 in arch/$(ARCH)/lib
+export EFI_RELOC	# Filename of EFU relocation code in arch/$(ARCH)/lib
+export CFLAGS_EFI	# Compiler flags to add when building EFI app
+export CFLAGS_NON_EFI	# Compiler flags to remove when building EFI app
+export EFI_TARGET	# binutils target if EFI is natively supported
+
 # If board code explicitly specified LDSCRIPT or CONFIG_SYS_LDSCRIPT, use
 # that (or fail if absent).  Otherwise, search for a linker script in a
 # standard location.
Signature · 1 line
2.8.0.rc3.226.g39d4020
#10 lore raw

PATCH v4 5/14 efi: Makefile: Export variables for use with EFI

Quoted 6 lines

When building an EFI app we need three things:

- start-up code
- relocation code
- link script

Quoted 6 lines

These are all different for each architecture. We also need special compiler flags in some cases.

Add top-level Makefile variables for these along with documentation.

Thanks, applied to efi-next

Alex

#11 lore raw

PATCH v4 6/14 efi: Add support for a hello world test program

In reply to Simon Glass

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.

---

Changes in v4:
- Move hello world test program into new patch

Changes in v3: None
Changes in v2: None

 cmd/Kconfig                    |  9 +++++++++
 cmd/bootefi.c                  | 27 +++++++++++++++++++++------
 doc/README.efi                 | 22 ++++++++++++++++++++++
 include/asm-generic/sections.h |  2 ++
 lib/efi_loader/Makefile        |  4 ++++
 lib/efi_loader/helloworld.c    | 24 ++++++++++++++++++++++++
 scripts/Makefile.lib           | 33 +++++++++++++++++++++++++++++++++
 7 files changed, 115 insertions(+), 6 deletions(-)
 create mode 100644 lib/efi_loader/helloworld.c
cmd/Kconfig +9 -0
index e339d86..a5d030b 100644
@@ -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
cmd/bootefi.c +21 -6
index 3ab256e..ae1b713 100644
@@ -239,13 +239,23 @@ 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")) {
+		ulong size = __efi_hello_world_end - __efi_hello_world_begin;
 
-	addr = simple_strtoul(saddr, NULL, 16);
+		addr = CONFIG_SYS_LOAD_ADDR;
+		memcpy((char *)addr, __efi_hello_world_begin, size);
+	} else
+#endif
+	{
+		saddr = argv[1];
 
-	if (argc > 2) {
-		sfdt = argv[2];
-		fdt_addr = simple_strtoul(sfdt, NULL, 16);
+		addr = simple_strtoul(saddr, NULL, 16);
+
+		if (argc > 2) {
+			sfdt = argv[2];
+			fdt_addr = simple_strtoul(sfdt, NULL, 16);
+		}
 	}
 
 	printf("## Starting EFI application at %08lx ...\n", addr);
@@ -263,7 +273,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(
doc/README.efi +22 -0
index 1fd3f00..6e76310 100644
@@ -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
 -----------
 
include/asm-generic/sections.h +2 -0
index d69bc60..daf021b 100644
@@ -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[];
lib/efi_loader/Makefile +4 -0
index 12159dd..f466408 100644
@@ -7,6 +7,10 @@
 # This file only gets included with CONFIG_EFI_LOADER set, so all
 # object inclusion implicitly depends on it
 
+CFLAGS_helloworld.o := $(CFLAGS_EFI)
+CFLAGS_REMOVE_helloworld.o := $(CFLAGS_NON_EFI)
+
+obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o
 obj-y += efi_image_loader.o efi_boottime.o efi_runtime.o efi_console.o
 obj-y += efi_memory.o
 obj-$(CONFIG_LCD) += efi_gop.o
lib/efi_loader/helloworld.c new file +24 -0
new file mode 100644
index 0000000..03e65ab
@@ -0,0 +1,24 @@
+/*
+ * EFI hello world
+ *
+ * Copyright (c) 2016 Google, Inc
+ * Written by Simon Glass <[email protected]>
+ *
+ * SPDX-License-Identifier:     GPL-2.0+
+ */
+
+#include <common.h>
+#include <part_efi.h>
+#include <efi_api.h>
+
+efi_status_t EFIAPI efi_main(efi_handle_t handle,
+			     struct efi_system_table *systable)
+{
+	struct efi_simple_text_output_protocol *con_out = systable->con_out;
+	struct efi_boot_services *boottime = systable->boottime;
+
+	con_out->output_string(con_out, L"Hello, world!\n");
+	boottime->exit(handle, 0, 0, NULL);
+
+	return EFI_SUCCESS;
+}
scripts/Makefile.lib +33 -0
index 45a0e1d..956a8a9 100644
@@ -321,6 +321,39 @@ 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)/%_efi.S: $(obj)/%.efi
+	$(call cmd,S_efi)
+
+$(obj)/%.efi: $(obj)/%.so
+	$(OBJCOPY) -j .header -j .text -j .sdata -j .data -j .dynamic \
+		-j .dynsym  -j .rel* -j .rela* -j .reloc \
+		$(if $(EFI_TARGET),$(EFI_TARGET),-O binary) $^ $@
+
+EFI_LDS_PATH = $(srctree)/arch/$(ARCH)/lib/$(EFI_LDS)
+
+$(obj)/helloworld.so: $(EFI_LDS_PATH)
+
+$(obj)/helloworld.so: $(obj)/helloworld.o arch/$(ARCH)/lib/$(EFI_CRT0) \
+		arch/$(ARCH)/lib/$(EFI_RELOC)
+	$(LD) -nostdlib -znocombreloc -T $(EFI_LDS_PATH) -shared -Bsymbolic \
+		$^ -o $@
+
 # ACPI
 # ---------------------------------------------------------------------------
 quiet_cmd_acpi_c_asl= ASL     $<
Signature · 1 line
2.8.0.rc3.226.g39d4020
#12 lore raw

PATCH v4 6/14 efi: Add support for a hello world test program

Quoted 4 lines

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.

Thanks, applied to efi-next

Alex

#13 lore raw

PATCH v4 7/14 elf: arm: Add a few ARM relocation types

In reply to Simon Glass

Rather than hard-coding the relocation type, add it to the ELF header file and use it from there.

---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 arch/arm/lib/relocate.S    |  3 ++-
 arch/arm/lib/relocate_64.S |  3 ++-
 include/elf.h              | 13 +++++++++++++
 3 files changed, 17 insertions(+), 2 deletions(-)
arch/arm/lib/relocate.S +2 -1
index 475d503..a6fb07c 100644
@@ -8,6 +8,7 @@
 
 #include <asm-offsets.h>
 #include <config.h>
+#include <elf.h>
 #include <linux/linkage.h>
 #ifdef CONFIG_CPU_V7M
 #include <asm/armv7m.h>
@@ -96,7 +97,7 @@ copy_loop:
 fixloop:
 	ldmia	r2!, {r0-r1}		/* (r0,r1) <- (SRC location,fixup) */
 	and	r1, r1, #0xff
-	cmp	r1, #23			/* relative fixup? */
+	cmp	r1, #R_ARM_RELATIVE
 	bne	fixnext
 
 	/* relative fix: increase location by offset */
arch/arm/lib/relocate_64.S +2 -1
index 5c51cae..242e56e 100644
@@ -10,6 +10,7 @@
 
 #include <asm-offsets.h>
 #include <config.h>
+#include <elf.h>
 #include <linux/linkage.h>
 #include <asm/macro.h>
 
@@ -47,7 +48,7 @@ fixloop:
 	ldp	x0, x1, [x2], #16	/* (x0,x1) <- (SRC location, fixup) */
 	ldr	x4, [x2], #8		/* x4 <- addend */
 	and	x1, x1, #0xffffffff
-	cmp	x1, #1027		/* relative fixup? */
+	cmp	x1, #R_AARCH64_RELATIVE
 	bne	fixnext
 
 	/* relative fix: store addend plus offset@dest location */
include/elf.h +13 -0
index bcc5eb7..aaecac7 100644
@@ -13,6 +13,7 @@
 #ifndef _ELF_H
 #define _ELF_H
 
+#ifndef __ASSEMBLER__
 #include "compiler.h"
 
 /*
@@ -517,6 +518,8 @@ unsigned long elf_hash(const unsigned char *name);
 
 #define ELF_TARG_VER	1	/* The ver for which this code is intended */
 
+#endif /* __ASSEMBLER */
+
 /*
  * XXX - PowerPC defines really don't belong in here,
  * but we'll put them in for simplicity.
@@ -602,6 +605,16 @@ unsigned long elf_hash(const unsigned char *name);
    that may still be in object files.  */
 #define R_PPC_TOC16             255
 
+ /* ARM relocs */
+#define R_ARM_NONE		0	/* No reloc */
+#define R_ARM_RELATIVE		23	/* Adjust by program base */
+
+/* AArch64 relocs */
+#define R_AARCH64_NONE		0	/* No relocation.  */
+#define R_AARCH64_RELATIVE	1027	/* Adjust by program base.  */
+
+#ifndef __ASSEMBLER__
 int valid_elf_image(unsigned long addr);
+#endif
 
 #endif /* _ELF_H */
Signature · 1 line
2.8.0.rc3.226.g39d4020
#14 lore raw

PATCH v4 7/14 elf: arm: Add a few ARM relocation types

Quoted 4 lines

Rather than hard-coding the relocation type, add it to the ELF header file and use it from there.

Thanks, applied to efi-next

Alex

#15 lore raw

PATCH v4 8/14 efi: arm: Add EFI app support

In reply to Simon Glass

Add support for EFI apps on ARM. This includes start-up and relocation code, plus a link script and some compiler setting changes.

---

Changes in v4:
- Add new patch to add EFI app support

Changes in v3: None
Changes in v2: None

 arch/arm/config.mk           |   7 +++
 arch/arm/lib/Makefile        |  10 ++++
 arch/arm/lib/crt0_arm_efi.S  | 138 +++++++++++++++++++++++++++++++++++++++++++
 arch/arm/lib/elf_arm_efi.lds |  70 ++++++++++++++++++++++
 arch/arm/lib/reloc_arm_efi.c |  66 +++++++++++++++++++++
 lib/efi_loader/Kconfig       |   2 +-
 6 files changed, 292 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/lib/crt0_arm_efi.S
 create mode 100644 arch/arm/lib/elf_arm_efi.lds
 create mode 100644 arch/arm/lib/reloc_arm_efi.c
arch/arm/config.mk +7 -0
index 542b897..27914a9 100644
@@ -13,6 +13,9 @@ CONFIG_STANDALONE_LOAD_ADDR = 0xc100000
 endif
 endif
 
+CFLAGS_NON_EFI := -fno-pic -ffixed-r9 -ffunction-sections -fdata-sections
+CFLAGS_EFI := -fpic -fshort-wchar
+
 LDFLAGS_FINAL += --gc-sections
 PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections \
 		     -fno-common -ffixed-r9
@@ -148,3 +151,7 @@ ifneq ($(CONFIG_VF610),)
 ALL-y += u-boot.vyb
 endif
 endif
+
+EFI_LDS := elf_arm_efi.lds
+EFI_CRT0 := crt0_arm_efi.o
+EFI_RELOC := reloc_arm_efi.o
arch/arm/lib/Makefile +10 -0
index caa62c6..a812306 100644
@@ -92,3 +92,13 @@ AFLAGS_memset.o := -DMEMSET_NO_THUMB_BUILD
 AFLAGS_memcpy.o := -DMEMCPY_NO_THUMB_BUILD
 endif
 endif
+
+# For building EFI apps
+CFLAGS_$(EFI_CRT0) := $(CFLAGS_EFI)
+CFLAGS_REMOVE_$(EFI_CRT0) := $(CFLAGS_NON_EFI)
+
+CFLAGS_$(EFI_RELOC) := $(CFLAGS_EFI)
+CFLAGS_REMOVE_$(EFI_RELOC) := $(CFLAGS_NON_EFI)
+
+extra-$(CONFIG_CMD_BOOTEFI_HELLO) += $(EFI_CRT0) $(EFI_RELOC)
+extra-$(CONFIG_EFI) += $(EFI_CRT0) $(EFI_RELOC)
arch/arm/lib/crt0_arm_efi.S new file +138 -0

138 lines not on this page · raw message

arch/arm/lib/elf_arm_efi.lds new file +70 -0

70 lines not on this page · raw message

arch/arm/lib/reloc_arm_efi.c new file +66 -0

66 lines not on this page · raw message

lib/efi_loader/Kconfig +1 -1
index 37a0dd6..48563aa 100644
@@ -1,6 +1,6 @@
 config EFI_LOADER
 	bool "Support running EFI Applications in U-Boot"
-	depends on (ARM64 ||?ARM) && OF_LIBFDT
+	depends on (ARM64 || ARM) && OF_LIBFDT
 	default y
 	help
 	  Select this option if you want to run EFI applications (like grub2)
Signature · 1 line
2.8.0.rc3.226.g39d4020
#16 lore raw

PATCH v4 8/14 efi: arm: Add EFI app support

Quoted 4 lines

Add support for EFI apps on ARM. This includes start-up and relocation code, plus a link script and some compiler setting changes.

Thanks, applied to efi-next

Alex

#17 lore raw

PATCH v4 9/14 efi: arm: Add aarch64 EFI app support

In reply to Simon Glass

Add support for EFI apps on aarch64. This includes start-up and relocation code plus a link script.

---

Changes in v4:
- Add new patch to add EFI app support on aarch64

Changes in v3: None
Changes in v2: None

 arch/arm/cpu/armv8/config.mk     |   4 ++
 arch/arm/lib/crt0_aarch64_efi.S  | 135 +++++++++++++++++++++++++++++++++++++++
 arch/arm/lib/elf_aarch64_efi.lds |  70 ++++++++++++++++++++
 arch/arm/lib/reloc_aarch64_efi.c |  87 +++++++++++++++++++++++++
 4 files changed, 296 insertions(+)
 create mode 100644 arch/arm/lib/crt0_aarch64_efi.S
 create mode 100644 arch/arm/lib/elf_aarch64_efi.lds
 create mode 100644 arch/arm/lib/reloc_aarch64_efi.c
arch/arm/cpu/armv8/config.mk +4 -0
index 6850258..27b66d4 100644
@@ -8,3 +8,7 @@ PLATFORM_RELFLAGS += -fno-common -ffixed-x18
 
 PF_NO_UNALIGNED := $(call cc-option, -mstrict-align)
 PLATFORM_CPPFLAGS += $(PF_NO_UNALIGNED)
+
+EFI_LDS := elf_aarch64_efi.lds
+EFI_CRT0 := crt0_aarch64_efi.o
+EFI_RELOC := reloc_aarch64_efi.o
arch/arm/lib/crt0_aarch64_efi.S new file +135 -0

135 lines not on this page · raw message

arch/arm/lib/elf_aarch64_efi.lds new file +70 -0

70 lines not on this page · raw message

arch/arm/lib/reloc_aarch64_efi.c new file +87 -0

87 lines not on this page · raw message

Signature · 1 line
2.8.0.rc3.226.g39d4020
#18 lore raw

PATCH v4 9/14 efi: arm: Add aarch64 EFI app support

Quoted 4 lines

Add support for EFI apps on aarch64. This includes start-up and relocation code plus a link script.

Thanks, applied to efi-next

Alex

#19 lore raw

PATCH v4 10/14 efi: arm: Enable the hello world test program

In reply to Simon Glass

It is useful to have a basic sanity check for EFI loader support. Enable this for ARM.

---

Changes in v4:
- Use the build-generated 'hello world' program instead of a binary blob

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

 cmd/Kconfig | 1 +
 1 file changed, 1 insertion(+)
cmd/Kconfig +1 -0
index a5d030b..d3b675c 100644
@@ -184,6 +184,7 @@ config CMD_BOOTEFI
 config CMD_BOOTEFI_HELLO
 	bool "Allow booting a standard EFI hello world for testing"
 	depends on CMD_BOOTEFI
+	default y if 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
Signature · 1 line
2.8.0.rc3.226.g39d4020
#20 lore raw

PATCH v4 11/14 x86: Move efi .lds files into the 'lib' directory

In reply to Simon Glass

These files now need to be in a standard place so that they can be located by generic Makefile rules. Move them to the 'lib' directory.

---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 arch/x86/config.mk                           | 2 +-
 arch/x86/{cpu/efi => lib}/elf_ia32_efi.lds   | 0
 arch/x86/{cpu/efi => lib}/elf_x86_64_efi.lds | 0
 3 files changed, 1 insertion(+), 1 deletion(-)
 rename arch/x86/{cpu/efi => lib}/elf_ia32_efi.lds (100%)
 rename arch/x86/{cpu/efi => lib}/elf_x86_64_efi.lds (100%)
arch/x86/config.mk +1 -1
index d7addd8..a17abbb 100644
@@ -45,7 +45,7 @@ endif
 
 EFIPAYLOAD_BFDARCH = i386
 
-LDSCRIPT_EFI := $(srctree)/$(CPUDIR)/efi/elf_$(EFIARCH)_efi.lds
+LDSCRIPT_EFI := $(srctree)/arch/x86/lib/elf_$(EFIARCH)_efi.lds
 EFISTUB := crt0-efi-$(EFIARCH).o reloc_$(EFIARCH).o
 OBJCOPYFLAGS_EFI += --target=efi-app-$(EFIARCH)
 
arch/x86/lib/elf_ia32_efi.lds renamed from arch/x86/cpu/efi/elf_ia32_efi.lds +0 -0
similarity index 100%
rename from arch/x86/cpu/efi/elf_ia32_efi.lds
rename to arch/x86/lib/elf_ia32_efi.lds
arch/x86/lib/elf_x86_64_efi.lds renamed from arch/x86/cpu/efi/elf_x86_64_efi.lds +0 -0
similarity index 100%
rename from arch/x86/cpu/efi/elf_x86_64_efi.lds
rename to arch/x86/lib/elf_x86_64_efi.lds
Signature · 1 line
2.8.0.rc3.226.g39d4020
#21 lore raw

PATCH v4 11/14 x86: Move efi .lds files into the 'lib' directory

Quoted 4 lines

These files now need to be in a standard place so that they can be located by generic Makefile rules. Move them to the 'lib' directory.

Thanks, applied to efi-next

Alex

#22 lore raw

PATCH v4 12/14 x86: Move efi .S files into the 'lib' directory

In reply to Simon Glass

These files now need to be in a standard place so that they can be located by generic Makefile rules. Move them to the 'lib' directory.

---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 Makefile                                               |  2 +-
 arch/x86/config.mk                                     |  2 +-
 arch/x86/lib/Makefile                                  | 18 ++++++++++++++++++
 arch/x86/lib/{efi/crt0-efi-ia32.S => crt0_ia32_efi.S}  |  0
 .../lib/{efi/crt0-efi-x86_64.S => crt0_x86_64_efi.S}   |  0
 arch/x86/lib/efi/Makefile                              | 18 ------------------
 arch/x86/lib/{efi/reloc_ia32.c => reloc_ia32_efi.c}    |  0
 .../x86/lib/{efi/reloc_x86_64.c => reloc_x86_64_efi.c} |  0
 8 files changed, 20 insertions(+), 20 deletions(-)
 rename arch/x86/lib/{efi/crt0-efi-ia32.S => crt0_ia32_efi.S} (100%)
 rename arch/x86/lib/{efi/crt0-efi-x86_64.S => crt0_x86_64_efi.S} (100%)
 rename arch/x86/lib/{efi/reloc_ia32.c => reloc_ia32_efi.c} (100%)
 rename arch/x86/lib/{efi/reloc_x86_64.c => reloc_x86_64_efi.c} (100%)
Makefile +1 -1
index d3a6a12..c868fa2 100644
@@ -1140,7 +1140,7 @@ quiet_cmd_u-boot_payload ?= LD      $@
       cmd_u-boot_payload ?= $(LD) $(LDFLAGS_EFI_PAYLOAD) -o $@ \
       -T u-boot-payload.lds arch/x86/cpu/call32.o \
       lib/efi/efi.o lib/efi/efi_stub.o u-boot.bin.o \
-      $(addprefix arch/$(ARCH)/lib/efi/,$(EFISTUB))
+      $(addprefix arch/$(ARCH)/lib/,$(EFISTUB))
 
 u-boot-payload: u-boot.bin.o u-boot-payload.lds FORCE
 	$(call if_changed,u-boot_payload)
arch/x86/config.mk +1 -1
index a17abbb..12a8d73 100644
@@ -46,7 +46,7 @@ endif
 EFIPAYLOAD_BFDARCH = i386
 
 LDSCRIPT_EFI := $(srctree)/arch/x86/lib/elf_$(EFIARCH)_efi.lds
-EFISTUB := crt0-efi-$(EFIARCH).o reloc_$(EFIARCH).o
+EFISTUB := crt0_$(EFIARCH)_efi.o reloc_$(EFIARCH)_efi.o
 OBJCOPYFLAGS_EFI += --target=efi-app-$(EFIARCH)
 
 CPPFLAGS_REMOVE_crt0-efi-$(EFIARCH).o += $(CFLAGS_NON_EFI)
arch/x86/lib/Makefile +18 -0
index b9c2922..aad6555 100644
@@ -44,3 +44,21 @@ NORMAL_LIBGCC = $(shell $(CC) $(PLATFORM_CPPFLAGS) -print-libgcc-file-name)
 OBJCOPYFLAGS := --prefix-symbols=__normal_
 $(obj)/lib.a: $(NORMAL_LIBGCC) FORCE
 	$(call if_changed,objcopy)
+
+obj-$(CONFIG_EFI_APP) += crt0_ia32_efi.o reloc_ia32_efi.o
+
+ifneq ($(CONFIG_EFI_STUB),)
+
+CFLAGS_REMOVE_reloc_ia32_efi.o += -mregparm=3
+CFLAGS_reloc_ia32_efi.o += -fpic -fshort-wchar
+
+# When building for 64-bit we must remove the i386-specific flags
+CFLAGS_REMOVE_reloc_x86_64_efi.o += -mregparm=3 -march=i386 -m32
+CFLAGS_reloc_x86_64_efi.o += -fpic -fshort-wchar
+
+AFLAGS_REMOVE_crt0_x86_64_efi.o += -mregparm=3 -march=i386 -m32
+AFLAGS_crt0_x86_64_efi.o += -fpic -fshort-wchar
+
+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
arch/x86/lib/crt0_ia32_efi.S renamed from arch/x86/lib/efi/crt0-efi-ia32.S +0 -0
similarity index 100%
rename from arch/x86/lib/efi/crt0-efi-ia32.S
rename to arch/x86/lib/crt0_ia32_efi.S
arch/x86/lib/crt0_x86_64_efi.S renamed from arch/x86/lib/efi/crt0-efi-x86_64.S +0 -0
similarity index 100%
rename from arch/x86/lib/efi/crt0-efi-x86_64.S
rename to arch/x86/lib/crt0_x86_64_efi.S
arch/x86/lib/efi/Makefile +0 -18
index af4503e..43aadfc 100644
@@ -7,21 +7,3 @@
 
 obj-$(CONFIG_EFI_STUB) += car.o
 obj-$(CONFIG_EFI_STUB) += efi.o
-
-obj-$(CONFIG_EFI_APP) += crt0-efi-ia32.o reloc_ia32.o
-
-ifneq ($(CONFIG_EFI_STUB),)
-
-CFLAGS_REMOVE_reloc_ia32.o += -mregparm=3
-CFLAGS_reloc_ia32.o += -fpic -fshort-wchar
-
-# When building for 64-bit we must remove the i386-specific flags
-CFLAGS_REMOVE_reloc_x86_64.o += -mregparm=3 -march=i386 -m32
-CFLAGS_reloc_x86_64.o += -fpic -fshort-wchar
-
-AFLAGS_REMOVE_crt0-efi-x86_64.o += -mregparm=3 -march=i386 -m32
-AFLAGS_crt0-efi-x86_64.o += -fpic -fshort-wchar
-
-extra-$(CONFIG_EFI_STUB_32BIT) += crt0-efi-ia32.o reloc_ia32.o
-extra-$(CONFIG_EFI_STUB_64BIT) += crt0-efi-x86_64.o reloc_x86_64.o
-endif
arch/x86/lib/reloc_ia32_efi.c renamed from arch/x86/lib/efi/reloc_ia32.c +0 -0
similarity index 100%
rename from arch/x86/lib/efi/reloc_ia32.c
rename to arch/x86/lib/reloc_ia32_efi.c
arch/x86/lib/reloc_x86_64_efi.c renamed from arch/x86/lib/efi/reloc_x86_64.c +0 -0
similarity index 100%
rename from arch/x86/lib/efi/reloc_x86_64.c
rename to arch/x86/lib/reloc_x86_64_efi.c
Signature · 1 line
2.8.0.rc3.226.g39d4020
#23 lore raw

PATCH v4 12/14 x86: Move efi .S files into the 'lib' directory

Quoted 4 lines

These files now need to be in a standard place so that they can be located by generic Makefile rules. Move them to the 'lib' directory.

Thanks, applied to efi-next

Alex

#24 lore raw

PATCH v4 13/14 efi: x86: Adjust EFI files support efi_loader

In reply to Simon Glass

Add compiler flags and make a few minor adjustments to support the efi loader.

---

Changes in v4:
- Add new patch to adjust EFI files support efi_loader

Changes in v3: None
Changes in v2: None

 arch/x86/config.mk              | 16 ++++++++++++++++
 arch/x86/lib/Makefile           |  5 +++++
 arch/x86/lib/elf_ia32_efi.lds   |  2 --
 arch/x86/lib/elf_x86_64_efi.lds |  2 --
 4 files changed, 21 insertions(+), 4 deletions(-)
arch/x86/config.mk +16 -0
index 12a8d73..03c71f7 100644
@@ -65,3 +65,19 @@ PLATFORM_LDFLAGS += --emit-relocs
 LDFLAGS_FINAL += --gc-sections -pie
 
 endif
+
+ifneq ($(CONFIG_EFI_STUB)$(CONFIG_CMD_BOOTEFI_HELLO),)
+
+ifneq ($(CONFIG_EFI_STUB_64BIT),)
+EFI_LDS := elf_x86_64_efi.lds
+EFI_CRT0 := crt0_x86_64_efi.o
+EFI_RELOC := reloc_x86_64_efi.o
+EFI_TARGET := --target=efi-app-ia32
+else
+EFI_LDS := elf_ia32_efi.lds
+EFI_CRT0 := crt0_ia32_efi.o
+EFI_RELOC := reloc_ia32_efi.o
+EFI_TARGET := --target=efi-app-x86_64
+endif
+
+endif
arch/x86/lib/Makefile +5 -0
index aad6555..ff402dc 100644
@@ -61,4 +61,9 @@ AFLAGS_crt0_x86_64_efi.o += -fpic -fshort-wchar
 
 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
+
+ifneq ($(CONFIG_EFI_STUB)$(CONFIG_CMD_BOOTEFI_HELLO),)
+extra-y += $(EFI_CRT0) $(EFI_RELOC)
 endif
arch/x86/lib/elf_ia32_efi.lds +0 -2
index cd3b0a9..174d36f 100644
@@ -6,8 +6,6 @@
  * Modified from usr/lib32/elf_ia32_efi.lds in gnu-efi
  */
 
-#include <config.h>
-
 OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
 OUTPUT_ARCH(i386)
 ENTRY(_start)
arch/x86/lib/elf_x86_64_efi.lds +0 -2
index 9d9f057..70c7c52 100644
@@ -6,8 +6,6 @@
  * Modified from usr/lib32/elf_x86_64_efi.lds in gnu-efi
  */
 
-#include <config.h>
-
 OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64")
 OUTPUT_ARCH(i386:x86-64)
 ENTRY(_start)
Signature · 1 line
2.8.0.rc3.226.g39d4020
#25 lore raw

PATCH v4 13/14 efi: x86: Adjust EFI files support efi_loader

Quoted 4 lines

Add compiler flags and make a few minor adjustments to support the efi loader.

Thanks, applied to efi-next

Alex

#26 lore raw

PATCH v4 14/14 x86: Enable EFI loader support

In reply to Simon Glass

Enable this so that EFI applications (notably grub) can be run under U-Boot on x86 platforms.

At present the 'hello world' EFI application is not supported for the qemu-x86_efi_payload64 board. That board builds a payload consisting of a 64-bit header and a 32-bit U-Boot, which is incompatible with the way the EFI loader builds its EFI application. The following error is obtained:

x86_64-linux-ld.bfd: i386 architecture of input file
`lib/efi_loader/helloworld.o' is incompatible with i386:x86-64 output

This could be corrected with additional Makefile rules. For now, this feature is disabled for that board.

---

Changes in v4:
- Drop the binary 'hello world' program

Changes in v3: None
Changes in v2:
- Remove EFI support from README.x86 TODO list

 configs/efi-x86_defconfig                | 1 +
 configs/qemu-x86_efi_payload64_defconfig | 1 +
 configs/stm32f429-discovery_defconfig    | 1 +
 doc/README.x86                           | 1 -
 lib/efi_loader/Kconfig                   | 2 +-
 5 files changed, 4 insertions(+), 2 deletions(-)
configs/efi-x86_defconfig +1 -0
index b31c73b..1fe6142 100644
@@ -34,3 +34,4 @@ CONFIG_USB=y
 CONFIG_USB_STORAGE=y
 CONFIG_USB_KEYBOARD=y
 CONFIG_EFI=y
+# CONFIG_EFI_LOADER is not set
configs/qemu-x86_efi_payload64_defconfig +1 -0
index c081ead..a9ffd92 100644
@@ -52,3 +52,4 @@ CONFIG_USE_PRIVATE_LIBGCC=y
 CONFIG_EFI=y
 CONFIG_EFI_STUB=y
 CONFIG_EFI_STUB_64BIT=y
+# CONFIG_CMD_BOOTEFI_HELLO is not set
configs/stm32f429-discovery_defconfig +1 -0
index 24e2221..a68494b 100644
@@ -10,3 +10,4 @@ CONFIG_SYS_PROMPT="U-Boot > "
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_CMD_TIMER=y
 CONFIG_OF_LIBFDT=y
+# CONFIG_CMD_BOOTEFI_HELLO is not set
doc/README.x86 +0 -1
index 6799559..a38cc1b 100644
@@ -1077,7 +1077,6 @@ TODO List
 ---------
 - Audio
 - Chrome OS verified boot
-- Support for CONFIG_EFI_LOADER
 - Building U-Boot to run in 64-bit mode
 
 References
lib/efi_loader/Kconfig +1 -1
index 48563aa..8e7e8a5 100644
@@ -1,6 +1,6 @@
 config EFI_LOADER
 	bool "Support running EFI Applications in U-Boot"
-	depends on (ARM64 || ARM) && OF_LIBFDT
+	depends on (ARM64 || ARM || X86) && OF_LIBFDT
 	default y
 	help
 	  Select this option if you want to run EFI applications (like grub2)
Signature · 1 line
2.8.0.rc3.226.g39d4020
#27 lore raw

PATCH v4 14/14 x86: Enable EFI loader support

Quoted 8 lines

Enable this so that EFI applications (notably grub) can be run under U-Boot on x86 platforms.

At present the 'hello world' EFI application is not supported for the qemu-x86_efi_payload64 board. That board builds a payload consisting of a 64-bit header and a 32-bit U-Boot, which is incompatible with the way the EFI loader builds its EFI application. The following error is obtained:

Quoted 8 lines

x86_64-linux-ld.bfd: i386 architecture of input file
`lib/efi_loader/helloworld.o' is incompatible with i386:x86-64 output

This could be corrected with additional Makefile rules. For now, this feature is disabled for that board.

Thanks, applied to efi-next

Alex

#28 lore raw

v4 cover efi: x86: Add EFI hello world and loader support for x86

In reply to Simon Glass

Resend attempt...

Quoted 105 lines · Simon Glass

This series adds EFI loader support for x86. Since U-Boot already supports running as an EFI app (and as a payload) this is relatively straightforward, requiring just moving files into place and updating a few compiler flags.

One problem with the EFI loader is that it lacks even rudimentary test support within U-Boot. At present the only way to test it is to boot an EFI application. As a step towards correcting this, this series also adds support for a 'hello world' test program which can be used to make sure that EFI loader support works correctly on a supported architecture. It is only a very simple program (it makes just two API calls!) but it does provide a sanity check and can be expanded as needed.

No attempt is made to create a pytest with this, but it should be fairly straightforward to do so.

Changes in v4:
- Move hello world test program into new patch
- Add new patch to add EFI app support
- Add new patch to add EFI app support on aarch64
- Use the build-generated 'hello world' program instead of a binary blob
- Add new patch to adjust EFI files support efi_loader
- Drop the binary 'hello world' program

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:
- Add new patch to tidy up selection of building the EFI stub
- Remove EFI support from README.x86 TODO list

Simon Glass (14):
x86: Correct a build warning in x86 tables
efi: Correct cache flush alignment
efi: Fix debug message address format
x86: Tidy up selection of building the EFI stub
efi: Makefile: Export variables for use with EFI
efi: Add support for a hello world test program
elf: arm: Add a few ARM relocation types
efi: arm: Add EFI app support
efi: arm: Add aarch64 EFI app support
efi: arm: Enable the hello world test program
x86: Move efi .lds files into the 'lib' directory
x86: Move efi .S files into the 'lib' directory
efi: x86: Adjust EFI files support efi_loader
x86: Enable EFI loader support

 Makefile                                           |  11 +-
 arch/arm/config.mk                                 |   7 ++
 arch/arm/cpu/armv8/config.mk                       |   4 +
 arch/arm/lib/Makefile                              |  10 ++
 arch/arm/lib/crt0_aarch64_efi.S                    | 135 ++++++++++++++++++++
 arch/arm/lib/crt0_arm_efi.S                        | 138 +++++++++++++++++++++
 arch/arm/lib/elf_aarch64_efi.lds                   |  70 +++++++++++
 arch/arm/lib/elf_arm_efi.lds                       |  70 +++++++++++
 arch/arm/lib/reloc_aarch64_efi.c                   |  87 +++++++++++++
 arch/arm/lib/reloc_arm_efi.c                       |  66 ++++++++++
 arch/arm/lib/relocate.S                            |   3 +-
 arch/arm/lib/relocate_64.S                         |   3 +-
 arch/x86/config.mk                                 |  20 ++-
 arch/x86/lib/Makefile                              |  23 ++++
 .../lib/{efi/crt0-efi-ia32.S => crt0_ia32_efi.S}   |   0
 .../{efi/crt0-efi-x86_64.S => crt0_x86_64_efi.S}   |   0
 arch/x86/lib/efi/Makefile                          |  18 ---
 arch/x86/{cpu/efi => lib}/elf_ia32_efi.lds         |   2 -
 arch/x86/{cpu/efi => lib}/elf_x86_64_efi.lds       |   2 -
 .../x86/lib/{efi/reloc_ia32.c => reloc_ia32_efi.c} |   0
 .../lib/{efi/reloc_x86_64.c => reloc_x86_64_efi.c} |   0
 arch/x86/lib/tables.c                              |   2 +
 cmd/Kconfig                                        |  10 ++
 cmd/bootefi.c                                      |  29 +++--
 configs/efi-x86_defconfig                          |   1 +
 configs/qemu-x86_efi_payload64_defconfig           |   1 +
 configs/stm32f429-discovery_defconfig              |   1 +
 doc/README.efi                                     |  22 ++++
 doc/README.x86                                     |   1 -
 include/asm-generic/sections.h                     |   2 +
 include/efi.h                                      |   7 +-
 include/elf.h                                      |  13 ++
 lib/efi/Makefile                                   |   4 +-
 lib/efi_loader/Kconfig                             |   2 +-
 lib/efi_loader/Makefile                            |   4 +
 lib/efi_loader/efi_image_loader.c                  |   3 +-
 lib/efi_loader/helloworld.c                        |  24 ++++
 scripts/Makefile.lib                               |  33 +++++
 38 files changed, 787 insertions(+), 41 deletions(-)
 create mode 100644 arch/arm/lib/crt0_aarch64_efi.S
 create mode 100644 arch/arm/lib/crt0_arm_efi.S
 create mode 100644 arch/arm/lib/elf_aarch64_efi.lds
 create mode 100644 arch/arm/lib/elf_arm_efi.lds
 create mode 100644 arch/arm/lib/reloc_aarch64_efi.c
 create mode 100644 arch/arm/lib/reloc_arm_efi.c
 rename arch/x86/lib/{efi/crt0-efi-ia32.S => crt0_ia32_efi.S} (100%)
 rename arch/x86/lib/{efi/crt0-efi-x86_64.S => crt0_x86_64_efi.S} (100%)
 rename arch/x86/{cpu/efi => lib}/elf_ia32_efi.lds (98%)
 rename arch/x86/{cpu/efi => lib}/elf_x86_64_efi.lds (98%)
 rename arch/x86/lib/{efi/reloc_ia32.c => reloc_ia32_efi.c} (100%)
 rename arch/x86/lib/{efi/reloc_x86_64.c => reloc_x86_64_efi.c} (100%)
 create mode 100644 lib/efi_loader/helloworld.c

--
2.8.0.rc3.226.g39d4020