Bad Block Management
Subsystems (2)
PATCH 1/1 Bad Block Management
Here come our patch and a short introduction for this patch. Any comments are welcome.
[MTD] [NAND] Bad Block Management
During the lifetime of a NAN device, additional Bad blocks may develop. The NAN devices have a Status Register that indicates whether an operation is successful or not. Additional Bad Blocks are identified when attempts to program or erase give errors in the Status Register. As the failure of a page program operation does not affect the data in other pages in the same block, most of the data within a failing block can be moved to a new block prior to marking the block bad. Blocks can be marked as bad and new blocks allocated using two general methods:
1. Skip Block method:
In the Skip Block method, the algorithm creates the Bad Block Table and when the target address corresponds to a Bad Block address, the data is stored in the next good block, skipping the Bad Block.
2. Reserve Block method:
The Reserve Block Method uses the same Bad Block Table format as the Skip Block Method. However, in the Reserve Block Method, Bad Blocks are not skipped but instead are replaced by a block from the reserved block area. This replacement is achieved by a layer of software which automatically remaps bad blocks to their corresponding replacement blocks. For this purpose, the Bad Block Management software creates two areas in NAN flash: the User Addressable Block Area and the Reserved Block Area as shown below.
This patch implements "reserve block method" on Motorola's SCUM-A11 platform mobile devices. With the Reserved Block method, any exist bad block or newly wearing out block will be replaced by reserved block while block pool still available . The maximum number of reserved blocks is set to be 10% of the total size of the NAN device. With the reserved block pool for bad block replacement, applications will see the NAN chip contains only contiguous good blocks; the physical bad blocks will be replaced with good blocks from the reserved pool in very low level and it is transparent to the upper level applications.
Best Regards
Motorola Mobile Device
Zhao Shengzhe
drivers/mtd/mtdpart.c +65 -1
@@ -1,12 +1,17 @@/* * Simple MTD partitioning layer * +* Copyright 2005 Motorola, Inc. * (C) 2000 Nicolas Pitre <[email protected]> * * This code is GPL * * 02-21-2002 Thomas Gleixner <[email protected]> * added support for read_oob, write_oob +* +* 05-06-2005 feature CONFIG_MTD_NAND_BBM added by Motorola, Inc. +* create the block reserve pool partition. +* verify the size and start address of the reserve pool partition. */ #include <linux/module.h>
@@ -19,6 +24,14 @@#include <linux/mtd/partitions.h> #include <linux/mtd/compatmac.h> +#if defined(CONFIG_MTD_NAND_BBM ) +/* +* reserved block offset +* the last NAND partition will be used as reserved blocks +*/ +unsigned long rsvdblock_offset; +#endif +/* Our partition linked list */ static LIST_HEAD (mtd_partitions);
@@ -163,6 +176,14 @@ len, retlen, buf); } +#ifdef CONFIG_MTD_NAND_BBM +static int part_block_replace (struct mtd_info *mtd,loff_t ofs,int lock) +{ +struct mtd_part *part =PART (mtd); +return part->master->block_replace (part->master, ofs + part->offset, lock); +} +#endif +static int part_write_oob (struct mtd_info *mtd,loff_t to,struct mtd_oob_ops *ops) {
@@ -349,6 +370,11 @@if (master->panic_write) slave->mtd.panic_write = part_panic_write; +#ifdef CONFIG_MTD_NAND_BBM +if (master->block_replace) + slave->mtd.block_replace = part_block_replace; +#endif +if (master->point && master->unpoint) { slave->mtd.point = part_point; slave->mtd.unpoint = part_unpoint;
@@ -465,6 +491,10 @@ } slave->mtd.ecclayout = master->ecclayout; +#ifndef CONFIG_MTD_NAND_BBM +/* Since we have bbt, there is no need to check here. +* block_isbad may use uninitialized rsvdblock_offset before 'rsv' partition is added. +*/ if (master->block_isbad) {uint32_t offs =0 ;
@@ -475,7 +505,7 @@ offs += slave->mtd.erasesize; } } - +#endif out_register:if (part->mtdp) {/* store the object pointer (caller may or may not register it*/
@@ -486,6 +516,40 @@add_mtd_device (&slave->mtd); slave->registered =1 ; } +#if defined(CONFIG_MTD_NAND_BBM ) +/* preset the reserved block offset */ +if (master->type ==MTD_NANDFLASH && i == nbparts-1 ) { +int bbmblocks =0 ; +int rsvdblocks =0 ; +int erasesize = master->erasesize; + +if (strcmp (slave->mtd.name,"rsv" )) +panic ("%s's \"rsv\" partition does not exist," +" NAND Bad Block cann't be handled!\n" , master->name); + + rsvdblock_offset = slave->offset; +printk (KERN_INFO "%s's capacity:%dMB, reserved block offset:0x%08x\n" , + master->name, (master->size/(1024 *1024 )), rsvdblock_offset); + +/* +* check the block number for the BBT/BBM reserved block pool... +* reserved block number for NAND flash should be 2% of the total blocks, +* plus: +* add extra 1 NFI, 2 BBT and 2 BBMs blocks. +* +* how to calculate BBMs: +* - 2 bytes for each block, +* - bbmblocks = ((totalblock*2)+(blocksize-1))/blocksize; +*/ + + bbmblocks = ((master->size/erasesize)*2 + (erasesize-1 )) / erasesize; + rsvdblocks = ((master->size/erasesize)/100 )*2 +3 + (bbmblocks*2 ); + +if (rsvdblock_offset != (master->size - (rsvdblocks*erasesize))) +panic ("%s:0x%08x's rsv partition must start at offset:0x%08x\n" , + master->name, master->size, master->size-(rsvdblocks*erasesize)); + } +#endif return slave; }
drivers/mtd/nand/Kconfig +17 -0
@@ -359,6 +359,23 @@ The simulator may simulate various NAND flash chips for the MTD nand layer. +config MTD_NAND_BBM + bool "NAND Bad Block Management support" + depends on MTD_NAND + default "n" + help + This enables the driver for the NAND flash to support Motorola Bad Block Management. + With this BBM feature, any exist bad block or newly wearing out block will be + replaced with good blocks from the reserved pool . applications will see the NAN + chip contains only contiguous good blocks and it is transparent to the upper level + applications. + +config MTD_NAND_BBM_DBG + bool "NAND Bad Block Management Debug support" + depends on MTD_NAND_BBM + help + This is for Bad Block Management development only + config MTD_NAND_PLATFORM tristate "Support for generic platform NAND driver" depends on MTD_NAND
drivers/mtd/nand/nand_base.c +328 -0
448 lines not on this page · raw message
drivers/mtd/nand/nand_bbt.c +759 -3
957 lines not on this page · raw message
include/linux/mtd/mtd.h +9 -0
@@ -1,7 +1,12 @@/* +* Copyright 2006 Motorola, Inc. * Copyright (C) 1999-2003 David Woodhouse <[email protected]> et al. * * Released under GPL +* +* ChangeLog: +* (mm-dd-yyyy) Author Comment +* 10-20-2006 Motorola feature CONFIG_MTD_NAND_BBM added. */ #ifndef __MTD_MTD_H__
@@ -200,6 +205,10 @@/* Bad block management functions */ int (*block_isbad) (struct mtd_info *mtd,loff_t ofs);int (*block_markbad) (struct mtd_info *mtd,loff_t ofs); +#ifdef CONFIG_MTD_NAND_BBM +/* get block replacement from reserve pool */ +int (*block_replace) (struct mtd_info *mtd,loff_t ofs,int lock); +#endif struct notifier_block reboot_notifier;/* default mode before reboot */
include/linux/mtd/nand.h +57 -0
93 lines not on this page · raw message
Quoted 1 line · Sheng-Zhe Zhao
Here come our patch and a short introduction for this patch. Any comments are welcome.
I tried to find it in the code but failed, I was wondering, how are bad blocks detected - I mean ones that develop over time, not factory-marked bad blocks.
Quoted 1 line
This patch implements "reserve block method" on Motorola's SCUM-A11 platform mobile devices. With the Reserved Block method, any exist bad
Why is it limited to this platform? The code looks generic enough.
/Ricard
--
Ricard Wolf Wanderlöf ricardw(at)axis.com
Axis Communications AB, Lund, Sweden www.axis.com
Phone +46 46 272 2016 Fax +46 46 13 61 30
See my comments below
-----Original Message-----
From: Ricard Wanderlof [mailto:[email protected]]
Sent: Wednesday, August 27, 2008 6:42 PM
To: Zhao Shengzhe-a18689
Cc: [email protected]
Subject: Re: [PATCH][MTD][NAND]Bad Block Management
Quoted 2 lines · Sheng-Zhe Zhao
Here come our patch and a short introduction for this patch. Any comments are welcome.
I tried to find it in the code but failed, I was wondering, how are bad blocks detected - I mean ones that develop over time, not factory-marked bad blocks.
[Shengzhe Zhao]
The bad blocks will be detected by low-level hardware driver. The NAN devices have a Status Register that indicates whether an operation is successful or not. Additional Bad Blocks are identified when attempts to program or erase give errors in the Status Register. Since our patch is in MTD layer, so you cannot find the codes for detecting bad blocks.
Quoted 3 lines
This patch implements "reserve block method" on Motorola's SCUM-A11 platform mobile devices. With the Reserved Block method, any exist bad
Why is it limited to this platform? The code looks generic enough.
[Shengzhe Zhao]
This patch is not limited to Moto platform only. Here we mentioned Moto platform just want to say it has been used in real product already.
/Ricard
--
Ricard Wolf Wanderlöf ricardw(at)axis.com
Axis Communications AB, Lund, Sweden www.axis.com
Phone +46 46 272 2016 Fax +46 46 13 61 30
Quoted 1 line · On Wed, 27 Aug 2008, Zhao Shengzhe-a18689 wrote:
The bad blocks will be detected by low-level hardware driver. The NAN devices have a Status Register that indicates whether an operation is successful or not. Additional Bad Blocks are identified when attempts to program or erase give errors in the Status Register. Since our patch is in MTD layer, so you cannot find the codes for detecting bad blocks.
OK.
When I ran some tests on an ST 256 MiB flash a while ago, I got the impression that by the time the status register indicates a problem, the block has been worn out (in the sense that subsequent reads are not reliable) for quite a while. So another approach would be to keep track of the amount of read errors encountered, together with the number of times the block has been rewritten due to excessive read errors. I'm not sure if UBI does this though if one wants that level of reliability.
/Ricard
--
Ricard Wolf Wanderlöf ricardw(at)axis.com
Axis Communications AB, Lund, Sweden www.axis.com
Phone +46 46 272 2016 Fax +46 46 13 61 30
2008/8/27 Sheng-Zhe Zhao <[email protected]>:
Quoted 5 lines
Here come our patch and a short introduction for this patch. Any comments are welcome.
[MTD] [NAND] Bad Block Management
During the lifetime of a NAN device, additional Bad blocks may develop. The NAN devices have a Status Register that indicates whether an operation is successful or not. Additional Bad Blocks are identified when attempts to program or erase give errors in the Status Register. As the failure of a page program operation does not affect the data in other pages in the same block, most of the data within a failing block can be moved to a new block prior to marking the block bad. Blocks can be marked as bad and new blocks allocated using two general methods:
Quoted 7 lines
1. Skip Block method:
In the Skip Block method, the algorithm creates the Bad Block Table and when the target address corresponds to a Bad Block address, the data is stored in the next good block, skipping the Bad Block.2. Reserve Block method:
The Reserve Block Method uses the same Bad Block Table format as the Skip Block Method. However, in the Reserve Block Method, Bad Blocks are not skipped but instead are replaced by a block from the reserved block area. This replacement is achieved by a layer of software which automatically remaps bad blocks to their corresponding replacement blocks. For this purpose, the Bad Block Management software creates two areas in NAN flash: the User Addressable Block Area and the Reserved Block Area as shown below.This patch implements "reserve block method" on Motorola's SCUM-A11 platform mobile devices. With the Reserved Block method, any exist bad block or newly wearing out block will be replaced by reserved block while block pool still available . The maximum number of reserved blocks is set to be 10% of the total size of the NAN device. With the reserved block pool for bad block replacement, applications will see the NAN chip contains only contiguous good blocks; the physical bad blocks will be replaced with good blocks from the reserved pool in very low level and it is transparent to the upper level applications.
Zhao,
Nice work. A few remarks:
I know there is a patch for the skip block method from Thomas Gleixner, but this was never submitted.
Anyway suppose you wanted to do Skip Block, I would suggest storing hte bad block table somewhere on flash (and not create it on the fly).
Wrt the 10% for Reserve Block: I would suggest making this a config parameter and allow the person to configure the kernel to choose the value he/she deems best for his system
Wrt the device wise approach: I think I would prefer if I could say per partition if I wanted to use this (and thus have the mapping done per partition). That way filesystems that do their own bad block handling can do it the way they want to.Now it seems a little bit double work to have bad block handling in both the filesystem and in the mtd layer.
Frans.
Quoted 6 lines · Frans Meulenbroeks
Wrt the device wise approach: I think I would prefer if I could say per partition if I wanted to use this (and thus have the mapping done per partition). That way filesystems that do their own bad block handling can do it the way they want to.Now it seems a little bit double work to have bad block handling in both the filesystem and in the mtd layer.
I don't believe it lives in the low-level MTD drivers. The _users_ (file system code, translation layers, etc.) of devices should handle this as they see fit (although we can provide _library_ code for them to use if they want to). I don't think it lives in the NAND driver though.
Signature · 2 lines
David Woodhouse Open Source Technology Centre [email protected] Intel Corporation
2008/8/27 David Woodhouse <[email protected]>:
Quoted 8 lines · Frans Meulenbroeks
Quoted 6 lines
Wrt the device wise approach: I think I would prefer if I could say per partition if I wanted to use this (and thus have the mapping done per partition). That way filesystems that do their own bad block handling can do it the way they want to.Now it seems a little bit double work to have bad block handling in both the filesystem and in the mtd layer.
Quoted 5 lines
I don't believe it lives in the low-level MTD drivers. The _users_ (file system code, translation layers, etc.) of devices should handle this as they see fit (although we can provide _library_ code for them to use if they want to). I don't think it lives in the NAND driver though.
David,
As this is reply to my msg, is this directed to me?
If so: yes I am definitely in favour of modularisation, separation of concerns etc (that is if it does not hamper performance too much). Then again: as far as I can see it the patch from Zhao is a patch in the driver level.
Wrt bad block handling etc. Guess this can be done in ftl or so (I'm not really an expert here).
Issue is that ftl seems quite complicated and seems to add quite some overhead. (and pardon me if my understanding of ftl is completely off).
Anyway, a good layering would probably be:
filesystem
optional bad block handling layer
block driver
Frans