mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] scripts/make_fit: move the dtbs to the start
@ 2025-05-20  9:12 Sven Püschel
  2025-05-20  9:38 ` Ahmad Fatoum
  2025-05-20 11:24 ` Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Sven Püschel @ 2025-05-20  9:12 UTC (permalink / raw)
  To: barebox; +Cc: Sven Püschel

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@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




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] scripts/make_fit: move the dtbs to the start
  2025-05-20  9:12 [PATCH] scripts/make_fit: move the dtbs to the start Sven Püschel
@ 2025-05-20  9:38 ` Ahmad Fatoum
  2025-05-20 11:24 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2025-05-20  9:38 UTC (permalink / raw)
  To: Sven Püschel, barebox

On 20.05.25 11:12, Sven Püschel wrote:
> 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@pengutronix.de>

The point of the FIT image is to make it easier to boot barebox from
existing bootloaders, so a workaround sounds sensible, even if U-Boot
should be ultimately fixed:

Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

Sascha, can this go into master? Thanks.

Ahmad

> ---
>  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


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] scripts/make_fit: move the dtbs to the start
  2025-05-20  9:12 [PATCH] scripts/make_fit: move the dtbs to the start Sven Püschel
  2025-05-20  9:38 ` Ahmad Fatoum
@ 2025-05-20 11:24 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2025-05-20 11:24 UTC (permalink / raw)
  To: barebox, Sven Püschel


On Tue, 20 May 2025 11:12:28 +0200, Sven Püschel wrote:
> 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:
> 
> [...]

Applied, thanks!

[1/1] scripts/make_fit: move the dtbs to the start
      https://git.pengutronix.de/cgit/barebox/commit/?id=59458c979d6b (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-05-20 11:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-20  9:12 [PATCH] scripts/make_fit: move the dtbs to the start Sven Püschel
2025-05-20  9:38 ` Ahmad Fatoum
2025-05-20 11:24 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox