aboutsummaryrefslogtreecommitdiffstats
path: root/package/boot/uboot-mediatek/patches/001-mtk-0022-spl-spl_legacy-fix-the-use-of-SPL_COPY_PAYLOAD_ONLY.patch
blob: a0ab14d2607b3388569adac5415d086d7dfce0e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
From ba9c81e720f39b5dbc14592252bfc9402afee79d Mon Sep 17 00:00:00 2001
From: Weijie Gao <weijie.gao@mediatek.com>
Date: Fri, 20 May 2022 11:23:58 +0800
Subject: [PATCH 22/25] spl: spl_legacy: fix the use of SPL_COPY_PAYLOAD_ONLY

If the payload is compressed, SPL_COPY_PAYLOAD_ONLY should always be set
since the payload will not be directly read to its load address. The
payload will first be read to a temporary buffer, and then be decompressed
to its load address, without image header.

If the payload is not compressed, and SPL_COPY_PAYLOAD_ONLY is set, image
header should be skipped on loading. Otherwise image header should also be
read to its load address.

Reviewed-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
---
 common/spl/spl_legacy.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

--- a/common/spl/spl_legacy.c
+++ b/common/spl/spl_legacy.c
@@ -88,15 +88,29 @@ int spl_load_legacy_img(struct spl_image
 	/* Read header into local struct */
 	load->read(load, header, sizeof(hdr), &hdr);
 
+	/*
+	 * If the payload is compressed, the decompressed data should be
+	 * directly write to its load address.
+	 */
+	if (spl_image_get_comp(&hdr) != IH_COMP_NONE)
+		spl_image->flags |= SPL_COPY_PAYLOAD_ONLY;
+
 	ret = spl_parse_image_header(spl_image, bootdev, &hdr);
 	if (ret)
 		return ret;
 
-	dataptr = header + sizeof(hdr);
-
 	/* Read image */
 	switch (spl_image_get_comp(&hdr)) {
 	case IH_COMP_NONE:
+		dataptr = header;
+
+		/*
+		 * Image header will be skipped only if SPL_COPY_PAYLOAD_ONLY
+		 * is set
+		 */
+		if (spl_image->flags & SPL_COPY_PAYLOAD_ONLY)
+			dataptr += sizeof(hdr);
+
 		load->read(load, dataptr, spl_image->size,
 			   (void *)(unsigned long)spl_image->load_addr);
 		break;
@@ -104,6 +118,9 @@ int spl_load_legacy_img(struct spl_image
 	case IH_COMP_LZMA:
 		lzma_len = LZMA_LEN;
 
+		/* dataptr points to compressed payload  */
+		dataptr = header + sizeof(hdr);
+
 		debug("LZMA: Decompressing %08lx to %08lx\n",
 		      dataptr, spl_image->load_addr);
 		src = malloc(spl_image->size);