README.nand 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. # SPDX-License-Identifier: GPL-2.0+
  2. NAND FLASH commands and notes
  3. See NOTE below!!!
  4. # (C) Copyright 2003
  5. # Dave Ellis, SIXNET, dge@sixnetio.com
  6. #
  7. Commands:
  8. nand bad
  9. Print a list of all of the bad blocks in the current device.
  10. nand device
  11. Print information about the current NAND device.
  12. nand device num
  13. Make device `num' the current device and print information about it.
  14. nand erase off|partition size
  15. nand erase clean [off|partition size]
  16. Erase `size' bytes starting at offset `off'. Alternatively partition
  17. name can be specified, in this case size will be eventually limited
  18. to not exceed partition size (this behaviour applies also to read
  19. and write commands). Only complete erase blocks can be erased.
  20. If `erase' is specified without an offset or size, the entire flash
  21. is erased. If `erase' is specified with partition but without an
  22. size, the entire partition is erased.
  23. If `clean' is specified, a JFFS2-style clean marker is written to
  24. each block after it is erased.
  25. This command will not erase blocks that are marked bad. There is
  26. a debug option in cmd_nand.c to allow bad blocks to be erased.
  27. Please read the warning there before using it, as blocks marked
  28. bad by the manufacturer must _NEVER_ be erased.
  29. nand info
  30. Print information about all of the NAND devices found.
  31. nand read addr ofs|partition size
  32. Read `size' bytes from `ofs' in NAND flash to `addr'. Blocks that
  33. are marked bad are skipped. If a page cannot be read because an
  34. uncorrectable data error is found, the command stops with an error.
  35. nand read.oob addr ofs|partition size
  36. Read `size' bytes from the out-of-band data area corresponding to
  37. `ofs' in NAND flash to `addr'. This is limited to the 16 bytes of
  38. data for one 512-byte page or 2 256-byte pages. There is no check
  39. for bad blocks or ECC errors.
  40. nand write addr ofs|partition size
  41. Write `size' bytes from `addr' to `ofs' in NAND flash. Blocks that
  42. are marked bad are skipped. If a page cannot be read because an
  43. uncorrectable data error is found, the command stops with an error.
  44. As JFFS2 skips blocks similarly, this allows writing a JFFS2 image,
  45. as long as the image is short enough to fit even after skipping the
  46. bad blocks. Compact images, such as those produced by mkfs.jffs2
  47. should work well, but loading an image copied from another flash is
  48. going to be trouble if there are any bad blocks.
  49. nand write.trimffs addr ofs|partition size
  50. Enabled by the CONFIG_CMD_NAND_TRIMFFS macro. This command will write to
  51. the NAND flash in a manner identical to the 'nand write' command
  52. described above -- with the additional check that all pages at the end
  53. of eraseblocks which contain only 0xff data will not be written to the
  54. NAND flash. This behaviour is required when flashing UBI images
  55. containing UBIFS volumes as per the UBI FAQ[1].
  56. [1] http://www.linux-mtd.infradead.org/doc/ubi.html#L_flasher_algo
  57. nand write.oob addr ofs|partition size
  58. Write `size' bytes from `addr' to the out-of-band data area
  59. corresponding to `ofs' in NAND flash. This is limited to the 16 bytes
  60. of data for one 512-byte page or 2 256-byte pages. There is no check
  61. for bad blocks.
  62. nand read.raw addr ofs|partition [count]
  63. nand write.raw addr ofs|partition [count]
  64. Read or write one or more pages at "ofs" in NAND flash, from or to
  65. "addr" in memory. This is a raw access, so ECC is avoided and the
  66. OOB area is transferred as well. If count is absent, it is assumed
  67. to be one page. As with .yaffs2 accesses, the data is formatted as
  68. a packed sequence of "data, oob, data, oob, ..." -- no alignment of
  69. individual pages is maintained.
  70. Configuration Options:
  71. CONFIG_SYS_NAND_U_BOOT_OFFS
  72. NAND Offset from where SPL will read u-boot image. This is the starting
  73. address of u-boot MTD partition in NAND.
  74. CONFIG_CMD_NAND
  75. Enables NAND support and commands.
  76. CONFIG_CMD_NAND_TORTURE
  77. Enables the torture command (see description of this command below).
  78. CONFIG_SYS_NAND_MAX_CHIPS
  79. The maximum number of NAND chips per device to be supported.
  80. CONFIG_SYS_NAND_SELF_INIT
  81. Traditionally, glue code in drivers/mtd/nand/raw/nand.c has driven
  82. the initialization process -- it provides the mtd and nand
  83. structs, calls a board init function for a specific device,
  84. calls nand_scan(), and registers with mtd.
  85. This arrangement does not provide drivers with the flexibility to
  86. run code between nand_scan_ident() and nand_scan_tail(), or other
  87. deviations from the "normal" flow.
  88. If a board defines CONFIG_SYS_NAND_SELF_INIT, drivers/mtd/nand/raw/nand.c
  89. will make one call to board_nand_init(), with no arguments. That
  90. function is responsible for calling a driver init function for
  91. each NAND device on the board, that performs all initialization
  92. tasks except setting mtd->name, and registering with the rest of
  93. U-Boot. Those last tasks are accomplished by calling nand_register()
  94. on the new mtd device.
  95. Example of new init to be added to the end of an existing driver
  96. init:
  97. /* chip is struct nand_chip, and is now provided by the driver. */
  98. mtd = nand_to_mtd(&chip);
  99. /*
  100. * Fill in appropriate values if this driver uses these fields,
  101. * or uses the standard read_byte/write_buf/etc. functions from
  102. * nand_base.c that use these fields.
  103. */
  104. chip.IO_ADDR_R = ...;
  105. chip.IO_ADDR_W = ...;
  106. if (nand_scan_ident(mtd, CFG_SYS_MAX_NAND_CHIPS, NULL))
  107. error out
  108. /*
  109. * Insert here any code you wish to run after the chip has been
  110. * identified, but before any other I/O is done.
  111. */
  112. if (nand_scan_tail(mtd))
  113. error out
  114. /*
  115. * devnum is the device number to be used in nand commands
  116. * and in mtd->name. Must be less than CONFIG_SYS_MAX_NAND_DEVICE.
  117. */
  118. if (nand_register(devnum, mtd))
  119. error out
  120. In addition to providing more flexibility to the driver, it reduces
  121. the difference between a U-Boot driver and its Linux counterpart.
  122. nand_init() is now reduced to calling board_nand_init() once, and
  123. printing a size summary. This should also make it easier to
  124. transition to delayed NAND initialization.
  125. Please convert your driver even if you don't need the extra
  126. flexibility, so that one day we can eliminate the old mechanism.
  127. Platform specific options
  128. =========================
  129. CONFIG_NAND_OMAP_GPMC
  130. Enables omap_gpmc.c driver for OMAPx and AMxxxx platforms.
  131. GPMC controller is used for parallel NAND flash devices, and can
  132. do ECC calculation (not ECC error detection) for HAM1, BCH4, BCH8
  133. and BCH16 ECC algorithms.
  134. CONFIG_NAND_OMAP_ELM
  135. Enables omap_elm.c driver for OMAPx and AMxxxx platforms.
  136. ELM controller is used for ECC error detection (not ECC calculation)
  137. of BCH4, BCH8 and BCH16 ECC algorithms.
  138. Some legacy platforms like OMAP3xx do not have in-built ELM h/w engine,
  139. thus such SoC platforms need to depend on software library for ECC error
  140. detection. However ECC calculation on such plaforms would still be
  141. done by GPMC controller.
  142. CONFIG_SPL_NAND_AM33XX_BCH
  143. Enables SPL-NAND driver (am335x_spl_bch.c) which supports ELM based
  144. hardware ECC correction. This is useful for platforms which have ELM
  145. hardware engine and use NAND boot mode.
  146. Some legacy platforms like OMAP3xx do not have in-built ELM h/w engine,
  147. so those platforms should use CONFIG_SPL_NAND_SIMPLE for enabling
  148. SPL-NAND driver with software ECC correction support.
  149. CONFIG_NAND_OMAP_GPMC_PREFETCH
  150. On OMAP platforms that use the GPMC controller
  151. (CONFIG_NAND_OMAP_GPMC_PREFETCH), this options enables the code that
  152. uses the prefetch mode to speed up read operations.
  153. NOTE:
  154. =====
  155. The Disk On Chip driver is currently broken and has been for some time.
  156. There is a driver in drivers/mtd/nand/raw, taken from Linux, that works with
  157. the current NAND system but has not yet been adapted to the u-boot
  158. environment.
  159. Additional improvements to the NAND subsystem by Guido Classen, 10-10-2006
  160. JFFS2 related commands:
  161. implement "nand erase clean" and old "nand erase"
  162. using both the new code which is able to skip bad blocks
  163. "nand erase clean" additionally writes JFFS2-cleanmarkers in the oob.
  164. Miscellaneous and testing commands:
  165. "markbad [offset]"
  166. create an artificial bad block (for testing bad block handling)
  167. "scrub [offset length]"
  168. like "erase" but don't skip bad block. Instead erase them.
  169. DANGEROUS!!! Factory set bad blocks will be lost. Use only
  170. to remove artificial bad blocks created with the "markbad" command.
  171. "torture offset [size]"
  172. Torture block to determine if it is still reliable.
  173. Enabled by the CONFIG_CMD_NAND_TORTURE configuration option.
  174. This command returns 0 if the block is still reliable, else 1.
  175. If the block is detected as unreliable, it is up to the user to decide to
  176. mark this block as bad.
  177. The analyzed block is put through 3 erase / write cycles (or less if the block
  178. is detected as unreliable earlier).
  179. This command can be used in scripts, e.g. together with the markbad command to
  180. automate retries and handling of possibly newly detected bad blocks if the
  181. nand write command fails.
  182. It can also be used manually by users having seen some NAND errors in logs to
  183. search the root cause of these errors.
  184. The underlying nand_torture() function is also useful for code willing to
  185. automate actions following a nand->write() error. This would e.g. be required
  186. in order to program or update safely firmware to NAND, especially for the UBI
  187. part of such firmware.
  188. Optionally, a second parameter size can be given to test multiple blocks with
  189. one call. If size is not a multiple of the NAND's erase size, then the block
  190. that contains offset + size will be tested in full. If used with size, this
  191. command returns 0 if all tested blocks have been found reliable, else 1.
  192. NAND locking command (for chips with active LOCKPRE pin)
  193. "nand lock"
  194. set NAND chip to lock state (all pages locked)
  195. "nand lock tight"
  196. set NAND chip to lock tight state (software can't change locking anymore)
  197. "nand lock status"
  198. displays current locking status of all pages
  199. "nand unlock [offset] [size]"
  200. unlock consecutive area (can be called multiple times for different areas)
  201. "nand unlock.allexcept [offset] [size]"
  202. unlock all except specified consecutive area
  203. I have tested the code with board containing 128MiB NAND large page chips
  204. and 32MiB small page chips.