2 * linux/include/linux/mtd/bbm.h
4 * NAND family Bad Block Management (BBM) header file
5 * - Bad Block Table (BBT) implementation
7 * Copyright © 2005 Samsung Electronics
8 * Kyungmin Park <kyungmin.park@samsung.com>
10 * Copyright © 2000-2005
11 * Thomas Gleixner <tglx@linuxtronix.de>
13 * 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.
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.
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
28 #ifndef __LINUX_MTD_BBM_H
29 #define __LINUX_MTD_BBM_H
31 /* The maximum number of NAND chips in an array */
32 #ifndef CONFIG_SYS_NAND_MAX_CHIPS
33 #define CONFIG_SYS_NAND_MAX_CHIPS 1
37 * struct nand_bbt_descr - bad block table descriptor
38 * @options: options for this descriptor
39 * @pages: the page(s) where we find the bbt, used with option BBT_ABSPAGE
40 * when bbt is searched, then we store the found bbts pages here.
41 * Its an array and supports up to 8 chips now
42 * @offs: offset of the pattern in the oob area of the page
43 * @veroffs: offset of the bbt version counter in the oob are of the page
44 * @version: version read from the bbt page during scan
45 * @len: length of the pattern, if 0 no pattern check is performed
46 * @maxblocks: maximum number of blocks to search for a bbt. This number of
47 * blocks is reserved at the end of the device where the tables are
49 * @reserved_block_code: if non-0, this pattern denotes a reserved (rather than
50 * bad) block in the stored bbt
51 * @pattern: pattern to identify bad block table or factory marked good /
52 * bad blocks, can be NULL, if len = 0
54 * Descriptor for the bad block table marker and the descriptor for the
55 * pattern which identifies good and bad blocks. The assumption is made
56 * that the pattern and the version count are always located in the oob area
59 struct nand_bbt_descr {
61 int pages[CONFIG_SYS_NAND_MAX_CHIPS];
64 uint8_t version[CONFIG_SYS_NAND_MAX_CHIPS];
67 int reserved_block_code;
71 /* Options for the bad block table descriptors */
73 /* The number of bits used per block in the bbt on the device */
74 #define NAND_BBT_NRBITS_MSK 0x0000000F
75 #define NAND_BBT_1BIT 0x00000001
76 #define NAND_BBT_2BIT 0x00000002
77 #define NAND_BBT_4BIT 0x00000004
78 #define NAND_BBT_8BIT 0x00000008
79 /* The bad block table is in the last good block of the device */
80 #define NAND_BBT_LASTBLOCK 0x00000010
81 /* The bbt is at the given page, else we must scan for the bbt */
82 #define NAND_BBT_ABSPAGE 0x00000020
83 /* The bbt is at the given page, else we must scan for the bbt */
84 #define NAND_BBT_SEARCH 0x00000040
85 /* bbt is stored per chip on multichip devices */
86 #define NAND_BBT_PERCHIP 0x00000080
87 /* bbt has a version counter at offset veroffs */
88 #define NAND_BBT_VERSION 0x00000100
89 /* Create a bbt if none exists */
90 #define NAND_BBT_CREATE 0x00000200
91 /* Search good / bad pattern through all pages of a block */
92 #define NAND_BBT_SCANALLPAGES 0x00000400
93 /* Scan block empty during good / bad block scan */
94 #define NAND_BBT_SCANEMPTY 0x00000800
95 /* Write bbt if neccecary */
96 #define NAND_BBT_WRITE 0x00001000
97 /* Read and write back block contents when writing bbt */
98 #define NAND_BBT_SAVECONTENT 0x00002000
99 /* Search good / bad pattern on the first and the second page */
100 #define NAND_BBT_SCAN2NDPAGE 0x00004000
101 /* Search good / bad pattern on the last page of the eraseblock */
102 #define NAND_BBT_SCANLASTPAGE 0x00008000
103 /* Chip stores bad block marker on BOTH 1st and 6th bytes of OOB */
104 #define NAND_BBT_SCANBYTE1AND6 0x00100000
105 /* The nand_bbt_descr was created dynamicaly and must be freed */
106 #define NAND_BBT_DYNAMICSTRUCT 0x00200000
107 /* The bad block table does not OOB for marker */
108 #define NAND_BBT_NO_OOB 0x00400000
110 /* The maximum number of blocks to scan for a bbt */
111 #define NAND_BBT_SCAN_MAXBLOCKS 4
114 * Constants for oob configuration
116 #define NAND_SMALL_BADBLOCK_POS 5
117 #define NAND_LARGE_BADBLOCK_POS 0
118 #define ONENAND_BADBLOCK_POS 0
121 * Bad block scanning errors
123 #define ONENAND_BBT_READ_ERROR 1
124 #define ONENAND_BBT_READ_ECC_ERROR 2
125 #define ONENAND_BBT_READ_FATAL_ERROR 4
128 * struct bbm_info - [GENERIC] Bad Block Table data structure
129 * @bbt_erase_shift: [INTERN] number of address bits in a bbt entry
130 * @badblockpos: [INTERN] position of the bad block marker in the oob area
131 * @options: options for this descriptor
132 * @bbt: [INTERN] bad block table pointer
133 * @isbad_bbt: function to determine if a block is bad
134 * @badblock_pattern: [REPLACEABLE] bad block scan pattern used for
135 * initial bad block scan
136 * @priv: [OPTIONAL] pointer to private bbm date
145 int (*isbad_bbt)(struct mtd_info *mtd, loff_t ofs, int allowbbt);
147 /* TODO Add more NAND specific fileds */
148 struct nand_bbt_descr *badblock_pattern;
153 /* OneNAND BBT interface */
154 extern int onenand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd);
155 extern int onenand_default_bbt(struct mtd_info *mtd);
157 #endif /* __LINUX_MTD_BBM_H */