2 * Driver for NAND support, Rick Bronson
3 * borrowed heavily from:
4 * (c) 1999 Machine Vision Holdings, Inc.
5 * (c) 1999, 2000 David Woodhouse <dwmw2@infradead.org>
7 * Added 16-bit nand support
8 * (C) 2004 Texas Instruments
14 #ifndef CFG_NAND_LEGACY
22 #if defined(CONFIG_CMD_NAND)
27 #include <asm/byteorder.h>
28 #include <jffs2/jffs2.h>
31 #if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
33 /* parition handling routines */
34 int mtdparts_init(void);
35 int id_parse(const char *id, const char **ret_id, u8 *dev_type, u8 *dev_num);
36 int find_dev_and_part(const char *id, struct mtd_device **dev,
37 u8 *part_num, struct part_info **part);
40 extern nand_info_t nand_info[]; /* info for NAND chips */
42 static int nand_dump_oob(nand_info_t *nand, ulong off)
47 static int nand_dump(nand_info_t *nand, ulong off)
52 buf = malloc(nand->oobblock + nand->oobsize);
54 puts("No memory for page buffer\n");
57 off &= ~(nand->oobblock - 1);
58 i = nand_read_raw(nand, buf, off, nand->oobblock, nand->oobsize);
60 printf("Error (%d) reading page %08x\n", i, off);
64 printf("Page %08x dump:\n", off);
65 i = nand->oobblock >> 4; p = buf;
67 printf( "\t%02x %02x %02x %02x %02x %02x %02x %02x"
68 " %02x %02x %02x %02x %02x %02x %02x %02x\n",
69 p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],
70 p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]);
74 i = nand->oobsize >> 3;
76 printf( "\t%02x %02x %02x %02x %02x %02x %02x %02x\n",
77 p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
85 /* ------------------------------------------------------------------------- */
87 static inline int str2long(char *p, ulong *num)
91 *num = simple_strtoul(p, &endptr, 16);
92 return (*p != '\0' && *endptr == '\0') ? 1 : 0;
96 arg_off_size(int argc, char *argv[], nand_info_t *nand, ulong *off, ulong *size)
98 int idx = nand_curr_device;
99 #if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
100 struct mtd_device *dev;
101 struct part_info *part;
104 if (argc >= 1 && !(str2long(argv[0], off))) {
105 if ((mtdparts_init() == 0) &&
106 (find_dev_and_part(argv[0], &dev, &pnum, &part) == 0)) {
107 if (dev->id->type != MTD_DEV_TYPE_NAND) {
108 puts("not a NAND device\n");
113 if (!(str2long(argv[1], size))) {
114 printf("'%s' is not a number\n", argv[1]);
117 if (*size > part->size)
123 *nand = nand_info[idx];
130 if (!(str2long(argv[0], off))) {
131 printf("'%s' is not a number\n", argv[0]);
139 if (!(str2long(argv[1], size))) {
140 printf("'%s' is not a number\n", argv[1]);
144 *size = nand->size - *off;
147 #if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
150 printf("device %d ", idx);
151 if (*size == nand->size)
152 puts("whole chip\n");
154 printf("offset 0x%x, size 0x%x\n", *off, *size);
158 int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
161 ulong addr, off, size;
164 #ifdef CFG_NAND_QUIET
165 int quiet = CFG_NAND_QUIET;
169 const char *quiet_str = getenv("quiet");
171 /* at least two arguments please */
176 quiet = simple_strtoul(quiet_str, NULL, 0) != 0;
180 if (strcmp(cmd, "info") == 0) {
183 for (i = 0; i < CFG_MAX_NAND_DEVICE; i++) {
184 if (nand_info[i].name)
185 printf("Device %d: %s, sector size %lu KiB\n",
186 i, nand_info[i].name,
187 nand_info[i].erasesize >> 10);
192 if (strcmp(cmd, "device") == 0) {
195 if ((nand_curr_device < 0) ||
196 (nand_curr_device >= CFG_MAX_NAND_DEVICE))
197 puts("\nno devices available\n");
199 printf("\nDevice %d: %s\n", nand_curr_device,
200 nand_info[nand_curr_device].name);
203 dev = (int)simple_strtoul(argv[2], NULL, 10);
204 if (dev < 0 || dev >= CFG_MAX_NAND_DEVICE || !nand_info[dev].name) {
205 puts("No such device\n");
208 printf("Device %d: %s", dev, nand_info[dev].name);
209 puts("... is now current device\n");
210 nand_curr_device = dev;
212 #ifdef CFG_NAND_SELECT_DEVICE
214 * Select the chip in the board/cpu specific driver
216 board_nand_select_device(nand_info[dev].priv, dev);
222 if (strcmp(cmd, "bad") != 0 && strcmp(cmd, "erase") != 0 &&
223 strncmp(cmd, "dump", 4) != 0 &&
224 strncmp(cmd, "read", 4) != 0 && strncmp(cmd, "write", 5) != 0 &&
225 strcmp(cmd, "scrub") != 0 && strcmp(cmd, "markbad") != 0 &&
226 strcmp(cmd, "biterr") != 0 &&
227 strcmp(cmd, "lock") != 0 && strcmp(cmd, "unlock") != 0 )
230 /* the following commands operate on the current device */
231 if (nand_curr_device < 0 || nand_curr_device >= CFG_MAX_NAND_DEVICE ||
232 !nand_info[nand_curr_device].name) {
233 puts("\nno devices available\n");
236 nand = &nand_info[nand_curr_device];
238 if (strcmp(cmd, "bad") == 0) {
239 printf("\nDevice %d bad blocks:\n", nand_curr_device);
240 for (off = 0; off < nand->size; off += nand->erasesize)
241 if (nand_block_isbad(nand, off))
242 printf(" %08x\n", off);
249 * nand erase [clean] [off size]
251 if (strcmp(cmd, "erase") == 0 || strcmp(cmd, "scrub") == 0) {
252 nand_erase_options_t opts;
253 /* "clean" at index 2 means request to write cleanmarker */
254 int clean = argc > 2 && !strcmp("clean", argv[2]);
255 int o = clean ? 3 : 2;
256 int scrub = !strcmp(cmd, "scrub");
258 printf("\nNAND %s: ", scrub ? "scrub" : "erase");
259 /* skip first two or three arguments, look for offset and size */
260 if (arg_off_size(argc - o, argv + o, nand, &off, &size) != 0)
263 memset(&opts, 0, sizeof(opts));
271 "scrub option will erase all factory set "
274 "There is no reliable way to recover them.\n"
276 "Use this command only for testing purposes "
279 "are sure of what you are doing!\n"
280 "\nReally scrub this NAND flash? <y/N>\n");
282 if (getc() == 'y' && getc() == '\r') {
285 puts("scrub aborted\n");
289 ret = nand_erase_opts(nand, &opts);
290 printf("%s\n", ret ? "ERROR" : "OK");
292 return ret == 0 ? 0 : 1;
295 if (strncmp(cmd, "dump", 4) == 0) {
299 s = strchr(cmd, '.');
300 off = (int)simple_strtoul(argv[2], NULL, 16);
302 if (s != NULL && strcmp(s, ".oob") == 0)
303 ret = nand_dump_oob(nand, off);
305 ret = nand_dump(nand, off);
307 return ret == 0 ? 1 : 0;
312 if (strncmp(cmd, "read", 4) == 0 || strncmp(cmd, "write", 5) == 0) {
318 addr = (ulong)simple_strtoul(argv[2], NULL, 16);
320 read = strncmp(cmd, "read", 4) == 0; /* 1 = read, 0 = write */
321 printf("\nNAND %s: ", read ? "read" : "write");
322 if (arg_off_size(argc - 3, argv + 3, nand, &off, &size) != 0)
325 s = strchr(cmd, '.');
327 (!strcmp(s, ".jffs2") || !strcmp(s, ".e") || !strcmp(s, ".i"))) {
330 nand_read_options_t opts;
331 memset(&opts, 0, sizeof(opts));
332 opts.buffer = (u_char*) addr;
336 ret = nand_read_opts(nand, &opts);
339 nand_write_options_t opts;
340 memset(&opts, 0, sizeof(opts));
341 opts.buffer = (u_char*) addr;
344 /* opts.forcejffs2 = 1; */
348 ret = nand_write_opts(nand, &opts);
350 } else if (s != NULL && !strcmp(s, ".oob")) {
351 /* read out-of-band data */
353 ret = nand->read_oob(nand, off, size, (size_t *) &size,
356 ret = nand->write_oob(nand, off, size, (size_t *) &size,
360 ret = nand_read(nand, off, &size, (u_char *)addr);
362 ret = nand_write(nand, off, &size, (u_char *)addr);
365 printf(" %d bytes %s: %s\n", size,
366 read ? "read" : "written", ret ? "ERROR" : "OK");
368 return ret == 0 ? 0 : 1;
371 if (strcmp(cmd, "markbad") == 0) {
372 addr = (ulong)simple_strtoul(argv[2], NULL, 16);
374 int ret = nand->block_markbad(nand, addr);
376 printf("block 0x%08lx successfully marked as bad\n",
380 printf("block 0x%08lx NOT marked as bad! ERROR %d\n",
385 if (strcmp(cmd, "biterr") == 0) {
390 if (strcmp(cmd, "lock") == 0) {
394 if (!strcmp("tight", argv[2]))
396 if (!strcmp("status", argv[2]))
401 ulong block_start = 0;
403 int last_status = -1;
405 struct nand_chip *nand_chip = nand->priv;
406 /* check the WP bit */
407 nand_chip->cmdfunc (nand, NAND_CMD_STATUS, -1, -1);
408 printf("device is %swrite protected\n",
409 (nand_chip->read_byte(nand) & 0x80 ?
412 for (off = 0; off < nand->size; off += nand->oobblock) {
413 int s = nand_get_lock_status(nand, off);
415 /* print message only if status has changed
418 if (off == nand->size - nand->oobblock
419 || (s != last_status && off != 0)) {
421 printf("%08x - %08x: %8d pages %s%s%s\n",
424 (off-block_start)/nand->oobblock,
425 ((last_status & NAND_LOCK_STATUS_TIGHT) ? "TIGHT " : ""),
426 ((last_status & NAND_LOCK_STATUS_LOCK) ? "LOCK " : ""),
427 ((last_status & NAND_LOCK_STATUS_UNLOCK) ? "UNLOCK " : ""));
433 if (!nand_lock(nand, tight)) {
434 puts("NAND flash successfully locked\n");
436 puts("Error locking NAND flash\n");
443 if (strcmp(cmd, "unlock") == 0) {
444 if (arg_off_size(argc - 2, argv + 2, nand, &off, &size) < 0)
447 if (!nand_unlock(nand, off, size)) {
448 puts("NAND flash successfully unlocked\n");
450 puts("Error unlocking NAND flash, "
451 "write and erase will probably fail\n");
458 printf("Usage:\n%s\n", cmdtp->usage);
462 U_BOOT_CMD(nand, 5, 1, do_nand,
463 "nand - NAND sub-system\n",
464 "info - show available NAND devices\n"
465 "nand device [dev] - show or set current device\n"
466 "nand read[.jffs2] - addr off|partition size\n"
467 "nand write[.jffs2] - addr off|partition size - read/write `size' bytes starting\n"
468 " at offset `off' to/from memory address `addr'\n"
469 "nand erase [clean] [off size] - erase `size' bytes from\n"
470 " offset `off' (entire device if not specified)\n"
471 "nand bad - show bad blocks\n"
472 "nand dump[.oob] off - dump page\n"
473 "nand scrub - really clean NAND erasing bad blocks (UNSAFE)\n"
474 "nand markbad off - mark bad block at offset (UNSAFE)\n"
475 "nand biterr off - make a bit error at offset (UNSAFE)\n"
476 "nand lock [tight] [status] - bring nand to lock state or display locked pages\n"
477 "nand unlock [offset] [size] - unlock section\n");
479 static int nand_load_image(cmd_tbl_t *cmdtp, nand_info_t *nand,
480 ulong offset, ulong addr, char *cmd)
488 s = strchr(cmd, '.');
490 (!strcmp(s, ".jffs2") || !strcmp(s, ".e") || !strcmp(s, ".i")))
493 printf("\nLoading from %s, offset 0x%lx\n", nand->name, offset);
495 cnt = nand->oobblock;
497 nand_read_options_t opts;
498 memset(&opts, 0, sizeof(opts));
499 opts.buffer = (u_char*) addr;
501 opts.offset = offset;
503 r = nand_read_opts(nand, &opts);
505 r = nand_read(nand, offset, &cnt, (u_char *) addr);
509 puts("** Read error\n");
510 show_boot_progress (-56);
513 show_boot_progress (56);
515 hdr = (image_header_t *) addr;
517 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
518 printf("\n** Bad Magic Number 0x%x **\n", hdr->ih_magic);
519 show_boot_progress (-57);
522 show_boot_progress (57);
524 print_image_hdr(hdr);
526 cnt = (ntohl(hdr->ih_size) + sizeof (image_header_t));
528 nand_read_options_t opts;
529 memset(&opts, 0, sizeof(opts));
530 opts.buffer = (u_char*) addr;
532 opts.offset = offset;
534 r = nand_read_opts(nand, &opts);
536 r = nand_read(nand, offset, &cnt, (u_char *) addr);
540 puts("** Read error\n");
541 show_boot_progress (-58);
544 show_boot_progress (58);
546 /* Loading ok, update default load address */
550 /* Check if we should attempt an auto-start */
551 if (((ep = getenv("autostart")) != NULL) && (strcmp(ep, "yes") == 0)) {
553 extern int do_bootm(cmd_tbl_t *, int, int, char *[]);
556 local_args[1] = NULL;
558 printf("Automatic boot of image at addr 0x%08lx ...\n", addr);
560 do_bootm(cmdtp, 0, 1, local_args);
566 int do_nandboot(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
568 char *boot_device = NULL;
570 ulong addr, offset = 0;
571 #if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
572 struct mtd_device *dev;
573 struct part_info *part;
577 char *p = (argc == 2) ? argv[1] : argv[2];
578 if (!(str2long(p, &addr)) && (mtdparts_init() == 0) &&
579 (find_dev_and_part(p, &dev, &pnum, &part) == 0)) {
580 if (dev->id->type != MTD_DEV_TYPE_NAND) {
581 puts("Not a NAND device\n");
587 addr = simple_strtoul(argv[1], NULL, 16);
589 addr = CFG_LOAD_ADDR;
590 return nand_load_image(cmdtp, &nand_info[dev->id->num],
591 part->offset, addr, argv[0]);
596 show_boot_progress(52);
599 addr = CFG_LOAD_ADDR;
600 boot_device = getenv("bootdevice");
603 addr = simple_strtoul(argv[1], NULL, 16);
604 boot_device = getenv("bootdevice");
607 addr = simple_strtoul(argv[1], NULL, 16);
608 boot_device = argv[2];
611 addr = simple_strtoul(argv[1], NULL, 16);
612 boot_device = argv[2];
613 offset = simple_strtoul(argv[3], NULL, 16);
616 #if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
619 printf("Usage:\n%s\n", cmdtp->usage);
620 show_boot_progress(-53);
624 show_boot_progress(53);
626 puts("\n** No boot device **\n");
627 show_boot_progress(-54);
630 show_boot_progress(54);
632 idx = simple_strtoul(boot_device, NULL, 16);
634 if (idx < 0 || idx >= CFG_MAX_NAND_DEVICE || !nand_info[idx].name) {
635 printf("\n** Device %d not available\n", idx);
636 show_boot_progress(-55);
639 show_boot_progress(55);
641 return nand_load_image(cmdtp, &nand_info[idx], offset, addr, argv[0]);
644 U_BOOT_CMD(nboot, 4, 1, do_nandboot,
645 "nboot - boot from NAND device\n",
646 "[.jffs2] [partition] | [[[loadAddr] dev] offset]\n");
650 #else /* CFG_NAND_LEGACY */
653 * Legacy NAND support - to be phased out
659 #include <watchdog.h>
661 #ifdef CONFIG_show_boot_progress
662 # include <status_led.h>
663 # define show_boot_progress(arg) show_boot_progress(arg)
665 # define show_boot_progress(arg)
668 #if defined(CONFIG_CMD_NAND)
669 #include <linux/mtd/nand_legacy.h>
671 #include <linux/mtd/nand_ids.h>
672 #include <jffs2/jffs2.h>
675 #ifdef CONFIG_OMAP1510
676 void archflashwp(void *archdata, int wp);
679 #define ROUND_DOWN(value,boundary) ((value) & (~((boundary)-1)))
684 /* ****************** WARNING *********************
685 * When ALLOW_ERASE_BAD_DEBUG is non-zero the erase command will
686 * erase (or at least attempt to erase) blocks that are marked
687 * bad. This can be very handy if you are _sure_ that the block
688 * is OK, say because you marked a good block bad to test bad
689 * block handling and you are done testing, or if you have
690 * accidentally marked blocks bad.
692 * Erasing factory marked bad blocks is a _bad_ idea. If the
693 * erase succeeds there is no reliable way to find them again,
694 * and attempting to program or erase bad blocks can affect
695 * the data in _other_ (good) blocks.
697 #define ALLOW_ERASE_BAD_DEBUG 0
699 #define CONFIG_MTD_NAND_ECC /* enable ECC */
700 #define CONFIG_MTD_NAND_ECC_JFFS2
702 /* bits for nand_legacy_rw() `cmd'; or together as needed */
703 #define NANDRW_READ 0x01
704 #define NANDRW_WRITE 0x00
705 #define NANDRW_JFFS2 0x02
706 #define NANDRW_JFFS2_SKIP 0x04
709 * Imports from nand_legacy.c
711 extern struct nand_chip nand_dev_desc[CFG_MAX_NAND_DEVICE];
712 extern int curr_device;
713 extern int nand_legacy_erase(struct nand_chip *nand, size_t ofs,
714 size_t len, int clean);
715 extern int nand_legacy_rw(struct nand_chip *nand, int cmd, size_t start,
716 size_t len, size_t *retlen, u_char *buf);
717 extern void nand_print(struct nand_chip *nand);
718 extern void nand_print_bad(struct nand_chip *nand);
719 extern int nand_read_oob(struct nand_chip *nand, size_t ofs,
720 size_t len, size_t *retlen, u_char *buf);
721 extern int nand_write_oob(struct nand_chip *nand, size_t ofs,
722 size_t len, size_t *retlen, const u_char *buf);
725 int do_nand (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
732 printf ("Usage:\n%s\n", cmdtp->usage);
735 if (strcmp (argv[1], "info") == 0) {
740 for (i = 0; i < CFG_MAX_NAND_DEVICE; ++i) {
741 if (nand_dev_desc[i].ChipID ==
743 continue; /* list only known devices */
744 printf ("Device %d: ", i);
745 nand_print (&nand_dev_desc[i]);
749 } else if (strcmp (argv[1], "device") == 0) {
750 if ((curr_device < 0)
751 || (curr_device >= CFG_MAX_NAND_DEVICE)) {
752 puts ("\nno devices available\n");
755 printf ("\nDevice %d: ", curr_device);
756 nand_print (&nand_dev_desc[curr_device]);
759 } else if (strcmp (argv[1], "bad") == 0) {
760 if ((curr_device < 0)
761 || (curr_device >= CFG_MAX_NAND_DEVICE)) {
762 puts ("\nno devices available\n");
765 printf ("\nDevice %d bad blocks:\n", curr_device);
766 nand_print_bad (&nand_dev_desc[curr_device]);
770 printf ("Usage:\n%s\n", cmdtp->usage);
773 if (strcmp (argv[1], "device") == 0) {
774 int dev = (int) simple_strtoul (argv[2], NULL, 10);
776 printf ("\nDevice %d: ", dev);
777 if (dev >= CFG_MAX_NAND_DEVICE) {
778 puts ("unknown device\n");
781 nand_print (&nand_dev_desc[dev]);
782 /*nand_print (dev); */
784 if (nand_dev_desc[dev].ChipID == NAND_ChipID_UNKNOWN) {
790 puts ("... is now current device\n");
793 } else if (strcmp (argv[1], "erase") == 0
794 && strcmp (argv[2], "clean") == 0) {
795 struct nand_chip *nand = &nand_dev_desc[curr_device];
797 ulong size = nand->totlen;
800 printf ("\nNAND erase: device %d offset %ld, size %ld ... ", curr_device, off, size);
802 ret = nand_legacy_erase (nand, off, size, 1);
804 printf ("%s\n", ret ? "ERROR" : "OK");
809 printf ("Usage:\n%s\n", cmdtp->usage);
812 /* at least 4 args */
814 if (strncmp (argv[1], "read", 4) == 0 ||
815 strncmp (argv[1], "write", 5) == 0) {
816 ulong addr = simple_strtoul (argv[2], NULL, 16);
817 ulong off = simple_strtoul (argv[3], NULL, 16);
818 ulong size = simple_strtoul (argv[4], NULL, 16);
819 int cmd = (strncmp (argv[1], "read", 4) == 0) ?
820 NANDRW_READ : NANDRW_WRITE;
822 char *cmdtail = strchr (argv[1], '.');
824 if (cmdtail && !strncmp (cmdtail, ".oob", 2)) {
825 /* read out-of-band data */
826 if (cmd & NANDRW_READ) {
827 ret = nand_read_oob (nand_dev_desc + curr_device,
828 off, size, (size_t *) & total,
831 ret = nand_write_oob (nand_dev_desc + curr_device,
832 off, size, (size_t *) & total,
836 } else if (cmdtail && !strncmp (cmdtail, ".jffs2", 2))
837 cmd |= NANDRW_JFFS2; /* skip bad blocks */
838 else if (cmdtail && !strncmp (cmdtail, ".jffs2s", 2)) {
839 cmd |= NANDRW_JFFS2; /* skip bad blocks (on read too) */
840 if (cmd & NANDRW_READ)
841 cmd |= NANDRW_JFFS2_SKIP; /* skip bad blocks (on read too) */
844 /* need ".e" same as ".j" for compatibility with older units */
845 else if (cmdtail && !strcmp (cmdtail, ".e"))
846 cmd |= NANDRW_JFFS2; /* skip bad blocks */
848 #ifdef CFG_NAND_SKIP_BAD_DOT_I
849 /* need ".i" same as ".jffs2s" for compatibility with older units (esd) */
850 /* ".i" for image -> read skips bad block (no 0xff) */
851 else if (cmdtail && !strcmp (cmdtail, ".i")) {
852 cmd |= NANDRW_JFFS2; /* skip bad blocks (on read too) */
853 if (cmd & NANDRW_READ)
854 cmd |= NANDRW_JFFS2_SKIP; /* skip bad blocks (on read too) */
856 #endif /* CFG_NAND_SKIP_BAD_DOT_I */
858 printf ("Usage:\n%s\n", cmdtp->usage);
862 printf ("\nNAND %s: device %d offset %ld, size %ld ...\n",
863 (cmd & NANDRW_READ) ? "read" : "write",
864 curr_device, off, size);
866 ret = nand_legacy_rw (nand_dev_desc + curr_device,
871 printf (" %d bytes %s: %s\n", total,
872 (cmd & NANDRW_READ) ? "read" : "written",
873 ret ? "ERROR" : "OK");
876 } else if (strcmp (argv[1], "erase") == 0 &&
877 (argc == 4 || strcmp ("clean", argv[2]) == 0)) {
878 int clean = argc == 5;
880 simple_strtoul (argv[2 + clean], NULL, 16);
882 simple_strtoul (argv[3 + clean], NULL, 16);
885 printf ("\nNAND erase: device %d offset %ld, size %ld ...\n",
886 curr_device, off, size);
888 ret = nand_legacy_erase (nand_dev_desc + curr_device,
891 printf ("%s\n", ret ? "ERROR" : "OK");
895 printf ("Usage:\n%s\n", cmdtp->usage);
905 "nand - legacy NAND sub-system\n",
906 "info - show available NAND devices\n"
907 "nand device [dev] - show or set current device\n"
908 "nand read[.jffs2[s]] addr off size\n"
909 "nand write[.jffs2] addr off size - read/write `size' bytes starting\n"
910 " at offset `off' to/from memory address `addr'\n"
911 "nand erase [clean] [off size] - erase `size' bytes from\n"
912 " offset `off' (entire device if not specified)\n"
913 "nand bad - show bad blocks\n"
914 "nand read.oob addr off size - read out-of-band data\n"
915 "nand write.oob addr off size - read out-of-band data\n"
918 int do_nandboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
920 char *boot_device = NULL;
928 show_boot_progress (52);
931 addr = CFG_LOAD_ADDR;
932 boot_device = getenv ("bootdevice");
935 addr = simple_strtoul(argv[1], NULL, 16);
936 boot_device = getenv ("bootdevice");
939 addr = simple_strtoul(argv[1], NULL, 16);
940 boot_device = argv[2];
943 addr = simple_strtoul(argv[1], NULL, 16);
944 boot_device = argv[2];
945 offset = simple_strtoul(argv[3], NULL, 16);
948 printf ("Usage:\n%s\n", cmdtp->usage);
949 show_boot_progress (-53);
953 show_boot_progress (53);
955 puts ("\n** No boot device **\n");
956 show_boot_progress (-54);
959 show_boot_progress (54);
961 dev = simple_strtoul(boot_device, &ep, 16);
963 if ((dev >= CFG_MAX_NAND_DEVICE) ||
964 (nand_dev_desc[dev].ChipID == NAND_ChipID_UNKNOWN)) {
965 printf ("\n** Device %d not available\n", dev);
966 show_boot_progress (-55);
969 show_boot_progress (55);
971 printf ("\nLoading from device %d: %s at 0x%lx (offset 0x%lx)\n",
972 dev, nand_dev_desc[dev].name, nand_dev_desc[dev].IO_ADDR,
975 if (nand_legacy_rw (nand_dev_desc + dev, NANDRW_READ, offset,
976 SECTORSIZE, NULL, (u_char *)addr)) {
977 printf ("** Read error on %d\n", dev);
978 show_boot_progress (-56);
981 show_boot_progress (56);
983 hdr = (image_header_t *)addr;
985 if (ntohl(hdr->ih_magic) == IH_MAGIC) {
987 print_image_hdr (hdr);
989 cnt = (ntohl(hdr->ih_size) + sizeof(image_header_t));
992 printf ("\n** Bad Magic Number 0x%x **\n", ntohl(hdr->ih_magic));
993 show_boot_progress (-57);
996 show_boot_progress (57);
998 if (nand_legacy_rw (nand_dev_desc + dev, NANDRW_READ,
999 offset + SECTORSIZE, cnt, NULL,
1000 (u_char *)(addr+SECTORSIZE))) {
1001 printf ("** Read error on %d\n", dev);
1002 show_boot_progress (-58);
1005 show_boot_progress (58);
1007 /* Loading ok, update default load address */
1011 /* Check if we should attempt an auto-start */
1012 if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) {
1013 char *local_args[2];
1014 extern int do_bootm (cmd_tbl_t *, int, int, char *[]);
1016 local_args[0] = argv[0];
1017 local_args[1] = NULL;
1019 printf ("Automatic boot of image at addr 0x%08lx ...\n", addr);
1021 do_bootm (cmdtp, 0, 1, local_args);
1028 nboot, 4, 1, do_nandboot,
1029 "nboot - boot from NAND device\n",
1035 #endif /* CFG_NAND_LEGACY */