7bcc896565f2b9c5e5d934d557560496962b491b
[openwrt/staging/wigyori.git] /
1 From b4e5137067d34a099efd921532ece177560789ca Mon Sep 17 00:00:00 2001
2 From: Weijie Gao <weijie.gao@mediatek.com>
3 Date: Fri, 20 May 2022 11:24:04 +0800
4 Subject: [PATCH 23/25] spl: nand: support loading legacy image with payload
5 compressed
6
7 Add support to load legacy image with payload compressed. This redirects
8 the boot flow for all legacy images. If the payload is not compressed, the
9 actual behavior will remain unchanged.
10
11 Reviewed-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
12 Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
13 ---
14 common/spl/spl_nand.c | 27 +++++++++++++++++++++++++++
15 1 file changed, 27 insertions(+)
16
17 diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c
18 index 82a10ffa63..7b7579a2df 100644
19 --- a/common/spl/spl_nand.c
20 +++ b/common/spl/spl_nand.c
21 @@ -56,6 +56,21 @@ static ulong spl_nand_fit_read(struct spl_load_info *load, ulong offs,
22 return size / load->bl_len;
23 }
24
25 +static ulong spl_nand_legacy_read(struct spl_load_info *load, ulong offs,
26 + ulong size, void *dst)
27 +{
28 + int err;
29 +
30 + debug("%s: offs %lx, size %lx, dst %p\n",
31 + __func__, offs, size, dst);
32 +
33 + err = nand_spl_load_image(offs, size, dst);
34 + if (err)
35 + return 0;
36 +
37 + return size;
38 +}
39 +
40 struct mtd_info * __weak nand_get_mtd(void)
41 {
42 return NULL;
43 @@ -93,6 +108,18 @@ static int spl_nand_load_element(struct spl_image_info *spl_image,
44 load.bl_len = bl_len;
45 load.read = spl_nand_fit_read;
46 return spl_load_imx_container(spl_image, &load, offset / bl_len);
47 + } else if (IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_FORMAT) &&
48 + image_get_magic(header) == IH_MAGIC) {
49 + struct spl_load_info load;
50 +
51 + debug("Found legacy image\n");
52 + load.dev = NULL;
53 + load.priv = NULL;
54 + load.filename = NULL;
55 + load.bl_len = 1;
56 + load.read = spl_nand_legacy_read;
57 +
58 + return spl_load_legacy_img(spl_image, bootdev, &load, offset);
59 } else {
60 err = spl_parse_image_header(spl_image, bootdev, header);
61 if (err)
62 --
63 2.36.1
64