bootm: Handle compressed arm64 images with bootm
v2 cover bootm: Handle compressed arm64 images with bootm
This little series corrects a problem I noticed with arm64 images, where the kernel is not recognised:
U-Boot> tftp image.fit
Using ethernet@7d580000 device
TFTP from server 192.168.4.7; our IP address is 192.168.4.147 Filename 'image.fit'.
Load address: 0x1000000
Loading: ################################################## 23 MiB
20.5 MiB/s
done
Bytes transferred = 24118272 (1700400 hex)
U-Boot> bootm
## Loading kernel from FIT Image at 01000000 ...
Using 'conf-768' configuration
Trying 'kernel' kernel subimage
Description: Linux
Type: Kernel Image (no loading done)
Compression: gzip compressed
Data Start: 0x01000120
Data Size: 13662338 Bytes = 13 MiB
Verifying Hash Integrity ... OK
Bad Linux ARM64 Image magic!
With this series:
U-Boot> tftp 20000000 image.fit
Using ethernet@7d580000 device
TFTP from server 192.168.4.7; our IP address is 192.168.4.147 Filename 'image.fit'.
Load address: 0x20000000
Loading: ################################################## 23.5 MiB
20.8 MiB/s
done
Bytes transferred = 24642560 (1780400 hex)
U-Boot> bootm 0x20000000
## Loading kernel from FIT Image at 20000000 ...
Using 'conf-768' configuration
Trying 'kernel' kernel subimage
Description: Linux
Type: Kernel Image (no loading done)
Compression: zstd compressed
Data Start: 0x20000120
Data Size: 14333475 Bytes = 13.7 MiB
Verifying Hash Integrity ... OK
Using kernel load address 80000
## Loading fdt from FIT Image at 20000000 ...
Using 'conf-768' configuration
Trying 'fdt-768' fdt subimage
Description: Raspberry Pi 4 Model B
Type: Flat Device Tree
Compression: zstd compressed
Data Start: 0x215f820c
Data Size: 9137 Bytes = 8.9 KiB
Architecture: AArch64
Verifying Hash Integrity ... OK
Uncompressing Flat Device Tree to 3aff3010
Booting using the fdt blob at 0x3aff3010
Working FDT set to 3aff3010
Uncompressing Kernel Image (no loading done) to 80000
Moving Image from 0x80000 to 0x200000, end=2b00000
Using Device Tree in place at 000000003aff3010, end 000000003afff4c4
Working FDT set to 3aff3010
Starting kernel ...
[ 0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd083]
The problem is that the arm64 magic is checked before the image is decompressed.
Another issue is that the load address is read from the 'load' property even with a kernel_noload image. This means that the kernel is loaded to address 0, which may not be valid on the board. We can use the kernel_addr_r environment variable instead.
A patch is included to show the kernel load-address, so it is easy to see what is going on.
Changes in v2:
- Add a 'success' case to the cover letter
Simon Glass (4):
bootm: Allow ignoring the load address with kernel_noload
bootm: Move arm64-image processing later
image: Show the load address when decompressing
image: Correct load_bug typo
boot/bootm.c | 61 ++++++++++++++++++++++++++++++------------------- boot/image.c | 13 +++++++---- include/image.h | 2 +- 3 files changed, 48 insertions(+), 28 deletions(-)
Signature · 1 line
2.42.0.869.gea05f2083d-goog
PATCH v2 1/4 bootm: Allow ignoring the load address with kernel_noload
This image type is supposed to ignore the load address. But at present it fails if the load address is missing. If it is zero, the image is loaded at address 0, which may not work on all boards.
Make use of the kernel_addr_r environment variable, instead, since this seems to be a more reliable final address for the kernel.
Another option would be to create a new Kconfig for this, or to use a region of memory known to be free, e.g. calculated from the DRAM banks. But in any case we should try to avoid conflicting with the kernel_addr_r variable. So the approach in this patch seems reasonable to me.
---
(no changes since v1)
boot/bootm.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
boot/bootm.c +8 -2
@@ -176,7 +176,13 @@ static int bootm_find_os(struct cmd_tbl *cmdtp, int flag, int argc, images.os.end =fit_get_end (images.fit_hdr_os); -if (fit_image_get_load (images.fit_hdr_os, images.fit_noffset_os, +if (images.os.type ==IH_TYPE_KERNEL_NOLOAD ) { +ulong load; + + load =env_get_hex ("kernel_addr_r" ,-1UL ); +printf ("Using kernel load address %lx\n" , load); + images.os.load = load; + }else if (fit_image_get_load (images.fit_hdr_os, images.fit_noffset_os, &images.os.load)) {puts ("Can't get image load address!\n" );bootstage_error (BOOTSTAGE_ID_FIT_LOADADDR );
@@ -229,7 +235,7 @@ static int bootm_find_os(struct cmd_tbl *cmdtp, int flag, int argc, ret =fit_image_get_entry (images.fit_hdr_os, images.fit_noffset_os, &images.ep); -if (ret) { +if (ret && images.os.type ==IH_TYPE_KERNEL_NOLOAD ) {puts ("Can't get entry point property!\n" );return 1 ; }
Signature · 1 line
2.42.0.869.gea05f2083d-goog
PATCH v2 2/4 bootm: Move arm64-image processing later
In reply to Simon GlassIf the image is compressed, then the existing check fails, since the header is wrong.
Move the check later in the boot process, after the kernel is decompressed. This allows use of bootm with compressed kernels, while still permitting an uncompressed kernel to be used.
---
(no changes since v1)
boot/bootm.c | 51 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 21 deletions(-)
boot/bootm.c +30 -21
@@ -245,27 +245,6 @@ static int bootm_find_os(struct cmd_tbl *cmdtp, int flag, int argc,return 1 ; } -if (images.os.type ==IH_TYPE_KERNEL_NOLOAD ) { -if (IS_ENABLED (CONFIG_CMD_BOOTI ) && - images.os.arch ==IH_ARCH_ARM64 && - images.os.os ==IH_OS_LINUX ) { -ulong image_addr; -ulong image_size; - - ret =booti_setup (images.os.image_start, &image_addr, - &image_size, true); -if (ret !=0 ) -return 1 ; - - images.os.type =IH_TYPE_KERNEL ; - images.os.load = image_addr; - images.ep = image_addr; - }else { - images.os.load = images.os.image_start; - images.ep += images.os.image_start; - } - } - images.os.start =map_to_sysmem (os_hdr);return 0 ;
@@ -472,6 +451,36 @@ static int bootm_load_os(struct bootm_headers *images, int boot_progress) } } +if (IS_ENABLED (CONFIG_CMD_BOOTI ) && + images->os.type ==IH_TYPE_KERNEL_NOLOAD && + images->os.arch ==IH_ARCH_ARM64 && + images->os.os ==IH_OS_LINUX ) { +ulong relocated_addr; +ulong image_size; +int ret; + + ret =booti_setup (load, &relocated_addr, &image_size, + false); +if (ret) { +printf ("Failed to prep arm64 kernel (err=%d)\n" , + ret); +return BOOTM_ERR_RESET ; + } + +/* Handle BOOTM_STATE_LOADOS */ +if (relocated_addr != load) { +printf ("Moving Image from 0x%lx to 0x%lx, end=%lx\n" , + load, + relocated_addr, relocated_addr + image_size); +memmove ((void *)relocated_addr, + load_buf, image_size); + } + + images->ep = relocated_addr; + images->os.start = relocated_addr; + images->os.end = relocated_addr + image_size; + } +lmb_reserve (&images->lmb, images->os.load, (load_end - images->os.load));return 0 ;
Signature · 1 line
2.42.0.869.gea05f2083d-goog
PATCH v2 3/4 image: Show the load address when decompressing
In reply to Simon GlassThe destination address for decompression (or copying) is useful information. Show this to the user while booting, e.g.:
Uncompressing Kernel Image (no loading done) to 2080000
---
(no changes since v1)
boot/image.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
boot/image.c +9 -4
@@ -415,15 +415,20 @@ void image_print_contents(const void *ptr)* @type: OS type (IH_OS_...) * @comp_type: Compression type being used (IH_COMP_...) * @is_xip: true if the load address matches the image start +* @load: Load address for printing */ -static void print_decomp_msg (int comp_type,int type,bool is_xip) +static void print_decomp_msg (int comp_type,int type,bool is_xip, +ulong load) {const char *name =genimg_get_type_name (type); +/* Shows "Loading Kernel Image" for example */ if (comp_type ==IH_COMP_NONE ) -printf (" %s %s\n" , is_xip ?"XIP" :"Loading" , name); +printf (" %s %s" , is_xip ?"XIP" :"Loading" , name);else -printf (" Uncompressing %s\n" , name); +printf (" Uncompressing %s" , name); + +printf (" to %lx\n" , load); }int image_decomp_type (const unsigned char *buf,ulong len)
@@ -448,7 +453,7 @@ int image_decomp(int comp, ulong load, ulong image_start, int type,int ret = -ENOSYS ; *load_end = load; -print_decomp_msg (comp, type, load == image_start); +print_decomp_msg (comp, type, load == image_start, load);/* * Load the image to the right place, decompressing if needed. After
Signature · 1 line
2.42.0.869.gea05f2083d-goog
PATCH v2 4/4 image: Correct load_bug typo
In reply to Simon GlassCorrect a typo in the function comment for image_decomp().
---
Changes in v2:
- Add a 'success' case to the cover letter
include/image.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/image.h +1 -1
@@ -936,7 +936,7 @@ int image_decomp_type(const unsigned char *buf, ulong len);* @load: Destination load address in U-Boot memory * @image_start Image start address (where we are decompressing from) * @type: OS type (IH_OS_...) -* @load_bug: Place to decompress to +* @load_buf: Place to decompress to * @image_buf: Address to decompress from * @image_len: Number of bytes in @image_buf to decompress * @unc_len: Available space for decompression
Signature · 1 line
2.42.0.869.gea05f2083d-goog