On Thu, Nov 14, 2019 at 2:02 PM Tim Harvey <thar...@gateworks.com> wrote: > > Lokesh, > > I'm trying to convert the imx6 Gateworks Ventana boards to DM which > requires using NAND based FIT images for the multiple DTB's. > > You apparently added support for this in > 8bd887727913e9393ef467cdf8b0146babb2673d but I find it fails because > the raw nand read functions take byte offset/size yet read > page-aligned. Because bl_len=1 the buffer pointer is not adjusted in > spl_load_fit_image to the proper position in the buffer. Thus raw > page-aligned image load works but as soon as you start parsing a FIT > Image and need to load elements that are not page-aligned things go > wrong. > > How did you test this? > > I'm not sure what the best approach is to fix this. Any ideas? >
The following addresses this issue but perhaps only for MXS_NAND as it doesn't appear that get_nand_dev_by_index() is supported by all raw nand drivers and likely should be handled by some dm variant: Author: Tim Harvey <thar...@gateworks.com> Date: Thu Nov 14 13:01:17 2019 -0800 spl: nand: use nand pagesize to fix loading FIT images The nand read functions are page-aligned to the writesize of the NAND device. This fixes loading non-page-aligned elements. Signed-off-by: Tim Harvey <thar...@gateworks.com> 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) { Tim _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot