From patchwork Sat May 9 11:55:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 245338 List-Id: U-Boot discussion From: dariobin at libero.it (Dario Binacchi) Date: Sat, 9 May 2020 13:55:04 +0200 Subject: [PATCH 1/3] spl: fix format of function documentation In-Reply-To: <20200509115506.31746-1-dariobin@libero.it> References: <20200509115506.31746-1-dariobin@libero.it> Message-ID: <20200509115506.31746-2-dariobin@libero.it> U-Boot adopted the kernel-doc annotation style. Signed-off-by: Dario Binacchi --- include/spl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/spl.h b/include/spl.h index 6bf9fd8beb..e2fbd6d765 100644 --- a/include/spl.h +++ b/include/spl.h @@ -151,7 +151,7 @@ struct spl_image_info { #endif }; -/* +/** * Information required to load data from a device * * @dev: Pointer to the device, e.g. struct mmc * From patchwork Sat May 9 11:55:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 245339 List-Id: U-Boot discussion From: dariobin at libero.it (Dario Binacchi) Date: Sat, 9 May 2020 13:55:05 +0200 Subject: [PATCH 2/3] spl: fit: fail fit loading in case of FDT appending error In-Reply-To: <20200509115506.31746-1-dariobin@libero.it> References: <20200509115506.31746-1-dariobin@libero.it> Message-ID: <20200509115506.31746-3-dariobin@libero.it> If uboot does not embed its device tree and the FIT loading function returns error in case of failure in the FDT append, the redundant itb image could be loaded. Signed-off-by: Dario Binacchi --- common/spl/spl_fit.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index c51e4beb1c..cc518383e8 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -617,9 +617,14 @@ int spl_load_simple_fit(struct spl_image_info *spl_image, * Booting a next-stage U-Boot may require us to append the FDT. * We allow this to fail, as the U-Boot image might embed its FDT. */ - if (spl_image->os == IH_OS_U_BOOT) - spl_fit_append_fdt(spl_image, info, sector, fit, - images, base_offset); + if (spl_image->os == IH_OS_U_BOOT) { + ret = spl_fit_append_fdt(spl_image, info, sector, fit, + images, base_offset); +#if !CONFIG_IS_ENABLED(OF_EMBED) + if (ret < 0) + return ret; +#endif + } firmware_node = node; /* Now check if there are more images for us to load */ From patchwork Sat May 9 11:55:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 245340 List-Id: U-Boot discussion From: dariobin at libero.it (Dario Binacchi) Date: Sat, 9 May 2020 13:55:06 +0200 Subject: [PATCH 3/3] spl: fit: nand: fix fit loading in case of bad blocks In-Reply-To: <20200509115506.31746-1-dariobin@libero.it> References: <20200509115506.31746-1-dariobin@libero.it> Message-ID: <20200509115506.31746-4-dariobin@libero.it> The offset at which the image to be loaded from NAND is located is retrieved from the itb header. The presence of bad blocks in the area of the NAND where the itb image is located could invalidate the offset which must therefore be adjusted taking into account the state of the sectors concerned. Signed-off-by: Dario Binacchi --- common/spl/spl_fit.c | 7 ++++--- common/spl/spl_nand.c | 7 +++++++ drivers/mtd/nand/raw/nand_spl_loaders.c | 28 +++++++++++++++++++++++++ include/nand.h | 1 + include/spl.h | 4 ++++ 5 files changed, 44 insertions(+), 3 deletions(-) diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index cc518383e8..70e8fa95c9 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -284,10 +284,11 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector, overhead = get_aligned_image_overhead(info, offset); nr_sectors = get_aligned_image_size(info, length, offset); + offset = get_aligned_image_offset(info, offset); + offset = info->adjust_offset(info, sector, offset); - if (info->read(info, - sector + get_aligned_image_offset(info, offset), - nr_sectors, (void *)load_ptr) != nr_sectors) + if (info->read(info, sector + offset, nr_sectors, + (void *)load_ptr) != nr_sectors) return -EIO; debug("External data: dst=%lx, offset=%x, size=%lx\n", diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c index 5f8a111a2f..1aa82d7298 100644 --- a/common/spl/spl_nand.c +++ b/common/spl/spl_nand.c @@ -36,6 +36,12 @@ static int spl_nand_load_image(struct spl_image_info *spl_image, } #else +static ulong spl_nand_adjust_offset(struct spl_load_info *load, ulong sector, + ulong offset) +{ + return nand_spl_adjust_offset(sector, offset); +} + static ulong spl_nand_fit_read(struct spl_load_info *load, ulong offs, ulong size, void *dst) { @@ -67,6 +73,7 @@ static int spl_nand_load_element(struct spl_image_info *spl_image, load.filename = NULL; load.bl_len = 1; load.read = spl_nand_fit_read; + load.adjust_offset = spl_nand_adjust_offset; return spl_load_simple_fit(spl_image, &load, offset, header); } else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) { struct spl_load_info load; diff --git a/drivers/mtd/nand/raw/nand_spl_loaders.c b/drivers/mtd/nand/raw/nand_spl_loaders.c index 177c12b581..4befc75c04 100644 --- a/drivers/mtd/nand/raw/nand_spl_loaders.c +++ b/drivers/mtd/nand/raw/nand_spl_loaders.c @@ -41,6 +41,34 @@ int nand_spl_load_image(uint32_t offs, unsigned int size, void *dst) return 0; } +/** + * nand_spl_adjust_offset - Adjust offset from a starting sector + * @sector: Address of the sector + * @offs: Offset starting from @sector + * + * If one or more bad blocks are in the address space between @sector + * and @sector + @offs, @offs is increased by the NAND block size for + * each bad block found. + */ +u32 nand_spl_adjust_offset(u32 sector, u32 offs) +{ + unsigned int block, lastblock; + + block = sector / CONFIG_SYS_NAND_BLOCK_SIZE; + lastblock = (sector + offs) / CONFIG_SYS_NAND_BLOCK_SIZE; + + while (block <= lastblock) { + if (nand_is_bad_block(block)) { + offs += CONFIG_SYS_NAND_BLOCK_SIZE; + lastblock++; + } + + block++; + } + + return offs; +} + #ifdef CONFIG_SPL_UBI /* * Temporary storage for non NAND page aligned and non NAND page sized diff --git a/include/nand.h b/include/nand.h index 93cbe1e25d..80dd6469bc 100644 --- a/include/nand.h +++ b/include/nand.h @@ -120,6 +120,7 @@ int nand_unlock(struct mtd_info *mtd, loff_t start, size_t length, int allexcept); int nand_get_lock_status(struct mtd_info *mtd, loff_t offset); +u32 nand_spl_adjust_offset(u32 sector, u32 offs); int nand_spl_load_image(uint32_t offs, unsigned int size, void *dst); int nand_spl_read_block(int block, int offset, int len, void *dst); void nand_deselect(void); diff --git a/include/spl.h b/include/spl.h index e2fbd6d765..bb31a20595 100644 --- a/include/spl.h +++ b/include/spl.h @@ -159,6 +159,8 @@ struct spl_image_info { * @bl_len: Block length for reading in bytes * @filename: Name of the fit image file. * @read: Function to call to read from the device + * @adjust_offset: Function to call to adjust offset used to read from the + * device */ struct spl_load_info { void *dev; @@ -167,6 +169,8 @@ struct spl_load_info { const char *filename; ulong (*read)(struct spl_load_info *load, ulong sector, ulong count, void *buf); + ulong (*adjust_offset)(struct spl_load_info *load, ulong sector, + ulong offset); }; /*