[U-Boot] [RFC PATCH] spl: nand: use nand pagesize to fix loading FIT images

Tim Harvey tharvey at gateworks.com
Tue Nov 19 01:12:02 UTC 2019


The nand read functions are page-aligned to the writesize of the NAND
device. This fixes loading non-page-aligned elements.

I ran into this issue while trying to convert the IMX6 Gateworks Ventana
board support to DM which requires NAND based FIT images to handle multiple
DTB's. I'm not sure how anyone could be using NAND based FIT images without
some sort of page size alignment other than the 1 byte in the current code.

Note that the RAW NAND drivers deal with byte offsets/counts instead of
sector offsets/counts like the blk devices but we are able to handle
the conversion within spl_nand.c.

Sending this as an RFC as I'm looking for the correct way to handle getting
the mtd_info to find the page size. Certainly using get_nand_dev_by_index(0)
is not the way to go as its not even implemented by many of the nand drivers.

Signed-off-by: Tim Harvey <tharvey at gateworks.com>
---
 common/spl/spl_nand.c               | 14 +++++++++-----
 drivers/mtd/nand/raw/mxs_nand_spl.c |  4 ++++
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c
index 5f8a111..280ee3b 100644
--- a/common/spl/spl_nand.c
+++ b/common/spl/spl_nand.c
@@ -36,14 +36,16 @@ static int spl_nand_load_image(struct spl_image_info *spl_image,
 }
 #else
 
-static ulong spl_nand_fit_read(struct spl_load_info *load, ulong offs,
-			       ulong size, void *dst)
+static ulong spl_nand_fit_read(struct spl_load_info *load, ulong page,
+			       ulong pages, void *dst)
 {
 	int ret;
+	ulong offs = page * load->bl_len;
+	ulong size = pages * load->bl_len;
 
 	ret = nand_spl_load_image(offs, size, dst);
 	if (!ret)
-		return size;
+		return pages;
 	else
 		return 0;
 }
@@ -51,6 +53,7 @@ static ulong spl_nand_fit_read(struct spl_load_info *load, ulong offs,
 static int spl_nand_load_element(struct spl_image_info *spl_image,
 				 int offset, struct image_header *header)
 {
+	struct mtd_info *mtd = get_nand_dev_by_index(0);
 	int err;
 
 	err = nand_spl_load_image(offset, sizeof(*header), (void *)header);
@@ -65,9 +68,10 @@ static int spl_nand_load_element(struct spl_image_info *spl_image,
 		load.dev = NULL;
 		load.priv = NULL;
 		load.filename = NULL;
-		load.bl_len = 1;
+		load.bl_len = mtd->writesize;
 		load.read = spl_nand_fit_read;
-		return spl_load_simple_fit(spl_image, &load, offset, header);
+		return spl_load_simple_fit(spl_image, &load,
+					   offset / load.bl_len, header);
 	} else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
 		struct spl_load_info load;
 
diff --git a/drivers/mtd/nand/raw/mxs_nand_spl.c b/drivers/mtd/nand/raw/mxs_nand_spl.c
index 975a91a..222fa5c 100644
--- a/drivers/mtd/nand/raw/mxs_nand_spl.c
+++ b/drivers/mtd/nand/raw/mxs_nand_spl.c
@@ -11,6 +11,10 @@
 static struct mtd_info *mtd;
 static struct nand_chip nand_chip;
 
+struct mtd_info *get_nand_dev_by_index(int dev) {
+	return mtd;
+}
+
 static void mxs_nand_command(struct mtd_info *mtd, unsigned int command,
 			     int column, int page_addr)
 {
-- 
2.7.4



More information about the U-Boot mailing list