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