README.nand 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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_MAX_NAND_DEVICE
  79. The maximum number of NAND devices you want to support.
  80. CONFIG_SYS_NAND_MAX_ECCPOS
  81. If specified, overrides the maximum number of ECC bytes
  82. supported. Useful for reducing image size, especially with SPL.
  83. This must be at least 48 if nand_base.c is used.
  84. CONFIG_SYS_NAND_MAX_OOBFREE
  85. If specified, overrides the maximum number of free OOB regions
  86. supported. Useful for reducing image size, especially with SPL.
  87. This must be at least 2 if nand_base.c is used.
  88. CONFIG_SYS_NAND_MAX_CHIPS
  89. The maximum number of NAND chips per device to be supported.
  90. CONFIG_SYS_NAND_SELF_INIT
  91. Traditionally, glue code in drivers/mtd/nand/raw/nand.c has driven
  92. the initialization process -- it provides the mtd and nand
  93. structs, calls a board init function for a specific device,
  94. calls nand_scan(), and registers with mtd.
  95. This arrangement does not provide drivers with the flexibility to
  96. run code between nand_scan_ident() and nand_scan_tail(), or other
  97. deviations from the "normal" flow.
  98. If a board defines CONFIG_SYS_NAND_SELF_INIT, drivers/mtd/nand/raw/nand.c
  99. will make one call to board_nand_init(), with no arguments. That
  100. function is responsible for calling a driver init function for
  101. each NAND device on the board, that performs all initialization
  102. tasks except setting mtd->name, and registering with the rest of
  103. U-Boot. Those last tasks are accomplished by calling nand_register()
  104. on the new mtd device.
  105. Example of new init to be added to the end of an existing driver
  106. init:
  107. /* chip is struct nand_chip, and is now provided by the driver. */
  108. mtd = nand_to_mtd(&chip);
  109. /*
  110. * Fill in appropriate values if this driver uses these fields,
  111. * or uses the standard read_byte/write_buf/etc. functions from
  112. * nand_base.c that use these fields.
  113. */
  114. chip.IO_ADDR_R = ...;
  115. chip.IO_ADDR_W = ...;
  116. if (nand_scan_ident(mtd, CONFIG_SYS_MAX_NAND_CHIPS, NULL))
  117. error out
  118. /*
  119. * Insert here any code you wish to run after the chip has been
  120. * identified, but before any other I/O is done.
  121. */
  122. if (nand_scan_tail(mtd))
  123. error out
  124. /*
  125. * devnum is the device number to be used in nand commands
  126. * and in mtd->name. Must be less than CONFIG_SYS_MAX_NAND_DEVICE.
  127. */
  128. if (nand_register(devnum, mtd))
  129. error out
  130. In addition to providing more flexibility to the driver, it reduces
  131. the difference between a U-Boot driver and its Linux counterpart.
  132. nand_init() is now reduced to calling board_nand_init() once, and
  133. printing a size summary. This should also make it easier to
  134. transition to delayed NAND initialization.
  135. Please convert your driver even if you don't need the extra
  136. flexibility, so that one day we can eliminate the old mechanism.
  137. Platform specific options
  138. =========================
  139. CONFIG_NAND_OMAP_GPMC
  140. Enables omap_gpmc.c driver for OMAPx and AMxxxx platforms.
  141. GPMC controller is used for parallel NAND flash devices, and can
  142. do ECC calculation (not ECC error detection) for HAM1, BCH4, BCH8
  143. and BCH16 ECC algorithms.
  144. CONFIG_NAND_OMAP_ELM
  145. Enables omap_elm.c driver for OMAPx and AMxxxx platforms.
  146. ELM controller is used for ECC error detection (not ECC calculation)
  147. of BCH4, BCH8 and BCH16 ECC algorithms.
  148. Some legacy platforms like OMAP3xx do not have in-built ELM h/w engine,
  149. thus such SoC platforms need to depend on software library for ECC error
  150. detection. However ECC calculation on such plaforms would still be
  151. done by GPMC controller.
  152. CONFIG_SPL_NAND_AM33XX_BCH
  153. Enables SPL-NAND driver (am335x_spl_bch.c) which supports ELM based
  154. hardware ECC correction. This is useful for platforms which have ELM
  155. hardware engine and use NAND boot mode.
  156. Some legacy platforms like OMAP3xx do not have in-built ELM h/w engine,
  157. so those platforms should use CONFIG_SPL_NAND_SIMPLE for enabling
  158. SPL-NAND driver with software ECC correction support.
  159. CONFIG_NAND_OMAP_GPMC_PREFETCH
  160. On OMAP platforms that use the GPMC controller
  161. (CONFIG_NAND_OMAP_GPMC_PREFETCH), this options enables the code that
  162. uses the prefetch mode to speed up read operations.
  163. NOTE:
  164. =====
  165. The Disk On Chip driver is currently broken and has been for some time.
  166. There is a driver in drivers/mtd/nand/raw, taken from Linux, that works with
  167. the current NAND system but has not yet been adapted to the u-boot
  168. environment.
  169. Additional improvements to the NAND subsystem by Guido Classen, 10-10-2006
  170. JFFS2 related commands:
  171. implement "nand erase clean" and old "nand erase"
  172. using both the new code which is able to skip bad blocks
  173. "nand erase clean" additionally writes JFFS2-cleanmarkers in the oob.
  174. Miscellaneous and testing commands:
  175. "markbad [offset]"
  176. create an artificial bad block (for testing bad block handling)
  177. "scrub [offset length]"
  178. like "erase" but don't skip bad block. Instead erase them.
  179. DANGEROUS!!! Factory set bad blocks will be lost. Use only
  180. to remove artificial bad blocks created with the "markbad" command.
  181. "torture offset [size]"
  182. Torture block to determine if it is still reliable.
  183. Enabled by the CONFIG_CMD_NAND_TORTURE configuration option.
  184. This command returns 0 if the block is still reliable, else 1.
  185. If the block is detected as unreliable, it is up to the user to decide to
  186. mark this block as bad.
  187. The analyzed block is put through 3 erase / write cycles (or less if the block
  188. is detected as unreliable earlier).
  189. This command can be used in scripts, e.g. together with the markbad command to
  190. automate retries and handling of possibly newly detected bad blocks if the
  191. nand write command fails.
  192. It can also be used manually by users having seen some NAND errors in logs to
  193. search the root cause of these errors.
  194. The underlying nand_torture() function is also useful for code willing to
  195. automate actions following a nand->write() error. This would e.g. be required
  196. in order to program or update safely firmware to NAND, especially for the UBI
  197. part of such firmware.
  198. Optionally, a second parameter size can be given to test multiple blocks with
  199. one call. If size is not a multiple of the NAND's erase size, then the block
  200. that contains offset + size will be tested in full. If used with size, this
  201. command returns 0 if all tested blocks have been found reliable, else 1.
  202. NAND locking command (for chips with active LOCKPRE pin)
  203. "nand lock"
  204. set NAND chip to lock state (all pages locked)
  205. "nand lock tight"
  206. set NAND chip to lock tight state (software can't change locking anymore)
  207. "nand lock status"
  208. displays current locking status of all pages
  209. "nand unlock [offset] [size]"
  210. unlock consecutive area (can be called multiple times for different areas)
  211. "nand unlock.allexcept [offset] [size]"
  212. unlock all except specified consecutive area
  213. I have tested the code with board containing 128MiB NAND large page chips
  214. and 32MiB small page chips.