All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Trimarchi <michael@amarulasolutions.com>
To: Han Xu <han.xu@nxp.com>, U-Boot-Denx <u-boot@lists.denx.de>
Cc: Ye Li <ye.li@nxp.com>, Stefano Babic <sbabic@denx.de>,
	Miquel Raynal <miquel.raynal@bootlin.com>,
	Fabio Estevam <festevam@denx.de>,
	Dario Binacchi <dario.binacchi@amarulasolutions.com>,
	Sean Anderson <sean.anderson@seco.com>,
	linux-kernel@amarulasolutions.com,
	Jagan Teki <jagan@amarulasolutions.com>,
	Ariel D'Alessandro <ariel.dalessandro@collabora.com>,
	Fabio Estevam <festevam@gmail.com>
Subject: [PATCH V2 3/4] arm: mach-imx: cmd_nandbcb fix bad block handling
Date: Wed, 27 Apr 2022 07:50:24 +0200	[thread overview]
Message-ID: <20220427055025.231586-4-michael@amarulasolutions.com> (raw)
In-Reply-To: <20220427055025.231586-1-michael@amarulasolutions.com>

The badblock should be skipped properly in reading and writing.
Fix the logic. The bcb struct is written, skipping the bad block,
so we need to read using the same logic. This was tested create
bad block in the area and then flash it and read it back.

Cc: Han Xu <han.xu@nxp.com>
Cc: Fabio Estevam <festevam@gmail.com>
Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
---
V1->V2:
	- Adjust the commit message
	- Add Cc Han Xu and Fabio
	- move out from RFC
---
 arch/arm/mach-imx/cmd_nandbcb.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/arch/arm/mach-imx/cmd_nandbcb.c b/arch/arm/mach-imx/cmd_nandbcb.c
index f119e9f88d..c54f52b343 100644
--- a/arch/arm/mach-imx/cmd_nandbcb.c
+++ b/arch/arm/mach-imx/cmd_nandbcb.c
@@ -506,10 +506,6 @@ static int read_fcb(struct boot_config *boot_cfg, struct fcb_block *fcb,
 	int ret = 0;
 
 	mtd = boot_cfg->mtd;
-	if (mtd_block_isbad(mtd, off)) {
-		printf("Block %d is bad, skipped\n", (int)CONV_TO_BLOCKS(off));
-		return 1;
-	}
 
 	fcb_raw_page = kzalloc(mtd->writesize + mtd->oobsize, GFP_KERNEL);
 	if (!fcb_raw_page) {
@@ -530,7 +526,7 @@ static int read_fcb(struct boot_config *boot_cfg, struct fcb_block *fcb,
 		else if (plat_config.misc_flags & FCB_ENCODE_BCH_40b)
 			mxs_nand_mode_fcb_40bit(mtd);
 
-		ret = nand_read(mtd, off, &size, (u_char *)fcb);
+		ret = nand_read_skip_bad(mtd, off, &size, NULL, mtd->size, (u_char *)fcb);
 
 		/* switch BCH back */
 		mxs_nand_mode_normal(mtd);
@@ -617,6 +613,7 @@ static int write_fcb(struct boot_config *boot_cfg, struct fcb_block *fcb)
 	for (i = 0; i < g_boot_search_count; i++) {
 		if (mtd_block_isbad(mtd, off)) {
 			printf("Block %d is bad, skipped\n", i);
+			off += mtd->erasesize;
 			continue;
 		}
 
@@ -676,20 +673,15 @@ static int read_dbbt(struct boot_config *boot_cfg, struct dbbt_block *dbbt,
 		      void *dbbt_data_page, loff_t off)
 {
 	size_t size;
+	size_t actual_size;
 	struct mtd_info *mtd;
 	loff_t to;
 	int ret;
 
 	mtd = boot_cfg->mtd;
 
-	if (mtd_block_isbad(mtd, off)) {
-		printf("Block %d is bad, skipped\n",
-		       (int)CONV_TO_BLOCKS(off));
-		return 1;
-	}
-
 	size = sizeof(struct dbbt_block);
-	ret = nand_read(mtd, off, &size, (u_char *)dbbt);
+	ret = nand_read_skip_bad(mtd, off, &size, &actual_size, mtd->size, (u_char *)dbbt);
 	printf("NAND DBBT read from 0x%llx offset 0x%zx read: %s\n",
 	       off, size, ret ? "ERROR" : "OK");
 	if (ret)
@@ -697,9 +689,9 @@ static int read_dbbt(struct boot_config *boot_cfg, struct dbbt_block *dbbt,
 
 	/* dbbtpages == 0 if no bad blocks */
 	if (dbbt->dbbtpages > 0) {
-		to = off + 4 * mtd->writesize;
+		to = off + 4 * mtd->writesize + actual_size - size;
 		size = mtd->writesize;
-		ret = nand_read(mtd, to, &size, dbbt_data_page);
+		ret = nand_read_skip_bad(mtd, to, &size, NULL, mtd->size, dbbt_data_page);
 		printf("DBBT data read from 0x%llx offset 0x%zx read: %s\n",
 		       to, size, ret ? "ERROR" : "OK");
 
@@ -729,6 +721,7 @@ static int write_dbbt(struct boot_config *boot_cfg, struct dbbt_block *dbbt,
 		if (mtd_block_isbad(mtd, off)) {
 			printf("Block %d is bad, skipped\n",
 			       (int)(i + CONV_TO_BLOCKS(off)));
+			off += mtd->erasesize;
 			continue;
 		}
 
-- 
2.25.1


  parent reply	other threads:[~2022-04-27  5:51 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-27  5:50 [PATCH V2 0/4] MXS nand fixes in SPL Michael Trimarchi
2022-04-27  5:50 ` [PATCH V2 1/4] nand: raw: mxs_nand: Fix specific hook registration Michael Trimarchi
2022-05-06 14:40   ` Han Xu
2022-04-27  5:50 ` [PATCH V2 2/4] mtd: nand: mxs_nand_spl: Fix bad block skipping Michael Trimarchi
2022-04-28  0:27   ` Han Xu
2022-04-28  5:01     ` Michael Nazzareno Trimarchi
2022-05-01  6:36       ` Michael Nazzareno Trimarchi
2022-05-02 21:32         ` Han Xu
2022-05-03  5:14           ` Michael Nazzareno Trimarchi
2022-05-06  8:21             ` Michael Nazzareno Trimarchi
2022-05-06 14:41   ` Han Xu
2022-05-06 14:44     ` Michael Nazzareno Trimarchi
2022-04-27  5:50 ` Michael Trimarchi [this message]
2022-05-06 14:41   ` [PATCH V2 3/4] arm: mach-imx: cmd_nandbcb fix bad block handling Han Xu
2022-05-11  6:49     ` Michael Nazzareno Trimarchi
2022-05-11 15:17       ` Tim Harvey
2022-04-27  5:50 ` [PATCH 4/4] spl: spl_nand: Fix bad block handling in fitImage Michael Trimarchi
2022-04-28 12:45   ` Tom Rini
2022-05-06 14:42   ` Han Xu
2022-05-11 15:16 ` [PATCH V2 0/4] MXS nand fixes in SPL 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=20220427055025.231586-4-michael@amarulasolutions.com \
    --to=michael@amarulasolutions.com \
    --cc=ariel.dalessandro@collabora.com \
    --cc=dario.binacchi@amarulasolutions.com \
    --cc=festevam@denx.de \
    --cc=festevam@gmail.com \
    --cc=han.xu@nxp.com \
    --cc=jagan@amarulasolutions.com \
    --cc=linux-kernel@amarulasolutions.com \
    --cc=miquel.raynal@bootlin.com \
    --cc=sbabic@denx.de \
    --cc=sean.anderson@seco.com \
    --cc=u-boot@lists.denx.de \
    --cc=ye.li@nxp.com \
    /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 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.