bbm.h 5.3 KB

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