From 9f8fed23401613288056db8036431b7487f62fea Mon Sep 17 00:00:00 2001 From: Ye Li Date: Wed, 26 Dec 2018 21:45:54 -0800 Subject: [PATCH] MLK-20664-1 imx8qxp: spl: Enable SPL container support for NAND Add the NAND support to SPL container parser and enable it for imx8qxp arm2 nand reworked board. The SPL NAND will read from nandfit mtdpart (128MB offset) to parsing the entire boot image and get the 3rd container from it. This requires burning tool (uuu) to program the entire boot image into nandfit. Signed-off-by: Ye Li (cherry picked from commit 4b2850ccfd8b387590c9fb4abfffdd0ac5cc8e58) --- arch/arm/mach-imx/imx8/parser.c | 31 +++++++++++++++++++++++++++++-- common/spl/spl_nand.c | 16 ++++++++++++++-- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/arch/arm/mach-imx/imx8/parser.c b/arch/arm/mach-imx/imx8/parser.c index 88432f4c0d..cba2d9eab5 100644 --- a/arch/arm/mach-imx/imx8/parser.c +++ b/arch/arm/mach-imx/imx8/parser.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -16,7 +17,8 @@ #define MMC_DEV 0 #define QSPI_DEV 1 -#define RAM_DEV 3 +#define NAND_DEV 2 +#define RAM_DEV 3 #define SEC_SECURE_RAM_BASE (0x31800000UL) #define SEC_SECURE_RAM_END_BASE (SEC_SECURE_RAM_BASE + 0xFFFFUL) @@ -34,7 +36,8 @@ static int read(u32 start, u32 len, void *load_addr) { int ret = -ENODEV; - if (!device && current_dev_type != RAM_DEV) { + if (current_dev_type != NAND_DEV && current_dev_type != RAM_DEV + && !device) { debug("No device selected\n"); return ret; } @@ -68,6 +71,15 @@ static int read(u32 start, u32 len, void *load_addr) } } #endif +#ifdef CONFIG_SPL_NAND_SUPPORT + if (current_dev_type == NAND_DEV) { + ret = nand_spl_load_image(start, len, load_addr); + if (ret != 0) { + debug("Read container image from NAND failed\n"); + return -EIO; + } + } +#endif if (current_dev_type == RAM_DEV) { memcpy(load_addr, (const void *)(ulong)start, len); @@ -253,6 +265,21 @@ int spi_load_image_parse_container(struct spl_image_info *spl_image, return ret; } +int nand_load_image_parse_container(struct spl_image_info *spl_image, + unsigned long offset) +{ + int ret = 0; + + current_dev_type = NAND_DEV; + device = NULL; + + start_offset = offset; + + ret = read_auth_container(spl_image); + + return ret; +} + int sdp_load_image_parse_container(struct spl_image_info *spl_image, unsigned long offset) { diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c index c418541114..7d9ff94aeb 100644 --- a/common/spl/spl_nand.c +++ b/common/spl/spl_nand.c @@ -11,12 +11,20 @@ #include #include -#if defined(CONFIG_SPL_NAND_RAW_ONLY) +#ifdef CONFIG_PARSE_CONTAINER +int __weak nand_load_image_parse_container(struct spl_image_info *spl_image, + unsigned long offset) +{ + return -EINVAL; +} +#endif + uint32_t __weak spl_nand_get_uboot_raw_page(void) { return CONFIG_SYS_NAND_U_BOOT_OFFS; } +#if defined(CONFIG_SPL_NAND_RAW_ONLY) static int spl_nand_load_image(struct spl_image_info *spl_image, struct spl_boot_device *bootdev) { @@ -64,11 +72,15 @@ static int spl_nand_load_element(struct spl_image_info *spl_image, load.read = spl_nand_fit_read; return spl_load_simple_fit(spl_image, &load, offset, header); } else { +#ifdef CONFIG_PARSE_CONTAINER + return nand_load_image_parse_container(spl_image, offset); +#else err = spl_parse_image_header(spl_image, header); if (err) return err; return nand_spl_load_image(offset, spl_image->size, (void *)(ulong)spl_image->load_addr); +#endif } } @@ -139,7 +151,7 @@ static int spl_nand_load_image(struct spl_image_info *spl_image, #endif #endif /* Load u-boot */ - err = spl_nand_load_element(spl_image, CONFIG_SYS_NAND_U_BOOT_OFFS, + err = spl_nand_load_element(spl_image, spl_nand_get_uboot_raw_page(), header); #ifdef CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND #if CONFIG_SYS_NAND_U_BOOT_OFFS != CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND -- 2.17.1