mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ladislav Michl <ladis@linux-mips.org>
To: barebox@lists.infradead.org
Subject: Re: [PATCH 03/16] mtd: nand: hide in-memory BBT implementation details
Date: Mon, 29 Oct 2018 12:43:29 +0100	[thread overview]
Message-ID: <20181029114329.GA12977@lenoch> (raw)
In-Reply-To: <20181029100702.GA7947@lenoch>

On Mon, Oct 29, 2018 at 11:07:02AM +0100, Ladislav Michl wrote:
> On Sun, Oct 28, 2018 at 10:22:13PM +0100, Ladislav Michl wrote:
> > Linux commit b32843b772db adapted for Barebox:
> 
> Hmm, there's something fishy with markgood functions (trying different board).
> Debugging now...
> 
> >   nand_base.c shouldn't have to know the implementation details of
> >   nand_bbt's in-memory BBT. Specifically, nand_base shouldn't perform the
> >   bit masking and shifting to isolate a BBT entry.
> > 
> >   Instead, just move some of the BBT code into a new nand_markbad_bbt()
> >   interface. This interface allows external users (i.e., nand_base) to
> >   mark a single block as bad in the BBT. Then nand_bbt will take care of
> >   modifying the in-memory BBT and updating the flash-based BBT (if
> >   applicable).

Two bugs spotted:
1) we need to select chip again after erase
2) Linux cares only about marking block bad in BBT while Barebox supports
   also unmarking it. Thus we need a bit more complicated version of
   bbt_mark_entry.

Incremental patch bellow. Please let me know if there are another issues
with this serie, I'll squash it for v2.

Thank you.

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index e290081bb..6004f423b 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -447,8 +447,11 @@ static int nand_block_markgood_lowlevel(struct mtd_info *mtd, loff_t ofs)
 		nand_erase_nand(mtd, &einfo, 0);
 		mtd->allow_erasebad = allow_erasebad;
 
-		/* Still bad? */
-		ret = chip->block_bad(mtd, ofs, 0);
+		/*
+		 * Verify erase succeded. We need to select chip again,
+		 * as nand_erase_nand deselected it.
+		 */
+		ret = chip->block_bad(mtd, ofs, 1);
 		if (ret)
 			return ret;
 	}
diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c
index b4f3b7e95..65870d3ec 100644
--- a/drivers/mtd/nand/nand_bbt.c
+++ b/drivers/mtd/nand/nand_bbt.c
@@ -89,8 +89,14 @@ static inline uint8_t bbt_get_entry(struct nand_chip *chip, int block)
 static inline void bbt_mark_entry(struct nand_chip *chip, int block,
 		uint8_t mark)
 {
-	uint8_t msk = (mark & BBT_ENTRY_MASK) << ((block & BBT_ENTRY_MASK) * 2);
-	chip->bbt[block >> BBT_ENTRY_SHIFT] |= msk;
+	/*
+	 * Unlike original Linux implementation, Barebox needs also
+	 * mark block as good again, so mask entry comletely.
+	 */
+	int index = block >> BBT_ENTRY_SHIFT;
+	int shift = (block & BBT_ENTRY_MASK) * 2;
+	chip->bbt[index] &= ~(BBT_ENTRY_MASK << shift);
+	chip->bbt[index] |= (mark & BBT_ENTRY_MASK) << shift;
 }
 
 static int check_pattern_no_oob(uint8_t *buf, struct nand_bbt_descr *td)

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

  reply	other threads:[~2018-10-29 11:43 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-28 21:19 [PATCH 00/16] NAND update (1st step) Ladislav Michl
2018-10-28 21:21 ` [PATCH 01/16] mtd: nand: refactor chip->block_markbad interface Ladislav Michl
2018-10-28 21:21 ` [PATCH 02/16] mtd: nand: remove multiplied-by-2 block logic Ladislav Michl
2018-10-28 21:22 ` [PATCH 03/16] mtd: nand: hide in-memory BBT implementation details Ladislav Michl
2018-10-29 10:07   ` Ladislav Michl
2018-10-29 11:43     ` Ladislav Michl [this message]
2018-10-30  9:07       ` Sascha Hauer
2018-10-28 21:22 ` [PATCH 04/16] mtd: nand: remove NAND_BBT_SCANEMPTY Ladislav Michl
2018-10-28 21:22 ` [PATCH 05/16] mtd: nand: Request strength instead of bytes for soft BCH Ladislav Michl
2018-10-28 21:23 ` [PATCH 06/16] mtd: atmel_nand: Add per board ECC setup Ladislav Michl
2018-10-28 21:23 ` [PATCH 07/16] mtd: nand: simplify nand_bch_init() usage Ladislav Michl
2018-10-28 21:24 ` [PATCH 08/16] mtd: nand_bbt: kill NAND_BBT_SCANALLPAGES Ladislav Michl
2018-10-28 21:24 ` [PATCH 09/16] mtd: nand_bbt: handle error case for nand_create_badblock_pattern() Ladislav Michl
2018-10-28 21:25 ` [PATCH 10/16] mtd: nand_bbt: make nand_scan_bbt() static Ladislav Michl
2018-10-28 21:25 ` [PATCH 11/16] mtd: nand_bbt: unify/fix error handling in nand_scan_bbt() Ladislav Michl
2018-10-28 21:25 ` [PATCH 12/16] mtd: nand_bbt: Move BBT block selection logic out of write_bbt() Ladislav Michl
2018-10-28 21:26 ` [PATCH 13/16] mtd: nand_bbt: scan for next free bbt block if writing bbt fails Ladislav Michl
2018-10-28 21:26 ` [PATCH 14/16] mtd: nand: Kill the chip->scan_bbt() hook Ladislav Michl
2019-01-21  8:32   ` Sascha Hauer
2018-10-28 21:27 ` [PATCH 15/16] mtd: nand: Kill cellinfo Ladislav Michl
2018-10-28 21:27 ` [PATCH 16/16] mtd: nand: detect OOB size for Toshiba 24nm raw SLC Ladislav Michl

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=20181029114329.GA12977@lenoch \
    --to=ladis@linux-mips.org \
    --cc=barebox@lists.infradead.org \
    /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