[1/4] mtd: nand: erase block before marking bad
diff mbox

Message ID 1326507110-10893-1-git-send-email-computersforpeace@gmail.com
State New, archived
Headers show

Commit Message

Brian Norris Jan. 14, 2012, 2:11 a.m. UTC
Many NAND flash systems (especially those with MLC NAND) cannot be
reliably written twice in a row. For instance, when marking a bad block,
the block may already have data written to it, and so we should attempt
to erase the block before writing a bad block marker to its OOB region.

We can ignore erase failures, since the block may be bad such that it
cannot be erased properly; we still attempt to write zeros to its spare
area.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
---
 drivers/mtd/nand/nand_base.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

Comments

Artem Bityutskiy Jan. 16, 2012, 12:07 p.m. UTC | #1
On Fri, 2012-01-13 at 18:11 -0800, Brian Norris wrote:
> Many NAND flash systems (especially those with MLC NAND) cannot be
> reliably written twice in a row. For instance, when marking a bad block,
> the block may already have data written to it, and so we should attempt
> to erase the block before writing a bad block marker to its OOB region.
> 
> We can ignore erase failures, since the block may be bad such that it
> cannot be erased properly; we still attempt to write zeros to its spare
> area.
> 
> Signed-off-by: Brian Norris <computersforpeace@gmail.com>

All four look good, pushed to l2-mtd.git, thanks.

What are your plans WRT marking blocks as bad both in the OOB and the
table?
Brian Norris Jan. 16, 2012, 7:18 p.m. UTC | #2
On Mon, Jan 16, 2012 at 4:07 AM, Artem Bityutskiy <dedekind1@gmail.com> wrote:
> On Fri, 2012-01-13 at 18:11 -0800, Brian Norris wrote:
>> Many NAND flash systems (especially those with MLC NAND) cannot be
>> reliably written twice in a row. For instance, when marking a bad block,
>> the block may already have data written to it, and so we should attempt
>> to erase the block before writing a bad block marker to its OOB region.
>
> All four look good, pushed to l2-mtd.git, thanks.

Sorry, but actually this "erase block before marking bad" patch is
incorrect. I didn't test this particular revision, and so I forgot
that the erase fails because the block is already marked as bad:

  nand_erase_nand: attempt to erase a bad block at page 0x...

I'll send a fixup patch on top of l2-mtd-2.6.

> What are your plans WRT marking blocks as bad both in the OOB and the
> table?

I don't have a 100% definite plan, but I've been trying to track the
comments/suggestions in the other thread. I'll reply to that thread so
we have the right reply-chain and CC list for discussion.

Brian

Patch
diff mbox

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 8a393f9..f0e768f 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -407,6 +407,14 @@  static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
 		ret = nand_update_bbt(mtd, ofs);
 	else {
 		struct mtd_oob_ops ops;
+		struct erase_info einfo;
+
+		/* Attempt erase before marking OOB */
+		memset(&einfo, 0, sizeof(einfo));
+		einfo.mtd = mtd;
+		einfo.addr = ofs;
+		einfo.len = 1 << chip->phys_erase_shift;
+		nand_erase_nand(mtd, &einfo, 0);
 
 		nand_get_device(chip, mtd, FL_WRITING);