2005-09-27 17:26:39 +07:00
|
|
|
/*
|
|
|
|
* linux/include/linux/mtd/bbm.h
|
|
|
|
*
|
|
|
|
* NAND family Bad Block Management (BBM) header file
|
|
|
|
* - Bad Block Table (BBT) implementation
|
|
|
|
*
|
2010-08-09 02:58:20 +07:00
|
|
|
* Copyright © 2005 Samsung Electronics
|
2005-09-27 17:26:39 +07:00
|
|
|
* Kyungmin Park <kyungmin.park@samsung.com>
|
|
|
|
*
|
2010-08-09 02:58:20 +07:00
|
|
|
* Copyright © 2000-2005
|
2005-09-27 17:26:39 +07:00
|
|
|
* Thomas Gleixner <tglx@linuxtronix.de>
|
|
|
|
*
|
2010-08-09 02:58:20 +07:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
2005-09-27 17:26:39 +07:00
|
|
|
*/
|
|
|
|
#ifndef __LINUX_MTD_BBM_H
|
|
|
|
#define __LINUX_MTD_BBM_H
|
|
|
|
|
|
|
|
/* The maximum number of NAND chips in an array */
|
|
|
|
#define NAND_MAX_CHIPS 8
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct nand_bbt_descr - bad block table descriptor
|
2009-09-21 04:28:04 +07:00
|
|
|
* @options: options for this descriptor
|
|
|
|
* @pages: the page(s) where we find the bbt, used with option BBT_ABSPAGE
|
|
|
|
* when bbt is searched, then we store the found bbts pages here.
|
|
|
|
* Its an array and supports up to 8 chips now
|
|
|
|
* @offs: offset of the pattern in the oob area of the page
|
|
|
|
* @veroffs: offset of the bbt version counter in the oob are of the page
|
|
|
|
* @version: version read from the bbt page during scan
|
|
|
|
* @len: length of the pattern, if 0 no pattern check is performed
|
|
|
|
* @maxblocks: maximum number of blocks to search for a bbt. This number of
|
|
|
|
* blocks is reserved at the end of the device where the tables are
|
|
|
|
* written.
|
|
|
|
* @reserved_block_code: if non-0, this pattern denotes a reserved (rather than
|
|
|
|
* bad) block in the stored bbt
|
|
|
|
* @pattern: pattern to identify bad block table or factory marked good /
|
|
|
|
* bad blocks, can be NULL, if len = 0
|
2005-09-27 17:26:39 +07:00
|
|
|
*
|
|
|
|
* Descriptor for the bad block table marker and the descriptor for the
|
|
|
|
* pattern which identifies good and bad blocks. The assumption is made
|
|
|
|
* that the pattern and the version count are always located in the oob area
|
|
|
|
* of the first block.
|
|
|
|
*/
|
|
|
|
struct nand_bbt_descr {
|
|
|
|
int options;
|
|
|
|
int pages[NAND_MAX_CHIPS];
|
|
|
|
int offs;
|
|
|
|
int veroffs;
|
|
|
|
uint8_t version[NAND_MAX_CHIPS];
|
|
|
|
int len;
|
|
|
|
int maxblocks;
|
|
|
|
int reserved_block_code;
|
|
|
|
uint8_t *pattern;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Options for the bad block table descriptors */
|
|
|
|
|
|
|
|
/* The number of bits used per block in the bbt on the device */
|
|
|
|
#define NAND_BBT_NRBITS_MSK 0x0000000F
|
|
|
|
#define NAND_BBT_1BIT 0x00000001
|
|
|
|
#define NAND_BBT_2BIT 0x00000002
|
|
|
|
#define NAND_BBT_4BIT 0x00000004
|
|
|
|
#define NAND_BBT_8BIT 0x00000008
|
|
|
|
/* The bad block table is in the last good block of the device */
|
|
|
|
#define NAND_BBT_LASTBLOCK 0x00000010
|
|
|
|
/* The bbt is at the given page, else we must scan for the bbt */
|
|
|
|
#define NAND_BBT_ABSPAGE 0x00000020
|
|
|
|
/* bbt is stored per chip on multichip devices */
|
|
|
|
#define NAND_BBT_PERCHIP 0x00000080
|
|
|
|
/* bbt has a version counter at offset veroffs */
|
|
|
|
#define NAND_BBT_VERSION 0x00000100
|
2010-10-02 02:37:37 +07:00
|
|
|
/* Create a bbt if none exists */
|
2005-09-27 17:26:39 +07:00
|
|
|
#define NAND_BBT_CREATE 0x00000200
|
2011-06-01 06:31:24 +07:00
|
|
|
/*
|
|
|
|
* Create an empty BBT with no vendor information. Vendor's information may be
|
|
|
|
* unavailable, for example, if the NAND controller has a different data and OOB
|
|
|
|
* layout or if this information is already purged. Must be used in conjunction
|
|
|
|
* with NAND_BBT_CREATE.
|
|
|
|
*/
|
2011-06-01 06:31:26 +07:00
|
|
|
#define NAND_BBT_CREATE_EMPTY 0x00000400
|
2005-09-27 17:26:39 +07:00
|
|
|
/* Search good / bad pattern through all pages of a block */
|
2011-06-01 06:31:26 +07:00
|
|
|
#define NAND_BBT_SCANALLPAGES 0x00000800
|
2005-09-27 17:26:39 +07:00
|
|
|
/* Scan block empty during good / bad block scan */
|
2011-06-01 06:31:26 +07:00
|
|
|
#define NAND_BBT_SCANEMPTY 0x00001000
|
2005-09-27 17:26:39 +07:00
|
|
|
/* Write bbt if neccecary */
|
2011-06-01 06:31:26 +07:00
|
|
|
#define NAND_BBT_WRITE 0x00002000
|
2005-09-27 17:26:39 +07:00
|
|
|
/* Read and write back block contents when writing bbt */
|
2011-06-01 06:31:26 +07:00
|
|
|
#define NAND_BBT_SAVECONTENT 0x00004000
|
2005-09-27 17:26:39 +07:00
|
|
|
/* Search good / bad pattern on the first and the second page */
|
2011-06-01 06:31:26 +07:00
|
|
|
#define NAND_BBT_SCAN2NDPAGE 0x00008000
|
2010-06-24 03:36:02 +07:00
|
|
|
/* Search good / bad pattern on the last page of the eraseblock */
|
2011-06-01 06:31:26 +07:00
|
|
|
#define NAND_BBT_SCANLASTPAGE 0x00010000
|
2011-06-01 06:31:22 +07:00
|
|
|
/*
|
|
|
|
* Use a flash based bad block table. By default, OOB identifier is saved in
|
|
|
|
* OOB area. This option is passed to the default bad block table function.
|
|
|
|
*/
|
2011-06-01 06:31:26 +07:00
|
|
|
#define NAND_BBT_USE_FLASH 0x00020000
|
2012-06-26 21:28:28 +07:00
|
|
|
/*
|
|
|
|
* Do not store flash based bad block table marker in the OOB area; store it
|
|
|
|
* in-band.
|
|
|
|
*/
|
2011-06-01 06:31:26 +07:00
|
|
|
#define NAND_BBT_NO_OOB 0x00040000
|
mtd: nand: write BBM to OOB even with flash-based BBT
Currently, the flash-based BBT implementation writes bad block data only
to its flash-based table and not to the OOB marker area. Then, as new bad
blocks are marked over time, the OOB markers become incomplete and the
flash-based table becomes the only source of current bad block
information. This becomes an obvious problem when, for example:
* bootloader cannot read the flash-based BBT format
* BBT is corrupted and the flash must be rescanned for bad
blocks; we want to remember bad blocks that were marked from Linux
So to keep the bad block markers in sync with the flash-based BBT, this
patch changes the default so that we write bad block markers to the proper
OOB area on each block in addition to flash-based BBT. Comments are
updated, expanded, and/or relocated as necessary.
The new flash-based BBT procedure for marking bad blocks:
(1) erase the affected block, to allow OOB marker to be written cleanly
(2) update in-memory BBT
(3) write bad block marker to OOB area of affected block
(4) update flash-based BBT
Note that we retain the first error encountered in (3) or (4), finish the
procedures, and dump the error in the end.
This should handle power cuts gracefully enough. (1) and (2) are mostly
harmless (note that (1) will not erase an already-recognized bad block).
The OOB and BBT may be "out of sync" if we experience power loss bewteen
(3) and (4), but we can reasonably expect that on next boot, subsequent
I/O operations will discover that the block should be marked bad again,
thus re-syncing the OOB and BBT.
Note that this is a change from the previous default flash-based BBT
behavior. If your system cannot support writing bad block markers to OOB,
use the new NAND_BBT_NO_OOB_BBM option (in combination with
NAND_BBT_USE_FLASH and NAND_BBT_NO_OOB).
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
2012-02-07 04:44:00 +07:00
|
|
|
/*
|
|
|
|
* Do not write new bad block markers to OOB; useful, e.g., when ECC covers
|
|
|
|
* entire spare area. Must be used with NAND_BBT_USE_FLASH.
|
|
|
|
*/
|
|
|
|
#define NAND_BBT_NO_OOB_BBM 0x00080000
|
2011-06-01 06:31:26 +07:00
|
|
|
|
2011-06-01 06:31:27 +07:00
|
|
|
/*
|
|
|
|
* Flag set by nand_create_default_bbt_descr(), marking that the nand_bbt_descr
|
|
|
|
* was allocated dynamicaly and must be freed in nand_release(). Has no meaning
|
|
|
|
* in nand_chip.bbt_options.
|
|
|
|
*/
|
2011-06-01 06:31:26 +07:00
|
|
|
#define NAND_BBT_DYNAMICSTRUCT 0x80000000
|
2005-09-27 17:26:39 +07:00
|
|
|
|
|
|
|
/* The maximum number of blocks to scan for a bbt */
|
|
|
|
#define NAND_BBT_SCAN_MAXBLOCKS 4
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Constants for oob configuration
|
|
|
|
*/
|
2009-09-21 04:28:04 +07:00
|
|
|
#define NAND_SMALL_BADBLOCK_POS 5
|
|
|
|
#define NAND_LARGE_BADBLOCK_POS 0
|
|
|
|
#define ONENAND_BADBLOCK_POS 0
|
2005-09-27 17:26:39 +07:00
|
|
|
|
2007-02-07 10:15:01 +07:00
|
|
|
/*
|
|
|
|
* Bad block scanning errors
|
|
|
|
*/
|
|
|
|
#define ONENAND_BBT_READ_ERROR 1
|
|
|
|
#define ONENAND_BBT_READ_ECC_ERROR 2
|
|
|
|
#define ONENAND_BBT_READ_FATAL_ERROR 4
|
|
|
|
|
2005-09-27 17:26:39 +07:00
|
|
|
/**
|
2006-06-29 11:48:38 +07:00
|
|
|
* struct bbm_info - [GENERIC] Bad Block Table data structure
|
|
|
|
* @bbt_erase_shift: [INTERN] number of address bits in a bbt entry
|
|
|
|
* @badblockpos: [INTERN] position of the bad block marker in the oob area
|
|
|
|
* @options: options for this descriptor
|
|
|
|
* @bbt: [INTERN] bad block table pointer
|
|
|
|
* @isbad_bbt: function to determine if a block is bad
|
|
|
|
* @badblock_pattern: [REPLACEABLE] bad block scan pattern used for
|
|
|
|
* initial bad block scan
|
|
|
|
* @priv: [OPTIONAL] pointer to private bbm date
|
2005-09-27 17:26:39 +07:00
|
|
|
*/
|
|
|
|
struct bbm_info {
|
|
|
|
int bbt_erase_shift;
|
|
|
|
int badblockpos;
|
|
|
|
int options;
|
|
|
|
|
|
|
|
uint8_t *bbt;
|
|
|
|
|
|
|
|
int (*isbad_bbt)(struct mtd_info *mtd, loff_t ofs, int allowbbt);
|
|
|
|
|
|
|
|
/* TODO Add more NAND specific fileds */
|
|
|
|
struct nand_bbt_descr *badblock_pattern;
|
|
|
|
|
|
|
|
void *priv;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* OneNAND BBT interface */
|
|
|
|
extern int onenand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd);
|
|
|
|
extern int onenand_default_bbt(struct mtd_info *mtd);
|
|
|
|
|
|
|
|
#endif /* __LINUX_MTD_BBM_H */
|