91810673e9cf073b7a214d2e15ef697a86ef4bd5
[openwrt/openwrt.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 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);
28
29 + /*
30 + * If the payload is compressed, the decompressed data should be
31 + * directly write to its load address.
32 + */
33 + if (spl_image_get_comp(&hdr) != IH_COMP_NONE)
34 + spl_image->flags |= SPL_COPY_PAYLOAD_ONLY;
35 +
36 ret = spl_parse_image_header(spl_image, bootdev, &hdr);
37 if (ret)
38 return ret;
39
40 - dataptr = header + sizeof(hdr);
41 -
42 /* Read image */
43 switch (spl_image_get_comp(&hdr)) {
44 case IH_COMP_NONE:
45 + dataptr = header;
46 +
47 + /*
48 + * Image header will be skipped only if SPL_COPY_PAYLOAD_ONLY
49 + * is set
50 + */
51 + if (spl_image->flags & SPL_COPY_PAYLOAD_ONLY)
52 + dataptr += sizeof(hdr);
53 +
54 load->read(load, dataptr, spl_image->size,
55 (void *)(unsigned long)spl_image->load_addr);
56 break;
57 @@ -104,6 +118,9 @@ int spl_load_legacy_img(struct spl_image_info *spl_image,
58 case IH_COMP_LZMA:
59 lzma_len = LZMA_LEN;
60
61 + /* dataptr points to compressed payload */
62 + dataptr = header + sizeof(hdr);
63 +
64 debug("LZMA: Decompressing %08lx to %08lx\n",
65 dataptr, spl_image->load_addr);
66 src = malloc(spl_image->size);
67 --
68 2.36.1
69