blob: b5171f4d407c6d602100bb9b15993754d6d0c921 [file] [log] [blame]
wdenk7a8e9bed2003-05-31 18:35:21 +00001NAND FLASH commands and notes
2
Wolfgang Denk4e3ccd22006-03-06 11:25:22 +01003See NOTE below!!!
4
wdenk7a8e9bed2003-05-31 18:35:21 +00005# (C) Copyright 2003
6# Dave Ellis, SIXNET, dge@sixnetio.com
7#
8# See file CREDITS for list of people who contributed to this
9# project.
10#
11# This program is free software; you can redistribute it and/or
12# modify it under the terms of the GNU General Public License as
13# published by the Free Software Foundation; either version 2 of
14# the License, or (at your option) any later version.
15#
16# This program is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License
22# along with this program; if not, write to the Free Software
23# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24# MA 02111-1307 USA
25
26Commands:
27
28 nand bad
29 Print a list of all of the bad blocks in the current device.
30
31 nand device
32 Print information about the current NAND device.
33
34 nand device num
35 Make device `num' the current device and print information about it.
36
Stefan Roese856f0542006-10-28 15:55:52 +020037 nand erase off|partition size
38 nand erase clean [off|partition size]
39 Erase `size' bytes starting at offset `off'. Alternatively partition
40 name can be specified, in this case size will be eventually limited
41 to not exceed partition size (this behaviour applies also to read
42 and write commands). Only complete erase blocks can be erased.
43
44 If `erase' is specified without an offset or size, the entire flash
45 is erased. If `erase' is specified with partition but without an
46 size, the entire partition is erased.
wdenk7a8e9bed2003-05-31 18:35:21 +000047
48 If `clean' is specified, a JFFS2-style clean marker is written to
Stefan Roese856f0542006-10-28 15:55:52 +020049 each block after it is erased.
wdenk7a8e9bed2003-05-31 18:35:21 +000050
51 This command will not erase blocks that are marked bad. There is
52 a debug option in cmd_nand.c to allow bad blocks to be erased.
53 Please read the warning there before using it, as blocks marked
54 bad by the manufacturer must _NEVER_ be erased.
55
56 nand info
57 Print information about all of the NAND devices found.
58
Stefan Roese856f0542006-10-28 15:55:52 +020059 nand read addr ofs|partition size
wdenk7a8e9bed2003-05-31 18:35:21 +000060 Read `size' bytes from `ofs' in NAND flash to `addr'. If a page
61 cannot be read because it is marked bad or an uncorrectable data
wdenk8bde7f72003-06-27 21:31:46 +000062 error is found the command stops with an error.
wdenk7a8e9bed2003-05-31 18:35:21 +000063
Stefan Roese856f0542006-10-28 15:55:52 +020064 nand read.jffs2 addr ofs|partition size
wdenk7a8e9bed2003-05-31 18:35:21 +000065 Like `read', but the data for blocks that are marked bad is read as
66 0xff. This gives a readable JFFS2 image that can be processed by
67 the JFFS2 commands such as ls and fsload.
68
Stefan Roese856f0542006-10-28 15:55:52 +020069 nand read.oob addr ofs|partition size
wdenk7a8e9bed2003-05-31 18:35:21 +000070 Read `size' bytes from the out-of-band data area corresponding to
71 `ofs' in NAND flash to `addr'. This is limited to the 16 bytes of
72 data for one 512-byte page or 2 256-byte pages. There is no check
73 for bad blocks or ECC errors.
74
Stefan Roese856f0542006-10-28 15:55:52 +020075 nand write addr ofs|partition size
wdenk7a8e9bed2003-05-31 18:35:21 +000076 Write `size' bytes from `addr' to `ofs' in NAND flash. If a page
77 cannot be written because it is marked bad or the write fails the
wdenk8bde7f72003-06-27 21:31:46 +000078 command stops with an error.
wdenk7a8e9bed2003-05-31 18:35:21 +000079
Stefan Roese856f0542006-10-28 15:55:52 +020080 nand write.jffs2 addr ofs|partition size
wdenk7a8e9bed2003-05-31 18:35:21 +000081 Like `write', but blocks that are marked bad are skipped and the
82 is written to the next block instead. This allows writing writing
83 a JFFS2 image, as long as the image is short enough to fit even
84 after skipping the bad blocks. Compact images, such as those
85 produced by mkfs.jffs2 should work well, but loading an image copied
86 from another flash is going to be trouble if there are any bad blocks.
87
Stefan Roese856f0542006-10-28 15:55:52 +020088 nand write.oob addr ofs|partition size
wdenk7a8e9bed2003-05-31 18:35:21 +000089 Write `size' bytes from `addr' to the out-of-band data area
90 corresponding to `ofs' in NAND flash. This is limited to the 16 bytes
91 of data for one 512-byte page or 2 256-byte pages. There is no check
92 for bad blocks.
93
94Configuration Options:
95
96 CFG_CMD_NAND
97 A good one to add to CONFIG_COMMANDS since it enables NAND support.
98
99 CONFIG_MTD_NAND_ECC_JFFS2
100 Define this if you want the Error Correction Code information in
101 the out-of-band data to be formatted to match the JFFS2 file system.
102 CONFIG_MTD_NAND_ECC_YAFFS would be another useful choice for
103 someone to implement.
104
105 CFG_MAX_NAND_DEVICE
106 The maximum number of NAND devices you want to support.
107
108NAND Interface:
109
110 #define NAND_WAIT_READY(nand)
111 Wait until the NAND flash is ready. Typically this would be a
112 loop waiting for the READY/BUSY line from the flash to indicate it
113 it is ready.
114
115 #define WRITE_NAND_COMMAND(d, adr)
116 Write the command byte `d' to the flash at `adr' with the
117 CLE (command latch enable) line true. If your board uses writes to
118 different addresses to control CLE and ALE, you can modify `adr'
119 to be the appropriate address here. If your board uses I/O registers
120 to control them, it is probably better to let NAND_CTL_SETCLE()
121 and company do it.
122
123 #define WRITE_NAND_ADDRESS(d, adr)
124 Write the address byte `d' to the flash at `adr' with the
125 ALE (address latch enable) line true. If your board uses writes to
126 different addresses to control CLE and ALE, you can modify `adr'
127 to be the appropriate address here. If your board uses I/O registers
128 to control them, it is probably better to let NAND_CTL_SETALE()
129 and company do it.
130
131 #define WRITE_NAND(d, adr)
132 Write the data byte `d' to the flash at `adr' with the
133 ALE and CLE lines false. If your board uses writes to
134 different addresses to control CLE and ALE, you can modify `adr'
135 to be the appropriate address here. If your board uses I/O registers
136 to control them, it is probably better to let NAND_CTL_CLRALE()
137 and company do it.
138
139 #define READ_NAND(adr)
140 Read a data byte from the flash at `adr' with the
141 ALE and CLE lines false. If your board uses reads from
142 different addresses to control CLE and ALE, you can modify `adr'
143 to be the appropriate address here. If your board uses I/O registers
144 to control them, it is probably better to let NAND_CTL_CLRALE()
145 and company do it.
146
147 #define NAND_DISABLE_CE(nand)
148 Set CE (Chip Enable) low to enable the NAND flash.
149
150 #define NAND_ENABLE_CE(nand)
151 Set CE (Chip Enable) high to disable the NAND flash.
152
153 #define NAND_CTL_CLRALE(nandptr)
154 Set ALE (address latch enable) low. If ALE control is handled by
155 WRITE_NAND_ADDRESS() this can be empty.
156
157 #define NAND_CTL_SETALE(nandptr)
158 Set ALE (address latch enable) high. If ALE control is handled by
159 WRITE_NAND_ADDRESS() this can be empty.
160
161 #define NAND_CTL_CLRCLE(nandptr)
162 Set CLE (command latch enable) low. If CLE control is handled by
163 WRITE_NAND_ADDRESS() this can be empty.
164
165 #define NAND_CTL_SETCLE(nandptr)
166 Set CLE (command latch enable) high. If CLE control is handled by
167 WRITE_NAND_ADDRESS() this can be empty.
wdenk8bde7f72003-06-27 21:31:46 +0000168
wdenk7a8e9bed2003-05-31 18:35:21 +0000169More Definitions:
170
171 These definitions are needed in the board configuration for now, but
172 may really belong in a header file.
173 TODO: Figure which ones are truly configuration settings and rename
wdenk8bde7f72003-06-27 21:31:46 +0000174 them to CFG_NAND_... and move the rest somewhere appropriate.
wdenk7a8e9bed2003-05-31 18:35:21 +0000175
176 #define SECTORSIZE 512
177 #define ADDR_COLUMN 1
178 #define ADDR_PAGE 2
179 #define ADDR_COLUMN_PAGE 3
180 #define NAND_ChipID_UNKNOWN 0x00
181 #define NAND_MAX_FLOORS 1
182 #define NAND_MAX_CHIPS 1
Wolfgang Denk4e3ccd22006-03-06 11:25:22 +0100183
184
Wolfgang Denk4e3ccd22006-03-06 11:25:22 +0100185NOTE:
186=====
187
188We now use a complete rewrite of the NAND code based on what is in
1892.6.12 Linux kernel.
190
191The old NAND handling code has been re-factored and is now confined
192to only board-specific files and - unfortunately - to the DoC code
193(see below). A new configuration variable has been introduced:
194CFG_NAND_LEGACY, which has to be defined in the board config file if
195that board uses legacy code. If CFG_NAND_LEGACY is defined, the board
196specific config.mk file should also have "BOARDLIBS =
197drivers/nand_legacy/libnand_legacy.a". For boards using the new NAND
198approach (PPChameleon and netstar at the moment) no variable is
199necessary, but the config.mk should have "BOARDLIBS =
200drivers/nand/libnand.a".
201
202The necessary changes have been made to all affected boards, and no
203build breakage has been introduced, except for NETTA and NETTA_ISDN
204targets from MAKEALL. This is due to the fact that these two boards
205use JFFS, which has been adopted to use the new NAND, and at the same
206time use NAND in legacy mode. The breakage will disappear when the
207board-specific code is changed to the new NAND.
208
Wolfgang Denkbfc81252006-03-06 13:03:37 +0100209As mentioned above, the legacy code is still used by the DoC subsystem.
210The consequence of this is that the legacy NAND can't be removed from
211the tree until the DoC is ported to use the new NAND support (or boards
Wolfgang Denk4e3ccd22006-03-06 11:25:22 +0100212with DoC will break).
Stefan Roese2255b2d2006-10-10 12:36:02 +0200213
214
Stefan Roese2255b2d2006-10-10 12:36:02 +0200215Additional improvements to the NAND subsystem by Guido Classen, 10-10-2006
216
217JFFS2 related commands:
218
219 implement "nand erase clean" and old "nand erase"
220 using both the new code which is able to skip bad blocks
221 "nand erase clean" additionally writes JFFS2-cleanmarkers in the oob.
222
223 "nand write.jffs2"
224 like "nand write" but skip found bad eraseblocks
225
226 "nand read.jffs2"
227 like "nand read" but skip found bad eraseblocks
228
229Miscellaneous and testing commands:
230 "markbad [offset]"
231 create an artificial bad block (for testing bad block handling)
232
233 "scrub [offset length]"
234 like "erase" but don't skip bad block. Instead erase them.
235 DANGEROUS!!! Factory set bad blocks will be lost. Use only
236 to remove artificial bad blocks created with the "markbad" command.
237
238
239NAND locking command (for chips with active LOCKPRE pin)
240
241 "nand lock"
242 set NAND chip to lock state (all pages locked)
243
244 "nand lock tight"
245 set NAND chip to lock tight state (software can't change locking anymore)
246
247 "nand lock status"
248 displays current locking status of all pages
249
250 "nand unlock [offset] [size]"
251 unlock consecutive area (can be called multiple times for different areas)
252
253
254I have tested the code with board containing 128MiB NAND large page chips
255and 32MiB small page chips.