bbm.h 4.3 KB

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