Fix TI DTB alignment issues with recent libfdt update
Subsystems (4)
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.
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 | 3 ++- scripts/Makefile.xpl | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
PATCH 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.
--- scripts/Makefile.xpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/Makefile.xpl +1 -1
@@ -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
Re: [PATCH 1/2] scripts/Makefile.xpl: Align filtered DTB to 8-byte within multidtb.fit
Quoted 11 lines · Beleswar Padhi
When
CONFIG_SPL_MULTI_DTB_FITis 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 settinggd->fdt_blob, because of the recent libfdt hardening since commit0535e46d55d7("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")
Quoted 4 lines
Add the -B
0x8flag to mkimage to enforce 8-byte alignment for all DTB entries within the multidtb FIT image.Signed-off-by Beleswar Padhi <[email protected]>
Signature · 1 line
Tom
Re: [PATCH 1/2] scripts/Makefile.xpl: Align filtered DTB to 8-byte within multidtb.fit
In reply to Beleswar PadhiQuoted 5 lines · Beleswar Padhi
When
CONFIG_SPL_MULTI_DTB_FITis 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
This misalignment causes -FDT_ERR_ALIGNMENT failure in
setup_multi_dtb_fit()when locating the next available DTB within the FIT blob and settinggd->fdt_blob, because of the recent libfdt hardening since commit0535e46d55d7("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")Add the -B
0x8flag to mkimage to enforce 8-byte alignment for all DTB entries within the multidtb FIT image.
Are there any other places where mkimage should enforce -B 8 too ?
Re: [PATCH 1/2] scripts/Makefile.xpl: Align filtered DTB to 8-byte within multidtb.fit
In reply to Beleswar PadhiQuoted 10 lines · Beleswar Padhi
When
CONFIG_SPL_MULTI_DTB_FITis 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 settinggd->fdt_blob, because of the recent libfdt hardening since commit0535e46d55d7("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")
Is a fixes tag justified in this case? Technically the commit 0535e46d55d7 did cause the regression[1].
[1]: https://lore.kernel.org/u-boot/[email protected]/
Quoted 14 lines
Add the -B
0x8flag to mkimage to enforce 8-byte alignment for all DTB entries within the multidtb FIT image.Signed-off-by Beleswar Padhi <[email protected]>--- scripts/Makefile.xpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/Makefile.xpl +0
-0
scripts/Makefile.xpl $(SHRUNK_ARCH_DTB): $$(patsubst $(obj)/dts/%, $(dt_dir)/%, $$@) $(dir $(SHRUNK_A · line 605
Quoted 5 lines
scripts/Makefile.xpl +1
-1@@ -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 \
The patch looks alright to me though I wonder if as a next step we should put the logic to ensure device-tree alignment directly into mkimage since it already knows which blob is the device-tree (the one passed with -b option)?
Quoted 3 lines
scripts/Makefile.xpl +0
-0$(patsubst %,-b %,$(SHRUNK_ARCH_DTB)) $(obj)/$(SPL_BIN).multidtb.fit: /dev/null $(SHRUNK_ARCH_DTB) FORCE
Re: [PATCH 1/2] scripts/Makefile.xpl: Align filtered DTB to 8-byte within multidtb.fit
Quoted 11 lines · Anshul Dalal
Quoted 10 lines · Beleswar Padhi
When
CONFIG_SPL_MULTI_DTB_FITis 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 settinggd->fdt_blob, because of the recent libfdt hardening since commit0535e46d55d7("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")
Quoted 4 lines
Is a fixes tag justified in this case? Technically the commit
0535e46d55d7did cause the regression[1].
Originally I didn't consider this a regression because the commit 0535e46d55d7 only enforced the alignment check. The alignment requirement was part of DT spec since long... But doesn't hurt to add the fixes tag I guess. Will do in v2.
Quoted 29 lines
Quoted 14 lines
Add the -B
0x8flag to mkimage to enforce 8-byte alignment for all DTB entries within the multidtb FIT image.Signed-off-by Beleswar Padhi <[email protected]>--- scripts/Makefile.xpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/Makefile.xpl +0
-0scripts/Makefile.xpl $(SHRUNK_ARCH_DTB): $$(patsubst $(obj)/dts/%, $(dt_dir)/%, $$@) $(dir $(SHRUNK_A · line 605
Quoted 5 lines
scripts/Makefile.xpl +1
-1@@ -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 \The patch looks alright to me though I wonder if as a next step we should put the logic to ensure device-tree alignment directly into mkimage since it already knows which blob is the device-tree (the one passed with -b option)?
Reviewed-by Anshul Dalal <[email protected]>Quoted 3 lines
scripts/Makefile.xpl +0
-0$(patsubst %,-b %,$(SHRUNK_ARCH_DTB)) $(obj)/$(SPL_BIN).multidtb.fit: /dev/null $(SHRUNK_ARCH_DTB) FORCE
PATCH 2/2 ARM: OMAP2+: Pad SPL binary to 8-byte alignment before DTB
In reply to Beleswar PadhiThe OMAP2 SPL linker script (also used for K3 platforms) currently uses 4-byte alignment after the __u_boot_list section. Change this to 8-byte alignment to meet the device tree specification requirement for DTB alignment.
However, 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 the aligned address (e.g., 0x41c35a00). When the FIT image containing device trees is concatenated to the above SPL binary, it gets appended at the unaligned file size, causing libfdt validation failure.
To fix this, add an alignment directive inside the __u_boot_list section itself. 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.
--- arch/arm/mach-omap2/u-boot-spl.lds | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/mach-omap2/u-boot-spl.lds +2 -1
@@ -35,9 +35,10 @@ SECTIONS . = ALIGN(4); __u_boot_list : { KEEP(*(SORT(__u_boot_list*))); + . = ALIGN(8); } >.sram - . = ALIGN(4); + . = ALIGN(8); __image_copy_end = .; _end = .; _image_binary_end = .;
Signature · 1 line
2.34.1
Re: [PATCH 2/2] ARM: OMAP2+: Pad SPL binary to 8-byte alignment before DTB
Quoted 29 lines · Beleswar Padhi
The OMAP2 SPL linker script (also used for K3 platforms) currently uses 4-byte alignment after the
__u_boot_listsection. Change this to 8-byte alignment to meet the device tree specification requirement for DTB alignment.However, 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 the aligned address (e.g.,0x41c35a00). When the FIT image containing device trees is concatenated to the above SPL binary, it gets appended at the unaligned file size, causing libfdt validation failure.To fix this, add an alignment directive inside the
__u_boot_listsection itself. 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.Signed-off-by Beleswar Padhi <[email protected]>--- arch/arm/mach-omap2/u-boot-spl.lds | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/arm/mach-omap2/u-boot-spl.lds +0
-0@@ -35,9 +35,10 @@ SECTIONS . = ALIGN(4);
arch/arm/mach-omap2/u-boot-spl.lds SECTIONS · line 44
Quoted 10 lines
arch/arm/mach-omap2/u-boot-spl.lds +2
-1__u_boot_list : { KEEP(*(SORT(__u_boot_list*))); + . = ALIGN(8); } >.sram - . = ALIGN(4); + . = ALIGN(8); __image_copy_end = .; _end = .; _image_binary_end = .;
Do we need both of these? Shouldn't we just need the one inside the sram section with a comment that this ensures the end of the SRAM portion is 8-byte aligned?
Signature · 1 line
Tom
Re: [PATCH 2/2] ARM: OMAP2+: Pad SPL binary to 8-byte alignment before DTB
Hi Tom,
Quoted 36 lines · Tom Rini
Quoted 34 lines · Beleswar Padhi
The OMAP2 SPL linker script (also used for K3 platforms) currently uses 4-byte alignment after the
__u_boot_listsection. Change this to 8-byte alignment to meet the device tree specification requirement for DTB alignment.However, 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 the aligned address (e.g.,0x41c35a00). When the FIT image containing device trees is concatenated to the above SPL binary, it gets appended at the unaligned file size, causing libfdt validation failure.To fix this, add an alignment directive inside the
__u_boot_listsection itself. 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.Signed-off-by Beleswar Padhi <[email protected]>--- arch/arm/mach-omap2/u-boot-spl.lds | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/arm/mach-omap2/u-boot-spl.lds +1
-0@@ -35,9 +35,10 @@ SECTIONS . = ALIGN(4); __u_boot_list : { KEEP(*(SORT(__u_boot_list*))); + . = ALIGN(8); } >.sram
Quoted 8 lines
arch/arm/mach-omap2/u-boot-spl.lds SECTIONS · line 44
Quoted 5 lines
arch/arm/mach-omap2/u-boot-spl.lds +1
-1- . = ALIGN(4); + . = ALIGN(8); __image_copy_end = .; _end = .; _image_binary_end = .;Do we need both of these? Shouldn't we just need the one inside the sram section with a comment that this ensures the end of the SRAM portion is 8-byte aligned?
Yes, we need only the first directive. But second one is just defensive programming, if someday someone changes the memory layout, this just hints that __image_copy_end should always be 8-byte aligned... Doesn't hurt to have it? Let me know what you think!
Thanks,
Beleswar
Re: [PATCH 2/2] ARM: OMAP2+: Pad SPL binary to 8-byte alignment before DTB
Quoted 48 lines · Beleswar
Hi Tom,
Quoted 35 lines · Tom Rini
Quoted 33 lines · Beleswar Padhi
The OMAP2 SPL linker script (also used for K3 platforms) currently uses 4-byte alignment after the
__u_boot_listsection. Change this to 8-byte alignment to meet the device tree specification requirement for DTB alignment.However, 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 the aligned address (e.g.,0x41c35a00). When the FIT image containing device trees is concatenated to the above SPL binary, it gets appended at the unaligned file size, causing libfdt validation failure.To fix this, add an alignment directive inside the
__u_boot_listsection itself. 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.Signed-off-by Beleswar Padhi <[email protected]>---
arch/arm/mach-omap2/u-boot-spl.lds| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)arch/arm/mach-omap2/u-boot-spl.lds +1
-0@@ -35,9 +35,10 @@ SECTIONS . = ALIGN(4); __u_boot_list : { KEEP(*(SORT(__u_boot_list*))); + . = ALIGN(8); } >.sramQuoted 8 lines
arch/arm/mach-omap2/u-boot-spl.lds SECTIONS · line 44
Quoted 5 lines
arch/arm/mach-omap2/u-boot-spl.lds +1
-1- . = ALIGN(4); + . = ALIGN(8); __image_copy_end = .; _end = .; _image_binary_end = .;Do we need both of these? Shouldn't we just need the one inside the sram section with a comment that this ensures the end of the SRAM portion is 8-byte aligned?
Quoted 1 line
Yes, we need only the first directive.
Would that work if the __u_boot_list section is empty ? I think it won't and you would end up with possible 4-byte alignment again.
Re: [PATCH 2/2] ARM: OMAP2+: Pad SPL binary to 8-byte alignment before DTB
Quoted 49 lines · Marek Vasut
Quoted 48 lines · Beleswar
Hi Tom,
Quoted 43 lines · Tom Rini
Quoted 28 lines · Beleswar Padhi
The OMAP2 SPL linker script (also used for K3 platforms) currently uses 4-byte alignment after the
__u_boot_listsection. Change this to 8-byte alignment to meet the device tree specification requirement for DTB alignment.However, 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 the aligned address (e.g.,0x41c35a00). When the FIT image containing device trees is concatenated to the above SPL binary, it gets appended at the unaligned file size, causing libfdt validation failure.To fix this, add an alignment directive inside the
__u_boot_listsection itself. 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.Signed-off-by Beleswar Padhi <[email protected]>---
arch/arm/mach-omap2/u-boot-spl.lds| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)arch/arm/mach-omap2/u-boot-spl.lds +0
-0arch/arm/mach-omap2/u-boot-spl.lds SECTIONS · line 43
Quoted 10 lines
arch/arm/mach-omap2/u-boot-spl.lds +2
-1@@ -35,9 +35,10 @@ SECTIONS . = ALIGN(4); __u_boot_list : { KEEP(*(SORT(__u_boot_list*))); + . = ALIGN(8); } >.sram - . = ALIGN(4); + . = ALIGN(8); __image_copy_end = .; _end = .; _image_binary_end = .;Do we need both of these? Shouldn't we just need the one inside the sram section with a comment that this ensures the end of the SRAM portion is 8-byte aligned?
Quoted 3 lines
Quoted 1 line
Yes, we need only the first directive.
Would that work if the
__u_boot_listsection is empty ? I think it won't and you would end up with possible 4-byte alignment again.
It won't work. But having the second ALIGN(8) won't fix it either. Either we change the whole linker script to be 8-byte aligned, or we leave a comment on the last section saying it should be 8-byte aligned for DTB concatenation. I think the latter is a better approach. We don't necessarily need to enforce 8-byte alignment for every section of the binary.
Thanks,
Beleswar
Re: [PATCH 2/2] ARM: OMAP2+: Pad SPL binary to 8-byte alignment before DTB
In reply to Padhi, BeleswarQuoted 48 lines · Beleswar
Hi Tom,
Quoted 35 lines · Tom Rini
Quoted 33 lines · Beleswar Padhi
The OMAP2 SPL linker script (also used for K3 platforms) currently uses 4-byte alignment after the
__u_boot_listsection. Change this to 8-byte alignment to meet the device tree specification requirement for DTB alignment.However, 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 the aligned address (e.g.,0x41c35a00). When the FIT image containing device trees is concatenated to the above SPL binary, it gets appended at the unaligned file size, causing libfdt validation failure.To fix this, add an alignment directive inside the
__u_boot_listsection itself. 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.Signed-off-by Beleswar Padhi <[email protected]>--- arch/arm/mach-omap2/u-boot-spl.lds | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/arm/mach-omap2/u-boot-spl.lds +1
-0@@ -35,9 +35,10 @@ SECTIONS . = ALIGN(4); __u_boot_list : { KEEP(*(SORT(__u_boot_list*))); + . = ALIGN(8); } >.sramQuoted 8 lines
arch/arm/mach-omap2/u-boot-spl.lds SECTIONS · line 44
Quoted 5 lines
arch/arm/mach-omap2/u-boot-spl.lds +1
-1- . = ALIGN(4); + . = ALIGN(8); __image_copy_end = .; _end = .; _image_binary_end = .;Do we need both of these? Shouldn't we just need the one inside the sram section with a comment that this ensures the end of the SRAM portion is 8-byte aligned?
Quoted 5 lines
Yes, we need only the first directive. But second one is just defensive programming, if someday someone changes the memory layout, this just hints that
__image_copy_endshould always be 8-byte aligned... Doesn't hurt to have
it? Let me know what you think!
I think a comment is better defensive programming than extra ALIGN statements. And with this discovery, we should also I think audit the rest of the linker scripts with a ". = ALIGN(4)" to see if they're likely in similar spots.
Signature · 1 line
Tom