]>
Commit | Line | Data |
---|---|---|
dc7c9a1a WD |
1 | /* |
2 | * Driver for NAND support, Rick Bronson | |
3 | * borrowed heavily from: | |
4 | * (c) 1999 Machine Vision Holdings, Inc. | |
5 | * (c) 1999, 2000 David Woodhouse <[email protected]> | |
384cc687 | 6 | * |
c9f7351b BG |
7 | * Ported 'dynenv' to 'nand env.oob' command |
8 | * (C) 2010 Nanometrics, Inc. | |
9 | * 'dynenv' -- Dynamic environment offset in NAND OOB | |
10 | * (C) Copyright 2006-2007 OpenMoko, Inc. | |
384cc687 WD |
11 | * Added 16-bit nand support |
12 | * (C) 2004 Texas Instruments | |
ea533c26 | 13 | * |
418396e2 | 14 | * Copyright 2010, 2012 Freescale Semiconductor |
ea533c26 SW |
15 | * The portions of this file whose copyright is held by Freescale and which |
16 | * are not considered a derived work of GPL v2-only code may be distributed | |
17 | * and/or modified under the terms of the GNU General Public License as | |
18 | * published by the Free Software Foundation; either version 2 of the | |
19 | * License, or (at your option) any later version. | |
dc7c9a1a WD |
20 | */ |
21 | ||
22 | #include <common.h> | |
cfa460ad | 23 | #include <linux/mtd/mtd.h> |
addb2e16 | 24 | #include <command.h> |
24b852a7 | 25 | #include <console.h> |
addb2e16 BS |
26 | #include <watchdog.h> |
27 | #include <malloc.h> | |
28 | #include <asm/byteorder.h> | |
addb2e16 BS |
29 | #include <jffs2/jffs2.h> |
30 | #include <nand.h> | |
31 | ||
0c8a8491 | 32 | #if defined(CONFIG_CMD_MTDPARTS) |
856f0544 | 33 | |
445093d1 | 34 | /* partition handling routines */ |
856f0544 SR |
35 | int mtdparts_init(void); |
36 | int id_parse(const char *id, const char **ret_id, u8 *dev_type, u8 *dev_num); | |
37 | int find_dev_and_part(const char *id, struct mtd_device **dev, | |
4b070809 | 38 | u8 *part_num, struct part_info **part); |
856f0544 SR |
39 | #endif |
40 | ||
151c06ec SW |
41 | static int nand_dump(struct mtd_info *mtd, ulong off, int only_oob, |
42 | int repeat) | |
addb2e16 BS |
43 | { |
44 | int i; | |
9ad754fe | 45 | u_char *datbuf, *oobbuf, *p; |
8c5659a6 | 46 | static loff_t last; |
e40520b5 | 47 | int ret = 0; |
8c5659a6 SW |
48 | |
49 | if (repeat) | |
151c06ec | 50 | off = last + mtd->writesize; |
8c5659a6 SW |
51 | |
52 | last = off; | |
addb2e16 | 53 | |
151c06ec | 54 | datbuf = memalign(ARCH_DMA_MINALIGN, mtd->writesize); |
e40520b5 | 55 | if (!datbuf) { |
addb2e16 BS |
56 | puts("No memory for page buffer\n"); |
57 | return 1; | |
58 | } | |
e40520b5 | 59 | |
151c06ec | 60 | oobbuf = memalign(ARCH_DMA_MINALIGN, mtd->oobsize); |
e40520b5 MY |
61 | if (!oobbuf) { |
62 | puts("No memory for page buffer\n"); | |
63 | ret = 1; | |
64 | goto free_dat; | |
65 | } | |
151c06ec | 66 | off &= ~(mtd->writesize - 1); |
cfa460ad | 67 | loff_t addr = (loff_t) off; |
9ad754fe WJ |
68 | struct mtd_oob_ops ops; |
69 | memset(&ops, 0, sizeof(ops)); | |
70 | ops.datbuf = datbuf; | |
cfdae12f | 71 | ops.oobbuf = oobbuf; |
151c06ec SW |
72 | ops.len = mtd->writesize; |
73 | ops.ooblen = mtd->oobsize; | |
dfe64e2c | 74 | ops.mode = MTD_OPS_RAW; |
151c06ec | 75 | i = mtd_read_oob(mtd, addr, &ops); |
addb2e16 | 76 | if (i < 0) { |
e870690b | 77 | printf("Error (%d) reading page %08lx\n", i, off); |
e40520b5 MY |
78 | ret = 1; |
79 | goto free_all; | |
addb2e16 | 80 | } |
e870690b | 81 | printf("Page %08lx dump:\n", off); |
4b070809 | 82 | |
7d25cd34 | 83 | if (!only_oob) { |
151c06ec | 84 | i = mtd->writesize >> 4; |
7d25cd34 MY |
85 | p = datbuf; |
86 | ||
87 | while (i--) { | |
9ad754fe WJ |
88 | printf("\t%02x %02x %02x %02x %02x %02x %02x %02x" |
89 | " %02x %02x %02x %02x %02x %02x %02x %02x\n", | |
90 | p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], | |
dfbf617f SW |
91 | p[8], p[9], p[10], p[11], p[12], p[13], p[14], |
92 | p[15]); | |
7d25cd34 MY |
93 | p += 16; |
94 | } | |
addb2e16 | 95 | } |
7d25cd34 | 96 | |
addb2e16 | 97 | puts("OOB:\n"); |
151c06ec | 98 | i = mtd->oobsize >> 3; |
cfdae12f | 99 | p = oobbuf; |
addb2e16 | 100 | while (i--) { |
cfa460ad WJ |
101 | printf("\t%02x %02x %02x %02x %02x %02x %02x %02x\n", |
102 | p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); | |
addb2e16 BS |
103 | p += 8; |
104 | } | |
e40520b5 MY |
105 | |
106 | free_all: | |
9ad754fe | 107 | free(oobbuf); |
e40520b5 MY |
108 | free_dat: |
109 | free(datbuf); | |
addb2e16 | 110 | |
e40520b5 | 111 | return ret; |
addb2e16 BS |
112 | } |
113 | ||
114 | /* ------------------------------------------------------------------------- */ | |
115 | ||
ea533c26 SW |
116 | static int set_dev(int dev) |
117 | { | |
1cfce74f | 118 | if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE || !nand_info[dev]) { |
ea533c26 SW |
119 | puts("No such device\n"); |
120 | return -1; | |
121 | } | |
122 | ||
123 | if (nand_curr_device == dev) | |
124 | return 0; | |
125 | ||
b616d9b0 | 126 | printf("Device %d: %s", dev, nand_info[dev]->name); |
ea533c26 SW |
127 | puts("... is now current device\n"); |
128 | nand_curr_device = dev; | |
129 | ||
130 | #ifdef CONFIG_SYS_NAND_SELECT_DEVICE | |
b616d9b0 | 131 | board_nand_select_device(nand_info[dev]->priv, dev); |
ea533c26 SW |
132 | #endif |
133 | ||
134 | return 0; | |
135 | } | |
136 | ||
50657c27 NM |
137 | #ifdef CONFIG_CMD_NAND_LOCK_UNLOCK |
138 | static void print_status(ulong start, ulong end, ulong erasesize, int status) | |
139 | { | |
e70bfa29 JH |
140 | /* |
141 | * Micron NAND flash (e.g. MT29F4G08ABADAH4) BLOCK LOCK READ STATUS is | |
142 | * not the same as others. Instead of bit 1 being lock, it is | |
143 | * #lock_tight. To make the driver support either format, ignore bit 1 | |
144 | * and use only bit 0 and bit 2. | |
145 | */ | |
50657c27 NM |
146 | printf("%08lx - %08lx: %08lx blocks %s%s%s\n", |
147 | start, | |
148 | end - 1, | |
149 | (end - start) / erasesize, | |
150 | ((status & NAND_LOCK_STATUS_TIGHT) ? "TIGHT " : ""), | |
e70bfa29 | 151 | (!(status & NAND_LOCK_STATUS_UNLOCK) ? "LOCK " : ""), |
50657c27 NM |
152 | ((status & NAND_LOCK_STATUS_UNLOCK) ? "UNLOCK " : "")); |
153 | } | |
154 | ||
151c06ec | 155 | static void do_nand_status(struct mtd_info *mtd) |
50657c27 NM |
156 | { |
157 | ulong block_start = 0; | |
158 | ulong off; | |
159 | int last_status = -1; | |
160 | ||
17cb4b8f | 161 | struct nand_chip *nand_chip = mtd_to_nand(mtd); |
50657c27 | 162 | /* check the WP bit */ |
151c06ec | 163 | nand_chip->cmdfunc(mtd, NAND_CMD_STATUS, -1, -1); |
50657c27 | 164 | printf("device is %swrite protected\n", |
151c06ec SW |
165 | (nand_chip->read_byte(mtd) & 0x80 ? |
166 | "NOT " : "")); | |
50657c27 | 167 | |
151c06ec SW |
168 | for (off = 0; off < mtd->size; off += mtd->erasesize) { |
169 | int s = nand_get_lock_status(mtd, off); | |
50657c27 NM |
170 | |
171 | /* print message only if status has changed */ | |
172 | if (s != last_status && off != 0) { | |
151c06ec | 173 | print_status(block_start, off, mtd->erasesize, |
50657c27 NM |
174 | last_status); |
175 | block_start = off; | |
176 | } | |
177 | last_status = s; | |
178 | } | |
179 | /* Print the last block info */ | |
151c06ec | 180 | print_status(block_start, off, mtd->erasesize, last_status); |
50657c27 NM |
181 | } |
182 | #endif | |
183 | ||
c9f7351b BG |
184 | #ifdef CONFIG_ENV_OFFSET_OOB |
185 | unsigned long nand_env_oob_offset; | |
186 | ||
ea533c26 | 187 | int do_nand_env_oob(cmd_tbl_t *cmdtp, int argc, char *const argv[]) |
c9f7351b BG |
188 | { |
189 | int ret; | |
190 | uint32_t oob_buf[ENV_OFFSET_SIZE/sizeof(uint32_t)]; | |
b616d9b0 | 191 | struct mtd_info *mtd = nand_info[0]; |
c9f7351b BG |
192 | char *cmd = argv[1]; |
193 | ||
8b7d5124 | 194 | if (CONFIG_SYS_MAX_NAND_DEVICE == 0 || !mtd) { |
ea533c26 SW |
195 | puts("no devices available\n"); |
196 | return 1; | |
197 | } | |
198 | ||
199 | set_dev(0); | |
200 | ||
c9f7351b | 201 | if (!strcmp(cmd, "get")) { |
151c06ec | 202 | ret = get_nand_env_oob(mtd, &nand_env_oob_offset); |
53504a27 | 203 | if (ret) |
c9f7351b | 204 | return 1; |
53504a27 SW |
205 | |
206 | printf("0x%08lx\n", nand_env_oob_offset); | |
c9f7351b | 207 | } else if (!strcmp(cmd, "set")) { |
ea533c26 SW |
208 | loff_t addr; |
209 | loff_t maxsize; | |
c9f7351b | 210 | struct mtd_oob_ops ops; |
ea533c26 | 211 | int idx = 0; |
c9f7351b BG |
212 | |
213 | if (argc < 3) | |
214 | goto usage; | |
215 | ||
c39d6a0e | 216 | /* We don't care about size, or maxsize. */ |
09c32807 | 217 | if (mtd_arg_off(argv[2], &idx, &addr, &maxsize, &maxsize, |
b616d9b0 | 218 | MTD_DEV_TYPE_NAND, nand_info[idx]->size)) { |
09c32807 HS |
219 | puts("Offset or partition name expected\n"); |
220 | return 1; | |
221 | } | |
222 | if (set_dev(idx)) { | |
ea533c26 SW |
223 | puts("Offset or partition name expected\n"); |
224 | return 1; | |
225 | } | |
226 | ||
227 | if (idx != 0) { | |
228 | puts("Partition not on first NAND device\n"); | |
c9f7351b BG |
229 | return 1; |
230 | } | |
231 | ||
151c06ec | 232 | if (mtd->oobavail < ENV_OFFSET_SIZE) { |
53504a27 SW |
233 | printf("Insufficient available OOB bytes:\n" |
234 | "%d OOB bytes available but %d required for " | |
235 | "env.oob support\n", | |
151c06ec | 236 | mtd->oobavail, ENV_OFFSET_SIZE); |
c9f7351b BG |
237 | return 1; |
238 | } | |
239 | ||
151c06ec | 240 | if ((addr & (mtd->erasesize - 1)) != 0) { |
c9f7351b BG |
241 | printf("Environment offset must be block-aligned\n"); |
242 | return 1; | |
243 | } | |
244 | ||
245 | ops.datbuf = NULL; | |
246 | ops.mode = MTD_OOB_AUTO; | |
247 | ops.ooboffs = 0; | |
248 | ops.ooblen = ENV_OFFSET_SIZE; | |
249 | ops.oobbuf = (void *) oob_buf; | |
250 | ||
251 | oob_buf[0] = ENV_OOB_MARKER; | |
151c06ec | 252 | oob_buf[1] = addr / mtd->erasesize; |
c9f7351b | 253 | |
151c06ec | 254 | ret = mtd->write_oob(mtd, ENV_OFFSET_SIZE, &ops); |
53504a27 | 255 | if (ret) { |
c9f7351b BG |
256 | printf("Error writing OOB block 0\n"); |
257 | return ret; | |
258 | } | |
53504a27 | 259 | |
151c06ec | 260 | ret = get_nand_env_oob(mtd, &nand_env_oob_offset); |
53504a27 SW |
261 | if (ret) { |
262 | printf("Error reading env offset in OOB\n"); | |
263 | return ret; | |
264 | } | |
265 | ||
266 | if (addr != nand_env_oob_offset) { | |
267 | printf("Verification of env offset in OOB failed: " | |
ea533c26 SW |
268 | "0x%08llx expected but got 0x%08lx\n", |
269 | (unsigned long long)addr, nand_env_oob_offset); | |
53504a27 SW |
270 | return 1; |
271 | } | |
c9f7351b BG |
272 | } else { |
273 | goto usage; | |
274 | } | |
275 | ||
276 | return ret; | |
277 | ||
278 | usage: | |
4c12eeb8 | 279 | return CMD_RET_USAGE; |
c9f7351b BG |
280 | } |
281 | ||
282 | #endif | |
283 | ||
ce80ddc1 | 284 | static void nand_print_and_set_info(int idx) |
672ed2ae | 285 | { |
b616d9b0 | 286 | struct mtd_info *mtd = nand_info[idx]; |
17cb4b8f | 287 | struct nand_chip *chip = mtd_to_nand(mtd); |
ce80ddc1 | 288 | |
672ed2ae WG |
289 | printf("Device %d: ", idx); |
290 | if (chip->numchips > 1) | |
291 | printf("%dx ", chip->numchips); | |
292 | printf("%s, sector size %u KiB\n", | |
151c06ec SW |
293 | mtd->name, mtd->erasesize >> 10); |
294 | printf(" Page size %8d b\n", mtd->writesize); | |
295 | printf(" OOB size %8d b\n", mtd->oobsize); | |
296 | printf(" Erase size %8d b\n", mtd->erasesize); | |
5db73feb HS |
297 | printf(" subpagesize %8d b\n", chip->subpagesize); |
298 | printf(" options 0x%8x\n", chip->options); | |
299 | printf(" bbt options 0x%8x\n", chip->bbt_options); | |
ce80ddc1 MV |
300 | |
301 | /* Set geometry info */ | |
151c06ec SW |
302 | setenv_hex("nand_writesize", mtd->writesize); |
303 | setenv_hex("nand_oobsize", mtd->oobsize); | |
304 | setenv_hex("nand_erasesize", mtd->erasesize); | |
672ed2ae WG |
305 | } |
306 | ||
151c06ec | 307 | static int raw_access(struct mtd_info *mtd, ulong addr, loff_t off, |
2dc3c483 | 308 | ulong count, int read, int no_verify) |
418396e2 SW |
309 | { |
310 | int ret = 0; | |
418396e2 SW |
311 | |
312 | while (count--) { | |
313 | /* Raw access */ | |
314 | mtd_oob_ops_t ops = { | |
315 | .datbuf = (u8 *)addr, | |
151c06ec SW |
316 | .oobbuf = ((u8 *)addr) + mtd->writesize, |
317 | .len = mtd->writesize, | |
318 | .ooblen = mtd->oobsize, | |
dfe64e2c | 319 | .mode = MTD_OPS_RAW |
418396e2 SW |
320 | }; |
321 | ||
6b94f118 | 322 | if (read) { |
151c06ec | 323 | ret = mtd_read_oob(mtd, off, &ops); |
6b94f118 | 324 | } else { |
151c06ec | 325 | ret = mtd_write_oob(mtd, off, &ops); |
2dc3c483 | 326 | if (!ret && !no_verify) |
151c06ec | 327 | ret = nand_verify_page_oob(mtd, &ops, off); |
6b94f118 | 328 | } |
418396e2 SW |
329 | |
330 | if (ret) { | |
331 | printf("%s: error at offset %llx, ret %d\n", | |
332 | __func__, (long long)off, ret); | |
333 | break; | |
334 | } | |
335 | ||
151c06ec SW |
336 | addr += mtd->writesize + mtd->oobsize; |
337 | off += mtd->writesize; | |
418396e2 SW |
338 | } |
339 | ||
340 | return ret; | |
341 | } | |
342 | ||
e834402f | 343 | /* Adjust a chip/partition size down for bad blocks so we don't |
9b80aa8e | 344 | * read/write past the end of a chip/partition by accident. |
e834402f HC |
345 | */ |
346 | static void adjust_size_for_badblocks(loff_t *size, loff_t offset, int dev) | |
347 | { | |
348 | /* We grab the nand info object here fresh because this is usually | |
349 | * called after arg_off_size() which can change the value of dev. | |
350 | */ | |
b616d9b0 | 351 | struct mtd_info *mtd = nand_info[dev]; |
e834402f HC |
352 | loff_t maxoffset = offset + *size; |
353 | int badblocks = 0; | |
354 | ||
355 | /* count badblocks in NAND from offset to offset + size */ | |
151c06ec SW |
356 | for (; offset < maxoffset; offset += mtd->erasesize) { |
357 | if (nand_block_isbad(mtd, offset)) | |
e834402f HC |
358 | badblocks++; |
359 | } | |
360 | /* adjust size if any bad blocks found */ | |
361 | if (badblocks) { | |
151c06ec | 362 | *size -= badblocks * mtd->erasesize; |
e834402f HC |
363 | printf("size adjusted to 0x%llx (%d bad blocks)\n", |
364 | (unsigned long long)*size, badblocks); | |
365 | } | |
366 | } | |
367 | ||
088f1b19 | 368 | static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
addb2e16 | 369 | { |
ea533c26 SW |
370 | int i, ret = 0; |
371 | ulong addr; | |
c39d6a0e | 372 | loff_t off, size, maxsize; |
addb2e16 | 373 | char *cmd, *s; |
151c06ec | 374 | struct mtd_info *mtd; |
6d0f6bcf JCPV |
375 | #ifdef CONFIG_SYS_NAND_QUIET |
376 | int quiet = CONFIG_SYS_NAND_QUIET; | |
c750d2e6 | 377 | #else |
2255b2d2 | 378 | int quiet = 0; |
c750d2e6 | 379 | #endif |
2255b2d2 | 380 | const char *quiet_str = getenv("quiet"); |
ea533c26 | 381 | int dev = nand_curr_device; |
8c5659a6 | 382 | int repeat = flag & CMD_FLAG_REPEAT; |
addb2e16 BS |
383 | |
384 | /* at least two arguments please */ | |
385 | if (argc < 2) | |
386 | goto usage; | |
387 | ||
2255b2d2 SR |
388 | if (quiet_str) |
389 | quiet = simple_strtoul(quiet_str, NULL, 0) != 0; | |
390 | ||
addb2e16 BS |
391 | cmd = argv[1]; |
392 | ||
8c5659a6 SW |
393 | /* Only "dump" is repeatable. */ |
394 | if (repeat && strcmp(cmd, "dump")) | |
395 | return 0; | |
396 | ||
addb2e16 BS |
397 | if (strcmp(cmd, "info") == 0) { |
398 | ||
399 | putc('\n'); | |
6d0f6bcf | 400 | for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) { |
4004a818 | 401 | if (nand_info[i]) |
ce80ddc1 | 402 | nand_print_and_set_info(i); |
addb2e16 BS |
403 | } |
404 | return 0; | |
405 | } | |
406 | ||
407 | if (strcmp(cmd, "device") == 0) { | |
addb2e16 | 408 | if (argc < 3) { |
672ed2ae | 409 | putc('\n'); |
ea533c26 | 410 | if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE) |
672ed2ae | 411 | puts("no devices available\n"); |
addb2e16 | 412 | else |
ce80ddc1 | 413 | nand_print_and_set_info(dev); |
addb2e16 BS |
414 | return 0; |
415 | } | |
43a2b0e7 | 416 | |
ea533c26 SW |
417 | dev = (int)simple_strtoul(argv[2], NULL, 10); |
418 | set_dev(dev); | |
43a2b0e7 | 419 | |
addb2e16 BS |
420 | return 0; |
421 | } | |
422 | ||
c9f7351b BG |
423 | #ifdef CONFIG_ENV_OFFSET_OOB |
424 | /* this command operates only on the first nand device */ | |
ea533c26 SW |
425 | if (strcmp(cmd, "env.oob") == 0) |
426 | return do_nand_env_oob(cmdtp, argc - 1, argv + 1); | |
c9f7351b BG |
427 | #endif |
428 | ||
ea533c26 SW |
429 | /* The following commands operate on the current device, unless |
430 | * overridden by a partition specifier. Note that if somehow the | |
431 | * current device is invalid, it will have to be changed to a valid | |
432 | * one before these commands can run, even if a partition specifier | |
433 | * for another device is to be used. | |
434 | */ | |
435 | if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE || | |
4004a818 | 436 | !nand_info[dev]) { |
addb2e16 BS |
437 | puts("\nno devices available\n"); |
438 | return 1; | |
439 | } | |
b616d9b0 | 440 | mtd = nand_info[dev]; |
addb2e16 BS |
441 | |
442 | if (strcmp(cmd, "bad") == 0) { | |
ea533c26 | 443 | printf("\nDevice %d bad blocks:\n", dev); |
151c06ec SW |
444 | for (off = 0; off < mtd->size; off += mtd->erasesize) |
445 | if (nand_block_isbad(mtd, off)) | |
ea533c26 | 446 | printf(" %08llx\n", (unsigned long long)off); |
addb2e16 BS |
447 | return 0; |
448 | } | |
449 | ||
856f0544 SR |
450 | /* |
451 | * Syntax is: | |
452 | * 0 1 2 3 4 | |
453 | * nand erase [clean] [off size] | |
454 | */ | |
30486322 | 455 | if (strncmp(cmd, "erase", 5) == 0 || strncmp(cmd, "scrub", 5) == 0) { |
2255b2d2 | 456 | nand_erase_options_t opts; |
856f0544 | 457 | /* "clean" at index 2 means request to write cleanmarker */ |
3043c045 | 458 | int clean = argc > 2 && !strcmp("clean", argv[2]); |
60899816 MV |
459 | int scrub_yes = argc > 2 && !strcmp("-y", argv[2]); |
460 | int o = (clean || scrub_yes) ? 3 : 2; | |
30486322 | 461 | int scrub = !strncmp(cmd, "scrub", 5); |
30486322 SW |
462 | int spread = 0; |
463 | int args = 2; | |
60899816 MV |
464 | const char *scrub_warn = |
465 | "Warning: " | |
466 | "scrub option will erase all factory set bad blocks!\n" | |
467 | " " | |
468 | "There is no reliable way to recover them.\n" | |
469 | " " | |
470 | "Use this command only for testing purposes if you\n" | |
471 | " " | |
472 | "are sure of what you are doing!\n" | |
473 | "\nReally scrub this NAND flash? <y/N>\n"; | |
30486322 SW |
474 | |
475 | if (cmd[5] != 0) { | |
476 | if (!strcmp(&cmd[5], ".spread")) { | |
477 | spread = 1; | |
478 | } else if (!strcmp(&cmd[5], ".part")) { | |
30486322 SW |
479 | args = 1; |
480 | } else if (!strcmp(&cmd[5], ".chip")) { | |
30486322 SW |
481 | args = 0; |
482 | } else { | |
483 | goto usage; | |
484 | } | |
485 | } | |
486 | ||
487 | /* | |
488 | * Don't allow missing arguments to cause full chip/partition | |
489 | * erases -- easy to do accidentally, e.g. with a misspelled | |
490 | * variable name. | |
491 | */ | |
492 | if (argc != o + args) | |
493 | goto usage; | |
2255b2d2 | 494 | |
30486322 | 495 | printf("\nNAND %s: ", cmd); |
856f0544 | 496 | /* skip first two or three arguments, look for offset and size */ |
09c32807 HS |
497 | if (mtd_arg_off_size(argc - o, argv + o, &dev, &off, &size, |
498 | &maxsize, MTD_DEV_TYPE_NAND, | |
b616d9b0 | 499 | nand_info[dev]->size) != 0) |
09c32807 HS |
500 | return 1; |
501 | ||
502 | if (set_dev(dev)) | |
856f0544 | 503 | return 1; |
2255b2d2 | 504 | |
b616d9b0 | 505 | mtd = nand_info[dev]; |
ea533c26 | 506 | |
2255b2d2 SR |
507 | memset(&opts, 0, sizeof(opts)); |
508 | opts.offset = off; | |
509 | opts.length = size; | |
510 | opts.jffs2 = clean; | |
511 | opts.quiet = quiet; | |
30486322 | 512 | opts.spread = spread; |
2255b2d2 SR |
513 | |
514 | if (scrub) { | |
a5dffa4b | 515 | if (scrub_yes) { |
60899816 | 516 | opts.scrub = 1; |
a5dffa4b PA |
517 | } else { |
518 | puts(scrub_warn); | |
519 | if (confirm_yesno()) { | |
6b94b496 | 520 | opts.scrub = 1; |
a5dffa4b | 521 | } else { |
6b94b496 | 522 | puts("scrub aborted\n"); |
46aabcc4 | 523 | return 1; |
6b94b496 | 524 | } |
2255b2d2 SR |
525 | } |
526 | } | |
151c06ec | 527 | ret = nand_erase_opts(mtd, &opts); |
addb2e16 BS |
528 | printf("%s\n", ret ? "ERROR" : "OK"); |
529 | ||
530 | return ret == 0 ? 0 : 1; | |
531 | } | |
532 | ||
533 | if (strncmp(cmd, "dump", 4) == 0) { | |
534 | if (argc < 3) | |
535 | goto usage; | |
536 | ||
addb2e16 | 537 | off = (int)simple_strtoul(argv[2], NULL, 16); |
151c06ec | 538 | ret = nand_dump(mtd, off, !strcmp(&cmd[4], ".oob"), repeat); |
addb2e16 BS |
539 | |
540 | return ret == 0 ? 1 : 0; | |
addb2e16 BS |
541 | } |
542 | ||
addb2e16 | 543 | if (strncmp(cmd, "read", 4) == 0 || strncmp(cmd, "write", 5) == 0) { |
ea533c26 | 544 | size_t rwsize; |
418396e2 | 545 | ulong pagecount = 1; |
2255b2d2 | 546 | int read; |
ced199dc | 547 | int raw = 0; |
2dc3c483 | 548 | int no_verify = 0; |
2255b2d2 | 549 | |
addb2e16 BS |
550 | if (argc < 4) |
551 | goto usage; | |
2255b2d2 | 552 | |
addb2e16 BS |
553 | addr = (ulong)simple_strtoul(argv[2], NULL, 16); |
554 | ||
2255b2d2 | 555 | read = strncmp(cmd, "read", 4) == 0; /* 1 = read, 0 = write */ |
856f0544 | 556 | printf("\nNAND %s: ", read ? "read" : "write"); |
4cbb651b | 557 | |
2255b2d2 | 558 | s = strchr(cmd, '.'); |
418396e2 | 559 | |
2dc3c483 | 560 | if (s && !strncmp(s, ".raw", 4)) { |
418396e2 SW |
561 | raw = 1; |
562 | ||
2dc3c483 BB |
563 | if (!strcmp(s, ".raw.noverify")) |
564 | no_verify = 1; | |
565 | ||
09c32807 HS |
566 | if (mtd_arg_off(argv[3], &dev, &off, &size, &maxsize, |
567 | MTD_DEV_TYPE_NAND, | |
b616d9b0 | 568 | nand_info[dev]->size)) |
09c32807 HS |
569 | return 1; |
570 | ||
571 | if (set_dev(dev)) | |
418396e2 SW |
572 | return 1; |
573 | ||
b616d9b0 | 574 | mtd = nand_info[dev]; |
93d3232d | 575 | |
418396e2 SW |
576 | if (argc > 4 && !str2long(argv[4], &pagecount)) { |
577 | printf("'%s' is not a number\n", argv[4]); | |
578 | return 1; | |
579 | } | |
580 | ||
151c06ec | 581 | if (pagecount * mtd->writesize > size) { |
418396e2 SW |
582 | puts("Size exceeds partition or device limit\n"); |
583 | return -1; | |
584 | } | |
585 | ||
151c06ec | 586 | rwsize = pagecount * (mtd->writesize + mtd->oobsize); |
418396e2 | 587 | } else { |
09c32807 HS |
588 | if (mtd_arg_off_size(argc - 3, argv + 3, &dev, &off, |
589 | &size, &maxsize, | |
590 | MTD_DEV_TYPE_NAND, | |
b616d9b0 | 591 | nand_info[dev]->size) != 0) |
09c32807 HS |
592 | return 1; |
593 | ||
594 | if (set_dev(dev)) | |
418396e2 SW |
595 | return 1; |
596 | ||
e834402f HC |
597 | /* size is unspecified */ |
598 | if (argc < 5) | |
599 | adjust_size_for_badblocks(&size, off, dev); | |
418396e2 SW |
600 | rwsize = size; |
601 | } | |
602 | ||
b616d9b0 | 603 | mtd = nand_info[dev]; |
93d3232d | 604 | |
984e03cd SW |
605 | if (!s || !strcmp(s, ".jffs2") || |
606 | !strcmp(s, ".e") || !strcmp(s, ".i")) { | |
dfbf617f | 607 | if (read) |
151c06ec | 608 | ret = nand_read_skip_bad(mtd, off, &rwsize, |
c39d6a0e | 609 | NULL, maxsize, |
4b070809 | 610 | (u_char *)addr); |
dfbf617f | 611 | else |
151c06ec | 612 | ret = nand_write_skip_bad(mtd, off, &rwsize, |
c39d6a0e | 613 | NULL, maxsize, |
6b94f118 PT |
614 | (u_char *)addr, |
615 | WITH_WR_VERIFY); | |
c9494866 BG |
616 | #ifdef CONFIG_CMD_NAND_TRIMFFS |
617 | } else if (!strcmp(s, ".trimffs")) { | |
618 | if (read) { | |
619 | printf("Unknown nand command suffix '%s'\n", s); | |
620 | return 1; | |
621 | } | |
151c06ec | 622 | ret = nand_write_skip_bad(mtd, off, &rwsize, NULL, |
c39d6a0e | 623 | maxsize, (u_char *)addr, |
6b94f118 | 624 | WITH_DROP_FFS | WITH_WR_VERIFY); |
47fc18f1 | 625 | #endif |
dfc99e14 | 626 | } else if (!strcmp(s, ".oob")) { |
cfa460ad WJ |
627 | /* out-of-band data */ |
628 | mtd_oob_ops_t ops = { | |
629 | .oobbuf = (u8 *)addr, | |
ea533c26 | 630 | .ooblen = rwsize, |
dfe64e2c | 631 | .mode = MTD_OPS_RAW |
cfa460ad WJ |
632 | }; |
633 | ||
fb3659ac | 634 | if (read) |
151c06ec | 635 | ret = mtd_read_oob(mtd, off, &ops); |
fb3659ac | 636 | else |
151c06ec | 637 | ret = mtd_write_oob(mtd, off, &ops); |
418396e2 | 638 | } else if (raw) { |
2dc3c483 BB |
639 | ret = raw_access(mtd, addr, off, pagecount, read, |
640 | no_verify); | |
856f0544 | 641 | } else { |
984e03cd SW |
642 | printf("Unknown nand command suffix '%s'.\n", s); |
643 | return 1; | |
2255b2d2 SR |
644 | } |
645 | ||
ea533c26 | 646 | printf(" %zu bytes %s: %s\n", rwsize, |
2255b2d2 | 647 | read ? "read" : "written", ret ? "ERROR" : "OK"); |
addb2e16 BS |
648 | |
649 | return ret == 0 ? 0 : 1; | |
650 | } | |
2255b2d2 | 651 | |
3287f6d3 BT |
652 | #ifdef CONFIG_CMD_NAND_TORTURE |
653 | if (strcmp(cmd, "torture") == 0) { | |
1866be7d MK |
654 | loff_t endoff; |
655 | unsigned int failed = 0, passed = 0; | |
656 | ||
3287f6d3 BT |
657 | if (argc < 3) |
658 | goto usage; | |
659 | ||
660 | if (!str2off(argv[2], &off)) { | |
661 | puts("Offset is not a valid number\n"); | |
662 | return 1; | |
663 | } | |
664 | ||
1866be7d MK |
665 | size = mtd->erasesize; |
666 | if (argc > 3) { | |
667 | if (!str2off(argv[3], &size)) { | |
668 | puts("Size is not a valid number\n"); | |
669 | return 1; | |
670 | } | |
671 | } | |
3287f6d3 | 672 | |
1866be7d MK |
673 | endoff = off + size; |
674 | if (endoff > mtd->size) { | |
675 | puts("Arguments beyond end of NAND\n"); | |
676 | return 1; | |
677 | } | |
678 | ||
679 | off = round_down(off, mtd->erasesize); | |
680 | endoff = round_up(endoff, mtd->erasesize); | |
681 | size = endoff - off; | |
682 | printf("\nNAND torture: device %d offset 0x%llx size 0x%llx (block size 0x%x)\n", | |
683 | dev, off, size, mtd->erasesize); | |
684 | while (off < endoff) { | |
685 | ret = nand_torture(mtd, off); | |
686 | if (ret) { | |
687 | failed++; | |
688 | printf(" block at 0x%llx failed\n", off); | |
689 | } else { | |
690 | passed++; | |
691 | } | |
692 | off += mtd->erasesize; | |
693 | } | |
694 | printf(" Passed: %u, failed: %u\n", passed, failed); | |
695 | return failed != 0; | |
3287f6d3 BT |
696 | } |
697 | #endif | |
698 | ||
2255b2d2 | 699 | if (strcmp(cmd, "markbad") == 0) { |
8360b66b WD |
700 | argc -= 2; |
701 | argv += 2; | |
2255b2d2 | 702 | |
8360b66b WD |
703 | if (argc <= 0) |
704 | goto usage; | |
705 | ||
706 | while (argc > 0) { | |
707 | addr = simple_strtoul(*argv, NULL, 16); | |
708 | ||
151c06ec | 709 | if (mtd_block_markbad(mtd, addr)) { |
8360b66b WD |
710 | printf("block 0x%08lx NOT marked " |
711 | "as bad! ERROR %d\n", | |
712 | addr, ret); | |
713 | ret = 1; | |
714 | } else { | |
715 | printf("block 0x%08lx successfully " | |
716 | "marked as bad\n", | |
717 | addr); | |
718 | } | |
719 | --argc; | |
720 | ++argv; | |
2255b2d2 | 721 | } |
8360b66b | 722 | return ret; |
2255b2d2 | 723 | } |
dfbf617f | 724 | |
2255b2d2 SR |
725 | if (strcmp(cmd, "biterr") == 0) { |
726 | /* todo */ | |
727 | return 1; | |
728 | } | |
729 | ||
50657c27 | 730 | #ifdef CONFIG_CMD_NAND_LOCK_UNLOCK |
2255b2d2 | 731 | if (strcmp(cmd, "lock") == 0) { |
50657c27 | 732 | int tight = 0; |
2255b2d2 SR |
733 | int status = 0; |
734 | if (argc == 3) { | |
735 | if (!strcmp("tight", argv[2])) | |
736 | tight = 1; | |
737 | if (!strcmp("status", argv[2])) | |
738 | status = 1; | |
739 | } | |
2255b2d2 | 740 | if (status) { |
151c06ec | 741 | do_nand_status(mtd); |
cfa460ad | 742 | } else { |
151c06ec | 743 | if (!nand_lock(mtd, tight)) { |
5e1dae5c WJ |
744 | puts("NAND flash successfully locked\n"); |
745 | } else { | |
746 | puts("Error locking NAND flash\n"); | |
747 | return 1; | |
748 | } | |
2255b2d2 SR |
749 | } |
750 | return 0; | |
751 | } | |
752 | ||
eee623a5 JH |
753 | if (strncmp(cmd, "unlock", 5) == 0) { |
754 | int allexcept = 0; | |
755 | ||
756 | s = strchr(cmd, '.'); | |
757 | ||
758 | if (s && !strcmp(s, ".allexcept")) | |
759 | allexcept = 1; | |
760 | ||
09c32807 HS |
761 | if (mtd_arg_off_size(argc - 2, argv + 2, &dev, &off, &size, |
762 | &maxsize, MTD_DEV_TYPE_NAND, | |
b616d9b0 | 763 | nand_info[dev]->size) < 0) |
09c32807 HS |
764 | return 1; |
765 | ||
766 | if (set_dev(dev)) | |
856f0544 | 767 | return 1; |
2255b2d2 | 768 | |
b616d9b0 | 769 | if (!nand_unlock(nand_info[dev], off, size, allexcept)) { |
5e1dae5c WJ |
770 | puts("NAND flash successfully unlocked\n"); |
771 | } else { | |
772 | puts("Error unlocking NAND flash, " | |
3043c045 | 773 | "write and erase will probably fail\n"); |
5e1dae5c WJ |
774 | return 1; |
775 | } | |
2255b2d2 SR |
776 | return 0; |
777 | } | |
50657c27 | 778 | #endif |
2255b2d2 | 779 | |
addb2e16 | 780 | usage: |
4c12eeb8 | 781 | return CMD_RET_USAGE; |
addb2e16 BS |
782 | } |
783 | ||
088f1b19 KP |
784 | #ifdef CONFIG_SYS_LONGHELP |
785 | static char nand_help_text[] = | |
a89c33db WD |
786 | "info - show available NAND devices\n" |
787 | "nand device [dev] - show or set current device\n" | |
788 | "nand read - addr off|partition size\n" | |
789 | "nand write - addr off|partition size\n" | |
790 | " read/write 'size' bytes starting at offset 'off'\n" | |
791 | " to/from memory address 'addr', skipping bad blocks.\n" | |
418396e2 | 792 | "nand read.raw - addr off|partition [count]\n" |
2dc3c483 | 793 | "nand write.raw[.noverify] - addr off|partition [count]\n" |
418396e2 | 794 | " Use read.raw/write.raw to avoid ECC and access the flash as-is.\n" |
c9494866 BG |
795 | #ifdef CONFIG_CMD_NAND_TRIMFFS |
796 | "nand write.trimffs - addr off|partition size\n" | |
797 | " write 'size' bytes starting at offset 'off' from memory address\n" | |
798 | " 'addr', skipping bad blocks and dropping any pages at the end\n" | |
799 | " of eraseblocks that contain only 0xFF\n" | |
47fc18f1 | 800 | #endif |
eb3abce8 | 801 | "nand erase[.spread] [clean] off size - erase 'size' bytes " |
30486322 SW |
802 | "from offset 'off'\n" |
803 | " With '.spread', erase enough for given file size, otherwise,\n" | |
804 | " 'size' includes skipped bad blocks.\n" | |
805 | "nand erase.part [clean] partition - erase entire mtd partition'\n" | |
806 | "nand erase.chip [clean] - erase entire chip'\n" | |
a89c33db WD |
807 | "nand bad - show bad blocks\n" |
808 | "nand dump[.oob] off - dump page\n" | |
3287f6d3 | 809 | #ifdef CONFIG_CMD_NAND_TORTURE |
1866be7d MK |
810 | "nand torture off - torture one block at offset\n" |
811 | "nand torture off [size] - torture blocks from off to off+size\n" | |
3287f6d3 | 812 | #endif |
60899816 | 813 | "nand scrub [-y] off size | scrub.part partition | scrub.chip\n" |
30486322 | 814 | " really clean NAND erasing bad blocks (UNSAFE)\n" |
a89c33db WD |
815 | "nand markbad off [...] - mark bad block(s) at offset (UNSAFE)\n" |
816 | "nand biterr off - make a bit error at offset (UNSAFE)" | |
50657c27 | 817 | #ifdef CONFIG_CMD_NAND_LOCK_UNLOCK |
a89c33db WD |
818 | "\n" |
819 | "nand lock [tight] [status]\n" | |
820 | " bring nand to lock state or display locked pages\n" | |
eee623a5 | 821 | "nand unlock[.allexcept] [offset] [size] - unlock section" |
50657c27 | 822 | #endif |
c9f7351b BG |
823 | #ifdef CONFIG_ENV_OFFSET_OOB |
824 | "\n" | |
825 | "nand env.oob - environment offset in OOB of block 0 of" | |
826 | " first device.\n" | |
827 | "nand env.oob set off|partition - set enviromnent offset\n" | |
828 | "nand env.oob get - get environment offset" | |
829 | #endif | |
088f1b19 KP |
830 | ""; |
831 | #endif | |
832 | ||
833 | U_BOOT_CMD( | |
834 | nand, CONFIG_SYS_MAXARGS, 1, do_nand, | |
835 | "NAND sub-system", nand_help_text | |
50657c27 | 836 | ); |
addb2e16 | 837 | |
151c06ec | 838 | static int nand_load_image(cmd_tbl_t *cmdtp, struct mtd_info *mtd, |
4b070809 | 839 | ulong offset, ulong addr, char *cmd) |
addb2e16 | 840 | { |
addb2e16 | 841 | int r; |
67d668bf | 842 | char *s; |
4ca79f47 | 843 | size_t cnt; |
21d29f7f | 844 | #if defined(CONFIG_IMAGE_FORMAT_LEGACY) |
addb2e16 | 845 | image_header_t *hdr; |
21d29f7f | 846 | #endif |
09475f75 | 847 | #if defined(CONFIG_FIT) |
3bab76a2 | 848 | const void *fit_hdr = NULL; |
09475f75 | 849 | #endif |
10e03893 TK |
850 | |
851 | s = strchr(cmd, '.'); | |
852 | if (s != NULL && | |
65d8bc94 | 853 | (strcmp(s, ".jffs2") && strcmp(s, ".e") && strcmp(s, ".i"))) { |
984e03cd | 854 | printf("Unknown nand load suffix '%s'\n", s); |
770605e4 | 855 | bootstage_error(BOOTSTAGE_ID_NAND_SUFFIX); |
984e03cd SW |
856 | return 1; |
857 | } | |
addb2e16 | 858 | |
151c06ec | 859 | printf("\nLoading from %s, offset 0x%lx\n", mtd->name, offset); |
addb2e16 | 860 | |
151c06ec SW |
861 | cnt = mtd->writesize; |
862 | r = nand_read_skip_bad(mtd, offset, &cnt, NULL, mtd->size, | |
863 | (u_char *)addr); | |
addb2e16 | 864 | if (r) { |
856f0544 | 865 | puts("** Read error\n"); |
770605e4 | 866 | bootstage_error(BOOTSTAGE_ID_NAND_HDR_READ); |
addb2e16 BS |
867 | return 1; |
868 | } | |
770605e4 | 869 | bootstage_mark(BOOTSTAGE_ID_NAND_HDR_READ); |
addb2e16 | 870 | |
9a4daad0 | 871 | switch (genimg_get_format ((void *)addr)) { |
21d29f7f | 872 | #if defined(CONFIG_IMAGE_FORMAT_LEGACY) |
d5934ad7 MB |
873 | case IMAGE_FORMAT_LEGACY: |
874 | hdr = (image_header_t *)addr; | |
875 | ||
770605e4 | 876 | bootstage_mark(BOOTSTAGE_ID_NAND_TYPE); |
d5934ad7 | 877 | image_print_contents (hdr); |
addb2e16 | 878 | |
d5934ad7 MB |
879 | cnt = image_get_image_size (hdr); |
880 | break; | |
21d29f7f | 881 | #endif |
d5934ad7 MB |
882 | #if defined(CONFIG_FIT) |
883 | case IMAGE_FORMAT_FIT: | |
09475f75 | 884 | fit_hdr = (const void *)addr; |
09475f75 MB |
885 | puts ("Fit image detected...\n"); |
886 | ||
887 | cnt = fit_get_size (fit_hdr); | |
888 | break; | |
d5934ad7 MB |
889 | #endif |
890 | default: | |
770605e4 | 891 | bootstage_error(BOOTSTAGE_ID_NAND_TYPE); |
d5934ad7 | 892 | puts ("** Unknown image type\n"); |
addb2e16 BS |
893 | return 1; |
894 | } | |
770605e4 | 895 | bootstage_mark(BOOTSTAGE_ID_NAND_TYPE); |
addb2e16 | 896 | |
151c06ec SW |
897 | r = nand_read_skip_bad(mtd, offset, &cnt, NULL, mtd->size, |
898 | (u_char *)addr); | |
addb2e16 | 899 | if (r) { |
856f0544 | 900 | puts("** Read error\n"); |
770605e4 | 901 | bootstage_error(BOOTSTAGE_ID_NAND_READ); |
addb2e16 BS |
902 | return 1; |
903 | } | |
770605e4 | 904 | bootstage_mark(BOOTSTAGE_ID_NAND_READ); |
addb2e16 | 905 | |
09475f75 MB |
906 | #if defined(CONFIG_FIT) |
907 | /* This cannot be done earlier, we need complete FIT image in RAM first */ | |
3bab76a2 MB |
908 | if (genimg_get_format ((void *)addr) == IMAGE_FORMAT_FIT) { |
909 | if (!fit_check_format (fit_hdr)) { | |
770605e4 | 910 | bootstage_error(BOOTSTAGE_ID_NAND_FIT_READ); |
3bab76a2 MB |
911 | puts ("** Bad FIT image format\n"); |
912 | return 1; | |
913 | } | |
770605e4 | 914 | bootstage_mark(BOOTSTAGE_ID_NAND_FIT_READ_OK); |
3bab76a2 MB |
915 | fit_print_contents (fit_hdr); |
916 | } | |
09475f75 MB |
917 | #endif |
918 | ||
addb2e16 BS |
919 | /* Loading ok, update default load address */ |
920 | ||
921 | load_addr = addr; | |
922 | ||
67d668bf | 923 | return bootm_maybe_autostart(cmdtp, cmd); |
addb2e16 BS |
924 | } |
925 | ||
088f1b19 KP |
926 | static int do_nandboot(cmd_tbl_t *cmdtp, int flag, int argc, |
927 | char * const argv[]) | |
856f0544 SR |
928 | { |
929 | char *boot_device = NULL; | |
930 | int idx; | |
931 | ulong addr, offset = 0; | |
0c8a8491 | 932 | #if defined(CONFIG_CMD_MTDPARTS) |
856f0544 SR |
933 | struct mtd_device *dev; |
934 | struct part_info *part; | |
935 | u8 pnum; | |
936 | ||
937 | if (argc >= 2) { | |
938 | char *p = (argc == 2) ? argv[1] : argv[2]; | |
939 | if (!(str2long(p, &addr)) && (mtdparts_init() == 0) && | |
940 | (find_dev_and_part(p, &dev, &pnum, &part) == 0)) { | |
941 | if (dev->id->type != MTD_DEV_TYPE_NAND) { | |
942 | puts("Not a NAND device\n"); | |
943 | return 1; | |
944 | } | |
945 | if (argc > 3) | |
946 | goto usage; | |
947 | if (argc == 3) | |
10e03893 | 948 | addr = simple_strtoul(argv[1], NULL, 16); |
856f0544 | 949 | else |
6d0f6bcf | 950 | addr = CONFIG_SYS_LOAD_ADDR; |
b616d9b0 | 951 | return nand_load_image(cmdtp, nand_info[dev->id->num], |
4b070809 | 952 | part->offset, addr, argv[0]); |
856f0544 SR |
953 | } |
954 | } | |
955 | #endif | |
956 | ||
770605e4 | 957 | bootstage_mark(BOOTSTAGE_ID_NAND_PART); |
856f0544 SR |
958 | switch (argc) { |
959 | case 1: | |
6d0f6bcf | 960 | addr = CONFIG_SYS_LOAD_ADDR; |
856f0544 SR |
961 | boot_device = getenv("bootdevice"); |
962 | break; | |
963 | case 2: | |
964 | addr = simple_strtoul(argv[1], NULL, 16); | |
965 | boot_device = getenv("bootdevice"); | |
966 | break; | |
967 | case 3: | |
968 | addr = simple_strtoul(argv[1], NULL, 16); | |
969 | boot_device = argv[2]; | |
970 | break; | |
971 | case 4: | |
972 | addr = simple_strtoul(argv[1], NULL, 16); | |
973 | boot_device = argv[2]; | |
974 | offset = simple_strtoul(argv[3], NULL, 16); | |
975 | break; | |
976 | default: | |
0c8a8491 | 977 | #if defined(CONFIG_CMD_MTDPARTS) |
856f0544 SR |
978 | usage: |
979 | #endif | |
770605e4 | 980 | bootstage_error(BOOTSTAGE_ID_NAND_SUFFIX); |
4c12eeb8 | 981 | return CMD_RET_USAGE; |
856f0544 | 982 | } |
770605e4 | 983 | bootstage_mark(BOOTSTAGE_ID_NAND_SUFFIX); |
856f0544 SR |
984 | |
985 | if (!boot_device) { | |
986 | puts("\n** No boot device **\n"); | |
770605e4 | 987 | bootstage_error(BOOTSTAGE_ID_NAND_BOOT_DEVICE); |
856f0544 SR |
988 | return 1; |
989 | } | |
770605e4 | 990 | bootstage_mark(BOOTSTAGE_ID_NAND_BOOT_DEVICE); |
addb2e16 | 991 | |
856f0544 SR |
992 | idx = simple_strtoul(boot_device, NULL, 16); |
993 | ||
4004a818 | 994 | if (idx < 0 || idx >= CONFIG_SYS_MAX_NAND_DEVICE || !nand_info[idx]) { |
856f0544 | 995 | printf("\n** Device %d not available\n", idx); |
770605e4 | 996 | bootstage_error(BOOTSTAGE_ID_NAND_AVAILABLE); |
856f0544 SR |
997 | return 1; |
998 | } | |
770605e4 | 999 | bootstage_mark(BOOTSTAGE_ID_NAND_AVAILABLE); |
856f0544 | 1000 | |
b616d9b0 | 1001 | return nand_load_image(cmdtp, nand_info[idx], offset, addr, argv[0]); |
856f0544 SR |
1002 | } |
1003 | ||
1004 | U_BOOT_CMD(nboot, 4, 1, do_nandboot, | |
2fb2604d | 1005 | "boot from NAND device", |
a89c33db WD |
1006 | "[partition] | [[[loadAddr] dev] offset]" |
1007 | ); |