1ef16c9955ddfd84ebc5077bebedc32aa22ce07c
[openwrt/staging/neocturne.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 --- a/common/spl/spl_nand.c
18 +++ b/common/spl/spl_nand.c
19 @@ -56,6 +56,21 @@ static ulong spl_nand_fit_read(struct sp
20 return size / load->bl_len;
21 }
22
23 +static ulong spl_nand_legacy_read(struct spl_load_info *load, ulong offs,
24 + ulong size, void *dst)
25 +{
26 + int err;
27 +
28 + debug("%s: offs %lx, size %lx, dst %p\n",
29 + __func__, offs, size, dst);
30 +
31 + err = nand_spl_load_image(offs, size, dst);
32 + if (err)
33 + return 0;
34 +
35 + return size;
36 +}
37 +
38 struct mtd_info * __weak nand_get_mtd(void)
39 {
40 return NULL;
41 @@ -93,6 +108,18 @@ static int spl_nand_load_element(struct
42 load.bl_len = bl_len;
43 load.read = spl_nand_fit_read;
44 return spl_load_imx_container(spl_image, &load, offset / bl_len);
45 + } else if (IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_FORMAT) &&
46 + image_get_magic(header) == IH_MAGIC) {
47 + struct spl_load_info load;
48 +
49 + debug("Found legacy image\n");
50 + load.dev = NULL;
51 + load.priv = NULL;
52 + load.filename = NULL;
53 + load.bl_len = 1;
54 + load.read = spl_nand_legacy_read;
55 +
56 + return spl_load_legacy_img(spl_image, bootdev, &load, offset);
57 } else {
58 err = spl_parse_image_header(spl_image, bootdev, header);
59 if (err)