1 /* 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 14 * it under the terms of the GNU General Public License version 2 as 15 * published by the Free Software Foundation. 16 */ 17 #ifndef __LINUX_MTD_BBM_H 18 #define __LINUX_MTD_BBM_H 19 20 /* The maximum number of NAND chips in an array */ 21 #ifndef CONFIG_SYS_NAND_MAX_CHIPS 22 #define CONFIG_SYS_NAND_MAX_CHIPS 1 23 #endif 24 25 /** 26 * struct nand_bbt_descr - bad block table descriptor 27 * @param options options for this descriptor 28 * @param pages the page(s) where we find the bbt, used with 29 * option BBT_ABSPAGE when bbt is searched, 30 * then we store the found bbts pages here. 31 * Its an array and supports up to 8 chips now 32 * @param offs offset of the pattern in the oob area of the page 33 * @param veroffs offset of the bbt version counter in the oob are of the page 34 * @param version version read from the bbt page during scan 35 * @param len length of the pattern, if 0 no pattern check is performed 36 * @param maxblocks maximum number of blocks to search for a bbt. This number of 37 * blocks is reserved at the end of the device 38 * where the tables are written. 39 * @param reserved_block_code if non-0, this pattern denotes a reserved 40 * (rather than bad) block in the stored bbt 41 * @param pattern pattern to identify bad block table or factory marked 42 * good / bad blocks, can be NULL, if len = 0 43 * 44 * Descriptor for the bad block table marker and the descriptor for the 45 * pattern which identifies good and bad blocks. The assumption is made 46 * that the pattern and the version count are always located in the oob area 47 * of the first block. 48 */ 49 struct nand_bbt_descr { 50 int options; 51 int pages[CONFIG_SYS_NAND_MAX_CHIPS]; 52 int offs; 53 int veroffs; 54 uint8_t version[CONFIG_SYS_NAND_MAX_CHIPS]; 55 int len; 56 int maxblocks; 57 int reserved_block_code; 58 uint8_t *pattern; 59 }; 60 61 /* Options for the bad block table descriptors */ 62 63 /* The number of bits used per block in the bbt on the device */ 64 #define NAND_BBT_NRBITS_MSK 0x0000000F 65 #define NAND_BBT_1BIT 0x00000001 66 #define NAND_BBT_2BIT 0x00000002 67 #define NAND_BBT_4BIT 0x00000004 68 #define NAND_BBT_8BIT 0x00000008 69 /* The bad block table is in the last good block of the device */ 70 #define NAND_BBT_LASTBLOCK 0x00000010 71 /* The bbt is at the given page, else we must scan for the bbt */ 72 #define NAND_BBT_ABSPAGE 0x00000020 73 /* The bbt is at the given page, else we must scan for the bbt */ 74 #define NAND_BBT_SEARCH 0x00000040 75 /* bbt is stored per chip on multichip devices */ 76 #define NAND_BBT_PERCHIP 0x00000080 77 /* bbt has a version counter at offset veroffs */ 78 #define NAND_BBT_VERSION 0x00000100 79 /* Create a bbt if none axists */ 80 #define NAND_BBT_CREATE 0x00000200 81 /* Search good / bad pattern through all pages of a block */ 82 #define NAND_BBT_SCANALLPAGES 0x00000400 83 /* Scan block empty during good / bad block scan */ 84 #define NAND_BBT_SCANEMPTY 0x00000800 85 /* Write bbt if neccecary */ 86 #define NAND_BBT_WRITE 0x00001000 87 /* Read and write back block contents when writing bbt */ 88 #define NAND_BBT_SAVECONTENT 0x00002000 89 /* Search good / bad pattern on the first and the second page */ 90 #define NAND_BBT_SCAN2NDPAGE 0x00004000 91 92 /* The maximum number of blocks to scan for a bbt */ 93 #define NAND_BBT_SCAN_MAXBLOCKS 4 94 95 /* 96 * Constants for oob configuration 97 */ 98 #define ONENAND_BADBLOCK_POS 0 99 100 /* 101 * Bad block scanning errors 102 */ 103 #define ONENAND_BBT_READ_ERROR 1 104 #define ONENAND_BBT_READ_ECC_ERROR 2 105 #define ONENAND_BBT_READ_FATAL_ERROR 4 106 107 /** 108 * struct bbt_info - [GENERIC] Bad Block Table data structure 109 * @param bbt_erase_shift [INTERN] number of address bits in a bbt entry 110 * @param badblockpos [INTERN] position of the bad block marker in the oob area 111 * @param bbt [INTERN] bad block table pointer 112 * @param badblock_pattern [REPLACEABLE] bad block scan pattern used for initial bad block scan 113 * @param priv [OPTIONAL] pointer to private bbm date 114 */ 115 struct bbm_info { 116 int bbt_erase_shift; 117 int badblockpos; 118 int options; 119 120 uint8_t *bbt; 121 122 int (*isbad_bbt) (struct mtd_info * mtd, loff_t ofs, int allowbbt); 123 124 /* TODO Add more NAND specific fileds */ 125 struct nand_bbt_descr *badblock_pattern; 126 127 void *priv; 128 }; 129 130 /* OneNAND BBT interface */ 131 extern int onenand_scan_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd); 132 extern int onenand_default_bbt (struct mtd_info *mtd); 133 134 #endif /* __LINUX_MTD_BBM_H */ 135