Skip to contentSkip to conversation

Update linker scripts to ensure appended device tree is correctly aligned

PATCH In review Tom Rini 9 participants 56 messages Jan 15 – Feb 6

Subsystems (18)
lore
Share & tools
lore

Tom Rini

author
#0 lore raw

cover Update linker scripts to ensure appended device tree is correctly aligned

Hey all,

This series builds on top of what Beleswar Padhi did in [1]. While there's still discussion about the mkimage related parts, the linker portion appears to the reliable path forward. An alternative that I had mentioned before, and was part of previous discussions on this topic[2] is in the end I believe not reliable enough. While we can take an output file and pad it to where we think it needs to be, ultimately the linker needs to place the symbol where we want it and if that isn't where we pad to, we have a different problem. So what this series does (but each commit message elaborates on the arch-specific linker scripts being inconsistent) is make sure the linker script will place the required symbol at 8-byte alignment, and then also use an ASSERT to fail the build if this would not be true due to some unforseen event.

Given the number of platforms which have failure to run right now, I'd like to pick up at least 2/2 of Beleswar's series as well as this series early next week.

[1]: https://lore.kernel.org/u-boot/[email protected]/
[2]: https://source.denx.de/u-boot/u-boot/-/issues/30

Signature · 1 line
Tom
author
#1 lore raw

PATCH 1/10 Makefile: Have binary_size_check report only first match of _image_binary_end

If we have ASSERT macros that validate the position of _image_binary_end, our awk expression will report a string that causes the rest of our check to fail with garbage values. Have it exit after the first match to fix this.

---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
index 50737f938503..37cebd4f8edd 100644
@@ -1583,7 +1583,7 @@ binary_size_check: u-boot-nodtb.bin FORCE
 	map_size=$(shell cat u-boot.map | \
 		awk ' \
 			/_image_copy_start/ { start = $$1 } \
-			/_image_binary_end/ { end = $$1 } \
+			/_image_binary_end/ { end = $$1;exit } \
 			END { \
 				if (start != "" && end != "") \
 					print end " " start; \
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH 01/10] Makefile: Have binary_size_check report only first match of _image_binary_end

Quoted 15 lines · Tom Rini

If we have ASSERT macros that validate the position of _image_binary_end, our awk expression will report a string that causes the rest of our check to fail with garbage values. Have it exit after the first match to fix this.

---
  Makefile | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +0 -0
index 50737f938503..37cebd4f8edd 100644

Makefile binary_size_check: u-boot-nodtb.bin FORCE · line 1586

Quoted 5 lines
Makefile +1 -1
@@ -1583,7 +1583,7 @@ binary_size_check: u-boot-nodtb.bin FORCE
  	map_size=$(shell cat u-boot.map | \
  		awk ' \
  			/_image_copy_start/ { start = $$1 } \
-			/_image_binary_end/ { end = $$1 } \
+			/_image_binary_end/ { end = $$1;exit } \

Can this same check also confirm that _image_binary_end or __bss_end is at 8 byte aligned offset ? That would allow us to trap all the built-in DT alignment errors.

author
#3 lore raw

Re: [PATCH 01/10] Makefile: Have binary_size_check report only first match of _image_binary_end

Quoted 11 lines · Marek Vasut
Quoted 10 lines · Tom Rini

If we have ASSERT macros that validate the position of _image_binary_end, our awk expression will report a string that causes the rest of our check to fail with garbage values. Have it exit after the first match to fix this.

---
  Makefile | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

Makefile binary_size_check: u-boot-nodtb.bin FORCE · line 1586

Quoted 10 lines
Makefile +1 -1
index 50737f938503..37cebd4f8edd 100644
@@ -1583,7 +1583,7 @@ binary_size_check: u-boot-nodtb.bin FORCE
  	map_size=$(shell cat u-boot.map | \
  		awk ' \
  			/_image_copy_start/ { start = $$1 } \
-			/_image_binary_end/ { end = $$1 } \
+			/_image_binary_end/ { end = $$1;exit } \

Can this same check also confirm that _image_binary_end or __bss_end is at 8 byte aligned offset ? That would allow us to trap all the built-in DT alignment errors.

We should have that now via the linker scripts. Also note that this call here isn't universal.

Signature · 1 line
Tom
author
#4 lore raw

PATCH 2/10 arm: Update linker scripts to ensure appended device tree is aligned

In reply to Tom Rini

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Expands some linker sections to be more readable when adding a second statement to the section.
- Aligns the final section before _end (for U-Boot) or _image_binary_end or __bss_end (for xPL phases) by 8-bytes by adding '. = ALIGN(8);' to the final section before the symbol.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).
- Remove now-spurious '. = ALIGN(x);' statements that were intended to provide the above alignments.

---
The only part of this I am only mostly rather than fully confident in is having caught all cases of having SPL_SEPARATE_BSS being false. I believe I have as the generic ARM SPL linker script enforces the BSS ending with 8-byte alignment, and the point of the ASSERTs here is to catch the case where the section we're adding the ALIGN to ends up being empty and so that ALIGN would become useless.

Cc "NXP i.MX U-Boot Team" <[email protected]>
Cc Adam Ford <[email protected]>
Cc Andre Przywara <[email protected]>
Cc Aspeed BMC SW team <[email protected]>
Cc Chia-Wei Wang <[email protected]>
Cc Eugen Hristev <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Ilias Apalodimas <[email protected]>
Cc Jagan Teki <[email protected]>
Cc Joel Stanley <[email protected]>
Cc Kever Yang <[email protected]>
Cc Marek Vasut <[email protected]>
Cc Michal Simek <[email protected]>
Cc Philipp Tomsich <[email protected]>
Cc Richard Henderson <[email protected]>
Cc Ryan Chen <[email protected]>
Cc Stefano Babic <[email protected]>
---
 arch/arm/cpu/arm1136/u-boot-spl.lds            | 8 ++++++--
 arch/arm/cpu/arm926ejs/mxs/u-boot-spl.lds      | 5 ++++-
 arch/arm/cpu/arm926ejs/sunxi/u-boot-spl.lds    | 5 ++++-
 arch/arm/cpu/armv7/sunxi/u-boot-spl.lds        | 5 ++++-
 arch/arm/cpu/armv8/u-boot-spl.lds              | 4 +++-
 arch/arm/cpu/armv8/u-boot.lds                  | 2 ++
 arch/arm/cpu/u-boot-spl.lds                    | 5 ++++-
 arch/arm/cpu/u-boot.lds                        | 4 ++++
 arch/arm/mach-aspeed/ast2600/u-boot-spl.lds    | 4 ++++
 arch/arm/mach-at91/arm926ejs/u-boot-spl.lds    | 9 +++++++--
 arch/arm/mach-at91/armv7/u-boot-spl.lds        | 9 +++++++--
 arch/arm/mach-omap2/u-boot-spl.lds             | 3 +++
 arch/arm/mach-rockchip/u-boot-tpl-v8.lds       | 5 ++++-
 arch/arm/mach-zynq/u-boot-spl.lds              | 6 ++++--
 arch/arm/mach-zynq/u-boot.lds                  | 3 +++
 board/davinci/da8xxevm/u-boot-spl-da850evm.lds | 4 ++++
 board/samsung/common/exynos-uboot-spl.lds      | 5 ++++-
 17 files changed, 71 insertions(+), 15 deletions(-)
arch/arm/cpu/arm1136/u-boot-spl.lds +6 -2
index b7af29183a97..22a9302275ae 100644
@@ -30,8 +30,10 @@ SECTIONS
 	.rodata : { *(SORT_BY_ALIGNMENT(.rodata*)) } >.sram
 
 	. = ALIGN(4);
-	.data : { *(SORT_BY_ALIGNMENT(.data*)) } >.sram
-	. = ALIGN(4);
+	.data : {
+		*(SORT_BY_ALIGNMENT(.data*))
+		. = ALIGN(8);
+	} >.sram
 	__image_copy_end = .;
 	_end = .;
 
@@ -44,3 +46,5 @@ SECTIONS
 		__bss_end = .;
 	} >.sdram
 }
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");
arch/arm/cpu/arm926ejs/mxs/u-boot-spl.lds +4 -1
index 7c6309246f8b..b4adae272eba 100644
@@ -45,7 +45,7 @@ SECTIONS
 		. = ALIGN(4);
 		__bss_start = .;
 		*(.bss*)
-		. = ALIGN(4);
+		. = ALIGN(8);
 		__bss_end = .;
 	}
 
@@ -62,3 +62,6 @@ SECTIONS
 	.gnu : { *(.gnu*) }
 	.ARM.exidx : { *(.ARM.exidx*) }
 }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
arch/arm/cpu/arm926ejs/sunxi/u-boot-spl.lds +4 -1
index cf65e8c46281..2225985c79c0 100644
@@ -31,9 +31,9 @@ SECTIONS
 	. = ALIGN(4);
 	__u_boot_list : {
 		KEEP(*(SORT(__u_boot_list*)));
+		. = ALIGN(8);
 	} > .sram
 
-	. = ALIGN(4);
 	__image_copy_end = .;
 	_end = .;
 	_image_binary_end = .;
@@ -47,3 +47,6 @@ SECTIONS
 		__bss_end = .;
 	} > .sdram
 }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
arch/arm/cpu/armv7/sunxi/u-boot-spl.lds +4 -1
index fb7a789b28b8..e69291d8be6d 100644
@@ -40,9 +40,9 @@ SECTIONS
 	. = ALIGN(4);
 	__u_boot_list : {
 		KEEP(*(SORT(__u_boot_list*)));
+		. = ALIGN(8);
 	} > .sram
 
-	. = ALIGN(4);
 	__image_copy_end = .;
 	_end = .;
 	_image_binary_end = .;
@@ -56,3 +56,6 @@ SECTIONS
 		__bss_end = .;
 	} > .sdram
 }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
arch/arm/cpu/armv8/u-boot-spl.lds +3 -1
index c4f83ec9cfc4..d9963846c4f4 100644
@@ -52,9 +52,9 @@ SECTIONS
 	__u_boot_list : {
 		. = ALIGN(8);
 		KEEP(*(SORT(__u_boot_list*)));
+		. = ALIGN(8);
 	} >.sram
 
-	. = ALIGN(8);
 	__image_copy_end = .;
 	_end = .;
 	_image_binary_end = .;
@@ -89,5 +89,7 @@ SECTIONS
 #endif
 }
 
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
 ASSERT(ADDR(.bss) % 8 == 0, \
        ".bss must be 8-byte aligned");
arch/arm/cpu/armv8/u-boot.lds +2 -0
index f4ce98c82c8d..704e0bf9468d 100644
@@ -175,3 +175,5 @@ SECTIONS
 #include "linux-kernel-image-header-vars.h"
 #endif
 }
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");
arch/arm/cpu/u-boot-spl.lds +4 -1
index 5aecb61ce902..d780a5060774 100644
@@ -51,9 +51,9 @@ SECTIONS
 		__rel_dyn_start = .;
 		*(.rel*)
 		__rel_dyn_end = .;
+		. = ALIGN(8);
 	}
 
-	. = ALIGN(8);
 	_image_binary_end = .;
 	_end = .;
 
@@ -80,6 +80,9 @@ ASSERT(__image_copy_end - __image_copy_start <= (IMAGE_MAX_SIZE), \
 	"SPL image too big");
 #endif
 
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
+
 #if defined(CONFIG_SPL_BSS_MAX_SIZE)
 ASSERT(__bss_end - __bss_start <= (CONFIG_SPL_BSS_MAX_SIZE), \
 	"SPL image BSS too big");
arch/arm/cpu/u-boot.lds +4 -0
index 78aad093d3b2..8e2266a90fe2 100644
@@ -164,6 +164,7 @@ SECTIONS
 		__rel_dyn_start = .;
 		*(.rel*)
 		__rel_dyn_end = .;
+		. = ALIGN(8);
 	}
 
 	_end = .;
@@ -192,3 +193,6 @@ SECTIONS
 	/DISCARD/ : { *(.ARM.exidx*) }
 	/DISCARD/ : { *(.gnu.linkonce.armexidx.*) }
 }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
arch/arm/mach-aspeed/ast2600/u-boot-spl.lds +4 -0
index 9502a7384b53..c9664a6ce566 100644
@@ -59,6 +59,7 @@ SECTIONS
 		__rel_dyn_start = .;
 		*(.rel*)
 		__rel_dyn_end = .;
+		. = ALIGN(8);
 	} > .nor
 
 	_end = .;
@@ -79,6 +80,9 @@ ASSERT(__image_copy_end - __image_copy_start <= (IMAGE_MAX_SIZE), \
 	"SPL image too big");
 #endif
 
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
+
 #if defined(CONFIG_SPL_BSS_MAX_SIZE)
 ASSERT(__bss_end - __bss_start <= (CONFIG_SPL_BSS_MAX_SIZE), \
 	"SPL image BSS too big");
arch/arm/mach-at91/arm926ejs/u-boot-spl.lds +7 -2
index 09cf838cf96e..1af4f7b6524c 100644
@@ -29,9 +29,11 @@ SECTIONS
 	.data : { *(SORT_BY_ALIGNMENT(.data*)) } >.sram
 
 	. = ALIGN(4);
-	__u_boot_list : { KEEP(*(SORT(__u_boot_list*))) } > .sram
+	__u_boot_list : {
+		KEEP(*(SORT(__u_boot_list*)))
+		. = ALIGN(8);
+	} > .sram
 
-	. = ALIGN(4);
 	__image_copy_end = .;
 	_end = .;
 	_image_binary_end = .;
@@ -51,6 +53,9 @@ ASSERT(__image_copy_end - __start <= (IMAGE_MAX_SIZE), \
 	"SPL image too big");
 #endif
 
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
+
 #if defined(CONFIG_SPL_BSS_MAX_SIZE)
 ASSERT(__bss_end - __bss_start <= (CONFIG_SPL_BSS_MAX_SIZE), \
 	"SPL image BSS too big");
arch/arm/mach-at91/armv7/u-boot-spl.lds +7 -2
index 460a91d93ec4..287764df48ff 100644
@@ -36,9 +36,11 @@ SECTIONS
 	.data : { *(SORT_BY_ALIGNMENT(.data*)) } >.sram
 
 	. = ALIGN(4);
-	__u_boot_list : { KEEP(*(SORT(__u_boot_list*))) } > .sram
+	__u_boot_list : {
+		KEEP(*(SORT(__u_boot_list*)))
+		. = ALIGN(8);
+	} > .sram
 
-	. = ALIGN(4);
 	__image_copy_end = .;
 	_end = .;
 	_image_binary_end = .;
@@ -52,3 +54,6 @@ SECTIONS
 		__bss_end = .;
 	} >.sdram
 }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
arch/arm/mach-omap2/u-boot-spl.lds +3 -0
index 5ad169a37b73..86ab692ae390 100644
@@ -55,3 +55,6 @@ SECTIONS
 		__bss_end = .;
 	} >.sdram
 }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
arch/arm/mach-rockchip/u-boot-tpl-v8.lds +4 -1
index 958a1b70aefe..2c0f5c3e5f32 100644
@@ -42,9 +42,9 @@ SECTIONS
 	__u_boot_list : {
 		. = ALIGN(8);
 		KEEP(*(SORT(__u_boot_list*)));
+		. = ALIGN(8);
 	}
 
-	. = ALIGN(8);
 	__image_copy_end = .;
 	_end = .;
 	_image_binary_end = .;
@@ -69,6 +69,9 @@ ASSERT(__image_copy_end - __image_copy_start < (CONFIG_TPL_MAX_SIZE), \
 	"TPL image too big");
 #endif
 
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
+
 #if defined(CONFIG_TPL_BSS_MAX_SIZE)
 ASSERT(__bss_end - __bss_start < (CONFIG_TPL_BSS_MAX_SIZE), \
 	"TPL image BSS too big");
arch/arm/mach-zynq/u-boot-spl.lds +4 -2
index d96a57702886..17f0d7c9b72f 100644
@@ -39,10 +39,9 @@ SECTIONS
 	. = ALIGN(4);
 	__u_boot_list : {
 		KEEP(*(SORT(__u_boot_list*)));
+		. = ALIGN(8);
 	} > .sram
 
-	. = ALIGN(4);
-
 	_image_binary_end = .;
 
 	_end = .;
@@ -62,3 +61,6 @@ SECTIONS
 	/DISCARD/ : { *(.interp*) }
 	/DISCARD/ : { *(.gnu*) }
 }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
arch/arm/mach-zynq/u-boot.lds +3 -0
index f52523edf490..2a8e3399e0bf 100644
@@ -66,6 +66,7 @@ SECTIONS
 		__rel_dyn_start = .;
 		*(.rel*)
 		__rel_dyn_end = .;
+		. = ALIGN(8);
 	}
 
 	_end = .;
@@ -98,3 +99,5 @@ SECTIONS
 	/DISCARD/ : { *(.ARM.exidx*) }
 	/DISCARD/ : { *(.gnu.linkonce.armexidx.*) }
 }
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");
board/davinci/da8xxevm/u-boot-spl-da850evm.lds +4 -0
index 56d6f4f114b9..d1a82e118af1 100644
@@ -43,6 +43,7 @@ SECTIONS
 		__rel_dyn_start = .;
 		*(.rel*)
 		__rel_dyn_end = .;
+		. = ALIGN(8);
 	} >.sram
 
 	__image_copy_end = .;
@@ -58,3 +59,6 @@ SECTIONS
 		__bss_end = .;
 	} >.sdram
 }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
board/samsung/common/exynos-uboot-spl.lds +4 -1
index 9d3b57e98dbb..62e150bcf335 100644
@@ -48,7 +48,10 @@ SECTIONS
 		. = ALIGN(4);
 		__bss_start = .;
 		*(.bss*)
-		. = ALIGN(4);
+		. = ALIGN(8);
 		__bss_end = .;
 	} >.sram
 }
+
+ASSERT(__bss_end % 8 == 0, \
+       "__bss_end must be 8-byte aligned for device tree");
Signature · 1 line
2.43.0
#5 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

Hi Tom,

arch/arm/cpu/armv8/u-boot.lds and arch/arm/mach-omap2/u-boot-spl.lds can use the same alignment. Is the omap2 case covered by the TI patches? I think it's better if you bundle this up in this series

Cheers
/Ilias

Quoted 418 lines · Tom Rini

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Expands some linker sections to be more readable when adding a second statement to the section.
- Aligns the final section before _end (for U-Boot) or _image_binary_end or __bss_end (for xPL phases) by 8-bytes by adding '. = ALIGN(8);' to the final section before the symbol.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).
- Remove now-spurious '. = ALIGN(x);' statements that were intended to provide the above alignments.

---
The only part of this I am only mostly rather than fully confident in is having caught all cases of having SPL_SEPARATE_BSS being false. I believe I have as the generic ARM SPL linker script enforces the BSS ending with 8-byte alignment, and the point of the ASSERTs here is to catch the case where the section we're adding the ALIGN to ends up being empty and so that ALIGN would become useless.

Cc "NXP i.MX U-Boot Team" <[email protected]>
Cc Adam Ford <[email protected]>
Cc Andre Przywara <[email protected]>
Cc Aspeed BMC SW team <[email protected]>
Cc Chia-Wei Wang <[email protected]>
Cc Eugen Hristev <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Ilias Apalodimas <[email protected]>
Cc Jagan Teki <[email protected]>
Cc Joel Stanley <[email protected]>
Cc Kever Yang <[email protected]>
Cc Marek Vasut <[email protected]>
Cc Michal Simek <[email protected]>
Cc Philipp Tomsich <[email protected]>
Cc Richard Henderson <[email protected]>
Cc Ryan Chen <[email protected]>
Cc Stefano Babic <[email protected]>
---
 arch/arm/cpu/arm1136/u-boot-spl.lds            | 8 ++++++--
 arch/arm/cpu/arm926ejs/mxs/u-boot-spl.lds      | 5 ++++-
 arch/arm/cpu/arm926ejs/sunxi/u-boot-spl.lds    | 5 ++++-
 arch/arm/cpu/armv7/sunxi/u-boot-spl.lds        | 5 ++++-
 arch/arm/cpu/armv8/u-boot-spl.lds              | 4 +++-
 arch/arm/cpu/armv8/u-boot.lds                  | 2 ++
 arch/arm/cpu/u-boot-spl.lds                    | 5 ++++-
 arch/arm/cpu/u-boot.lds                        | 4 ++++
 arch/arm/mach-aspeed/ast2600/u-boot-spl.lds    | 4 ++++
 arch/arm/mach-at91/arm926ejs/u-boot-spl.lds    | 9 +++++++--
 arch/arm/mach-at91/armv7/u-boot-spl.lds        | 9 +++++++--
 arch/arm/mach-omap2/u-boot-spl.lds             | 3 +++
 arch/arm/mach-rockchip/u-boot-tpl-v8.lds       | 5 ++++-
 arch/arm/mach-zynq/u-boot-spl.lds              | 6 ++++--
 arch/arm/mach-zynq/u-boot.lds                  | 3 +++
 board/davinci/da8xxevm/u-boot-spl-da850evm.lds | 4 ++++
 board/samsung/common/exynos-uboot-spl.lds      | 5 ++++-
 17 files changed, 71 insertions(+), 15 deletions(-)
arch/arm/cpu/arm1136/u-boot-spl.lds +6 -2
index b7af29183a97..22a9302275ae 100644
@@ -30,8 +30,10 @@ SECTIONS
        .rodata : { *(SORT_BY_ALIGNMENT(.rodata*)) } >.sram
 
        . = ALIGN(4);
-       .data : { *(SORT_BY_ALIGNMENT(.data*)) } >.sram
-       . = ALIGN(4);
+       .data : {
+               *(SORT_BY_ALIGNMENT(.data*))
+               . = ALIGN(8);
+       } >.sram
        __image_copy_end = .;
        _end = .;
 
@@ -44,3 +46,5 @@ SECTIONS
                __bss_end = .;
        } >.sdram
 }
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");
arch/arm/cpu/arm926ejs/mxs/u-boot-spl.lds +4 -1
index 7c6309246f8b..b4adae272eba 100644
@@ -45,7 +45,7 @@ SECTIONS
                . = ALIGN(4);
                __bss_start = .;
                *(.bss*)
-               . = ALIGN(4);
+               . = ALIGN(8);
                __bss_end = .;
        }
 
@@ -62,3 +62,6 @@ SECTIONS
        .gnu : { *(.gnu*) }
        .ARM.exidx : { *(.ARM.exidx*) }
 }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
arch/arm/cpu/arm926ejs/sunxi/u-boot-spl.lds +4 -1
index cf65e8c46281..2225985c79c0 100644
@@ -31,9 +31,9 @@ SECTIONS
        . = ALIGN(4);
        __u_boot_list : {
                KEEP(*(SORT(__u_boot_list*)));
+               . = ALIGN(8);
        } > .sram
 
-       . = ALIGN(4);
        __image_copy_end = .;
        _end = .;
        _image_binary_end = .;
@@ -47,3 +47,6 @@ SECTIONS
                __bss_end = .;
        } > .sdram
 }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
arch/arm/cpu/armv7/sunxi/u-boot-spl.lds +4 -1
index fb7a789b28b8..e69291d8be6d 100644
@@ -40,9 +40,9 @@ SECTIONS
        . = ALIGN(4);
        __u_boot_list : {
                KEEP(*(SORT(__u_boot_list*)));
+               . = ALIGN(8);
        } > .sram
 
-       . = ALIGN(4);
        __image_copy_end = .;
        _end = .;
        _image_binary_end = .;
@@ -56,3 +56,6 @@ SECTIONS
                __bss_end = .;
        } > .sdram
 }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
arch/arm/cpu/armv8/u-boot-spl.lds +3 -1
index c4f83ec9cfc4..d9963846c4f4 100644
@@ -52,9 +52,9 @@ SECTIONS
        __u_boot_list : {
                . = ALIGN(8);
                KEEP(*(SORT(__u_boot_list*)));
+               . = ALIGN(8);
        } >.sram
 
-       . = ALIGN(8);
        __image_copy_end = .;
        _end = .;
        _image_binary_end = .;
@@ -89,5 +89,7 @@ SECTIONS
 #endif
 }
 
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
 ASSERT(ADDR(.bss) % 8 == 0, \
        ".bss must be 8-byte aligned");
arch/arm/cpu/armv8/u-boot.lds +2 -0
index f4ce98c82c8d..704e0bf9468d 100644
@@ -175,3 +175,5 @@ SECTIONS
 #include "linux-kernel-image-header-vars.h"
 #endif
 }
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");
arch/arm/cpu/u-boot-spl.lds +4 -1
index 5aecb61ce902..d780a5060774 100644
@@ -51,9 +51,9 @@ SECTIONS
                __rel_dyn_start = .;
                *(.rel*)
                __rel_dyn_end = .;
+               . = ALIGN(8);
        }
 
-       . = ALIGN(8);
        _image_binary_end = .;
        _end = .;
 
@@ -80,6 +80,9 @@ ASSERT(__image_copy_end - __image_copy_start <= (IMAGE_MAX_SIZE), \
        "SPL image too big");
 #endif
 
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
+
 #if defined(CONFIG_SPL_BSS_MAX_SIZE)
 ASSERT(__bss_end - __bss_start <= (CONFIG_SPL_BSS_MAX_SIZE), \
        "SPL image BSS too big");
arch/arm/cpu/u-boot.lds +4 -0
index 78aad093d3b2..8e2266a90fe2 100644
@@ -164,6 +164,7 @@ SECTIONS
                __rel_dyn_start = .;
                *(.rel*)
                __rel_dyn_end = .;
+               . = ALIGN(8);
        }
 
        _end = .;
@@ -192,3 +193,6 @@ SECTIONS
        /DISCARD/ : { *(.ARM.exidx*) }
        /DISCARD/ : { *(.gnu.linkonce.armexidx.*) }
 }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
arch/arm/mach-aspeed/ast2600/u-boot-spl.lds +4 -0
index 9502a7384b53..c9664a6ce566 100644
@@ -59,6 +59,7 @@ SECTIONS
                __rel_dyn_start = .;
                *(.rel*)
                __rel_dyn_end = .;
+               . = ALIGN(8);
        } > .nor
 
        _end = .;
@@ -79,6 +80,9 @@ ASSERT(__image_copy_end - __image_copy_start <= (IMAGE_MAX_SIZE), \
        "SPL image too big");
 #endif
 
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
+
 #if defined(CONFIG_SPL_BSS_MAX_SIZE)
 ASSERT(__bss_end - __bss_start <= (CONFIG_SPL_BSS_MAX_SIZE), \
        "SPL image BSS too big");
arch/arm/mach-at91/arm926ejs/u-boot-spl.lds +7 -2
index 09cf838cf96e..1af4f7b6524c 100644
@@ -29,9 +29,11 @@ SECTIONS
        .data : { *(SORT_BY_ALIGNMENT(.data*)) } >.sram
 
        . = ALIGN(4);
-       __u_boot_list : { KEEP(*(SORT(__u_boot_list*))) } > .sram
+       __u_boot_list : {
+               KEEP(*(SORT(__u_boot_list*)))
+               . = ALIGN(8);
+       } > .sram
 
-       . = ALIGN(4);
        __image_copy_end = .;
        _end = .;
        _image_binary_end = .;
@@ -51,6 +53,9 @@ ASSERT(__image_copy_end - __start <= (IMAGE_MAX_SIZE), \
        "SPL image too big");
 #endif
 
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
+
 #if defined(CONFIG_SPL_BSS_MAX_SIZE)
 ASSERT(__bss_end - __bss_start <= (CONFIG_SPL_BSS_MAX_SIZE), \
        "SPL image BSS too big");
arch/arm/mach-at91/armv7/u-boot-spl.lds +7 -2
index 460a91d93ec4..287764df48ff 100644
@@ -36,9 +36,11 @@ SECTIONS
        .data : { *(SORT_BY_ALIGNMENT(.data*)) } >.sram
 
        . = ALIGN(4);
-       __u_boot_list : { KEEP(*(SORT(__u_boot_list*))) } > .sram
+       __u_boot_list : {
+               KEEP(*(SORT(__u_boot_list*)))
+               . = ALIGN(8);
+       } > .sram
 
-       . = ALIGN(4);
        __image_copy_end = .;
        _end = .;
        _image_binary_end = .;
@@ -52,3 +54,6 @@ SECTIONS
                __bss_end = .;
        } >.sdram
 }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
arch/arm/mach-omap2/u-boot-spl.lds +3 -0
index 5ad169a37b73..86ab692ae390 100644
@@ -55,3 +55,6 @@ SECTIONS
                __bss_end = .;
        } >.sdram
 }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
arch/arm/mach-rockchip/u-boot-tpl-v8.lds +4 -1
index 958a1b70aefe..2c0f5c3e5f32 100644
@@ -42,9 +42,9 @@ SECTIONS
        __u_boot_list : {
                . = ALIGN(8);
                KEEP(*(SORT(__u_boot_list*)));
+               . = ALIGN(8);
        }
 
-       . = ALIGN(8);
        __image_copy_end = .;
        _end = .;
        _image_binary_end = .;
@@ -69,6 +69,9 @@ ASSERT(__image_copy_end - __image_copy_start < (CONFIG_TPL_MAX_SIZE), \
        "TPL image too big");
 #endif
 
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
+
 #if defined(CONFIG_TPL_BSS_MAX_SIZE)
 ASSERT(__bss_end - __bss_start < (CONFIG_TPL_BSS_MAX_SIZE), \
        "TPL image BSS too big");
arch/arm/mach-zynq/u-boot-spl.lds +4 -2
index d96a57702886..17f0d7c9b72f 100644
@@ -39,10 +39,9 @@ SECTIONS
        . = ALIGN(4);
        __u_boot_list : {
                KEEP(*(SORT(__u_boot_list*)));
+               . = ALIGN(8);
        } > .sram
 
-       . = ALIGN(4);
-
        _image_binary_end = .;
 
        _end = .;
@@ -62,3 +61,6 @@ SECTIONS
        /DISCARD/ : { *(.interp*) }
        /DISCARD/ : { *(.gnu*) }
 }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
arch/arm/mach-zynq/u-boot.lds +3 -0
index f52523edf490..2a8e3399e0bf 100644
@@ -66,6 +66,7 @@ SECTIONS
                __rel_dyn_start = .;
                *(.rel*)
                __rel_dyn_end = .;
+               . = ALIGN(8);
        }
 
        _end = .;
@@ -98,3 +99,5 @@ SECTIONS
        /DISCARD/ : { *(.ARM.exidx*) }
        /DISCARD/ : { *(.gnu.linkonce.armexidx.*) }
 }
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");
board/davinci/da8xxevm/u-boot-spl-da850evm.lds +4 -0
index 56d6f4f114b9..d1a82e118af1 100644
@@ -43,6 +43,7 @@ SECTIONS
                __rel_dyn_start = .;
                *(.rel*)
                __rel_dyn_end = .;
+               . = ALIGN(8);
        } >.sram
 
        __image_copy_end = .;
@@ -58,3 +59,6 @@ SECTIONS
                __bss_end = .;
        } >.sdram
 }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
board/samsung/common/exynos-uboot-spl.lds +4 -2
index 9d3b57e98dbb..62e150bcf335 100644
@@ -48,7 +48,10 @@ SECTIONS
                . = ALIGN(4);
                __bss_start = .;
                *(.bss*)
-               . = ALIGN(4);
+               . = ALIGN(8);
                __bss_end = .;
        } >.sram
 }
+
+ASSERT(__bss_end % 8 == 0, \
+       "__bss_end must be 8-byte aligned for device tree");
--

2.43.0

author
#6 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

Quoted 5 lines · Ilias Apalodimas

Hi Tom,

arch/arm/cpu/armv8/u-boot.lds and arch/arm/mach-omap2/u-boot-spl.lds can use the same alignment. Is the omap2 case covered by the TI patches? I think it's better if you bundle this up in this series

Correct, the TI patches fix omap2 (and a number of other platforms, that linker script should be renamed, it's the sram+sdram SPL case) platforms. I mentioned needing it in the cover letter btw :)

Signature · 1 line
Tom
Reviewed-by
#7 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

Hi Tom

Quoted 5 lines · Tom Rini
Quoted 2 lines · Ilias Apalodimas

Hi Tom,

Quoted 7 lines
Quoted 3 lines

arch/arm/cpu/armv8/u-boot.lds and arch/arm/mach-omap2/u-boot-spl.lds can use the same alignment. Is the omap2 case covered by the TI patches? I think it's better if you bundle this up in this series

Correct, the TI patches fix omap2 (and a number of other platforms, that linker script should be renamed, it's the sram+sdram SPL case) platforms. I mentioned needing it in the cover letter btw :)

Ah, I wasn't in the cc list for the cover letter and missed it. I am ok with the TI patches going on a different patchset. Can you amend the arm64 .lds file?

Quoted 3 lines

--
Tom

author
#8 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

Quoted 12 lines · Ilias Apalodimas

Hi Tom

Quoted 9 lines · Tom Rini
Quoted 5 lines · Ilias Apalodimas

Hi Tom,

arch/arm/cpu/armv8/u-boot.lds and arch/arm/mach-omap2/u-boot-spl.lds can use the same alignment. Is the omap2 case covered by the TI patches? I think it's better if you bundle this up in this series

Quoted 7 lines
Quoted 3 lines

Correct, the TI patches fix omap2 (and a number of other platforms, that linker script should be renamed, it's the sram+sdram SPL case) platforms. I mentioned needing it in the cover letter btw :)

Ah, I wasn't in the cc list for the cover letter and missed it. I am ok with the TI patches going on a different patchset. Can you amend the arm64 .lds file?

Yes, I can amend the arm64 .lds file as well for consistency.

Signature · 1 line
Tom
maintainer Tested-by on v1 2/10
#9 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

In reply to Tom Rini
Quoted 404 lines · Tom Rini

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Expands some linker sections to be more readable when adding a second statement to the section.
- Aligns the final section before _end (for U-Boot) or _image_binary_end or __bss_end (for xPL phases) by 8-bytes by adding '. = ALIGN(8);' to the final section before the symbol.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).
- Remove now-spurious '. = ALIGN(x);' statements that were intended to provide the above alignments.

---
The only part of this I am only mostly rather than fully confident in is having caught all cases of having SPL_SEPARATE_BSS being false. I believe I have as the generic ARM SPL linker script enforces the BSS ending with 8-byte alignment, and the point of the ASSERTs here is to catch the case where the section we're adding the ALIGN to ends up being empty and so that ALIGN would become useless.

Cc "NXP i.MX U-Boot Team" <[email protected]>
Cc Adam Ford <[email protected]>
Cc Andre Przywara <[email protected]>
Cc Aspeed BMC SW team <[email protected]>
Cc Chia-Wei Wang <[email protected]>
Cc Eugen Hristev <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Ilias Apalodimas <[email protected]>
Cc Jagan Teki <[email protected]>
Cc Joel Stanley <[email protected]>
Cc Kever Yang <[email protected]>
Cc Marek Vasut <[email protected]>
Cc Michal Simek <[email protected]>
Cc Philipp Tomsich <[email protected]>
Cc Richard Henderson <[email protected]>
Cc Ryan Chen <[email protected]>
Cc Stefano Babic <[email protected]>
---
  arch/arm/cpu/arm1136/u-boot-spl.lds            | 8 ++++++--
  arch/arm/cpu/arm926ejs/mxs/u-boot-spl.lds      | 5 ++++-
  arch/arm/cpu/arm926ejs/sunxi/u-boot-spl.lds    | 5 ++++-
  arch/arm/cpu/armv7/sunxi/u-boot-spl.lds        | 5 ++++-
  arch/arm/cpu/armv8/u-boot-spl.lds              | 4 +++-
  arch/arm/cpu/armv8/u-boot.lds                  | 2 ++
  arch/arm/cpu/u-boot-spl.lds                    | 5 ++++-
  arch/arm/cpu/u-boot.lds                        | 4 ++++
  arch/arm/mach-aspeed/ast2600/u-boot-spl.lds    | 4 ++++
  arch/arm/mach-at91/arm926ejs/u-boot-spl.lds    | 9 +++++++--
  arch/arm/mach-at91/armv7/u-boot-spl.lds        | 9 +++++++--
  arch/arm/mach-omap2/u-boot-spl.lds             | 3 +++
  arch/arm/mach-rockchip/u-boot-tpl-v8.lds       | 5 ++++-
  arch/arm/mach-zynq/u-boot-spl.lds              | 6 ++++--
  arch/arm/mach-zynq/u-boot.lds                  | 3 +++
  board/davinci/da8xxevm/u-boot-spl-da850evm.lds | 4 ++++
  board/samsung/common/exynos-uboot-spl.lds      | 5 ++++-
  17 files changed, 71 insertions(+), 15 deletions(-)
arch/arm/cpu/arm1136/u-boot-spl.lds +6 -2
index b7af29183a97..22a9302275ae 100644
@@ -30,8 +30,10 @@ SECTIONS
  	.rodata : { *(SORT_BY_ALIGNMENT(.rodata*)) } >.sram
 
  	. = ALIGN(4);
-	.data : { *(SORT_BY_ALIGNMENT(.data*)) } >.sram
-	. = ALIGN(4);
+	.data : {
+		*(SORT_BY_ALIGNMENT(.data*))
+		. = ALIGN(8);
+	} >.sram
  	__image_copy_end = .;
  	_end = .;
 
@@ -44,3 +46,5 @@ SECTIONS
  		__bss_end = .;
  	} >.sdram
  }
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");
arch/arm/cpu/arm926ejs/mxs/u-boot-spl.lds +4 -1
index 7c6309246f8b..b4adae272eba 100644
@@ -45,7 +45,7 @@ SECTIONS
  		. = ALIGN(4);
  		__bss_start = .;
  		*(.bss*)
-		. = ALIGN(4);
+		. = ALIGN(8);
  		__bss_end = .;
  	}
 
@@ -62,3 +62,6 @@ SECTIONS
  	.gnu : { *(.gnu*) }
  	.ARM.exidx : { *(.ARM.exidx*) }
  }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
arch/arm/cpu/arm926ejs/sunxi/u-boot-spl.lds +4 -1
index cf65e8c46281..2225985c79c0 100644
@@ -31,9 +31,9 @@ SECTIONS
  	. = ALIGN(4);
  	__u_boot_list : {
  		KEEP(*(SORT(__u_boot_list*)));
+		. = ALIGN(8);
  	} > .sram
 
-	. = ALIGN(4);
  	__image_copy_end = .;
  	_end = .;
  	_image_binary_end = .;
@@ -47,3 +47,6 @@ SECTIONS
  		__bss_end = .;
  	} > .sdram
  }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
arch/arm/cpu/armv7/sunxi/u-boot-spl.lds +4 -1
index fb7a789b28b8..e69291d8be6d 100644
@@ -40,9 +40,9 @@ SECTIONS
  	. = ALIGN(4);
  	__u_boot_list : {
  		KEEP(*(SORT(__u_boot_list*)));
+		. = ALIGN(8);
  	} > .sram
 
-	. = ALIGN(4);
  	__image_copy_end = .;
  	_end = .;
  	_image_binary_end = .;
@@ -56,3 +56,6 @@ SECTIONS
  		__bss_end = .;
  	} > .sdram
  }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
arch/arm/cpu/armv8/u-boot-spl.lds +3 -1
index c4f83ec9cfc4..d9963846c4f4 100644
@@ -52,9 +52,9 @@ SECTIONS
  	__u_boot_list : {
  		. = ALIGN(8);
  		KEEP(*(SORT(__u_boot_list*)));
+		. = ALIGN(8);
  	} >.sram
 
-	. = ALIGN(8);
  	__image_copy_end = .;
  	_end = .;
  	_image_binary_end = .;
@@ -89,5 +89,7 @@ SECTIONS
  #endif
  }
 
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
  ASSERT(ADDR(.bss) % 8 == 0, \
         ".bss must be 8-byte aligned");
arch/arm/cpu/armv8/u-boot.lds +2 -0
index f4ce98c82c8d..704e0bf9468d 100644
@@ -175,3 +175,5 @@ SECTIONS
  #include "linux-kernel-image-header-vars.h"
  #endif
  }
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");
arch/arm/cpu/u-boot-spl.lds +4 -1
index 5aecb61ce902..d780a5060774 100644
@@ -51,9 +51,9 @@ SECTIONS
  		__rel_dyn_start = .;
  		*(.rel*)
  		__rel_dyn_end = .;
+		. = ALIGN(8);
  	}
 
-	. = ALIGN(8);
  	_image_binary_end = .;
  	_end = .;
 
@@ -80,6 +80,9 @@ ASSERT(__image_copy_end - __image_copy_start <= (IMAGE_MAX_SIZE), \
  	"SPL image too big");
  #endif
 
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
+
  #if defined(CONFIG_SPL_BSS_MAX_SIZE)
  ASSERT(__bss_end - __bss_start <= (CONFIG_SPL_BSS_MAX_SIZE), \
  	"SPL image BSS too big");
arch/arm/cpu/u-boot.lds +4 -0
index 78aad093d3b2..8e2266a90fe2 100644
@@ -164,6 +164,7 @@ SECTIONS
  		__rel_dyn_start = .;
  		*(.rel*)
  		__rel_dyn_end = .;
+		. = ALIGN(8);
  	}
 
  	_end = .;
@@ -192,3 +193,6 @@ SECTIONS
  	/DISCARD/ : { *(.ARM.exidx*) }
  	/DISCARD/ : { *(.gnu.linkonce.armexidx.*) }
  }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
arch/arm/mach-aspeed/ast2600/u-boot-spl.lds +4 -0
index 9502a7384b53..c9664a6ce566 100644
@@ -59,6 +59,7 @@ SECTIONS
  		__rel_dyn_start = .;
  		*(.rel*)
  		__rel_dyn_end = .;
+		. = ALIGN(8);
  	} > .nor
 
  	_end = .;
@@ -79,6 +80,9 @@ ASSERT(__image_copy_end - __image_copy_start <= (IMAGE_MAX_SIZE), \
  	"SPL image too big");
  #endif
 
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
+
  #if defined(CONFIG_SPL_BSS_MAX_SIZE)
  ASSERT(__bss_end - __bss_start <= (CONFIG_SPL_BSS_MAX_SIZE), \
  	"SPL image BSS too big");
arch/arm/mach-at91/arm926ejs/u-boot-spl.lds +7 -2
index 09cf838cf96e..1af4f7b6524c 100644
@@ -29,9 +29,11 @@ SECTIONS
  	.data : { *(SORT_BY_ALIGNMENT(.data*)) } >.sram
 
  	. = ALIGN(4);
-	__u_boot_list : { KEEP(*(SORT(__u_boot_list*))) } > .sram
+	__u_boot_list : {
+		KEEP(*(SORT(__u_boot_list*)))
+		. = ALIGN(8);
+	} > .sram
 
-	. = ALIGN(4);
  	__image_copy_end = .;
  	_end = .;
  	_image_binary_end = .;
@@ -51,6 +53,9 @@ ASSERT(__image_copy_end - __start <= (IMAGE_MAX_SIZE), \
  	"SPL image too big");
  #endif
 
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
+
  #if defined(CONFIG_SPL_BSS_MAX_SIZE)
  ASSERT(__bss_end - __bss_start <= (CONFIG_SPL_BSS_MAX_SIZE), \
  	"SPL image BSS too big");
arch/arm/mach-at91/armv7/u-boot-spl.lds +7 -2
index 460a91d93ec4..287764df48ff 100644
@@ -36,9 +36,11 @@ SECTIONS
  	.data : { *(SORT_BY_ALIGNMENT(.data*)) } >.sram
 
  	. = ALIGN(4);
-	__u_boot_list : { KEEP(*(SORT(__u_boot_list*))) } > .sram
+	__u_boot_list : {
+		KEEP(*(SORT(__u_boot_list*)))
+		. = ALIGN(8);
+	} > .sram
 
-	. = ALIGN(4);
  	__image_copy_end = .;
  	_end = .;
  	_image_binary_end = .;
@@ -52,3 +54,6 @@ SECTIONS
  		__bss_end = .;
  	} >.sdram
  }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
arch/arm/mach-omap2/u-boot-spl.lds +3 -0
index 5ad169a37b73..86ab692ae390 100644
@@ -55,3 +55,6 @@ SECTIONS
  		__bss_end = .;
  	} >.sdram
  }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
arch/arm/mach-rockchip/u-boot-tpl-v8.lds +4 -1
index 958a1b70aefe..2c0f5c3e5f32 100644
@@ -42,9 +42,9 @@ SECTIONS
  	__u_boot_list : {
  		. = ALIGN(8);
  		KEEP(*(SORT(__u_boot_list*)));
+		. = ALIGN(8);
  	}
 
-	. = ALIGN(8);
  	__image_copy_end = .;
  	_end = .;
  	_image_binary_end = .;
@@ -69,6 +69,9 @@ ASSERT(__image_copy_end - __image_copy_start < (CONFIG_TPL_MAX_SIZE), \
  	"TPL image too big");
  #endif
 
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
+
  #if defined(CONFIG_TPL_BSS_MAX_SIZE)
  ASSERT(__bss_end - __bss_start < (CONFIG_TPL_BSS_MAX_SIZE), \
  	"TPL image BSS too big");
arch/arm/mach-zynq/u-boot-spl.lds +4 -2
index d96a57702886..17f0d7c9b72f 100644
@@ -39,10 +39,9 @@ SECTIONS
  	. = ALIGN(4);
  	__u_boot_list : {
  		KEEP(*(SORT(__u_boot_list*)));
+		. = ALIGN(8);
  	} > .sram
 
-	. = ALIGN(4);
-
  	_image_binary_end = .;
 
  	_end = .;
@@ -62,3 +61,6 @@ SECTIONS
  	/DISCARD/ : { *(.interp*) }
  	/DISCARD/ : { *(.gnu*) }
  }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
arch/arm/mach-zynq/u-boot.lds +3 -0
index f52523edf490..2a8e3399e0bf 100644
@@ -66,6 +66,7 @@ SECTIONS
  		__rel_dyn_start = .;
  		*(.rel*)
  		__rel_dyn_end = .;
+		. = ALIGN(8);
  	}
 
  	_end = .;
@@ -98,3 +99,5 @@ SECTIONS
  	/DISCARD/ : { *(.ARM.exidx*) }
  	/DISCARD/ : { *(.gnu.linkonce.armexidx.*) }
  }
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");
board/davinci/da8xxevm/u-boot-spl-da850evm.lds +4 -0
index 56d6f4f114b9..d1a82e118af1 100644
@@ -43,6 +43,7 @@ SECTIONS
  		__rel_dyn_start = .;
  		*(.rel*)
  		__rel_dyn_end = .;
+		. = ALIGN(8);
  	} >.sram
 
  	__image_copy_end = .;
@@ -58,3 +59,6 @@ SECTIONS
  		__bss_end = .;
  	} >.sdram
  }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
board/samsung/common/exynos-uboot-spl.lds +0 -0
index 9d3b57e98dbb..62e150bcf335 100644
@@ -48,7 +48,10 @@ SECTIONS
  		. = ALIGN(4);

board/samsung/common/exynos-uboot-spl.lds SECTIONS · line 57

Quoted 10 lines
board/samsung/common/exynos-uboot-spl.lds +4 -1
  		__bss_start = .;
  		*(.bss*)
-		. = ALIGN(4);
+		. = ALIGN(8);
  		__bss_end = .;
  	} >.sram
  }
+
+ASSERT(__bss_end % 8 == 0, \
+       "__bss_end must be 8-byte aligned for device tree");

Thanks,
Michal

reviewer
#10 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

In reply to Tom Rini

Hi Tom,

Quoted 18 lines · Tom Rini

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Expands some linker sections to be more readable when adding a second statement to the section.
- Aligns the final section before _end (for U-Boot) or _image_binary_end or __bss_end (for xPL phases) by 8-bytes by adding '. = ALIGN(8);' to the final section before the symbol.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).
- Remove now-spurious '. = ALIGN(x);' statements that were intended to provide the above alignments.

Quoted 8 lines

---
The only part of this I am only mostly rather than fully confident in is having caught all cases of having SPL_SEPARATE_BSS being false. I believe I have as the generic ARM SPL linker script enforces the BSS ending with 8-byte alignment, and the point of the ASSERTs here is to catch the case where the section we're adding the ALIGN to ends up being empty and so that ALIGN would become useless.

I'm working on bringing up Rockchip RV1103 (ARMv7 SoC, no custom .lds file)

After this patch is applied, the board does not boot anymore:

Missing DTB
spl_early_init() failed: -2
### ERROR ### Please RESET the board ###

If I force "imply SPL_SEPARATE_BSS" in the SoC Kconfig, the board boots again.

In this case, the build shows some warnings:

LD spl/u-boot-spl
/usr/bin/arm-linux-gnueabihf-ld: invalid length for memory region .sram /usr/bin/arm-linux-gnueabihf-ld: invalid origin for memory region .sdram /usr/bin/arm-linux-gnueabihf-ld: invalid length for memory region .sdram
OBJCOPY spl/u-boot-spl-nodtb.bin

  SYM     spl/u-boot-spl.sym
  CAT     spl/u-boot-spl-dtb.bin
  COPY    spl/u-boot-spl.bin
  BINMAN  .binman_stamp
  OFCHK   .config

RV1108 is also an ARMv7 without SPL_SEPARATE_BSS, so I believe it is also affected by this change.

What do you suggest?

Thanks

reviewer
#11 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

Quoted 2 lines · Fabio Estevam

RV1108 is also an ARMv7 without SPL_SEPARATE_BSS, so I believe it is also affected by this change.

The change below restores the boot:

arch/arm/cpu/u-boot-spl.lds +1 -0
index d780a5060774..fc2b7fcb969f 100644
@@ -40,6 +40,7 @@ SECTIONS
        .binman_sym_table : {
                __binman_sym_start = .;
                KEEP(*(SORT(.binman_sym*)));
+               . = ALIGN(8);
                __binman_sym_end = .;
        }
 

If you agree, I can send a formal patch.

#12 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

Quoted 19 lines · Fabio Estevam
Quoted 2 lines · Fabio Estevam

RV1108 is also an ARMv7 without SPL_SEPARATE_BSS, so I believe it is also affected by this change.

The change below restores the boot:

arch/arm/cpu/u-boot-spl.lds +1 -0
index d780a5060774..fc2b7fcb969f 100644
@@ -40,6 +40,7 @@ SECTIONS
         .binman_sym_table : {
                 __binman_sym_start = .;
                 KEEP(*(SORT(.binman_sym*)));
+               . = ALIGN(8);
                 __binman_sym_end = .;
         }
 
Quoted 1 line

If you agree, I can send a formal patch.

Shouldn't we instead find a way to surely align ONLY the _image_binary_end or __bss_end symbols instead of adding random ALIGN(8) into the linker scripts ?

author
#13 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

Quoted 20 lines · Marek Vasut
Quoted 19 lines · Fabio Estevam
Quoted 2 lines · Fabio Estevam

RV1108 is also an ARMv7 without SPL_SEPARATE_BSS, so I believe it is also affected by this change.

The change below restores the boot:

arch/arm/cpu/u-boot-spl.lds +1 -0
index d780a5060774..fc2b7fcb969f 100644
@@ -40,6 +40,7 @@ SECTIONS
         .binman_sym_table : {
                 __binman_sym_start = .;
                 KEEP(*(SORT(.binman_sym*)));
+               . = ALIGN(8);
                 __binman_sym_end = .;
         }
 
Quoted 5 lines
Quoted 1 line

If you agree, I can send a formal patch.

Shouldn't we instead find a way to surely align ONLY the _image_binary_end or __bss_end symbols instead of adding random ALIGN(8) into the linker scripts ?

We did that, yes. I'm not sure what Fabio is running in to here..

Signature · 1 line
Tom
reviewer
#14 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

Hi Tom and Marek,

Quoted 1 line · Tom Rini

We did that, yes. I'm not sure what Fabio is running in to here..

Let me share more information with you.

The board I am working on is based on Rockchip RV1103 (ARMv7) and will submit it upstream soon.

The board was booting fin last week. Yesterday, after rebasing it against the top of the tree U-Boot, the board no longer boots.

The boot error is:

Missing DTB
spl_early_init() failed: -2
### ERROR ### Please RESET the board ###

After running "git bisect", I found Tom's commit 8b0ebe054bb3 ("arm:
Update linker scripts to ensure appended device tree is aligned") to be the guilty one.

If I partially revert the arm/cpu/u-boot-spl.lds change, as shown below, the board boots again:

arch/arm/cpu/u-boot-spl.lds +1 -1
@@ -51,9 +51,9 @@ SECTIONS
                __rel_dyn_start = .;
                *(.rel*)
                __rel_dyn_end = .;
-               . = ALIGN(8);
        }
 
+       . = ALIGN(8);
        _image_binary_end = .;
        _end = .;
 

With Tom's commit applied (failing case), the spl/u-boot-spl.map looks like this:

.rel.dyn 0x0000000000015cac 0x4

                0x0000000000015cac                __rel_dyn_start = .
 *(.rel*)
 .rel.iplt      0x0000000000015cac        0x0 arch/arm/cpu/armv7/start.o
                0x0000000000015cac                __rel_dyn_end = .
                0x0000000000015cb0                . = ALIGN (0x8)
 *fill*         0x0000000000015cac        0x4
                0x0000000000015cb0                _image_binary_end = .
                0x0000000000015cb0                _end = .

With the partial revert above (booting case):

.rel.dyn 0x0000000000015cac 0x0

                0x0000000000015cac                __rel_dyn_start = .
 *(.rel*)
 .rel.iplt      0x0000000000015cac        0x0 arch/arm/cpu/armv7/start.o
                0x0000000000015cac                __rel_dyn_end = .
                0x0000000000015cb0                . = ALIGN (0x8)
                0x0000000000015cb0                _image_binary_end = .
                0x0000000000015cb0                _end = .

Basically, in the good case, .rel.dyn is zero. In the failing case:
.rel.dyn is 0x4 and *fill* is 0x4 as well.

This change messes with dtb being found in SPL.

What would be a proper fix?

Thanks

author
#15 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

Quoted 10 lines · Fabio Estevam

Hi Tom and Marek,

Quoted 1 line · Tom Rini

We did that, yes. I'm not sure what Fabio is running in to here..

Let me share more information with you.

The board I am working on is based on Rockchip RV1103 (ARMv7) and will submit it upstream soon.

Can you please share it with my off-list maybe? I'm still confused as to where the "sram" and "sdram" parts are coming from.

Quoted 53 lines

The board was booting fin last week. Yesterday, after rebasing it against the top of the tree U-Boot, the board no longer boots.

The boot error is:

Missing DTB
spl_early_init() failed: -2
### ERROR ### Please RESET the board ###

After running "git bisect", I found Tom's commit 8b0ebe054bb3 ("arm:
Update linker scripts to ensure appended device tree is aligned") to be the guilty one.

If I partially revert the arm/cpu/u-boot-spl.lds change, as shown below, the board boots again:

arch/arm/cpu/u-boot-spl.lds +1 -1
@@ -51,9 +51,9 @@ SECTIONS
                __rel_dyn_start = .;
                *(.rel*)
                __rel_dyn_end = .;
-               . = ALIGN(8);
        }
 
+       . = ALIGN(8);
        _image_binary_end = .;
        _end = .;
 

With Tom's commit applied (failing case), the spl/u-boot-spl.map looks like this:

.rel.dyn 0x0000000000015cac 0x4

                0x0000000000015cac                __rel_dyn_start = .
 *(.rel*)
 .rel.iplt      0x0000000000015cac        0x0 arch/arm/cpu/armv7/start.o
                0x0000000000015cac                __rel_dyn_end = .
                0x0000000000015cb0                . = ALIGN (0x8)
 *fill*         0x0000000000015cac        0x4
                0x0000000000015cb0                _image_binary_end = .
                0x0000000000015cb0                _end = .

With the partial revert above (booting case):

.rel.dyn 0x0000000000015cac 0x0

                0x0000000000015cac                __rel_dyn_start = .
 *(.rel*)
 .rel.iplt      0x0000000000015cac        0x0 arch/arm/cpu/armv7/start.o
                0x0000000000015cac                __rel_dyn_end = .
                0x0000000000015cb0                . = ALIGN (0x8)
                0x0000000000015cb0                _image_binary_end = .
                0x0000000000015cb0                _end = .
Quoted 6 lines

Basically, in the good case, .rel.dyn is zero. In the failing case:
.rel.dyn is 0x4 and *fill* is 0x4 as well.

This change messes with dtb being found in SPL.

What would be a proper fix?

Well, where is the dtb ending up in the resulting binary? The addresses are aligned correctly, but the dtb isn't where it's supposed to be, where is it instead? A challenge here is that I could only check the linker script used by about half of the 32bit ARM boards (arch/arm/mach-omap2/u-boot-spl.lds) and not the one used by the other half (arch/arm/cpu/u-boot-spl.lds). The initial error you reported makes me wonder if we can somehow unify these two afterall, which would be good in general to do.

Signature · 1 line
Tom
reviewer
#16 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

Quoted 1 line · Tom Rini

Can you please share it with my off-list maybe? I'm still confused as to

My work-in-progress tree is at:

https://github.com/fabioestevam/u-boot/commits/rv1103_prep/

This tree boots fine. After rebasing these patches to the top of the tree, it fails to boot.

Quoted 8 lines

Well, where is the dtb ending up in the resulting binary? The addresses are aligned correctly, but the dtb isn't where it's supposed to be, where is it instead? A challenge here is that I could only check the linker script used by about half of the 32bit ARM boards (arch/arm/mach-omap2/u-boot-spl.lds) and not the one used by the other half (arch/arm/cpu/u-boot-spl.lds). The initial error you reported makes me wonder if we can somehow unify these two afterall, which would be good in general to do.

The spl/u-boot-spl.bin file is 4 bytes longer in the failing case.

Let me know if you need any further clarification or if you'd like me to test something.

Thanks

author
#17 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

Quoted 20 lines · Fabio Estevam
Quoted 1 line · Tom Rini

Can you please share it with my off-list maybe? I'm still confused as to

My work-in-progress tree is at:

https://github.com/fabioestevam/u-boot/commits/rv1103_prep/

This tree boots fine. After rebasing these patches to the top of the tree, it fails to boot.

Quoted 8 lines

Well, where is the dtb ending up in the resulting binary? The addresses are aligned correctly, but the dtb isn't where it's supposed to be, where is it instead? A challenge here is that I could only check the linker script used by about half of the 32bit ARM boards (arch/arm/mach-omap2/u-boot-spl.lds) and not the one used by the other half (arch/arm/cpu/u-boot-spl.lds). The initial error you reported makes me wonder if we can somehow unify these two afterall, which would be good in general to do.

Quoted 4 lines

The spl/u-boot-spl.bin file is 4 bytes longer in the failing case.

Let me know if you need any further clarification or if you'd like me to test something.

Oh, does
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
also fix it for you, or no? Trying to figure out which case we're hitting now..

Signature · 1 line
Tom
author
#19 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

In reply to Fabio Estevam
Quoted 10 lines · Fabio Estevam
Quoted 1 line · Tom Rini

Can you please share it with my off-list maybe? I'm still confused as to

My work-in-progress tree is at:

https://github.com/fabioestevam/u-boot/commits/rv1103_prep/

This tree boots fine. After rebasing these patches to the top of the tree, it fails to boot.

OK. FWIW, I can't reproduce those linker messages about ".sdram" and ".sram", even when I point ROCKCHIP_TPL at the right binary file (per the docs).

Quoted 9 lines
Quoted 8 lines

Well, where is the dtb ending up in the resulting binary? The addresses are aligned correctly, but the dtb isn't where it's supposed to be, where is it instead? A challenge here is that I could only check the linker script used by about half of the 32bit ARM boards (arch/arm/mach-omap2/u-boot-spl.lds) and not the one used by the other half (arch/arm/cpu/u-boot-spl.lds). The initial error you reported makes me wonder if we can somehow unify these two afterall, which would be good in general to do.

Quoted 4 lines

The spl/u-boot-spl.bin file is 4 bytes longer in the failing case.

Let me know if you need any further clarification or if you'd like me to test something.

I think you need to figure out where the mismatch is between where the device tree is appended in the binary, and where it's expected to be, in the binary, and then why something is writing it to the incorrect spot. At run time, in xPL (and this is lib/fdtdec.c) we look at either _image_binary_end if SEPARATE_BSS is enabled, or __bss_end if not. Looking at the config, I see we are not SEPARATE_BSS here, so it needs to be at __bss_end. And in both works and fails branches (my own quick rebase -q origin/master), for me, __bss_end is the same location.

Signature · 1 line
Tom
reviewer
#20 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

Quoted 3 lines · Tom Rini

OK. FWIW, I can't reproduce those linker messages about ".sdram" and ".sram", even when I point ROCKCHIP_TPL at the right binary file (per the docs).

I only see these messages if I force SPL_SEPARATE_BSS.

The board boots despite these messages.

Quoted 8 lines

I think you need to figure out where the mismatch is between where the device tree is appended in the binary, and where it's expected to be, in the binary, and then why something is writing it to the incorrect spot. At run time, in xPL (and this is lib/fdtdec.c) we look at either _image_binary_end if SEPARATE_BSS is enabled, or __bss_end if not. Looking at the config, I see we are not SEPARATE_BSS here, so it needs to be at __bss_end. And in both works and fails branches (my own quick rebase -q origin/master), for me, __bss_end is the same location.

The dtb is placed at shifted-by-4 offset after the commit in Subject line:

With 8b0ebe054bb3 ("arm: Update linker scripts to ensure appended device tree is aligned"):

$ hexdump -Cv spl/u-boot-spl.bin | grep 'd0 0d fe ed'
000029f0  d0 0d fe ed 00 29 05 db  8a 18 03 d2 43 6a 1b ba  |.....)......Cj..|
00015f10  00 00 00 00 d0 0d fe ed  00 00 0a 43 00 00 00 38  |...........C...8|

Because of this shift the dtb cannot be found and the boot fails.

With 8b0ebe054bb3 ("arm: Update linker scripts to ensure appended device tree is aligned") reverted"

$ hexdump -Cv spl/u-boot-spl.bin | grep 'd0 0d fe ed'
000029f0  d0 0d fe ed 00 29 05 db  8a 18 03 d2 43 6a 1b ba  |.....)......Cj..|
00015f10  d0 0d fe ed 00 00 0a 43  00 00 00 38 00 00 08 a8  |.......C...8....|

Here the dtb is found and boot proceeds.

author
#21 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

Quoted 9 lines · Fabio Estevam
Quoted 3 lines · Tom Rini

OK. FWIW, I can't reproduce those linker messages about ".sdram" and ".sram", even when I point ROCKCHIP_TPL at the right binary file (per the docs).

I only see these messages if I force SPL_SEPARATE_BSS.

The board boots despite these messages.

So with SEPARATE_BSS the dtb is found where it's expected to be? But that then brings us back to what I'm saying..

Quoted 10 lines
Quoted 8 lines

I think you need to figure out where the mismatch is between where the device tree is appended in the binary, and where it's expected to be, in the binary, and then why something is writing it to the incorrect spot. At run time, in xPL (and this is lib/fdtdec.c) we look at either _image_binary_end if SEPARATE_BSS is enabled, or __bss_end if not. Looking at the config, I see we are not SEPARATE_BSS here, so it needs to be at __bss_end. And in both works and fails branches (my own quick rebase -q origin/master), for me, __bss_end is the same location.

The dtb is placed at shifted-by-4 offset after the commit in Subject line:

What's appending the dtb there? With SPL_SEPARATE_BSS off it needs to be at __bss_end, and that's the same location for me, in both cases.

Signature · 1 line
Tom
reviewer
#22 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

Quoted 2 lines · Tom Rini

So with SEPARATE_BSS the dtb is found where it's expected to be? But that then brings us back to what I'm saying..

I retried with SEPARATE_BSS, and it also does not boot. Sorry for the confusion.

Quoted 2 lines

What's appending the dtb there? With SPL_SEPARATE_BSS off it needs to be at __bss_end, and that's the same location for me, in both cases.

Correct: spl/u-boot-spl.map shows:

                0x0000000000015f10                __bss_end = .

So the dtb should be present at 0x15f10.

The commit in the Subject is what appends 4 bytes, and the binary is now shifted, causing the boot failure:

hexdump -Cv spl/u-boot-spl.bin | grep 'd0 0d fe ed'
00015f10 00 00 00 00 d0 0d fe ed 00 00 0a 43 00 00 00 38 |...........C...8|

reviewer
#23 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

Quoted 5 lines · Fabio Estevam

The commit in the Subject is what appends 4 bytes, and the binary is now shifted, causing the boot failure:

hexdump -Cv spl/u-boot-spl.bin | grep 'd0 0d fe ed'
00015f10 00 00 00 00 d0 0d fe ed 00 00 0a 43 00 00 00 38 |...........C...8|

To make things simple, let's use a supported board in mainline.

Please follow these steps to reproduce the bug:

U-Boot top-of-tree:

make mrproper
make sonoff-ihost-rv1126_defconfig
cat spl/u-boot-spl.map | grep __bss_end

                0x000000000000b468                __bss_end = .
                0x0000000000000054                __bss_size =

(__bss_end - __bss_start)

hexdump -Cv spl/u-boot-spl.bin | grep 'd0 0d fe ed'

000016d0  a9 98 00 00 15 15 00 00  d0 0d fe ed 48 99 00 00  |............H...|
00001d20  08 00 70 47 6f f0 12 00  70 47 00 bf d0 0d fe ed  |..pGo...pG......|
0000b460  00 00 00 00 00 00 00 00  00 00 00 00 d0 0d fe ed  |................|

b468 contains 00 00 00 00 instead of FDT_MAGIC. FDT_MAGIC appears at b468 + 4.

After reverting 8b0ebe054bb3334c6ca9bed018360b08d4ddc7a4:

cat spl/u-boot-spl.map | grep __bss_end

                0x000000000000b468                __bss_end = .
                0x0000000000000054                __bss_size =
(__bss_end - __bss_start)
hexdump -Cv spl/u-boot-spl.bin | grep 'd0 0d fe ed'
000016d0  a9 98 00 00 15 15 00 00  d0 0d fe ed 48 99 00 00  |............H...|
00001d20  08 00 70 47 6f f0 12 00  70 47 00 bf d0 0d fe ed  |..pGo...pG......|
0000b460  00 00 00 00 00 00 00 00  d0 0d fe ed 00 00 0d 95  |................|

b468 contains FDT_MAGIC as expected.

author
#24 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

Quoted 39 lines · Fabio Estevam
Quoted 5 lines · Fabio Estevam

The commit in the Subject is what appends 4 bytes, and the binary is now shifted, causing the boot failure:

hexdump -Cv spl/u-boot-spl.bin | grep 'd0 0d fe ed'
00015f10 00 00 00 00 d0 0d fe ed 00 00 0a 43 00 00 00 38 |...........C...8|

To make things simple, let's use a supported board in mainline.

Please follow these steps to reproduce the bug:

U-Boot top-of-tree:

make mrproper
make sonoff-ihost-rv1126_defconfig
cat spl/u-boot-spl.map | grep __bss_end

                0x000000000000b468                __bss_end = .
                0x0000000000000054                __bss_size =

(__bss_end - __bss_start)

hexdump -Cv spl/u-boot-spl.bin | grep 'd0 0d fe ed'

000016d0  a9 98 00 00 15 15 00 00  d0 0d fe ed 48 99 00 00  |............H...|
00001d20  08 00 70 47 6f f0 12 00  70 47 00 bf d0 0d fe ed  |..pGo...pG......|
0000b460  00 00 00 00 00 00 00 00  00 00 00 00 d0 0d fe ed  |................|

b468 contains 00 00 00 00 instead of FDT_MAGIC. FDT_MAGIC appears at b468 + 4.

After reverting 8b0ebe054bb3334c6ca9bed018360b08d4ddc7a4:

cat spl/u-boot-spl.map | grep __bss_end

                0x000000000000b468                __bss_end = .
                0x0000000000000054                __bss_size =
(__bss_end - __bss_start)
hexdump -Cv spl/u-boot-spl.bin | grep 'd0 0d fe ed'
000016d0  a9 98 00 00 15 15 00 00  d0 0d fe ed 48 99 00 00  |............H...|
00001d20  08 00 70 47 6f f0 12 00  70 47 00 bf d0 0d fe ed  |..pGo...pG......|
0000b460  00 00 00 00 00 00 00 00  d0 0d fe ed 00 00 0d 95  |................|
Quoted 1 line

b468 contains FDT_MAGIC as expected.

So this:

arch/arm/cpu/u-boot-spl.lds +1 -1
index d780a5060774..dcc201c30482 100644
@@ -50,8 +50,8 @@ SECTIONS
 	.rel.dyn : {
 		__rel_dyn_start = .;
 		*(.rel*)
-		__rel_dyn_end = .;
 		. = ALIGN(8);
+		__rel_dyn_end = .;
 	}
 
 	_image_binary_end = .;

Will shift the dtb location lower and __rel_dyn_end 4 bytes higher. Which is probably fine.

Signature · 1 line
Tom
reviewer
#25 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

Quoted 17 lines · Tom Rini

So this:

arch/arm/cpu/u-boot-spl.lds +1 -1
index d780a5060774..dcc201c30482 100644
@@ -50,8 +50,8 @@ SECTIONS
        .rel.dyn : {
                __rel_dyn_start = .;
                *(.rel*)
-               __rel_dyn_end = .;
                . = ALIGN(8);
+               __rel_dyn_end = .;
        }
 
        _image_binary_end = .;
Quoted 2 lines

Will shift the dtb location lower and __rel_dyn_end 4 bytes higher. Which is probably fine.

This change fixes rv1126, but still fails on rv1103:

sonoff-ihost-rv1126_defconfig:

$ cat spl/u-boot-spl.map | grep __bss_end
                0x000000000000b468                __bss_end = .
                0x0000000000000050                __bss_size =
(__bss_end - __bss_start)
$ hexdump -Cv spl/u-boot-spl.bin | grep 'd0 0d fe ed'
000016d0  af 98 00 00 15 15 00 00  d0 0d fe ed 4e 99 00 00  |............N...|
00001d20  08 00 70 47 6f f0 12 00  70 47 00 bf d0 0d fe ed  |..pGo...pG......|
0000b460  00 00 00 00 00 00 00 00  d0 0d fe ed 00 00 0d 95  |................|

dtb is correctly found at 0xb468.

omega4-rv1103_defconfig:

$ cat spl/u-boot-spl.map | grep __bss_end
                0x0000000000015f18                __bss_end = .
                0x0000000000000264                __bss_size =
(__bss_end - __bss_start)
$ hexdump -Cv spl/u-boot-spl.bin | grep 'd0 0d fe ed'
000029f0  d0 0d fe ed 00 29 05 db  8a 18 03 d2 43 6a 1b ba  |.....)......Cj..|
00015f10  00 00 00 00 00 00 00 00  00 00 00 00 d0 0d fe ed  |................|

dtb is not found at 0x15f18.

author
#26 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

Quoted 45 lines · Fabio Estevam
Quoted 17 lines · Tom Rini

So this:

arch/arm/cpu/u-boot-spl.lds +1 -1
index d780a5060774..dcc201c30482 100644
@@ -50,8 +50,8 @@ SECTIONS
        .rel.dyn : {
                __rel_dyn_start = .;
                *(.rel*)
-               __rel_dyn_end = .;
                . = ALIGN(8);
+               __rel_dyn_end = .;
        }
 
        _image_binary_end = .;
Quoted 2 lines

Will shift the dtb location lower and __rel_dyn_end 4 bytes higher. Which is probably fine.

This change fixes rv1126, but still fails on rv1103:

sonoff-ihost-rv1126_defconfig:

$ cat spl/u-boot-spl.map | grep __bss_end
                0x000000000000b468                __bss_end = .
                0x0000000000000050                __bss_size =
(__bss_end - __bss_start)
$ hexdump -Cv spl/u-boot-spl.bin | grep 'd0 0d fe ed'
000016d0  af 98 00 00 15 15 00 00  d0 0d fe ed 4e 99 00 00  |............N...|
00001d20  08 00 70 47 6f f0 12 00  70 47 00 bf d0 0d fe ed  |..pGo...pG......|
0000b460  00 00 00 00 00 00 00 00  d0 0d fe ed 00 00 0d 95  |................|

dtb is correctly found at 0xb468.

omega4-rv1103_defconfig:

$ cat spl/u-boot-spl.map | grep __bss_end
                0x0000000000015f18                __bss_end = .
                0x0000000000000264                __bss_size =
(__bss_end - __bss_start)
Quoted 5 lines
$ hexdump -Cv spl/u-boot-spl.bin | grep 'd0 0d fe ed'
000029f0  d0 0d fe ed 00 29 05 db  8a 18 03 d2 43 6a 1b ba  |.....)......Cj..|
00015f10  00 00 00 00 00 00 00 00  00 00 00 00 d0 0d fe ed  |................|

dtb is not found at 0x15f18.

Keep looking then please, thanks.

Signature · 1 line
Tom
author
#27 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

In reply to Fabio Estevam
Quoted 53 lines · Fabio Estevam

Hi Tom,

Quoted 18 lines · Tom Rini

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Expands some linker sections to be more readable when adding a second statement to the section.
- Aligns the final section before _end (for U-Boot) or _image_binary_end or __bss_end (for xPL phases) by 8-bytes by adding '. = ALIGN(8);' to the final section before the symbol.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).
- Remove now-spurious '. = ALIGN(x);' statements that were intended to provide the above alignments.

Quoted 8 lines

---
The only part of this I am only mostly rather than fully confident in is having caught all cases of having SPL_SEPARATE_BSS being false. I believe I have as the generic ARM SPL linker script enforces the BSS ending with 8-byte alignment, and the point of the ASSERTs here is to catch the case where the section we're adding the ALIGN to ends up being empty and so that ALIGN would become useless.

I'm working on bringing up Rockchip RV1103 (ARMv7 SoC, no custom .lds file)

After this patch is applied, the board does not boot anymore:

Missing DTB
spl_early_init() failed: -2
### ERROR ### Please RESET the board ###

If I force "imply SPL_SEPARATE_BSS" in the SoC Kconfig, the board boots again.

In this case, the build shows some warnings:

LD spl/u-boot-spl
/usr/bin/arm-linux-gnueabihf-ld: invalid length for memory region .sram /usr/bin/arm-linux-gnueabihf-ld: invalid origin for memory region .sdram /usr/bin/arm-linux-gnueabihf-ld: invalid length for memory region .sdram
OBJCOPY spl/u-boot-spl-nodtb.bin

  SYM     spl/u-boot-spl.sym
  CAT     spl/u-boot-spl-dtb.bin
  COPY    spl/u-boot-spl.bin
  BINMAN  .binman_stamp
  OFCHK   .config
Quoted 4 lines

RV1108 is also an ARMv7 without SPL_SEPARATE_BSS, so I believe it is also affected by this change.

What do you suggest?

Where are those memory regions coming from? They aren't specified in arch/arm/cpu/u-boot-spl.lds

Signature · 1 line
Tom
#28 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

In reply to Tom Rini

Hi,

Quoted 17 lines · Tom Rini

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Expands some linker sections to be more readable when adding a second statement to the section.
- Aligns the final section before _end (for U-Boot) or _image_binary_end or __bss_end (for xPL phases) by 8-bytes by adding '. = ALIGN(8);' to the final section before the symbol.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).
- Remove now-spurious '. = ALIGN(x);' statements that were intended to provide the above alignments.

Quoted 1 line

For unclear reasons, this seems to break boot via xmodem protocol on my Synology DS414. I found this commit via 'git bisect'. The symptom is:

| kwboot version 2026.04-rc1-00098-g6ad0cf8f83db
| Detected kwbimage v1 with SPI boot signature
| Patching image boot signature to UART
| Aligning image header to Xmodem block size
| Sending boot message. Please reboot the target...\
| Sending boot image header (67584 bytes)...
|   0 % [......................................................................]
|  13 % [......................................................................]
|  26 % [......................................................................]
|  39 % [......................................................................]
|  53 % [......................................................................]
|  66 % [......................................................................]
|  79 % [......................................................................]
|  92 % [......................................                                ]
| Done
| Missing DTB
| spl_init() failed: -2
| ### ERROR ### Please RESET the board ###
| 
| 
| xmodem: Connection timed out

Debug printf()s in fdtdec_prepare_fdt() show that fdt_check_header() returns -FDT_ERR_BADMAGIC.

With HEAD at a8d982e1f1726 ("x86: cpu: Fix crash on FTRACE enabled builds"), reverting arch/arm/cpu/u-boot-spl.lds like so:

| @@ -41,14 +41,21 @@ SECTIONS
|                 __binman_sym_start = .;
|                 KEEP(*(SORT(.binman_sym*)));
|                 __binman_sym_end = .;
| -               . = ALIGN(8);
|         }
|  
| +       . = ALIGN(4); /* critical! */
|         __image_copy_end = .;
| +       .rel.dyn : {
| +               __rel_dyn_start = .;
| +               *(.rel*)
| +               __rel_dyn_end = .;
| +       }
| +
| +       . = ALIGN(8);
|         _image_binary_end = .;
|         _end = .;
|  
| -       .bss : {
| +       .bss __rel_dyn_start (OVERLAY) : {
|                 __bss_start = .;
|                 *(.bss*)
|                  . = ALIGN(8);

The SPL image starts up again and continues loading the real uboot image. Note that I have no idea what these changes actually do, so I need instructions if I should dig further.

Thanks, Phil

author
#29 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

Quoted 78 lines · Phil Sutter

Hi,

Quoted 17 lines · Tom Rini

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Expands some linker sections to be more readable when adding a second statement to the section.
- Aligns the final section before _end (for U-Boot) or _image_binary_end or __bss_end (for xPL phases) by 8-bytes by adding '. = ALIGN(8);' to the final section before the symbol.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).
- Remove now-spurious '. = ALIGN(x);' statements that were intended to provide the above alignments.

Quoted 1 line

For unclear reasons, this seems to break boot via xmodem protocol on my Synology DS414. I found this commit via 'git bisect'. The symptom is:

| kwboot version 2026.04-rc1-00098-g6ad0cf8f83db
| Detected kwbimage v1 with SPI boot signature
| Patching image boot signature to UART
| Aligning image header to Xmodem block size
| Sending boot message. Please reboot the target...\
| Sending boot image header (67584 bytes)...
|   0 % [......................................................................]
|  13 % [......................................................................]
|  26 % [......................................................................]
|  39 % [......................................................................]
|  53 % [......................................................................]
|  66 % [......................................................................]
|  79 % [......................................................................]
|  92 % [......................................                                ]
| Done
| Missing DTB
| spl_init() failed: -2
| ### ERROR ### Please RESET the board ###
| 
| 
| xmodem: Connection timed out

Debug printf()s in fdtdec_prepare_fdt() show that fdt_check_header() returns -FDT_ERR_BADMAGIC.

With HEAD at a8d982e1f1726 ("x86: cpu: Fix crash on FTRACE enabled builds"), reverting arch/arm/cpu/u-boot-spl.lds like so:

| @@ -41,14 +41,21 @@ SECTIONS
|                 __binman_sym_start = .;
|                 KEEP(*(SORT(.binman_sym*)));
|                 __binman_sym_end = .;
| -               . = ALIGN(8);
|         }
|  
| +       . = ALIGN(4); /* critical! */
|         __image_copy_end = .;
| +       .rel.dyn : {
| +               __rel_dyn_start = .;
| +               *(.rel*)
| +               __rel_dyn_end = .;
| +       }
| +
| +       . = ALIGN(8);
|         _image_binary_end = .;
|         _end = .;
|  
| -       .bss : {
| +       .bss __rel_dyn_start (OVERLAY) : {
|                 __bss_start = .;
|                 *(.bss*)
|                  . = ALIGN(8);
Quoted 3 lines

The SPL image starts up again and continues loading the real uboot image. Note that I have no idea what these changes actually do, so I need instructions if I should dig further.

Does:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
fix it?

Signature · 1 line
Tom
#30 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

Quoted 79 lines · Tom Rini
Quoted 78 lines · Phil Sutter

Hi,

Quoted 17 lines · Tom Rini

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Expands some linker sections to be more readable when adding a second statement to the section.
- Aligns the final section before _end (for U-Boot) or _image_binary_end or __bss_end (for xPL phases) by 8-bytes by adding '. = ALIGN(8);' to the final section before the symbol.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).
- Remove now-spurious '. = ALIGN(x);' statements that were intended to provide the above alignments.

Quoted 1 line

For unclear reasons, this seems to break boot via xmodem protocol on my Synology DS414. I found this commit via 'git bisect'. The symptom is:

| kwboot version 2026.04-rc1-00098-g6ad0cf8f83db
| Detected kwbimage v1 with SPI boot signature
| Patching image boot signature to UART
| Aligning image header to Xmodem block size
| Sending boot message. Please reboot the target...\
| Sending boot image header (67584 bytes)...
|   0 % [......................................................................]
|  13 % [......................................................................]
|  26 % [......................................................................]
|  39 % [......................................................................]
|  53 % [......................................................................]
|  66 % [......................................................................]
|  79 % [......................................................................]
|  92 % [......................................                                ]
| Done
| Missing DTB
| spl_init() failed: -2
| ### ERROR ### Please RESET the board ###
| 
| 
| xmodem: Connection timed out

Debug printf()s in fdtdec_prepare_fdt() show that fdt_check_header() returns -FDT_ERR_BADMAGIC.

With HEAD at a8d982e1f1726 ("x86: cpu: Fix crash on FTRACE enabled builds"), reverting arch/arm/cpu/u-boot-spl.lds like so:

| @@ -41,14 +41,21 @@ SECTIONS
|                 __binman_sym_start = .;
|                 KEEP(*(SORT(.binman_sym*)));
|                 __binman_sym_end = .;
| -               . = ALIGN(8);
|         }
|  
| +       . = ALIGN(4); /* critical! */
|         __image_copy_end = .;
| +       .rel.dyn : {
| +               __rel_dyn_start = .;
| +               *(.rel*)
| +               __rel_dyn_end = .;
| +       }
| +
| +       . = ALIGN(8);
|         _image_binary_end = .;
|         _end = .;
|  
| -       .bss : {
| +       .bss __rel_dyn_start (OVERLAY) : {
|                 __bss_start = .;
|                 *(.bss*)
|                  . = ALIGN(8);
Quoted 7 lines
Quoted 3 lines

The SPL image starts up again and continues loading the real uboot image. Note that I have no idea what these changes actually do, so I need instructions if I should dig further.

Does:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
fix it?

Sadly not, same result.

Thanks for the quick reply!

Cheers, Phil

author
#31 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

Quoted 84 lines · Phil Sutter
Quoted 83 lines · Tom Rini
Quoted 81 lines · Phil Sutter

Hi,

Quoted 17 lines · Tom Rini

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Expands some linker sections to be more readable when adding a second statement to the section.
- Aligns the final section before _end (for U-Boot) or _image_binary_end or __bss_end (for xPL phases) by 8-bytes by adding '. = ALIGN(8);' to the final section before the symbol.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).
- Remove now-spurious '. = ALIGN(x);' statements that were intended to provide the above alignments.

Quoted 1 line

For unclear reasons, this seems to break boot via xmodem protocol on my Synology DS414. I found this commit via 'git bisect'. The symptom is:

| kwboot version 2026.04-rc1-00098-g6ad0cf8f83db
| Detected kwbimage v1 with SPI boot signature
| Patching image boot signature to UART
| Aligning image header to Xmodem block size
| Sending boot message. Please reboot the target...\
| Sending boot image header (67584 bytes)...
|   0 % [......................................................................]
|  13 % [......................................................................]
|  26 % [......................................................................]
|  39 % [......................................................................]
|  53 % [......................................................................]
|  66 % [......................................................................]
|  79 % [......................................................................]
|  92 % [......................................                                ]
| Done
| Missing DTB
| spl_init() failed: -2
| ### ERROR ### Please RESET the board ###
| 
| 
| xmodem: Connection timed out

Debug printf()s in fdtdec_prepare_fdt() show that fdt_check_header() returns -FDT_ERR_BADMAGIC.

With HEAD at a8d982e1f1726 ("x86: cpu: Fix crash on FTRACE enabled builds"), reverting arch/arm/cpu/u-boot-spl.lds like so:

| @@ -41,14 +41,21 @@ SECTIONS
|                 __binman_sym_start = .;
|                 KEEP(*(SORT(.binman_sym*)));
|                 __binman_sym_end = .;
| -               . = ALIGN(8);
|         }
|  
| +       . = ALIGN(4); /* critical! */
|         __image_copy_end = .;
| +       .rel.dyn : {
| +               __rel_dyn_start = .;
| +               *(.rel*)
| +               __rel_dyn_end = .;
| +       }
| +
| +       . = ALIGN(8);
|         _image_binary_end = .;
|         _end = .;
|  
| -       .bss : {
| +       .bss __rel_dyn_start (OVERLAY) : {
|                 __bss_start = .;
|                 *(.bss*)
|                  . = ALIGN(8);

The SPL image starts up again and continues loading the real uboot image. Note that I have no idea what these changes actually do, so I need instructions if I should dig further.

Quoted 5 lines
Quoted 3 lines

Does:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
fix it?

Sadly not, same result.

Ugh. What file, specifically, do you send via xmodem? And so that maybe I can more easily replicate the failure, are you using the kernel.org gcc-14.2.0 toolchain or something else?

Signature · 1 line
Tom
#32 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

Quoted 89 lines · Tom Rini
Quoted 88 lines · Phil Sutter
Quoted 86 lines · Tom Rini
Quoted 78 lines · Phil Sutter

Hi,

Quoted 17 lines · Tom Rini

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Expands some linker sections to be more readable when adding a second statement to the section.
- Aligns the final section before _end (for U-Boot) or _image_binary_end or __bss_end (for xPL phases) by 8-bytes by adding '. = ALIGN(8);' to the final section before the symbol.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).
- Remove now-spurious '. = ALIGN(x);' statements that were intended to provide the above alignments.

Quoted 1 line

For unclear reasons, this seems to break boot via xmodem protocol on my Synology DS414. I found this commit via 'git bisect'. The symptom is:

| kwboot version 2026.04-rc1-00098-g6ad0cf8f83db
| Detected kwbimage v1 with SPI boot signature
| Patching image boot signature to UART
| Aligning image header to Xmodem block size
| Sending boot message. Please reboot the target...\
| Sending boot image header (67584 bytes)...
|   0 % [......................................................................]
|  13 % [......................................................................]
|  26 % [......................................................................]
|  39 % [......................................................................]
|  53 % [......................................................................]
|  66 % [......................................................................]
|  79 % [......................................................................]
|  92 % [......................................                                ]
| Done
| Missing DTB
| spl_init() failed: -2
| ### ERROR ### Please RESET the board ###
| 
| 
| xmodem: Connection timed out

Debug printf()s in fdtdec_prepare_fdt() show that fdt_check_header() returns -FDT_ERR_BADMAGIC.

With HEAD at a8d982e1f1726 ("x86: cpu: Fix crash on FTRACE enabled builds"), reverting arch/arm/cpu/u-boot-spl.lds like so:

| @@ -41,14 +41,21 @@ SECTIONS
|                 __binman_sym_start = .;
|                 KEEP(*(SORT(.binman_sym*)));
|                 __binman_sym_end = .;
| -               . = ALIGN(8);
|         }
|  
| +       . = ALIGN(4); /* critical! */
|         __image_copy_end = .;
| +       .rel.dyn : {
| +               __rel_dyn_start = .;
| +               *(.rel*)
| +               __rel_dyn_end = .;
| +       }
| +
| +       . = ALIGN(8);
|         _image_binary_end = .;
|         _end = .;
|  
| -       .bss : {
| +       .bss __rel_dyn_start (OVERLAY) : {
|                 __bss_start = .;
|                 *(.bss*)
|                  . = ALIGN(8);
Quoted 3 lines

The SPL image starts up again and continues loading the real uboot image. Note that I have no idea what these changes actually do, so I need instructions if I should dig further.

Does:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
fix it?

Quoted 5 lines
Quoted 1 line

Sadly not, same result.

Ugh. What file, specifically, do you send via xmodem? And so that maybe I can more easily replicate the failure, are you using the kernel.org gcc-14.2.0 toolchain or something else?

I am building with a custom-built arm-openadk-linux-uclibceabi-gcc version 14.3.0. Basically what I run is:

MYENV='ARCH=arm CROSS_COMPILE=~/git/openadk-ds414/toolchain_synology-ds414_uclibc-ng_softfp_eabi_arm/usr/bin/arm-openadk-linux-uclibceabi-'

make $MYENV clean && \
for f in $(ls u-boot*.kwb 2>/dev/null); do rm $f; done && \
make $MYENV ds414_defconfig && \
make $MYENV -j12 && \
./tools/kwboot -a -t -p -b u-boot-*spl.kwb /dev/ttyUSB0

With current uboot, this should be u-boot-with-spl.kwb image.

With said patch reverted (or the above changes applied), I produce a working u-boot-with-spl.kwb which loads and boots linux from flash. So my toolchain is at least not totally broken. ;)

Cheers, Phil

author
#33 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

Quoted 107 lines · Phil Sutter
Quoted 89 lines · Tom Rini
Quoted 88 lines · Phil Sutter
Quoted 86 lines · Tom Rini
Quoted 78 lines · Phil Sutter

Hi,

Quoted 17 lines · Tom Rini

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Expands some linker sections to be more readable when adding a second statement to the section.
- Aligns the final section before _end (for U-Boot) or _image_binary_end or __bss_end (for xPL phases) by 8-bytes by adding '. = ALIGN(8);' to the final section before the symbol.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).
- Remove now-spurious '. = ALIGN(x);' statements that were intended to provide the above alignments.

Quoted 1 line

For unclear reasons, this seems to break boot via xmodem protocol on my Synology DS414. I found this commit via 'git bisect'. The symptom is:

| kwboot version 2026.04-rc1-00098-g6ad0cf8f83db
| Detected kwbimage v1 with SPI boot signature
| Patching image boot signature to UART
| Aligning image header to Xmodem block size
| Sending boot message. Please reboot the target...\
| Sending boot image header (67584 bytes)...
|   0 % [......................................................................]
|  13 % [......................................................................]
|  26 % [......................................................................]
|  39 % [......................................................................]
|  53 % [......................................................................]
|  66 % [......................................................................]
|  79 % [......................................................................]
|  92 % [......................................                                ]
| Done
| Missing DTB
| spl_init() failed: -2
| ### ERROR ### Please RESET the board ###
| 
| 
| xmodem: Connection timed out

Debug printf()s in fdtdec_prepare_fdt() show that fdt_check_header() returns -FDT_ERR_BADMAGIC.

With HEAD at a8d982e1f1726 ("x86: cpu: Fix crash on FTRACE enabled builds"), reverting arch/arm/cpu/u-boot-spl.lds like so:

| @@ -41,14 +41,21 @@ SECTIONS
|                 __binman_sym_start = .;
|                 KEEP(*(SORT(.binman_sym*)));
|                 __binman_sym_end = .;
| -               . = ALIGN(8);
|         }
|  
| +       . = ALIGN(4); /* critical! */
|         __image_copy_end = .;
| +       .rel.dyn : {
| +               __rel_dyn_start = .;
| +               *(.rel*)
| +               __rel_dyn_end = .;
| +       }
| +
| +       . = ALIGN(8);
|         _image_binary_end = .;
|         _end = .;
|  
| -       .bss : {
| +       .bss __rel_dyn_start (OVERLAY) : {
|                 __bss_start = .;
|                 *(.bss*)
|                  . = ALIGN(8);
Quoted 3 lines

The SPL image starts up again and continues loading the real uboot image. Note that I have no idea what these changes actually do, so I need instructions if I should dig further.

Does:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
fix it?

Quoted 5 lines
Quoted 1 line

Sadly not, same result.

Ugh. What file, specifically, do you send via xmodem? And so that maybe I can more easily replicate the failure, are you using the kernel.org gcc-14.2.0 toolchain or something else?

I am building with a custom-built arm-openadk-linux-uclibceabi-gcc version 14.3.0. Basically what I run is:

MYENV='ARCH=arm CROSS_COMPILE=~/git/openadk-ds414/toolchain_synology-ds414_uclibc-ng_softfp_eabi_arm/usr/bin/arm-openadk-linux-uclibceabi-'

make $MYENV clean && \
for f in $(ls u-boot*.kwb 2>/dev/null); do rm $f; done && \
make $MYENV ds414_defconfig && \
make $MYENV -j12 && \
./tools/kwboot -a -t -p -b u-boot-*spl.kwb /dev/ttyUSB0

Quoted 5 lines

With current uboot, this should be u-boot-with-spl.kwb image.

With said patch reverted (or the above changes applied), I produce a working u-boot-with-spl.kwb which loads and boots linux from flash. So my toolchain is at least not totally broken. ;)

Right, so, for background, the following threads might shed some light on things:
https://lore.kernel.org/u-boot/CAOMZO5DZNJ+=AP1spWCv7Ar6etf03H=DFVU=mXZcC7QFTGoh_Q@mail.gmail.com/
https://lore.kernel.org/u-boot/[email protected]/

And so to that end, can you please do:
hexdump -Cv u-boot-with-spl.kwb | grep 'd0 0d fe ed'
and let me know what that says? And the first line there should match, content-wise at least (but not quite file offset) spl/u-boot-spl. I was asking about your toolchain because with gcc-14.2.0 from kernel.org:

$ hexdump -Cv /tmp/ds414/spl/u-boot-spl | grep 'd0 0d fe ed'
00002ed0  6f f0 12 00 70 47 00 bf  d0 0d fe ed 00 29 05 db  |o...pG.......)..|
$ hexdump -Cv /tmp/ds414/u-boot-with-spl.kwb | grep 'd0 0d fe ed'
00001ed0  6f f0 12 00 70 47 00 bf  d0 0d fe ed 00 29 05 db  |o...pG.......)..|

And while this should then *work* that's luck and not design. If you can confirm that instead 'd0 0d fe ed' is in the middle (and so 4 byte but not 8 byte aligned) it'll at least be the same symptom as before.

Signature · 1 line
Tom
#34 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

Quoted 124 lines · Tom Rini
Quoted 107 lines · Phil Sutter
Quoted 89 lines · Tom Rini
Quoted 88 lines · Phil Sutter
Quoted 86 lines · Tom Rini
Quoted 78 lines · Phil Sutter

Hi,

Quoted 17 lines · Tom Rini

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Expands some linker sections to be more readable when adding a second statement to the section.
- Aligns the final section before _end (for U-Boot) or _image_binary_end or __bss_end (for xPL phases) by 8-bytes by adding '. = ALIGN(8);' to the final section before the symbol.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).
- Remove now-spurious '. = ALIGN(x);' statements that were intended to provide the above alignments.

Quoted 1 line

For unclear reasons, this seems to break boot via xmodem protocol on my Synology DS414. I found this commit via 'git bisect'. The symptom is:

| kwboot version 2026.04-rc1-00098-g6ad0cf8f83db
| Detected kwbimage v1 with SPI boot signature
| Patching image boot signature to UART
| Aligning image header to Xmodem block size
| Sending boot message. Please reboot the target...\
| Sending boot image header (67584 bytes)...
|   0 % [......................................................................]
|  13 % [......................................................................]
|  26 % [......................................................................]
|  39 % [......................................................................]
|  53 % [......................................................................]
|  66 % [......................................................................]
|  79 % [......................................................................]
|  92 % [......................................                                ]
| Done
| Missing DTB
| spl_init() failed: -2
| ### ERROR ### Please RESET the board ###
| 
| 
| xmodem: Connection timed out

Debug printf()s in fdtdec_prepare_fdt() show that fdt_check_header() returns -FDT_ERR_BADMAGIC.

With HEAD at a8d982e1f1726 ("x86: cpu: Fix crash on FTRACE enabled builds"), reverting arch/arm/cpu/u-boot-spl.lds like so:

| @@ -41,14 +41,21 @@ SECTIONS
|                 __binman_sym_start = .;
|                 KEEP(*(SORT(.binman_sym*)));
|                 __binman_sym_end = .;
| -               . = ALIGN(8);
|         }
|  
| +       . = ALIGN(4); /* critical! */
|         __image_copy_end = .;
| +       .rel.dyn : {
| +               __rel_dyn_start = .;
| +               *(.rel*)
| +               __rel_dyn_end = .;
| +       }
| +
| +       . = ALIGN(8);
|         _image_binary_end = .;
|         _end = .;
|  
| -       .bss : {
| +       .bss __rel_dyn_start (OVERLAY) : {
|                 __bss_start = .;
|                 *(.bss*)
|                  . = ALIGN(8);
Quoted 3 lines

The SPL image starts up again and continues loading the real uboot image. Note that I have no idea what these changes actually do, so I need instructions if I should dig further.

Does:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
fix it?

Quoted 5 lines
Quoted 1 line

Sadly not, same result.

Ugh. What file, specifically, do you send via xmodem? And so that maybe I can more easily replicate the failure, are you using the kernel.org gcc-14.2.0 toolchain or something else?

I am building with a custom-built arm-openadk-linux-uclibceabi-gcc version 14.3.0. Basically what I run is:

MYENV='ARCH=arm CROSS_COMPILE=~/git/openadk-ds414/toolchain_synology-ds414_uclibc-ng_softfp_eabi_arm/usr/bin/arm-openadk-linux-uclibceabi-'

make $MYENV clean && \
for f in $(ls u-boot*.kwb 2>/dev/null); do rm $f; done && \
make $MYENV ds414_defconfig && \
make $MYENV -j12 && \
./tools/kwboot -a -t -p -b u-boot-*spl.kwb /dev/ttyUSB0

Quoted 5 lines

With current uboot, this should be u-boot-with-spl.kwb image.

With said patch reverted (or the above changes applied), I produce a working u-boot-with-spl.kwb which loads and boots linux from flash. So my toolchain is at least not totally broken. ;)

Right, so, for background, the following threads might shed some light on things:
https://lore.kernel.org/u-boot/CAOMZO5DZNJ+=AP1spWCv7Ar6etf03H=DFVU=mXZcC7QFTGoh_Q@mail.gmail.com/
https://lore.kernel.org/u-boot/[email protected]/

And so to that end, can you please do:
hexdump -Cv u-boot-with-spl.kwb | grep 'd0 0d fe ed'
and let me know what that says? And the first line there should match, content-wise at least (but not quite file offset) spl/u-boot-spl. I was asking about your toolchain because with gcc-14.2.0 from kernel.org:

Quoted 4 lines
$ hexdump -Cv /tmp/ds414/spl/u-boot-spl | grep 'd0 0d fe ed'
00002ed0  6f f0 12 00 70 47 00 bf  d0 0d fe ed 00 29 05 db  |o...pG.......)..|
$ hexdump -Cv /tmp/ds414/u-boot-with-spl.kwb | grep 'd0 0d fe ed'
00001ed0  6f f0 12 00 70 47 00 bf  d0 0d fe ed 00 29 05 db  |o...pG.......)..|

This is with HEAD at a8d982e1f17 + your "spl: Ensure final section before BSS is non-empty" applied:

% hexdump -Cv u-boot-with-spl.kwb | grep 'd0 0d fe ed' | head -n1 00001ed0 6f f0 12 00 70 47 00 bf d0 0d fe ed 00 29 05 db |o...pG.......)..|

% hexdump -Cv spl/u-boot-spl | grep 'd0 0d fe ed'
00002ed0 6f f0 12 00 70 47 00 bf d0 0d fe ed 00 29 05 db |o...pG.......)..|

Quoted 3 lines

And while this should then *work* that's luck and not design. If you can confirm that instead 'd0 0d fe ed' is in the middle (and so 4 byte but not 8 byte aligned) it'll at least be the same symptom as before.

Hmm. My dumps indicate correct 8B alignment, right? Switching over to a branch which has the problematic commit reverted and produced images work, I get exactly the same output from hexdump on those files, BTW. Does that mean we're on the wrong track and my problem is not wrong DTB alignment?

Cheers, Phil

author
#35 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

Quoted 139 lines · Phil Sutter
Quoted 124 lines · Tom Rini
Quoted 107 lines · Phil Sutter
Quoted 89 lines · Tom Rini
Quoted 88 lines · Phil Sutter
Quoted 86 lines · Tom Rini
Quoted 78 lines · Phil Sutter

Hi,

Quoted 17 lines · Tom Rini

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Expands some linker sections to be more readable when adding a second statement to the section.
- Aligns the final section before _end (for U-Boot) or _image_binary_end or __bss_end (for xPL phases) by 8-bytes by adding '. = ALIGN(8);' to the final section before the symbol.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).
- Remove now-spurious '. = ALIGN(x);' statements that were intended to provide the above alignments.

Quoted 1 line

For unclear reasons, this seems to break boot via xmodem protocol on my Synology DS414. I found this commit via 'git bisect'. The symptom is:

| kwboot version 2026.04-rc1-00098-g6ad0cf8f83db
| Detected kwbimage v1 with SPI boot signature
| Patching image boot signature to UART
| Aligning image header to Xmodem block size
| Sending boot message. Please reboot the target...\
| Sending boot image header (67584 bytes)...
|   0 % [......................................................................]
|  13 % [......................................................................]
|  26 % [......................................................................]
|  39 % [......................................................................]
|  53 % [......................................................................]
|  66 % [......................................................................]
|  79 % [......................................................................]
|  92 % [......................................                                ]
| Done
| Missing DTB
| spl_init() failed: -2
| ### ERROR ### Please RESET the board ###
| 
| 
| xmodem: Connection timed out

Debug printf()s in fdtdec_prepare_fdt() show that fdt_check_header() returns -FDT_ERR_BADMAGIC.

With HEAD at a8d982e1f1726 ("x86: cpu: Fix crash on FTRACE enabled builds"), reverting arch/arm/cpu/u-boot-spl.lds like so:

| @@ -41,14 +41,21 @@ SECTIONS
|                 __binman_sym_start = .;
|                 KEEP(*(SORT(.binman_sym*)));
|                 __binman_sym_end = .;
| -               . = ALIGN(8);
|         }
|  
| +       . = ALIGN(4); /* critical! */
|         __image_copy_end = .;
| +       .rel.dyn : {
| +               __rel_dyn_start = .;
| +               *(.rel*)
| +               __rel_dyn_end = .;
| +       }
| +
| +       . = ALIGN(8);
|         _image_binary_end = .;
|         _end = .;
|  
| -       .bss : {
| +       .bss __rel_dyn_start (OVERLAY) : {
|                 __bss_start = .;
|                 *(.bss*)
|                  . = ALIGN(8);
Quoted 3 lines

The SPL image starts up again and continues loading the real uboot image. Note that I have no idea what these changes actually do, so I need instructions if I should dig further.

Does:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
fix it?

Quoted 5 lines
Quoted 1 line

Sadly not, same result.

Ugh. What file, specifically, do you send via xmodem? And so that maybe I can more easily replicate the failure, are you using the kernel.org gcc-14.2.0 toolchain or something else?

I am building with a custom-built arm-openadk-linux-uclibceabi-gcc version 14.3.0. Basically what I run is:

MYENV='ARCH=arm CROSS_COMPILE=~/git/openadk-ds414/toolchain_synology-ds414_uclibc-ng_softfp_eabi_arm/usr/bin/arm-openadk-linux-uclibceabi-'

make $MYENV clean && \
for f in $(ls u-boot*.kwb 2>/dev/null); do rm $f; done && \
make $MYENV ds414_defconfig && \
make $MYENV -j12 && \
./tools/kwboot -a -t -p -b u-boot-*spl.kwb /dev/ttyUSB0

Quoted 5 lines

With current uboot, this should be u-boot-with-spl.kwb image.

With said patch reverted (or the above changes applied), I produce a working u-boot-with-spl.kwb which loads and boots linux from flash. So my toolchain is at least not totally broken. ;)

Right, so, for background, the following threads might shed some light on things:
https://lore.kernel.org/u-boot/CAOMZO5DZNJ+=AP1spWCv7Ar6etf03H=DFVU=mXZcC7QFTGoh_Q@mail.gmail.com/
https://lore.kernel.org/u-boot/[email protected]/

And so to that end, can you please do:
hexdump -Cv u-boot-with-spl.kwb | grep 'd0 0d fe ed'
and let me know what that says? And the first line there should match, content-wise at least (but not quite file offset) spl/u-boot-spl. I was asking about your toolchain because with gcc-14.2.0 from kernel.org:

Quoted 4 lines
$ hexdump -Cv /tmp/ds414/spl/u-boot-spl | grep 'd0 0d fe ed'
00002ed0  6f f0 12 00 70 47 00 bf  d0 0d fe ed 00 29 05 db  |o...pG.......)..|
$ hexdump -Cv /tmp/ds414/u-boot-with-spl.kwb | grep 'd0 0d fe ed'
00001ed0  6f f0 12 00 70 47 00 bf  d0 0d fe ed 00 29 05 db  |o...pG.......)..|

This is with HEAD at a8d982e1f17 + your "spl: Ensure final section before BSS is non-empty" applied:

% hexdump -Cv u-boot-with-spl.kwb | grep 'd0 0d fe ed' | head -n1 00001ed0 6f f0 12 00 70 47 00 bf d0 0d fe ed 00 29 05 db |o...pG.......)..|

% hexdump -Cv spl/u-boot-spl | grep 'd0 0d fe ed'
00002ed0 6f f0 12 00 70 47 00 bf d0 0d fe ed 00 29 05 db |o...pG.......)..|

Quoted 8 lines
Quoted 3 lines

And while this should then *work* that's luck and not design. If you can confirm that instead 'd0 0d fe ed' is in the middle (and so 4 byte but not 8 byte aligned) it'll at least be the same symptom as before.

Hmm. My dumps indicate correct 8B alignment, right? Switching over to a branch which has the problematic commit reverted and produced images work, I get exactly the same output from hexdump on those files, BTW. Does that mean we're on the wrong track and my problem is not wrong DTB alignment?

So, I'm not sure. The error message is what shows up quickly from trying to find the device tree, and not finding it. In debugging the other times, we did see mysterious shifts 4 bytes in either direction, but never 8 bytes. I think you might need to start throwing some debug prints around and seeing where the device tree *is* at run time in relation to where it's expected to be.

Signature · 1 line
Tom
#36 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

Quoted 149 lines · Tom Rini
Quoted 139 lines · Phil Sutter
Quoted 124 lines · Tom Rini
Quoted 107 lines · Phil Sutter
Quoted 89 lines · Tom Rini
Quoted 88 lines · Phil Sutter
Quoted 86 lines · Tom Rini
Quoted 78 lines · Phil Sutter

Hi,

Quoted 17 lines · Tom Rini

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Expands some linker sections to be more readable when adding a second statement to the section.
- Aligns the final section before _end (for U-Boot) or _image_binary_end or __bss_end (for xPL phases) by 8-bytes by adding '. = ALIGN(8);' to the final section before the symbol.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).
- Remove now-spurious '. = ALIGN(x);' statements that were intended to provide the above alignments.

Quoted 1 line

For unclear reasons, this seems to break boot via xmodem protocol on my Synology DS414. I found this commit via 'git bisect'. The symptom is:

| kwboot version 2026.04-rc1-00098-g6ad0cf8f83db
| Detected kwbimage v1 with SPI boot signature
| Patching image boot signature to UART
| Aligning image header to Xmodem block size
| Sending boot message. Please reboot the target...\
| Sending boot image header (67584 bytes)...
|   0 % [......................................................................]
|  13 % [......................................................................]
|  26 % [......................................................................]
|  39 % [......................................................................]
|  53 % [......................................................................]
|  66 % [......................................................................]
|  79 % [......................................................................]
|  92 % [......................................                                ]
| Done
| Missing DTB
| spl_init() failed: -2
| ### ERROR ### Please RESET the board ###
| 
| 
| xmodem: Connection timed out

Debug printf()s in fdtdec_prepare_fdt() show that fdt_check_header() returns -FDT_ERR_BADMAGIC.

With HEAD at a8d982e1f1726 ("x86: cpu: Fix crash on FTRACE enabled builds"), reverting arch/arm/cpu/u-boot-spl.lds like so:

| @@ -41,14 +41,21 @@ SECTIONS
|                 __binman_sym_start = .;
|                 KEEP(*(SORT(.binman_sym*)));
|                 __binman_sym_end = .;
| -               . = ALIGN(8);
|         }
|  
| +       . = ALIGN(4); /* critical! */
|         __image_copy_end = .;
| +       .rel.dyn : {
| +               __rel_dyn_start = .;
| +               *(.rel*)
| +               __rel_dyn_end = .;
| +       }
| +
| +       . = ALIGN(8);
|         _image_binary_end = .;
|         _end = .;
|  
| -       .bss : {
| +       .bss __rel_dyn_start (OVERLAY) : {
|                 __bss_start = .;
|                 *(.bss*)
|                  . = ALIGN(8);
Quoted 3 lines

The SPL image starts up again and continues loading the real uboot image. Note that I have no idea what these changes actually do, so I need instructions if I should dig further.

Does:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
fix it?

Quoted 5 lines
Quoted 1 line

Sadly not, same result.

Ugh. What file, specifically, do you send via xmodem? And so that maybe I can more easily replicate the failure, are you using the kernel.org gcc-14.2.0 toolchain or something else?

I am building with a custom-built arm-openadk-linux-uclibceabi-gcc version 14.3.0. Basically what I run is:

MYENV='ARCH=arm CROSS_COMPILE=~/git/openadk-ds414/toolchain_synology-ds414_uclibc-ng_softfp_eabi_arm/usr/bin/arm-openadk-linux-uclibceabi-'

make $MYENV clean && \
for f in $(ls u-boot*.kwb 2>/dev/null); do rm $f; done && \
make $MYENV ds414_defconfig && \
make $MYENV -j12 && \
./tools/kwboot -a -t -p -b u-boot-*spl.kwb /dev/ttyUSB0

Quoted 5 lines

With current uboot, this should be u-boot-with-spl.kwb image.

With said patch reverted (or the above changes applied), I produce a working u-boot-with-spl.kwb which loads and boots linux from flash. So my toolchain is at least not totally broken. ;)

Right, so, for background, the following threads might shed some light on things:
https://lore.kernel.org/u-boot/CAOMZO5DZNJ+=AP1spWCv7Ar6etf03H=DFVU=mXZcC7QFTGoh_Q@mail.gmail.com/
https://lore.kernel.org/u-boot/[email protected]/

And so to that end, can you please do:
hexdump -Cv u-boot-with-spl.kwb | grep 'd0 0d fe ed'
and let me know what that says? And the first line there should match, content-wise at least (but not quite file offset) spl/u-boot-spl. I was asking about your toolchain because with gcc-14.2.0 from kernel.org:

Quoted 4 lines
$ hexdump -Cv /tmp/ds414/spl/u-boot-spl | grep 'd0 0d fe ed'
00002ed0  6f f0 12 00 70 47 00 bf  d0 0d fe ed 00 29 05 db  |o...pG.......)..|
$ hexdump -Cv /tmp/ds414/u-boot-with-spl.kwb | grep 'd0 0d fe ed'
00001ed0  6f f0 12 00 70 47 00 bf  d0 0d fe ed 00 29 05 db  |o...pG.......)..|

This is with HEAD at a8d982e1f17 + your "spl: Ensure final section before BSS is non-empty" applied:

% hexdump -Cv u-boot-with-spl.kwb | grep 'd0 0d fe ed' | head -n1 00001ed0 6f f0 12 00 70 47 00 bf d0 0d fe ed 00 29 05 db |o...pG.......)..|

% hexdump -Cv spl/u-boot-spl | grep 'd0 0d fe ed'
00002ed0 6f f0 12 00 70 47 00 bf d0 0d fe ed 00 29 05 db |o...pG.......)..|

Quoted 8 lines
Quoted 3 lines

And while this should then *work* that's luck and not design. If you can confirm that instead 'd0 0d fe ed' is in the middle (and so 4 byte but not 8 byte aligned) it'll at least be the same symptom as before.

Hmm. My dumps indicate correct 8B alignment, right? Switching over to a branch which has the problematic commit reverted and produced images work, I get exactly the same output from hexdump on those files, BTW. Does that mean we're on the wrong track and my problem is not wrong DTB alignment?

Quoted 6 lines

So, I'm not sure. The error message is what shows up quickly from trying to find the device tree, and not finding it. In debugging the other times, we did see mysterious shifts 4 bytes in either direction, but never 8 bytes. I think you might need to start throwing some debug prints around and seeing where the device tree *is* at run time in relation to where it's expected to be.

FDT_MAGIC sequence is found 12B before 'blob' as passed to fdtdec_prepare_fdt(). I searched in a range of (-128;127), it was the only offset which matched.

Cheers, Phil

author
#37 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

Quoted 157 lines · Phil Sutter
Quoted 149 lines · Tom Rini
Quoted 139 lines · Phil Sutter
Quoted 124 lines · Tom Rini
Quoted 107 lines · Phil Sutter
Quoted 89 lines · Tom Rini
Quoted 88 lines · Phil Sutter
Quoted 86 lines · Tom Rini
Quoted 78 lines · Phil Sutter

Hi,

Quoted 17 lines · Tom Rini

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Expands some linker sections to be more readable when adding a second statement to the section.
- Aligns the final section before _end (for U-Boot) or _image_binary_end or __bss_end (for xPL phases) by 8-bytes by adding '. = ALIGN(8);' to the final section before the symbol.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).
- Remove now-spurious '. = ALIGN(x);' statements that were intended to provide the above alignments.

Quoted 1 line

For unclear reasons, this seems to break boot via xmodem protocol on my Synology DS414. I found this commit via 'git bisect'. The symptom is:

| kwboot version 2026.04-rc1-00098-g6ad0cf8f83db
| Detected kwbimage v1 with SPI boot signature
| Patching image boot signature to UART
| Aligning image header to Xmodem block size
| Sending boot message. Please reboot the target...\
| Sending boot image header (67584 bytes)...
|   0 % [......................................................................]
|  13 % [......................................................................]
|  26 % [......................................................................]
|  39 % [......................................................................]
|  53 % [......................................................................]
|  66 % [......................................................................]
|  79 % [......................................................................]
|  92 % [......................................                                ]
| Done
| Missing DTB
| spl_init() failed: -2
| ### ERROR ### Please RESET the board ###
| 
| 
| xmodem: Connection timed out

Debug printf()s in fdtdec_prepare_fdt() show that fdt_check_header() returns -FDT_ERR_BADMAGIC.

With HEAD at a8d982e1f1726 ("x86: cpu: Fix crash on FTRACE enabled builds"), reverting arch/arm/cpu/u-boot-spl.lds like so:

| @@ -41,14 +41,21 @@ SECTIONS
|                 __binman_sym_start = .;
|                 KEEP(*(SORT(.binman_sym*)));
|                 __binman_sym_end = .;
| -               . = ALIGN(8);
|         }
|  
| +       . = ALIGN(4); /* critical! */
|         __image_copy_end = .;
| +       .rel.dyn : {
| +               __rel_dyn_start = .;
| +               *(.rel*)
| +               __rel_dyn_end = .;
| +       }
| +
| +       . = ALIGN(8);
|         _image_binary_end = .;
|         _end = .;
|  
| -       .bss : {
| +       .bss __rel_dyn_start (OVERLAY) : {
|                 __bss_start = .;
|                 *(.bss*)
|                  . = ALIGN(8);
Quoted 3 lines

The SPL image starts up again and continues loading the real uboot image. Note that I have no idea what these changes actually do, so I need instructions if I should dig further.

Does:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
fix it?

Quoted 5 lines
Quoted 1 line

Sadly not, same result.

Ugh. What file, specifically, do you send via xmodem? And so that maybe I can more easily replicate the failure, are you using the kernel.org gcc-14.2.0 toolchain or something else?

I am building with a custom-built arm-openadk-linux-uclibceabi-gcc version 14.3.0. Basically what I run is:

MYENV='ARCH=arm CROSS_COMPILE=~/git/openadk-ds414/toolchain_synology-ds414_uclibc-ng_softfp_eabi_arm/usr/bin/arm-openadk-linux-uclibceabi-'

make $MYENV clean && \
for f in $(ls u-boot*.kwb 2>/dev/null); do rm $f; done && \
make $MYENV ds414_defconfig && \
make $MYENV -j12 && \
./tools/kwboot -a -t -p -b u-boot-*spl.kwb /dev/ttyUSB0

Quoted 5 lines

With current uboot, this should be u-boot-with-spl.kwb image.

With said patch reverted (or the above changes applied), I produce a working u-boot-with-spl.kwb which loads and boots linux from flash. So my toolchain is at least not totally broken. ;)

Right, so, for background, the following threads might shed some light on things:
https://lore.kernel.org/u-boot/CAOMZO5DZNJ+=AP1spWCv7Ar6etf03H=DFVU=mXZcC7QFTGoh_Q@mail.gmail.com/
https://lore.kernel.org/u-boot/[email protected]/

And so to that end, can you please do:
hexdump -Cv u-boot-with-spl.kwb | grep 'd0 0d fe ed'
and let me know what that says? And the first line there should match, content-wise at least (but not quite file offset) spl/u-boot-spl. I was asking about your toolchain because with gcc-14.2.0 from kernel.org:

Quoted 4 lines
$ hexdump -Cv /tmp/ds414/spl/u-boot-spl | grep 'd0 0d fe ed'
00002ed0  6f f0 12 00 70 47 00 bf  d0 0d fe ed 00 29 05 db  |o...pG.......)..|
$ hexdump -Cv /tmp/ds414/u-boot-with-spl.kwb | grep 'd0 0d fe ed'
00001ed0  6f f0 12 00 70 47 00 bf  d0 0d fe ed 00 29 05 db  |o...pG.......)..|

This is with HEAD at a8d982e1f17 + your "spl: Ensure final section before BSS is non-empty" applied:

% hexdump -Cv u-boot-with-spl.kwb | grep 'd0 0d fe ed' | head -n1 00001ed0 6f f0 12 00 70 47 00 bf d0 0d fe ed 00 29 05 db |o...pG.......)..|

% hexdump -Cv spl/u-boot-spl | grep 'd0 0d fe ed'
00002ed0 6f f0 12 00 70 47 00 bf d0 0d fe ed 00 29 05 db |o...pG.......)..|

Quoted 8 lines
Quoted 3 lines

And while this should then *work* that's luck and not design. If you can confirm that instead 'd0 0d fe ed' is in the middle (and so 4 byte but not 8 byte aligned) it'll at least be the same symptom as before.

Hmm. My dumps indicate correct 8B alignment, right? Switching over to a branch which has the problematic commit reverted and produced images work, I get exactly the same output from hexdump on those files, BTW. Does that mean we're on the wrong track and my problem is not wrong DTB alignment?

Quoted 6 lines

So, I'm not sure. The error message is what shows up quickly from trying to find the device tree, and not finding it. In debugging the other times, we did see mysterious shifts 4 bytes in either direction, but never 8 bytes. I think you might need to start throwing some debug prints around and seeing where the device tree *is* at run time in relation to where it's expected to be.

Quoted 3 lines

FDT_MAGIC sequence is found 12B before 'blob' as passed to fdtdec_prepare_fdt(). I searched in a range of (-128;127), it was the only offset which matched.

So, our mysterious 4 shift is now 12. If you undo the patch I asked you to test, is it now 4B before? I basically want to confirm that my newest patch just changes when we hit this problem and doesn't solve it, only changes the mystery shift. Oh, and can you please readelf -S the spl/u-boot-spl for both with my patch and current master AND the one you made work? Thanks again!

Quoted 2 lines

Cheers, Phil

Signature · 1 line
Tom
#38 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

Quoted 162 lines · Tom Rini
Quoted 157 lines · Phil Sutter
Quoted 149 lines · Tom Rini
Quoted 139 lines · Phil Sutter
Quoted 124 lines · Tom Rini
Quoted 107 lines · Phil Sutter
Quoted 89 lines · Tom Rini
Quoted 88 lines · Phil Sutter
Quoted 86 lines · Tom Rini
Quoted 78 lines · Phil Sutter

Hi,

Quoted 17 lines · Tom Rini

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Expands some linker sections to be more readable when adding a second statement to the section.
- Aligns the final section before _end (for U-Boot) or _image_binary_end or __bss_end (for xPL phases) by 8-bytes by adding '. = ALIGN(8);' to the final section before the symbol.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).
- Remove now-spurious '. = ALIGN(x);' statements that were intended to provide the above alignments.

Quoted 1 line

For unclear reasons, this seems to break boot via xmodem protocol on my Synology DS414. I found this commit via 'git bisect'. The symptom is:

| kwboot version 2026.04-rc1-00098-g6ad0cf8f83db
| Detected kwbimage v1 with SPI boot signature
| Patching image boot signature to UART
| Aligning image header to Xmodem block size
| Sending boot message. Please reboot the target...\
| Sending boot image header (67584 bytes)...
|   0 % [......................................................................]
|  13 % [......................................................................]
|  26 % [......................................................................]
|  39 % [......................................................................]
|  53 % [......................................................................]
|  66 % [......................................................................]
|  79 % [......................................................................]
|  92 % [......................................                                ]
| Done
| Missing DTB
| spl_init() failed: -2
| ### ERROR ### Please RESET the board ###
| 
| 
| xmodem: Connection timed out

Debug printf()s in fdtdec_prepare_fdt() show that fdt_check_header() returns -FDT_ERR_BADMAGIC.

With HEAD at a8d982e1f1726 ("x86: cpu: Fix crash on FTRACE enabled builds"), reverting arch/arm/cpu/u-boot-spl.lds like so:

| @@ -41,14 +41,21 @@ SECTIONS
|                 __binman_sym_start = .;
|                 KEEP(*(SORT(.binman_sym*)));
|                 __binman_sym_end = .;
| -               . = ALIGN(8);
|         }
|  
| +       . = ALIGN(4); /* critical! */
|         __image_copy_end = .;
| +       .rel.dyn : {
| +               __rel_dyn_start = .;
| +               *(.rel*)
| +               __rel_dyn_end = .;
| +       }
| +
| +       . = ALIGN(8);
|         _image_binary_end = .;
|         _end = .;
|  
| -       .bss : {
| +       .bss __rel_dyn_start (OVERLAY) : {
|                 __bss_start = .;
|                 *(.bss*)
|                  . = ALIGN(8);
Quoted 3 lines

The SPL image starts up again and continues loading the real uboot image. Note that I have no idea what these changes actually do, so I need instructions if I should dig further.

Does:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
fix it?

Quoted 5 lines
Quoted 1 line

Sadly not, same result.

Ugh. What file, specifically, do you send via xmodem? And so that maybe I can more easily replicate the failure, are you using the kernel.org gcc-14.2.0 toolchain or something else?

I am building with a custom-built arm-openadk-linux-uclibceabi-gcc version 14.3.0. Basically what I run is:

MYENV='ARCH=arm CROSS_COMPILE=~/git/openadk-ds414/toolchain_synology-ds414_uclibc-ng_softfp_eabi_arm/usr/bin/arm-openadk-linux-uclibceabi-'

make $MYENV clean && \
for f in $(ls u-boot*.kwb 2>/dev/null); do rm $f; done && \
make $MYENV ds414_defconfig && \
make $MYENV -j12 && \
./tools/kwboot -a -t -p -b u-boot-*spl.kwb /dev/ttyUSB0

Quoted 5 lines

With current uboot, this should be u-boot-with-spl.kwb image.

With said patch reverted (or the above changes applied), I produce a working u-boot-with-spl.kwb which loads and boots linux from flash. So my toolchain is at least not totally broken. ;)

Right, so, for background, the following threads might shed some light on things:
https://lore.kernel.org/u-boot/CAOMZO5DZNJ+=AP1spWCv7Ar6etf03H=DFVU=mXZcC7QFTGoh_Q@mail.gmail.com/
https://lore.kernel.org/u-boot/[email protected]/

And so to that end, can you please do:
hexdump -Cv u-boot-with-spl.kwb | grep 'd0 0d fe ed'
and let me know what that says? And the first line there should match, content-wise at least (but not quite file offset) spl/u-boot-spl. I was asking about your toolchain because with gcc-14.2.0 from kernel.org:

Quoted 4 lines
$ hexdump -Cv /tmp/ds414/spl/u-boot-spl | grep 'd0 0d fe ed'
00002ed0  6f f0 12 00 70 47 00 bf  d0 0d fe ed 00 29 05 db  |o...pG.......)..|
$ hexdump -Cv /tmp/ds414/u-boot-with-spl.kwb | grep 'd0 0d fe ed'
00001ed0  6f f0 12 00 70 47 00 bf  d0 0d fe ed 00 29 05 db  |o...pG.......)..|

This is with HEAD at a8d982e1f17 + your "spl: Ensure final section before BSS is non-empty" applied:

% hexdump -Cv u-boot-with-spl.kwb | grep 'd0 0d fe ed' | head -n1 00001ed0 6f f0 12 00 70 47 00 bf d0 0d fe ed 00 29 05 db |o...pG.......)..|

% hexdump -Cv spl/u-boot-spl | grep 'd0 0d fe ed'
00002ed0 6f f0 12 00 70 47 00 bf d0 0d fe ed 00 29 05 db |o...pG.......)..|

Quoted 8 lines
Quoted 3 lines

And while this should then *work* that's luck and not design. If you can confirm that instead 'd0 0d fe ed' is in the middle (and so 4 byte but not 8 byte aligned) it'll at least be the same symptom as before.

Hmm. My dumps indicate correct 8B alignment, right? Switching over to a branch which has the problematic commit reverted and produced images work, I get exactly the same output from hexdump on those files, BTW. Does that mean we're on the wrong track and my problem is not wrong DTB alignment?

Quoted 6 lines

So, I'm not sure. The error message is what shows up quickly from trying to find the device tree, and not finding it. In debugging the other times, we did see mysterious shifts 4 bytes in either direction, but never 8 bytes. I think you might need to start throwing some debug prints around and seeing where the device tree *is* at run time in relation to where it's expected to be.

Quoted 3 lines

FDT_MAGIC sequence is found 12B before 'blob' as passed to fdtdec_prepare_fdt(). I searched in a range of (-128;127), it was the only offset which matched.

Quoted 6 lines

So, our mysterious 4 shift is now 12. If you undo the patch I asked you to test, is it now 4B before? I basically want to confirm that my newest patch just changes when we hit this problem and doesn't solve it, only changes the mystery shift. Oh, and can you please readelf -S the spl/u-boot-spl for both with my patch and current master AND the one you made work? Thanks again!

Sorry for the mess, I did my FDT_MAGIC search with master branch, so not with your patch applied. Readelf prints:

% readelf -S spl/u-boot-spl
There are 20 section headers, starting at offset 0x127d54:

Section Headers:

  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        40004030 001030 009c1e 00  AX  0   0 16
  [ 2] .rodata           PROGBITS        4000dc50 00ac50 0016f9 00   A  0   0  4
  [ 3] .data             PROGBITS        4000f360 00c360 0042e0 00  WA  0   0 32
  [ 4] __u_boot_list     PROGBITS        40013640 010640 000594 00  WA  0   0  4
  [ 5] .binman_sym_table NOBITS          40013bd4 010bd4 000004 00  WA  0   0  1
  [ 6] .bss              NOBITS          40013be0 010bd4 000728 00  WA  0   0 32
  [ 7] .ARM.attributes   ARM_ATTRIBUTES  00000000 010bd4 000029 00      0   0  1
  [ 8] .comment          PROGBITS        00000000 010bfd 000012 01  MS  0   0  1
  [ 9] .debug_line       PROGBITS        00000000 010c0f 02844f 00      0   0  1
  [10] .debug_info       PROGBITS        00000000 03905e 076ced 00      0   0  1
  [11] .debug_abbrev     PROGBITS        00000000 0afd4b 00f697 00      0   0  1
  [12] .debug_aranges    PROGBITS        00000000 0bf3e8 002430 00      0   0  8
  [13] .debug_str        PROGBITS        00000000 0c1818 00d85c 01  MS  0   0  1
  [14] .debug_loc        PROGBITS        00000000 0cf074 044a87 00      0   0  1
  [15] .debug_ranges     PROGBITS        00000000 113b00 006578 00      0   0  8
  [16] .debug_frame      PROGBITS        00000000 11a078 0069c0 00      0   0  4
  [17] .symtab           SYMTAB          00000000 120a38 004d10 10     18 888  4
  [18] .strtab           STRTAB          00000000 125748 002539 00      0   0  1
  [19] .shstrtab         STRTAB          00000000 127c81 0000d3 00      0   0  1

Next try with your patch applied on top of master:

FDT_MAGIC is found at offset -8. Readelf:

There are 19 section headers, starting at offset 0x127d34:

Section Headers:

  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        40004030 001030 009c1e 00  AX  0   0 16
  [ 2] .rodata           PROGBITS        4000dc50 00ac50 0016f9 00   A  0   0  4
  [ 3] .data             PROGBITS        4000f360 00c360 0042e0 00  WA  0   0 32
  [ 4] __u_boot_list     PROGBITS        40013640 010640 000598 00  WA  0   0  4
  [ 5] .bss              NOBITS          40013be0 010bd8 000728 00  WA  0   0 32
  [ 6] .ARM.attributes   ARM_ATTRIBUTES  00000000 010bd8 000029 00      0   0  1
  [ 7] .comment          PROGBITS        00000000 010c01 000012 01  MS  0   0  1
  [ 8] .debug_line       PROGBITS        00000000 010c13 02844f 00      0   0  1
  [ 9] .debug_info       PROGBITS        00000000 039062 076ced 00      0   0  1
  [10] .debug_abbrev     PROGBITS        00000000 0afd4f 00f697 00      0   0  1
  [11] .debug_aranges    PROGBITS        00000000 0bf3e8 002430 00      0   0  8
  [12] .debug_str        PROGBITS        00000000 0c1818 00d85c 01  MS  0   0  1
  [13] .debug_loc        PROGBITS        00000000 0cf074 044a87 00      0   0  1
  [14] .debug_ranges     PROGBITS        00000000 113b00 006578 00      0   0  8
  [15] .debug_frame      PROGBITS        00000000 11a078 0069c0 00      0   0  4
  [16] .symtab           SYMTAB          00000000 120a38 004d00 10     17 887  4
  [17] .strtab           STRTAB          00000000 125738 002539 00      0   0  1
  [18] .shstrtab         STRTAB          00000000 127c71 0000c1 00      0   0  1

Finally, with problematic patches reverted:

FDT_MAGIC is found at offset 0 (obviously). Readelf:

There are 19 section headers, starting at offset 0x1284a0:

Section Headers:

  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        40004030 001030 009c1e 00  AX  0   0 16
  [ 2] .rodata           PROGBITS        4000dc50 00ac50 0016f9 00   A  0   0  4
  [ 3] .data             PROGBITS        4000f360 00c360 0042e0 00  WA  0   0 32
  [ 4] __u_boot_list     PROGBITS        40013640 010640 000594 00  WA  0   0  4
  [ 5] .bss              PROGBITS        40013bd4 010bd4 000734 00   W  0   0  4
  [ 6] .ARM.attributes   ARM_ATTRIBUTES  00000000 011308 000029 00      0   0  1
  [ 7] .comment          PROGBITS        00000000 011331 000012 01  MS  0   0  1
  [ 8] .debug_line       PROGBITS        00000000 011343 02844f 00      0   0  1
  [ 9] .debug_info       PROGBITS        00000000 039792 076ced 00      0   0  1
  [10] .debug_abbrev     PROGBITS        00000000 0b047f 00f697 00      0   0  1
  [11] .debug_aranges    PROGBITS        00000000 0bfb18 002430 00      0   0  8
  [12] .debug_str        PROGBITS        00000000 0c1f48 00d85c 01  MS  0   0  1
  [13] .debug_loc        PROGBITS        00000000 0cf7a4 044a87 00      0   0  1
  [14] .debug_ranges     PROGBITS        00000000 114230 006578 00      0   0  8
  [15] .debug_frame      PROGBITS        00000000 11a7a8 0069c0 00      0   0  4
  [16] .symtab           SYMTAB          00000000 121168 004d20 10     17 887  4
  [17] .strtab           STRTAB          00000000 125e88 002557 00      0   0  1
  [18] .shstrtab         STRTAB          00000000 1283df 0000c1 00      0   0  1

HTH, Phil

author
#39 lore raw

Re: [PATCH 02/10] arm: Update linker scripts to ensure appended device tree is aligned

Quoted 255 lines · Phil Sutter
Quoted 162 lines · Tom Rini
Quoted 157 lines · Phil Sutter
Quoted 149 lines · Tom Rini
Quoted 139 lines · Phil Sutter
Quoted 124 lines · Tom Rini
Quoted 107 lines · Phil Sutter
Quoted 89 lines · Tom Rini
Quoted 88 lines · Phil Sutter
Quoted 86 lines · Tom Rini
Quoted 78 lines · Phil Sutter

Hi,

Quoted 17 lines · Tom Rini

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Expands some linker sections to be more readable when adding a second statement to the section.
- Aligns the final section before _end (for U-Boot) or _image_binary_end or __bss_end (for xPL phases) by 8-bytes by adding '. = ALIGN(8);' to the final section before the symbol.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).
- Remove now-spurious '. = ALIGN(x);' statements that were intended to provide the above alignments.

Quoted 1 line

For unclear reasons, this seems to break boot via xmodem protocol on my Synology DS414. I found this commit via 'git bisect'. The symptom is:

| kwboot version 2026.04-rc1-00098-g6ad0cf8f83db
| Detected kwbimage v1 with SPI boot signature
| Patching image boot signature to UART
| Aligning image header to Xmodem block size
| Sending boot message. Please reboot the target...\
| Sending boot image header (67584 bytes)...
|   0 % [......................................................................]
|  13 % [......................................................................]
|  26 % [......................................................................]
|  39 % [......................................................................]
|  53 % [......................................................................]
|  66 % [......................................................................]
|  79 % [......................................................................]
|  92 % [......................................                                ]
| Done
| Missing DTB
| spl_init() failed: -2
| ### ERROR ### Please RESET the board ###
| 
| 
| xmodem: Connection timed out

Debug printf()s in fdtdec_prepare_fdt() show that fdt_check_header() returns -FDT_ERR_BADMAGIC.

With HEAD at a8d982e1f1726 ("x86: cpu: Fix crash on FTRACE enabled builds"), reverting arch/arm/cpu/u-boot-spl.lds like so:

| @@ -41,14 +41,21 @@ SECTIONS
|                 __binman_sym_start = .;
|                 KEEP(*(SORT(.binman_sym*)));
|                 __binman_sym_end = .;
| -               . = ALIGN(8);
|         }
|  
| +       . = ALIGN(4); /* critical! */
|         __image_copy_end = .;
| +       .rel.dyn : {
| +               __rel_dyn_start = .;
| +               *(.rel*)
| +               __rel_dyn_end = .;
| +       }
| +
| +       . = ALIGN(8);
|         _image_binary_end = .;
|         _end = .;
|  
| -       .bss : {
| +       .bss __rel_dyn_start (OVERLAY) : {
|                 __bss_start = .;
|                 *(.bss*)
|                  . = ALIGN(8);
Quoted 3 lines

The SPL image starts up again and continues loading the real uboot image. Note that I have no idea what these changes actually do, so I need instructions if I should dig further.

Does:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
fix it?

Quoted 5 lines
Quoted 1 line

Sadly not, same result.

Ugh. What file, specifically, do you send via xmodem? And so that maybe I can more easily replicate the failure, are you using the kernel.org gcc-14.2.0 toolchain or something else?

I am building with a custom-built arm-openadk-linux-uclibceabi-gcc version 14.3.0. Basically what I run is:

MYENV='ARCH=arm CROSS_COMPILE=~/git/openadk-ds414/toolchain_synology-ds414_uclibc-ng_softfp_eabi_arm/usr/bin/arm-openadk-linux-uclibceabi-'

make $MYENV clean && \
for f in $(ls u-boot*.kwb 2>/dev/null); do rm $f; done && \
make $MYENV ds414_defconfig && \
make $MYENV -j12 && \
./tools/kwboot -a -t -p -b u-boot-*spl.kwb /dev/ttyUSB0

Quoted 5 lines

With current uboot, this should be u-boot-with-spl.kwb image.

With said patch reverted (or the above changes applied), I produce a working u-boot-with-spl.kwb which loads and boots linux from flash. So my toolchain is at least not totally broken. ;)

Right, so, for background, the following threads might shed some light on things:
https://lore.kernel.org/u-boot/CAOMZO5DZNJ+=AP1spWCv7Ar6etf03H=DFVU=mXZcC7QFTGoh_Q@mail.gmail.com/
https://lore.kernel.org/u-boot/[email protected]/

And so to that end, can you please do:
hexdump -Cv u-boot-with-spl.kwb | grep 'd0 0d fe ed'
and let me know what that says? And the first line there should match, content-wise at least (but not quite file offset) spl/u-boot-spl. I was asking about your toolchain because with gcc-14.2.0 from kernel.org:

Quoted 4 lines
$ hexdump -Cv /tmp/ds414/spl/u-boot-spl | grep 'd0 0d fe ed'
00002ed0  6f f0 12 00 70 47 00 bf  d0 0d fe ed 00 29 05 db  |o...pG.......)..|
$ hexdump -Cv /tmp/ds414/u-boot-with-spl.kwb | grep 'd0 0d fe ed'
00001ed0  6f f0 12 00 70 47 00 bf  d0 0d fe ed 00 29 05 db  |o...pG.......)..|

This is with HEAD at a8d982e1f17 + your "spl: Ensure final section before BSS is non-empty" applied:

% hexdump -Cv u-boot-with-spl.kwb | grep 'd0 0d fe ed' | head -n1 00001ed0 6f f0 12 00 70 47 00 bf d0 0d fe ed 00 29 05 db |o...pG.......)..|

% hexdump -Cv spl/u-boot-spl | grep 'd0 0d fe ed'
00002ed0 6f f0 12 00 70 47 00 bf d0 0d fe ed 00 29 05 db |o...pG.......)..|

Quoted 8 lines
Quoted 3 lines

And while this should then *work* that's luck and not design. If you can confirm that instead 'd0 0d fe ed' is in the middle (and so 4 byte but not 8 byte aligned) it'll at least be the same symptom as before.

Hmm. My dumps indicate correct 8B alignment, right? Switching over to a branch which has the problematic commit reverted and produced images work, I get exactly the same output from hexdump on those files, BTW. Does that mean we're on the wrong track and my problem is not wrong DTB alignment?

Quoted 6 lines

So, I'm not sure. The error message is what shows up quickly from trying to find the device tree, and not finding it. In debugging the other times, we did see mysterious shifts 4 bytes in either direction, but never 8 bytes. I think you might need to start throwing some debug prints around and seeing where the device tree *is* at run time in relation to where it's expected to be.

Quoted 3 lines

FDT_MAGIC sequence is found 12B before 'blob' as passed to fdtdec_prepare_fdt(). I searched in a range of (-128;127), it was the only offset which matched.

Quoted 6 lines

So, our mysterious 4 shift is now 12. If you undo the patch I asked you to test, is it now 4B before? I basically want to confirm that my newest patch just changes when we hit this problem and doesn't solve it, only changes the mystery shift. Oh, and can you please readelf -S the spl/u-boot-spl for both with my patch and current master AND the one you made work? Thanks again!

Sorry for the mess, I did my FDT_MAGIC search with master branch, so not with your patch applied. Readelf prints:

% readelf -S spl/u-boot-spl
There are 20 section headers, starting at offset 0x127d54:

Section Headers:

  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        40004030 001030 009c1e 00  AX  0   0 16
  [ 2] .rodata           PROGBITS        4000dc50 00ac50 0016f9 00   A  0   0  4
  [ 3] .data             PROGBITS        4000f360 00c360 0042e0 00  WA  0   0 32
  [ 4] __u_boot_list     PROGBITS        40013640 010640 000594 00  WA  0   0  4
  [ 5] .binman_sym_table NOBITS          40013bd4 010bd4 000004 00  WA  0   0  1
  [ 6] .bss              NOBITS          40013be0 010bd4 000728 00  WA  0   0 32
  [ 7] .ARM.attributes   ARM_ATTRIBUTES  00000000 010bd4 000029 00      0   0  1
  [ 8] .comment          PROGBITS        00000000 010bfd 000012 01  MS  0   0  1
  [ 9] .debug_line       PROGBITS        00000000 010c0f 02844f 00      0   0  1
  [10] .debug_info       PROGBITS        00000000 03905e 076ced 00      0   0  1
  [11] .debug_abbrev     PROGBITS        00000000 0afd4b 00f697 00      0   0  1
  [12] .debug_aranges    PROGBITS        00000000 0bf3e8 002430 00      0   0  8
  [13] .debug_str        PROGBITS        00000000 0c1818 00d85c 01  MS  0   0  1
  [14] .debug_loc        PROGBITS        00000000 0cf074 044a87 00      0   0  1
  [15] .debug_ranges     PROGBITS        00000000 113b00 006578 00      0   0  8
  [16] .debug_frame      PROGBITS        00000000 11a078 0069c0 00      0   0  4
  [17] .symtab           SYMTAB          00000000 120a38 004d10 10     18 888  4
  [18] .strtab           STRTAB          00000000 125748 002539 00      0   0  1
  [19] .shstrtab         STRTAB          00000000 127c81 0000d3 00      0   0  1

Next try with your patch applied on top of master:

FDT_MAGIC is found at offset -8. Readelf:

There are 19 section headers, starting at offset 0x127d34:

Section Headers:

  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        40004030 001030 009c1e 00  AX  0   0 16
  [ 2] .rodata           PROGBITS        4000dc50 00ac50 0016f9 00   A  0   0  4
  [ 3] .data             PROGBITS        4000f360 00c360 0042e0 00  WA  0   0 32
  [ 4] __u_boot_list     PROGBITS        40013640 010640 000598 00  WA  0   0  4
  [ 5] .bss              NOBITS          40013be0 010bd8 000728 00  WA  0   0 32
  [ 6] .ARM.attributes   ARM_ATTRIBUTES  00000000 010bd8 000029 00      0   0  1
  [ 7] .comment          PROGBITS        00000000 010c01 000012 01  MS  0   0  1
  [ 8] .debug_line       PROGBITS        00000000 010c13 02844f 00      0   0  1
  [ 9] .debug_info       PROGBITS        00000000 039062 076ced 00      0   0  1
  [10] .debug_abbrev     PROGBITS        00000000 0afd4f 00f697 00      0   0  1
  [11] .debug_aranges    PROGBITS        00000000 0bf3e8 002430 00      0   0  8
  [12] .debug_str        PROGBITS        00000000 0c1818 00d85c 01  MS  0   0  1
  [13] .debug_loc        PROGBITS        00000000 0cf074 044a87 00      0   0  1
  [14] .debug_ranges     PROGBITS        00000000 113b00 006578 00      0   0  8
  [15] .debug_frame      PROGBITS        00000000 11a078 0069c0 00      0   0  4
  [16] .symtab           SYMTAB          00000000 120a38 004d00 10     17 887  4
  [17] .strtab           STRTAB          00000000 125738 002539 00      0   0  1
  [18] .shstrtab         STRTAB          00000000 127c71 0000c1 00      0   0  1

Finally, with problematic patches reverted:

FDT_MAGIC is found at offset 0 (obviously). Readelf:

There are 19 section headers, starting at offset 0x1284a0:

Section Headers:

  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        40004030 001030 009c1e 00  AX  0   0 16
  [ 2] .rodata           PROGBITS        4000dc50 00ac50 0016f9 00   A  0   0  4
  [ 3] .data             PROGBITS        4000f360 00c360 0042e0 00  WA  0   0 32
  [ 4] __u_boot_list     PROGBITS        40013640 010640 000594 00  WA  0   0  4
  [ 5] .bss              PROGBITS        40013bd4 010bd4 000734 00   W  0   0  4
  [ 6] .ARM.attributes   ARM_ATTRIBUTES  00000000 011308 000029 00      0   0  1
  [ 7] .comment          PROGBITS        00000000 011331 000012 01  MS  0   0  1
  [ 8] .debug_line       PROGBITS        00000000 011343 02844f 00      0   0  1
  [ 9] .debug_info       PROGBITS        00000000 039792 076ced 00      0   0  1
  [10] .debug_abbrev     PROGBITS        00000000 0b047f 00f697 00      0   0  1
  [11] .debug_aranges    PROGBITS        00000000 0bfb18 002430 00      0   0  8
  [12] .debug_str        PROGBITS        00000000 0c1f48 00d85c 01  MS  0   0  1
  [13] .debug_loc        PROGBITS        00000000 0cf7a4 044a87 00      0   0  1
  [14] .debug_ranges     PROGBITS        00000000 114230 006578 00      0   0  8
  [15] .debug_frame      PROGBITS        00000000 11a7a8 0069c0 00      0   0  4
  [16] .symtab           SYMTAB          00000000 121168 004d20 10     17 887  4
  [17] .strtab           STRTAB          00000000 125e88 002557 00      0   0  1
  [18] .shstrtab         STRTAB          00000000 1283df 0000c1 00      0   0  1
Quoted 1 line

HTH, Phil

It's confusing, but it does help, thanks again. I'll be cc'ing you and Brian on a patch that supersedes the one I asked you to try. I finally see where the discrepency comes from, and I'm doing to builds now to check the old behavior first before I run off and fix this for the needed new behavior.

Signature · 1 line
Tom
author
#40 lore raw

PATCH 3/10 m68k: Update linker scripts to ensure appended device tree is aligned

In reply to Tom Rini

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Remove part of what Marek Vasut did in commit 9ed99e2eeadb ("m68k:
Assure end of U-Boot is at 8-byte aligned offset") as we now better understand what can trigger failure and check for it.
- Rewrite the '.dynsym' section to follow modern practices, and include the 8-byte alignment at the end of the section.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).

---
Cc: Ilias Apalodimas <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Richard Henderson <[email protected]>

---
 arch/m68k/cpu/u-boot.lds | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
arch/m68k/cpu/u-boot.lds +10 -9
index be1ad0170af6..452003ff43cb 100644
@@ -69,28 +69,27 @@ SECTIONS
 	__ex_table : { *(__ex_table) }
 	__stop___ex_table = .;
 
-	. = ALIGN(8);
+	. = ALIGN(4);
 	__init_begin = .;
 	.text.init : { *(.text.init) }
 	.data.init : { *(.data.init) }
-	. = ALIGN(8);
+	. = ALIGN(4);
 	__init_end = .;
 
-	. = ALIGN(8);
+	. = ALIGN(4);
 	__rel_dyn_start = .;
 	.rela.dyn : {
 		*(.rela.dyn)
 	}
 	__rel_dyn_end = .;
 
-	. = ALIGN(8);
-	__dyn_sym_start = .;
-	.dynsym : {
+	.dynsym ALIGN(4) : {
+		__dyn_sym_start = .;
 		*(.dynsym)
+		__dyn_sym_end = .;
+		. = ALIGN(8);
 	}
-	__dyn_sym_end = .;
 
-	. = ALIGN(8);
 	_end = .;
 
 	__bss_start = .;
@@ -100,9 +99,11 @@ SECTIONS
 		*(.bss*)
 		*(.sbss*)
 		*(COMMON)
-		. = ALIGN(8);
+		. = ALIGN(4);
 		_ebss = .;
 	}
 	__bss_end = . ;
 	PROVIDE (end = .);
 }
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");
Signature · 1 line
2.43.0
author
#41 lore raw

PATCH 4/10 microblaze: Update linker scripts to ensure appended device tree is aligned

In reply to Tom Rini

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Aligns the final section before _end (for U-Boot) or _image_binary_end (for xPL phases) by 8-bytes by adjusting the ALIGN(4) statement to be ALIGN(8) in the final section before the symbol.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).

---
Cc: Ilias Apalodimas <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Michal Simek <[email protected]>
Cc: Richard Henderson <[email protected]>

---
 arch/microblaze/cpu/u-boot-spl.lds | 5 ++++-
 arch/microblaze/cpu/u-boot.lds     | 4 +++-
 2 files changed, 7 insertions(+), 2 deletions(-)
arch/microblaze/cpu/u-boot-spl.lds +4 -1
index 09abbea84d06..620ef2c96dbd 100644
@@ -50,7 +50,7 @@ SECTIONS
 		*(.bss)
 		*(.bss.*)
 		*(COMMON)
-		. = ALIGN(4);
+		. = ALIGN(8);
 		__bss_end = .;
 	}
 	_end = . ;
@@ -61,3 +61,6 @@ SECTIONS
 ASSERT(_end - _start <= (CONFIG_SPL_MAX_FOOTPRINT), \
         "SPL image plus BSS too big");
 #endif
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
arch/microblaze/cpu/u-boot.lds +3 -1
index a2c8fb2e21c0..70fa49c31712 100644
@@ -67,8 +67,10 @@ SECTIONS
 		*(.scommon)
 		*(.bss*)
 		*(COMMON)
-		. = ALIGN(4);
+		. = ALIGN(8);
 		__bss_end = .;
 	}
 	_end = . ;
 }
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");
Signature · 1 line
2.43.0
maintainer Tested-by on v1 4/10
#42 lore raw

Re: [PATCH 04/10] microblaze: Update linker scripts to ensure appended device tree is aligned

Quoted 50 lines · Tom Rini

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Aligns the final section before _end (for U-Boot) or _image_binary_end (for xPL phases) by 8-bytes by adjusting the ALIGN(4) statement to be ALIGN(8) in the final section before the symbol.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).

---
Cc: Ilias Apalodimas <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Michal Simek <[email protected]>
Cc: Richard Henderson <[email protected]>

---
  arch/microblaze/cpu/u-boot-spl.lds | 5 ++++-
  arch/microblaze/cpu/u-boot.lds     | 4 +++-
  2 files changed, 7 insertions(+), 2 deletions(-)
arch/microblaze/cpu/u-boot-spl.lds +4 -1
index 09abbea84d06..620ef2c96dbd 100644
@@ -50,7 +50,7 @@ SECTIONS
  		*(.bss)
  		*(.bss.*)
  		*(COMMON)
-		. = ALIGN(4);
+		. = ALIGN(8);
  		__bss_end = .;
  	}
  	_end = . ;
@@ -61,3 +61,6 @@ SECTIONS
  ASSERT(_end - _start <= (CONFIG_SPL_MAX_FOOTPRINT), \
          "SPL image plus BSS too big");
  #endif
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
arch/microblaze/cpu/u-boot.lds +0 -0
index a2c8fb2e21c0..70fa49c31712 100644
@@ -67,8 +67,10 @@ SECTIONS
  		*(.scommon)

arch/microblaze/cpu/u-boot.lds SECTIONS · line 76

Quoted 10 lines
arch/microblaze/cpu/u-boot.lds +3 -1
  		*(.bss*)
  		*(COMMON)
-		. = ALIGN(4);
+		. = ALIGN(8);
  		__bss_end = .;
  	}
  	_end = . ;
  }
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");

Thanks,
Michal

Reviewed-by on v1 4/10
#43 lore raw

Re: [PATCH 04/10] microblaze: Update linker scripts to ensure appended device tree is aligned

In reply to Tom Rini
Quoted 14 lines · Tom Rini

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Aligns the final section before _end (for U-Boot) or _image_binary_end (for xPL phases) by 8-bytes by adjusting the ALIGN(4) statement to be ALIGN(8) in the final section before the symbol.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).

Quoted 2 lines

---

Quoted 48 lines
Cc Ilias Apalodimas <[email protected]>
Cc Marek Vasut <[email protected]>
Cc Michal Simek <[email protected]>
Cc Richard Henderson <[email protected]>
---
 arch/microblaze/cpu/u-boot-spl.lds | 5 ++++-
 arch/microblaze/cpu/u-boot.lds     | 4 +++-
 2 files changed, 7 insertions(+), 2 deletions(-)
arch/microblaze/cpu/u-boot-spl.lds +4 -1
index 09abbea84d06..620ef2c96dbd 100644
@@ -50,7 +50,7 @@ SECTIONS
                *(.bss)
                *(.bss.*)
                *(COMMON)
-               . = ALIGN(4);
+               . = ALIGN(8);
                __bss_end = .;
        }
        _end = . ;
@@ -61,3 +61,6 @@ SECTIONS
 ASSERT(_end - _start <= (CONFIG_SPL_MAX_FOOTPRINT), \
         "SPL image plus BSS too big");
 #endif
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
arch/microblaze/cpu/u-boot.lds +3 -2
index a2c8fb2e21c0..70fa49c31712 100644
@@ -67,8 +67,10 @@ SECTIONS
                *(.scommon)
                *(.bss*)
                *(COMMON)
-               . = ALIGN(4);
+               . = ALIGN(8);
                __bss_end = .;
        }
        _end = . ;
 }
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");
--

2.43.0

author
#44 lore raw

PATCH 5/10 mips: Update linker scripts to ensure appended device tree is aligned

In reply to Tom Rini

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Aligns the final section before _end (for U-Boot) or _image_binary_end (for xPL phases) by 8-bytes by adding '. = ALIGN(8);' to the final section before the symbol. For SPL we need this in two places to cover all build configurations.
- Remove now-spurious '. = ALIGN(x);' statements that were intended to provide the above alignments.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).

---
Cc: Daniel Schwierzeck <[email protected]> (maintainer:MIPS)
Cc: Ilias Apalodimas <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Richard Henderson <[email protected]>

---
 arch/mips/cpu/u-boot-spl.lds | 6 +++++-
 arch/mips/cpu/u-boot.lds     | 4 +++-
 2 files changed, 8 insertions(+), 2 deletions(-)
arch/mips/cpu/u-boot-spl.lds +5 -1
index 310a5c5053b1..ea2deed34f15 100644
@@ -27,16 +27,17 @@ SECTIONS
 	.data : {
 		*(SORT_BY_ALIGNMENT(.data*))
 		*(SORT_BY_ALIGNMENT(.sdata*))
+		. = ALIGN(8);
 	} > .spl_mem
 
 #if defined(CONFIG_SPL_DM) || defined(CONFIG_SPL_LOADER_SUPPORT)
 	. = ALIGN(4);
 	__u_boot_list : {
 		KEEP(*(SORT(__u_boot_list*)));
+		. = ALIGN(8);
 	} > .spl_mem
 #endif
 
-	. = ALIGN(4);
 	__image_copy_end = .;
 	__image_copy_len = __image_copy_end - __text_start;
 
@@ -123,3 +124,6 @@ SECTIONS
 		*(.eh_frame)
 	}
 }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
arch/mips/cpu/u-boot.lds +3 -1
index 133ea05df3da..d59a48b7ef85 100644
@@ -54,9 +54,9 @@ SECTIONS
 		LONG(0xFFFFFFFF);
 		FILL(0);
 		. += CONFIG_MIPS_RELOCATION_TABLE_SIZE - 4;
+		. = ALIGN(8);
 	}
 
-	. = ALIGN(8);
 	_end = .;
 
 	.bss __rel_start (OVERLAY) : {
@@ -140,3 +140,5 @@ SECTIONS
 		*(.eh_frame)
 	}
 }
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");
Signature · 1 line
2.43.0
Reviewed-by on v1 5/10
#45 lore raw

Re: [PATCH 05/10] mips: Update linker scripts to ensure appended device tree is aligned

Quoted 23 lines · Tom Rini

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Aligns the final section before _end (for U-Boot) or _image_binary_end (for xPL phases) by 8-bytes by adding '. = ALIGN(8);' to the final section before the symbol. For SPL we need this in two places to cover all build configurations.
- Remove now-spurious '. = ALIGN(x);' statements that were intended to provide the above alignments.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).

---
Cc: Daniel Schwierzeck <[email protected]> (maintainer:MIPS)
Cc: Ilias Apalodimas <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Richard Henderson <[email protected]>

Quoted 5 lines
---
 arch/mips/cpu/u-boot-spl.lds | 6 +++++-
 arch/mips/cpu/u-boot.lds     | 4 +++-
 2 files changed, 8 insertions(+), 2 deletions(-)
author
#46 lore raw

PATCH 6/10 nios2: Update linker scripts to ensure appended device tree is aligned

In reply to Tom Rini

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Aligns the final section before _end 8-bytes by adding '. = ALIGN(8);' to the final section before the symbol.
- Remove a now-spurious '. = ALIGN(x);' statement that was intended to provide the above alignments.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).

---
Cc: Ilias Apalodimas <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Thomas Chou <[email protected]>

---
 arch/nios2/cpu/u-boot.lds | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/nios2/cpu/u-boot.lds +3 -1
index 5b9e27d94062..fc366d44341d 100644
@@ -60,8 +60,8 @@ SECTIONS
 	  *(.sdata)
 	  *(.sdata.*)
 	  *(.gnu.linkonce.s.*)
+	  . = ALIGN(8);
 	}
-	. = ALIGN(4);
 
 	_edata = .;
 	PROVIDE (edata = .);
@@ -124,3 +124,5 @@ SECTIONS
 	.debug_typenames 0 : { *(.debug_typenames) }
 	.debug_varnames	 0 : { *(.debug_varnames) }
 }
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");
Signature · 1 line
2.43.0
Acked-by on v1 6/10
#47 lore raw

Re: [PATCH 06/10] nios2: Update linker scripts to ensure appended device tree is aligned

Quoted 15 lines · Tom Rini

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Aligns the final section before _end 8-bytes by adding '. = ALIGN(8);' to the final section before the symbol.
- Remove a now-spurious '. = ALIGN(x);' statement that was intended to provide the above alignments.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).

Quoted 7 lines

---
Cc: Ilias Apalodimas <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Thomas Chou <[email protected]>
---

Quoted 26 lines
 arch/nios2/cpu/u-boot.lds | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/nios2/cpu/u-boot.lds +3 -2
index 5b9e27d94062..fc366d44341d 100644
@@ -60,8 +60,8 @@ SECTIONS
          *(.sdata)
          *(.sdata.*)
          *(.gnu.linkonce.s.*)
+         . = ALIGN(8);
        }
-       . = ALIGN(4);
 
        _edata = .;
        PROVIDE (edata = .);
@@ -124,3 +124,5 @@ SECTIONS
        .debug_typenames 0 : { *(.debug_typenames) }
        .debug_varnames  0 : { *(.debug_varnames) }
 }
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");
--

2.43.0

author
#48 lore raw

PATCH 7/10 powerpc: Update linker scripts to ensure appended device tree is aligned

In reply to Tom Rini

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Aligns the final section before _end by 8-bytes by adding '. = ALIGN(8);' or changing an existing ALIGN(4) statement.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).

---
Cc: "Marek Behún" <[email protected]>
Cc: Christophe Leroy <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Mario Six <[email protected]>
Cc: Richard Henderson <[email protected]>

---
 arch/powerpc/cpu/mpc83xx/u-boot.lds | 3 +++
 arch/powerpc/cpu/mpc85xx/u-boot.lds | 4 +++-
 board/cssi/cmpc885/u-boot.lds       | 3 +++
 board/cssi/mcr3000/u-boot.lds       | 3 +++
 4 files changed, 12 insertions(+), 1 deletion(-)
arch/powerpc/cpu/mpc83xx/u-boot.lds +3 -0
index 1a1e537b2a76..5becc4d236ef 100644
@@ -56,6 +56,7 @@ SECTIONS
    * _end - This is end of u-boot.bin image.
    * dtb will be appended here to make u-boot-dtb.bin
    */
+  . = ALIGN(8);
   _end = .;
 
   . = ALIGN(4096);
@@ -77,3 +78,5 @@ SECTIONS
   PROVIDE (end = .);
 }
 ENTRY(_start)
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");
arch/powerpc/cpu/mpc85xx/u-boot.lds +3 -1
index 3af0dfdf336b..3c9959bef097 100644
@@ -78,7 +78,7 @@ SECTIONS
   __init_begin = .;
   .text.init : { *(.text.init) }
   .data.init : { *(.data.init) }
-  . = ALIGN(4);
+  . = ALIGN(8);
   __init_end = .;
   _end = .;
 
@@ -119,3 +119,5 @@ SECTIONS
   __bss_end = . ;
   PROVIDE (end = .);
 }
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");
board/cssi/cmpc885/u-boot.lds +3 -0
index 167606357e00..da9cff64d465 100644
@@ -72,6 +72,7 @@ SECTIONS
 	 * _end - This is end of u-boot.bin image.
 	 * dtb will be appended here to make u-boot-dtb.bin
 	 */
+	. = ALIGN(8);
 	_end = .;
 
 	. = ALIGN(4096);
@@ -93,3 +94,5 @@ SECTIONS
 	PROVIDE (end = .);
 }
 ENTRY(_start)
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");
board/cssi/mcr3000/u-boot.lds +3 -0
index 66afdebc0f77..1fd98726b2a8 100644
@@ -72,6 +72,7 @@ SECTIONS
 	 * _end - This is end of u-boot.bin image.
 	 * dtb will be appended here to make u-boot-dtb.bin
 	 */
+	. = ALIGN(8);
 	_end = .;
 
 	. = ALIGN(4096);
@@ -93,3 +94,5 @@ SECTIONS
 	PROVIDE (end = .);
 }
 ENTRY(_start)
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");
Signature · 1 line
2.43.0
reviewer Reviewed-by on v1 7/10
#49 lore raw

Re: [PATCH 07/10] powerpc: Update linker scripts to ensure appended device tree is aligned

Le 15/01/2026 à 23:19, Tom Rini a écrit :

Quoted 12 lines

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Aligns the final section before _end by 8-bytes by adding '. = ALIGN(8);' or changing an existing ALIGN(4) statement.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).

Quoted 1 line
Quoted 87 lines

---
Cc: "Marek Behún" <[email protected]>
Cc: Christophe Leroy <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Mario Six <[email protected]>
Cc: Richard Henderson <[email protected]>

---
  arch/powerpc/cpu/mpc83xx/u-boot.lds | 3 +++
  arch/powerpc/cpu/mpc85xx/u-boot.lds | 4 +++-
  board/cssi/cmpc885/u-boot.lds       | 3 +++
  board/cssi/mcr3000/u-boot.lds       | 3 +++
  4 files changed, 12 insertions(+), 1 deletion(-)
arch/powerpc/cpu/mpc83xx/u-boot.lds +3 -0
index 1a1e537b2a76..5becc4d236ef 100644
@@ -56,6 +56,7 @@ SECTIONS
     * _end - This is end of u-boot.bin image.
     * dtb will be appended here to make u-boot-dtb.bin
     */
+  . = ALIGN(8);
    _end = .;
 
    . = ALIGN(4096);
@@ -77,3 +78,5 @@ SECTIONS
    PROVIDE (end = .);
  }
  ENTRY(_start)
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");
arch/powerpc/cpu/mpc85xx/u-boot.lds +3 -1
index 3af0dfdf336b..3c9959bef097 100644
@@ -78,7 +78,7 @@ SECTIONS
    __init_begin = .;
    .text.init : { *(.text.init) }
    .data.init : { *(.data.init) }
-  . = ALIGN(4);
+  . = ALIGN(8);
    __init_end = .;
    _end = .;
 
@@ -119,3 +119,5 @@ SECTIONS
    __bss_end = . ;
    PROVIDE (end = .);
  }
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");
board/cssi/cmpc885/u-boot.lds +3 -0
index 167606357e00..da9cff64d465 100644
@@ -72,6 +72,7 @@ SECTIONS
  	 * _end - This is end of u-boot.bin image.
  	 * dtb will be appended here to make u-boot-dtb.bin
  	 */
+	. = ALIGN(8);
  	_end = .;
 
  	. = ALIGN(4096);
@@ -93,3 +94,5 @@ SECTIONS
  	PROVIDE (end = .);
  }
  ENTRY(_start)
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");
board/cssi/mcr3000/u-boot.lds +3 -0
index 66afdebc0f77..1fd98726b2a8 100644
@@ -72,6 +72,7 @@ SECTIONS
  	 * _end - This is end of u-boot.bin image.
  	 * dtb will be appended here to make u-boot-dtb.bin
  	 */
+	. = ALIGN(8);
  	_end = .;
 
  	. = ALIGN(4096);
@@ -93,3 +94,5 @@ SECTIONS
  	PROVIDE (end = .);
  }
  ENTRY(_start)
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");
author
#50 lore raw

PATCH 8/10 riscv: Update linker scripts to ensure appended device tree is aligned

In reply to Tom Rini

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Aligns the final section before _end (for U-Boot) or _image_binary_end (for xPL phases) by 8-bytes by adding '. = ALIGN(8);' to the final section before the symbol.
- Remove a now-spurious '. = ALIGN(x);' statement that was intended to provide the above alignments.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).

---
Cc: Ilias Apalodimas <[email protected]>
Cc: Leo <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Rick Chen <[email protected]>

---
 arch/riscv/cpu/u-boot-spl.lds | 4 ++++
 arch/riscv/cpu/u-boot.lds     | 5 +++--
 2 files changed, 7 insertions(+), 2 deletions(-)
arch/riscv/cpu/u-boot-spl.lds +4 -0
index 0717833df556..35de28db8f3a 100644
@@ -43,6 +43,7 @@ SECTIONS
 		__binman_sym_start = .;
 		KEEP(*(SORT(.binman_sym*)));
 		__binman_sym_end = .;
+		. = ALIGN(8);
 	} > .spl_mem
 
 	_end = .;
@@ -56,3 +57,6 @@ SECTIONS
 		__bss_end = .;
 	} > .bss_mem
 }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
arch/riscv/cpu/u-boot.lds +3 -2
index b11ea8b56d25..c299c00fa298 100644
@@ -73,10 +73,9 @@ SECTIONS
 		__dyn_sym_start = .;
 		*(.dynsym)
 		__dyn_sym_end = .;
+		. = ALIGN(8);
 	}
 
-	. = ALIGN(8);
-
 	_end = .;
 
 	.bss : {
@@ -86,3 +85,5 @@ SECTIONS
 		__bss_end = .;
 	}
 }
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");
Signature · 1 line
2.43.0
Reviewed-by on v1 8/10
#51 lore raw

Re: [PATCH 08/10] riscv: Update linker scripts to ensure appended device tree is aligned

Quoted 24 lines · Tom Rini

[EXTERNAL MAIL]

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Aligns the final section before _end (for U-Boot) or _image_binary_end (for xPL phases) by 8-bytes by adding '. = ALIGN(8);' to the final section before the symbol.
- Remove a now-spurious '. = ALIGN(x);' statement that was intended to provide the above alignments.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).

---
Cc: Ilias Apalodimas <[email protected]>
Cc: Leo <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Rick Chen <[email protected]>

Quoted 4 lines
---
 arch/riscv/cpu/u-boot-spl.lds | 4 ++++
 arch/riscv/cpu/u-boot.lds     | 5 +++--
 2 files changed, 7 insertions(+), 2 deletions(-)
Reviewed-by on v1 8/10
#52 lore raw

Re: [PATCH 08/10] riscv: Update linker scripts to ensure appended device tree is aligned

In reply to Tom Rini
Quoted 16 lines · Tom Rini

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Aligns the final section before _end (for U-Boot) or _image_binary_end (for xPL phases) by 8-bytes by adding '. = ALIGN(8);' to the final section before the symbol.
- Remove a now-spurious '. = ALIGN(x);' statement that was intended to provide the above alignments.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).

Quoted 2 lines

---

Quoted 54 lines
Cc Ilias Apalodimas <[email protected]>
Cc Marek Vasut <[email protected]>
Cc Richard Henderson <[email protected]>
Cc Rick Chen <[email protected]>
---
 arch/riscv/cpu/u-boot-spl.lds | 4 ++++
 arch/riscv/cpu/u-boot.lds     | 5 +++--
 2 files changed, 7 insertions(+), 2 deletions(-)
arch/riscv/cpu/u-boot-spl.lds +4 -0
index 0717833df556..35de28db8f3a 100644
@@ -43,6 +43,7 @@ SECTIONS
                __binman_sym_start = .;
                KEEP(*(SORT(.binman_sym*)));
                __binman_sym_end = .;
+               . = ALIGN(8);
        } > .spl_mem
 
        _end = .;
@@ -56,3 +57,6 @@ SECTIONS
                __bss_end = .;
        } > .bss_mem
 }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
arch/riscv/cpu/u-boot.lds +3 -3
index b11ea8b56d25..c299c00fa298 100644
@@ -73,10 +73,9 @@ SECTIONS
                __dyn_sym_start = .;
                *(.dynsym)
                __dyn_sym_end = .;
+               . = ALIGN(8);
        }
 
-       . = ALIGN(8);
-
        _end = .;
 
        .bss : {
@@ -86,3 +85,5 @@ SECTIONS
                __bss_end = .;
        }
 }
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");
--

2.43.0

author
#53 lore raw

PATCH 9/10 sandbox: Update linker scripts to ensure appended device tree is aligned

In reply to Tom Rini

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Aligns the final section before _image_binary_end (for xPL phases) by 8-bytes by adding '. = ALIGN(8);' to the final section before the symbol.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).

---
Cc: Ilias Apalodimas <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Simon Glass <[email protected]>

---
 arch/sandbox/cpu/u-boot-spl.lds | 4 ++++
 1 file changed, 4 insertions(+)
arch/sandbox/cpu/u-boot-spl.lds +4 -0
index a81d66a6f2e8..bd5a164b8c95 100644
@@ -25,9 +25,13 @@ SECTIONS
 		*(_u_boot_sandbox_getopt_start)
 		KEEP(*(_u_boot_sandbox_getopt))
 		*(_u_boot_sandbox_getopt_end)
+		. = ALIGN(8);
 	}
 
 	_image_binary_end = .;
 }
 
 INSERT AFTER .data;
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
Signature · 1 line
2.43.0
author
#54 lore raw

PATCH 10/10 x86: Update linker scripts to ensure appended device tree is aligned

In reply to Tom Rini

With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our device tree is not 8-byte aligned. In commit f613a6e15ef7 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains that we must have ALIGN(x) statements inside of a section to ensure that padding is included and not simply that the linker address counter is incremented. To that end, this patch:
- Rewrite the '.rel.dyn' (u-boot.lds) to follow modern practices, and include the 8-byte alignment at the end of the section.
- Expands the '.dynamic' section (u-boot-64.lds) to be more readable when adding a second statement to the section.
- Aligns the final section before _end (for U-Boot) or _image_binary_end or __bss_end (for xPL phases) by 8-bytes by adding '. = ALIGN(8);' to the final section before the symbol or changing an existing ALIGN(4) statement.
- Ensure that we do have alignment by adding an ASSERT so that when not aligned we fail to link (and explain why).

---
Cc: Bin Meng <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Simon Glass <[email protected]>

---
 arch/x86/cpu/u-boot-64.lds  |  6 ++++--
 arch/x86/cpu/u-boot-spl.lds | 10 +++++++++-
 arch/x86/cpu/u-boot.lds     | 11 ++++++-----
 3 files changed, 19 insertions(+), 8 deletions(-)
arch/x86/cpu/u-boot-64.lds +4 -2
index 00a6d8691211..0c353c5d7401 100644
@@ -86,9 +86,11 @@ SECTIONS
 	__rel_dyn_end = .;
 	. = ALIGN(4);
 
-	.dynamic : { *(.dynamic) }
+	.dynamic : {
+		*(.dynamic)
+		. = ALIGN(8);
+	}
 
-	. = ALIGN(4);
 	_end = .;
 
 	.bss __rel_dyn_start (OVERLAY) : {
arch/x86/cpu/u-boot-spl.lds +9 -1
index 50b4b1608552..57cdce6d7515 100644
@@ -68,7 +68,7 @@ SECTIONS
 		__bss_start = .;
 		*(.bss*)
 		*(COM*)
-		. = ALIGN(4);
+		. = ALIGN(8);
 		__bss_end = .;
 	}
 	__bss_size = __bss_end - __bss_start;
@@ -97,3 +97,11 @@ SECTIONS
 #endif
 
 }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
+
+#if !CONFIG_IS_ENABLED(SEPARATE_BSS)
+ASSERT(__bss_end % 8 == 0, \
+       "__bss_end must be 8-byte aligned for device tree");
+#endif
arch/x86/cpu/u-boot.lds +6 -5
index c418ff44aa08..ea070acd6a15 100644
@@ -79,13 +79,12 @@ SECTIONS
 	. = ALIGN(4);
 	.dynsym : { *(.dynsym*) }
 
-	. = ALIGN(4);
-	__rel_dyn_start = .;
-	.rel.dyn : {
+	.rel.dyn ALIGN(4) : {
+		__rel_dyn_start = .;
 		*(.rel*)
+		__rel_dyn_end = .;
+		. = ALIGN(8);
 	}
-	__rel_dyn_end = .;
-	. = ALIGN(4);
 	_end = .;
 
 	.bss __rel_dyn_start (OVERLAY) : {
@@ -120,3 +119,5 @@ SECTIONS
 #endif
 
 }
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");
Signature · 1 line
2.43.0
author
#55 lore raw
In reply to Tom Rini
Quoted 15 lines · Tom Rini

Hey all,

This series builds on top of what Beleswar Padhi did in [1]. While there's still discussion about the mkimage related parts, the linker portion appears to the reliable path forward. An alternative that I had mentioned before, and was part of previous discussions on this topic[2] is in the end I believe not reliable enough. While we can take an output file and pad it to where we think it needs to be, ultimately the linker needs to place the symbol where we want it and if that isn't where we pad to, we have a different problem. So what this series does (but each commit message elaborates on the arch-specific linker scripts being inconsistent) is make sure the linker script will place the required symbol at 8-byte alignment, and then also use an ASSERT to fail the build if this would not be true due to some unforseen event.

Quoted 1 line

[...]

Applied to u-boot/master, thanks!

[01/10] Makefile: Have binary_size_check report only first match of _image_binary_end

        commit: 90efb8d394de9df1ae2c20f5e25ffc2009dc7ec5
[02/10] arm: Update linker scripts to ensure appended device tree is aligned
        commit: 8b0ebe054bb3334c6ca9bed018360b08d4ddc7a4
[03/10] m68k: Update linker scripts to ensure appended device tree is aligned
        commit: dac67bf0bee168de8f43050fe9b1d776de1ee00f
[04/10] microblaze: Update linker scripts to ensure appended device tree is aligned
        commit: 2e52030584d069b702f8367ddd34b3a65f522806
[05/10] mips: Update linker scripts to ensure appended device tree is aligned
        commit: b220a43f5ae69f1b258976691fe70414c4fc2259
[06/10] nios2: Update linker scripts to ensure appended device tree is aligned
        commit: 546d84ca0cb367240c93aa3e3492be4dccf85332
[07/10] powerpc: Update linker scripts to ensure appended device tree is aligned
        commit: 87d3780ebc242e28a180606f72335ce37d8bcca1
[08/10] riscv: Update linker scripts to ensure appended device tree is aligned
        commit: f150843499b3139c2358f5659411571399902d4a
[09/10] sandbox: Update linker scripts to ensure appended device tree is aligned
        commit: 94b81451890f42b422bb13b03e2c1034b9bfb43d
[10/10] x86: Update linker scripts to ensure appended device tree is aligned
        commit: 410d31bae4b863eabd70adb22a0c9976bfe4fee3
Signature · 1 line
Tom