README.nand 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. NAND FLASH commands and notes
  2. See NOTE below!!!
  3. # (C) Copyright 2003
  4. # Dave Ellis, SIXNET, dge@sixnetio.com
  5. #
  6. # See file CREDITS for list of people who contributed to this
  7. # project.
  8. #
  9. # This program is free software; you can redistribute it and/or
  10. # modify it under the terms of the GNU General Public License as
  11. # published by the Free Software Foundation; either version 2 of
  12. # the License, or (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program; if not, write to the Free Software
  21. # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. # MA 02111-1307 USA
  23. Commands:
  24. nand bad
  25. Print a list of all of the bad blocks in the current device.
  26. nand device
  27. Print information about the current NAND device.
  28. nand device num
  29. Make device `num' the current device and print information about it.
  30. nand erase off|partition size
  31. nand erase clean [off|partition size]
  32. Erase `size' bytes starting at offset `off'. Alternatively partition
  33. name can be specified, in this case size will be eventually limited
  34. to not exceed partition size (this behaviour applies also to read
  35. and write commands). Only complete erase blocks can be erased.
  36. If `erase' is specified without an offset or size, the entire flash
  37. is erased. If `erase' is specified with partition but without an
  38. size, the entire partition is erased.
  39. If `clean' is specified, a JFFS2-style clean marker is written to
  40. each block after it is erased.
  41. This command will not erase blocks that are marked bad. There is
  42. a debug option in cmd_nand.c to allow bad blocks to be erased.
  43. Please read the warning there before using it, as blocks marked
  44. bad by the manufacturer must _NEVER_ be erased.
  45. nand info
  46. Print information about all of the NAND devices found.
  47. nand read addr ofs|partition size
  48. Read `size' bytes from `ofs' in NAND flash to `addr'. Blocks that
  49. are marked bad are skipped. If a page cannot be read because an
  50. uncorrectable data error is found, the command stops with an error.
  51. nand read.oob addr ofs|partition size
  52. Read `size' bytes from the out-of-band data area corresponding to
  53. `ofs' in NAND flash to `addr'. This is limited to the 16 bytes of
  54. data for one 512-byte page or 2 256-byte pages. There is no check
  55. for bad blocks or ECC errors.
  56. nand write addr ofs|partition size
  57. Write `size' bytes from `addr' to `ofs' in NAND flash. Blocks that
  58. are marked bad are skipped. If a page cannot be read because an
  59. uncorrectable data error is found, the command stops with an error.
  60. As JFFS2 skips blocks similarly, this allows writing a JFFS2 image,
  61. as long as the image is short enough to fit even after skipping the
  62. bad blocks. Compact images, such as those produced by mkfs.jffs2
  63. should work well, but loading an image copied from another flash is
  64. going to be trouble if there are any bad blocks.
  65. nand write.oob addr ofs|partition size
  66. Write `size' bytes from `addr' to the out-of-band data area
  67. corresponding to `ofs' in NAND flash. This is limited to the 16 bytes
  68. of data for one 512-byte page or 2 256-byte pages. There is no check
  69. for bad blocks.
  70. Configuration Options:
  71. CONFIG_CMD_NAND
  72. Enables NAND support and commmands.
  73. CONFIG_MTD_NAND_ECC_JFFS2
  74. Define this if you want the Error Correction Code information in
  75. the out-of-band data to be formatted to match the JFFS2 file system.
  76. CONFIG_MTD_NAND_ECC_YAFFS would be another useful choice for
  77. someone to implement.
  78. CFG_MAX_NAND_DEVICE
  79. The maximum number of NAND devices you want to support.
  80. NAND Interface:
  81. #define NAND_WAIT_READY(nand)
  82. Wait until the NAND flash is ready. Typically this would be a
  83. loop waiting for the READY/BUSY line from the flash to indicate it
  84. it is ready.
  85. #define WRITE_NAND_COMMAND(d, adr)
  86. Write the command byte `d' to the flash at `adr' with the
  87. CLE (command latch enable) line true. If your board uses writes to
  88. different addresses to control CLE and ALE, you can modify `adr'
  89. to be the appropriate address here. If your board uses I/O registers
  90. to control them, it is probably better to let NAND_CTL_SETCLE()
  91. and company do it.
  92. #define WRITE_NAND_ADDRESS(d, adr)
  93. Write the address byte `d' to the flash at `adr' with the
  94. ALE (address latch enable) line true. If your board uses writes to
  95. different addresses to control CLE and ALE, you can modify `adr'
  96. to be the appropriate address here. If your board uses I/O registers
  97. to control them, it is probably better to let NAND_CTL_SETALE()
  98. and company do it.
  99. #define WRITE_NAND(d, adr)
  100. Write the data byte `d' to the flash at `adr' with the
  101. ALE and CLE lines false. If your board uses writes to
  102. different addresses to control CLE and ALE, you can modify `adr'
  103. to be the appropriate address here. If your board uses I/O registers
  104. to control them, it is probably better to let NAND_CTL_CLRALE()
  105. and company do it.
  106. #define READ_NAND(adr)
  107. Read a data byte from the flash at `adr' with the
  108. ALE and CLE lines false. If your board uses reads from
  109. different addresses to control CLE and ALE, you can modify `adr'
  110. to be the appropriate address here. If your board uses I/O registers
  111. to control them, it is probably better to let NAND_CTL_CLRALE()
  112. and company do it.
  113. #define NAND_DISABLE_CE(nand)
  114. Set CE (Chip Enable) low to enable the NAND flash.
  115. #define NAND_ENABLE_CE(nand)
  116. Set CE (Chip Enable) high to disable the NAND flash.
  117. #define NAND_CTL_CLRALE(nandptr)
  118. Set ALE (address latch enable) low. If ALE control is handled by
  119. WRITE_NAND_ADDRESS() this can be empty.
  120. #define NAND_CTL_SETALE(nandptr)
  121. Set ALE (address latch enable) high. If ALE control is handled by
  122. WRITE_NAND_ADDRESS() this can be empty.
  123. #define NAND_CTL_CLRCLE(nandptr)
  124. Set CLE (command latch enable) low. If CLE control is handled by
  125. WRITE_NAND_ADDRESS() this can be empty.
  126. #define NAND_CTL_SETCLE(nandptr)
  127. Set CLE (command latch enable) high. If CLE control is handled by
  128. WRITE_NAND_ADDRESS() this can be empty.
  129. More Definitions:
  130. These definitions are needed in the board configuration for now, but
  131. may really belong in a header file.
  132. TODO: Figure which ones are truly configuration settings and rename
  133. them to CFG_NAND_... and move the rest somewhere appropriate.
  134. #define SECTORSIZE 512
  135. #define ADDR_COLUMN 1
  136. #define ADDR_PAGE 2
  137. #define ADDR_COLUMN_PAGE 3
  138. #define NAND_ChipID_UNKNOWN 0x00
  139. #define NAND_MAX_FLOORS 1
  140. #define NAND_MAX_CHIPS 1
  141. #define CFG_DAVINCI_BROKEN_ECC
  142. Versions of U-Boot <= 1.3.3 and Montavista Linux kernels
  143. generated bogus ECCs on large-page NAND. Both large and small page
  144. NAND ECCs were incompatible with the Linux davinci git tree (since
  145. NAND was integrated in 2.6.24).
  146. Turn this ON if you want backwards compatibility.
  147. Turn this OFF if you want U-Boot and the Linux davinci git kernel
  148. to use the same ECC format.
  149. NOTE:
  150. =====
  151. We now use a complete rewrite of the NAND code based on what is in
  152. 2.6.12 Linux kernel.
  153. The old NAND handling code has been re-factored and is now confined
  154. to only board-specific files and - unfortunately - to the DoC code
  155. (see below). A new configuration variable has been introduced:
  156. CONFIG_NAND_LEGACY, which has to be defined in the board config file if
  157. that board uses legacy code.
  158. The necessary changes have been made to all affected boards, and no
  159. build breakage has been introduced, except for NETTA and NETTA_ISDN
  160. targets from MAKEALL. This is due to the fact that these two boards
  161. use JFFS, which has been adopted to use the new NAND, and at the same
  162. time use NAND in legacy mode. The breakage will disappear when the
  163. board-specific code is changed to the new NAND.
  164. As mentioned above, the legacy code is still used by the DoC subsystem.
  165. The consequence of this is that the legacy NAND can't be removed from
  166. the tree until the DoC is ported to use the new NAND support (or boards
  167. with DoC will break).
  168. Additional improvements to the NAND subsystem by Guido Classen, 10-10-2006
  169. JFFS2 related commands:
  170. implement "nand erase clean" and old "nand erase"
  171. using both the new code which is able to skip bad blocks
  172. "nand erase clean" additionally writes JFFS2-cleanmarkers in the oob.
  173. Miscellaneous and testing commands:
  174. "markbad [offset]"
  175. create an artificial bad block (for testing bad block handling)
  176. "scrub [offset length]"
  177. like "erase" but don't skip bad block. Instead erase them.
  178. DANGEROUS!!! Factory set bad blocks will be lost. Use only
  179. to remove artificial bad blocks created with the "markbad" command.
  180. NAND locking command (for chips with active LOCKPRE pin)
  181. "nand lock"
  182. set NAND chip to lock state (all pages locked)
  183. "nand lock tight"
  184. set NAND chip to lock tight state (software can't change locking anymore)
  185. "nand lock status"
  186. displays current locking status of all pages
  187. "nand unlock [offset] [size]"
  188. unlock consecutive area (can be called multiple times for different areas)
  189. I have tested the code with board containing 128MiB NAND large page chips
  190. and 32MiB small page chips.