[PATCH v2 01/10] Makefile: add SPL_REMAKE_ELF_LDSCRIPT feature
michael.srba at seznam.cz
michael.srba at seznam.cz
Sat Apr 11 02:00:06 CEST 2026
From: Michael Srba <Michael.Srba at seznam.cz>
On some platforms (at least Qualcomm), the bootrom expects an ELF file.
Since the contents of the ELF file are platform specific, add a config
option that allows specifying a linker script to use to produce the
ELF file.
Signed-off-by: Michael Srba <Michael.Srba at seznam.cz>
---
Makefile | 28 ++++++++++++++++++++++++++++
common/spl/Kconfig | 9 +++++++++
2 files changed, 37 insertions(+)
diff --git a/Makefile b/Makefile
index 8af18668b0f..754ca4d67e2 100644
--- a/Makefile
+++ b/Makefile
@@ -1232,6 +1232,9 @@ INPUTS-$(CONFIG_SPL) += $(CONFIG_SPL_TARGET:"%"=%)
endif
INPUTS-$(CONFIG_REMAKE_ELF) += u-boot.elf
INPUTS-$(CONFIG_SPL_REMAKE_ELF) += spl/u-boot-spl.elf
+ifneq ($(CONFIG_SPL_REMAKE_ELF_LDSCRIPT),)
+INPUTS-y += spl/u-boot-spl.elf
+endif
INPUTS-$(CONFIG_EFI_APP) += u-boot-app.efi
INPUTS-$(CONFIG_EFI_STUB) += u-boot-payload.efi
@@ -2001,6 +2004,8 @@ u-boot.elf: u-boot.bin u-boot-elf.lds FORCE
$(Q)$(OBJCOPY) -I binary $(PLATFORM_ELFFLAGS) $< u-boot-elf.o
$(call if_changed,u-boot-elf)
+ifeq ($(CONFIG_SPL_REMAKE_ELF_LDSCRIPT),)
+
quiet_cmd_u-boot-spl-elf ?= LD $@
cmd_u-boot-spl-elf ?= $(LD) spl/u-boot-spl-elf.o -o $@ \
$(if $(CONFIG_SYS_BIG_ENDIAN),-EB,-EL) \
@@ -2010,10 +2015,33 @@ spl/u-boot-spl.elf: spl/u-boot-spl.bin u-boot-elf.lds
$(Q)$(OBJCOPY) -I binary $(PLATFORM_ELFFLAGS) $< spl/u-boot-spl-elf.o
$(call if_changed,u-boot-spl-elf)
+endif
+
u-boot-elf.lds: arch/u-boot-elf.lds prepare FORCE
$(call if_changed_dep,cpp_lds)
PHONY += prepare0
+
+ifeq ($(CONFIG_SPL),y)
+ifneq ($(CONFIG_SPL_REMAKE_ELF_LDSCRIPT),)
+
+SPL_REMAKE_ELF_LDSCRIPT := $(addprefix $(srctree)/,$(CONFIG_SPL_REMAKE_ELF_LDSCRIPT:"%"=%))
+
+spl/u-boot-spl-elf.lds: $(SPL_REMAKE_ELF_LDSCRIPT) FORCE
+ $(call if_changed_dep,cpp_lds)
+
+quiet_cmd_u-boot-spl-elf ?= LD $@
+ cmd_u-boot-spl-elf ?= $(LD) spl/u-boot-spl-elf.o -o $@ \
+ $(if $(CONFIG_SYS_BIG_ENDIAN),-EB,-EL) \
+ -T spl/u-boot-spl-elf.lds --defsym=$(CONFIG_PLATFORM_ELFENTRY)=$(CONFIG_SPL_TEXT_BASE) \
+ -Ttext=$(CONFIG_SPL_TEXT_BASE) -z max-page-size=0x1000
+spl/u-boot-spl.elf: spl/u-boot-spl.bin spl/u-boot-spl-elf.lds
+ $(Q)$(OBJCOPY) -I binary $(PLATFORM_ELFFLAGS) $< spl/u-boot-spl-elf.o
+ $(call if_changed,u-boot-spl-elf)
+
+endif
+endif
+
# MediaTek's ARM-based u-boot needs a header to contains its load address
# which is parsed by the BootROM.
# If the SPL build is enabled, the header will be added to the spl binary,
diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index d1a85f50209..f8981cb4fe5 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -247,6 +247,15 @@ config SPL_HANDOFF
proper. Also SPL can receive information from TPL in the same place
if that is enabled.
+config SPL_REMAKE_ELF_LDSCRIPT
+ string "Linker script to run with u-boot-spl.bin as input"
+ depends on !SPL_REMAKE_ELF
+ help
+ This allows specifying a linker script that will act on u-boot-spl.bin.
+ Some platforms (e.g Qualcomm) use the ELF format in creative ways,
+ including in the bootrom. Unlike SPL_REMAKE_ELF which uses a standard
+ linker script, this allows specifying a platorm-specific one.
+
config SPL_LDSCRIPT
string "Linker script for the SPL stage"
default "arch/arm/cpu/arm926ejs/sunxi/u-boot-spl.lds" if MACH_SUNIV
--
2.53.0
More information about the U-Boot
mailing list