blob: 71292b1a86bc91629acd1c61bf9e4d83e97a65a3 [file] [log] [blame]
Kyungmin Parkd7e8ce12007-09-10 17:15:14 +09001/*
2 * linux/include/linux/mtd/bbm.h
3 *
4 * NAND family Bad Block Management (BBM) header file
5 * - Bad Block Table (BBT) implementation
6 *
7 * Copyright (c) 2005-2007 Samsung Electronics
8 * Kyungmin Park <kyungmin.park@samsung.com>
9 *
10 * Copyright (c) 2000-2005
11 * Thomas Gleixner <tglx@linuxtronix.de>
12 *
13 * This program is free software; you can redistribute it and/or modify
Christian Hitz2a8e0fc2011-10-12 09:32:02 +020014 * 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 Parkd7e8ce12007-09-10 17:15:14 +090027 */
28#ifndef __LINUX_MTD_BBM_H
29#define __LINUX_MTD_BBM_H
30
31/* The maximum number of NAND chips in an array */
Wolfgang Grandegger6c869632009-01-16 18:55:54 +010032#ifndef CONFIG_SYS_NAND_MAX_CHIPS
33#define CONFIG_SYS_NAND_MAX_CHIPS 1
Kyungmin Parkd7e8ce12007-09-10 17:15:14 +090034#endif
35
36/**
37 * struct nand_bbt_descr - bad block table descriptor
38 * @param options options for this descriptor
39 * @param pages the page(s) where we find the bbt, used with
Wolfgang Denk53677ef2008-05-20 16:00:29 +020040 * option BBT_ABSPAGE when bbt is searched,
41 * then we store the found bbts pages here.
Kyungmin Parkd7e8ce12007-09-10 17:15:14 +090042 * Its an array and supports up to 8 chips now
43 * @param offs offset of the pattern in the oob area of the page
44 * @param veroffs offset of the bbt version counter in the oob are of the page
45 * @param version version read from the bbt page during scan
46 * @param len length of the pattern, if 0 no pattern check is performed
47 * @param maxblocks maximum number of blocks to search for a bbt. This number of
48 * blocks is reserved at the end of the device
49 * where the tables are written.
50 * @param reserved_block_code if non-0, this pattern denotes a reserved
51 * (rather than bad) block in the stored bbt
52 * @param pattern pattern to identify bad block table or factory marked
53 * good / bad blocks, can be NULL, if len = 0
54 *
55 * Descriptor for the bad block table marker and the descriptor for the
56 * pattern which identifies good and bad blocks. The assumption is made
57 * that the pattern and the version count are always located in the oob area
58 * of the first block.
59 */
60struct nand_bbt_descr {
61 int options;
Wolfgang Grandegger6c869632009-01-16 18:55:54 +010062 int pages[CONFIG_SYS_NAND_MAX_CHIPS];
Kyungmin Parkd7e8ce12007-09-10 17:15:14 +090063 int offs;
64 int veroffs;
Wolfgang Grandegger6c869632009-01-16 18:55:54 +010065 uint8_t version[CONFIG_SYS_NAND_MAX_CHIPS];
Kyungmin Parkd7e8ce12007-09-10 17:15:14 +090066 int len;
67 int maxblocks;
68 int reserved_block_code;
69 uint8_t *pattern;
70};
71
72/* Options for the bad block table descriptors */
73
74/* The number of bits used per block in the bbt on the device */
75#define NAND_BBT_NRBITS_MSK 0x0000000F
76#define NAND_BBT_1BIT 0x00000001
77#define NAND_BBT_2BIT 0x00000002
78#define NAND_BBT_4BIT 0x00000004
79#define NAND_BBT_8BIT 0x00000008
80/* The bad block table is in the last good block of the device */
81#define NAND_BBT_LASTBLOCK 0x00000010
82/* The bbt is at the given page, else we must scan for the bbt */
83#define NAND_BBT_ABSPAGE 0x00000020
Kyungmin Parkd7e8ce12007-09-10 17:15:14 +090084/* bbt is stored per chip on multichip devices */
85#define NAND_BBT_PERCHIP 0x00000080
86/* bbt has a version counter at offset veroffs */
87#define NAND_BBT_VERSION 0x00000100
Christian Hitz2a8e0fc2011-10-12 09:32:02 +020088/* Create a bbt if none exists */
Kyungmin Parkd7e8ce12007-09-10 17:15:14 +090089#define NAND_BBT_CREATE 0x00000200
Sergey Lapindfe64e22013-01-14 03:46:50 +000090/*
91 * Create an empty BBT with no vendor information. Vendor's information may be
92 * unavailable, for example, if the NAND controller has a different data and OOB
93 * layout or if this information is already purged. Must be used in conjunction
94 * with NAND_BBT_CREATE.
95 */
96#define NAND_BBT_CREATE_EMPTY 0x00000400
Kyungmin Parkd7e8ce12007-09-10 17:15:14 +090097/* Search good / bad pattern through all pages of a block */
Sergey Lapindfe64e22013-01-14 03:46:50 +000098#define NAND_BBT_SCANALLPAGES 0x00000800
Kyungmin Parkd7e8ce12007-09-10 17:15:14 +090099/* Scan block empty during good / bad block scan */
Sergey Lapindfe64e22013-01-14 03:46:50 +0000100#define NAND_BBT_SCANEMPTY 0x00001000
Kyungmin Parkd7e8ce12007-09-10 17:15:14 +0900101/* Write bbt if neccecary */
Sergey Lapindfe64e22013-01-14 03:46:50 +0000102#define NAND_BBT_WRITE 0x00002000
Kyungmin Parkd7e8ce12007-09-10 17:15:14 +0900103/* Read and write back block contents when writing bbt */
Sergey Lapindfe64e22013-01-14 03:46:50 +0000104#define NAND_BBT_SAVECONTENT 0x00004000
Kyungmin Parkd7e8ce12007-09-10 17:15:14 +0900105/* Search good / bad pattern on the first and the second page */
Sergey Lapindfe64e22013-01-14 03:46:50 +0000106#define NAND_BBT_SCAN2NDPAGE 0x00008000
Christian Hitz2a8e0fc2011-10-12 09:32:02 +0200107/* Search good / bad pattern on the last page of the eraseblock */
Sergey Lapindfe64e22013-01-14 03:46:50 +0000108#define NAND_BBT_SCANLASTPAGE 0x00010000
109/*
110 * Use a flash based bad block table. By default, OOB identifier is saved in
111 * OOB area. This option is passed to the default bad block table function.
112 */
113#define NAND_BBT_USE_FLASH 0x00020000
114/*
115 * Do not store flash based bad block table marker in the OOB area; store it
116 * in-band.
117 */
118#define NAND_BBT_NO_OOB 0x00040000
119/*
120 * Do not write new bad block markers to OOB; useful, e.g., when ECC covers
121 * entire spare area. Must be used with NAND_BBT_USE_FLASH.
122 */
123#define NAND_BBT_NO_OOB_BBM 0x00080000
124
125/*
126 * Flag set by nand_create_default_bbt_descr(), marking that the nand_bbt_descr
127 * was allocated dynamicaly and must be freed in nand_release(). Has no meaning
128 * in nand_chip.bbt_options.
129 */
130#define NAND_BBT_DYNAMICSTRUCT 0x80000000
Kyungmin Parkd7e8ce12007-09-10 17:15:14 +0900131
132/* The maximum number of blocks to scan for a bbt */
133#define NAND_BBT_SCAN_MAXBLOCKS 4
134
135/*
136 * Constants for oob configuration
137 */
138#define ONENAND_BADBLOCK_POS 0
139
Kyungmin Parkbfd7f382008-08-19 08:42:53 +0900140/*
141 * Bad block scanning errors
142 */
143#define ONENAND_BBT_READ_ERROR 1
144#define ONENAND_BBT_READ_ECC_ERROR 2
145#define ONENAND_BBT_READ_FATAL_ERROR 4
146
Kyungmin Parkd7e8ce12007-09-10 17:15:14 +0900147/**
148 * struct bbt_info - [GENERIC] Bad Block Table data structure
149 * @param bbt_erase_shift [INTERN] number of address bits in a bbt entry
150 * @param badblockpos [INTERN] position of the bad block marker in the oob area
151 * @param bbt [INTERN] bad block table pointer
152 * @param badblock_pattern [REPLACEABLE] bad block scan pattern used for initial bad block scan
153 * @param priv [OPTIONAL] pointer to private bbm date
154 */
155struct bbm_info {
156 int bbt_erase_shift;
157 int badblockpos;
158 int options;
159
160 uint8_t *bbt;
161
162 int (*isbad_bbt) (struct mtd_info * mtd, loff_t ofs, int allowbbt);
163
164 /* TODO Add more NAND specific fileds */
165 struct nand_bbt_descr *badblock_pattern;
166
167 void *priv;
168};
169
170/* OneNAND BBT interface */
171extern int onenand_scan_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd);
172extern int onenand_default_bbt (struct mtd_info *mtd);
173
174#endif /* __LINUX_MTD_BBM_H */