All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] Fix the SPL loading of a FIT image from NAND
@ 2020-05-09 11:55 Dario Binacchi
  2020-05-09 11:55 ` [PATCH 1/3] spl: fix format of function documentation Dario Binacchi
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Dario Binacchi @ 2020-05-09 11:55 UTC (permalink / raw)
  To: u-boot


Loading u-boot and its fdt from a NAND memory area with bad blocks led
to the creation of these patches.


Dario Binacchi (3):
  spl: fix format of function documentation
  spl: fit: fail fit loading in case of FDT appending error
  spl: fit: nand: fix fit loading in case of bad blocks

 common/spl/spl_fit.c                    | 18 ++++++++++------
 common/spl/spl_nand.c                   |  7 +++++++
 drivers/mtd/nand/raw/nand_spl_loaders.c | 28 +++++++++++++++++++++++++
 include/nand.h                          |  1 +
 include/spl.h                           |  6 +++++-
 5 files changed, 53 insertions(+), 7 deletions(-)

-- 
2.17.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] spl: fix format of function documentation
  2020-05-09 11:55 [PATCH 0/3] Fix the SPL loading of a FIT image from NAND Dario Binacchi
@ 2020-05-09 11:55 ` Dario Binacchi
  2020-05-09 11:55 ` [PATCH 2/3] spl: fit: fail fit loading in case of FDT appending error Dario Binacchi
  2020-05-09 11:55 ` [PATCH 3/3] spl: fit: nand: fix fit loading in case of bad blocks Dario Binacchi
  2 siblings, 0 replies; 5+ messages in thread
From: Dario Binacchi @ 2020-05-09 11:55 UTC (permalink / raw)
  To: u-boot

U-Boot adopted the kernel-doc annotation style.

Signed-off-by: Dario Binacchi <dariobin@libero.it>
---

 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 *
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] spl: fit: fail fit loading in case of FDT appending error
  2020-05-09 11:55 [PATCH 0/3] Fix the SPL loading of a FIT image from NAND Dario Binacchi
  2020-05-09 11:55 ` [PATCH 1/3] spl: fix format of function documentation Dario Binacchi
@ 2020-05-09 11:55 ` Dario Binacchi
  2020-05-09 12:07   ` Stefan Roese
  2020-05-09 11:55 ` [PATCH 3/3] spl: fit: nand: fix fit loading in case of bad blocks Dario Binacchi
  2 siblings, 1 reply; 5+ messages in thread
From: Dario Binacchi @ 2020-05-09 11:55 UTC (permalink / raw)
  To: u-boot

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 <dariobin@libero.it>
---

 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 */
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] spl: fit: nand: fix fit loading in case of bad blocks
  2020-05-09 11:55 [PATCH 0/3] Fix the SPL loading of a FIT image from NAND Dario Binacchi
  2020-05-09 11:55 ` [PATCH 1/3] spl: fix format of function documentation Dario Binacchi
  2020-05-09 11:55 ` [PATCH 2/3] spl: fit: fail fit loading in case of FDT appending error Dario Binacchi
@ 2020-05-09 11:55 ` Dario Binacchi
  2 siblings, 0 replies; 5+ messages in thread
From: Dario Binacchi @ 2020-05-09 11:55 UTC (permalink / raw)
  To: u-boot

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 <dariobin@libero.it>
---

 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);
 };
 
 /*
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] spl: fit: fail fit loading in case of FDT appending error
  2020-05-09 11:55 ` [PATCH 2/3] spl: fit: fail fit loading in case of FDT appending error Dario Binacchi
@ 2020-05-09 12:07   ` Stefan Roese
  0 siblings, 0 replies; 5+ messages in thread
From: Stefan Roese @ 2020-05-09 12:07 UTC (permalink / raw)
  To: u-boot

On 09.05.20 13:55, Dario Binacchi wrote:
> 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 <dariobin@libero.it>
> ---
> 
>   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)

Please use this instead of using #ifdef's:

		if (IS_ENABLED(CONFIG_OF_EMBED))

Thanks,
Stefan

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-05-09 12:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-09 11:55 [PATCH 0/3] Fix the SPL loading of a FIT image from NAND Dario Binacchi
2020-05-09 11:55 ` [PATCH 1/3] spl: fix format of function documentation Dario Binacchi
2020-05-09 11:55 ` [PATCH 2/3] spl: fit: fail fit loading in case of FDT appending error Dario Binacchi
2020-05-09 12:07   ` Stefan Roese
2020-05-09 11:55 ` [PATCH 3/3] spl: fit: nand: fix fit loading in case of bad blocks Dario Binacchi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.