From 805377b1f5ae1834e2b1a07dbb6fed94672e0954 Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Sat, 15 Mar 2025 15:17:59 -0700 Subject: [PATCH 01/15] arm: Remove stray .mmutable reference in linker script The .mmutable section was deprecated in 2012 [1] and finally removed entirely from U-Boot in 2022 [2], so this special handling is no longer necessary. Remove it to tidy up the linker script. [1]: dde3b70dcf3d ("arm: add a common .lds link script") [2]: 3135ba642f9a ("arm: pxa: Remove CONFIG_CPU_PXA25X") Signed-off-by: Sam Edwards Reviewed-by: Ilias Apalodimas --- arch/arm/cpu/u-boot.lds | 9 --------- 1 file changed, 9 deletions(-) diff --git a/arch/arm/cpu/u-boot.lds b/arch/arm/cpu/u-boot.lds index 2f50087f57a..63e82a09fad 100644 --- a/arch/arm/cpu/u-boot.lds +++ b/arch/arm/cpu/u-boot.lds @@ -169,15 +169,6 @@ SECTIONS _end = .; _image_binary_end = .; - /* - * Deprecated: this MMU section is used by pxa at present but - * should not be used by new boards/CPUs. - */ - . = ALIGN(4096); - .mmutable : { - *(.mmutable) - } - /* * These sections occupy the same memory, but their lifetimes do * not overlap: U-Boot initializes .bss only after applying dynamic From 6ba839a0f5473aac8dc038f8601071234c810119 Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Sat, 15 Mar 2025 15:18:00 -0700 Subject: [PATCH 02/15] arm: Exclude eabi_compat from LTO These symbols need to survive the IR-level dead function elimination pass, since nothing at the IR level is referencing them (calls to these are inserted later, at codegen time). Signed-off-by: Sam Edwards Acked-by: Ilias Apalodimas --- arch/arm/lib/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile index 1c95dd6fed2..74cd5051552 100644 --- a/arch/arm/lib/Makefile +++ b/arch/arm/lib/Makefile @@ -92,6 +92,7 @@ obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o # For EABI conformant tool chains, provide eabi_compat() ifneq (,$(findstring -mabi=aapcs-linux,$(PLATFORM_CPPFLAGS))) extra-y += eabi_compat.o +CFLAGS_REMOVE_eabi_compat.o := $(LTO_CFLAGS) endif # some files can only build in ARM or THUMB2, not THUMB1 From 828484a7740d4ebfed8db85e4b4569cfbfe66cde Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Sat, 15 Mar 2025 15:18:01 -0700 Subject: [PATCH 03/15] arm: Add __aeabi_memclr in eabi_compat LLVM's code generator will sometimes emit calls to __aeabi_memclr. Add an implementation of this for LLVM compatibility. Signed-off-by: Sam Edwards Reviewed-by: Ilias Apalodimas --- arch/arm/lib/eabi_compat.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/arm/lib/eabi_compat.c b/arch/arm/lib/eabi_compat.c index 602efe04c04..e4190c049a3 100644 --- a/arch/arm/lib/eabi_compat.c +++ b/arch/arm/lib/eabi_compat.c @@ -37,3 +37,8 @@ void __aeabi_memset(void *dest, size_t n, int c) { (void) memset(dest, c, n); } + +void __aeabi_memclr(void *dest, size_t n) +{ + (void) memset(dest, 0, n); +} From deba40dd0ba452a3f15a359894e6b50494870d0e Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Sat, 15 Mar 2025 15:18:02 -0700 Subject: [PATCH 04/15] arm: Add aligned-memory aliases to eabi_compat These are sometimes used by LLVM's code-generator, when it can guarantee that the memory buffer being passed is aligned on a (4- or 8-byte) boundary. They can safely be aliased to the unaligned versions. Signed-off-by: Sam Edwards Reviewed-by: Ilias Apalodimas --- arch/arm/lib/eabi_compat.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/arm/lib/eabi_compat.c b/arch/arm/lib/eabi_compat.c index e4190c049a3..e6cafcc5f2b 100644 --- a/arch/arm/lib/eabi_compat.c +++ b/arch/arm/lib/eabi_compat.c @@ -33,12 +33,24 @@ void __aeabi_memcpy(void *dest, const void *src, size_t n) (void) memcpy(dest, src, n); } +void __aeabi_memcpy4(void *dest, const void *src, size_t n) __alias(__aeabi_memcpy); + +void __aeabi_memcpy8(void *dest, const void *src, size_t n) __alias(__aeabi_memcpy); + void __aeabi_memset(void *dest, size_t n, int c) { (void) memset(dest, c, n); } +void __aeabi_memset4(void *dest, size_t n, int c) __alias(__aeabi_memset); + +void __aeabi_memset8(void *dest, size_t n, int c) __alias(__aeabi_memset); + void __aeabi_memclr(void *dest, size_t n) { (void) memset(dest, 0, n); } + +void __aeabi_memclr4(void *dest, size_t n) __alias(__aeabi_memclr); + +void __aeabi_memclr8(void *dest, size_t n) __alias(__aeabi_memclr); From 16448c443c8cacba7dacb3e919c0b414f70b8a7c Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Sat, 15 Mar 2025 15:18:03 -0700 Subject: [PATCH 05/15] arm: Discard unwanted sections in linker script There are a handful of sections that are not useful in the U-Boot output binary. At present, the linker script moves these to the end of the binary, after the _image_binary_end marker symbol, so that they don't get loaded. The linker script syntax supports discarding sections that shouldn't be included in the output. Switch to this instead, to make the intention clearer and reduce the ELF sections that have to be handled later in the build. This is also consistent with the other architectures' linker scripts. Signed-off-by: Sam Edwards Reviewed-by: Ilias Apalodimas --- arch/arm/cpu/u-boot.lds | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/arch/arm/cpu/u-boot.lds b/arch/arm/cpu/u-boot.lds index 63e82a09fad..817e7a983ae 100644 --- a/arch/arm/cpu/u-boot.lds +++ b/arch/arm/cpu/u-boot.lds @@ -181,14 +181,14 @@ SECTIONS __bss_end = .; } - .dynsym _image_binary_end : { *(.dynsym) } - .dynbss : { *(.dynbss) } - .dynstr : { *(.dynstr*) } - .dynamic : { *(.dynamic*) } - .plt : { *(.plt*) } - .interp : { *(.interp*) } - .gnu.hash : { *(.gnu.hash) } - .gnu : { *(.gnu*) } - .ARM.exidx : { *(.ARM.exidx*) } - .gnu.linkonce.armexidx : { *(.gnu.linkonce.armexidx.*) } + /DISCARD/ : { *(.dynsym) } + /DISCARD/ : { *(.dynbss) } + /DISCARD/ : { *(.dynstr*) } + /DISCARD/ : { *(.dynamic*) } + /DISCARD/ : { *(.plt*) } + /DISCARD/ : { *(.interp*) } + /DISCARD/ : { *(.gnu.hash) } + /DISCARD/ : { *(.gnu*) } + /DISCARD/ : { *(.ARM.exidx*) } + /DISCARD/ : { *(.gnu.linkonce.armexidx.*) } } From d5734b183c3d578fff1c1e81e46a1d04342edffe Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Sat, 15 Mar 2025 15:18:04 -0700 Subject: [PATCH 06/15] arm: Replace 'adrl' in EFI crt0 LLVM's IAS does not (and cannot easily) support the 'adrl' pseudoinstruction, and ARM developers generally do not consider it portable across assembler implementations either. Instead, expand it into the two subtract instructions it would emit anyway. An explanation of the math follows: The .+8 and .+4 refer to the same memory location; this is because the .+4 expression occurs in a subsequent instruction, 4 bytes after the first. This memory location is the value of the PC register when it is read by the first sub instruction. Thus, both inner parenthesized expressions evaluate to the same result: PC's offset relative to image_base. The subtract instructions then remove one byte each (low, then high) of the total offset, thereby getting the absolute address of image_base loaded in r0. Signed-off-by: Sam Edwards Reviewed-by: Ilias Apalodimas --- arch/arm/lib/crt0_arm_efi.S | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm/lib/crt0_arm_efi.S b/arch/arm/lib/crt0_arm_efi.S index 91b0fe12c51..235b3a0c48f 100644 --- a/arch/arm/lib/crt0_arm_efi.S +++ b/arch/arm/lib/crt0_arm_efi.S @@ -149,7 +149,8 @@ _start: adr r1, .L_DYNAMIC ldr r0, [r1] add r1, r0, r1 - adrl r0, image_base + sub r0, pc, #((.+8-image_base) & 0xff) + sub r0, r0, #((.+4-image_base) & 0xff00) bl _relocate teq r0, #0 bne 0f From 8c39dc549b0de155c02a2b39f01dae19775f41a5 Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Sat, 15 Mar 2025 15:18:05 -0700 Subject: [PATCH 07/15] x86: Fix call64's section flags When a section is not flagged with SHF_ALLOC, LLD's --gc-sections algorithm fails to visit the sections that it references. As a result of this, LLD was dropping the call64.o(.data) section, which is itself only referenced by .text_call64. This appears to be a bug in LLD, but the .section directive for .text_call64 should really have the correct flags either way. Add `"ax"` to mark the section as ALLOC ("supposed to be loaded") and CODE ("supposed to be executed"). Fixes: 7dc82591d68e2a ("x86: Move call64 into its own section") Signed-off-by: Sam Edwards --- arch/x86/cpu/i386/call64.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/cpu/i386/call64.S b/arch/x86/cpu/i386/call64.S index d81bcc6f8f4..424732fa3fa 100644 --- a/arch/x86/cpu/i386/call64.S +++ b/arch/x86/cpu/i386/call64.S @@ -10,7 +10,7 @@ #include .code32 -.section .text_call64 +.section .text_call64, "ax" .globl cpu_call64 cpu_call64: /* From 86838a1ddc8a0e5b5f548a5051e5e68f90fb6660 Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Sat, 15 Mar 2025 15:18:06 -0700 Subject: [PATCH 08/15] makefile: Avoid objcopy --gap-fill for .hex/.srec This flag only makes sense for `binary` output, because .hex/.srec are sparse formats and represent gaps without filler. While the GNU binutils version of objcopy does not seem to mind the extra flag being passed, llvm-objcopy considers this a fatal error. There is already a version of the objcopy command template in the Makefile that doesn't use --gap-fill, which is provided for EFI. So use this other version for all .hex/.srec outputs as well. Signed-off-by: Sam Edwards Acked-by: Ilias Apalodimas --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 0694c425438..9c353af17cd 100644 --- a/Makefile +++ b/Makefile @@ -1067,7 +1067,7 @@ quiet_cmd_objcopy = OBJCOPY $@ cmd_objcopy = $(OBJCOPY) --gap-fill=0xff $(OBJCOPYFLAGS) \ $(OBJCOPYFLAGS_$(@F)) $< $@ -# Provide a version which does not do this, for use by EFI +# Provide a version which does not do this, for use by EFI and hex/srec quiet_cmd_zobjcopy = OBJCOPY $@ cmd_zobjcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@ @@ -1282,7 +1282,7 @@ OBJCOPYFLAGS_u-boot.hex := -O ihex OBJCOPYFLAGS_u-boot.srec := -O srec u-boot.hex u-boot.srec: u-boot FORCE - $(call if_changed,objcopy) + $(call if_changed,zobjcopy) OBJCOPYFLAGS_u-boot-elf.srec := $(OBJCOPYFLAGS_u-boot.srec) @@ -1296,12 +1296,12 @@ OBJCOPYFLAGS_u-boot-elf.srec += --change-addresses=0x50000000 endif u-boot-elf.srec: u-boot.elf FORCE - $(call if_changed,objcopy) + $(call if_changed,zobjcopy) OBJCOPYFLAGS_u-boot-spl.srec = $(OBJCOPYFLAGS_u-boot.srec) spl/u-boot-spl.srec: spl/u-boot-spl FORCE - $(call if_changed,objcopy) + $(call if_changed,zobjcopy) %.scif: %.srec $(Q)$(MAKE) $(build)=arch/arm/mach-renesas $@ @@ -1436,7 +1436,7 @@ OBJCOPYFLAGS_u-boot.ldr.hex := -I binary -O ihex OBJCOPYFLAGS_u-boot.ldr.srec := -I binary -O srec u-boot.ldr.hex u-boot.ldr.srec: u-boot.ldr FORCE - $(call if_changed,objcopy) + $(call if_changed,zobjcopy) ifdef CONFIG_SPL_LOAD_FIT MKIMAGEFLAGS_u-boot.img = -f auto -A $(ARCH) -T firmware -C none -O u-boot \ From 7a8121fe6d314b314531eee7487272601f469c1d Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Sat, 15 Mar 2025 15:18:07 -0700 Subject: [PATCH 09/15] makefile: Add `norelro` linker option RELRO is an instruction to a dynamic loader to make a memory range read-only after relocations are applied, for added security. Some linkers (e.g. LLD) require that all sections covered by the RELRO are contiguous, so that only a single RELRO is needed. U-Boot at present neither satisfies this requirement (e.g. x86_64 linker script currently puts .dynamic too far from .got) nor preserves the RELRO when converting away from ELF, therefore add `-z norelro` to global linker options. This can be brought back in the future when the linker scripts are cleaned up and U-Boot understands RELROs. Signed-off-by: Sam Edwards Reviewed-by: Ilias Apalodimas --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 9c353af17cd..05a93813afa 100644 --- a/Makefile +++ b/Makefile @@ -820,6 +820,7 @@ KBUILD_AFLAGS += $(KAFLAGS) KBUILD_CFLAGS += $(KCFLAGS) KBUILD_LDFLAGS += -z noexecstack +KBUILD_LDFLAGS += -z norelro KBUILD_LDFLAGS += $(call ld-option,--no-warn-rwx-segments) KBUILD_HOSTCFLAGS += $(if $(CONFIG_TOOLS_DEBUG),-g) From 586bb720e776396208df399874665ae8c6eb81e8 Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Sat, 15 Mar 2025 15:18:08 -0700 Subject: [PATCH 10/15] makefile: Add READELF command variable This allows setting READELF=llvm-readelf in order to use the LLVM version of the readelf utility. It also aligns with the practice of not using $(CROSS_COMPILE) in any build recipes directly, reducing the number of places where $(CROSS_COMPILE) is used. Signed-off-by: Sam Edwards Reviewed-by: Heinrich Schuchardt Reviewed-by: Ilias Apalodimas --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 05a93813afa..fb5cd67745f 100644 --- a/Makefile +++ b/Makefile @@ -406,6 +406,7 @@ LDR = $(CROSS_COMPILE)ldr STRIP = $(CROSS_COMPILE)strip OBJCOPY = $(CROSS_COMPILE)objcopy OBJDUMP = $(CROSS_COMPILE)objdump +READELF = $(CROSS_COMPILE)readelf LEX = flex YACC = bison AWK = awk @@ -2177,7 +2178,7 @@ System.map: u-boot # ARM relocations should all be R_ARM_RELATIVE (32-bit) or # R_AARCH64_RELATIVE (64-bit). checkarmreloc: u-boot - @RELOC="`$(CROSS_COMPILE)readelf -r -W $< | cut -d ' ' -f 4 | \ + @RELOC="`$(READELF) -r -W $< | cut -d ' ' -f 4 | \ grep R_A | sort -u`"; \ if test "$$RELOC" != "R_ARM_RELATIVE" -a \ "$$RELOC" != "R_AARCH64_RELATIVE"; then \ From f692540b24a7775e43f1d315d3e13a5d3ed21dd4 Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Sat, 15 Mar 2025 15:18:09 -0700 Subject: [PATCH 11/15] arm: riscv: efi: Export _start symbol from crt0_*_efi stubs While the _start label is only intended for use locally to populate the (hand-written) PE header, the linker script includes ENTRY(_start) which designates it as the entry point in the output ELF, resulting in linker warnings under some linkers (e.g. LLVM's lld) due to _start not being a globally-visible symbol. Since ELF is only an intermediary build format, and the aforementioned PE header correctly points to _start, the ENTRY(_start) directive could easily be removed to silence this warning. However, since some developers who are debugging EFI by analyzing the intermediary ELF may appreciate having correct entry-point information, this patch instead promotes the _start labels to global symbols, silencing the linker warning and making the intermediary ELF reflect the true entry point. This patch doesn't affect the final output binaries in any way. Signed-off-by: Sam Edwards Reviewed-by: Heinrich Schuchardt --- arch/arm/lib/crt0_aarch64_efi.S | 1 + arch/arm/lib/crt0_arm_efi.S | 1 + arch/riscv/lib/crt0_riscv_efi.S | 1 + 3 files changed, 3 insertions(+) diff --git a/arch/arm/lib/crt0_aarch64_efi.S b/arch/arm/lib/crt0_aarch64_efi.S index e21b54fdbcb..003d5f83041 100644 --- a/arch/arm/lib/crt0_aarch64_efi.S +++ b/arch/arm/lib/crt0_aarch64_efi.S @@ -144,6 +144,7 @@ section_table: IMAGE_SCN_CNT_INITIALIZED_DATA) .align 12 + .globl _start _start: stp x29, x30, [sp, #-32]! mov x29, sp diff --git a/arch/arm/lib/crt0_arm_efi.S b/arch/arm/lib/crt0_arm_efi.S index 235b3a0c48f..593ee1e194a 100644 --- a/arch/arm/lib/crt0_arm_efi.S +++ b/arch/arm/lib/crt0_arm_efi.S @@ -143,6 +143,7 @@ section_table: IMAGE_SCN_CNT_INITIALIZED_DATA) .align 12 + .globl _start _start: stmfd sp!, {r0-r2, lr} diff --git a/arch/riscv/lib/crt0_riscv_efi.S b/arch/riscv/lib/crt0_riscv_efi.S index 9eacbe4a859..f170e4b26d6 100644 --- a/arch/riscv/lib/crt0_riscv_efi.S +++ b/arch/riscv/lib/crt0_riscv_efi.S @@ -179,6 +179,7 @@ section_table: IMAGE_SCN_CNT_INITIALIZED_DATA) .align 12 + .globl _start _start: addi sp, sp, -(SIZE_LONG * 3) SAVE_LONG(a0, 0) From 1755071db7d95fa0b95e9f9bedd3785e2abc10cf Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Sat, 15 Mar 2025 15:18:10 -0700 Subject: [PATCH 12/15] efi_loader: Move .dynamic out of .text in EFI EFI applications need to be relocatable. Ordinarily, this is achieved through a PE-format .reloc section, but since that requires toolchain tricks to achieve, U-Boot's EFI applications instead embed ELF-flavored relocation information and use it for self-relocation; thus, the .dynamic section needs to be preserved. Before this patch, it was tacked on to the end of .text, but this was not proper: A .text section is SHT_PROGBITS, while the .dynamic section is SHT_DYNAMIC. Attempting to combine them like this creates a section type mismatch. While GNU ld doesn't seem to complain, LLVM's lld considers this a fatal linking error. This patch moves .dynamic out to its own section, so that the output ELF has the correct types. (They're all mashed together when converting to binary anyway, so this patch causes no change in the final .efi output.) Signed-off-by: Sam Edwards Cc: Heinrich Schuchardt Reviewed-by: Heinrich Schuchardt --- lib/efi_loader/elf_efi.ldsi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/efi_loader/elf_efi.ldsi b/lib/efi_loader/elf_efi.ldsi index 190a88fb69e..4fa5ca43872 100644 --- a/lib/efi_loader/elf_efi.ldsi +++ b/lib/efi_loader/elf_efi.ldsi @@ -21,10 +21,10 @@ SECTIONS *(.gnu.linkonce.t.*) *(.srodata) *(.rodata*) - . = ALIGN(16); - *(.dynamic); - . = ALIGN(512); } + . = ALIGN(16); + .dynamic : { *(.dynamic) } + . = ALIGN(512); .rela.dyn : { *(.rela.dyn) } .rela.plt : { *(.rela.plt) } .rela.got : { *(.rela.got) } From 9ca475a6b5da06908a70d1eceb439d480137d69b Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Sat, 15 Mar 2025 15:18:11 -0700 Subject: [PATCH 13/15] scripts/Makefile.lib: efi: Preserve the .dynstr section as well This section is required by .dynamic and llvm-objcopy will exit with a fatal error if it is not also preserved in the output. Signed-off-by: Sam Edwards --- scripts/Makefile.lib | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 18993435eae..275c308154b 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -513,8 +513,8 @@ $(obj)/%_efi.S: $(obj)/%.efi $(call cmd,S_efi) quiet_cmd_efi_objcopy = OBJCOPY $@ -cmd_efi_objcopy = $(OBJCOPY) -j .header -j .text -j .sdata -j .data -j \ - .dynamic -j .dynsym -j .rel* -j .rela* -j .reloc \ +cmd_efi_objcopy = $(OBJCOPY) -j .header -j .text -j .sdata -j .data \ + -j .dynamic -j .dynstr -j .dynsym -j .rel* -j .reloc \ $(if $(EFI_TARGET),$(EFI_TARGET),-O binary) $^ $@ $(obj)/%.efi: $(obj)/%_efi.so From 17d830cb4b6cdbac56d41938d455820fd7a96a89 Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Sat, 15 Mar 2025 15:18:12 -0700 Subject: [PATCH 14/15] spl: riscv: opensbi: Error on misaligned FDT libfdt 1.6.1+ requires the FDT to be 8-byte aligned and returns an error if not. OpenSBI 1.0+ includes this version of libfdt and will also reject misaligned FDTs. However, OpenSBI cannot indicate the error to the user: since it cannot access the serial console, it can only silently hang. This proved very difficult to diagnose without proper debugging facilities. Therefore, give the U-Boot SPL, which *can* print error messages, an additional check for proper FDT alignment. Hopefully this saves a lot of development cycles if another developer encounters alignment problems. Signed-off-by: Sam Edwards --- common/spl/spl_opensbi.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/common/spl/spl_opensbi.c b/common/spl/spl_opensbi.c index 5a26d7c31a4..0ed6afeacc6 100644 --- a/common/spl/spl_opensbi.c +++ b/common/spl/spl_opensbi.c @@ -57,6 +57,11 @@ void __noreturn spl_invoke_opensbi(struct spl_image_info *spl_image) hang(); } + if (!IS_ALIGNED((uintptr_t)spl_image->fdt_addr, 8)) { + pr_err("SPL image loaded an improperly-aligned device tree\n"); + hang(); + } + /* * Originally, u-boot-spl will place DTB directly after the kernel, * but the size of the kernel did not include the BSS section, which From 358d1cc232c30091767ce192e74169e7861ae58a Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Sat, 15 Mar 2025 15:18:13 -0700 Subject: [PATCH 15/15] spl: Align FDT load address While the image size is generally a multiple of 8 bytes, this is not actually guaranteed; some linkers (like LLD) will shave a few bytes off of the end of output sections if there are no content bytes there. Since libfdt imposes a hard rule of 8-byte alignment, make the SPL also be explicit about the alignment when loading the FDT. Signed-off-by: Sam Edwards --- common/spl/spl_fit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index 49b4df60560..86506d6905c 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -397,7 +397,7 @@ static int spl_fit_append_fdt(struct spl_image_info *spl_image, * Use the address following the image as target address for the * device tree. */ - image_info.load_addr = spl_image->load_addr + spl_image->size; + image_info.load_addr = ALIGN(spl_image->load_addr + spl_image->size, 8); /* Figure out which device tree the board wants to use */ node = spl_fit_get_image_node(ctx, FIT_FDT_PROP, index++);