blob: 3bf8f954b642581c271a7236e8e1b46f6820b015 [file] [log] [blame]
Kyungmin Park87590e22005-09-27 11:26:39 +01001/*
2 * linux/include/linux/mtd/bbm.h
3 *
4 * NAND family Bad Block Management (BBM) header file
5 * - Bad Block Table (BBT) implementation
6 *
David Woodhousea1452a32010-08-08 20:58:20 +01007 * Copyright © 2005 Samsung Electronics
Kyungmin Park87590e22005-09-27 11:26:39 +01008 * Kyungmin Park <kyungmin.park@samsung.com>
9 *
David Woodhousea1452a32010-08-08 20:58:20 +010010 * Copyright © 2000-2005
Kyungmin Park87590e22005-09-27 11:26:39 +010011 * Thomas Gleixner <tglx@linuxtronix.de>
12 *
David Woodhousea1452a32010-08-08 20:58:20 +010013 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 *
Kyungmin Park87590e22005-09-27 11:26:39 +010027 */
28#ifndef __LINUX_MTD_BBM_H
29#define __LINUX_MTD_BBM_H
30
31/* The maximum number of NAND chips in an array */
32#define NAND_MAX_CHIPS 8
33
34/**
35 * struct nand_bbt_descr - bad block table descriptor
Alessandro Rubinic62d81b2009-09-20 23:28:04 +020036 * @options: options for this descriptor
37 * @pages: the page(s) where we find the bbt, used with option BBT_ABSPAGE
38 * when bbt is searched, then we store the found bbts pages here.
39 * Its an array and supports up to 8 chips now
40 * @offs: offset of the pattern in the oob area of the page
41 * @veroffs: offset of the bbt version counter in the oob are of the page
42 * @version: version read from the bbt page during scan
43 * @len: length of the pattern, if 0 no pattern check is performed
44 * @maxblocks: maximum number of blocks to search for a bbt. This number of
45 * blocks is reserved at the end of the device where the tables are
46 * written.
47 * @reserved_block_code: if non-0, this pattern denotes a reserved (rather than
48 * bad) block in the stored bbt
49 * @pattern: pattern to identify bad block table or factory marked good /
50 * bad blocks, can be NULL, if len = 0
Kyungmin Park87590e22005-09-27 11:26:39 +010051 *
52 * Descriptor for the bad block table marker and the descriptor for the
53 * pattern which identifies good and bad blocks. The assumption is made
54 * that the pattern and the version count are always located in the oob area
55 * of the first block.
56 */
57struct nand_bbt_descr {
58 int options;
59 int pages[NAND_MAX_CHIPS];
60 int offs;
61 int veroffs;
62 uint8_t version[NAND_MAX_CHIPS];
63 int len;
64 int maxblocks;
65 int reserved_block_code;
66 uint8_t *pattern;
67};
68
69/* Options for the bad block table descriptors */
70
71/* The number of bits used per block in the bbt on the device */
72#define NAND_BBT_NRBITS_MSK 0x0000000F
73#define NAND_BBT_1BIT 0x00000001
74#define NAND_BBT_2BIT 0x00000002
75#define NAND_BBT_4BIT 0x00000004
76#define NAND_BBT_8BIT 0x00000008
77/* The bad block table is in the last good block of the device */
78#define NAND_BBT_LASTBLOCK 0x00000010
79/* The bbt is at the given page, else we must scan for the bbt */
80#define NAND_BBT_ABSPAGE 0x00000020
Kyungmin Park87590e22005-09-27 11:26:39 +010081/* bbt is stored per chip on multichip devices */
82#define NAND_BBT_PERCHIP 0x00000080
83/* bbt has a version counter at offset veroffs */
84#define NAND_BBT_VERSION 0x00000100
Sebastian Andrzej Siewior453281a2010-10-01 21:37:37 +020085/* Create a bbt if none exists */
Kyungmin Park87590e22005-09-27 11:26:39 +010086#define NAND_BBT_CREATE 0x00000200
Brian Norrisb8f80682011-05-31 16:31:24 -070087/*
88 * Create an empty BBT with no vendor information. Vendor's information may be
89 * unavailable, for example, if the NAND controller has a different data and OOB
90 * layout or if this information is already purged. Must be used in conjunction
91 * with NAND_BBT_CREATE.
92 */
Brian Norrisb4dc53e2011-05-31 16:31:26 -070093#define NAND_BBT_CREATE_EMPTY 0x00000400
Kyungmin Park87590e22005-09-27 11:26:39 +010094/* Write bbt if neccecary */
Brian Norrisb4dc53e2011-05-31 16:31:26 -070095#define NAND_BBT_WRITE 0x00002000
Kyungmin Park87590e22005-09-27 11:26:39 +010096/* Read and write back block contents when writing bbt */
Brian Norrisb4dc53e2011-05-31 16:31:26 -070097#define NAND_BBT_SAVECONTENT 0x00004000
Kyungmin Park87590e22005-09-27 11:26:39 +010098/* Search good / bad pattern on the first and the second page */
Brian Norrisb4dc53e2011-05-31 16:31:26 -070099#define NAND_BBT_SCAN2NDPAGE 0x00008000
Brian Norris30fe8112010-06-23 13:36:02 -0700100/* Search good / bad pattern on the last page of the eraseblock */
Brian Norrisb4dc53e2011-05-31 16:31:26 -0700101#define NAND_BBT_SCANLASTPAGE 0x00010000
Brian Norrisa40f7342011-05-31 16:31:22 -0700102/*
103 * Use a flash based bad block table. By default, OOB identifier is saved in
104 * OOB area. This option is passed to the default bad block table function.
105 */
Brian Norrisb4dc53e2011-05-31 16:31:26 -0700106#define NAND_BBT_USE_FLASH 0x00020000
Shmulik Ladkanif3bae3d2012-06-26 17:28:28 +0300107/*
108 * Do not store flash based bad block table marker in the OOB area; store it
109 * in-band.
110 */
Brian Norrisb4dc53e2011-05-31 16:31:26 -0700111#define NAND_BBT_NO_OOB 0x00040000
Brian Norrise2414f42012-02-06 13:44:00 -0800112/*
113 * Do not write new bad block markers to OOB; useful, e.g., when ECC covers
114 * entire spare area. Must be used with NAND_BBT_USE_FLASH.
115 */
116#define NAND_BBT_NO_OOB_BBM 0x00080000
Brian Norrisb4dc53e2011-05-31 16:31:26 -0700117
Brian Norris9eeff822011-05-31 16:31:27 -0700118/*
119 * Flag set by nand_create_default_bbt_descr(), marking that the nand_bbt_descr
120 * was allocated dynamicaly and must be freed in nand_release(). Has no meaning
121 * in nand_chip.bbt_options.
122 */
Brian Norrisb4dc53e2011-05-31 16:31:26 -0700123#define NAND_BBT_DYNAMICSTRUCT 0x80000000
Kyungmin Park87590e22005-09-27 11:26:39 +0100124
125/* The maximum number of blocks to scan for a bbt */
126#define NAND_BBT_SCAN_MAXBLOCKS 4
127
128/*
129 * Constants for oob configuration
130 */
Alessandro Rubinic62d81b2009-09-20 23:28:04 +0200131#define NAND_SMALL_BADBLOCK_POS 5
132#define NAND_LARGE_BADBLOCK_POS 0
133#define ONENAND_BADBLOCK_POS 0
Kyungmin Park87590e22005-09-27 11:26:39 +0100134
Kyungmin Park211ac752007-02-07 12:15:01 +0900135/*
136 * Bad block scanning errors
137 */
138#define ONENAND_BBT_READ_ERROR 1
139#define ONENAND_BBT_READ_ECC_ERROR 2
140#define ONENAND_BBT_READ_FATAL_ERROR 4
141
Kyungmin Park87590e22005-09-27 11:26:39 +0100142/**
Randy Dunlapea9b6dc2006-06-28 21:48:38 -0700143 * struct bbm_info - [GENERIC] Bad Block Table data structure
144 * @bbt_erase_shift: [INTERN] number of address bits in a bbt entry
145 * @badblockpos: [INTERN] position of the bad block marker in the oob area
146 * @options: options for this descriptor
147 * @bbt: [INTERN] bad block table pointer
148 * @isbad_bbt: function to determine if a block is bad
149 * @badblock_pattern: [REPLACEABLE] bad block scan pattern used for
150 * initial bad block scan
151 * @priv: [OPTIONAL] pointer to private bbm date
Kyungmin Park87590e22005-09-27 11:26:39 +0100152 */
153struct bbm_info {
154 int bbt_erase_shift;
155 int badblockpos;
156 int options;
157
158 uint8_t *bbt;
159
160 int (*isbad_bbt)(struct mtd_info *mtd, loff_t ofs, int allowbbt);
161
162 /* TODO Add more NAND specific fileds */
163 struct nand_bbt_descr *badblock_pattern;
164
165 void *priv;
166};
167
168/* OneNAND BBT interface */
Kyungmin Park87590e22005-09-27 11:26:39 +0100169extern int onenand_default_bbt(struct mtd_info *mtd);
170
171#endif /* __LINUX_MTD_BBM_H */