include: replace linux/module.h with "struct module" wherever possible
[linux-2.6/next.git] / drivers / mtd / nand / nand_bbt.c
blob4165857752ca267de3efef0a917eec42dc484b00
1 /*
2 * drivers/mtd/nand_bbt.c
4 * Overview:
5 * Bad block table support for the NAND driver
7 * Copyright (C) 2004 Thomas Gleixner (tglx@linutronix.de)
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
13 * Description:
15 * When nand_scan_bbt is called, then it tries to find the bad block table
16 * depending on the options in the BBT descriptor(s). If no flash based BBT
17 * (NAND_USE_FLASH_BBT) is specified then the device is scanned for factory
18 * marked good / bad blocks. This information is used to create a memory BBT.
19 * Once a new bad block is discovered then the "factory" information is updated
20 * on the device.
21 * If a flash based BBT is specified then the function first tries to find the
22 * BBT on flash. If a BBT is found then the contents are read and the memory
23 * based BBT is created. If a mirrored BBT is selected then the mirror is
24 * searched too and the versions are compared. If the mirror has a greater
25 * version number than the mirror BBT is used to build the memory based BBT.
26 * If the tables are not versioned, then we "or" the bad block information.
27 * If one of the BBTs is out of date or does not exist it is (re)created.
28 * If no BBT exists at all then the device is scanned for factory marked
29 * good / bad blocks and the bad block tables are created.
31 * For manufacturer created BBTs like the one found on M-SYS DOC devices
32 * the BBT is searched and read but never created
34 * The auto generated bad block table is located in the last good blocks
35 * of the device. The table is mirrored, so it can be updated eventually.
36 * The table is marked in the OOB area with an ident pattern and a version
37 * number which indicates which of both tables is more up to date. If the NAND
38 * controller needs the complete OOB area for the ECC information then the
39 * option NAND_USE_FLASH_BBT_NO_OOB should be used: it moves the ident pattern
40 * and the version byte into the data area and the OOB area will remain
41 * untouched.
43 * The table uses 2 bits per block
44 * 11b: block is good
45 * 00b: block is factory marked bad
46 * 01b, 10b: block is marked bad due to wear
48 * The memory bad block table uses the following scheme:
49 * 00b: block is good
50 * 01b: block is marked bad due to wear
51 * 10b: block is reserved (to protect the bbt area)
52 * 11b: block is factory marked bad
54 * Multichip devices like DOC store the bad block info per floor.
56 * Following assumptions are made:
57 * - bbts start at a page boundary, if autolocated on a block boundary
58 * - the space necessary for a bbt in FLASH does not exceed a block boundary
62 #include <linux/slab.h>
63 #include <linux/types.h>
64 #include <linux/mtd/mtd.h>
65 #include <linux/mtd/nand.h>
66 #include <linux/mtd/nand_ecc.h>
67 #include <linux/bitops.h>
68 #include <linux/delay.h>
69 #include <linux/vmalloc.h>
70 #include <linux/export.h>
72 static int check_pattern_no_oob(uint8_t *buf, struct nand_bbt_descr *td)
74 int ret;
76 ret = memcmp(buf, td->pattern, td->len);
77 if (!ret)
78 return ret;
79 return -1;
82 /**
83 * check_pattern - [GENERIC] check if a pattern is in the buffer
84 * @buf: the buffer to search
85 * @len: the length of buffer to search
86 * @paglen: the pagelength
87 * @td: search pattern descriptor
89 * Check for a pattern at the given place. Used to search bad block
90 * tables and good / bad block identifiers.
91 * If the SCAN_EMPTY option is set then check, if all bytes except the
92 * pattern area contain 0xff
95 static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_descr *td)
97 int i, end = 0;
98 uint8_t *p = buf;
100 if (td->options & NAND_BBT_NO_OOB)
101 return check_pattern_no_oob(buf, td);
103 end = paglen + td->offs;
104 if (td->options & NAND_BBT_SCANEMPTY) {
105 for (i = 0; i < end; i++) {
106 if (p[i] != 0xff)
107 return -1;
110 p += end;
112 /* Compare the pattern */
113 for (i = 0; i < td->len; i++) {
114 if (p[i] != td->pattern[i])
115 return -1;
118 /* Check both positions 1 and 6 for pattern? */
119 if (td->options & NAND_BBT_SCANBYTE1AND6) {
120 if (td->options & NAND_BBT_SCANEMPTY) {
121 p += td->len;
122 end += NAND_SMALL_BADBLOCK_POS - td->offs;
123 /* Check region between positions 1 and 6 */
124 for (i = 0; i < NAND_SMALL_BADBLOCK_POS - td->offs - td->len;
125 i++) {
126 if (*p++ != 0xff)
127 return -1;
130 else {
131 p += NAND_SMALL_BADBLOCK_POS - td->offs;
133 /* Compare the pattern */
134 for (i = 0; i < td->len; i++) {
135 if (p[i] != td->pattern[i])
136 return -1;
140 if (td->options & NAND_BBT_SCANEMPTY) {
141 p += td->len;
142 end += td->len;
143 for (i = end; i < len; i++) {
144 if (*p++ != 0xff)
145 return -1;
148 return 0;
152 * check_short_pattern - [GENERIC] check if a pattern is in the buffer
153 * @buf: the buffer to search
154 * @td: search pattern descriptor
156 * Check for a pattern at the given place. Used to search bad block
157 * tables and good / bad block identifiers. Same as check_pattern, but
158 * no optional empty check
161 static int check_short_pattern(uint8_t *buf, struct nand_bbt_descr *td)
163 int i;
164 uint8_t *p = buf;
166 /* Compare the pattern */
167 for (i = 0; i < td->len; i++) {
168 if (p[td->offs + i] != td->pattern[i])
169 return -1;
171 /* Need to check location 1 AND 6? */
172 if (td->options & NAND_BBT_SCANBYTE1AND6) {
173 for (i = 0; i < td->len; i++) {
174 if (p[NAND_SMALL_BADBLOCK_POS + i] != td->pattern[i])
175 return -1;
178 return 0;
182 * add_marker_len - compute the length of the marker in data area
183 * @td: BBT descriptor used for computation
185 * The length will be 0 if the markeris located in OOB area.
187 static u32 add_marker_len(struct nand_bbt_descr *td)
189 u32 len;
191 if (!(td->options & NAND_BBT_NO_OOB))
192 return 0;
194 len = td->len;
195 if (td->options & NAND_BBT_VERSION)
196 len++;
197 return len;
201 * read_bbt - [GENERIC] Read the bad block table starting from page
202 * @mtd: MTD device structure
203 * @buf: temporary buffer
204 * @page: the starting page
205 * @num: the number of bbt descriptors to read
206 * @td: the bbt describtion table
207 * @offs: offset in the memory table
209 * Read the bad block table starting from page.
212 static int read_bbt(struct mtd_info *mtd, uint8_t *buf, int page, int num,
213 struct nand_bbt_descr *td, int offs)
215 int res, i, j, act = 0;
216 struct nand_chip *this = mtd->priv;
217 size_t retlen, len, totlen;
218 loff_t from;
219 int bits = td->options & NAND_BBT_NRBITS_MSK;
220 uint8_t msk = (uint8_t) ((1 << bits) - 1);
221 u32 marker_len;
222 int reserved_block_code = td->reserved_block_code;
224 totlen = (num * bits) >> 3;
225 marker_len = add_marker_len(td);
226 from = ((loff_t) page) << this->page_shift;
228 while (totlen) {
229 len = min(totlen, (size_t) (1 << this->bbt_erase_shift));
230 if (marker_len) {
232 * In case the BBT marker is not in the OOB area it
233 * will be just in the first page.
235 len -= marker_len;
236 from += marker_len;
237 marker_len = 0;
239 res = mtd->read(mtd, from, len, &retlen, buf);
240 if (res < 0) {
241 if (retlen != len) {
242 printk(KERN_INFO "nand_bbt: Error reading bad block table\n");
243 return res;
245 printk(KERN_WARNING "nand_bbt: ECC error while reading bad block table\n");
248 /* Analyse data */
249 for (i = 0; i < len; i++) {
250 uint8_t dat = buf[i];
251 for (j = 0; j < 8; j += bits, act += 2) {
252 uint8_t tmp = (dat >> j) & msk;
253 if (tmp == msk)
254 continue;
255 if (reserved_block_code && (tmp == reserved_block_code)) {
256 printk(KERN_DEBUG "nand_read_bbt: Reserved block at 0x%012llx\n",
257 (loff_t)((offs << 2) + (act >> 1)) << this->bbt_erase_shift);
258 this->bbt[offs + (act >> 3)] |= 0x2 << (act & 0x06);
259 mtd->ecc_stats.bbtblocks++;
260 continue;
262 /* Leave it for now, if its matured we can move this
263 * message to MTD_DEBUG_LEVEL0 */
264 printk(KERN_DEBUG "nand_read_bbt: Bad block at 0x%012llx\n",
265 (loff_t)((offs << 2) + (act >> 1)) << this->bbt_erase_shift);
266 /* Factory marked bad or worn out ? */
267 if (tmp == 0)
268 this->bbt[offs + (act >> 3)] |= 0x3 << (act & 0x06);
269 else
270 this->bbt[offs + (act >> 3)] |= 0x1 << (act & 0x06);
271 mtd->ecc_stats.badblocks++;
274 totlen -= len;
275 from += len;
277 return 0;
281 * read_abs_bbt - [GENERIC] Read the bad block table starting at a given page
282 * @mtd: MTD device structure
283 * @buf: temporary buffer
284 * @td: descriptor for the bad block table
285 * @chip: read the table for a specific chip, -1 read all chips.
286 * Applies only if NAND_BBT_PERCHIP option is set
288 * Read the bad block table for all chips starting at a given page
289 * We assume that the bbt bits are in consecutive order.
291 static int read_abs_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td, int chip)
293 struct nand_chip *this = mtd->priv;
294 int res = 0, i;
296 if (td->options & NAND_BBT_PERCHIP) {
297 int offs = 0;
298 for (i = 0; i < this->numchips; i++) {
299 if (chip == -1 || chip == i)
300 res = read_bbt(mtd, buf, td->pages[i],
301 this->chipsize >> this->bbt_erase_shift,
302 td, offs);
303 if (res)
304 return res;
305 offs += this->chipsize >> (this->bbt_erase_shift + 2);
307 } else {
308 res = read_bbt(mtd, buf, td->pages[0],
309 mtd->size >> this->bbt_erase_shift, td, 0);
310 if (res)
311 return res;
313 return 0;
317 * BBT marker is in the first page, no OOB.
319 static int scan_read_raw_data(struct mtd_info *mtd, uint8_t *buf, loff_t offs,
320 struct nand_bbt_descr *td)
322 size_t retlen;
323 size_t len;
325 len = td->len;
326 if (td->options & NAND_BBT_VERSION)
327 len++;
329 return mtd->read(mtd, offs, len, &retlen, buf);
333 * Scan read raw data from flash
335 static int scan_read_raw_oob(struct mtd_info *mtd, uint8_t *buf, loff_t offs,
336 size_t len)
338 struct mtd_oob_ops ops;
339 int res;
341 ops.mode = MTD_OOB_RAW;
342 ops.ooboffs = 0;
343 ops.ooblen = mtd->oobsize;
346 while (len > 0) {
347 if (len <= mtd->writesize) {
348 ops.oobbuf = buf + len;
349 ops.datbuf = buf;
350 ops.len = len;
351 return mtd->read_oob(mtd, offs, &ops);
352 } else {
353 ops.oobbuf = buf + mtd->writesize;
354 ops.datbuf = buf;
355 ops.len = mtd->writesize;
356 res = mtd->read_oob(mtd, offs, &ops);
358 if (res)
359 return res;
362 buf += mtd->oobsize + mtd->writesize;
363 len -= mtd->writesize;
365 return 0;
368 static int scan_read_raw(struct mtd_info *mtd, uint8_t *buf, loff_t offs,
369 size_t len, struct nand_bbt_descr *td)
371 if (td->options & NAND_BBT_NO_OOB)
372 return scan_read_raw_data(mtd, buf, offs, td);
373 else
374 return scan_read_raw_oob(mtd, buf, offs, len);
378 * Scan write data with oob to flash
380 static int scan_write_bbt(struct mtd_info *mtd, loff_t offs, size_t len,
381 uint8_t *buf, uint8_t *oob)
383 struct mtd_oob_ops ops;
385 ops.mode = MTD_OOB_PLACE;
386 ops.ooboffs = 0;
387 ops.ooblen = mtd->oobsize;
388 ops.datbuf = buf;
389 ops.oobbuf = oob;
390 ops.len = len;
392 return mtd->write_oob(mtd, offs, &ops);
395 static u32 bbt_get_ver_offs(struct mtd_info *mtd, struct nand_bbt_descr *td)
397 u32 ver_offs = td->veroffs;
399 if (!(td->options & NAND_BBT_NO_OOB))
400 ver_offs += mtd->writesize;
401 return ver_offs;
405 * read_abs_bbts - [GENERIC] Read the bad block table(s) for all chips starting at a given page
406 * @mtd: MTD device structure
407 * @buf: temporary buffer
408 * @td: descriptor for the bad block table
409 * @md: descriptor for the bad block table mirror
411 * Read the bad block table(s) for all chips starting at a given page
412 * We assume that the bbt bits are in consecutive order.
415 static int read_abs_bbts(struct mtd_info *mtd, uint8_t *buf,
416 struct nand_bbt_descr *td, struct nand_bbt_descr *md)
418 struct nand_chip *this = mtd->priv;
420 /* Read the primary version, if available */
421 if (td->options & NAND_BBT_VERSION) {
422 scan_read_raw(mtd, buf, (loff_t)td->pages[0] << this->page_shift,
423 mtd->writesize, td);
424 td->version[0] = buf[bbt_get_ver_offs(mtd, td)];
425 printk(KERN_DEBUG "Bad block table at page %d, version 0x%02X\n",
426 td->pages[0], td->version[0]);
429 /* Read the mirror version, if available */
430 if (md && (md->options & NAND_BBT_VERSION)) {
431 scan_read_raw(mtd, buf, (loff_t)md->pages[0] << this->page_shift,
432 mtd->writesize, td);
433 md->version[0] = buf[bbt_get_ver_offs(mtd, md)];
434 printk(KERN_DEBUG "Bad block table at page %d, version 0x%02X\n",
435 md->pages[0], md->version[0]);
437 return 1;
441 * Scan a given block full
443 static int scan_block_full(struct mtd_info *mtd, struct nand_bbt_descr *bd,
444 loff_t offs, uint8_t *buf, size_t readlen,
445 int scanlen, int len)
447 int ret, j;
449 ret = scan_read_raw_oob(mtd, buf, offs, readlen);
450 if (ret)
451 return ret;
453 for (j = 0; j < len; j++, buf += scanlen) {
454 if (check_pattern(buf, scanlen, mtd->writesize, bd))
455 return 1;
457 return 0;
461 * Scan a given block partially
463 static int scan_block_fast(struct mtd_info *mtd, struct nand_bbt_descr *bd,
464 loff_t offs, uint8_t *buf, int len)
466 struct mtd_oob_ops ops;
467 int j, ret;
469 ops.ooblen = mtd->oobsize;
470 ops.oobbuf = buf;
471 ops.ooboffs = 0;
472 ops.datbuf = NULL;
473 ops.mode = MTD_OOB_PLACE;
475 for (j = 0; j < len; j++) {
477 * Read the full oob until read_oob is fixed to
478 * handle single byte reads for 16 bit
479 * buswidth
481 ret = mtd->read_oob(mtd, offs, &ops);
482 if (ret)
483 return ret;
485 if (check_short_pattern(buf, bd))
486 return 1;
488 offs += mtd->writesize;
490 return 0;
494 * create_bbt - [GENERIC] Create a bad block table by scanning the device
495 * @mtd: MTD device structure
496 * @buf: temporary buffer
497 * @bd: descriptor for the good/bad block search pattern
498 * @chip: create the table for a specific chip, -1 read all chips.
499 * Applies only if NAND_BBT_PERCHIP option is set
501 * Create a bad block table by scanning the device
502 * for the given good/bad block identify pattern
504 static int create_bbt(struct mtd_info *mtd, uint8_t *buf,
505 struct nand_bbt_descr *bd, int chip)
507 struct nand_chip *this = mtd->priv;
508 int i, numblocks, len, scanlen;
509 int startblock;
510 loff_t from;
511 size_t readlen;
513 printk(KERN_INFO "Scanning device for bad blocks\n");
515 if (bd->options & NAND_BBT_SCANALLPAGES)
516 len = 1 << (this->bbt_erase_shift - this->page_shift);
517 else if (bd->options & NAND_BBT_SCAN2NDPAGE)
518 len = 2;
519 else
520 len = 1;
522 if (!(bd->options & NAND_BBT_SCANEMPTY)) {
523 /* We need only read few bytes from the OOB area */
524 scanlen = 0;
525 readlen = bd->len;
526 } else {
527 /* Full page content should be read */
528 scanlen = mtd->writesize + mtd->oobsize;
529 readlen = len * mtd->writesize;
532 if (chip == -1) {
533 /* Note that numblocks is 2 * (real numblocks) here, see i+=2
534 * below as it makes shifting and masking less painful */
535 numblocks = mtd->size >> (this->bbt_erase_shift - 1);
536 startblock = 0;
537 from = 0;
538 } else {
539 if (chip >= this->numchips) {
540 printk(KERN_WARNING "create_bbt(): chipnr (%d) > available chips (%d)\n",
541 chip + 1, this->numchips);
542 return -EINVAL;
544 numblocks = this->chipsize >> (this->bbt_erase_shift - 1);
545 startblock = chip * numblocks;
546 numblocks += startblock;
547 from = (loff_t)startblock << (this->bbt_erase_shift - 1);
550 if (this->options & NAND_BBT_SCANLASTPAGE)
551 from += mtd->erasesize - (mtd->writesize * len);
553 for (i = startblock; i < numblocks;) {
554 int ret;
556 BUG_ON(bd->options & NAND_BBT_NO_OOB);
558 if (bd->options & NAND_BBT_SCANALLPAGES)
559 ret = scan_block_full(mtd, bd, from, buf, readlen,
560 scanlen, len);
561 else
562 ret = scan_block_fast(mtd, bd, from, buf, len);
564 if (ret < 0)
565 return ret;
567 if (ret) {
568 this->bbt[i >> 3] |= 0x03 << (i & 0x6);
569 printk(KERN_WARNING "Bad eraseblock %d at 0x%012llx\n",
570 i >> 1, (unsigned long long)from);
571 mtd->ecc_stats.badblocks++;
574 i += 2;
575 from += (1 << this->bbt_erase_shift);
577 return 0;
581 * search_bbt - [GENERIC] scan the device for a specific bad block table
582 * @mtd: MTD device structure
583 * @buf: temporary buffer
584 * @td: descriptor for the bad block table
586 * Read the bad block table by searching for a given ident pattern.
587 * Search is preformed either from the beginning up or from the end of
588 * the device downwards. The search starts always at the start of a
589 * block.
590 * If the option NAND_BBT_PERCHIP is given, each chip is searched
591 * for a bbt, which contains the bad block information of this chip.
592 * This is necessary to provide support for certain DOC devices.
594 * The bbt ident pattern resides in the oob area of the first page
595 * in a block.
597 static int search_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td)
599 struct nand_chip *this = mtd->priv;
600 int i, chips;
601 int bits, startblock, block, dir;
602 int scanlen = mtd->writesize + mtd->oobsize;
603 int bbtblocks;
604 int blocktopage = this->bbt_erase_shift - this->page_shift;
606 /* Search direction top -> down ? */
607 if (td->options & NAND_BBT_LASTBLOCK) {
608 startblock = (mtd->size >> this->bbt_erase_shift) - 1;
609 dir = -1;
610 } else {
611 startblock = 0;
612 dir = 1;
615 /* Do we have a bbt per chip ? */
616 if (td->options & NAND_BBT_PERCHIP) {
617 chips = this->numchips;
618 bbtblocks = this->chipsize >> this->bbt_erase_shift;
619 startblock &= bbtblocks - 1;
620 } else {
621 chips = 1;
622 bbtblocks = mtd->size >> this->bbt_erase_shift;
625 /* Number of bits for each erase block in the bbt */
626 bits = td->options & NAND_BBT_NRBITS_MSK;
628 for (i = 0; i < chips; i++) {
629 /* Reset version information */
630 td->version[i] = 0;
631 td->pages[i] = -1;
632 /* Scan the maximum number of blocks */
633 for (block = 0; block < td->maxblocks; block++) {
635 int actblock = startblock + dir * block;
636 loff_t offs = (loff_t)actblock << this->bbt_erase_shift;
638 /* Read first page */
639 scan_read_raw(mtd, buf, offs, mtd->writesize, td);
640 if (!check_pattern(buf, scanlen, mtd->writesize, td)) {
641 td->pages[i] = actblock << blocktopage;
642 if (td->options & NAND_BBT_VERSION) {
643 offs = bbt_get_ver_offs(mtd, td);
644 td->version[i] = buf[offs];
646 break;
649 startblock += this->chipsize >> this->bbt_erase_shift;
651 /* Check, if we found a bbt for each requested chip */
652 for (i = 0; i < chips; i++) {
653 if (td->pages[i] == -1)
654 printk(KERN_WARNING "Bad block table not found for chip %d\n", i);
655 else
656 printk(KERN_DEBUG "Bad block table found at page %d, version 0x%02X\n", td->pages[i],
657 td->version[i]);
659 return 0;
663 * search_read_bbts - [GENERIC] scan the device for bad block table(s)
664 * @mtd: MTD device structure
665 * @buf: temporary buffer
666 * @td: descriptor for the bad block table
667 * @md: descriptor for the bad block table mirror
669 * Search and read the bad block table(s)
671 static int search_read_bbts(struct mtd_info *mtd, uint8_t * buf, struct nand_bbt_descr *td, struct nand_bbt_descr *md)
673 /* Search the primary table */
674 search_bbt(mtd, buf, td);
676 /* Search the mirror table */
677 if (md)
678 search_bbt(mtd, buf, md);
680 /* Force result check */
681 return 1;
685 * write_bbt - [GENERIC] (Re)write the bad block table
687 * @mtd: MTD device structure
688 * @buf: temporary buffer
689 * @td: descriptor for the bad block table
690 * @md: descriptor for the bad block table mirror
691 * @chipsel: selector for a specific chip, -1 for all
693 * (Re)write the bad block table
696 static int write_bbt(struct mtd_info *mtd, uint8_t *buf,
697 struct nand_bbt_descr *td, struct nand_bbt_descr *md,
698 int chipsel)
700 struct nand_chip *this = mtd->priv;
701 struct erase_info einfo;
702 int i, j, res, chip = 0;
703 int bits, startblock, dir, page, offs, numblocks, sft, sftmsk;
704 int nrchips, bbtoffs, pageoffs, ooboffs;
705 uint8_t msk[4];
706 uint8_t rcode = td->reserved_block_code;
707 size_t retlen, len = 0;
708 loff_t to;
709 struct mtd_oob_ops ops;
711 ops.ooblen = mtd->oobsize;
712 ops.ooboffs = 0;
713 ops.datbuf = NULL;
714 ops.mode = MTD_OOB_PLACE;
716 if (!rcode)
717 rcode = 0xff;
718 /* Write bad block table per chip rather than per device ? */
719 if (td->options & NAND_BBT_PERCHIP) {
720 numblocks = (int)(this->chipsize >> this->bbt_erase_shift);
721 /* Full device write or specific chip ? */
722 if (chipsel == -1) {
723 nrchips = this->numchips;
724 } else {
725 nrchips = chipsel + 1;
726 chip = chipsel;
728 } else {
729 numblocks = (int)(mtd->size >> this->bbt_erase_shift);
730 nrchips = 1;
733 /* Loop through the chips */
734 for (; chip < nrchips; chip++) {
736 /* There was already a version of the table, reuse the page
737 * This applies for absolute placement too, as we have the
738 * page nr. in td->pages.
740 if (td->pages[chip] != -1) {
741 page = td->pages[chip];
742 goto write;
745 /* Automatic placement of the bad block table */
746 /* Search direction top -> down ? */
747 if (td->options & NAND_BBT_LASTBLOCK) {
748 startblock = numblocks * (chip + 1) - 1;
749 dir = -1;
750 } else {
751 startblock = chip * numblocks;
752 dir = 1;
755 for (i = 0; i < td->maxblocks; i++) {
756 int block = startblock + dir * i;
757 /* Check, if the block is bad */
758 switch ((this->bbt[block >> 2] >>
759 (2 * (block & 0x03))) & 0x03) {
760 case 0x01:
761 case 0x03:
762 continue;
764 page = block <<
765 (this->bbt_erase_shift - this->page_shift);
766 /* Check, if the block is used by the mirror table */
767 if (!md || md->pages[chip] != page)
768 goto write;
770 printk(KERN_ERR "No space left to write bad block table\n");
771 return -ENOSPC;
772 write:
774 /* Set up shift count and masks for the flash table */
775 bits = td->options & NAND_BBT_NRBITS_MSK;
776 msk[2] = ~rcode;
777 switch (bits) {
778 case 1: sft = 3; sftmsk = 0x07; msk[0] = 0x00; msk[1] = 0x01;
779 msk[3] = 0x01;
780 break;
781 case 2: sft = 2; sftmsk = 0x06; msk[0] = 0x00; msk[1] = 0x01;
782 msk[3] = 0x03;
783 break;
784 case 4: sft = 1; sftmsk = 0x04; msk[0] = 0x00; msk[1] = 0x0C;
785 msk[3] = 0x0f;
786 break;
787 case 8: sft = 0; sftmsk = 0x00; msk[0] = 0x00; msk[1] = 0x0F;
788 msk[3] = 0xff;
789 break;
790 default: return -EINVAL;
793 bbtoffs = chip * (numblocks >> 2);
795 to = ((loff_t) page) << this->page_shift;
797 /* Must we save the block contents ? */
798 if (td->options & NAND_BBT_SAVECONTENT) {
799 /* Make it block aligned */
800 to &= ~((loff_t) ((1 << this->bbt_erase_shift) - 1));
801 len = 1 << this->bbt_erase_shift;
802 res = mtd->read(mtd, to, len, &retlen, buf);
803 if (res < 0) {
804 if (retlen != len) {
805 printk(KERN_INFO "nand_bbt: Error "
806 "reading block for writing "
807 "the bad block table\n");
808 return res;
810 printk(KERN_WARNING "nand_bbt: ECC error "
811 "while reading block for writing "
812 "bad block table\n");
814 /* Read oob data */
815 ops.ooblen = (len >> this->page_shift) * mtd->oobsize;
816 ops.oobbuf = &buf[len];
817 res = mtd->read_oob(mtd, to + mtd->writesize, &ops);
818 if (res < 0 || ops.oobretlen != ops.ooblen)
819 goto outerr;
821 /* Calc the byte offset in the buffer */
822 pageoffs = page - (int)(to >> this->page_shift);
823 offs = pageoffs << this->page_shift;
824 /* Preset the bbt area with 0xff */
825 memset(&buf[offs], 0xff, (size_t) (numblocks >> sft));
826 ooboffs = len + (pageoffs * mtd->oobsize);
828 } else if (td->options & NAND_BBT_NO_OOB) {
829 ooboffs = 0;
830 offs = td->len;
831 /* the version byte */
832 if (td->options & NAND_BBT_VERSION)
833 offs++;
834 /* Calc length */
835 len = (size_t) (numblocks >> sft);
836 len += offs;
837 /* Make it page aligned ! */
838 len = ALIGN(len, mtd->writesize);
839 /* Preset the buffer with 0xff */
840 memset(buf, 0xff, len);
841 /* Pattern is located at the begin of first page */
842 memcpy(buf, td->pattern, td->len);
843 } else {
844 /* Calc length */
845 len = (size_t) (numblocks >> sft);
846 /* Make it page aligned ! */
847 len = ALIGN(len, mtd->writesize);
848 /* Preset the buffer with 0xff */
849 memset(buf, 0xff, len +
850 (len >> this->page_shift)* mtd->oobsize);
851 offs = 0;
852 ooboffs = len;
853 /* Pattern is located in oob area of first page */
854 memcpy(&buf[ooboffs + td->offs], td->pattern, td->len);
857 if (td->options & NAND_BBT_VERSION)
858 buf[ooboffs + td->veroffs] = td->version[chip];
860 /* walk through the memory table */
861 for (i = 0; i < numblocks;) {
862 uint8_t dat;
863 dat = this->bbt[bbtoffs + (i >> 2)];
864 for (j = 0; j < 4; j++, i++) {
865 int sftcnt = (i << (3 - sft)) & sftmsk;
866 /* Do not store the reserved bbt blocks ! */
867 buf[offs + (i >> sft)] &=
868 ~(msk[dat & 0x03] << sftcnt);
869 dat >>= 2;
873 memset(&einfo, 0, sizeof(einfo));
874 einfo.mtd = mtd;
875 einfo.addr = to;
876 einfo.len = 1 << this->bbt_erase_shift;
877 res = nand_erase_nand(mtd, &einfo, 1);
878 if (res < 0)
879 goto outerr;
881 res = scan_write_bbt(mtd, to, len, buf,
882 td->options & NAND_BBT_NO_OOB ? NULL :
883 &buf[len]);
884 if (res < 0)
885 goto outerr;
887 printk(KERN_DEBUG "Bad block table written to 0x%012llx, version "
888 "0x%02X\n", (unsigned long long)to, td->version[chip]);
890 /* Mark it as used */
891 td->pages[chip] = page;
893 return 0;
895 outerr:
896 printk(KERN_WARNING
897 "nand_bbt: Error while writing bad block table %d\n", res);
898 return res;
902 * nand_memory_bbt - [GENERIC] create a memory based bad block table
903 * @mtd: MTD device structure
904 * @bd: descriptor for the good/bad block search pattern
906 * The function creates a memory based bbt by scanning the device
907 * for manufacturer / software marked good / bad blocks
909 static inline int nand_memory_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
911 struct nand_chip *this = mtd->priv;
913 bd->options &= ~NAND_BBT_SCANEMPTY;
914 return create_bbt(mtd, this->buffers->databuf, bd, -1);
918 * check_create - [GENERIC] create and write bbt(s) if necessary
919 * @mtd: MTD device structure
920 * @buf: temporary buffer
921 * @bd: descriptor for the good/bad block search pattern
923 * The function checks the results of the previous call to read_bbt
924 * and creates / updates the bbt(s) if necessary
925 * Creation is necessary if no bbt was found for the chip/device
926 * Update is necessary if one of the tables is missing or the
927 * version nr. of one table is less than the other
929 static int check_create(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *bd)
931 int i, chips, writeops, chipsel, res;
932 struct nand_chip *this = mtd->priv;
933 struct nand_bbt_descr *td = this->bbt_td;
934 struct nand_bbt_descr *md = this->bbt_md;
935 struct nand_bbt_descr *rd, *rd2;
937 /* Do we have a bbt per chip ? */
938 if (td->options & NAND_BBT_PERCHIP)
939 chips = this->numchips;
940 else
941 chips = 1;
943 for (i = 0; i < chips; i++) {
944 writeops = 0;
945 rd = NULL;
946 rd2 = NULL;
947 /* Per chip or per device ? */
948 chipsel = (td->options & NAND_BBT_PERCHIP) ? i : -1;
949 /* Mirrored table available ? */
950 if (md) {
951 if (td->pages[i] == -1 && md->pages[i] == -1) {
952 writeops = 0x03;
953 goto create;
956 if (td->pages[i] == -1) {
957 rd = md;
958 td->version[i] = md->version[i];
959 writeops = 1;
960 goto writecheck;
963 if (md->pages[i] == -1) {
964 rd = td;
965 md->version[i] = td->version[i];
966 writeops = 2;
967 goto writecheck;
970 if (td->version[i] == md->version[i]) {
971 rd = td;
972 if (!(td->options & NAND_BBT_VERSION))
973 rd2 = md;
974 goto writecheck;
977 if (((int8_t) (td->version[i] - md->version[i])) > 0) {
978 rd = td;
979 md->version[i] = td->version[i];
980 writeops = 2;
981 } else {
982 rd = md;
983 td->version[i] = md->version[i];
984 writeops = 1;
987 goto writecheck;
989 } else {
990 if (td->pages[i] == -1) {
991 writeops = 0x01;
992 goto create;
994 rd = td;
995 goto writecheck;
997 create:
998 /* Create the bad block table by scanning the device ? */
999 if (!(td->options & NAND_BBT_CREATE))
1000 continue;
1002 /* Create the table in memory by scanning the chip(s) */
1003 if (!(this->options & NAND_CREATE_EMPTY_BBT))
1004 create_bbt(mtd, buf, bd, chipsel);
1006 td->version[i] = 1;
1007 if (md)
1008 md->version[i] = 1;
1009 writecheck:
1010 /* read back first ? */
1011 if (rd)
1012 read_abs_bbt(mtd, buf, rd, chipsel);
1013 /* If they weren't versioned, read both. */
1014 if (rd2)
1015 read_abs_bbt(mtd, buf, rd2, chipsel);
1017 /* Write the bad block table to the device ? */
1018 if ((writeops & 0x01) && (td->options & NAND_BBT_WRITE)) {
1019 res = write_bbt(mtd, buf, td, md, chipsel);
1020 if (res < 0)
1021 return res;
1024 /* Write the mirror bad block table to the device ? */
1025 if ((writeops & 0x02) && md && (md->options & NAND_BBT_WRITE)) {
1026 res = write_bbt(mtd, buf, md, td, chipsel);
1027 if (res < 0)
1028 return res;
1031 return 0;
1035 * mark_bbt_regions - [GENERIC] mark the bad block table regions
1036 * @mtd: MTD device structure
1037 * @td: bad block table descriptor
1039 * The bad block table regions are marked as "bad" to prevent
1040 * accidental erasures / writes. The regions are identified by
1041 * the mark 0x02.
1043 static void mark_bbt_region(struct mtd_info *mtd, struct nand_bbt_descr *td)
1045 struct nand_chip *this = mtd->priv;
1046 int i, j, chips, block, nrblocks, update;
1047 uint8_t oldval, newval;
1049 /* Do we have a bbt per chip ? */
1050 if (td->options & NAND_BBT_PERCHIP) {
1051 chips = this->numchips;
1052 nrblocks = (int)(this->chipsize >> this->bbt_erase_shift);
1053 } else {
1054 chips = 1;
1055 nrblocks = (int)(mtd->size >> this->bbt_erase_shift);
1058 for (i = 0; i < chips; i++) {
1059 if ((td->options & NAND_BBT_ABSPAGE) ||
1060 !(td->options & NAND_BBT_WRITE)) {
1061 if (td->pages[i] == -1)
1062 continue;
1063 block = td->pages[i] >> (this->bbt_erase_shift - this->page_shift);
1064 block <<= 1;
1065 oldval = this->bbt[(block >> 3)];
1066 newval = oldval | (0x2 << (block & 0x06));
1067 this->bbt[(block >> 3)] = newval;
1068 if ((oldval != newval) && td->reserved_block_code)
1069 nand_update_bbt(mtd, (loff_t)block << (this->bbt_erase_shift - 1));
1070 continue;
1072 update = 0;
1073 if (td->options & NAND_BBT_LASTBLOCK)
1074 block = ((i + 1) * nrblocks) - td->maxblocks;
1075 else
1076 block = i * nrblocks;
1077 block <<= 1;
1078 for (j = 0; j < td->maxblocks; j++) {
1079 oldval = this->bbt[(block >> 3)];
1080 newval = oldval | (0x2 << (block & 0x06));
1081 this->bbt[(block >> 3)] = newval;
1082 if (oldval != newval)
1083 update = 1;
1084 block += 2;
1086 /* If we want reserved blocks to be recorded to flash, and some
1087 new ones have been marked, then we need to update the stored
1088 bbts. This should only happen once. */
1089 if (update && td->reserved_block_code)
1090 nand_update_bbt(mtd, (loff_t)(block - 2) << (this->bbt_erase_shift - 1));
1095 * verify_bbt_descr - verify the bad block description
1096 * @mtd: MTD device structure
1097 * @bd: the table to verify
1099 * This functions performs a few sanity checks on the bad block description
1100 * table.
1102 static void verify_bbt_descr(struct mtd_info *mtd, struct nand_bbt_descr *bd)
1104 struct nand_chip *this = mtd->priv;
1105 u32 pattern_len;
1106 u32 bits;
1107 u32 table_size;
1109 if (!bd)
1110 return;
1112 pattern_len = bd->len;
1113 bits = bd->options & NAND_BBT_NRBITS_MSK;
1115 BUG_ON((this->options & NAND_USE_FLASH_BBT_NO_OOB) &&
1116 !(this->options & NAND_USE_FLASH_BBT));
1117 BUG_ON(!bits);
1119 if (bd->options & NAND_BBT_VERSION)
1120 pattern_len++;
1122 if (bd->options & NAND_BBT_NO_OOB) {
1123 BUG_ON(!(this->options & NAND_USE_FLASH_BBT));
1124 BUG_ON(!(this->options & NAND_USE_FLASH_BBT_NO_OOB));
1125 BUG_ON(bd->offs);
1126 if (bd->options & NAND_BBT_VERSION)
1127 BUG_ON(bd->veroffs != bd->len);
1128 BUG_ON(bd->options & NAND_BBT_SAVECONTENT);
1131 if (bd->options & NAND_BBT_PERCHIP)
1132 table_size = this->chipsize >> this->bbt_erase_shift;
1133 else
1134 table_size = mtd->size >> this->bbt_erase_shift;
1135 table_size >>= 3;
1136 table_size *= bits;
1137 if (bd->options & NAND_BBT_NO_OOB)
1138 table_size += pattern_len;
1139 BUG_ON(table_size > (1 << this->bbt_erase_shift));
1143 * nand_scan_bbt - [NAND Interface] scan, find, read and maybe create bad block table(s)
1144 * @mtd: MTD device structure
1145 * @bd: descriptor for the good/bad block search pattern
1147 * The function checks, if a bad block table(s) is/are already
1148 * available. If not it scans the device for manufacturer
1149 * marked good / bad blocks and writes the bad block table(s) to
1150 * the selected place.
1152 * The bad block table memory is allocated here. It must be freed
1153 * by calling the nand_free_bbt function.
1156 int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
1158 struct nand_chip *this = mtd->priv;
1159 int len, res = 0;
1160 uint8_t *buf;
1161 struct nand_bbt_descr *td = this->bbt_td;
1162 struct nand_bbt_descr *md = this->bbt_md;
1164 len = mtd->size >> (this->bbt_erase_shift + 2);
1165 /* Allocate memory (2bit per block) and clear the memory bad block table */
1166 this->bbt = kzalloc(len, GFP_KERNEL);
1167 if (!this->bbt) {
1168 printk(KERN_ERR "nand_scan_bbt: Out of memory\n");
1169 return -ENOMEM;
1172 /* If no primary table decriptor is given, scan the device
1173 * to build a memory based bad block table
1175 if (!td) {
1176 if ((res = nand_memory_bbt(mtd, bd))) {
1177 printk(KERN_ERR "nand_bbt: Can't scan flash and build the RAM-based BBT\n");
1178 kfree(this->bbt);
1179 this->bbt = NULL;
1181 return res;
1183 verify_bbt_descr(mtd, td);
1184 verify_bbt_descr(mtd, md);
1186 /* Allocate a temporary buffer for one eraseblock incl. oob */
1187 len = (1 << this->bbt_erase_shift);
1188 len += (len >> this->page_shift) * mtd->oobsize;
1189 buf = vmalloc(len);
1190 if (!buf) {
1191 printk(KERN_ERR "nand_bbt: Out of memory\n");
1192 kfree(this->bbt);
1193 this->bbt = NULL;
1194 return -ENOMEM;
1197 /* Is the bbt at a given page ? */
1198 if (td->options & NAND_BBT_ABSPAGE) {
1199 res = read_abs_bbts(mtd, buf, td, md);
1200 } else {
1201 /* Search the bad block table using a pattern in oob */
1202 res = search_read_bbts(mtd, buf, td, md);
1205 if (res)
1206 res = check_create(mtd, buf, bd);
1208 /* Prevent the bbt regions from erasing / writing */
1209 mark_bbt_region(mtd, td);
1210 if (md)
1211 mark_bbt_region(mtd, md);
1213 vfree(buf);
1214 return res;
1218 * nand_update_bbt - [NAND Interface] update bad block table(s)
1219 * @mtd: MTD device structure
1220 * @offs: the offset of the newly marked block
1222 * The function updates the bad block table(s)
1224 int nand_update_bbt(struct mtd_info *mtd, loff_t offs)
1226 struct nand_chip *this = mtd->priv;
1227 int len, res = 0, writeops = 0;
1228 int chip, chipsel;
1229 uint8_t *buf;
1230 struct nand_bbt_descr *td = this->bbt_td;
1231 struct nand_bbt_descr *md = this->bbt_md;
1233 if (!this->bbt || !td)
1234 return -EINVAL;
1236 /* Allocate a temporary buffer for one eraseblock incl. oob */
1237 len = (1 << this->bbt_erase_shift);
1238 len += (len >> this->page_shift) * mtd->oobsize;
1239 buf = kmalloc(len, GFP_KERNEL);
1240 if (!buf) {
1241 printk(KERN_ERR "nand_update_bbt: Out of memory\n");
1242 return -ENOMEM;
1245 writeops = md != NULL ? 0x03 : 0x01;
1247 /* Do we have a bbt per chip ? */
1248 if (td->options & NAND_BBT_PERCHIP) {
1249 chip = (int)(offs >> this->chip_shift);
1250 chipsel = chip;
1251 } else {
1252 chip = 0;
1253 chipsel = -1;
1256 td->version[chip]++;
1257 if (md)
1258 md->version[chip]++;
1260 /* Write the bad block table to the device ? */
1261 if ((writeops & 0x01) && (td->options & NAND_BBT_WRITE)) {
1262 res = write_bbt(mtd, buf, td, md, chipsel);
1263 if (res < 0)
1264 goto out;
1266 /* Write the mirror bad block table to the device ? */
1267 if ((writeops & 0x02) && md && (md->options & NAND_BBT_WRITE)) {
1268 res = write_bbt(mtd, buf, md, td, chipsel);
1271 out:
1272 kfree(buf);
1273 return res;
1276 /* Define some generic bad / good block scan pattern which are used
1277 * while scanning a device for factory marked good / bad blocks. */
1278 static uint8_t scan_ff_pattern[] = { 0xff, 0xff };
1280 static uint8_t scan_agand_pattern[] = { 0x1C, 0x71, 0xC7, 0x1C, 0x71, 0xC7 };
1282 static struct nand_bbt_descr agand_flashbased = {
1283 .options = NAND_BBT_SCANEMPTY | NAND_BBT_SCANALLPAGES,
1284 .offs = 0x20,
1285 .len = 6,
1286 .pattern = scan_agand_pattern
1289 /* Generic flash bbt decriptors
1291 static uint8_t bbt_pattern[] = {'B', 'b', 't', '0' };
1292 static uint8_t mirror_pattern[] = {'1', 't', 'b', 'B' };
1294 static struct nand_bbt_descr bbt_main_descr = {
1295 .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
1296 | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP,
1297 .offs = 8,
1298 .len = 4,
1299 .veroffs = 12,
1300 .maxblocks = 4,
1301 .pattern = bbt_pattern
1304 static struct nand_bbt_descr bbt_mirror_descr = {
1305 .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
1306 | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP,
1307 .offs = 8,
1308 .len = 4,
1309 .veroffs = 12,
1310 .maxblocks = 4,
1311 .pattern = mirror_pattern
1314 static struct nand_bbt_descr bbt_main_no_bbt_descr = {
1315 .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
1316 | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP
1317 | NAND_BBT_NO_OOB,
1318 .len = 4,
1319 .veroffs = 4,
1320 .maxblocks = 4,
1321 .pattern = bbt_pattern
1324 static struct nand_bbt_descr bbt_mirror_no_bbt_descr = {
1325 .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
1326 | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP
1327 | NAND_BBT_NO_OOB,
1328 .len = 4,
1329 .veroffs = 4,
1330 .maxblocks = 4,
1331 .pattern = mirror_pattern
1334 #define BBT_SCAN_OPTIONS (NAND_BBT_SCANLASTPAGE | NAND_BBT_SCAN2NDPAGE | \
1335 NAND_BBT_SCANBYTE1AND6)
1337 * nand_create_default_bbt_descr - [Internal] Creates a BBT descriptor structure
1338 * @this: NAND chip to create descriptor for
1340 * This function allocates and initializes a nand_bbt_descr for BBM detection
1341 * based on the properties of "this". The new descriptor is stored in
1342 * this->badblock_pattern. Thus, this->badblock_pattern should be NULL when
1343 * passed to this function.
1346 static int nand_create_default_bbt_descr(struct nand_chip *this)
1348 struct nand_bbt_descr *bd;
1349 if (this->badblock_pattern) {
1350 printk(KERN_WARNING "BBT descr already allocated; not replacing.\n");
1351 return -EINVAL;
1353 bd = kzalloc(sizeof(*bd), GFP_KERNEL);
1354 if (!bd) {
1355 printk(KERN_ERR "nand_create_default_bbt_descr: Out of memory\n");
1356 return -ENOMEM;
1358 bd->options = this->options & BBT_SCAN_OPTIONS;
1359 bd->offs = this->badblockpos;
1360 bd->len = (this->options & NAND_BUSWIDTH_16) ? 2 : 1;
1361 bd->pattern = scan_ff_pattern;
1362 bd->options |= NAND_BBT_DYNAMICSTRUCT;
1363 this->badblock_pattern = bd;
1364 return 0;
1368 * nand_default_bbt - [NAND Interface] Select a default bad block table for the device
1369 * @mtd: MTD device structure
1371 * This function selects the default bad block table
1372 * support for the device and calls the nand_scan_bbt function
1375 int nand_default_bbt(struct mtd_info *mtd)
1377 struct nand_chip *this = mtd->priv;
1379 /* Default for AG-AND. We must use a flash based
1380 * bad block table as the devices have factory marked
1381 * _good_ blocks. Erasing those blocks leads to loss
1382 * of the good / bad information, so we _must_ store
1383 * this information in a good / bad table during
1384 * startup
1386 if (this->options & NAND_IS_AND) {
1387 /* Use the default pattern descriptors */
1388 if (!this->bbt_td) {
1389 this->bbt_td = &bbt_main_descr;
1390 this->bbt_md = &bbt_mirror_descr;
1392 this->options |= NAND_USE_FLASH_BBT;
1393 return nand_scan_bbt(mtd, &agand_flashbased);
1396 /* Is a flash based bad block table requested ? */
1397 if (this->options & NAND_USE_FLASH_BBT) {
1398 /* Use the default pattern descriptors */
1399 if (!this->bbt_td) {
1400 if (this->options & NAND_USE_FLASH_BBT_NO_OOB) {
1401 this->bbt_td = &bbt_main_no_bbt_descr;
1402 this->bbt_md = &bbt_mirror_no_bbt_descr;
1403 } else {
1404 this->bbt_td = &bbt_main_descr;
1405 this->bbt_md = &bbt_mirror_descr;
1408 } else {
1409 this->bbt_td = NULL;
1410 this->bbt_md = NULL;
1413 if (!this->badblock_pattern)
1414 nand_create_default_bbt_descr(this);
1416 return nand_scan_bbt(mtd, this->badblock_pattern);
1420 * nand_isbad_bbt - [NAND Interface] Check if a block is bad
1421 * @mtd: MTD device structure
1422 * @offs: offset in the device
1423 * @allowbbt: allow access to bad block table region
1426 int nand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt)
1428 struct nand_chip *this = mtd->priv;
1429 int block;
1430 uint8_t res;
1432 /* Get block number * 2 */
1433 block = (int)(offs >> (this->bbt_erase_shift - 1));
1434 res = (this->bbt[block >> 3] >> (block & 0x06)) & 0x03;
1436 DEBUG(MTD_DEBUG_LEVEL2, "nand_isbad_bbt(): bbt info for offs 0x%08x: (block %d) 0x%02x\n",
1437 (unsigned int)offs, block >> 1, res);
1439 switch ((int)res) {
1440 case 0x00:
1441 return 0;
1442 case 0x01:
1443 return 1;
1444 case 0x02:
1445 return allowbbt ? 0 : 1;
1447 return 1;
1450 EXPORT_SYMBOL(nand_scan_bbt);
1451 EXPORT_SYMBOL(nand_default_bbt);