From: Michael Trimarchi <michael@amarulasolutions.com>
To: Stefano Babic <sbabic@denx.de>, uboot-imx@nxp.com
Cc: Fabio Estevam <festevam@gmail.com>, u-boot@lists.denx.de
Subject: [RFC PATCH] arm: mach-imx: cmd_nandbcb fix bad block handling
Date: Sat, 23 Apr 2022 00:11:05 +0200 [thread overview]
Message-ID: <20220422221105.2954828-1-michael@amarulasolutions.com> (raw)
The badblock should be skipped properly in reading and writing.
Fix the logic
NOTE. This is a rfc. Working on imx8mn and found the bad block
handling in nand is quite broken. Seems that bootrom does not handle
it so I switch on spl nand bad block and found there other bugs. I have
fixed most of them. Let's start in how to read back the nandbcb
Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
---
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 100dc17a15..48955092b7 100644
--- a/arch/arm/mach-imx/cmd_nandbcb.c
+++ b/arch/arm/mach-imx/cmd_nandbcb.c
@@ -505,10 +505,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) {
@@ -529,7 +525,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);
@@ -616,6 +612,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;
}
@@ -675,20 +672,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)
@@ -696,9 +688,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");
@@ -728,6 +720,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
reply other threads:[~2022-04-22 22:11 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20220422221105.2954828-1-michael@amarulasolutions.com \
--to=michael@amarulasolutions.com \
--cc=festevam@gmail.com \
--cc=sbabic@denx.de \
--cc=u-boot@lists.denx.de \
--cc=uboot-imx@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox