spl: pad external DTB to _image_binary_end with separate BSS
Subsystems (4)
PATCH 1/1 spl: pad external DTB to _image_binary_end with separate BSS
When CONFIG_SPL_SEPARATE_BSS is enabled, fdt_find_separate() expects the SPL control DTB at _image_binary_end. However, u-boot-spl-dtb.bin is currently generated by concatenating u-boot-spl-nodtb.bin and the SPL DTB directly, without padding up to _image_binary_end.
On evb-ast2600 this places the appended SPL DTB at 0xc92c while _image_binary_end is 0xc930. The SPL therefore checks four bytes past the FDT header and fails early with:
Missing DTB
No serial driver found
Add padding between the xPL nodtb binary and the DTB when separate BSS is enabled, so the DTB is placed where fdt_find_separate() expects it.
--- scripts/Makefile.xpl | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
scripts/Makefile.xpl +13 -2
@@ -332,8 +332,8 @@ endif ifneq ($(build_dtb),) $(obj)/$(SPL_BIN)-dtb.bin: $(obj)/$(SPL_BIN)-nodtb.bin \ - $(if $(CONFIG_$(PHASE_)SEPARATE_BSS),,$(obj)/$(SPL_BIN)-pad.bin) \ - $(FINAL_DTB_CONTAINER) FORCE + $(if $(CONFIG_$(PHASE_)SEPARATE_BSS),$(obj)/$(SPL_BIN)-image-end-pad.bin,$(obj)/$(SPL_BIN)-pad.bin) \ + $(FINAL_DTB_CONTAINER) FORCE $(call if_changed,cat) $(obj)/$(SPL_BIN).bin: $(obj)/$(SPL_BIN)-dtb.bin FORCE
@@ -343,6 +343,17 @@ $(obj)/$(SPL_BIN).bin: $(obj)/$(SPL_BIN)-nodtb.bin FORCE $(call if_changed,copy) endif +# Create a file that pads from the end of the xPL nodtb binary to _image_binary_end +$(obj)/$(SPL_BIN)-image-end-pad.bin: $(obj)/$(SPL_BIN) $(obj)/$(SPL_BIN)-nodtb.bin + @image_end=$$($(NM) $(obj)/$(SPL_BIN) | awk '/ _image_binary_end/ {print "ibase=16; " toupper($$1)}' | bc); \ + actual=$$(wc -c < $(obj)/$(SPL_BIN)-nodtb.bin); \ + count=$$((image_end - actual)); \ + if [ $$count -lt 0 ]; then \ + echo "Invalid xPL padding: image_end=$$image_end actual=$$actual"; \ + exit 1; \ + fi; \ + dd if=/dev/zero of=$@ bs=1 count=$$count 2>/dev/null + # Create a file that pads from the end of u-boot-spl-nodtb.bin to bss_end $(obj)/$(SPL_BIN)-pad.bin: $(obj)/$(SPL_BIN) @bss_size_str=$(shell $(NM) $< | awk 'BEGIN {size = 0} /__bss_size/ {size = $$1} END {print "ibase=16; " toupper(size)}' | bc); \
Signature · 1 line
2.43.0
Quoted 10 lines · Quentin Strydom
When
CONFIG_SPL_SEPARATE_BSSis enabled,fdt_find_separate()expects the SPL control DTB at_image_binary_end. However, u-boot-spl-dtb.bin is currently generated by concatenating u-boot-spl-nodtb.bin and the SPL DTB directly, without padding up to_image_binary_end.On evb-ast2600 this places the appended SPL DTB at
0xc92cwhile_image_binary_endis0xc930. The SPL therefore checks four bytes past the FDT header and fails early with:
Quoted 8 lines
Missing DTB
No serial driver foundAdd padding between the xPL nodtb binary and the DTB when separate BSS is enabled, so the DTB is placed where
fdt_find_separate()expects it.Signed-off-by Quentin Strydom <[email protected]>
I'm glad someone has been able to test this on hardware now, and I'm sorry it wasn't fixed when dealing with the rest of the fallout here. I'm not sure this is quite the correct fix however as we should be ensuring that output file and _image_binary_end agree. What sections are, and aren't being included when we create the -nodtb.bin file? I think the place I ended up putting the '. = ALIGN(8)' in commit 8b0ebe054bb3 ("arm: Update linker scripts to ensure appended device tree is aligned") ended up not being correct on this platform.
Signature · 1 line
Tom
PATCH v2 1/1 arm: aspeed: Fix AST2600 SPL external DTB alignment
For AST2600 SPL with CONFIG_SPL_SEPARATE_BSS=y and CONFIG_OF_SEPARATE=y, fdt_find_separate() expects the appended control DTB at _image_binary_end.
The AST2600 SPL linker script aligned _image_binary_end via the .binman_sym_table section. In builds where that section has no emitted contents, objcopy -O binary does not include the alignment bytes in spl/u-boot-spl-nodtb.bin. This causes the nodtb binary to end before _image_binary_end, so the appended DTB is placed too early.
On evb-ast2600 this produced:
sizeof(spl/u-boot-spl-nodtb.bin) = 0xc92c
_image_binary_end = 0xc930
SPL then looked four bytes past the FDT header and failed with:
Missing DTB
No serial driver found
Move the 8-byte alignment into the preceding emitted __u_boot_list section so the objcopy output and _image_binary_end agree.
---
Changes in v2:
- Replace the Makefile padding change with an AST2600 SPL linker script fix.
- Move the 8-byte alignment into the emitted __u_boot_list section so spl/u-boot-spl-nodtb.bin and _image_binary_end agree.
- This was reproduced and tested with QEMU ast2600-evb, not physical hardware.
arch/arm/mach-aspeed/ast2600/u-boot-spl.lds | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mach-aspeed/ast2600/u-boot-spl.lds +1 -1
@@ -42,6 +42,7 @@ SECTIONS . = ALIGN(4); __u_boot_list : { KEEP(*(SORT(__u_boot_list*))); + . = ALIGN(8); } > .nor . = ALIGN(4);
@@ -49,7 +50,6 @@ SECTIONS __binman_sym_start = .; KEEP(*(SORT(.binman_sym*))); __binman_sym_end = .; - . = ALIGN(8); } > .nor /*
Signature · 1 line
2.43.0
Re: [PATCH v2] arm: aspeed: Fix AST2600 SPL external DTB alignment
Quoted 11 lines · Quentin Strydom
For AST2600 SPL with
CONFIG_SPL_SEPARATE_BSS=yandCONFIG_OF_SEPARATE=y,fdt_find_separate()expects the appended control DTB at_image_binary_end.The AST2600 SPL linker script aligned
_image_binary_endvia the .binman_sym_table section. In builds where that section has no emitted contents, objcopy -O binary does not include the alignment bytes in spl/u-boot-spl-nodtb.bin. This causes the nodtb binary to end before_image_binary_end, so the appended DTB is placed too early.[...]
Applied to u-boot/master, thanks!
[1/1] arm: aspeed: Fix AST2600 SPL external DTB alignment
commit: fcda974e36033ad5331a9b4a4a551af4e141ad7d
Signature · 1 line
Tom
Thanks, that makes sense.
Just to clarify, I reproduced and tested this with QEMU’s ast2600-evb machine rather than physical AST2600 hardware.
I checked the SPL section layout and I think you are right that the better fix is in the AST2600 SPL linker script rather than in scripts/Makefile.xpl.
With the v1 Makefile fix reverted, the mismatch was:
sizeof(spl/u-boot-spl-nodtb.bin) = 0xc92c_image_binary_end = 0xc930
The last emitted section was __u_boot_list, ending at 0xc92c, while _image_binary_end was advanced to 0xc930 by the alignment associated with .binman_sym_table. In this build .binman_sym_table did not contribute emitted contents, so objcopy -O binary did not include those alignment bytes in spl/u-boot-spl-nodtb.bin.
I have tested a v2 which moves the 8-byte alignment into the emitted __u_boot_list section. With that change:
sizeof(spl/u-boot-spl-nodtb.bin) = 0xc930_image_binary_end = 0xc930
The appended SPL DTB starts at 0xc930, and the external-DTB build boots successfully under QEMU with:
qemu-system-arm -M ast2600-evb,execute-in-place=on,bmc-console=uart5 \
-drive file=flash.img,format=raw,if=mtd -nographic
I have sent v2 with the linker-script fix.
Quentin
Quoted 33 lines · Tom Rini
Quoted 10 lines · Quentin Strydom
When
CONFIG_SPL_SEPARATE_BSSis enabled,fdt_find_separate()expects the SPL control DTB at_image_binary_end. However, u-boot-spl-dtb.bin is currently generated by concatenating u-boot-spl-nodtb.bin and the SPL DTB directly, without padding up to_image_binary_end.On evb-ast2600 this places the appended SPL DTB at
0xc92cwhile_image_binary_endis0xc930. The SPL therefore checks four bytes past the FDT header and fails early with:Quoted 8 lines
Missing DTB
No serial driver foundAdd padding between the xPL nodtb binary and the DTB when separate BSS is enabled, so the DTB is placed where
fdt_find_separate()expects it.Signed-off-by Quentin Strydom <[email protected]>I'm glad someone has been able to test this on hardware now, and I'm sorry it wasn't fixed when dealing with the rest of the fallout here. I'm not sure this is quite the correct fix however as we should be ensuring that output file and
_image_binary_endagree. What sections are, and aren't being included when we create the -nodtb.bin file? I think the place I ended up putting the '. = ALIGN(8)' in commit8b0ebe054bb3("arm: Update linker scripts to ensure appended device tree is aligned") ended up not being correct on this platform.--
Tom
Quoted 25 lines · Quentin Strydom
Thanks, that makes sense.
Just to clarify, I reproduced and tested this with QEMU’s ast2600-evb machine rather than physical AST2600 hardware.
I checked the SPL section layout and I think you are right that the better fix is in the AST2600 SPL linker script rather than in
scripts/Makefile.xpl.With the v1
Makefilefix reverted, the mismatch was:sizeof(spl/u-boot-spl-nodtb.bin) =
0xc92c_image_binary_end=0xc930The last emitted section was
__u_boot_list, ending at0xc92c, while_image_binary_endwas advanced to0xc930by the alignment associated with .binman_sym_table. In this build .binman_sym_table did not contribute emitted contents, so objcopy -O binary did not include those alignment bytes in spl/u-boot-spl-nodtb.bin.I have tested a v2 which moves the 8-byte alignment into the emitted
__u_boot_listsection. With that change:sizeof(spl/u-boot-spl-nodtb.bin) =
0xc930_image_binary_end=0xc930
Quoted 7 lines
The appended SPL DTB starts at
0xc930, and the external-DTB build boots successfully under QEMU with:qemu-system-arm -M ast2600-evb,execute-in-place=on,bmc-console=uart5 \
-drive file=flash.img,format=raw,if=mtd -nographicI have sent v2 with the linker-script fix.
Ah, so we've just been lucky in CI then, OK. Thanks for looking more at this!
Signature · 1 line
Tom