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 diff --git a/common/spl/spl_legacy.c b/common/spl/spl_legacy.c
22 index 2ec7154423..ae8731c782 100644
23 --- a/common/spl/spl_legacy.c
24 +++ b/common/spl/spl_legacy.c
25 @@ -88,15 +88,29 @@ int spl_load_legacy_img(struct spl_image_info *spl_image,
26 /* Read header into local struct */
27 load->read(load, header, sizeof(hdr), &hdr);
30 + * If the payload is compressed, the decompressed data should be
31 + * directly write to its load address.
33 + if (spl_image_get_comp(&hdr) != IH_COMP_NONE)
34 + spl_image->flags |= SPL_COPY_PAYLOAD_ONLY;
36 ret = spl_parse_image_header(spl_image, bootdev, &hdr);
40 - dataptr = header + sizeof(hdr);
43 switch (spl_image_get_comp(&hdr)) {
48 + * Image header will be skipped only if SPL_COPY_PAYLOAD_ONLY
51 + if (spl_image->flags & SPL_COPY_PAYLOAD_ONLY)
52 + dataptr += sizeof(hdr);
54 load->read(load, dataptr, spl_image->size,
55 (void *)(unsigned long)spl_image->load_addr);
57 @@ -104,6 +118,9 @@ int spl_load_legacy_img(struct spl_image_info *spl_image,
61 + /* dataptr points to compressed payload */
62 + dataptr = header + sizeof(hdr);
64 debug("LZMA: Decompressing %08lx to %08lx\n",
65 dataptr, spl_image->load_addr);
66 src = malloc(spl_image->size);