[U-Boot] [RFC 1/1] efi_loader: support building UEFI binaries on sandbox
Heinrich Schuchardt
xypron.glpk at gmx.de
Thu Nov 7 23:29:01 UTC 2019
On the sandbox the UEFI binaries must match the host architectures.
Adjust the Makefiles. Provide the PE/COFF header and relocation files.
Allow building helloworld.efi on the sandbox.
Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
---
include/host_arch.h provokes some false positives in checkpatch.pl as this
include is also meant to be used in Makefile.
---
Makefile | 19 +++++++++++++++++
arch/sandbox/config.mk | 28 ++++++++++++++++++++++++
arch/sandbox/lib/crt0_sandbox_efi.S | 32 ++++++++++++++++++++++++++++
arch/sandbox/lib/reloc_sandbox_efi.c | 32 ++++++++++++++++++++++++++++
cmd/Kconfig | 2 +-
include/host_arch.h | 24 +++++++++++++++++++++
lib/efi_loader/Makefile | 3 +++
7 files changed, 139 insertions(+), 1 deletion(-)
create mode 100644 arch/sandbox/lib/crt0_sandbox_efi.S
create mode 100644 arch/sandbox/lib/reloc_sandbox_efi.c
create mode 100644 include/host_arch.h
diff --git a/Makefile b/Makefile
index a94b538e4a..41fdbfdfce 100644
--- a/Makefile
+++ b/Makefile
@@ -17,6 +17,25 @@ NAME =
# o Look for make include files relative to root of kernel src
MAKEFLAGS += -rR --include-dir=$(CURDIR)
+# Determine host architecture
+include include/host_arch.h
+MK_ARCH="${shell uname -m}"
+unexport HOST_ARCH
+ifeq ("x86_64", $(MK_ARCH))
+ export HOST_ARCH=$(HOST_ARCH_X86_64)
+else ifneq (,$(findstring $(MK_ARCH), "i386" "i486" "i586" "i686"))
+ export HOST_ARCH=$(HOST_ARCH_X86)
+else ifneq (,$(findstring $(MK_ARCH), "aarch64" "armv8l"))
+ export HOST_ARCH=$(HOST_ARCH_AARCH64)
+else ifeq ("armv7l", $(MK_ARCH))
+ export HOST_ARCH=$(HOST_ARCH_ARM)
+else ifeq ("riscv32", $(MK_ARCH))
+ export HOST_ARCH=$(HOST_ARCH_RISCV32)
+else ifeq ("riscv64", $(MK_ARCH))
+ export HOST_ARCH=$(HOST_ARCH_RISCV64)
+endif
+undefine MK_ARCH
+
# Avoid funny character set dependencies
unexport LC_ALL
LC_COLLATE=C
diff --git a/arch/sandbox/config.mk b/arch/sandbox/config.mk
index 05fbbd7bcc..a225c9cbfa 100644
--- a/arch/sandbox/config.mk
+++ b/arch/sandbox/config.mk
@@ -27,3 +27,31 @@ cmd_u-boot-spl = (cd $(obj) && $(CC) -o $(SPL_BIN) -Wl,-T u-boot-spl.lds \
$(PLATFORM_LIBS) -Wl,-Map -Wl,u-boot-spl.map -Wl,--gc-sections)
CONFIG_ARCH_DEVICE_TREE := sandbox
+
+ifeq ($(HOST_ARCH),$(HOST_ARCH_X86_64))
+EFI_LDS := ${SRCDIR}/../../../arch/x86/lib/elf_x86_64_efi.lds
+EFI_TARGET := --target=efi-app-x86_64
+else ifeq ($(HOST_ARCH),$(HOST_ARCH_X86))
+EFI_LDS := ${SRCDIR}/../../../arch/x86/lib/elf_ia32_efi.lds
+EFI_TARGET := --target=efi-app-ia32
+else ifeq ($(HOST_ARCH),$(HOST_ARCH_AARCH64))
+EFI_LDS := ${SRCDIR}/../../../arch/arm/lib/elf_aarch64_efi.lds
+OBJCOPYFLAGS += -j .text -j .secure_text -j .secure_data -j .rodata -j .data \
+ -j .u_boot_list -j .rela.dyn -j .got -j .got.plt \
+ -j .binman_sym_table -j .text_rest \
+ -j .efi_runtime -j .efi_runtime_rel
+else ifeq ($(HOST_ARCH),$(HOST_ARCH_ARM))
+EFI_LDS := ${SRCDIR}/../../../arch/arm/lib/elf_arm_efi.lds
+OBJCOPYFLAGS += -j .text -j .secure_text -j .secure_data -j .rodata -j .hash \
+ -j .data -j .got -j .got.plt -j .u_boot_list -j .rel.dyn \
+ -j .binman_sym_table -j .text_rest \
+ -j .efi_runtime -j .efi_runtime_rel
+else ifeq ($(HOST_ARCH),$(HOST_ARCH_RISCV32))
+EFI_LDS := ${SRCDIR}/../../../arch/riscv/lib/elf_riscv32_efi.lds
+else ifeq ($(HOST_ARCH),$(HOST_ARCH_RISCV64))
+EFI_LDS := ${SRCDIR}/../../../arch/riscv/lib/elf_riscv64_efi.lds
+endif
+EFI_CRT0 := crt0_sandbox_efi.o
+EFI_RELOC := reloc_sandbox_efi.o
+AFLAGS_crt0_sandbox_efi.o += -DHOST_ARCH="$(HOST_ARCH)"
+CFLAGS_reloc_sandbox_efi.o += -DHOST_ARCH="$(HOST_ARCH)"
diff --git a/arch/sandbox/lib/crt0_sandbox_efi.S b/arch/sandbox/lib/crt0_sandbox_efi.S
new file mode 100644
index 0000000000..b15766c514
--- /dev/null
+++ b/arch/sandbox/lib/crt0_sandbox_efi.S
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * PE/COFF header for EFI applications
+ *
+ * Copyright (c) 2019 Heinrich Schuchardt
+ */
+
+#include <host_arch.h>
+
+#if HOST_ARCH == HOST_ARCH_X86_64
+#include "../../../arch/x86/lib/crt0_x86_64_efi.S"
+#endif
+
+#if HOST_ARCH == HOST_ARCH_X86
+#include "../../../arch/x86/lib/crt0_ia32_efi.S"
+#endif
+
+#if HOST_ARCH == HOST_ARCH_AARCH64
+#include "../../../arch/arm/lib/crt0_aarch64_efi.S"
+#endif
+
+#if HOST_ARCH == HOST_ARCH_ARM
+#include "../../../arch/arm/lib/crt0_arm_efi.S"
+#endif
+
+#if HOST_ARCH == HOST_ARCH_RISCV32
+#include "../../../arch/riscv/lib/crt0_riscv_efi.S"
+#endif
+
+#if HOST_ARCH == HOST_ARCH_RISCV64
+#include "../../../arch/riscv/lib/crt0_riscv_efi.S"
+#endif
diff --git a/arch/sandbox/lib/reloc_sandbox_efi.c b/arch/sandbox/lib/reloc_sandbox_efi.c
new file mode 100644
index 0000000000..a21e6757c5
--- /dev/null
+++ b/arch/sandbox/lib/reloc_sandbox_efi.c
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * position independent shared object relocator
+ *
+ * Copyright (c) 2019 Heinrich Schuchardt
+ */
+
+#include <host_arch.h>
+
+#if HOST_ARCH == HOST_ARCH_X86_64
+#include "../../../arch/x86/lib/reloc_x86_64_efi.c"
+#endif
+
+#if HOST_ARCH == HOST_ARCH_X86
+#include "../../../arch/x86/lib/reloc_ia32_efi.c"
+#endif
+
+#if HOST_ARCH == HOST_ARCH_AARCH64
+#include "../../../arch/arm/lib/reloc_aarch64_efi.c"
+#endif
+
+#if HOST_ARCH == HOST_ARCH_ARM
+#include "../../../arch/arm/lib/reloc_arm_efi.c"
+#endif
+
+#if HOST_ARCH == HOST_ARCH_RISCV32
+#include "../../../arch/riscv/lib/reloc_riscv_efi.c"
+#endif
+
+#if HOST_ARCH == HOST_ARCH_RISCV64
+#include "../../../arch/riscv/lib/reloc_riscv_efi.c"
+#endif
diff --git a/cmd/Kconfig b/cmd/Kconfig
index c414c5d8e6..4da64e61b0 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -320,7 +320,7 @@ config BOOTM_VXWORKS
config CMD_BOOTEFI_HELLO_COMPILE
bool "Compile a standard EFI hello world binary for testing"
- depends on CMD_BOOTEFI && !CPU_V7M && !SANDBOX
+ depends on CMD_BOOTEFI && !CPU_V7M
default y
help
This compiles a standard EFI hello world application with U-Boot so
diff --git a/include/host_arch.h b/include/host_arch.h
new file mode 100644
index 0000000000..169d494513
--- /dev/null
+++ b/include/host_arch.h
@@ -0,0 +1,24 @@
+#if 0
+# SPDX SPDX-License-Identifier: GPL-2.0+
+#
+# Constants defining the host architecture in assembler, C, and make files.
+# The values are arbitrary.
+#
+# Copyright 2019 Heinrich Schuchardt <xypron.glpk at gmx.de>
+#endif
+
+#if 0
+export HOST_ARCH_AARCH64=0xaa64
+export HOST_ARCH_ARM=0x00a7
+export HOST_ARCH_RISCV32=0x5032
+export HOST_ARCH_RISCV64=0x5064
+export HOST_ARCH_X86=0x0386
+export HOST_ARCH_X86_64=0x8664
+#endif
+
+#define HOST_ARCH_AARCH64 0xaa64
+#define HOST_ARCH_ARM 0x00a7
+#define HOST_ARCH_RISCV32 0x5032
+#define HOST_ARCH_RISCV64 0x5064
+#define HOST_ARCH_X86 0x0386
+#define HOST_ARCH_X86_64 0x8664
diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
index 01769ea58b..7db4060286 100644
--- a/lib/efi_loader/Makefile
+++ b/lib/efi_loader/Makefile
@@ -6,6 +6,9 @@
# This file only gets included with CONFIG_EFI_LOADER set, so all
# object inclusion implicitly depends on it
+asflags-y += -DHOST_ARCH="$(HOST_ARCH)"
+ccflags-y += -DHOST_ARCH="$(HOST_ARCH)"
+
CFLAGS_efi_boottime.o += \
-DFW_VERSION="0x$(VERSION)" \
-DFW_PATCHLEVEL="0x$(PATCHLEVEL)"
--
2.24.0.rc1
More information about the U-Boot
mailing list