CONFIG_REMAKE_ELF's u-boot.elf link step used the toolchain's
default page-size flags, and its .lds carried no 4K alignment
padding, so TME's IMGAUTH rejected the image for misaligned
segments.

Add a REMAKE_ELF_LDSCRIPT default for ARCH_SNAPDRAGON pointing at a
Snapdragon-specific .lds that pads .data to a 4K boundary, so this
applies to any Snapdragon board using CONFIG_REMAKE_ELF, not just
nord.

Signed-off-by: Aswin Murugan <[email protected]>
---
 Kconfig                                         |  8 ++++++++
 Makefile                                        |  5 +++++
 arch/arm/mach-snapdragon/Kconfig                |  3 +++
 .../mach-snapdragon/u-boot-elf-snapdragon.lds   | 17 +++++++++++++++++
 4 files changed, 33 insertions(+)
 create mode 100644 arch/arm/mach-snapdragon/u-boot-elf-snapdragon.lds

diff --git a/Kconfig b/Kconfig
index c8cfbf5d5de..b169c83728a 100644
--- a/Kconfig
+++ b/Kconfig
@@ -559,6 +559,14 @@ config REMAKE_ELF
          U-Boot binary (u-boot.bin), which may already have been statically
          relocated and may already have a device-tree appended to it.
 
+config REMAKE_ELF_LDSCRIPT
+       string "Linker script for u-boot.elf"
+       depends on REMAKE_ELF
+       default "arch/u-boot-elf.lds"
+       help
+         This allows specifying a linker script that will be used to
+         re-wrap the U-Boot binary into an ELF.
+
 config BUILD_TARGET
        string "Build target special images"
        default "u-boot-elf.shdr" if RCAR_64 && RCAR_64_RSIP
diff --git a/Makefile b/Makefile
index c6709ff09bb..86a4176c5d7 100644
--- a/Makefile
+++ b/Makefile
@@ -2026,6 +2026,11 @@ spl/u-boot-spl-elf.lds: $(SPL_REMAKE_ELF_LDSCRIPT) 
prepare FORCE
 u-boot-elf.lds: arch/u-boot-elf.lds prepare FORCE
        $(call if_changed_dep,cpp_lds)
 
+REMAKE_ELF_LDSCRIPT := $(addprefix 
$(srctree)/,$(CONFIG_REMAKE_ELF_LDSCRIPT:"%"=%))
+
+u-boot-elf.lds: $(REMAKE_ELF_LDSCRIPT) prepare FORCE
+       $(call if_changed_dep,cpp_lds)
+
 PHONY += prepare0
 # MediaTek's ARM-based u-boot needs a header to contains its load address
 # which is parsed by the BootROM.
diff --git a/arch/arm/mach-snapdragon/Kconfig b/arch/arm/mach-snapdragon/Kconfig
index 98b6655385e..08c100d0b85 100644
--- a/arch/arm/mach-snapdragon/Kconfig
+++ b/arch/arm/mach-snapdragon/Kconfig
@@ -26,6 +26,9 @@ config SYS_MALLOC_LEN
 config LNX_KRNL_IMG_TEXT_OFFSET_BASE
        default 0x80000000
 
+config REMAKE_ELF_LDSCRIPT
+       default "arch/arm/mach-snapdragon/u-boot-elf-snapdragon.lds"
+
 config SPL_SHARES_INIT_SP_ADDR
        # override the default from common/spl/Kconfig
        default n
diff --git a/arch/arm/mach-snapdragon/u-boot-elf-snapdragon.lds 
b/arch/arm/mach-snapdragon/u-boot-elf-snapdragon.lds
new file mode 100644
index 00000000000..fe29e175b2d
--- /dev/null
+++ b/arch/arm/mach-snapdragon/u-boot-elf-snapdragon.lds
@@ -0,0 +1,17 @@
+ENTRY(CONFIG_PLATFORM_ELFENTRY)
+SECTIONS
+{
+       . = CONFIG_PLATFORM_ELFENTRY;
+
+       .data : {
+               *(.data*)
+               /*
+                * Pad the LOAD segment out to a 4K boundary. TME's IMGAUTH
+                * checks not just p_align/p_offset but that p_filesz itself
+                * is a multiple of 4K (it hashes/verifies in fixed 4K
+                * blocks) - the raw u-boot.bin blob wrapped in here is not
+                * page-sized on its own.
+                */
+               . = ALIGN(0x1000);
+       }
+}
-- 
2.34.1

Reply via email to