[PATCH] scripts/make_fit: move the dtbs to the start

Sven Püschel s.pueschel at pengutronix.de
Tue May 20 02:12:28 PDT 2025


Move the dtbs to the start of the fit image to avoid u-boot overwriting
the dtb while relocating the kernel image.

Using a current u-boot master eeb5ff1a468b ("Merge tag
'efi-2025-07-rc3-2' of https://source.denx.de/u-boot/custodians/u-boot-efi")
failed to load a barebox fit image on a Pine64 Rock64 board:

=> bootm $loadaddr#conf-rk3328-rock64.dtb
   Using 'conf-rk3328-rock64.dtb' configuration
   Verifying Hash Integrity ... OK
   Trying 'kernel' kernel subimage
     Description:  barebox-2025.04.0-00231-g00fd6bfa3088-dirty
     Type:         Kernel Image (no loading done)
     Compression:  uncompressed
     Data Start:   0x00800968
     Data Size:    737350 Bytes = 720.1 KiB
   Verifying Hash Integrity ... OK
   Using 'conf-rk3328-rock64.dtb' configuration
   Verifying Hash Integrity ... OK
   Trying 'fdt-1' fdt subimage
     Description:  rk3328-rock64.dtb
     Type:         Flat Device Tree
     Compression:  uncompressed
     Data Start:   0x008b4a48
     Data Size:    37415 Bytes = 36.5 KiB
     Architecture: AArch64
   Verifying Hash Integrity ... OK
   Booting using the fdt blob at 0x8b4a48
Working FDT set to 8b4a48
   XIP Kernel Image (no loading done) to 800968
Moving Image from 0x800968 to 0x880000, end=0x934048
ERROR: image is not a fdt - must RESET the board to recover.
FDT creation failed!
resetting ...

The culprint was the fact that u-boot relocated the barebox image to
match the alignment requirements from the Linux kernel. But the
relocation did overwrite the devicetree and therefore failed to boot it.

To prevent this error from happening, move the dtbs in the generated
barebox fit image to the start, so u-boot cannot overwrite these when
moving the kernel image to a higher address.

Signed-off-by: Sven Püschel <s.pueschel at pengutronix.de>
---
 scripts/make_fit.py | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/scripts/make_fit.py b/scripts/make_fit.py
index 2190da4c00..4253b07e5f 100755
--- a/scripts/make_fit.py
+++ b/scripts/make_fit.py
@@ -267,12 +267,6 @@ def build_fit(args):
     dtbs_seen = set()
     fdts = {}
 
-    # Handle the kernel
-    with open(args.kernel, 'rb') as inf:
-        comp_data = compress_data(inf, 'none')
-    size += os.path.getsize(args.kernel)
-    write_kernel(fsw, comp_data, args)
-
     for fname in args.dtbs:
         # Ignore non-DTB (*.dtb) files
         if os.path.splitext(fname)[1] != '.dtb':
@@ -297,6 +291,12 @@ def build_fit(args):
 
         entries.append([dtbname, model, compat, files_seq])
 
+    # Handle the kernel
+    with open(args.kernel, 'rb') as inf:
+        comp_data = compress_data(inf, 'none')
+    size += os.path.getsize(args.kernel)
+    write_kernel(fsw, comp_data, args)
+
     finish_fit(fsw, entries)
 
     # Include the kernel itself in the returned file count
-- 
2.49.0




More information about the barebox mailing list