[PATCH 06/13] armv8: Big Endian enablement for compiler and linker

Jiaxun Yang jiaxun.yang at flygoat.com
Sun May 19 14:56:51 CEST 2024


Pass flags to compilers and linkers, also modify linker
scripts to set correct output format.

Signed-off-by: Jiaxun Yang <jiaxun.yang at flygoat.com>
---
 arch/arm/config.mk                | 14 ++++++++++++++
 arch/arm/cpu/armv8/u-boot-spl.lds |  6 ++++++
 arch/arm/cpu/armv8/u-boot.lds     |  4 ++++
 arch/arm/lib/elf_aarch64_efi.lds  |  7 +++++++
 scripts/Makefile.lib              |  3 ++-
 5 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/arch/arm/config.mk b/arch/arm/config.mk
index 5530d02b66c4..b3f70c1fe9db 100644
--- a/arch/arm/config.mk
+++ b/arch/arm/config.mk
@@ -34,11 +34,25 @@ PLATFORM_RELFLAGS	+= $(LLVM_RELFLAGS)
 PLATFORM_CPPFLAGS += -D__ARM__
 
 ifdef CONFIG_ARM64
+ifdef CONFIG_SYS_BIG_ENDIAN
+PLATFORM_ELFFLAGS += -B aarch64 -O elf64-bigaarch64
+else
 PLATFORM_ELFFLAGS += -B aarch64 -O elf64-littleaarch64
+endif
 else
 PLATFORM_ELFFLAGS += -B arm -O elf32-littlearm
 endif
 
+ifdef CONFIG_SYS_LITTLE_ENDIAN
+KBUILD_LDFLAGS += -EL
+PLATFORM_CPPFLAGS += -mlittle-endian
+endif
+
+ifdef CONFIG_SYS_BIG_ENDIAN
+KBUILD_LDFLAGS += -EB
+PLATFORM_CPPFLAGS += -mbig-endian
+endif
+
 # Choose between ARM/Thumb instruction sets
 ifeq ($(CONFIG_$(SPL_)SYS_THUMB_BUILD),y)
 AFLAGS_IMPLICIT_IT	:= $(call as-option,-Wa$(comma)-mimplicit-it=always)
diff --git a/arch/arm/cpu/armv8/u-boot-spl.lds b/arch/arm/cpu/armv8/u-boot-spl.lds
index ef8af67e11c3..1848c501c234 100644
--- a/arch/arm/cpu/armv8/u-boot-spl.lds
+++ b/arch/arm/cpu/armv8/u-boot-spl.lds
@@ -11,12 +11,18 @@
  *	Aneesh V <aneesh at ti.com>
  */
 
+#include <config.h>
+
 MEMORY { .sram : ORIGIN = IMAGE_TEXT_BASE,
 		LENGTH = IMAGE_MAX_SIZE }
 MEMORY { .sdram : ORIGIN = CONFIG_SPL_BSS_START_ADDR,
 		LENGTH = CONFIG_SPL_BSS_MAX_SIZE }
 
+#if CONFIG_IS_ENABLED(SYS_BIG_ENDIAN)
+OUTPUT_FORMAT("elf64-bigaarch64", "elf64-bigaarch64", "elf64-bigaarch64")
+#else
 OUTPUT_FORMAT("elf64-littleaarch64", "elf64-littleaarch64", "elf64-littleaarch64")
+#endif
 OUTPUT_ARCH(aarch64)
 ENTRY(_start)
 SECTIONS
diff --git a/arch/arm/cpu/armv8/u-boot.lds b/arch/arm/cpu/armv8/u-boot.lds
index 857f44412e07..f357e5468e27 100644
--- a/arch/arm/cpu/armv8/u-boot.lds
+++ b/arch/arm/cpu/armv8/u-boot.lds
@@ -10,7 +10,11 @@
 #include <config.h>
 #include <asm/psci.h>
 
+#if CONFIG_IS_ENABLED(SYS_BIG_ENDIAN)
+OUTPUT_FORMAT("elf64-bigaarch64", "elf64-bigaarch64", "elf64-bigaarch64")
+#else
 OUTPUT_FORMAT("elf64-littleaarch64", "elf64-littleaarch64", "elf64-littleaarch64")
+#endif
 OUTPUT_ARCH(aarch64)
 ENTRY(_start)
 SECTIONS
diff --git a/arch/arm/lib/elf_aarch64_efi.lds b/arch/arm/lib/elf_aarch64_efi.lds
index 5dd98091698c..4bba305bab35 100644
--- a/arch/arm/lib/elf_aarch64_efi.lds
+++ b/arch/arm/lib/elf_aarch64_efi.lds
@@ -5,7 +5,14 @@
  * Modified from elf_aarch64_efi.lds in gnu-efi
  */
 
+#include <config.h>
+
+#if CONFIG_IS_ENABLED(SYS_BIG_ENDIAN)
+OUTPUT_FORMAT("elf64-bigaarch64", "elf64-bigaarch64", "elf64-bigaarch64")
+#else
 OUTPUT_FORMAT("elf64-littleaarch64", "elf64-littleaarch64", "elf64-littleaarch64")
+#endif
+
 OUTPUT_ARCH(aarch64)
 
 PHDRS
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 62f87517c09c..ff88cc3e55cd 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -475,7 +475,8 @@ cmd_efi_objcopy = $(OBJCOPY) -j .header -j .text -j .sdata -j .data -j \
 $(obj)/%.efi: $(obj)/%_efi.so
 	$(call cmd,efi_objcopy)
 
-KBUILD_EFILDFLAGS = -nostdlib -zexecstack -znocombreloc -znorelro
+KBUILD_EFILDFLAGS += $(if $(CONFIG_SYS_BIG_ENDIAN),-EB,-EL)
+KBUILD_EFILDFLAGS += -nostdlib -zexecstack -znocombreloc -znorelro
 KBUILD_EFILDFLAGS += $(call ld-option,--no-warn-rwx-segments)
 quiet_cmd_efi_ld = LD      $@
 cmd_efi_ld = $(LD) $(KBUILD_EFILDFLAGS) -T $(EFI_LDS_PATH) \

-- 
2.43.0



More information about the U-Boot mailing list