mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] mtd: nand-imx: do not use blocks reserved for BBT
@ 2020-02-05 13:35 Sascha Hauer
  2020-02-05 13:35 ` [PATCH 2/3] mtd: nand-imx: Create BBT automatically when necessary Sascha Hauer
  2020-02-05 13:35 ` [PATCH 3/3] mtd: nand-imx: make sure the just created BBT is used Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Sascha Hauer @ 2020-02-05 13:35 UTC (permalink / raw)
  To: Barebox List; +Cc: ukl

Due to the differences of the logical page format and the raw page
format on NAND the generic nand support can't read the bad block marker
on the NAND. For this reason we cleared the NAND_BBT_CREATE flag and
have the imx_nand_bbm command to create a BBT if none is found in the
flash. We have also cleared the NAND_BBT_WRITE flag which causes
problems.  Normally a BBT occupies two blocks in NAND, but to have some
space for the BBT when one of these becomes bad we normally reserve 4
blocks for the BBT. In case we want to write the BBT to flash we have to
reserve them from being written to by general NAND operations. In case
we don't ever write to the BBT, as indicated by a cleared NAND_BBT_WRITE
flag, the reserved blocks can be used by the general NAND operations.
This way it happens that barebox uses the reserved blocks for data
storage, but Linux (which has NAND_BBT_WRITE set) can't read any data
from it.  This results in corrupted UBI images.

It's not necessary to clear the NAND_BBT_WRITE flag, all we really have
to do is to prevent the BBT layer from creating a new BBT. For this it's
enough to clear the NAND_BBT_CREATE flag.

Fixes: 545453ddae ("mtd: nand: Add command to generate a flash BBT")
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mtd/nand/nand_imx.c     | 11 ++++-------
 drivers/mtd/nand/nand_imx_bbm.c |  4 ++--
 2 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/mtd/nand/nand_imx.c b/drivers/mtd/nand/nand_imx.c
index 1a065cb46f..8e1558da6b 100644
--- a/drivers/mtd/nand/nand_imx.c
+++ b/drivers/mtd/nand/nand_imx.c
@@ -1072,7 +1072,7 @@ static uint8_t bbt_pattern[] = { 'B', 'b', 't', '0' };
 static uint8_t mirror_pattern[] = { '1', 't', 'b', 'B' };
 
 static struct nand_bbt_descr bbt_main_descr = {
-	.options = NAND_BBT_LASTBLOCK
+	.options = NAND_BBT_LASTBLOCK | NAND_BBT_WRITE
 		| NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP,
 	.offs = 0,
 	.len = 4,
@@ -1082,7 +1082,7 @@ static struct nand_bbt_descr bbt_main_descr = {
 };
 
 static struct nand_bbt_descr bbt_mirror_descr = {
-	.options = NAND_BBT_LASTBLOCK
+	.options = NAND_BBT_LASTBLOCK | NAND_BBT_WRITE
 		| NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP,
 	.offs = 0,
 	.len = 4,
@@ -1312,8 +1312,8 @@ static int __init imxnd_probe(struct device_d *dev)
 		if (nfc_is_v21())
 			writew(NFC_V2_SPAS_SPARESIZE(64), host->regs + NFC_V2_SPAS);
 	} else {
-		bbt_main_descr.options |= NAND_BBT_WRITE | NAND_BBT_CREATE;
-		bbt_mirror_descr.options |= NAND_BBT_WRITE | NAND_BBT_CREATE;
+		bbt_main_descr.options |= NAND_BBT_CREATE;
+		bbt_mirror_descr.options |= NAND_BBT_CREATE;
 
 		if (nfc_is_v21())
 			writew(NFC_V2_SPAS_SPARESIZE(16), host->regs + NFC_V2_SPAS);
@@ -1330,9 +1330,6 @@ static int __init imxnd_probe(struct device_d *dev)
 
 	if (host->flash_bbt && this->bbt_td->pages[0] == -1 && this->bbt_md->pages[0] == -1) {
 		dev_warn(dev, "no BBT found. create one using the imx_nand_bbm command\n");
-	} else {
-		bbt_main_descr.options |= NAND_BBT_WRITE | NAND_BBT_CREATE;
-		bbt_mirror_descr.options |= NAND_BBT_WRITE | NAND_BBT_CREATE;
 	}
 
 	add_mtd_nand_device(mtd, "nand");
diff --git a/drivers/mtd/nand/nand_imx_bbm.c b/drivers/mtd/nand/nand_imx_bbm.c
index c005482b06..582b4c069a 100644
--- a/drivers/mtd/nand/nand_imx_bbm.c
+++ b/drivers/mtd/nand/nand_imx_bbm.c
@@ -124,8 +124,8 @@ static int attach_bbt(struct mtd_info *mtd, void *bbt)
 {
 	struct nand_chip *chip = mtd_to_nand(mtd);
 
-	chip->bbt_td->options |= NAND_BBT_WRITE | NAND_BBT_CREATE;
-	chip->bbt_md->options |= NAND_BBT_WRITE | NAND_BBT_CREATE;
+	chip->bbt_td->options |= NAND_BBT_CREATE;
+	chip->bbt_md->options |= NAND_BBT_CREATE;
 	free(chip->bbt);
 	chip->bbt = bbt;
 
-- 
2.25.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-02-05 13:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-05 13:35 [PATCH 1/3] mtd: nand-imx: do not use blocks reserved for BBT Sascha Hauer
2020-02-05 13:35 ` [PATCH 2/3] mtd: nand-imx: Create BBT automatically when necessary Sascha Hauer
2020-02-05 13:35 ` [PATCH 3/3] mtd: nand-imx: make sure the just created BBT is used Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox