public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Tim Harvey <tharvey@gateworks.com>
To: u-boot@lists.denx.de
Subject: [PATCH 02/11] spl: fit: nand: allow for non-page-aligned elements
Date: Mon,  1 Mar 2021 14:33:28 -0800	[thread overview]
Message-ID: <20210301223337.7763-3-tharvey@gateworks.com> (raw)
In-Reply-To: <20210301223337.7763-1-tharvey@gateworks.com>

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>
---
 common/spl/spl_nand.c               | 20 +++++++++++++++-----
 drivers/mtd/nand/raw/mxs_nand_spl.c |  5 +++++
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c
index 8213836df4..59f4a84a36 100644
--- a/common/spl/spl_nand.c
+++ b/common/spl/spl_nand.c
@@ -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)
diff --git a/drivers/mtd/nand/raw/mxs_nand_spl.c b/drivers/mtd/nand/raw/mxs_nand_spl.c
index 46dc29df36..17f46ae5e9 100644
--- a/drivers/mtd/nand/raw/mxs_nand_spl.c
+++ b/drivers/mtd/nand/raw/mxs_nand_spl.c
@@ -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;
-- 
2.17.1

  parent reply	other threads:[~2021-03-01 22:33 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-01 22:33 [PATCH 00/11] imx: ventana: convert Gateworks Ventana to dm Tim Harvey
2021-03-01 22:33 ` [PATCH 01/11] spl: fit: nand: skip bad block handling if NAND chip not fully defined Tim Harvey
2021-03-02 13:28   ` Tom Rini
2021-04-08 20:57   ` sbabic at denx.de
2021-03-01 22:33 ` Tim Harvey [this message]
2021-03-02 13:28   ` [PATCH 02/11] spl: fit: nand: allow for non-page-aligned elements Tom Rini
2021-04-08 20:58   ` sbabic at denx.de
2021-03-01 22:33 ` [PATCH 03/11] dt-bindings: add tda1997x and bindings Tim Harvey
2021-03-02 13:28   ` Tom Rini
2021-04-08 20:57   ` sbabic at denx.de
2021-03-01 22:33 ` [PATCH 04/11] imx: ventana: add Gateworks Ventana dts Tim Harvey
2021-04-08 20:57   ` sbabic at denx.de
2021-03-01 22:33 ` [PATCH 05/11] arm: dts: imx6qdl-gw*: add dr_mode prop to dt to avoid error Tim Harvey
2021-04-05 21:27   ` Peter Robinson
2021-04-05 23:46     ` Tim Harvey
2021-04-08 20:57   ` sbabic at denx.de
2021-03-01 22:33 ` [PATCH 06/11] imx: ventana: convert U-Boot to OF_CONTROL using FIT image Tim Harvey
2021-04-08 20:57   ` sbabic at denx.de
     [not found]   ` <606f6e37.1c69fb81.a6d7.559aSMTPIN_ADDED_MISSING@mx.google.com>
2021-04-09 19:52     ` Tim Harvey
2021-04-09 20:00       ` Stefano Babic
2021-04-09 20:08         ` Tim Harvey
2021-04-09 20:14           ` Tim Harvey
2021-04-10  0:32             ` Tim Harvey
2021-03-01 22:33 ` [PATCH 07/11] imx: ventana: add pinctrl and remove unneeded UART init and config Tim Harvey
2021-04-08 20:57   ` sbabic at denx.de
2021-03-01 22:33 ` [PATCH 08/11] imx: ventana: enable dm support for USB Tim Harvey
2021-04-08 20:59   ` sbabic at denx.de
2021-03-01 22:33 ` [PATCH 09/11] imx: ventana: enable dm support for MMC and SATA Tim Harvey
2021-03-01 22:48   ` Peter Robinson
2021-03-02  0:19     ` Fabio Estevam
2021-03-02  1:41       ` Tim Harvey
2021-03-02 13:28         ` Tom Rini
2021-03-03  1:15     ` Kever Yang
2021-04-08 20:58   ` sbabic at denx.de
2021-03-01 22:33 ` [PATCH 10/11] imx: ventana: enable dm for MTD and NAND Tim Harvey
2021-04-08 20:59   ` sbabic at denx.de
2021-03-01 22:33 ` [PATCH 11/11] imx: ventana: enable dm for SPI Tim Harvey
2021-04-08 20:57   ` sbabic at denx.de
2021-03-25 13:59 ` [PATCH 00/11] imx: ventana: convert Gateworks Ventana to dm Tim Harvey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210301223337.7763-3-tharvey@gateworks.com \
    --to=tharvey@gateworks.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox