CONFIG_SYS_BOOTM_LEN is passed to image_decomp(), so the same should be
used for the buffer allocation. Deriving a buffer size from the
compressed size if not possible, as the compression ratio may be
arbitrarily high for data with many repititions (for example ranges of
0x00 or 0xff).

Fixes: 69544c4fd8b1 ("bootm: Support kernel_noload with compression")
Signed-off-by: Nora Schiffer <[email protected]>
---
 boot/bootm.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/boot/bootm.c b/boot/bootm.c
index 51d99a3385f..db29606021d 100644
--- a/boot/bootm.c
+++ b/boot/bootm.c
@@ -623,18 +623,15 @@ static int bootm_load_os(struct bootm_headers *images, 
int boot_progress)
        int err;
 
        /*
-        * For a "noload" compressed kernel we need to allocate a buffer large
-        * enough to decompress in to and use that as the load address now.
-        * Assume that the kernel compression is at most a factor of 4 since
-        * zstd almost achieves that.
+        * For a "noload" compressed kernel we need to allocate a buffer of
+        * size CONFIG_SYS_BOOTM_LEN and use that as the load address now.
         * Use an alignment of 2MB since this might help arm64
         */
        if (os.type == IH_TYPE_KERNEL_NOLOAD && os.comp != IH_COMP_NONE) {
-               ulong req_size = ALIGN(image_len * 4, SZ_1M);
                phys_addr_t addr;
 
                err = lmb_alloc_mem(LMB_MEM_ALLOC_ANY, SZ_2M, &addr,
-                                   req_size, LMB_NONE);
+                                   CONFIG_SYS_BOOTM_LEN, LMB_NONE);
                if (err)
                        return 1;
 
@@ -642,7 +639,7 @@ static int bootm_load_os(struct bootm_headers *images, int 
boot_progress)
                images->os.load = (ulong)addr;
                images->ep = (ulong)addr;
                debug("Allocated %lx bytes at %lx for kernel (size %lx) 
decompression\n",
-                     req_size, load, image_len);
+                     (ulong)CONFIG_SYS_BOOTM_LEN, load, image_len);
        }
 
        load_buf = map_sysmem(load, 0);
-- 
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
https://www.tq-group.com/

Reply via email to