spl: fit: nand: allow for non-page-aligned elements
authorTim Harvey <tharvey@gateworks.com>
Mon, 1 Mar 2021 22:33:28 +0000 (14:33 -0800)
committerStefano Babic <sbabic@denx.de>
Thu, 8 Apr 2021 18:29:53 +0000 (20:29 +0200)
Add a weak nand_get_mtd function for nand drivers to provide mtd info
and use this to set pagesize such that reading of non page-aligned
elements can succeed.

The spl_load_simple_fit already handles block block access so all we
need to do is provide the nand writesize as the block length.

Further cleanup of the drivers which use nand_spl_loaders.c such as
am335x_spl_bch.c, atmel_nand.c, and nand_spl_simple.c could be done
using info from mtd_info instead of statically defined details.

Signed-off-by: Tim Harvey <tharvey@gateworks.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
common/spl/spl_nand.c
drivers/mtd/nand/raw/mxs_nand_spl.c

index 8213836..59f4a84 100644 (file)
@@ -48,17 +48,27 @@ static ulong spl_nand_fit_read(struct spl_load_info *load, ulong offs,
 
        sector = *(int *)load->priv;
        offs = sector + nand_spl_adjust_offset(sector, offs - sector);
+#else
+       offs *= load->bl_len;
+       size *= load->bl_len;
 #endif
        err = nand_spl_load_image(offs, size, dst);
        if (err)
                return 0;
 
-       return size;
+       return size / load->bl_len;
+}
+
+struct mtd_info * __weak nand_get_mtd(void)
+{
+       return NULL;
 }
 
 static int spl_nand_load_element(struct spl_image_info *spl_image,
                                 int offset, struct image_header *header)
 {
+       struct mtd_info *mtd = nand_get_mtd();
+       int bl_len = mtd ? mtd->writesize : 1;
        int err;
 
        err = nand_spl_load_image(offset, sizeof(*header), (void *)header);
@@ -73,18 +83,18 @@ static int spl_nand_load_element(struct spl_image_info *spl_image,
                load.dev = NULL;
                load.priv = &offset;
                load.filename = NULL;
-               load.bl_len = 1;
+               load.bl_len = bl_len;
                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 / bl_len, header);
        } else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
                struct spl_load_info load;
 
                load.dev = NULL;
                load.priv = NULL;
                load.filename = NULL;
-               load.bl_len = 1;
+               load.bl_len = bl_len;
                load.read = spl_nand_fit_read;
-               return spl_load_imx_container(spl_image, &load, offset);
+               return spl_load_imx_container(spl_image, &load, offset / bl_len);
        } else {
                err = spl_parse_image_header(spl_image, header);
                if (err)
index 46dc29d..17f46ae 100644 (file)
@@ -282,6 +282,11 @@ int nand_spl_load_image(uint32_t offs, unsigned int size, void *buf)
        return 0;
 }
 
+struct mtd_info *nand_get_mtd(void)
+{
+       return mtd;
+}
+
 int nand_default_bbt(struct mtd_info *mtd)
 {
        return 0;