From 4c4bf046a528947c843ec703f667cd36b88e315a Mon Sep 17 00:00:00 2001 From: Weijie Gao Date: Fri, 20 May 2022 11:23:53 +0800 Subject: spl: allow using nand base without standard nand driver This patch removes the dependency to SPL_NAND_DRIVERS for SPL_NAND_BASE to allow minimal spl nand driver to use nand base for probing NAND chips. Signed-off-by: Weijie Gao --- common/spl/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'common') diff --git a/common/spl/Kconfig b/common/spl/Kconfig index 931619c366f..908d7d17fda 100644 --- a/common/spl/Kconfig +++ b/common/spl/Kconfig @@ -884,7 +884,7 @@ config SPL_NAND_SIMPLE expose the cmd_ctrl() interface. config SPL_NAND_BASE - depends on SPL_NAND_DRIVERS + depends on SPL_NAND_SUPPORT bool "Use Base NAND Driver" help Include nand_base.c in the SPL. -- cgit v1.3.1 From fdc03bf4e9342b2ccc553021554270624852cf84 Mon Sep 17 00:00:00 2001 From: Weijie Gao Date: Fri, 20 May 2022 11:23:58 +0800 Subject: 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 Signed-off-by: Weijie Gao --- common/spl/spl_legacy.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'common') diff --git a/common/spl/spl_legacy.c b/common/spl/spl_legacy.c index 2ec71544238..ae8731c782a 100644 --- a/common/spl/spl_legacy.c +++ b/common/spl/spl_legacy.c @@ -88,15 +88,29 @@ int spl_load_legacy_img(struct spl_image_info *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_info *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); -- cgit v1.3.1 From 4620e8aabc1431f2de3f4f5c1b22d4bc599e57b6 Mon Sep 17 00:00:00 2001 From: Weijie Gao Date: Fri, 20 May 2022 11:24:04 +0800 Subject: spl: nand: support loading legacy image with payload compressed Add support to load legacy image with payload compressed. This redirects the boot flow for all legacy images. If the payload is not compressed, the actual behavior will remain unchanged. Reviewed-by: Daniel Schwierzeck Signed-off-by: Weijie Gao --- common/spl/spl_nand.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'common') diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c index 82a10ffa63a..7b7579a2df1 100644 --- a/common/spl/spl_nand.c +++ b/common/spl/spl_nand.c @@ -56,6 +56,21 @@ static ulong spl_nand_fit_read(struct spl_load_info *load, ulong offs, return size / load->bl_len; } +static ulong spl_nand_legacy_read(struct spl_load_info *load, ulong offs, + ulong size, void *dst) +{ + int err; + + debug("%s: offs %lx, size %lx, dst %p\n", + __func__, offs, size, dst); + + err = nand_spl_load_image(offs, size, dst); + if (err) + return 0; + + return size; +} + struct mtd_info * __weak nand_get_mtd(void) { return NULL; @@ -93,6 +108,18 @@ static int spl_nand_load_element(struct spl_image_info *spl_image, load.bl_len = bl_len; load.read = spl_nand_fit_read; return spl_load_imx_container(spl_image, &load, offset / bl_len); + } else if (IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_FORMAT) && + image_get_magic(header) == IH_MAGIC) { + struct spl_load_info load; + + debug("Found legacy image\n"); + load.dev = NULL; + load.priv = NULL; + load.filename = NULL; + load.bl_len = 1; + load.read = spl_nand_legacy_read; + + return spl_load_legacy_img(spl_image, bootdev, &load, offset); } else { err = spl_parse_image_header(spl_image, bootdev, header); if (err) -- cgit v1.3.1