Skip to contentSkip to conversation

Fix TI DTB alignment issues with recent libfdt update

PATCH In review Beleswar Padhi 5 participants 27 messages Jan 12 – Jan 20

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover Fix TI DTB alignment issues with recent libfdt update

Recent libfdt updates (commit 0535e46d55d7 "scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") enforce strict 8-byte alignment for device tree blobs, as required by the device tree specification. This causes failures on platforms using CONFIG_SPL_MULTI_DTB_FIT, where DTBs were not properly aligned.

The alignment issue occurs at two levels:

1. DTBs embedded within the multidtb.fit FIT image may not be 8-byte aligned, even though the FIT image itself starts at an aligned address. This causes -FDT_ERR_ALIGNMENT failures when setup_multi_dtb_fit() tries to locate and use these DTBs.

2. The FIT image is concatenated to u-boot-spl-nodtb.bin at a boundary determined by the OMAP2 linker script. Currently, the linker only advances the location counter for alignment without padding the binary, causing the FIT image to be appended an unaligned offset.

This series addresses both issues:

Patch 1 adds the -B 0x8 flag to mkimage, ensuring all DTB entries within the FIT image are 8-byte aligned.

Patch 2 fixes the linker script to include padding in the binary by placing an alignment directive inside the __u_boot_list section, ensuring the FIT image is appended at an 8-byte aligned boundary.

v2: Changelog:
1. Remove extra ALIGN() directive, add a comment instead.
2. Add R/B, Reported-by and Fixes: tags.

Link to v1:
https://lore.kernel.org/all/[email protected]/

Testing done:
1. Boot tested on all TI K3 platforms.

Beleswar Padhi (2):
scripts/Makefile.xpl: Align filtered DTB to 8-byte within multidtb.fit
ARM: OMAP2+: Pad SPL binary to 8-byte alignment before DTB

 arch/arm/mach-omap2/u-boot-spl.lds | 6 +++++-
 scripts/Makefile.xpl               | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/2 scripts/Makefile.xpl: Align filtered DTB to 8-byte within multidtb.fit

When CONFIG_SPL_MULTI_DTB_FIT is enabled, multiple device trees are packed inside the multidtb.fit FIT image. While the individual DTBs and the FIT image start address are 8-byte aligned, the DTBs embedded within the FIT image are not guaranteed to maintain 8-byte alignment.

This misalignment causes -FDT_ERR_ALIGNMENT failure in setup_multi_dtb_fit() when locating the next available DTB within the FIT blob and setting gd->fdt_blob, because of the recent libfdt hardening since commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")

Add the -B 0x8 flag to mkimage to enforce 8-byte alignment for all DTB entries within the multidtb FIT image.

Fixes 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")

---
v2: Changelog:
1. Carry R/B, Reported-by, Closes and Fixes tag.

Link to v1:
https://lore.kernel.org/all/[email protected]/

 scripts/Makefile.xpl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/Makefile.xpl +1 -1
index 5e65d7b2498..1183f5180ba 100644
@@ -602,7 +602,7 @@ $(SHRUNK_ARCH_DTB): $$(patsubst $(obj)/dts/%, $(dt_dir)/%, $$@) $(dir $(SHRUNK_A
 targets += $(SPL_OF_LIST_TARGETS)
 
 MKIMAGEFLAGS_$(SPL_BIN).multidtb.fit = -f auto -A $(ARCH) -T firmware -C none -O u-boot \
-	-n "Multi DTB fit image for $(SPL_BIN)" -E \
+	-n "Multi DTB fit image for $(SPL_BIN)" -B 0x8 -E \
 	$(patsubst %,-b %,$(SHRUNK_ARCH_DTB))
 
 $(obj)/$(SPL_BIN).multidtb.fit: /dev/null $(SHRUNK_ARCH_DTB) FORCE
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v2 1/2] scripts/Makefile.xpl: Align filtered DTB to 8-byte within multidtb.fit

Quoted 4 lines · Beleswar Padhi

When CONFIG_SPL_MULTI_DTB_FIT is enabled, multiple device trees are packed inside the multidtb.fit FIT image. While the individual DTBs and the FIT image start address are 8-byte aligned, the DTBs embedded within the FIT image are not guaranteed to maintain 8-byte alignment.

Because DT properties are 4-byte aligned, and fitImage is a DT with long binary strings encoded in them. But that is not the case here, because the invocation does use mkimage -E .

Therefore I see two issues:
- Should the code which handles LEGACY fitImages with 4-byte alignment be fixed to relocate the blobs ? I think yes.
- Should mkimage -E align blobs to 8 bytes by default ? I think yes, and frankly, I thought it does so already, but apparently not.

#3 lore raw

Re: [PATCH v2 1/2] scripts/Makefile.xpl: Align filtered DTB to 8-byte within multidtb.fit

Quoted 11 lines · Marek Vasut
Quoted 4 lines · Beleswar Padhi

When CONFIG_SPL_MULTI_DTB_FIT is enabled, multiple device trees are packed inside the multidtb.fit FIT image. While the individual DTBs and the FIT image start address are 8-byte aligned, the DTBs embedded within the FIT image are not guaranteed to maintain 8-byte alignment.

Because DT properties are 4-byte aligned, and fitImage is a DT with long binary strings encoded in them. But that is not the case here, because the invocation does use mkimage -E .

Therefore I see two issues:
- Should the code which handles LEGACY fitImages with 4-byte alignment be fixed to relocate the blobs ? I think yes.

This we can fix in the Makefile via the dd command as suggested by Tom.

Quoted 2 lines

- Should mkimage -E align blobs to 8 bytes by default ? I think yes, and frankly, I thought it does so already, but apparently not.

This can be done, but should it be? Not all FITs demand an 8-byte alignment right? It is only the FDT which requires this.

#4 lore raw

Re: [PATCH v2 1/2] scripts/Makefile.xpl: Align filtered DTB to 8-byte within multidtb.fit

Quoted 8 lines · Beleswar
Quoted 6 lines · Marek Vasut
Quoted 4 lines · Beleswar Padhi

When CONFIG_SPL_MULTI_DTB_FIT is enabled, multiple device trees are packed inside the multidtb.fit FIT image. While the individual DTBs and the FIT image start address are 8-byte aligned, the DTBs embedded within the FIT image are not guaranteed to maintain 8-byte alignment.

Quoted 8 lines
Quoted 5 lines

Because DT properties are 4-byte aligned, and fitImage is a DT with long binary strings encoded in them. But that is not the case here, because the invocation does use mkimage -E .

Therefore I see two issues:
- Should the code which handles LEGACY fitImages with 4-byte alignment be fixed to relocate the blobs ? I think yes.

This we can fix in the Makefile via the dd command as suggested by Tom.

My concern is about LEGACY fitImages (means already generated ones), not newly generated ones.

Quoted 6 lines
Quoted 2 lines

- Should mkimage -E align blobs to 8 bytes by default ? I think yes, and frankly, I thought it does so already, but apparently not.

This can be done, but should it be? Not all FITs demand an 8-byte alignment right? It is only the FDT which requires this.

Maybe if image type is flat_dt, it should be implicitly 8-byte aligned then ?

#5 lore raw

Re: [PATCH v2 1/2] scripts/Makefile.xpl: Align filtered DTB to 8-byte within multidtb.fit

Quoted 18 lines · Marek Vasut
Quoted 17 lines · Beleswar
Quoted 13 lines · Marek Vasut
Quoted 4 lines · Beleswar Padhi

When CONFIG_SPL_MULTI_DTB_FIT is enabled, multiple device trees are packed inside the multidtb.fit FIT image. While the individual DTBs and the FIT image start address are 8-byte aligned, the DTBs embedded within the FIT image are not guaranteed to maintain 8-byte alignment.

Because DT properties are 4-byte aligned, and fitImage is a DT with long binary strings encoded in them. But that is not the case here, because the invocation does use mkimage -E .

Therefore I see two issues:
- Should the code which handles LEGACY fitImages with 4-byte alignment be fixed to relocate the blobs ? I think yes.

Quoted 4 lines
Quoted 1 line

This we can fix in the Makefile via the dd command as suggested by Tom.

My concern is about LEGACY fitImages (means already generated ones), not newly generated ones.

Why is that a concern? If it's a legacy fitImage for the OS, we relocate the device tree already normally to be aligned. If it's a legacy fitImage of U-Boot, it's an old U-Boot?

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

- Should mkimage -E align blobs to 8 bytes by default ? I think yes, and frankly, I thought it does so already, but apparently not.

This can be done, but should it be? Not all FITs demand an 8-byte alignment right? It is only the FDT which requires this.

Maybe if image type is flat_dt, it should be implicitly 8-byte aligned then ?

Well, the device tree spec says 8-byte alignment. It's not "FDT for OS" that's 8-byte, it's any device tree should start out 8 byte aligned, and everything else should then be naturally aligned. If we're looking in a device tree for another device tree to use in place and not relocate then that second tree must be aligned.

Or am I missing something?

Signature · 1 line
Tom
#6 lore raw

Re: [PATCH v2 1/2] scripts/Makefile.xpl: Align filtered DTB to 8-byte within multidtb.fit

Quoted 8 lines · Tom Rini
Quoted 4 lines
Quoted 1 line

This we can fix in the Makefile via the dd command as suggested by Tom.

My concern is about LEGACY fitImages (means already generated ones), not newly generated ones.

Why is that a concern? If it's a legacy fitImage for the OS, we relocate the device tree already normally to be aligned. If it's a legacy fitImage of U-Boot, it's an old U-Boot?

Not necessarily, it could be new U-Boot using old fitImage, for whatever reason (falcon boot maybe ?). We should not break that.

Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

- Should mkimage -E align blobs to 8 bytes by default ? I think yes, and frankly, I thought it does so already, but apparently not.

This can be done, but should it be? Not all FITs demand an 8-byte alignment right? It is only the FDT which requires this.

Maybe if image type is flat_dt, it should be implicitly 8-byte aligned then ?

Well, the device tree spec says 8-byte alignment.

8 byte alignment of what, start of DT, right ?

Quoted 7 lines

It's not "FDT for OS"
that's 8-byte, it's any device tree should start out 8 byte aligned, and everything else should then be naturally aligned. If we're looking in a device tree for another device tree to use in place and not relocate then that second tree must be aligned.

Or am I missing something?

The discussion is about mkimage -E which generates DTs for U-Boot SPL use. The DTs in those external data should likely be aligned to 8 bytes by default, i.e. implicitly set -B 8 (they don't seem to be right now).

#7 lore raw

Re: [PATCH v2 1/2] scripts/Makefile.xpl: Align filtered DTB to 8-byte within multidtb.fit

Quoted 17 lines · Marek Vasut
Quoted 8 lines · Tom Rini
Quoted 4 lines
Quoted 1 line

This we can fix in the Makefile via the dd command as suggested by Tom.

My concern is about LEGACY fitImages (means already generated ones), not newly generated ones.

Why is that a concern? If it's a legacy fitImage for the OS, we relocate the device tree already normally to be aligned. If it's a legacy fitImage of U-Boot, it's an old U-Boot?

Not necessarily, it could be new U-Boot using old fitImage, for whatever reason (falcon boot maybe ?). We should not break that.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

- Should mkimage -E align blobs to 8 bytes by default ? I think yes, and frankly, I thought it does so already, but apparently not.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

This can be done, but should it be? Not all FITs demand an 8-byte alignment right? It is only the FDT which requires this.

Maybe if image type is flat_dt, it should be implicitly 8-byte aligned then ?

Well, the device tree spec says 8-byte alignment.

8 byte alignment of what, start of DT, right ?

Yeah from start... In this case, the FDT for OS is aligned, but the sub DT from the FIT is not aligned by 8-bytes.

Quoted 9 lines
Quoted 8 lines

It's not "FDT for OS"
that's 8-byte, it's any device tree should start out 8 byte aligned, and everything else should then be naturally aligned. If we're looking in a device tree for another device tree to use in place and not relocate then that second tree must be aligned.

Or am I missing something?

The discussion is about mkimage -E which generates DTs for U-Boot SPL use. The DTs in those external data should likely be aligned to 8 bytes by default, i.e. implicitly set -B 8 (they don't seem to be right now).

Instead of -E, we can use '-b' which always takes DT and make sure that is 8-byte aligned by default:

Usage: mkimage [-D dtc_options] [-f fit-image.its|-f auto|-f auto-conf|-F] [-b <dtb> [-b <dtb>]] [-E] [-B size] [-i <ramdisk.cpio.gz>] fit-image -b => append the device tree binary to the FIT

Thanks,
Beleswar

#8 lore raw

Re: [PATCH v2 1/2] scripts/Makefile.xpl: Align filtered DTB to 8-byte within multidtb.fit

Quoted 9 lines · Beleswar Prasad Padhi
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

- Should mkimage -E align blobs to 8 bytes by default ? I think yes, and frankly, I thought it does so already, but apparently not.

This can be done, but should it be? Not all FITs demand an 8-byte alignment right? It is only the FDT which requires this.

Maybe if image type is flat_dt, it should be implicitly 8-byte aligned then ?

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Well, the device tree spec says 8-byte alignment.

8 byte alignment of what, start of DT, right ?

Yeah from start... In this case, the FDT for OS is aligned, but the sub DT from the FIT is not aligned by 8-bytes.

For mkimage -E (fit with trailing external data) , enforcing that alignment should be easily doable.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

It's not "FDT for OS"
that's 8-byte, it's any device tree should start out 8 byte aligned, and everything else should then be naturally aligned. If we're looking in a device tree for another device tree to use in place and not relocate then that second tree must be aligned.

Quoted 7 lines
Quoted 2 lines
Quoted 1 line

Or am I missing something?

The discussion is about mkimage -E which generates DTs for U-Boot SPL use. The DTs in those external data should likely be aligned to 8 bytes by default, i.e. implicitly set -B 8 (they don't seem to be right now).

Instead of -E, we can use '-b' which always takes DT and make sure that is 8-byte aligned by default:

Usage: mkimage [-D dtc_options] [-f fit-image.its|-f auto|-f auto-conf|-F] [-b <dtb> [-b <dtb>]] [-E] [-B size] [-i <ramdisk.cpio.gz>] fit-image -b => append the device tree binary to the FIT

The type flat_dt should likely always be implicitly aligned at minimum to 8 bytes , without -b or -B or -whatever flags.

Signature · 2 lines
Best regards,
Marek Vasut
#9 lore raw

Re: [PATCH v2 1/2] scripts/Makefile.xpl: Align filtered DTB to 8-byte within multidtb.fit

In reply to Marek Vasut
Quoted 7 lines · Marek Vasut
Quoted 5 lines · Tom Rini
Quoted 4 lines
Quoted 1 line

This we can fix in the Makefile via the dd command as suggested by Tom.

My concern is about LEGACY fitImages (means already generated ones), not newly generated ones.

Quoted 6 lines
Quoted 3 lines

Why is that a concern? If it's a legacy fitImage for the OS, we relocate the device tree already normally to be aligned. If it's a legacy fitImage of U-Boot, it's an old U-Boot?

Not necessarily, it could be new U-Boot using old fitImage, for whatever reason (falcon boot maybe ?). We should not break that.

If it's falcon boot then it's the OS case and we relocate it before passing on, that's not changed. That's why I'm saying I'm not sure there's a legacy case to worry about, since the big change now is that U-Boot also demands correctly aligned device trees. The Linux Kernel essentially always has, and other OSes probably as well. We were just bad and let 4-byte work for so long.

Quoted 19 lines
Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

- Should mkimage -E align blobs to 8 bytes by default ? I think yes, and frankly, I thought it does so already, but apparently not.

This can be done, but should it be? Not all FITs demand an 8-byte alignment right? It is only the FDT which requires this.

Maybe if image type is flat_dt, it should be implicitly 8-byte aligned then ?

Well, the device tree spec says 8-byte alignment.

8 byte alignment of what, start of DT, right ?

Quoted 6 lines

It's not "FDT for OS"
that's 8-byte, it's any device tree should start out 8 byte aligned, and everything else should then be naturally aligned. If we're looking in a device tree for another device tree to use in place and not relocate then that second tree must be aligned.

Quoted 4 lines
Quoted 1 line

Or am I missing something?

The discussion is about mkimage -E which generates DTs for U-Boot SPL use. The DTs in those external data should likely be aligned to 8 bytes by default, i.e. implicitly set -B 8 (they don't seem to be right now).

Right. So the only legacy case I can see would be using an old mkimage to generate a current U-Boot image. And I'm not super sure that can happen, outside of some sort of external to us tooling being wrapped around things, and at that point we have little control.

Signature · 1 line
Tom
#10 lore raw

Re: [PATCH v2 1/2] scripts/Makefile.xpl: Align filtered DTB to 8-byte within multidtb.fit

Quoted 12 lines · Tom Rini
Quoted 11 lines · Marek Vasut
Quoted 8 lines · Tom Rini
Quoted 4 lines
Quoted 1 line

This we can fix in the Makefile via the dd command as suggested by Tom.

My concern is about LEGACY fitImages (means already generated ones), not newly generated ones.

Why is that a concern? If it's a legacy fitImage for the OS, we relocate the device tree already normally to be aligned. If it's a legacy fitImage of U-Boot, it's an old U-Boot?

Quoted 5 lines
Quoted 2 lines

Not necessarily, it could be new U-Boot using old fitImage, for whatever reason (falcon boot maybe ?). We should not break that.

If it's falcon boot then it's the OS case and we relocate it before passing on, that's not changed.

Not always, cf the whole fdt_high=-1 bag of issues.

What I would like to see is something like

8fbcc0e0e839 ("boot: Assure FDT is always at 8-byte aligned address")

then we are safe against all obscure 4-byte-alignment cases.

Quoted 26 lines

That's why I'm saying I'm not sure
there's a legacy case to worry about, since the big change now is that U-Boot also demands correctly aligned device trees. The Linux Kernel essentially always has, and other OSes probably as well. We were just bad and let 4-byte work for so long.

Quoted 20 lines
Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

- Should mkimage -E align blobs to 8 bytes by default ? I think yes, and frankly, I thought it does so already, but apparently not.

This can be done, but should it be? Not all FITs demand an 8-byte alignment right? It is only the FDT which requires this.

Maybe if image type is flat_dt, it should be implicitly 8-byte aligned then ?

Well, the device tree spec says 8-byte alignment.

8 byte alignment of what, start of DT, right ?

Quoted 7 lines

It's not "FDT for OS"
that's 8-byte, it's any device tree should start out 8 byte aligned, and everything else should then be naturally aligned. If we're looking in a device tree for another device tree to use in place and not relocate then that second tree must be aligned.

Or am I missing something?

Quoted 8 lines
Quoted 3 lines

The discussion is about mkimage -E which generates DTs for U-Boot SPL use. The DTs in those external data should likely be aligned to 8 bytes by default, i.e. implicitly set -B 8 (they don't seem to be right now).

Right. So the only legacy case I can see would be using an old mkimage to generate a current U-Boot image. And I'm not super sure that can happen, outside of some sort of external to us tooling being wrapped around things, and at that point we have little control.

For that case, see above.

#11 lore raw

PATCH v2 2/2 ARM: OMAP2+: Pad SPL binary to 8-byte alignment before DTB

In reply to Beleswar Padhi

The OMAP2 SPL linker script (also used for K3 platforms) currently uses a 4-byte alignment directive after the __u_boot_list section. This alignment directive only advances the location counter without padding the actual binary output.

When objcopy extracts u-boot-spl-nodtb.bin, it includes only actual data, stopping at the last byte of __u_boot_list (e.g., 0x41c359fc), not an aligned address (e.g., 0x41c35a00). So, when the FIT image containing device trees is concatenated to the SPL binary, it gets appended at this unaligned file size, causing libfdt validation failure.

To fix this, move the alignment directive into the __u_boot_list section itself and make it 8-byte aligned as per DT spec. This forces the linker to include padding as part of the section data, ensuring objcopy includes the padding bytes in the binary and the appended FIT image starts at an 8-byte aligned boundary.

Fixes 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")

---
v2: Changelog:
1. Get rid of extra ALIGN() directive, replace it with a comment
2. Carry Reported-by, Closes and Fixes tag.

Link to v1:
https://lore.kernel.org/all/[email protected]/

 arch/arm/mach-omap2/u-boot-spl.lds | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/arm/mach-omap2/u-boot-spl.lds +5 -1
index 3bb759d8a1c..5ad169a37b7 100644
@@ -35,9 +35,13 @@ SECTIONS
 	. = ALIGN(4);
 	__u_boot_list : {
 		KEEP(*(SORT(__u_boot_list*)));
+		/*
+		 * Ensure 8-byte alignment at the end of the last section before
+		 * DTB is appended, to satisfy DT spec alignment requirements
+		 */
+		. = ALIGN(8);
 	} >.sram
 
-	. = ALIGN(4);
 	__image_copy_end = .;
 	_end = .;
 	_image_binary_end = .;
Signature · 1 line
2.34.1
#12 lore raw

Re: [PATCH v2 2/2] ARM: OMAP2+: Pad SPL binary to 8-byte alignment before DTB

Quoted 37 lines · Beleswar Padhi

The OMAP2 SPL linker script (also used for K3 platforms) currently uses a 4-byte alignment directive after the __u_boot_list section. This alignment directive only advances the location counter without padding the actual binary output.

When objcopy extracts u-boot-spl-nodtb.bin, it includes only actual data, stopping at the last byte of __u_boot_list (e.g., 0x41c359fc), not an aligned address (e.g., 0x41c35a00). So, when the FIT image containing device trees is concatenated to the SPL binary, it gets appended at this unaligned file size, causing libfdt validation failure.

To fix this, move the alignment directive into the __u_boot_list section itself and make it 8-byte aligned as per DT spec. This forces the linker to include padding as part of the section data, ensuring objcopy includes the padding bytes in the binary and the appended FIT image starts at an 8-byte aligned boundary.

Fixes 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")

---
v2: Changelog:
1. Get rid of extra ALIGN() directive, replace it with a comment
2. Carry Reported-by, Closes and Fixes tag.

Link to v1:
https://lore.kernel.org/all/[email protected]/

 arch/arm/mach-omap2/u-boot-spl.lds | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/arm/mach-omap2/u-boot-spl.lds +0 -0
index 3bb759d8a1c..5ad169a37b7 100644

arch/arm/mach-omap2/u-boot-spl.lds SECTIONS · line 42

Quoted 8 lines
arch/arm/mach-omap2/u-boot-spl.lds +5 -0
@@ -35,9 +35,13 @@ SECTIONS
 	. = ALIGN(4);
 	__u_boot_list : {
 		KEEP(*(SORT(__u_boot_list*)));
+		/*
+		 * Ensure 8-byte alignment at the end of the last section before
+		 * DTB is appended, to satisfy DT spec alignment requirements
+		 */
+		. = ALIGN(8);

I wonder if there could be a better way to handle this constraint, currently we have two major problems with this approach:

1. All platforms facing similar alignment issues would have to modify their linker scripts.

2. The FDT only gets appended directly to SPL binary in cases of CONFIG_SPL_SEPARATE_BSS. Otherwise we do (SPL binary + BSS + FDT) as per the $(obj)/$(SPL_BIN)-dtb.bin make target. Which means BSS would have to be 8-byte aligned as well as the SPL binary.

I wonder if we could have a new make target for say u-boot-spl-nodtb-aligned.bin which is just (SPL binary + optionally BSS
+ padding for alignment) and at runtime we modify the fdt addr in gd to point to the correctly aligned address?

Quoted 6 lines
arch/arm/mach-omap2/u-boot-spl.lds +0 -1
 	} >.sram
 
-	. = ALIGN(4);
 	__image_copy_end = .;
 	_end = .;
 	_image_binary_end = .;
#13 lore raw

Re: [PATCH v2 2/2] ARM: OMAP2+: Pad SPL binary to 8-byte alignment before DTB

Quoted 50 lines · Anshul Dalal
Quoted 37 lines · Beleswar Padhi

The OMAP2 SPL linker script (also used for K3 platforms) currently uses a 4-byte alignment directive after the __u_boot_list section. This alignment directive only advances the location counter without padding the actual binary output.

When objcopy extracts u-boot-spl-nodtb.bin, it includes only actual data, stopping at the last byte of __u_boot_list (e.g., 0x41c359fc), not an aligned address (e.g., 0x41c35a00). So, when the FIT image containing device trees is concatenated to the SPL binary, it gets appended at this unaligned file size, causing libfdt validation failure.

To fix this, move the alignment directive into the __u_boot_list section itself and make it 8-byte aligned as per DT spec. This forces the linker to include padding as part of the section data, ensuring objcopy includes the padding bytes in the binary and the appended FIT image starts at an 8-byte aligned boundary.

Fixes 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")

---
v2: Changelog:
1. Get rid of extra ALIGN() directive, replace it with a comment
2. Carry Reported-by, Closes and Fixes tag.

Link to v1:
https://lore.kernel.org/all/[email protected]/

 arch/arm/mach-omap2/u-boot-spl.lds | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/arm/mach-omap2/u-boot-spl.lds +0 -0
index 3bb759d8a1c..5ad169a37b7 100644

arch/arm/mach-omap2/u-boot-spl.lds SECTIONS · line 42

Quoted 8 lines
arch/arm/mach-omap2/u-boot-spl.lds +5 -0
@@ -35,9 +35,13 @@ SECTIONS
 	. = ALIGN(4);
 	__u_boot_list : {
 		KEEP(*(SORT(__u_boot_list*)));
+		/*
+		 * Ensure 8-byte alignment at the end of the last section before
+		 * DTB is appended, to satisfy DT spec alignment requirements
+		 */
+		. = ALIGN(8);

I wonder if there could be a better way to handle this constraint, currently we have two major problems with this approach:

Quoted 2 lines

1. All platforms facing similar alignment issues would have to modify their linker scripts.

Yes, agreed.

Quoted 9 lines

2. The FDT only gets appended directly to SPL binary in cases of CONFIG_SPL_SEPARATE_BSS. Otherwise we do (SPL binary + BSS + FDT) as per the $(obj)/$(SPL_BIN)-dtb.bin make target. Which means BSS would have to be 8-byte aligned as well as the SPL binary.

I wonder if we could have a new make target for say u-boot-spl-nodtb-aligned.bin which is just (SPL binary + optionally BSS
+ padding for alignment) and at runtime we modify the fdt addr in gd to point to the correctly aligned address?

Looking back at
https://lore.kernel.org/all/[email protected]/ we can use dd as a portable way to ensure that a file ends with 8-byte alignmnent by doing:
dd if=testfile bs=8 conv=sync of=testfile_pad
and we get a zero-padded 8-byte aligned output file, and at the end of that we can concatenate our dtb.

That would just leave the FIT images as the issue, which Marek provided feedback on in 1/2, yes?

Signature · 1 line
Tom
#14 lore raw

Re: [PATCH v2 2/2] ARM: OMAP2+: Pad SPL binary to 8-byte alignment before DTB

Quoted 66 lines · Tom Rini
Quoted 50 lines · Anshul Dalal
Quoted 37 lines · Beleswar Padhi

The OMAP2 SPL linker script (also used for K3 platforms) currently uses a 4-byte alignment directive after the __u_boot_list section. This alignment directive only advances the location counter without padding the actual binary output.

When objcopy extracts u-boot-spl-nodtb.bin, it includes only actual data, stopping at the last byte of __u_boot_list (e.g., 0x41c359fc), not an aligned address (e.g., 0x41c35a00). So, when the FIT image containing device trees is concatenated to the SPL binary, it gets appended at this unaligned file size, causing libfdt validation failure.

To fix this, move the alignment directive into the __u_boot_list section itself and make it 8-byte aligned as per DT spec. This forces the linker to include padding as part of the section data, ensuring objcopy includes the padding bytes in the binary and the appended FIT image starts at an 8-byte aligned boundary.

Fixes 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")

---
v2: Changelog:
1. Get rid of extra ALIGN() directive, replace it with a comment
2. Carry Reported-by, Closes and Fixes tag.

Link to v1:
https://lore.kernel.org/all/[email protected]/

  arch/arm/mach-omap2/u-boot-spl.lds | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
arch/arm/mach-omap2/u-boot-spl.lds +0 -0
index 3bb759d8a1c..5ad169a37b7 100644

arch/arm/mach-omap2/u-boot-spl.lds SECTIONS · line 42

Quoted 8 lines
arch/arm/mach-omap2/u-boot-spl.lds +5 -0
@@ -35,9 +35,13 @@ SECTIONS
  	. = ALIGN(4);
  	__u_boot_list : {
  		KEEP(*(SORT(__u_boot_list*)));
+		/*
+		 * Ensure 8-byte alignment at the end of the last section before
+		 * DTB is appended, to satisfy DT spec alignment requirements
+		 */
+		. = ALIGN(8);

I wonder if there could be a better way to handle this constraint, currently we have two major problems with this approach:

Quoted 2 lines

1. All platforms facing similar alignment issues would have to modify their linker scripts.

Yes, agreed.

Quoted 9 lines

2. The FDT only gets appended directly to SPL binary in cases of CONFIG_SPL_SEPARATE_BSS. Otherwise we do (SPL binary + BSS + FDT) as per the $(obj)/$(SPL_BIN)-dtb.bin make target. Which means BSS would have to be 8-byte aligned as well as the SPL binary.

I wonder if we could have a new make target for say u-boot-spl-nodtb-aligned.bin which is just (SPL binary + optionally BSS
+ padding for alignment) and at runtime we modify the fdt addr in gd to point to the correctly aligned address?

Quoted 7 lines

Looking back at
https://lore.kernel.org/all/[email protected]/ we can use dd as a portable way to ensure that a file ends with 8-byte alignmnent by doing:
dd if=testfile bs=8 conv=sync of=testfile_pad
and we get a zero-padded 8-byte aligned output file, and at the end of that we can concatenate our dtb.

You still need to make sure there is a symbol generated by the linker that points at the END of the u-boot binary . dd happens too late, so you cannot do that. The alignment has to be done by the linker, in the linker script I think.

#15 lore raw

Re: [PATCH v2 2/2] ARM: OMAP2+: Pad SPL binary to 8-byte alignment before DTB

Quoted 74 lines · Marek Vasut
Quoted 66 lines · Tom Rini
Quoted 50 lines · Anshul Dalal
Quoted 37 lines · Beleswar Padhi

The OMAP2 SPL linker script (also used for K3 platforms) currently uses a 4-byte alignment directive after the __u_boot_list section. This alignment directive only advances the location counter without padding the actual binary output.

When objcopy extracts u-boot-spl-nodtb.bin, it includes only actual data, stopping at the last byte of __u_boot_list (e.g., 0x41c359fc), not an aligned address (e.g., 0x41c35a00). So, when the FIT image containing device trees is concatenated to the SPL binary, it gets appended at this unaligned file size, causing libfdt validation failure.

To fix this, move the alignment directive into the __u_boot_list section itself and make it 8-byte aligned as per DT spec. This forces the linker to include padding as part of the section data, ensuring objcopy includes the padding bytes in the binary and the appended FIT image starts at an 8-byte aligned boundary.

Fixes 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")

---
v2: Changelog:
1. Get rid of extra ALIGN() directive, replace it with a comment
2. Carry Reported-by, Closes and Fixes tag.

Link to v1:
https://lore.kernel.org/all/[email protected]/

  arch/arm/mach-omap2/u-boot-spl.lds | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
arch/arm/mach-omap2/u-boot-spl.lds +0 -0
index 3bb759d8a1c..5ad169a37b7 100644

arch/arm/mach-omap2/u-boot-spl.lds SECTIONS · line 42

Quoted 8 lines
arch/arm/mach-omap2/u-boot-spl.lds +5 -0
@@ -35,9 +35,13 @@ SECTIONS
  	. = ALIGN(4);
  	__u_boot_list : {
  		KEEP(*(SORT(__u_boot_list*)));
+		/*
+		 * Ensure 8-byte alignment at the end of the last section before
+		 * DTB is appended, to satisfy DT spec alignment requirements
+		 */
+		. = ALIGN(8);

I wonder if there could be a better way to handle this constraint, currently we have two major problems with this approach:

Quoted 2 lines

1. All platforms facing similar alignment issues would have to modify their linker scripts.

Yes, agreed.

Quoted 9 lines

2. The FDT only gets appended directly to SPL binary in cases of CONFIG_SPL_SEPARATE_BSS. Otherwise we do (SPL binary + BSS + FDT) as per the $(obj)/$(SPL_BIN)-dtb.bin make target. Which means BSS would have to be 8-byte aligned as well as the SPL binary.

I wonder if we could have a new make target for say u-boot-spl-nodtb-aligned.bin which is just (SPL binary + optionally BSS
+ padding for alignment) and at runtime we modify the fdt addr in gd to point to the correctly aligned address?

Quoted 7 lines

Looking back at
https://lore.kernel.org/all/[email protected]/ we can use dd as a portable way to ensure that a file ends with 8-byte alignmnent by doing:
dd if=testfile bs=8 conv=sync of=testfile_pad
and we get a zero-padded 8-byte aligned output file, and at the end of that we can concatenate our dtb.

Quoted 4 lines

You still need to make sure there is a symbol generated by the linker that points at the END of the u-boot binary . dd happens too late, so you cannot do that. The alignment has to be done by the linker, in the linker script I think.

I guess the question is are we:
a) Look at $sym for device tree, and so $sym must be 8-byte aligned.
b) Look at end of self, rounded up to alignment, for device tree
c) (a) on some platforms (b) on other platforms
?

Signature · 1 line
Tom
#16 lore raw

Re: [PATCH v2 2/2] ARM: OMAP2+: Pad SPL binary to 8-byte alignment before DTB

Quoted 80 lines · Tom Rini
Quoted 74 lines · Marek Vasut
Quoted 66 lines · Tom Rini
Quoted 50 lines · Anshul Dalal
Quoted 37 lines · Beleswar Padhi

The OMAP2 SPL linker script (also used for K3 platforms) currently uses a 4-byte alignment directive after the __u_boot_list section. This alignment directive only advances the location counter without padding the actual binary output.

When objcopy extracts u-boot-spl-nodtb.bin, it includes only actual data, stopping at the last byte of __u_boot_list (e.g., 0x41c359fc), not an aligned address (e.g., 0x41c35a00). So, when the FIT image containing device trees is concatenated to the SPL binary, it gets appended at this unaligned file size, causing libfdt validation failure.

To fix this, move the alignment directive into the __u_boot_list section itself and make it 8-byte aligned as per DT spec. This forces the linker to include padding as part of the section data, ensuring objcopy includes the padding bytes in the binary and the appended FIT image starts at an 8-byte aligned boundary.

Fixes 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")

---
v2: Changelog:
1. Get rid of extra ALIGN() directive, replace it with a comment
2. Carry Reported-by, Closes and Fixes tag.

Link to v1:
https://lore.kernel.org/all/[email protected]/

   arch/arm/mach-omap2/u-boot-spl.lds | 6 +++++-
   1 file changed, 5 insertions(+), 1 deletion(-)
arch/arm/mach-omap2/u-boot-spl.lds +0 -0
index 3bb759d8a1c..5ad169a37b7 100644

arch/arm/mach-omap2/u-boot-spl.lds SECTIONS · line 42

Quoted 8 lines
arch/arm/mach-omap2/u-boot-spl.lds +5 -0
@@ -35,9 +35,13 @@ SECTIONS
   	. = ALIGN(4);
   	__u_boot_list : {
   		KEEP(*(SORT(__u_boot_list*)));
+		/*
+		 * Ensure 8-byte alignment at the end of the last section before
+		 * DTB is appended, to satisfy DT spec alignment requirements
+		 */
+		. = ALIGN(8);

I wonder if there could be a better way to handle this constraint, currently we have two major problems with this approach:

Quoted 2 lines

1. All platforms facing similar alignment issues would have to modify their linker scripts.

Yes, agreed.

Quoted 9 lines

2. The FDT only gets appended directly to SPL binary in cases of CONFIG_SPL_SEPARATE_BSS. Otherwise we do (SPL binary + BSS + FDT) as per the $(obj)/$(SPL_BIN)-dtb.bin make target. Which means BSS would have to be 8-byte aligned as well as the SPL binary.

I wonder if we could have a new make target for say u-boot-spl-nodtb-aligned.bin which is just (SPL binary + optionally BSS
+ padding for alignment) and at runtime we modify the fdt addr in gd to point to the correctly aligned address?

Quoted 7 lines

Looking back at
https://lore.kernel.org/all/[email protected]/ we can use dd as a portable way to ensure that a file ends with 8-byte alignmnent by doing:
dd if=testfile bs=8 conv=sync of=testfile_pad
and we get a zero-padded 8-byte aligned output file, and at the end of that we can concatenate our dtb.

Quoted 4 lines

You still need to make sure there is a symbol generated by the linker that points at the END of the u-boot binary . dd happens too late, so you cannot do that. The alignment has to be done by the linker, in the linker script I think.

Quoted 5 lines

I guess the question is are we:
a) Look at $sym for device tree, and so $sym must be 8-byte aligned.
b) Look at end of self, rounded up to alignment, for device tree
c) (a) on some platforms (b) on other platforms
?

$sym is at the end, which is not always 8 byte aligned . See lib/fdtdec.c for the relevant code:

1243 static void *fdt_find_separate(void)
1244 {
1245 void *fdt_blob = NULL;
1246
1247 if (IS_ENABLED(CONFIG_SANDBOX))
1248 return NULL;
1249
1250 #ifdef CONFIG_XPL_BUILD
1251 /* FDT is at end of BSS unless it is in a different memory region */
1252 if (CONFIG_IS_ENABLED(SEPARATE_BSS))
1253 fdt_blob = (ulong *)_image_binary_end;
1254 else
1255 fdt_blob = (ulong *)__bss_end;

#17 lore raw

Re: [PATCH v2 2/2] ARM: OMAP2+: Pad SPL binary to 8-byte alignment before DTB

Quoted 89 lines · Marek Vasut
Quoted 80 lines · Tom Rini
Quoted 74 lines · Marek Vasut
Quoted 66 lines · Tom Rini
Quoted 50 lines · Anshul Dalal
Quoted 37 lines · Beleswar Padhi

The OMAP2 SPL linker script (also used for K3 platforms) currently uses a 4-byte alignment directive after the __u_boot_list section. This alignment directive only advances the location counter without padding the actual binary output.

When objcopy extracts u-boot-spl-nodtb.bin, it includes only actual data, stopping at the last byte of __u_boot_list (e.g., 0x41c359fc), not an aligned address (e.g., 0x41c35a00). So, when the FIT image containing device trees is concatenated to the SPL binary, it gets appended at this unaligned file size, causing libfdt validation failure.

To fix this, move the alignment directive into the __u_boot_list section itself and make it 8-byte aligned as per DT spec. This forces the linker to include padding as part of the section data, ensuring objcopy includes the padding bytes in the binary and the appended FIT image starts at an 8-byte aligned boundary.

Fixes 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")

---
v2: Changelog:
1. Get rid of extra ALIGN() directive, replace it with a comment
2. Carry Reported-by, Closes and Fixes tag.

Link to v1:
https://lore.kernel.org/all/[email protected]/

   arch/arm/mach-omap2/u-boot-spl.lds | 6 +++++-
   1 file changed, 5 insertions(+), 1 deletion(-)
arch/arm/mach-omap2/u-boot-spl.lds +0 -0
index 3bb759d8a1c..5ad169a37b7 100644

arch/arm/mach-omap2/u-boot-spl.lds SECTIONS · line 42

Quoted 8 lines
arch/arm/mach-omap2/u-boot-spl.lds +5 -0
@@ -35,9 +35,13 @@ SECTIONS
   	. = ALIGN(4);
   	__u_boot_list : {
   		KEEP(*(SORT(__u_boot_list*)));
+		/*
+		 * Ensure 8-byte alignment at the end of the last section before
+		 * DTB is appended, to satisfy DT spec alignment requirements
+		 */
+		. = ALIGN(8);

I wonder if there could be a better way to handle this constraint, currently we have two major problems with this approach:

Quoted 2 lines

1. All platforms facing similar alignment issues would have to modify their linker scripts.

Yes, agreed.

Quoted 9 lines

2. The FDT only gets appended directly to SPL binary in cases of CONFIG_SPL_SEPARATE_BSS. Otherwise we do (SPL binary + BSS + FDT) as per the $(obj)/$(SPL_BIN)-dtb.bin make target. Which means BSS would have to be 8-byte aligned as well as the SPL binary.

I wonder if we could have a new make target for say u-boot-spl-nodtb-aligned.bin which is just (SPL binary + optionally BSS
+ padding for alignment) and at runtime we modify the fdt addr in gd to point to the correctly aligned address?

Quoted 7 lines

Looking back at
https://lore.kernel.org/all/[email protected]/ we can use dd as a portable way to ensure that a file ends with 8-byte alignmnent by doing:
dd if=testfile bs=8 conv=sync of=testfile_pad
and we get a zero-padded 8-byte aligned output file, and at the end of that we can concatenate our dtb.

Quoted 4 lines

You still need to make sure there is a symbol generated by the linker that points at the END of the u-boot binary . dd happens too late, so you cannot do that. The alignment has to be done by the linker, in the linker script I think.

Quoted 5 lines

I guess the question is are we:
a) Look at $sym for device tree, and so $sym must be 8-byte aligned.
b) Look at end of self, rounded up to alignment, for device tree
c) (a) on some platforms (b) on other platforms
?

$sym is at the end, which is not always 8 byte aligned . See lib/fdtdec.c for the relevant code:

Quoted 14 lines

1243 static void *fdt_find_separate(void)
1244 {
1245 void *fdt_blob = NULL;
1246
1247 if (IS_ENABLED(CONFIG_SANDBOX))
1248 return NULL;
1249
1250 #ifdef CONFIG_XPL_BUILD
1251 /* FDT is at end of BSS unless it is in a different memory
region */
1252 if (CONFIG_IS_ENABLED(SEPARATE_BSS))
1253 fdt_blob = (ulong *)_image_binary_end;
1254 else
1255 fdt_blob = (ulong *)__bss_end;

OK. And why can't we make that check at $sym rounded up, and ensure our build targets pad? Going back to the commit message here, it's easy to tell the linker to place $sym at the right spot, but it's hard to make sure the output is padded. So having typed all that, maybe we need to do:
d) Update linker scripts to ALIGN(8) the above symbols and have the make targets use dd to ensure padding prior to concatenation
?

Signature · 1 line
Tom
#18 lore raw

Re: [PATCH v2 2/2] ARM: OMAP2+: Pad SPL binary to 8-byte alignment before DTB

Quoted 105 lines · Tom Rini
Quoted 89 lines · Marek Vasut
Quoted 80 lines · Tom Rini
Quoted 74 lines · Marek Vasut
Quoted 66 lines · Tom Rini
Quoted 50 lines · Anshul Dalal
Quoted 37 lines · Beleswar Padhi

The OMAP2 SPL linker script (also used for K3 platforms) currently uses a 4-byte alignment directive after the __u_boot_list section. This alignment directive only advances the location counter without padding the actual binary output.

When objcopy extracts u-boot-spl-nodtb.bin, it includes only actual data, stopping at the last byte of __u_boot_list (e.g., 0x41c359fc), not an aligned address (e.g., 0x41c35a00). So, when the FIT image containing device trees is concatenated to the SPL binary, it gets appended at this unaligned file size, causing libfdt validation failure.

To fix this, move the alignment directive into the __u_boot_list section itself and make it 8-byte aligned as per DT spec. This forces the linker to include padding as part of the section data, ensuring objcopy includes the padding bytes in the binary and the appended FIT image starts at an 8-byte aligned boundary.

Fixes 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")

---
v2: Changelog:
1. Get rid of extra ALIGN() directive, replace it with a comment
2. Carry Reported-by, Closes and Fixes tag.

Link to v1:
https://lore.kernel.org/all/[email protected]/

   arch/arm/mach-omap2/u-boot-spl.lds | 6 +++++-
   1 file changed, 5 insertions(+), 1 deletion(-)
arch/arm/mach-omap2/u-boot-spl.lds +0 -0
index 3bb759d8a1c..5ad169a37b7 100644

arch/arm/mach-omap2/u-boot-spl.lds SECTIONS · line 42

Quoted 8 lines
arch/arm/mach-omap2/u-boot-spl.lds +5 -0
@@ -35,9 +35,13 @@ SECTIONS
   	. = ALIGN(4);
   	__u_boot_list : {
   		KEEP(*(SORT(__u_boot_list*)));
+		/*
+		 * Ensure 8-byte alignment at the end of the last section before
+		 * DTB is appended, to satisfy DT spec alignment requirements
+		 */
+		. = ALIGN(8);

I wonder if there could be a better way to handle this constraint, currently we have two major problems with this approach:

Quoted 2 lines

1. All platforms facing similar alignment issues would have to modify their linker scripts.

Yes, agreed.

Quoted 9 lines

2. The FDT only gets appended directly to SPL binary in cases of CONFIG_SPL_SEPARATE_BSS. Otherwise we do (SPL binary + BSS + FDT) as per the $(obj)/$(SPL_BIN)-dtb.bin make target. Which means BSS would have to be 8-byte aligned as well as the SPL binary.

I wonder if we could have a new make target for say u-boot-spl-nodtb-aligned.bin which is just (SPL binary + optionally BSS
+ padding for alignment) and at runtime we modify the fdt addr in gd to point to the correctly aligned address?

Quoted 7 lines

Looking back at
https://lore.kernel.org/all/[email protected]/ we can use dd as a portable way to ensure that a file ends with 8-byte alignmnent by doing:
dd if=testfile bs=8 conv=sync of=testfile_pad
and we get a zero-padded 8-byte aligned output file, and at the end of that we can concatenate our dtb.

Quoted 4 lines

You still need to make sure there is a symbol generated by the linker that points at the END of the u-boot binary . dd happens too late, so you cannot do that. The alignment has to be done by the linker, in the linker script I think.

Quoted 5 lines

I guess the question is are we:
a) Look at $sym for device tree, and so $sym must be 8-byte aligned.
b) Look at end of self, rounded up to alignment, for device tree
c) (a) on some platforms (b) on other platforms
?

$sym is at the end, which is not always 8 byte aligned . See lib/fdtdec.c for the relevant code:

Quoted 14 lines

1243 static void *fdt_find_separate(void)
1244 {
1245 void *fdt_blob = NULL;
1246
1247 if (IS_ENABLED(CONFIG_SANDBOX))
1248 return NULL;
1249
1250 #ifdef CONFIG_XPL_BUILD
1251 /* FDT is at end of BSS unless it is in a different memory
region */
1252 if (CONFIG_IS_ENABLED(SEPARATE_BSS))
1253 fdt_blob = (ulong *)_image_binary_end;
1254 else
1255 fdt_blob = (ulong *)__bss_end;

Quoted 8 lines

OK. And why can't we make that check at $sym rounded up, and ensure our build targets pad? Going back to the commit message here, it's easy to tell the linker to place $sym at the right spot, but it's hard to make sure the output is padded. So having typed all that, maybe we need to do:
d) Update linker scripts to ALIGN(8) the above symbols and have the make targets use dd to ensure padding prior to concatenation
?

Now that I've got a target where this issue is cropping up, and I can easily iterate on testing things, I *think* I was going in the wrong direction with dd. My inclination right now is to take (very soon) Beleswar's patch since they figured out the hard part on how to get the linker to do what we want and follow-up with my own commit cleaning up the other 12 linker files or so that seem to need a similar change.

Signature · 1 line
Tom
#19 lore raw

Re: [PATCH v2 2/2] ARM: OMAP2+: Pad SPL binary to 8-byte alignment before DTB

In reply to Tom Rini
Quoted 105 lines · Tom Rini
Quoted 89 lines · Marek Vasut
Quoted 80 lines · Tom Rini
Quoted 74 lines · Marek Vasut
Quoted 66 lines · Tom Rini
Quoted 50 lines · Anshul Dalal
Quoted 37 lines · Beleswar Padhi

The OMAP2 SPL linker script (also used for K3 platforms) currently uses a 4-byte alignment directive after the __u_boot_list section. This alignment directive only advances the location counter without padding the actual binary output.

When objcopy extracts u-boot-spl-nodtb.bin, it includes only actual data, stopping at the last byte of __u_boot_list (e.g., 0x41c359fc), not an aligned address (e.g., 0x41c35a00). So, when the FIT image containing device trees is concatenated to the SPL binary, it gets appended at this unaligned file size, causing libfdt validation failure.

To fix this, move the alignment directive into the __u_boot_list section itself and make it 8-byte aligned as per DT spec. This forces the linker to include padding as part of the section data, ensuring objcopy includes the padding bytes in the binary and the appended FIT image starts at an 8-byte aligned boundary.

Fixes 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")

---
v2: Changelog:
1. Get rid of extra ALIGN() directive, replace it with a comment
2. Carry Reported-by, Closes and Fixes tag.

Link to v1:
https://lore.kernel.org/all/[email protected]/

    arch/arm/mach-omap2/u-boot-spl.lds | 6 +++++-
    1 file changed, 5 insertions(+), 1 deletion(-)
arch/arm/mach-omap2/u-boot-spl.lds +0 -0
index 3bb759d8a1c..5ad169a37b7 100644

arch/arm/mach-omap2/u-boot-spl.lds SECTIONS · line 42

Quoted 8 lines
arch/arm/mach-omap2/u-boot-spl.lds +5 -0
@@ -35,9 +35,13 @@ SECTIONS
    	. = ALIGN(4);
    	__u_boot_list : {
    		KEEP(*(SORT(__u_boot_list*)));
+		/*
+		 * Ensure 8-byte alignment at the end of the last section before
+		 * DTB is appended, to satisfy DT spec alignment requirements
+		 */
+		. = ALIGN(8);

I wonder if there could be a better way to handle this constraint, currently we have two major problems with this approach:

Quoted 2 lines

1. All platforms facing similar alignment issues would have to modify their linker scripts.

Yes, agreed.

Quoted 9 lines

2. The FDT only gets appended directly to SPL binary in cases of CONFIG_SPL_SEPARATE_BSS. Otherwise we do (SPL binary + BSS + FDT) as per the $(obj)/$(SPL_BIN)-dtb.bin make target. Which means BSS would have to be 8-byte aligned as well as the SPL binary.

I wonder if we could have a new make target for say u-boot-spl-nodtb-aligned.bin which is just (SPL binary + optionally BSS
+ padding for alignment) and at runtime we modify the fdt addr in gd to point to the correctly aligned address?

Quoted 7 lines

Looking back at
https://lore.kernel.org/all/[email protected]/ we can use dd as a portable way to ensure that a file ends with 8-byte alignmnent by doing:
dd if=testfile bs=8 conv=sync of=testfile_pad
and we get a zero-padded 8-byte aligned output file, and at the end of that we can concatenate our dtb.

Quoted 4 lines

You still need to make sure there is a symbol generated by the linker that points at the END of the u-boot binary . dd happens too late, so you cannot do that. The alignment has to be done by the linker, in the linker script I think.

Quoted 5 lines

I guess the question is are we:
a) Look at $sym for device tree, and so $sym must be 8-byte aligned.
b) Look at end of self, rounded up to alignment, for device tree
c) (a) on some platforms (b) on other platforms
?

$sym is at the end, which is not always 8 byte aligned . See lib/fdtdec.c for the relevant code:

Quoted 14 lines

1243 static void *fdt_find_separate(void)
1244 {
1245 void *fdt_blob = NULL;
1246
1247 if (IS_ENABLED(CONFIG_SANDBOX))
1248 return NULL;
1249
1250 #ifdef CONFIG_XPL_BUILD
1251 /* FDT is at end of BSS unless it is in a different memory
region */
1252 if (CONFIG_IS_ENABLED(SEPARATE_BSS))
1253 fdt_blob = (ulong *)_image_binary_end;
1254 else
1255 fdt_blob = (ulong *)__bss_end;

Quoted 8 lines

OK. And why can't we make that check at $sym rounded up, and ensure our build targets pad? Going back to the commit message here, it's easy to tell the linker to place $sym at the right spot, but it's hard to make sure the output is padded. So having typed all that, maybe we need to do:
d) Update linker scripts to ALIGN(8) the above symbols and have the make targets use dd to ensure padding prior to concatenation
?

d) looks like what we should do, yes

#20 lore raw

Re: [PATCH v2 2/2] ARM: OMAP2+: Pad SPL binary to 8-byte alignment before DTB

Quoted 114 lines · Marek Vasut
Quoted 105 lines · Tom Rini
Quoted 89 lines · Marek Vasut
Quoted 80 lines · Tom Rini
Quoted 74 lines · Marek Vasut
Quoted 66 lines · Tom Rini
Quoted 50 lines · Anshul Dalal
Quoted 37 lines · Beleswar Padhi

The OMAP2 SPL linker script (also used for K3 platforms) currently uses a 4-byte alignment directive after the __u_boot_list section. This alignment directive only advances the location counter without padding the actual binary output.

When objcopy extracts u-boot-spl-nodtb.bin, it includes only actual data, stopping at the last byte of __u_boot_list (e.g., 0x41c359fc), not an aligned address (e.g., 0x41c35a00). So, when the FIT image containing device trees is concatenated to the SPL binary, it gets appended at this unaligned file size, causing libfdt validation failure.

To fix this, move the alignment directive into the __u_boot_list section itself and make it 8-byte aligned as per DT spec. This forces the linker to include padding as part of the section data, ensuring objcopy includes the padding bytes in the binary and the appended FIT image starts at an 8-byte aligned boundary.

Fixes 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")

---
v2: Changelog:
1. Get rid of extra ALIGN() directive, replace it with a comment
2. Carry Reported-by, Closes and Fixes tag.

Link to v1:
https://lore.kernel.org/all/[email protected]/

    arch/arm/mach-omap2/u-boot-spl.lds | 6 +++++-
    1 file changed, 5 insertions(+), 1 deletion(-)
arch/arm/mach-omap2/u-boot-spl.lds +0 -0
index 3bb759d8a1c..5ad169a37b7 100644

arch/arm/mach-omap2/u-boot-spl.lds SECTIONS · line 42

Quoted 8 lines
arch/arm/mach-omap2/u-boot-spl.lds +5 -0
@@ -35,9 +35,13 @@ SECTIONS
    	. = ALIGN(4);
    	__u_boot_list : {
    		KEEP(*(SORT(__u_boot_list*)));
+		/*
+		 * Ensure 8-byte alignment at the end of the last section before
+		 * DTB is appended, to satisfy DT spec alignment requirements
+		 */
+		. = ALIGN(8);

I wonder if there could be a better way to handle this constraint, currently we have two major problems with this approach:

Quoted 2 lines

1. All platforms facing similar alignment issues would have to modify their linker scripts.

Yes, agreed.

Quoted 9 lines

2. The FDT only gets appended directly to SPL binary in cases of CONFIG_SPL_SEPARATE_BSS. Otherwise we do (SPL binary + BSS + FDT) as per the $(obj)/$(SPL_BIN)-dtb.bin make target. Which means BSS would have to be 8-byte aligned as well as the SPL binary.

I wonder if we could have a new make target for say u-boot-spl-nodtb-aligned.bin which is just (SPL binary + optionally BSS
+ padding for alignment) and at runtime we modify the fdt addr in gd to point to the correctly aligned address?

Quoted 7 lines

Looking back at
https://lore.kernel.org/all/[email protected]/ we can use dd as a portable way to ensure that a file ends with 8-byte alignmnent by doing:
dd if=testfile bs=8 conv=sync of=testfile_pad
and we get a zero-padded 8-byte aligned output file, and at the end of that we can concatenate our dtb.

Quoted 4 lines

You still need to make sure there is a symbol generated by the linker that points at the END of the u-boot binary . dd happens too late, so you cannot do that. The alignment has to be done by the linker, in the linker script I think.

Quoted 5 lines

I guess the question is are we:
a) Look at $sym for device tree, and so $sym must be 8-byte aligned.
b) Look at end of self, rounded up to alignment, for device tree
c) (a) on some platforms (b) on other platforms
?

$sym is at the end, which is not always 8 byte aligned . See lib/fdtdec.c for the relevant code:

Quoted 14 lines

1243 static void *fdt_find_separate(void)
1244 {
1245 void *fdt_blob = NULL;
1246
1247 if (IS_ENABLED(CONFIG_SANDBOX))
1248 return NULL;
1249
1250 #ifdef CONFIG_XPL_BUILD
1251 /* FDT is at end of BSS unless it is in a different memory
region */
1252 if (CONFIG_IS_ENABLED(SEPARATE_BSS))
1253 fdt_blob = (ulong *)_image_binary_end;
1254 else
1255 fdt_blob = (ulong *)__bss_end;

Quoted 8 lines

OK. And why can't we make that check at $sym rounded up, and ensure our build targets pad? Going back to the commit message here, it's easy to tell the linker to place $sym at the right spot, but it's hard to make sure the output is padded. So having typed all that, maybe we need to do:
d) Update linker scripts to ALIGN(8) the above symbols and have the make targets use dd to ensure padding prior to concatenation
?

Quoted 1 line

d) looks like what we should do, yes

Poking at this harder, I'm not actually sure we need to use dd at all, but we do need to fix our linker scripts, and then going back to when Ilias reworked and cleaned up a bunch of them, get the changes reviewed by the toolchain experts he got ahold of :)

Signature · 1 line
Tom
#21 lore raw

Re: [PATCH v2 2/2] ARM: OMAP2+: Pad SPL binary to 8-byte alignment before DTB

On 1/14/26 3:17 PM, Tom Rini wrote:

Hello Tom,

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

OK. And why can't we make that check at $sym rounded up, and ensure our build targets pad? Going back to the commit message here, it's easy to tell the linker to place $sym at the right spot, but it's hard to make sure the output is padded. So having typed all that, maybe we need to do:
d) Update linker scripts to ALIGN(8) the above symbols and have the make targets use dd to ensure padding prior to concatenation
?

Quoted 6 lines
Quoted 1 line

d) looks like what we should do, yes

Poking at this harder, I'm not actually sure we need to use dd at all, but we do need to fix our linker scripts, and then going back to when Ilias reworked and cleaned up a bunch of them, get the changes reviewed by the toolchain experts he got ahold of :)

I wonder if LD can always guarantee trailing alignment of the binary. If it can, then yes, dd would only be obscuring alignment problems and trailing DT look up failures which are hard to debug. It would be nice to drop the dd part, but I am not sure if we are able to do it reliably.

#22 lore raw

Re: [PATCH v2 2/2] ARM: OMAP2+: Pad SPL binary to 8-byte alignment before DTB

Hi Marek,

Quoted 20 lines · Marek Vasut

On 1/14/26 3:17 PM, Tom Rini wrote:

Hello Tom,

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

OK. And why can't we make that check at $sym rounded up, and ensure our build targets pad? Going back to the commit message here, it's easy to tell the linker to place $sym at the right spot, but it's hard to make sure the output is padded. So having typed all that, maybe we need to do:
d) Update linker scripts to ALIGN(8) the above symbols and have the make targets use dd to ensure padding prior to concatenation
?

Quoted 6 lines
Quoted 1 line

d) looks like what we should do, yes

Poking at this harder, I'm not actually sure we need to use dd at all, but we do need to fix our linker scripts, and then going back to when Ilias reworked and cleaned up a bunch of them, get the changes reviewed by the toolchain experts he got ahold of :)

Quoted 4 lines

I wonder if LD can always guarantee trailing alignment of the binary. If it can, then yes, dd would only be obscuring alignment problems and trailing DT look up failures which are hard to debug. It would be nice to drop the dd part, but I am not sure if we are able to do it reliably.

LD won't pad align anything that doesn't have code afterwards. IOW inserting an . = ALIGN(8); just before the .end symbol won't guarantee alignement unless there's a section/code following.
What you can do is add an ALIGN(8) inside the last section. That will guarantee that the last symbol is aligned. There's also the SUBALIGN command which messes around with the input section alignment -- that normally is automatically calculated, but Tom tested it yesterday without success.

I'll have a closer look to the linker script in case I can come up with something more elegant. Which defconfig should I use to reproduce the issue?

Cheers
/Ilias

#23 lore raw

Re: [PATCH v2 2/2] ARM: OMAP2+: Pad SPL binary to 8-byte alignment before DTB

Quoted 38 lines · Ilias Apalodimas

Hi Marek,

Quoted 20 lines · Marek Vasut

On 1/14/26 3:17 PM, Tom Rini wrote:

Hello Tom,

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

OK. And why can't we make that check at $sym rounded up, and ensure our build targets pad? Going back to the commit message here, it's easy to tell the linker to place $sym at the right spot, but it's hard to make sure the output is padded. So having typed all that, maybe we need to do:
d) Update linker scripts to ALIGN(8) the above symbols and have the make targets use dd to ensure padding prior to concatenation
?

Quoted 6 lines
Quoted 1 line

d) looks like what we should do, yes

Poking at this harder, I'm not actually sure we need to use dd at all, but we do need to fix our linker scripts, and then going back to when Ilias reworked and cleaned up a bunch of them, get the changes reviewed by the toolchain experts he got ahold of :)

Quoted 4 lines

I wonder if LD can always guarantee trailing alignment of the binary. If it can, then yes, dd would only be obscuring alignment problems and trailing DT look up failures which are hard to debug. It would be nice to drop the dd part, but I am not sure if we are able to do it reliably.

LD won't pad align anything that doesn't have code afterwards. IOW inserting an . = ALIGN(8); just before the .end symbol won't guarantee alignement unless there's a section/code following.
What you can do is add an ALIGN(8) inside the last section. That will guarantee that the last symbol is aligned. There's also the SUBALIGN command which messes around with the input section alignment -- that normally is automatically calculated, but Tom tested it yesterday without success.

Quoted 3 lines

I'll have a closer look to the linker script in case I can come up with something more elegant. Which defconfig should I use to reproduce the issue?

We have reproduced the issue on multiple K3 SoCs, to start with you can make use of the am62px_evm_r5_defconfig with arm-none-eabi toolchain from ARM[1] with version 13.3.rel1.

[1]: https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads

Quoted 3 lines

Cheers
/Ilias

#24 lore raw

Re: [PATCH v2 2/2] ARM: OMAP2+: Pad SPL binary to 8-byte alignment before DTB

In reply to Beleswar Padhi
Quoted 37 lines · Beleswar Padhi

The OMAP2 SPL linker script (also used for K3 platforms) currently uses a 4-byte alignment directive after the __u_boot_list section. This alignment directive only advances the location counter without padding the actual binary output.

When objcopy extracts u-boot-spl-nodtb.bin, it includes only actual data, stopping at the last byte of __u_boot_list (e.g., 0x41c359fc), not an aligned address (e.g., 0x41c35a00). So, when the FIT image containing device trees is concatenated to the SPL binary, it gets appended at this unaligned file size, causing libfdt validation failure.

To fix this, move the alignment directive into the __u_boot_list section itself and make it 8-byte aligned as per DT spec. This forces the linker to include padding as part of the section data, ensuring objcopy includes the padding bytes in the binary and the appended FIT image starts at an 8-byte aligned boundary.

Fixes 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")

---
v2: Changelog:
1. Get rid of extra ALIGN() directive, replace it with a comment
2. Carry Reported-by, Closes and Fixes tag.

Link to v1:
https://lore.kernel.org/all/[email protected]/

  arch/arm/mach-omap2/u-boot-spl.lds | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
arch/arm/mach-omap2/u-boot-spl.lds +0 -0
index 3bb759d8a1c..5ad169a37b7 100644

arch/arm/mach-omap2/u-boot-spl.lds SECTIONS · line 43

Quoted 9 lines
arch/arm/mach-omap2/u-boot-spl.lds +5 -0
@@ -35,9 +35,13 @@ SECTIONS
  	. = ALIGN(4);
  	__u_boot_list : {
  		KEEP(*(SORT(__u_boot_list*)));
+		/*
+		 * Ensure 8-byte alignment at the end of the last section before
+		 * DTB is appended, to satisfy DT spec alignment requirements
+		 */
+		. = ALIGN(8);
  	} >.sram

Does this work even if the __u_boot_list section is empty ?

I think what you need is unconditional alignment of the end of the binary, that has to be 8 bytes aligned.

#25 lore raw

Re: [PATCH v2 2/2] ARM: OMAP2+: Pad SPL binary to 8-byte alignment before DTB

Quoted 33 lines · Marek Vasut
Quoted 32 lines · Beleswar Padhi

The OMAP2 SPL linker script (also used for K3 platforms) currently uses a 4-byte alignment directive after the __u_boot_list section. This alignment directive only advances the location counter without padding the actual binary output.

When objcopy extracts u-boot-spl-nodtb.bin, it includes only actual data, stopping at the last byte of __u_boot_list (e.g., 0x41c359fc), not an aligned address (e.g., 0x41c35a00). So, when the FIT image containing device trees is concatenated to the SPL binary, it gets appended at this unaligned file size, causing libfdt validation failure.

To fix this, move the alignment directive into the __u_boot_list section itself and make it 8-byte aligned as per DT spec. This forces the linker to include padding as part of the section data, ensuring objcopy includes the padding bytes in the binary and the appended FIT image starts at an 8-byte aligned boundary.

Fixes 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")

---
v2: Changelog:
1. Get rid of extra ALIGN() directive, replace it with a comment
2. Carry Reported-by, Closes and Fixes tag.

Link to v1:
https://lore.kernel.org/all/[email protected]/

  arch/arm/mach-omap2/u-boot-spl.lds | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
Quoted 15 lines
Quoted 5 lines
arch/arm/mach-omap2/u-boot-spl.lds +0 -0
index 3bb759d8a1c..5ad169a37b7 100644

arch/arm/mach-omap2/u-boot-spl.lds SECTIONS · line 43

Quoted 9 lines
arch/arm/mach-omap2/u-boot-spl.lds +5 -0
@@ -35,9 +35,13 @@ SECTIONS
  	. = ALIGN(4);
  	__u_boot_list : {
  		KEEP(*(SORT(__u_boot_list*)));
+		/*
+		 * Ensure 8-byte alignment at the end of the last section before
+		 * DTB is appended, to satisfy DT spec alignment requirements
+		 */
+		. = ALIGN(8);
  	} >.sram

Does this work even if the __u_boot_list section is empty ?

I'm not sure it can be empty, but it should still work.

Quoted 2 lines

I think what you need is unconditional alignment of the end of the binary, that has to be 8 bytes aligned.

We might need to look harder at what Anshul was suggesting in his reply, yeah. I'll chime in over there next.

Signature · 1 line
Tom
#26 lore raw

Re: (subset) [PATCH v2 0/2] Fix TI DTB alignment issues with recent libfdt update

In reply to Beleswar Padhi
Quoted 9 lines · Beleswar Padhi

Recent libfdt updates (commit 0535e46d55d7 "scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c") enforce strict 8-byte alignment for device tree blobs, as required by the device tree specification. This causes failures on platforms using CONFIG_SPL_MULTI_DTB_FIT, where DTBs were not properly aligned.

The alignment issue occurs at two levels:

[...]

Applied to u-boot/master, thanks!

[2/2] ARM: OMAP2+: Pad SPL binary to 8-byte alignment before DTB

      commit: 85f586035d75132b2b60d5e593e1c0049f5d126a
Signature · 1 line
Tom