README.nand 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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'. If a page
  49. cannot be read because it is marked bad or an uncorrectable data
  50. error is found the command stops with an error.
  51. nand read.jffs2 addr ofs|partition size
  52. Like `read', but the data for blocks that are marked bad is read as
  53. 0xff. This gives a readable JFFS2 image that can be processed by
  54. the JFFS2 commands such as ls and fsload.
  55. nand read.oob addr ofs|partition size
  56. Read `size' bytes from the out-of-band data area corresponding to
  57. `ofs' in NAND flash to `addr'. This is limited to the 16 bytes of
  58. data for one 512-byte page or 2 256-byte pages. There is no check
  59. for bad blocks or ECC errors.
  60. nand write addr ofs|partition size
  61. Write `size' bytes from `addr' to `ofs' in NAND flash. If a page
  62. cannot be written because it is marked bad or the write fails the
  63. command stops with an error.
  64. nand write.jffs2 addr ofs|partition size
  65. Like `write', but blocks that are marked bad are skipped and the
  66. is written to the next block instead. This allows writing writing
  67. a JFFS2 image, as long as the image is short enough to fit even
  68. after skipping the bad blocks. Compact images, such as those
  69. produced by mkfs.jffs2 should work well, but loading an image copied
  70. from another flash is going to be trouble if there are any bad blocks.
  71. nand write.oob addr ofs|partition size
  72. Write `size' bytes from `addr' to the out-of-band data area
  73. corresponding to `ofs' in NAND flash. This is limited to the 16 bytes
  74. of data for one 512-byte page or 2 256-byte pages. There is no check
  75. for bad blocks.
  76. Configuration Options:
  77. CFG_CMD_NAND
  78. A good one to add to CONFIG_COMMANDS since it enables NAND support.
  79. CONFIG_MTD_NAND_ECC_JFFS2
  80. Define this if you want the Error Correction Code information in
  81. the out-of-band data to be formatted to match the JFFS2 file system.
  82. CONFIG_MTD_NAND_ECC_YAFFS would be another useful choice for
  83. someone to implement.
  84. CFG_MAX_NAND_DEVICE
  85. The maximum number of NAND devices you want to support.
  86. NAND Interface:
  87. #define NAND_WAIT_READY(nand)
  88. Wait until the NAND flash is ready. Typically this would be a
  89. loop waiting for the READY/BUSY line from the flash to indicate it
  90. it is ready.
  91. #define WRITE_NAND_COMMAND(d, adr)
  92. Write the command byte `d' to the flash at `adr' with the
  93. CLE (command latch enable) line true. If your board uses writes to
  94. different addresses to control CLE and ALE, you can modify `adr'
  95. to be the appropriate address here. If your board uses I/O registers
  96. to control them, it is probably better to let NAND_CTL_SETCLE()
  97. and company do it.
  98. #define WRITE_NAND_ADDRESS(d, adr)
  99. Write the address byte `d' to the flash at `adr' with the
  100. ALE (address latch enable) line true. If your board uses writes to
  101. different addresses to control CLE and ALE, you can modify `adr'
  102. to be the appropriate address here. If your board uses I/O registers
  103. to control them, it is probably better to let NAND_CTL_SETALE()
  104. and company do it.
  105. #define WRITE_NAND(d, adr)
  106. Write the data byte `d' to the flash at `adr' with the
  107. ALE and CLE lines false. If your board uses writes to
  108. different addresses to control CLE and ALE, you can modify `adr'
  109. to be the appropriate address here. If your board uses I/O registers
  110. to control them, it is probably better to let NAND_CTL_CLRALE()
  111. and company do it.
  112. #define READ_NAND(adr)
  113. Read a data byte from the flash at `adr' with the
  114. ALE and CLE lines false. If your board uses reads from
  115. different addresses to control CLE and ALE, you can modify `adr'
  116. to be the appropriate address here. If your board uses I/O registers
  117. to control them, it is probably better to let NAND_CTL_CLRALE()
  118. and company do it.
  119. #define NAND_DISABLE_CE(nand)
  120. Set CE (Chip Enable) low to enable the NAND flash.
  121. #define NAND_ENABLE_CE(nand)
  122. Set CE (Chip Enable) high to disable the NAND flash.
  123. #define NAND_CTL_CLRALE(nandptr)
  124. Set ALE (address latch enable) low. If ALE control is handled by
  125. WRITE_NAND_ADDRESS() this can be empty.
  126. #define NAND_CTL_SETALE(nandptr)
  127. Set ALE (address latch enable) high. If ALE control is handled by
  128. WRITE_NAND_ADDRESS() this can be empty.
  129. #define NAND_CTL_CLRCLE(nandptr)
  130. Set CLE (command latch enable) low. If CLE control is handled by
  131. WRITE_NAND_ADDRESS() this can be empty.
  132. #define NAND_CTL_SETCLE(nandptr)
  133. Set CLE (command latch enable) high. If CLE control is handled by
  134. WRITE_NAND_ADDRESS() this can be empty.
  135. More Definitions:
  136. These definitions are needed in the board configuration for now, but
  137. may really belong in a header file.
  138. TODO: Figure which ones are truly configuration settings and rename
  139. them to CFG_NAND_... and move the rest somewhere appropriate.
  140. #define SECTORSIZE 512
  141. #define ADDR_COLUMN 1
  142. #define ADDR_PAGE 2
  143. #define ADDR_COLUMN_PAGE 3
  144. #define NAND_ChipID_UNKNOWN 0x00
  145. #define NAND_MAX_FLOORS 1
  146. #define NAND_MAX_CHIPS 1
  147. NOTE:
  148. =====
  149. We now use a complete rewrite of the NAND code based on what is in
  150. 2.6.12 Linux kernel.
  151. The old NAND handling code has been re-factored and is now confined
  152. to only board-specific files and - unfortunately - to the DoC code
  153. (see below). A new configuration variable has been introduced:
  154. CFG_NAND_LEGACY, which has to be defined in the board config file if
  155. that board uses legacy code.
  156. The necessary changes have been made to all affected boards, and no
  157. build breakage has been introduced, except for NETTA and NETTA_ISDN
  158. targets from MAKEALL. This is due to the fact that these two boards
  159. use JFFS, which has been adopted to use the new NAND, and at the same
  160. time use NAND in legacy mode. The breakage will disappear when the
  161. board-specific code is changed to the new NAND.
  162. As mentioned above, the legacy code is still used by the DoC subsystem.
  163. The consequence of this is that the legacy NAND can't be removed from
  164. the tree until the DoC is ported to use the new NAND support (or boards
  165. with DoC will break).
  166. Additional improvements to the NAND subsystem by Guido Classen, 10-10-2006
  167. JFFS2 related commands:
  168. implement "nand erase clean" and old "nand erase"
  169. using both the new code which is able to skip bad blocks
  170. "nand erase clean" additionally writes JFFS2-cleanmarkers in the oob.
  171. "nand write.jffs2"
  172. like "nand write" but skip found bad eraseblocks
  173. "nand read.jffs2"
  174. like "nand read" but skip found bad eraseblocks
  175. Miscellaneous and testing commands:
  176. "markbad [offset]"
  177. create an artificial bad block (for testing bad block handling)
  178. "scrub [offset length]"
  179. like "erase" but don't skip bad block. Instead erase them.
  180. DANGEROUS!!! Factory set bad blocks will be lost. Use only
  181. to remove artificial bad blocks created with the "markbad" command.
  182. NAND locking command (for chips with active LOCKPRE pin)
  183. "nand lock"
  184. set NAND chip to lock state (all pages locked)
  185. "nand lock tight"
  186. set NAND chip to lock tight state (software can't change locking anymore)
  187. "nand lock status"
  188. displays current locking status of all pages
  189. "nand unlock [offset] [size]"
  190. unlock consecutive area (can be called multiple times for different areas)
  191. I have tested the code with board containing 128MiB NAND large page chips
  192. and 32MiB small page chips.