1 From ba9c81e720f39b5dbc14592252bfc9402afee79d Mon Sep 17 00:00:00 2001
2 From: Weijie Gao <weijie.gao@mediatek.com>
3 Date: Fri, 20 May 2022 11:23:58 +0800
4 Subject: [PATCH 22/25] spl: spl_legacy: fix the use of SPL_COPY_PAYLOAD_ONLY
6 If the payload is compressed, SPL_COPY_PAYLOAD_ONLY should always be set
7 since the payload will not be directly read to its load address. The
8 payload will first be read to a temporary buffer, and then be decompressed
9 to its load address, without image header.
11 If the payload is not compressed, and SPL_COPY_PAYLOAD_ONLY is set, image
12 header should be skipped on loading. Otherwise image header should also be
13 read to its load address.
15 Reviewed-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
16 Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
18 common/spl/spl_legacy.c | 21 +++++++++++++++++++--
19 1 file changed, 19 insertions(+), 2 deletions(-)
21 --- a/common/spl/spl_legacy.c
22 +++ b/common/spl/spl_legacy.c
23 @@ -88,15 +88,29 @@ int spl_load_legacy_img(struct spl_image
24 /* Read header into local struct */
25 load->read(load, header, sizeof(hdr), &hdr);
28 + * If the payload is compressed, the decompressed data should be
29 + * directly write to its load address.
31 + if (spl_image_get_comp(&hdr) != IH_COMP_NONE)
32 + spl_image->flags |= SPL_COPY_PAYLOAD_ONLY;
34 ret = spl_parse_image_header(spl_image, bootdev, &hdr);
38 - dataptr = header + sizeof(hdr);
41 switch (spl_image_get_comp(&hdr)) {
46 + * Image header will be skipped only if SPL_COPY_PAYLOAD_ONLY
49 + if (spl_image->flags & SPL_COPY_PAYLOAD_ONLY)
50 + dataptr += sizeof(hdr);
52 load->read(load, dataptr, spl_image->size,
53 (void *)(unsigned long)spl_image->load_addr);
55 @@ -104,6 +118,9 @@ int spl_load_legacy_img(struct spl_image
59 + /* dataptr points to compressed payload */
60 + dataptr = header + sizeof(hdr);
62 debug("LZMA: Decompressing %08lx to %08lx\n",
63 dataptr, spl_image->load_addr);
64 src = malloc(spl_image->size);