README.nand 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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 size
  31. nand erase clean [off size]
  32. Erase `size' bytes starting at offset `off'. Only complete erase
  33. blocks can be erased.
  34. If `clean' is specified, a JFFS2-style clean marker is written to
  35. each block after it is erased. If `clean' is specified without an
  36. offset or size, the entire flash is erased.
  37. This command will not erase blocks that are marked bad. There is
  38. a debug option in cmd_nand.c to allow bad blocks to be erased.
  39. Please read the warning there before using it, as blocks marked
  40. bad by the manufacturer must _NEVER_ be erased.
  41. nand info
  42. Print information about all of the NAND devices found.
  43. nand read addr ofs size
  44. Read `size' bytes from `ofs' in NAND flash to `addr'. If a page
  45. cannot be read because it is marked bad or an uncorrectable data
  46. error is found the command stops with an error.
  47. nand read.jffs2 addr ofs size
  48. Like `read', but the data for blocks that are marked bad is read as
  49. 0xff. This gives a readable JFFS2 image that can be processed by
  50. the JFFS2 commands such as ls and fsload.
  51. nand read.oob addr ofs 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 size
  57. Write `size' bytes from `addr' to `ofs' in NAND flash. If a page
  58. cannot be written because it is marked bad or the write fails the
  59. command stops with an error.
  60. nand write.jffs2 addr ofs size
  61. Like `write', but blocks that are marked bad are skipped and the
  62. is written to the next block instead. This allows writing writing
  63. a JFFS2 image, as long as the image is short enough to fit even
  64. after skipping the bad blocks. Compact images, such as those
  65. produced by mkfs.jffs2 should work well, but loading an image copied
  66. from another flash is going to be trouble if there are any bad blocks.
  67. nand write.oob addr ofs size
  68. Write `size' bytes from `addr' to the out-of-band data area
  69. corresponding to `ofs' in NAND flash. This is limited to the 16 bytes
  70. of data for one 512-byte page or 2 256-byte pages. There is no check
  71. for bad blocks.
  72. Configuration Options:
  73. CFG_CMD_NAND
  74. A good one to add to CONFIG_COMMANDS since it enables NAND support.
  75. CONFIG_MTD_NAND_ECC_JFFS2
  76. Define this if you want the Error Correction Code information in
  77. the out-of-band data to be formatted to match the JFFS2 file system.
  78. CONFIG_MTD_NAND_ECC_YAFFS would be another useful choice for
  79. someone to implement.
  80. CFG_MAX_NAND_DEVICE
  81. The maximum number of NAND devices you want to support.
  82. NAND Interface:
  83. #define NAND_WAIT_READY(nand)
  84. Wait until the NAND flash is ready. Typically this would be a
  85. loop waiting for the READY/BUSY line from the flash to indicate it
  86. it is ready.
  87. #define WRITE_NAND_COMMAND(d, adr)
  88. Write the command byte `d' to the flash at `adr' with the
  89. CLE (command latch enable) line true. If your board uses writes to
  90. different addresses to control CLE and ALE, you can modify `adr'
  91. to be the appropriate address here. If your board uses I/O registers
  92. to control them, it is probably better to let NAND_CTL_SETCLE()
  93. and company do it.
  94. #define WRITE_NAND_ADDRESS(d, adr)
  95. Write the address byte `d' to the flash at `adr' with the
  96. ALE (address latch enable) line true. If your board uses writes to
  97. different addresses to control CLE and ALE, you can modify `adr'
  98. to be the appropriate address here. If your board uses I/O registers
  99. to control them, it is probably better to let NAND_CTL_SETALE()
  100. and company do it.
  101. #define WRITE_NAND(d, adr)
  102. Write the data byte `d' to the flash at `adr' with the
  103. ALE and CLE lines false. If your board uses writes to
  104. different addresses to control CLE and ALE, you can modify `adr'
  105. to be the appropriate address here. If your board uses I/O registers
  106. to control them, it is probably better to let NAND_CTL_CLRALE()
  107. and company do it.
  108. #define READ_NAND(adr)
  109. Read a data byte from the flash at `adr' with the
  110. ALE and CLE lines false. If your board uses reads from
  111. different addresses to control CLE and ALE, you can modify `adr'
  112. to be the appropriate address here. If your board uses I/O registers
  113. to control them, it is probably better to let NAND_CTL_CLRALE()
  114. and company do it.
  115. #define NAND_DISABLE_CE(nand)
  116. Set CE (Chip Enable) low to enable the NAND flash.
  117. #define NAND_ENABLE_CE(nand)
  118. Set CE (Chip Enable) high to disable the NAND flash.
  119. #define NAND_CTL_CLRALE(nandptr)
  120. Set ALE (address latch enable) low. If ALE control is handled by
  121. WRITE_NAND_ADDRESS() this can be empty.
  122. #define NAND_CTL_SETALE(nandptr)
  123. Set ALE (address latch enable) high. If ALE control is handled by
  124. WRITE_NAND_ADDRESS() this can be empty.
  125. #define NAND_CTL_CLRCLE(nandptr)
  126. Set CLE (command latch enable) low. If CLE control is handled by
  127. WRITE_NAND_ADDRESS() this can be empty.
  128. #define NAND_CTL_SETCLE(nandptr)
  129. Set CLE (command latch enable) high. If CLE control is handled by
  130. WRITE_NAND_ADDRESS() this can be empty.
  131. More Definitions:
  132. These definitions are needed in the board configuration for now, but
  133. may really belong in a header file.
  134. TODO: Figure which ones are truly configuration settings and rename
  135. them to CFG_NAND_... and move the rest somewhere appropriate.
  136. #define SECTORSIZE 512
  137. #define ADDR_COLUMN 1
  138. #define ADDR_PAGE 2
  139. #define ADDR_COLUMN_PAGE 3
  140. #define NAND_ChipID_UNKNOWN 0x00
  141. #define NAND_MAX_FLOORS 1
  142. #define NAND_MAX_CHIPS 1
  143. NOTE:
  144. =====
  145. We now use a complete rewrite of the NAND code based on what is in
  146. 2.6.12 Linux kernel.
  147. The old NAND handling code has been re-factored and is now confined
  148. to only board-specific files and - unfortunately - to the DoC code
  149. (see below). A new configuration variable has been introduced:
  150. CFG_NAND_LEGACY, which has to be defined in the board config file if
  151. that board uses legacy code. If CFG_NAND_LEGACY is defined, the board
  152. specific config.mk file should also have "BOARDLIBS =
  153. drivers/nand_legacy/libnand_legacy.a". For boards using the new NAND
  154. approach (PPChameleon and netstar at the moment) no variable is
  155. necessary, but the config.mk should have "BOARDLIBS =
  156. drivers/nand/libnand.a".
  157. The necessary changes have been made to all affected boards, and no
  158. build breakage has been introduced, except for NETTA and NETTA_ISDN
  159. targets from MAKEALL. This is due to the fact that these two boards
  160. use JFFS, which has been adopted to use the new NAND, and at the same
  161. time use NAND in legacy mode. The breakage will disappear when the
  162. board-specific code is changed to the new NAND.
  163. As mentioned above, the legacy code is still used by the DoC subsystem.
  164. The consequence of this is that the legacy NAND can't be removed from
  165. the tree until the DoC is ported to use the new NAND support (or boards
  166. with DoC will break).