a0ab14d2607b3388569adac5415d086d7dfce0e3
[openwrt/staging/mans0n.git] /
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
5
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.
10
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.
14
15 Reviewed-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
16 Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
17 ---
18 common/spl/spl_legacy.c | 21 +++++++++++++++++++--
19 1 file changed, 19 insertions(+), 2 deletions(-)
20
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);
26
27 + /*
28 + * If the payload is compressed, the decompressed data should be
29 + * directly write to its load address.
30 + */
31 + if (spl_image_get_comp(&hdr) != IH_COMP_NONE)
32 + spl_image->flags |= SPL_COPY_PAYLOAD_ONLY;
33 +
34 ret = spl_parse_image_header(spl_image, bootdev, &hdr);
35 if (ret)
36 return ret;
37
38 - dataptr = header + sizeof(hdr);
39 -
40 /* Read image */
41 switch (spl_image_get_comp(&hdr)) {
42 case IH_COMP_NONE:
43 + dataptr = header;
44 +
45 + /*
46 + * Image header will be skipped only if SPL_COPY_PAYLOAD_ONLY
47 + * is set
48 + */
49 + if (spl_image->flags & SPL_COPY_PAYLOAD_ONLY)
50 + dataptr += sizeof(hdr);
51 +
52 load->read(load, dataptr, spl_image->size,
53 (void *)(unsigned long)spl_image->load_addr);
54 break;
55 @@ -104,6 +118,9 @@ int spl_load_legacy_img(struct spl_image
56 case IH_COMP_LZMA:
57 lzma_len = LZMA_LEN;
58
59 + /* dataptr points to compressed payload */
60 + dataptr = header + sizeof(hdr);
61 +
62 debug("LZMA: Decompressing %08lx to %08lx\n",
63 dataptr, spl_image->load_addr);
64 src = malloc(spl_image->size);