From 22c7c1a827f19dba5fd65622b599e10d5319e3e9 Mon Sep 17 00:00:00 2001 From: Joseph Chen Date: Sat, 4 Apr 2020 11:20:31 +0800 Subject: [PATCH] spl: fit: support load multiple backup of images Signed-off-by: Joseph Chen Change-Id: I29bce60f1b958baedbd2b45e86a611b89547c0d8 --- Kconfig | 14 ++++++++++++++ common/spl/spl_fat.c | 6 ++++++ common/spl/spl_fit.c | 36 ++++++++++++++++++++++++++++++++++-- common/spl/spl_mmc.c | 6 ++++++ common/spl/spl_nand.c | 6 ++++++ common/spl/spl_net.c | 6 ++++++ common/spl/spl_ram.c | 6 ++++++ common/spl/spl_spi.c | 8 +++++++- 8 files changed, 85 insertions(+), 3 deletions(-) diff --git a/Kconfig b/Kconfig index d8d75067ab..34d11d2cf5 100644 --- a/Kconfig +++ b/Kconfig @@ -333,6 +333,20 @@ config SPL_FIT_HW_CRYPTO help Enable SPL hardware crypto for FIT image checksum and rsa verify. +config SPL_FIT_IMAGE_KB + int "SPL FIT image size in KiB" + depends on SPL_FIT + default 2048 + help + SPL FIT image size in KiB. + +config SPL_FIT_IMAGE_MULTIPLE + int "SPL FIT image multiple number" + depends on SPL_FIT + default 1 + help + SPL FIT image multiple number. + config SPL_SYS_DCACHE_OFF bool "Disable SPL dcache" default y diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c index 59a85a986a..10cbdba468 100644 --- a/common/spl/spl_fat.c +++ b/common/spl/spl_fat.c @@ -71,8 +71,14 @@ int spl_load_image_fat(struct spl_image_info *spl_image, if (err <= 0) goto end; +#ifdef CONFIG_SPL_FIT_IMAGE_MULTIPLE + if ((IS_ENABLED(CONFIG_SPL_LOAD_FIT) && + image_get_magic(header) == FDT_MAGIC) || + CONFIG_SPL_FIT_IMAGE_MULTIPLE > 1) { +#else if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) && image_get_magic(header) == FDT_MAGIC) { +#endif struct spl_load_info load; debug("Found FIT\n"); diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index 1e95b14445..b45a8988d6 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -342,8 +342,9 @@ static int spl_fit_image_get_os(const void *fit, int noffset, uint8_t *os) #endif } -int spl_load_simple_fit(struct spl_image_info *spl_image, - struct spl_load_info *info, ulong sector, void *fit) +static int spl_internal_load_simple_fit(struct spl_image_info *spl_image, + struct spl_load_info *info, + ulong sector, void *fit) { int sectors; ulong size; @@ -528,3 +529,34 @@ int spl_load_simple_fit(struct spl_image_info *spl_image, return 0; } + +int spl_load_simple_fit(struct spl_image_info *spl_image, + struct spl_load_info *info, ulong sector, void *fit) +{ + ulong sector_offs = sector; + int i; + + for (i = 0; i < CONFIG_SPL_FIT_IMAGE_MULTIPLE; i++) { + if (i > 0) { + sector_offs += + i * ((CONFIG_SPL_FIT_IMAGE_KB << 10) / info->bl_len); + printf("Trying fit image at 0x%lx sector\n", sector_offs); + if (info->read(info, sector_offs, 1, fit) != 1) { + printf("IO error\n"); + continue; + } + } + + if (image_get_magic(fit) != FDT_MAGIC) { + printf("Bad fit magic\n"); + continue; + } + + if (!spl_internal_load_simple_fit(spl_image, info, + sector_offs, fit)) + return 0; + } + + return -EINVAL; +} + diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index b31cb9c71a..d929f3ab9f 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -103,8 +103,14 @@ int mmc_load_image_raw_sector(struct spl_image_info *spl_image, goto end; } +#ifdef CONFIG_SPL_FIT_IMAGE_MULTIPLE + if ((IS_ENABLED(CONFIG_SPL_LOAD_FIT) && + image_get_magic(header) == FDT_MAGIC) || + CONFIG_SPL_FIT_IMAGE_MULTIPLE > 1) { +#else if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) && image_get_magic(header) == FDT_MAGIC) { +#endif struct spl_load_info load; debug("Found FIT\n"); diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c index 61aedf9f79..4d7238d795 100644 --- a/common/spl/spl_nand.c +++ b/common/spl/spl_nand.c @@ -85,8 +85,14 @@ static int spl_nand_load_element(struct spl_image_info *spl_image, if (err) return err; +#ifdef CONFIG_SPL_FIT_IMAGE_MULTIPLE + if ((IS_ENABLED(CONFIG_SPL_LOAD_FIT) && + image_get_magic(header) == FDT_MAGIC) || + CONFIG_SPL_FIT_IMAGE_MULTIPLE > 1) { +#else if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) && image_get_magic(header) == FDT_MAGIC) { +#endif struct spl_load_info load; debug("Found FIT\n"); diff --git a/common/spl/spl_net.c b/common/spl/spl_net.c index 79c9b3584b..f2d27434b4 100644 --- a/common/spl/spl_net.c +++ b/common/spl/spl_net.c @@ -47,8 +47,14 @@ static int spl_net_load_image(struct spl_image_info *spl_image, return rv; } +#ifdef CONFIG_SPL_FIT_IMAGE_MULTIPLE + if ((IS_ENABLED(CONFIG_SPL_LOAD_FIT) && + image_get_magic(header) == FDT_MAGIC) || + CONFIG_SPL_FIT_IMAGE_MULTIPLE > 1) { +#else if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) && image_get_magic(header) == FDT_MAGIC) { +#endif struct spl_load_info load; debug("Found FIT\n"); diff --git a/common/spl/spl_ram.c b/common/spl/spl_ram.c index 28663d8915..86136fce47 100644 --- a/common/spl/spl_ram.c +++ b/common/spl/spl_ram.c @@ -39,8 +39,14 @@ static int spl_ram_load_image(struct spl_image_info *spl_image, spl_dfu_cmd(0, "dfu_alt_info_ram", "ram", "0"); #endif +#ifdef CONFIG_SPL_FIT_IMAGE_MULTIPLE + if ((IS_ENABLED(CONFIG_SPL_LOAD_FIT) && + image_get_magic(header) == FDT_MAGIC) || + CONFIG_SPL_FIT_IMAGE_MULTIPLE > 1) { +#else if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) && image_get_magic(header) == FDT_MAGIC) { +#endif struct spl_load_info load; debug("Found FIT\n"); diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c index b3507eaf4b..bda318cc49 100644 --- a/common/spl/spl_spi.c +++ b/common/spl/spl_spi.c @@ -113,8 +113,14 @@ static int spl_spi_load_image(struct spl_image_info *spl_image, return err; } +#ifdef CONFIG_SPL_FIT_IMAGE_MULTIPLE + if ((IS_ENABLED(CONFIG_SPL_LOAD_FIT) && + image_get_magic(header) == FDT_MAGIC) || + CONFIG_SPL_FIT_IMAGE_MULTIPLE > 1) { +#else if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) && - image_get_magic(header) == FDT_MAGIC) { + image_get_magic(header) == FDT_MAGIC) { +#endif struct spl_load_info load; debug("Found FIT\n");