mtd nand erase and bad block

Adrian Hunter adrian.hunter at intel.com
Thu May 31 09:28:12 EDT 2012


On 31/05/12 15:12, Matteo Facchinetti wrote:
> Hi,
> 
> I'm developing a mtd driver for a nand flash controller and I need help;
> I'm to the end of the work, and I have problems and dubts about bad block
> handling.
> 
> For test, I mark manually bad block byte on flash block.
> When I erase with flash_erase, all works and skip the bad block:
> :~# flash_erase /dev/mtd6 0 0
> Erasing 1024 Kibyte @ 100000 --  2 % complete flash_erase: Skipping bad
> block at 00200000
> Erasing 1024 Kibyte @ 2700000 -- 100 % complete
> 
> If I try to erase with -N parameter I read the following output:
> ~# flash_erase -N /dev/mtd6 0 0
> Erasing 1024 Kibnand_erase_nand: attempt to erase a bad block at page
> 0x00001600
> yte @ 200000 --  5 % complete libmtd: error!: MEMERASE64 ioctl failed for
> eraseblock 2 (mtd6)
>         error 5 (Input/output error)
> flash_erase: error!: /dev/mtd6: MTD Erase failure
>              error 5 (Input/output error)
> Erasing 1024 Kibyte @ 2700000 -- 100 % complete
> 
> I espected that with -N option, flash_erase should erase the hand-damaged
> block, recovering the usability of the block. Is it true?
> 
> What's going wrong?

The NAND driver has validation to prevent erasure of bad blocks.  Refer
nand_erase_nand() in drivers/mtd/nand/nand_base

		/* Check if we have a bad block, we do not erase bad blocks! */
		if (nand_block_checkbad(mtd, ((loff_t) page) <<
					chip->page_shift, 0, allowbbt)) {
			pr_warn("%s: attempt to erase a bad block at page 0x%08x\n",
				    __func__, page);
			instr->state = MTD_ERASE_FAILED;
			goto erase_exit;
		}




More information about the linux-mtd mailing list