bbm.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 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. *
  27. */
  28. #ifndef __LINUX_MTD_BBM_H
  29. #define __LINUX_MTD_BBM_H
  30. /* The maximum number of NAND chips in an array */
  31. #ifndef CONFIG_SYS_NAND_MAX_CHIPS
  32. #define CONFIG_SYS_NAND_MAX_CHIPS 1
  33. #endif
  34. /**
  35. * struct nand_bbt_descr - bad block table descriptor
  36. * @param options options for this descriptor
  37. * @param pages the page(s) where we find the bbt, used with
  38. * option BBT_ABSPAGE when bbt is searched,
  39. * then we store the found bbts pages here.
  40. * Its an array and supports up to 8 chips now
  41. * @param offs offset of the pattern in the oob area of the page
  42. * @param veroffs offset of the bbt version counter in the oob are of the page
  43. * @param version version read from the bbt page during scan
  44. * @param len length of the pattern, if 0 no pattern check is performed
  45. * @param maxblocks maximum number of blocks to search for a bbt. This number of
  46. * blocks is reserved at the end of the device
  47. * where the tables are written.
  48. * @param reserved_block_code if non-0, this pattern denotes a reserved
  49. * (rather than bad) block in the stored bbt
  50. * @param pattern pattern to identify bad block table or factory marked
  51. * good / bad blocks, can be NULL, if len = 0
  52. *
  53. * Descriptor for the bad block table marker and the descriptor for the
  54. * pattern which identifies good and bad blocks. The assumption is made
  55. * that the pattern and the version count are always located in the oob area
  56. * of the first block.
  57. */
  58. struct nand_bbt_descr {
  59. int options;
  60. int pages[CONFIG_SYS_NAND_MAX_CHIPS];
  61. int offs;
  62. int veroffs;
  63. uint8_t version[CONFIG_SYS_NAND_MAX_CHIPS];
  64. int len;
  65. int maxblocks;
  66. int reserved_block_code;
  67. uint8_t *pattern;
  68. };
  69. /* Options for the bad block table descriptors */
  70. /* The number of bits used per block in the bbt on the device */
  71. #define NAND_BBT_NRBITS_MSK 0x0000000F
  72. #define NAND_BBT_1BIT 0x00000001
  73. #define NAND_BBT_2BIT 0x00000002
  74. #define NAND_BBT_4BIT 0x00000004
  75. #define NAND_BBT_8BIT 0x00000008
  76. /* The bad block table is in the last good block of the device */
  77. #define NAND_BBT_LASTBLOCK 0x00000010
  78. /* The bbt is at the given page, else we must scan for the bbt */
  79. #define NAND_BBT_ABSPAGE 0x00000020
  80. /* bbt is stored per chip on multichip devices */
  81. #define NAND_BBT_PERCHIP 0x00000080
  82. /* bbt has a version counter at offset veroffs */
  83. #define NAND_BBT_VERSION 0x00000100
  84. /* Create a bbt if none exists */
  85. #define NAND_BBT_CREATE 0x00000200
  86. /*
  87. * Create an empty BBT with no vendor information. Vendor's information may be
  88. * unavailable, for example, if the NAND controller has a different data and OOB
  89. * layout or if this information is already purged. Must be used in conjunction
  90. * with NAND_BBT_CREATE.
  91. */
  92. #define NAND_BBT_CREATE_EMPTY 0x00000400
  93. /* Search good / bad pattern through all pages of a block */
  94. #define NAND_BBT_SCANALLPAGES 0x00000800
  95. /* Scan block empty during good / bad block scan */
  96. #define NAND_BBT_SCANEMPTY 0x00001000
  97. /* Write bbt if neccecary */
  98. #define NAND_BBT_WRITE 0x00002000
  99. /* Read and write back block contents when writing bbt */
  100. #define NAND_BBT_SAVECONTENT 0x00004000
  101. /* Search good / bad pattern on the first and the second page */
  102. #define NAND_BBT_SCAN2NDPAGE 0x00008000
  103. /* Search good / bad pattern on the last page of the eraseblock */
  104. #define NAND_BBT_SCANLASTPAGE 0x00010000
  105. /*
  106. * Use a flash based bad block table. By default, OOB identifier is saved in
  107. * OOB area. This option is passed to the default bad block table function.
  108. */
  109. #define NAND_BBT_USE_FLASH 0x00020000
  110. /*
  111. * Do not store flash based bad block table marker in the OOB area; store it
  112. * in-band.
  113. */
  114. #define NAND_BBT_NO_OOB 0x00040000
  115. /*
  116. * Do not write new bad block markers to OOB; useful, e.g., when ECC covers
  117. * entire spare area. Must be used with NAND_BBT_USE_FLASH.
  118. */
  119. #define NAND_BBT_NO_OOB_BBM 0x00080000
  120. /*
  121. * Flag set by nand_create_default_bbt_descr(), marking that the nand_bbt_descr
  122. * was allocated dynamicaly and must be freed in nand_release(). Has no meaning
  123. * in nand_chip.bbt_options.
  124. */
  125. #define NAND_BBT_DYNAMICSTRUCT 0x80000000
  126. /* The maximum number of blocks to scan for a bbt */
  127. #define NAND_BBT_SCAN_MAXBLOCKS 4
  128. /*
  129. * Constants for oob configuration
  130. */
  131. #define ONENAND_BADBLOCK_POS 0
  132. /*
  133. * Bad block scanning errors
  134. */
  135. #define ONENAND_BBT_READ_ERROR 1
  136. #define ONENAND_BBT_READ_ECC_ERROR 2
  137. #define ONENAND_BBT_READ_FATAL_ERROR 4
  138. /**
  139. * struct bbt_info - [GENERIC] Bad Block Table data structure
  140. * @param bbt_erase_shift [INTERN] number of address bits in a bbt entry
  141. * @param badblockpos [INTERN] position of the bad block marker in the oob area
  142. * @param bbt [INTERN] bad block table pointer
  143. * @param badblock_pattern [REPLACEABLE] bad block scan pattern used for initial bad block scan
  144. * @param priv [OPTIONAL] pointer to private bbm date
  145. */
  146. struct bbm_info {
  147. int bbt_erase_shift;
  148. int badblockpos;
  149. int options;
  150. uint8_t *bbt;
  151. int (*isbad_bbt) (struct mtd_info * mtd, loff_t ofs, int allowbbt);
  152. /* TODO Add more NAND specific fileds */
  153. struct nand_bbt_descr *badblock_pattern;
  154. void *priv;
  155. };
  156. /* OneNAND BBT interface */
  157. extern int onenand_scan_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd);
  158. extern int onenand_default_bbt (struct mtd_info *mtd);
  159. #endif /* __LINUX_MTD_BBM_H */