Skip to contentSkip to conversation

arm: Support building as an EFI app

PATCH Superseded Simon Glass 3 participants 36 messages Feb 9, 2025 – Feb 11, 2025

Subsystems (8)
Arm (32-bit) x86 Kbuild PCI +4 more subsystems

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover arm: Support building as an EFI app

The original x86 EFI-app was written back in 2015, about a year before the EFI-loader was introduced. At that point, ARM mostly used U-Boot and FIT (Flat Image Tree).

Today, sadly, there are a few efforts to re-invent FIT poorly, to cater to more primitive boot-environments than U-Boot. One justification for this re-invetion has been that EDK2 did not support FIT.

EDK2 does now support FIT but only for the firmware stage. Even then, vendors tend to use their own forks, so any new features are slow to make it into the market.

EDK2 also supports the ext4 filesystem, but many devices don't include that feature, so most distros make use of FAT for storing their boot files. Since FAT is not journalled, it is not particularly reliable in the face of reset, power failure, etc.

As an interim measure, we can use U-Boot as an EFI app running on top of whatever EDK2 fork is in use. This allows use of modern features such as FIT and filesystems other than FAT. So far this only supports x86, but recent ARM laptops are making use of EFI too.

So this series adds an EFI app for 64-bit ARM.

Note: Since U-Boot does not support EFI's GOP 'blt-only' mode, the vidconsole does not operate, but it can still be used, since EDK2 handles drawing instead of U-Boot. As a result, the U-Boot logo is not shown.

Changes in v3:
- Use the same copyright message as the original pci_rom.c file
- Rewrite the commit message
- Drop setting of EFI_LDS and rely on the CONFIG_SYS_LDSCRIPT value

Changes in v2:
- Depend on CONFIG_EFI_APP instead
- Drop change to u-boot-elf rule
- Mention '64-bit ARM' here, rather than just 'ARM'
- Drop the word 'Sadly'
- Mention '64-bit ARM' here, rather than just 'ARM'
- Add new patch to rename VENDOR_EFI to ARCH_EFI
- Update to use ARCH_EFI instead of VENDOR_EFI
- Mention '64-bit ARM' here, rather than just 'ARM'
- Mention '64-bit ARM' here, rather than just 'ARM'
- Rework the commit message to clarify the relationship to link-scripts
- Expand commit message to explains that EFI_APP skips relocation
- Mention '64-bit ARM' here, rather than just 'ARM'
- Document the x86 field better and add a comment for ARM too
- Mention '64-bit ARM' here, rather than just 'ARM'
- Put the EFI-app case first in setup_mon_len(), for clarity
- Use ARCH_EFI instead of VENDOR_EFI
- Merge the linker-script rules into Kconfig in this patch
- Drop patch 'Select the EFI linker script for the app'

Simon Glass (29):
Makefile: Avoid using TEXT_BASE if not present
video: Move vesa_setup_video_priv() into its own file
video: Use a local mode_info struct in the EFI driver
lib: Provide fdtdec_get_pci_bar32() only with PCI enabled
efi: Rename app and payload to include x86
efi: Allow board/efi Kconfig to be used outside x86
efi: x86: Move EFI SDRAM-handling into a common file
treewide: Rename VENDOR_EFI to ARCH_EFI
efi: x86: Rework VENDOR_EFI option to permit other archs
efi: x86: Allow setting the global_data pointer with EFI
efi: Tidy up setup of global_data
efi: Rename ImageBase to image_base
efi: lmb: Avoid access to _start
efi: arm: Don't do the EL2 switch when running under EFI
efi: arm: Avoid allocating page tables when running under EFI
efi: arm: Avoid enabling caches when running under EFI
efi: arm: Implement access to global_data for EFI
efi: arm: Omit the ARM start-up code in the EFI app
efi: arm: Drop exception-level code when running as EFI app
efi: arm: x86: Allow use of the EFI table in the app
efi: arm: Disable --gc-sections for the app
efi: arm: Drop startup code from the app
efi: arm: Adjust how the monitor length is calculated
efi: arm: Provide startup and relocation code
efi: Generate the app as a shared library
efi: arm: Disable STATIC_RELA for the EFI app
efi: arm: Use EFI flags for all compilation with the app
efi: arm: Simplify the crt0 file and update link script
efi: arm: Add an EFI app for arm64

 Kconfig                               |   1 +
 MAINTAINERS                           |   4 +-
 Makefile                              |   6 +
 arch/Kconfig                          |   2 +
 arch/arm/Kconfig                      |   6 +-
 arch/arm/Makefile                     |   2 +
 arch/arm/config.mk                    |  12 +-
 arch/arm/cpu/armv8/Makefile           |   4 +-
 arch/arm/cpu/armv8/config.mk          |   6 +-
 arch/arm/dts/efi-arm_app.dts          |  31 +++++
 arch/arm/include/asm/global_data.h    |  18 ++-
 arch/arm/lib/Makefile                 |  12 +-
 arch/arm/lib/bootm.c                  |   7 +-
 arch/arm/lib/cache.c                  |   3 +
 arch/arm/lib/crt0_aarch64_efi.S       | 158 ++++----------------------
 arch/arm/lib/crt0_arm_efi.S           |   2 +-
 arch/arm/lib/elf_aarch64_efi.lds      |  49 +++++---
 arch/riscv/lib/crt0_riscv_efi.S       |  30 ++---
 arch/x86/Kconfig                      |   4 +-
 arch/x86/cpu/efi/Makefile             |   1 -
 arch/x86/include/asm/global_data.h    |   9 +-
 board/efi/Kconfig                     |  44 ++++++-
 board/efi/efi-arm_app/Kconfig         |  19 ++++
 board/efi/efi-arm_app/MAINTAINERS     |  13 +++
 board/efi/efi-arm_app/Makefile        |   5 +
 board/efi/efi-arm_app/board.c         |  18 +++
 board/efi/efi-arm_app/efi-arm_app.env |  11 ++
 board/efi/efi-x86_payload/Kconfig     |   2 +-
 common/board_f.c                      |   6 +-
 common/board_r.c                      |   9 +-
 configs/efi-arm_app64_defconfig       |  51 +++++++++
 configs/efi-x86_app32_defconfig       |   4 +-
 configs/efi-x86_app64_defconfig       |   4 +-
 configs/efi-x86_payload32_defconfig   |   4 +-
 configs/efi-x86_payload64_defconfig   |   4 +-
 doc/develop/uefi/u-boot_on_efi.rst    |  17 +--
 drivers/pci/pci_rom.c                 |  32 ------
 drivers/video/Makefile                |   2 +
 drivers/video/efi.c                   |   1 +
 drivers/video/vesa_helper.c           |  41 +++++++
 include/asm-generic/sections.h        |   2 +
 include/vesa.h                        |   2 +
 lib/efi/Kconfig                       |   2 +-
 lib/efi/Makefile                      |   1 +
 lib/efi/efi_app.c                     |  13 ++-
 {arch/x86/cpu => lib}/efi/sdram.c     |   1 -
 lib/fdtdec.c                          |   2 +
 lib/lmb.c                             |   3 +-
 48 files changed, 430 insertions(+), 250 deletions(-)
 create mode 100644 arch/arm/dts/efi-arm_app.dts
 create mode 100644 board/efi/efi-arm_app/Kconfig
 create mode 100644 board/efi/efi-arm_app/MAINTAINERS
 create mode 100644 board/efi/efi-arm_app/Makefile
 create mode 100644 board/efi/efi-arm_app/board.c
 create mode 100644 board/efi/efi-arm_app/efi-arm_app.env
 create mode 100644 configs/efi-arm_app64_defconfig
 create mode 100644 drivers/video/vesa_helper.c
 rename {arch/x86/cpu => lib}/efi/sdram.c (94%)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v3 1/29 Makefile: Avoid using TEXT_BASE if not present

This value is only available if CONFIG_HAVE_TEXT_BASE is enabled. Add conditions to avoid introducing errors in link scripts when it is not.

---

(no changes since v2)

Changes in v2:
- Depend on CONFIG_EFI_APP instead
- Drop change to u-boot-elf rule

 Makefile | 2 ++
 1 file changed, 2 insertions(+)
Makefile +2 -0
index 2f7614191a1..f989c31073f 100644
@@ -1050,8 +1050,10 @@ LDFLAGS_u-boot += -z notext $(call ld-option,--apply-dynamic-relocs)
 LDFLAGS_u-boot += --build-id=none
 
 ifeq ($(CONFIG_ARC)$(CONFIG_NIOS2)$(CONFIG_X86)$(CONFIG_XTENSA),)
+ifndef CONFIG_EFI_APP
 LDFLAGS_u-boot += -Ttext $(CONFIG_TEXT_BASE)
 endif
+endif
 
 # make the checker run with the right architecture
 CHECKFLAGS += --arch=$(ARCH)
Signature · 1 line
2.43.0
#2 lore raw

PATCH v3 2/29 video: Move vesa_setup_video_priv() into its own file

In reply to Simon Glass

This helper is used by the EFI driver and we would like to use that on ARM. Move the helper function into its own file, separate from PCI ROMs, which are an x86 thing.

Add a forward declaration for struct udevice so that the header can be included directly.

---

Changes in v3:
- Use the same copyright message as the original pci_rom.c file

 drivers/pci/pci_rom.c       | 32 -----------------------------
 drivers/video/Makefile      |  2 ++
 drivers/video/vesa_helper.c | 41 +++++++++++++++++++++++++++++++++++++
 include/vesa.h              |  2 ++
 4 files changed, 45 insertions(+), 32 deletions(-)
 create mode 100644 drivers/video/vesa_helper.c
drivers/pci/pci_rom.c +0 -32
index 2753df275ca..35654ca89ac 100644
@@ -334,38 +334,6 @@ err:
 	return ret;
 }
 
-int vesa_setup_video_priv(struct vesa_mode_info *vesa, u64 fb,
-			  struct video_priv *uc_priv,
-			  struct video_uc_plat *plat)
-{
-	if (!vesa->x_resolution)
-		return log_msg_ret("No x resolution", -ENXIO);
-	uc_priv->xsize = vesa->x_resolution;
-	uc_priv->ysize = vesa->y_resolution;
-	uc_priv->line_length = vesa->bytes_per_scanline;
-	switch (vesa->bits_per_pixel) {
-	case 32:
-	case 24:
-		uc_priv->bpix = VIDEO_BPP32;
-		break;
-	case 16:
-		uc_priv->bpix = VIDEO_BPP16;
-		break;
-	default:
-		return -EPROTONOSUPPORT;
-	}
-
-	/* Use double buffering if enabled */
-	if (IS_ENABLED(CONFIG_VIDEO_COPY) && plat->base)
-		plat->copy_base = fb;
-	else
-		plat->base = fb;
-	log_debug("base = %lx, copy_base = %lx\n", plat->base, plat->copy_base);
-	plat->size = vesa->bytes_per_scanline * vesa->y_resolution;
-
-	return 0;
-}
-
 int vesa_setup_video(struct udevice *dev, int (*int15_handler)(void))
 {
 	struct video_uc_plat *plat = dev_get_uclass_plat(dev);
drivers/video/Makefile +2 -0
index 5a00438ce06..416a929d36b 100644
@@ -27,6 +27,8 @@ obj-$(CONFIG_$(PHASE_)SIMPLE_PANEL) += simple_panel.o
 obj-$(CONFIG_VIDEO_LOGO) += u_boot_logo.o
 obj-$(CONFIG_$(PHASE_)BMP) += bmp.o
 
+obj-y += vesa_helper.o
+
 endif
 
 obj-$(CONFIG_BACKLIGHT_LM3533) += lm3533_backlight.o
drivers/video/vesa_helper.c new file +41 -0

41 lines not on this page · raw message

include/vesa.h +2 -0
index 9285bfa921a..abfc624e7cc 100644
@@ -10,6 +10,8 @@
 #ifndef _VESA_H
 #define _VESA_H
 
+struct udevice;
+
 /* these structs are for input from and output to OF */
 struct __packed vesa_screen_info {
 	u8 display_type;	/* 0=NONE, 1= analog, 2=digital */
Signature · 1 line
2.43.0
Reviewed-by on v3 2/29
#3 lore raw

Re: [PATCH v3 02/29] video: Move vesa_setup_video_priv() into its own file

Quoted 8 lines · Simon Glass

This helper is used by the EFI driver and we would like to use that on ARM. Move the helper function into its own file, separate from PCI ROMs, which are an x86 thing.

Add a forward declaration for struct udevice so that the header can be included directly.

Signature · 1 line
Tom
#4 lore raw

PATCH v3 3/29 video: Use a local mode_info struct in the EFI driver

In reply to Simon Glass

There is no need to use the global struct provided by PCI. Declare a local structure instead, so this can be used on ARM without including support for PCI ROMs.

---

(no changes since v1)

 drivers/video/efi.c | 1 +
 1 file changed, 1 insertion(+)
drivers/video/efi.c +1 -0
index a7b6d47f9a1..94d4c93dac3 100644
@@ -183,6 +183,7 @@ static int efi_video_probe(struct udevice *dev)
 {
 	struct video_uc_plat *plat = dev_get_uclass_plat(dev);
 	struct video_priv *uc_priv = dev_get_uclass_priv(dev);
+	struct vesa_state mode_info;
 	struct vesa_mode_info *vesa = &mode_info.vesa;
 	u64 fb;
 	int ret;
Signature · 1 line
2.43.0
Reviewed-by on v3 3/29
#5 lore raw

Re: [PATCH v3 03/29] video: Use a local mode_info struct in the EFI driver

Quoted 5 lines · Simon Glass

There is no need to use the global struct provided by PCI. Declare a local structure instead, so this can be used on ARM without including support for PCI ROMs.

This one really threw me when I first hit it :D I like this fix.

Quoted 19 lines

---

(no changes since v1)

  drivers/video/efi.c | 1 +
  1 file changed, 1 insertion(+)
drivers/video/efi.c +1 -0
index a7b6d47f9a1..94d4c93dac3 100644
@@ -183,6 +183,7 @@ static int efi_video_probe(struct udevice *dev)
  {
  	struct video_uc_plat *plat = dev_get_uclass_plat(dev);
  	struct video_priv *uc_priv = dev_get_uclass_priv(dev);
+	struct vesa_state mode_info;
  	struct vesa_mode_info *vesa = &mode_info.vesa;
  	u64 fb;
  	int ret;
Signature · 1 line
Caleb (they/them)
#6 lore raw

PATCH v3 4/29 lib: Provide fdtdec_get_pci_bar32() only with PCI enabled

In reply to Simon Glass

This function calls dm_pci_read_bar32() which is only available if PCI is enabled. Add this condition here too, so that the EFI app can build without needing --gc-sections

---

(no changes since v1)

 lib/fdtdec.c | 2 ++
 1 file changed, 2 insertions(+)
lib/fdtdec.c +2 -0
index 3b4247be25a..0244e8a3a72 100644
@@ -248,6 +248,7 @@ int fdtdec_get_pci_vendev(const void *blob, int node, u16 *vendor, u16 *device)
 	return -ENOENT;
 }
 
+#ifdef CONFIG_PCI
 int fdtdec_get_pci_bar32(const struct udevice *dev, struct fdt_pci_addr *addr,
 			 u32 *bar)
 {
@@ -264,6 +265,7 @@ int fdtdec_get_pci_bar32(const struct udevice *dev, struct fdt_pci_addr *addr,
 
 	return 0;
 }
+#endif
 
 int fdtdec_get_pci_bus_range(const void *blob, int node,
 			     struct fdt_resource *res)
Signature · 1 line
2.43.0
#7 lore raw

PATCH v3 5/29 efi: Rename app and payload to include x86

In reply to Simon Glass

Since we plan to support the EFI app and payload on 64-bit ARM too, rename the x86 target.

Adjust the Kconfig rules to allow non-x86 builds to be added.

---

(no changes since v2)

Changes in v2:
- Mention '64-bit ARM' here, rather than just 'ARM'

 board/efi/Kconfig                   | 12 ++++++++----
 board/efi/efi-x86_payload/Kconfig   |  2 +-
 configs/efi-x86_app32_defconfig     |  2 +-
 configs/efi-x86_app64_defconfig     |  2 +-
 configs/efi-x86_payload32_defconfig |  2 +-
 configs/efi-x86_payload64_defconfig |  2 +-
 6 files changed, 13 insertions(+), 9 deletions(-)
board/efi/Kconfig +8 -4
index 3df6e31c8ba..9027ca8482c 100644
@@ -4,7 +4,7 @@ choice
 	prompt "Mainboard model"
 	optional
 
-config TARGET_EFI_APP32
+config TARGET_EFI_X86_APP32
 	bool "32-bit efi application"
 	select EFI_APP
 	help
@@ -13,17 +13,17 @@ config TARGET_EFI_APP32
 	  takes over once the RAM, video and CPU are fully running.
 	  U-Boot is loaded as an application from EFI.
 
-config TARGET_EFI_APP64
+config TARGET_EFI_X86_APP64
 	bool "64-bit efi application"
 	select EFI_APP
-	select X86_64
+	select X86_64 if X86
 	help
 	  This target is used for running U-Boot on top of EFI in 64-bit mode.
 	  In this case EFI does the early initialisation, and U-Boot
 	  takes over once the RAM, video and CPU are fully running.
 	  U-Boot is loaded as an application from EFI.
 
-config TARGET_EFI_PAYLOAD
+config TARGET_EFI_X86_PAYLOAD
 	bool "efi payload"
 	help
 	  This target is used for running U-Boot on top of EFI. In
@@ -33,7 +33,11 @@ config TARGET_EFI_PAYLOAD
 
 endchoice
 
+if X86
+
 source "board/efi/efi-x86_app/Kconfig"
 source "board/efi/efi-x86_payload/Kconfig"
 
 endif
+
+endif
board/efi/efi-x86_payload/Kconfig +1 -1
index c500ca02ebf..d181bf6de09 100644
@@ -1,4 +1,4 @@
-if TARGET_EFI_PAYLOAD
+if TARGET_EFI_X86_PAYLOAD
 
 config SYS_BOARD
 	default "efi-x86_payload"
configs/efi-x86_app32_defconfig +1 -1
index b20c85f1cff..bfcef9afa88 100644
@@ -5,7 +5,7 @@ CONFIG_DEFAULT_DEVICE_TREE="efi-x86_app"
 CONFIG_DEBUG_UART_BASE=0x0
 CONFIG_DEBUG_UART_CLOCK=0
 CONFIG_VENDOR_EFI=y
-CONFIG_TARGET_EFI_APP32=y
+CONFIG_TARGET_EFI_X86_APP32=y
 CONFIG_DEBUG_UART=y
 CONFIG_EFI=y
 CONFIG_FIT=y
configs/efi-x86_app64_defconfig +1 -1
index 0988ad45205..8f1319c0b4c 100644
@@ -6,7 +6,7 @@ CONFIG_DEBUG_UART_BASE=0x0
 CONFIG_DEBUG_UART_CLOCK=0
 CONFIG_X86_RUN_64BIT=y
 CONFIG_VENDOR_EFI=y
-CONFIG_TARGET_EFI_APP64=y
+CONFIG_TARGET_EFI_X86_APP64=y
 CONFIG_DEBUG_UART=y
 CONFIG_EFI=y
 CONFIG_EFI_APP_64BIT=y
configs/efi-x86_payload32_defconfig +1 -1
index 957fd83e432..48e757f629d 100644
@@ -4,7 +4,7 @@ CONFIG_ENV_SIZE=0x1000
 CONFIG_DEFAULT_DEVICE_TREE="efi-x86_payload"
 CONFIG_PRE_CON_BUF_ADDR=0x100000
 CONFIG_VENDOR_EFI=y
-CONFIG_TARGET_EFI_PAYLOAD=y
+CONFIG_TARGET_EFI_X86_PAYLOAD=y
 CONFIG_EFI=y
 CONFIG_EFI_STUB=y
 CONFIG_FIT=y
configs/efi-x86_payload64_defconfig +1 -1
index 71612d7fb19..2606ac261c1 100644
@@ -4,7 +4,7 @@ CONFIG_ENV_SIZE=0x1000
 CONFIG_DEFAULT_DEVICE_TREE="efi-x86_payload"
 CONFIG_PRE_CON_BUF_ADDR=0x100000
 CONFIG_VENDOR_EFI=y
-CONFIG_TARGET_EFI_PAYLOAD=y
+CONFIG_TARGET_EFI_X86_PAYLOAD=y
 CONFIG_EFI=y
 CONFIG_EFI_STUB=y
 CONFIG_EFI_STUB_64BIT=y
Signature · 1 line
2.43.0
#8 lore raw

PATCH v3 6/29 efi: Allow board/efi Kconfig to be used outside x86

In reply to Simon Glass

So far only x86 supports the EFI app. ARM is going the same way, so allow these options to be enabled for 64-bit ARM too.

---

(no changes since v2)

Changes in v2:
- Drop the word 'Sadly'
- Mention '64-bit ARM' here, rather than just 'ARM'

 arch/Kconfig      | 2 ++
 arch/x86/Kconfig  | 1 -
 board/efi/Kconfig | 4 ++--
 3 files changed, 4 insertions(+), 3 deletions(-)
arch/Kconfig +2 -0
index 6258788f53f..493c827d74d 100644
@@ -544,6 +544,8 @@ source "arch/Kconfig.nxp"
 
 endif
 
+source "board/efi/Kconfig"
+
 source "board/keymile/Kconfig"
 
 choice
arch/x86/Kconfig +0 -1
index 23a1e21b29e..80396a3a2d5 100644
@@ -100,7 +100,6 @@ source "board/advantech/Kconfig"
 source "board/congatec/Kconfig"
 source "board/coreboot/Kconfig"
 source "board/dfi/Kconfig"
-source "board/efi/Kconfig"
 source "board/emulation/Kconfig"
 source "board/google/Kconfig"
 source "board/intel/Kconfig"
board/efi/Kconfig +2 -2
index 9027ca8482c..7545f808585 100644
@@ -1,5 +1,7 @@
 if VENDOR_EFI
 
+if X86
+
 choice
 	prompt "Mainboard model"
 	optional
@@ -33,8 +35,6 @@ config TARGET_EFI_X86_PAYLOAD
 
 endchoice
 
-if X86
-
 source "board/efi/efi-x86_app/Kconfig"
 source "board/efi/efi-x86_payload/Kconfig"
 
Signature · 1 line
2.43.0
#9 lore raw

PATCH v3 7/29 efi: x86: Move EFI SDRAM-handling into a common file

In reply to Simon Glass

This code is not actually x86-specific, so move it into the lib/efi dir where other archs can use it.

Drop inclusion of the unnecessary x86-specific header.

---

(no changes since v1)

 arch/x86/cpu/efi/Makefile         | 1 -
 lib/efi/Makefile                  | 1 +
 {arch/x86/cpu => lib}/efi/sdram.c | 1 -
 3 files changed, 1 insertion(+), 2 deletions(-)
 rename {arch/x86/cpu => lib}/efi/sdram.c (94%)
arch/x86/cpu/efi/Makefile +0 -1
index 9716a4ebe08..9be1d5e5401 100644
@@ -4,7 +4,6 @@
 
 ifdef CONFIG_EFI_APP
 obj-y += app.o
-obj-y += sdram.o
 endif
 
 ifdef CONFIG_EFI_STUB
lib/efi/Makefile +1 -0
index 315625c0e8c..5081d71a19f 100644
@@ -3,6 +3,7 @@
 # (C) Copyright 2015 Google, Inc
 
 obj-$(CONFIG_EFI_APP) += efi_app.o efi.o efi_app_init.o efi_vars.o efi_dtb.o
+obj-$(CONFIG_EFI_APP) += sdram.o
 obj-$(CONFIG_EFI_STUB) += efi_info.o
 
 ifeq ($(CONFIG_ARM64),y)
lib/efi/sdram.c renamed from arch/x86/cpu/efi/sdram.c +0 -1
similarity index 94%
rename from arch/x86/cpu/efi/sdram.c
rename to lib/efi/sdram.c
index 6fe40071140..bd59dfade0f 100644
@@ -6,7 +6,6 @@
 #include <efi.h>
 #include <init.h>
 #include <asm/global_data.h>
-#include <asm/u-boot-x86.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
Signature · 1 line
2.43.0
#10 lore raw

PATCH v3 8/29 treewide: Rename VENDOR_EFI to ARCH_EFI

In reply to Simon Glass

The 'vendor' concept comes from arch/x86. Rather than letting this spread around the tree, rename it to ARCH_EFI.

While EFI is not quite an architecture in the strict sense, it is similar to sandbox in that it sits somewhat above the CPU architecture.

---
Ideas for a better name are welcome.

(no changes since v2)

Changes in v2:
- Add new patch to rename VENDOR_EFI to ARCH_EFI

 arch/arm/lib/crt0_aarch64_efi.S     | 2 +-
 arch/arm/lib/crt0_arm_efi.S         | 2 +-
 arch/riscv/lib/crt0_riscv_efi.S     | 2 +-
 arch/x86/Kconfig                    | 2 +-
 board/efi/Kconfig                   | 2 +-
 configs/efi-x86_app32_defconfig     | 2 +-
 configs/efi-x86_app64_defconfig     | 2 +-
 configs/efi-x86_payload32_defconfig | 2 +-
 configs/efi-x86_payload64_defconfig | 2 +-
 9 files changed, 9 insertions(+), 9 deletions(-)
arch/arm/lib/crt0_aarch64_efi.S +1 -1
index fe6eca576ec..f1d5de6a93d 100644
@@ -66,7 +66,7 @@ extra_header_fields:
 	.long	_start - ImageBase		/* SizeOfHeaders */
 	.long	0				/* CheckSum */
 	.short	IMAGE_SUBSYSTEM_EFI_APPLICATION /* Subsystem */
-#if CONFIG_VENDOR_EFI
+#if CONFIG_ARCH_EFI
 	.short	0				/* DllCharacteristics */
 #else
 	.short	IMAGE_DLLCHARACTERISTICS_NX_COMPAT
arch/arm/lib/crt0_arm_efi.S +1 -1
index b5dfd4e3819..f58256223aa 100644
@@ -65,7 +65,7 @@ extra_header_fields:
 	.long	_start - image_base		/* SizeOfHeaders */
 	.long	0				/* CheckSum */
 	.short	IMAGE_SUBSYSTEM_EFI_APPLICATION	/* Subsystem */
-#if CONFIG_VENDOR_EFI
+#if CONFIG_ARCH_EFI
 	.short	0				/* DllCharacteristics */
 #else
 	.short	IMAGE_DLLCHARACTERISTICS_NX_COMPAT
arch/riscv/lib/crt0_riscv_efi.S +1 -1
index c7a4559eac8..424f18480fa 100644
@@ -96,7 +96,7 @@ extra_header_fields:
 	.long	_start - ImageBase		/* SizeOfHeaders */
 	.long	0				/* CheckSum */
 	.short	IMAGE_SUBSYSTEM_EFI_APPLICATION /* Subsystem */
-#if CONFIG_VENDOR_EFI
+#if CONFIG_ARCH_EFI
 	.short	0				/* DllCharacteristics */
 #else
 	.short	IMAGE_DLLCHARACTERISTICS_NX_COMPAT
arch/x86/Kconfig +1 -1
index 80396a3a2d5..8c225f314ff 100644
@@ -65,7 +65,7 @@ config VENDOR_COREBOOT
 config VENDOR_DFI
 	bool "dfi"
 
-config VENDOR_EFI
+config ARCH_EFI
 	bool "efi"
 
 config VENDOR_EMULATION
board/efi/Kconfig +1 -1
index 7545f808585..05ac8d15d49 100644
@@ -1,4 +1,4 @@
-if VENDOR_EFI
+if ARCH_EFI
 
 if X86
 
configs/efi-x86_app32_defconfig +1 -1
index bfcef9afa88..0cdfe467f53 100644
@@ -4,7 +4,7 @@ CONFIG_ENV_SIZE=0x1000
 CONFIG_DEFAULT_DEVICE_TREE="efi-x86_app"
 CONFIG_DEBUG_UART_BASE=0x0
 CONFIG_DEBUG_UART_CLOCK=0
-CONFIG_VENDOR_EFI=y
+CONFIG_ARCH_EFI=y
 CONFIG_TARGET_EFI_X86_APP32=y
 CONFIG_DEBUG_UART=y
 CONFIG_EFI=y
configs/efi-x86_app64_defconfig +1 -1
index 8f1319c0b4c..ca3f084ef4c 100644
@@ -5,7 +5,7 @@ CONFIG_DEFAULT_DEVICE_TREE="efi-x86_app"
 CONFIG_DEBUG_UART_BASE=0x0
 CONFIG_DEBUG_UART_CLOCK=0
 CONFIG_X86_RUN_64BIT=y
-CONFIG_VENDOR_EFI=y
+CONFIG_ARCH_EFI=y
 CONFIG_TARGET_EFI_X86_APP64=y
 CONFIG_DEBUG_UART=y
 CONFIG_EFI=y
configs/efi-x86_payload32_defconfig +1 -1
index 48e757f629d..d96228c0694 100644
@@ -3,7 +3,7 @@ CONFIG_NR_DRAM_BANKS=8
 CONFIG_ENV_SIZE=0x1000
 CONFIG_DEFAULT_DEVICE_TREE="efi-x86_payload"
 CONFIG_PRE_CON_BUF_ADDR=0x100000
-CONFIG_VENDOR_EFI=y
+CONFIG_ARCH_EFI=y
 CONFIG_TARGET_EFI_X86_PAYLOAD=y
 CONFIG_EFI=y
 CONFIG_EFI_STUB=y
configs/efi-x86_payload64_defconfig +1 -1
index 2606ac261c1..9e055da297c 100644
@@ -3,7 +3,7 @@ CONFIG_NR_DRAM_BANKS=8
 CONFIG_ENV_SIZE=0x1000
 CONFIG_DEFAULT_DEVICE_TREE="efi-x86_payload"
 CONFIG_PRE_CON_BUF_ADDR=0x100000
-CONFIG_VENDOR_EFI=y
+CONFIG_ARCH_EFI=y
 CONFIG_TARGET_EFI_X86_PAYLOAD=y
 CONFIG_EFI=y
 CONFIG_EFI_STUB=y
Signature · 1 line
2.43.0
Reviewed-by on v3 8/29
#11 lore raw

Re: [PATCH v3 08/29] treewide: Rename VENDOR_EFI to ARCH_EFI

Quoted 7 lines · Simon Glass

The 'vendor' concept comes from arch/x86. Rather than letting this spread around the tree, rename it to ARCH_EFI.

While EFI is not quite an architecture in the strict sense, it is similar to sandbox in that it sits somewhat above the CPU architecture.

Likely the best we can do for a generic enough name, thanks.

Signature · 1 line
Tom
#12 lore raw

PATCH v3 9/29 efi: x86: Rework VENDOR_EFI option to permit other archs

In reply to Simon Glass

At present only x86 supports the EFI app and (apart from Qualcomm) the payload. In preparation for supporting 64-bit ARM more generally, rename the existing ARCH_EFI option to ARCH_EFI_X86, using that to define a generic ARCH_EFI which will be enabled for all architectures.

---

(no changes since v2)

Changes in v2:
- Update to use ARCH_EFI instead of VENDOR_EFI
- Mention '64-bit ARM' here, rather than just 'ARM'

 arch/arm/Kconfig                    | 4 ++++
 arch/x86/Kconfig                    | 3 ++-
 board/efi/Kconfig                   | 9 +++++++--
 configs/efi-x86_app32_defconfig     | 2 +-
 configs/efi-x86_app64_defconfig     | 2 +-
 configs/efi-x86_payload32_defconfig | 2 +-
 configs/efi-x86_payload64_defconfig | 2 +-
 7 files changed, 17 insertions(+), 7 deletions(-)
arch/arm/Kconfig +4 -0
index 01cb27aa1d7..a55ba6b7f09 100644
@@ -2157,6 +2157,10 @@ config ARCH_GXP
 	select OF_CONTROL
 	imply CMD_DM
 
+config ARCH_EFI_ARM
+	bool "efi"
+	select ARCH_EFI
+
 endchoice
 
 config SUPPORT_PASSING_ATAGS
arch/x86/Kconfig +2 -1
index 8c225f314ff..c43180e1537 100644
@@ -65,8 +65,9 @@ config VENDOR_COREBOOT
 config VENDOR_DFI
 	bool "dfi"
 
-config ARCH_EFI
+config ARCH_EFI_X86
 	bool "efi"
+	select ARCH_EFI
 
 config VENDOR_EMULATION
 	bool "emulation"
board/efi/Kconfig +7 -2
index 05ac8d15d49..4c68d85a076 100644
@@ -1,3 +1,8 @@
+config ARCH_EFI
+	bool
+	select OF_CONTROL
+	select DM_SERIAL
+
 if ARCH_EFI
 
 if X86
@@ -38,6 +43,6 @@ endchoice
 source "board/efi/efi-x86_app/Kconfig"
 source "board/efi/efi-x86_payload/Kconfig"
 
-endif
+endif  # X86
 
-endif
+endif  # ARCH_EFI
configs/efi-x86_app32_defconfig +1 -1
index 0cdfe467f53..c9346da7d47 100644
@@ -4,7 +4,7 @@ CONFIG_ENV_SIZE=0x1000
 CONFIG_DEFAULT_DEVICE_TREE="efi-x86_app"
 CONFIG_DEBUG_UART_BASE=0x0
 CONFIG_DEBUG_UART_CLOCK=0
-CONFIG_ARCH_EFI=y
+CONFIG_ARCH_EFI_X86=y
 CONFIG_TARGET_EFI_X86_APP32=y
 CONFIG_DEBUG_UART=y
 CONFIG_EFI=y
configs/efi-x86_app64_defconfig +1 -1
index ca3f084ef4c..5bc1e9e5cd9 100644
@@ -5,7 +5,7 @@ CONFIG_DEFAULT_DEVICE_TREE="efi-x86_app"
 CONFIG_DEBUG_UART_BASE=0x0
 CONFIG_DEBUG_UART_CLOCK=0
 CONFIG_X86_RUN_64BIT=y
-CONFIG_ARCH_EFI=y
+CONFIG_ARCH_EFI_X86=y
 CONFIG_TARGET_EFI_X86_APP64=y
 CONFIG_DEBUG_UART=y
 CONFIG_EFI=y
configs/efi-x86_payload32_defconfig +1 -1
index d96228c0694..65e562e1bc8 100644
@@ -3,7 +3,7 @@ CONFIG_NR_DRAM_BANKS=8
 CONFIG_ENV_SIZE=0x1000
 CONFIG_DEFAULT_DEVICE_TREE="efi-x86_payload"
 CONFIG_PRE_CON_BUF_ADDR=0x100000
-CONFIG_ARCH_EFI=y
+CONFIG_ARCH_EFI_X86=y
 CONFIG_TARGET_EFI_X86_PAYLOAD=y
 CONFIG_EFI=y
 CONFIG_EFI_STUB=y
configs/efi-x86_payload64_defconfig +1 -1
index 9e055da297c..4f341f43ed9 100644
@@ -3,7 +3,7 @@ CONFIG_NR_DRAM_BANKS=8
 CONFIG_ENV_SIZE=0x1000
 CONFIG_DEFAULT_DEVICE_TREE="efi-x86_payload"
 CONFIG_PRE_CON_BUF_ADDR=0x100000
-CONFIG_ARCH_EFI=y
+CONFIG_ARCH_EFI_X86=y
 CONFIG_TARGET_EFI_X86_PAYLOAD=y
 CONFIG_EFI=y
 CONFIG_EFI_STUB=y
Signature · 1 line
2.43.0
Reviewed-by on v3 9/29
#13 lore raw

Re: [PATCH v3 09/29] efi: x86: Rework VENDOR_EFI option to permit other archs

Quoted 6 lines · Simon Glass

At present only x86 supports the EFI app and (apart from Qualcomm) the payload. In preparation for supporting 64-bit ARM more generally, rename the existing ARCH_EFI option to ARCH_EFI_X86, using that to define a generic ARCH_EFI which will be enabled for all architectures.

Signature · 1 line
Tom
#14 lore raw

PATCH v3 10/29 efi: x86: Allow setting the global_data pointer with EFI

In reply to Simon Glass

Provide a function which sets this pointer, for use in the EFI app.

---

(no changes since v1)

 arch/x86/include/asm/global_data.h | 7 +++++++
 1 file changed, 7 insertions(+)
arch/x86/include/asm/global_data.h +7 -0
index 06bd80ccc13..1bd1fa92078 100644
@@ -142,6 +142,13 @@ struct arch_global_data {
 /* TODO([email protected]): Consider using a fixed register for gd on x86_64 */
 #define gd global_data_ptr
 
+static inline void set_gd(volatile gd_t *gd_ptr)
+{
+	extern struct global_data *global_data_ptr;
+
+	global_data_ptr = (void *)gd_ptr;
+}
+
 #define DECLARE_GLOBAL_DATA_PTR   extern struct global_data *global_data_ptr
 # else
 static inline notrace gd_t *get_fs_gd_ptr(void)
Signature · 1 line
2.43.0
#15 lore raw

PATCH v3 11/29 efi: Tidy up setup of global_data

In reply to Simon Glass

Use the available functions for setting and getting the global_data pointer so that EFI-startup can operate on 64-bit ARM as well as x86.

---

(no changes since v2)

Changes in v2:
- Mention '64-bit ARM' here, rather than just 'ARM'

 lib/efi/efi_app.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
lib/efi/efi_app.c +8 -5
index ff8b62a1e1a..1aa43b511b3 100644
@@ -77,6 +77,7 @@ int efi_get_mmap(struct efi_mem_desc **descp, int *sizep, uint *keyp,
 static efi_status_t setup_memory(struct efi_priv *priv)
 {
 	struct efi_boot_services *boot = priv->boot;
+	struct global_data *ptr;
 	efi_physical_addr_t addr;
 	efi_status_t ret;
 	int pages;
@@ -86,10 +87,12 @@ static efi_status_t setup_memory(struct efi_priv *priv)
 	 * are very few assignments to global_data in U-Boot and this makes
 	 * it easier to find them.
 	 */
-	global_data_ptr = efi_malloc(priv, sizeof(struct global_data), &ret);
-	if (!global_data_ptr)
+	ptr = efi_malloc(priv, sizeof(*ptr), &ret);
+	if (!ptr)
 		return ret;
-	memset(gd, '\0', sizeof(*gd));
+	memset(ptr, '\0', sizeof(*ptr));
+
+	set_gd(ptr);
 
 	gd->malloc_base = (ulong)efi_malloc(priv, CONFIG_VAL(SYS_MALLOC_F_LEN),
 					    &ret);
@@ -138,8 +141,8 @@ static void free_memory(struct efi_priv *priv)
 		boot->free_pages(priv->ram_base, gd->ram_size >> 12);
 
 	efi_free(priv, (void *)gd->malloc_base);
-	efi_free(priv, gd);
-	global_data_ptr = NULL;
+	efi_free(priv, (void *)gd);
+	set_gd((void *)NULL);
 }
 
 static void scan_tables(struct efi_system_table *sys_table)
Signature · 1 line
2.43.0
#16 lore raw

PATCH v3 12/29 efi: Rename ImageBase to image_base

In reply to Simon Glass

It is confusing to have a camel-case indentifier in the these files. Rename them to fit with U-Boot's snake-case style.

The image_base symbol is already used in the x86 link-scripts.

---

(no changes since v2)

Changes in v2:
- Rework the commit message to clarify the relationship to link-scripts

 arch/arm/lib/crt0_aarch64_efi.S | 26 +++++++++++++-------------
 arch/riscv/lib/crt0_riscv_efi.S | 28 ++++++++++++++--------------
 include/asm-generic/sections.h  |  2 ++
 3 files changed, 29 insertions(+), 27 deletions(-)
arch/arm/lib/crt0_aarch64_efi.S +13 -13
index f1d5de6a93d..c1030e5392a 100644
@@ -15,12 +15,12 @@
 	/*
 	 * Magic "MZ" signature for PE/COFF
 	 */
-	.globl	ImageBase
-ImageBase:
+	.globl	image_base
+image_base:
 	.short	IMAGE_DOS_SIGNATURE		/* 'MZ' */
 	.skip	54				/* 'MZ' + pad + offset == 64 */
 	.long   LINUX_ARM64_MAGIC		/* For GRUB's linux command */
-	.long	pe_header - ImageBase		/* Offset to the PE header */
+	.long	pe_header - image_base		/* Offset to the PE header */
 pe_header:
 	.long	IMAGE_NT_SIGNATURE		/* 'PE' */
 coff_header:
@@ -43,11 +43,11 @@ optional_header:
 	.long	_etext - _start			/* SizeOfCode */
 	.long	0				/* SizeOfInitializedData */
 	.long	0				/* SizeOfUninitializedData */
-	.long	_start - ImageBase		/* AddressOfEntryPoint */
-	.long	_start - ImageBase		/* BaseOfCode */
+	.long	_start - image_base		/* AddressOfEntryPoint */
+	.long	_start - image_base		/* BaseOfCode */
 
 extra_header_fields:
-	.quad	0				/* ImageBase */
+	.quad	0				/* image_base */
 	.long	0x1000				/* SectionAlignment */
 	.long	0x200				/* FileAlignment */
 	.short	0				/* MajorOperatingSystemVersion */
@@ -58,12 +58,12 @@ extra_header_fields:
 	.short	0				/* MinorSubsystemVersion */
 	.long	0				/* Win32VersionValue */
 
-	.long	_edata - ImageBase		/* SizeOfImage */
+	.long	_edata - image_base		/* SizeOfImage */
 
 	/*
 	 * Everything before the kernel image is considered part of the header
 	 */
-	.long	_start - ImageBase		/* SizeOfHeaders */
+	.long	_start - image_base		/* SizeOfHeaders */
 	.long	0				/* CheckSum */
 	.short	IMAGE_SUBSYSTEM_EFI_APPLICATION /* Subsystem */
 #if CONFIG_ARCH_EFI
@@ -114,9 +114,9 @@ section_table:
 	.byte	0
 	.byte	0			/* end of 0 padding of section name */
 	.long	_etext - _start		/* VirtualSize */
-	.long	_start - ImageBase	/* VirtualAddress */
+	.long	_start - image_base	/* VirtualAddress */
 	.long	_etext - _start		/* SizeOfRawData */
-	.long	_start - ImageBase	/* PointerToRawData */
+	.long	_start - image_base	/* PointerToRawData */
 	.long	0			/* PointerToRelocations */
 	.long	0			/* PointerToLineNumbers */
 	.short	0			/* NumberOfRelocations */
@@ -131,9 +131,9 @@ section_table:
 	.byte	0
 	.byte	0			/* end of 0 padding of section name */
 	.long	_data_size		/* VirtualSize */
-	.long	_data - ImageBase	/* VirtualAddress */
+	.long	_data - image_base	/* VirtualAddress */
 	.long	_data_size		/* SizeOfRawData */
-	.long	_data - ImageBase	/* PointerToRawData */
+	.long	_data - image_base	/* PointerToRawData */
 	.long	0			/* PointerToRelocations */
 	.long	0			/* PointerToLineNumbers */
 	.short	0			/* NumberOfRelocations */
@@ -149,7 +149,7 @@ _start:
 	mov		x29, sp
 
 	stp		x0, x1, [sp, #16]
-	adr		x0, ImageBase
+	adr		x0, image_base
 	adrp		x1, _DYNAMIC
 	add		x1, x1, #:lo12:_DYNAMIC
 	bl		_relocate
arch/riscv/lib/crt0_riscv_efi.S +14 -14
index 424f18480fa..909d9e793d3 100644
@@ -41,14 +41,14 @@
 	/*
 	 * Magic "MZ" signature for PE/COFF
 	 */
-	.globl	ImageBase
-ImageBase:
+	.globl	image_base
+image_base:
 	.short	IMAGE_DOS_SIGNATURE		/* 'MZ' */
 	.skip	46				/* 'MZ' + pad + offset == 64 */
 	.long	0x43534952			/* Linux magic "RISCV */
 	.long	0x00000056
 	.long	0x05435352			/* Linux magic2 "RSC\x05*/
-	.long	pe_header - ImageBase		/* Offset to the PE header */
+	.long	pe_header - image_base		/* Offset to the PE header */
 pe_header:
 	.long	IMAGE_NT_SIGNATURE		/* 'PE' */
 coff_header:
@@ -66,17 +66,17 @@ optional_header:
 	.long	_edata - _start			/* SizeOfCode */
 	.long	0				/* SizeOfInitializedData */
 	.long	0				/* SizeOfUninitializedData */
-	.long	_start - ImageBase		/* AddressOfEntryPoint */
-	.long	_start - ImageBase		/* BaseOfCode */
+	.long	_start - image_base		/* AddressOfEntryPoint */
+	.long	_start - image_base		/* BaseOfCode */
 #if __riscv_xlen == 32
 	.long	0				/* BaseOfData */
 #endif
 
 extra_header_fields:
 #if __riscv_xlen == 32
-	.long	0				/* ImageBase */
+	.long	0				/* image_base */
 #else
-	.quad	0				/* ImageBase */
+	.quad	0				/* image_base */
 #endif
 	.long	0x200				/* SectionAlignment */
 	.long	0x200				/* FileAlignment */
@@ -88,12 +88,12 @@ extra_header_fields:
 	.short	0				/* MinorSubsystemVersion */
 	.long	0				/* Win32VersionValue */
 
-	.long	_edata - ImageBase		/* SizeOfImage */
+	.long	_edata - image_base		/* SizeOfImage */
 
 	/*
 	 * Everything before the kernel image is considered part of the header
 	 */
-	.long	_start - ImageBase		/* SizeOfHeaders */
+	.long	_start - image_base		/* SizeOfHeaders */
 	.long	0				/* CheckSum */
 	.short	IMAGE_SUBSYSTEM_EFI_APPLICATION /* Subsystem */
 #if CONFIG_ARCH_EFI
@@ -149,9 +149,9 @@ section_table:
 	.byte	0
 	.byte	0			/* end of 0 padding of section name */
 	.long	_etext - _start		/* VirtualSize */
-	.long	_start - ImageBase	/* VirtualAddress */
+	.long	_start - image_base	/* VirtualAddress */
 	.long	_etext - _start		/* SizeOfRawData */
-	.long	_start - ImageBase	/* PointerToRawData */
+	.long	_start - image_base	/* PointerToRawData */
 	.long	0			/* PointerToRelocations (0 for executables) */
 	.long	0			/* PointerToLineNumbers (0 for executables) */
 	.short	0			/* NumberOfRelocations  (0 for executables) */
@@ -166,9 +166,9 @@ section_table:
 	.byte	0
 	.byte	0			/* end of 0 padding of section name */
 	.long	_edata - _data		/* VirtualSize */
-	.long	_data - ImageBase	/* VirtualAddress */
+	.long	_data - image_base	/* VirtualAddress */
 	.long	_edata - _data		/* SizeOfRawData */
-	.long	_data - ImageBase	/* PointerToRawData */
+	.long	_data - image_base	/* PointerToRawData */
 	.long	0			/* PointerToRelocations */
 	.long	0			/* PointerToLineNumbers */
 	.short	0			/* NumberOfRelocations */
@@ -185,7 +185,7 @@ _start:
 	SAVE_LONG(a1, 1)
 	SAVE_LONG(ra, 2)
 
-	lla		a0, ImageBase
+	lla		a0, image_base
 	lla		a1, _DYNAMIC
 	call		_relocate
 	bne		a0, zero, 0f
include/asm-generic/sections.h +2 -0
index 5b040d0acd0..606fce65adc 100644
@@ -72,6 +72,8 @@ extern char __rel_dyn_start[], __rel_dyn_end[];
 extern char _image_binary_end[];
 extern char __dtb[];
 
+extern char image_base[];
+
 /*
  * This is the U-Boot entry point - prior to relocation it should be same
  * as __text_start
Signature · 1 line
2.43.0
#17 lore raw

Re: [PATCH v3 12/29] efi: Rename ImageBase to image_base

Quoted 5 lines · Simon Glass

It is confusing to have a camel-case indentifier in the these files. Rename them to fit with U-Boot's snake-case style.

The image_base symbol is already used in the x86 link-scripts.

Quoted 7 lines

---

(no changes since v2)

Changes in v2:
- Rework the commit message to clarify the relationship to link-scripts

Thanks for explaining where this comes from a bit more. I still think this is a case where our x86 code gets it backwards. To me following the naming convention of the specification we're implementing is more important than stylization. But I'd really like anyone else who deals with this area to chime in.

Signature · 1 line
Tom
#18 lore raw

PATCH v3 13/29 efi: lmb: Avoid access to _start

In reply to Simon Glass

The app does not have this symbol. Also the memory where the app is loaded is not under U-Boot's control.

There is no sense in relocating from one alloced region to another. U-Boot is not able to relocate to the top of memory, nor decide what other parts of memory are used for.

For these reasons, the EFI app skips relocation. It is not running at the address pointed to by the _start symbol.

So disable this reservation for the EFI app.

---

(no changes since v2)

Changes in v2:
- Expand commit message to explains that EFI_APP skips relocation

 lib/lmb.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/lmb.c +2 -1
index 588787d2a90..420eae4d0b8 100644
@@ -560,7 +560,8 @@ static void lmb_reserve_uboot_region(void)
 		lmb_reserve_flags(rsv_start, bank_end - rsv_start + 1,
 				  LMB_NOOVERWRITE);
 
-		if (gd->flags & GD_FLG_SKIP_RELOC)
+		if (!IS_ENABLED(CONFIG_EFI_APP) &&
+		    (gd->flags & GD_FLG_SKIP_RELOC))
 			lmb_reserve_flags((phys_addr_t)(uintptr_t)_start,
 					  gd->mon_len, LMB_NOOVERWRITE);
 
Signature · 1 line
2.43.0
#19 lore raw

PATCH v3 14/29 efi: arm: Don't do the EL2 switch when running under EFI

In reply to Simon Glass

The previous bootloader has likely done this already, so avoid trying to do it again. This fixes a crash in QEMU when booting from EDK2

---

(no changes since v1)

 arch/arm/lib/bootm.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
arch/arm/lib/bootm.c +5 -2
index 974cbfe8400..688c2f3f29b 100644
@@ -16,6 +16,7 @@
 #include <command.h>
 #include <cpu_func.h>
 #include <dm.h>
+#include <init.h>
 #include <log.h>
 #include <asm/global_data.h>
 #include <dm/root.h>
@@ -186,8 +187,10 @@ __weak void setup_board_tags(struct tag **in_params) {}
 #ifdef CONFIG_ARM64
 static void do_nonsec_virt_switch(void)
 {
-	smp_kick_all_cpus();
-	dcache_disable();	/* flush cache before swtiching to EL2 */
+	if (ll_boot_init()) {
+		smp_kick_all_cpus();
+		dcache_disable();	/* flush cache before swtiching to EL2 */
+	}
 }
 #endif
 
Signature · 1 line
2.43.0
#20 lore raw

PATCH v3 15/29 efi: arm: Avoid allocating page tables when running under EFI

In reply to Simon Glass

The previous bootloader has already set up the page tables, so don't try to do it again.

This fixes a crash in QEMU when booting from EDK2

---

(no changes since v1)

 arch/arm/lib/cache.c | 3 +++
 1 file changed, 3 insertions(+)
arch/arm/lib/cache.c +3 -0
index 516754caeaf..bdd0f202bf9 100644
@@ -6,6 +6,7 @@
 
 #include <config.h>
 #include <cpu_func.h>
+#include <init.h>
 #include <log.h>
 #include <malloc.h>
 #include <asm/cache.h>
@@ -138,6 +139,8 @@ int arch_reserve_mmu(void)
 
 __weak int arm_reserve_mmu(void)
 {
+	if (!ll_boot_init())
+		return 0;
 #if !(CONFIG_IS_ENABLED(SYS_ICACHE_OFF) && CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
 	/* reserve TLB table */
 	gd->arch.tlb_size = PGTABLE_SIZE;
Signature · 1 line
2.43.0
#21 lore raw

PATCH v3 16/29 efi: arm: Avoid enabling caches when running under EFI

In reply to Simon Glass

The previous bootloader has already set up the cache, so don't try to do it again.

This fixes a crash in QEMU when booting from EDK2

---

(no changes since v1)

 common/board_r.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
common/board_r.c +3 -2
index caac092c8e7..c4545e9b483 100644
@@ -110,8 +110,9 @@ static int initr_reloc(void)
  */
 static int initr_caches(void)
 {
-	/* Enable caches */
-	enable_caches();
+	if (ll_boot_init())
+		enable_caches();
+
 	return 0;
 }
 #endif
Signature · 1 line
2.43.0
#22 lore raw

PATCH v3 17/29 efi: arm: Implement access to global_data for EFI

In reply to Simon Glass

The EFI app likes to use a simple variable for global data. Implement this for ARM (for use only with 64-bit ARM at present).

---

(no changes since v2)

Changes in v2:
- Mention '64-bit ARM' here, rather than just 'ARM'

 arch/arm/include/asm/global_data.h | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
arch/arm/include/asm/global_data.h +12 -2
index 6e4471662a3..8d51111f095 100644
@@ -115,7 +115,13 @@ struct arch_global_data {
 
 #include <asm-generic/global_data.h>
 
-#if defined(__clang__) || defined(LTO_ENABLE)
+#ifdef CONFIG_EFI_APP
+
+#define DECLARE_GLOBAL_DATA_PTR   extern struct global_data *global_data_ptr
+
+#define gd global_data_ptr
+
+#elif defined(__clang__) || defined(LTO_ENABLE)
 
 #define DECLARE_GLOBAL_DATA_PTR
 #define gd	get_gd()
@@ -144,7 +150,11 @@ static inline gd_t *get_gd(void)
 
 static inline void set_gd(volatile gd_t *gd_ptr)
 {
-#ifdef CONFIG_ARM64
+#ifdef CONFIG_EFI_APP
+	extern struct global_data *global_data_ptr;
+
+	global_data_ptr = (void *)gd_ptr;
+#elif defined CONFIG_ARM64
 	__asm__ volatile("ldr x18, %0\n" : : "m"(gd_ptr));
 #elif __ARM_ARCH >= 7
 	__asm__ volatile("ldr r9, %0\n" : : "m"(gd_ptr));
Signature · 1 line
2.43.0
Reviewed-by on v3 17/29
#23 lore raw

Re: [PATCH v3 17/29] efi: arm: Implement access to global_data for EFI

Quoted 4 lines · Simon Glass

The EFI app likes to use a simple variable for global data. Implement this for ARM (for use only with 64-bit ARM at present).

Signature · 1 line
Tom
#24 lore raw

PATCH v3 18/29 efi: arm: Omit the ARM start-up code in the EFI app

In reply to Simon Glass

This code is not used with the EFI app, since it enters through a call to efi_main(). Remove start.S and crt files from the build.

---

(no changes since v1)

 arch/arm/Makefile     | 2 ++
 arch/arm/lib/Makefile | 6 ++++--
 2 files changed, 6 insertions(+), 2 deletions(-)
arch/arm/Makefile +2 -0
index cb87a684754..2e569b330d0 100644
@@ -104,7 +104,9 @@ PLATFORM_CPPFLAGS += $(patsubst %,-I$(srctree)/%include,$(machdirs))
 
 libs-y += $(machdirs)
 
+ifndef CONFIG_EFI_APP
 head-y := arch/arm/cpu/$(CPU)/start.o
+endif
 
 ifeq ($(CONFIG_XPL_BUILD),y)
 ifeq ($(CONFIG_SYS_SOC)$(CONFIG_SPL_FRAMEWORK),"mxs")
arch/arm/lib/Makefile +4 -2
index 14e3990925a..9500ba6fddc 100644
@@ -7,19 +7,21 @@ lib-$(CONFIG_USE_PRIVATE_LIBGCC) += ashldi3.o ashrdi3.o lshrdi3.o \
 				    lib1funcs.o uldivmod.o div0.o \
 				    div64.o muldi3.o
 
+ifndef CONFIG_EFI_APP
 ifdef CONFIG_CPU_V7M
 obj-y	+= vectors_m.o crt0.o
 else ifdef CONFIG_ARM64
 obj-y	+= crt0_64.o
 else
 obj-y	+= vectors.o crt0.o
-endif
+endif  #  CPU type
 
 ifdef CONFIG_ARM64
 obj-y   += setjmp_aarch64.o
 else
 obj-y   += setjmp.o
-endif
+endif  # ARM64
+endif  # CONFIG_EFI_APP
 
 ifndef CONFIG_XPL_BUILD
 ifdef CONFIG_ARM64
Signature · 1 line
2.43.0
#25 lore raw

PATCH v3 19/29 efi: arm: Drop exception-level code when running as EFI app

In reply to Simon Glass

The switch_to_non_secure_mode() function cannot be used since EFI is in charge of managing exception-levels.

Build just the exceptions.S file.

Modify the existing SPL rule to cater to the EFI app too.

---

Changes in v3:
- Rewrite the commit message

 arch/arm/cpu/armv8/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/cpu/armv8/Makefile +1 -1
index 2e71ff2dc97..7bd6cf21b19 100644
@@ -13,7 +13,7 @@ ifndef CONFIG_$(XPL_)SYS_DCACHE_OFF
 obj-y	+= cache_v8.o
 obj-y	+= cache.o
 endif
-ifdef CONFIG_XPL_BUILD
+ifneq ($(CONFIG_XPL_BUILD)$(CONFIG_EFI_APP),)
 obj-$(CONFIG_ARMV8_SPL_EXCEPTION_VECTORS) += exceptions.o
 else
 obj-y	+= exceptions.o
Signature · 1 line
2.43.0
#26 lore raw

Re: [PATCH v3 19/29] efi: arm: Drop exception-level code when running as EFI app

Quoted 21 lines · Simon Glass

The switch_to_non_secure_mode() function cannot be used since EFI is in charge of managing exception-levels.

Build just the exceptions.S file.

Modify the existing SPL rule to cater to the EFI app too.

---

Changes in v3:
- Rewrite the commit message

 arch/arm/cpu/armv8/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/cpu/armv8/Makefile +0 -0
index 2e71ff2dc97..7bd6cf21b19 100644

arch/arm/cpu/armv8/Makefile ifndef CONFIG_$(XPL_)SYS_DCACHE_OFF · line 19

Quoted 8 lines
arch/arm/cpu/armv8/Makefile +1 -1
@@ -13,7 +13,7 @@ ifndef CONFIG_$(XPL_)SYS_DCACHE_OFF
 obj-y	+= cache_v8.o
 obj-y	+= cache.o
 endif
-ifdef CONFIG_XPL_BUILD
+ifneq ($(CONFIG_XPL_BUILD)$(CONFIG_EFI_APP),)
 obj-$(CONFIG_ARMV8_SPL_EXCEPTION_VECTORS) += exceptions.o
 else
 obj-y	+= exceptions.o

Yes, this is still confusing and needs to be tidied up, please just file an issue and I'll pick it up.

Signature · 1 line
Tom
#27 lore raw

PATCH v3 20/29 efi: arm: x86: Allow use of the EFI table in the app

In reply to Simon Glass

It isn't worth the hassle of omitting this field for the app, since code is shared between the payload and the app. Adjust the condition to avoid a build error in the 'efi' command with the app on 64-bit ARM.

---

(no changes since v2)

Changes in v2:
- Document the x86 field better and add a comment for ARM too
- Mention '64-bit ARM' here, rather than just 'ARM'

 arch/arm/include/asm/global_data.h | 4 ++--
 arch/x86/include/asm/global_data.h | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
arch/arm/include/asm/global_data.h +2 -2
index 8d51111f095..ba12da6204e 100644
@@ -108,8 +108,8 @@ struct arch_global_data {
 #ifdef CONFIG_SMBIOS
 	ulong smbios_start;		/* Start address of SMBIOS table */
 #endif
-#ifdef CONFIG_EFI_STUB
-	ulong table;
+#ifdef CONFIG_EFI
+	ulong table;	/* holds the table address from previous EFI firmware */
 #endif
 };
 
arch/x86/include/asm/global_data.h +1 -1
index 1bd1fa92078..0d9fa823121 100644
@@ -110,7 +110,7 @@ struct arch_global_data {
 	int has_mtrr;
 	/* MRC training data */
 	struct mrc_output mrc[MRC_TYPE_COUNT];
-	ulong table;			/* Table pointer from previous loader */
+	ulong table;	/* coreboot/EFI table address from previous loader */
 	int turbo_state;		/* Current turbo state */
 	struct irq_routing_table *pirq_routing_table;
 	int dw_i2c_num_cards;		/* Used by designware i2c driver */
Signature · 1 line
2.43.0
#28 lore raw

PATCH v3 21/29 efi: arm: Disable --gc-sections for the app

In reply to Simon Glass

This option cannot be used with a shared library, since it results in everything being removed. Disable it.

---

(no changes since v1)

 arch/arm/config.mk | 2 ++
 1 file changed, 2 insertions(+)
arch/arm/config.mk +2 -0
index e0045e22271..20f4d41f2c3 100644
@@ -14,8 +14,10 @@ CFLAGS_NON_EFI := -fno-pic $(FIXED_REG) -ffunction-sections -fdata-sections \
 CFLAGS_EFI := -fpic -fshort-wchar
 
 ifneq ($(LTO_ENABLE)$(CONFIG_USE_PRIVATE_LIBGCC),yy)
+ifndef CONFIG_EFI_APP
 LDFLAGS_FINAL += --gc-sections
 endif
+endif
 
 ifneq ($(LTO_ENABLE),y)
 PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections
Signature · 1 line
2.43.0
#29 lore raw

PATCH v3 22/29 efi: arm: Drop startup code from the app

In reply to Simon Glass

The EFI app uses different startup and relocation code and the existing code uses symbols not present in the app. Drop it.

---

(no changes since v1)

 arch/arm/cpu/armv8/Makefile | 2 ++
 arch/arm/lib/Makefile       | 4 +++-
 2 files changed, 5 insertions(+), 1 deletion(-)
arch/arm/cpu/armv8/Makefile +2 -0
index 7bd6cf21b19..a8f5de58cc4 100644
@@ -3,7 +3,9 @@
 # (C) Copyright 2000-2003
 # Wolfgang Denk, DENX Software Engineering, [email protected].
 
+ifndef CONFIG_EFI_APP
 extra-y	:= start.o
+endif
 
 obj-y	+= cpu.o
 ifndef CONFIG_$(PHASE_)TIMER
arch/arm/lib/Makefile +3 -1
index 9500ba6fddc..a41566c816d 100644
@@ -24,11 +24,13 @@ endif  # ARM64
 endif  # CONFIG_EFI_APP
 
 ifndef CONFIG_XPL_BUILD
+ifndef CONFIG_EFI_APP
 ifdef CONFIG_ARM64
 obj-y	+= relocate_64.o
 else
 obj-y	+= relocate.o
-endif
+endif  # ARM64
+endif  # EFI_APP
 
 obj-$(CONFIG_CPU_V7M) += cmd_boot.o
 obj-$(CONFIG_OF_LIBFDT) += bootm-fdt.o
Signature · 1 line
2.43.0
#30 lore raw

PATCH v3 23/29 efi: arm: Adjust how the monitor length is calculated

In reply to Simon Glass

Adjust the conditions to support the EFI app when running on ARM.

---

(no changes since v2)

Changes in v2:
- Put the EFI-app case first in setup_mon_len(), for clarity

 common/board_f.c | 6 +++---
 common/board_r.c | 4 +++-
 2 files changed, 6 insertions(+), 4 deletions(-)
common/board_f.c +3 -3
index 8baaa2341a3..5b9203fec18 100644
@@ -261,7 +261,9 @@ static int init_func_i2c(void)
 
 static int setup_mon_len(void)
 {
-#if defined(CONFIG_ARCH_NEXELL)
+#if defined(CONFIG_EFI_APP)
+	gd->mon_len = (ulong)_end - (ulong)image_base;
+#elif defined(CONFIG_ARCH_NEXELL)
 	gd->mon_len = (ulong)__bss_end - (ulong)__image_copy_start;
 #elif defined(__ARM__) || defined(__MICROBLAZE__)
 	gd->mon_len = (ulong)__bss_end - (ulong)_start;
@@ -270,8 +272,6 @@ static int setup_mon_len(void)
 #elif defined(CONFIG_SANDBOX)
 	/* gcc does not provide _init in crti.o on RISC-V */
 	gd->mon_len = 0;
-#elif defined(CONFIG_EFI_APP)
-	gd->mon_len = (ulong)_end - (ulong)_init;
 #elif defined(CONFIG_NIOS2) || defined(CONFIG_XTENSA)
 	gd->mon_len = CONFIG_SYS_MONITOR_LEN;
 #elif defined(CONFIG_SH) || defined(CONFIG_RISCV)
common/board_r.c +3 -1
index c4545e9b483..3fa2d44402e 100644
@@ -124,7 +124,9 @@ __weak int fixup_cpu(void)
 
 static int initr_reloc_global_data(void)
 {
-#ifdef __ARM__
+#if defined(CONFIG_EFI_APP)
+	monitor_flash_len = (ulong)_end - (ulong)image_base;
+#elif defined __ARM__
 	monitor_flash_len = _end - __image_copy_start;
 #elif defined(CONFIG_RISCV)
 	monitor_flash_len = (ulong)_end - (ulong)_start;
Signature · 1 line
2.43.0
#32 lore raw

PATCH v3 24/29 efi: arm: Provide startup and relocation code

In reply to Simon Glass

Build in the EFI-app startup code as well as the code to relocate U-Boot to the loaded position, since this is under the control of the previous firmware.

---

(no changes since v1)

 arch/arm/lib/Makefile | 2 ++
 1 file changed, 2 insertions(+)
arch/arm/lib/Makefile +2 -0
index a41566c816d..a2b8ef96ff5 100644
@@ -32,6 +32,8 @@ obj-y	+= relocate.o
 endif  # ARM64
 endif  # EFI_APP
 
+obj-$(CONFIG_EFI_APP) += $(EFI_CRT0) $(EFI_RELOC)
+
 obj-$(CONFIG_CPU_V7M) += cmd_boot.o
 obj-$(CONFIG_OF_LIBFDT) += bootm-fdt.o
 obj-$(CONFIG_CMD_BOOTI) += bootm.o image.o
Signature · 1 line
2.43.0
#33 lore raw

PATCH v3 25/29 efi: Generate the app as a shared library

In reply to Simon Glass

The app should be built as a shared library, with position-independent code and the -shared flags. Update the Makefile to handle this.

---

(no changes since v1)

 Makefile | 4 ++++
 1 file changed, 4 insertions(+)
Makefile +4 -0
index f989c31073f..b3b13e29c26 100644
@@ -452,9 +452,13 @@ KBUILD_CFLAGS += $(call cc-option, -no-integrated-as)
 KBUILD_AFLAGS += $(call cc-option, -no-integrated-as)
 endif
 
+ifdef CONFIG_EFI_APP
+KBUILD_CFLAGS += -shared
+else
 # Don't generate position independent code
 KBUILD_CFLAGS	+= $(call cc-option,-fno-PIE)
 KBUILD_AFLAGS	+= $(call cc-option,-fno-PIE)
+endif
 
 # Read UBOOTRELEASE from include/config/uboot.release (if it exists)
 UBOOTRELEASE = $(shell cat include/config/uboot.release 2> /dev/null)
Signature · 1 line
2.43.0
#34 lore raw

PATCH v3 26/29 efi: arm: Disable STATIC_RELA for the EFI app

In reply to Simon Glass

This feature should not be used with the app, since we don't know where U-Boot will be loaded. Disable it.

---

(no changes since v1)

 arch/arm/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/Kconfig +1 -1
index a55ba6b7f09..fc8870c19be 100644
@@ -142,7 +142,7 @@ config GICV3_SUPPORT_GIC600
 
 config STATIC_RELA
 	bool
-	default y if ARM64
+	default y if ARM64 && !EFI_APP
 
 config DMA_ADDR_T_64BIT
 	bool
Signature · 1 line
2.43.0