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;
165 const char *quiet_str = getenv("quiet");
167 /* at least two arguments please */
172 quiet = simple_strtoul(quiet_str, NULL, 0) != 0;
176 if (strcmp(cmd, "info") == 0) {
179 for (i = 0; i < CFG_MAX_NAND_DEVICE; i++) {
180 if (nand_info[i].name)
181 printf("Device %d: %s, sector size %lu KiB\n",
182 i, nand_info[i].name,
183 nand_info[i].erasesize >> 10);
188 if (strcmp(cmd, "device") == 0) {
191 if ((nand_curr_device < 0) ||
192 (nand_curr_device >= CFG_MAX_NAND_DEVICE))
193 puts("\nno devices available\n");
195 printf("\nDevice %d: %s\n", nand_curr_device,
196 nand_info[nand_curr_device].name);
199 dev = (int)simple_strtoul(argv[2], NULL, 10);
200 if (dev < 0 || dev >= CFG_MAX_NAND_DEVICE || !nand_info[dev].name) {
201 puts("No such device\n");
204 printf("Device %d: %s", dev, nand_info[dev].name);
205 puts("... is now current device\n");
206 nand_curr_device = dev;
208 #ifdef CFG_NAND_SELECT_DEVICE
210 * Select the chip in the board/cpu specific driver
212 board_nand_select_device(nand_info[dev].priv, dev);
218 if (strcmp(cmd, "bad") != 0 && strcmp(cmd, "erase") != 0 &&
219 strncmp(cmd, "dump", 4) != 0 &&
220 strncmp(cmd, "read", 4) != 0 && strncmp(cmd, "write", 5) != 0 &&
221 strcmp(cmd, "scrub") != 0 && strcmp(cmd, "markbad") != 0 &&
222 strcmp(cmd, "biterr") != 0 &&
223 strcmp(cmd, "lock") != 0 && strcmp(cmd, "unlock") != 0 )
226 /* the following commands operate on the current device */
227 if (nand_curr_device < 0 || nand_curr_device >= CFG_MAX_NAND_DEVICE ||
228 !nand_info[nand_curr_device].name) {
229 puts("\nno devices available\n");
232 nand = &nand_info[nand_curr_device];
234 if (strcmp(cmd, "bad") == 0) {
235 printf("\nDevice %d bad blocks:\n", nand_curr_device);
236 for (off = 0; off < nand->size; off += nand->erasesize)
237 if (nand_block_isbad(nand, off))
238 printf(" %08x\n", off);
245 * nand erase [clean] [off size]
247 if (strcmp(cmd, "erase") == 0 || strcmp(cmd, "scrub") == 0) {
248 nand_erase_options_t opts;
249 /* "clean" at index 2 means request to write cleanmarker */
250 int clean = argc > 2 && !strcmp("clean", argv[2]);
251 int o = clean ? 3 : 2;
252 int scrub = !strcmp(cmd, "scrub");
254 printf("\nNAND %s: ", scrub ? "scrub" : "erase");
255 /* skip first two or three arguments, look for offset and size */
256 if (arg_off_size(argc - o, argv + o, nand, &off, &size) != 0)
259 memset(&opts, 0, sizeof(opts));
267 "scrub option will erase all factory set "
270 "There is no reliable way to recover them.\n"
272 "Use this command only for testing purposes "
275 "are sure of what you are doing!\n"
276 "\nReally scrub this NAND flash? <y/N>\n");
278 if (getc() == 'y' && getc() == '\r') {
281 puts("scrub aborted\n");
285 ret = nand_erase_opts(nand, &opts);
286 printf("%s\n", ret ? "ERROR" : "OK");
288 return ret == 0 ? 0 : 1;
291 if (strncmp(cmd, "dump", 4) == 0) {
295 s = strchr(cmd, '.');
296 off = (int)simple_strtoul(argv[2], NULL, 16);
298 if (s != NULL && strcmp(s, ".oob") == 0)
299 ret = nand_dump_oob(nand, off);
301 ret = nand_dump(nand, off);
303 return ret == 0 ? 1 : 0;
308 if (strncmp(cmd, "read", 4) == 0 || strncmp(cmd, "write", 5) == 0) {
314 addr = (ulong)simple_strtoul(argv[2], NULL, 16);
316 read = strncmp(cmd, "read", 4) == 0; /* 1 = read, 0 = write */
317 printf("\nNAND %s: ", read ? "read" : "write");
318 if (arg_off_size(argc - 3, argv + 3, nand, &off, &size) != 0)
321 s = strchr(cmd, '.');
323 (!strcmp(s, ".jffs2") || !strcmp(s, ".e") || !strcmp(s, ".i"))) {
326 nand_read_options_t opts;
327 memset(&opts, 0, sizeof(opts));
328 opts.buffer = (u_char*) addr;
332 ret = nand_read_opts(nand, &opts);
335 nand_write_options_t opts;
336 memset(&opts, 0, sizeof(opts));
337 opts.buffer = (u_char*) addr;
340 /* opts.forcejffs2 = 1; */
344 ret = nand_write_opts(nand, &opts);
348 ret = nand_read(nand, off, &size, (u_char *)addr);
350 ret = nand_write(nand, off, &size, (u_char *)addr);
353 printf(" %d bytes %s: %s\n", size,
354 read ? "read" : "written", ret ? "ERROR" : "OK");
356 return ret == 0 ? 0 : 1;
359 if (strcmp(cmd, "markbad") == 0) {
360 addr = (ulong)simple_strtoul(argv[2], NULL, 16);
362 int ret = nand->block_markbad(nand, addr);
364 printf("block 0x%08lx successfully marked as bad\n",
368 printf("block 0x%08lx NOT marked as bad! ERROR %d\n",
373 if (strcmp(cmd, "biterr") == 0) {
378 if (strcmp(cmd, "lock") == 0) {
382 if (!strcmp("tight", argv[2]))
384 if (!strcmp("status", argv[2]))
389 ulong block_start = 0;
391 int last_status = -1;
393 struct nand_chip *nand_chip = nand->priv;
394 /* check the WP bit */
395 nand_chip->cmdfunc (nand, NAND_CMD_STATUS, -1, -1);
396 printf("device is %swrite protected\n",
397 (nand_chip->read_byte(nand) & 0x80 ?
400 for (off = 0; off < nand->size; off += nand->oobblock) {
401 int s = nand_get_lock_status(nand, off);
403 /* print message only if status has changed
406 if (off == nand->size - nand->oobblock
407 || (s != last_status && off != 0)) {
409 printf("%08x - %08x: %8d pages %s%s%s\n",
412 (off-block_start)/nand->oobblock,
413 ((last_status & NAND_LOCK_STATUS_TIGHT) ? "TIGHT " : ""),
414 ((last_status & NAND_LOCK_STATUS_LOCK) ? "LOCK " : ""),
415 ((last_status & NAND_LOCK_STATUS_UNLOCK) ? "UNLOCK " : ""));
421 if (!nand_lock(nand, tight)) {
422 puts("NAND flash successfully locked\n");
424 puts("Error locking NAND flash\n");
431 if (strcmp(cmd, "unlock") == 0) {
432 if (arg_off_size(argc - 2, argv + 2, nand, &off, &size) < 0)
435 if (!nand_unlock(nand, off, size)) {
436 puts("NAND flash successfully unlocked\n");
438 puts("Error unlocking NAND flash, "
439 "write and erase will probably fail\n");
446 printf("Usage:\n%s\n", cmdtp->usage);
450 U_BOOT_CMD(nand, 5, 1, do_nand,
451 "nand - NAND sub-system\n",
452 "info - show available NAND devices\n"
453 "nand device [dev] - show or set current device\n"
454 "nand read[.jffs2] - addr off|partition size\n"
455 "nand write[.jffs2] - addr off|partiton size - read/write `size' bytes starting\n"
456 " at offset `off' to/from memory address `addr'\n"
457 "nand erase [clean] [off size] - erase `size' bytes from\n"
458 " offset `off' (entire device if not specified)\n"
459 "nand bad - show bad blocks\n"
460 "nand dump[.oob] off - dump page\n"
461 "nand scrub - really clean NAND erasing bad blocks (UNSAFE)\n"
462 "nand markbad off - mark bad block at offset (UNSAFE)\n"
463 "nand biterr off - make a bit error at offset (UNSAFE)\n"
464 "nand lock [tight] [status] - bring nand to lock state or display locked pages\n"
465 "nand unlock [offset] [size] - unlock section\n");
467 static int nand_load_image(cmd_tbl_t *cmdtp, nand_info_t *nand,
468 ulong offset, ulong addr, char *cmd)
475 printf("\nLoading from %s, offset 0x%lx\n", nand->name, offset);
477 cnt = nand->oobblock;
478 r = nand_read(nand, offset, &cnt, (u_char *) addr);
480 puts("** Read error\n");
481 show_boot_progress (-56);
484 show_boot_progress (56);
486 hdr = (image_header_t *) addr;
488 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
489 printf("\n** Bad Magic Number 0x%x **\n", hdr->ih_magic);
490 show_boot_progress (-57);
493 show_boot_progress (57);
495 print_image_hdr(hdr);
497 cnt = (ntohl(hdr->ih_size) + sizeof (image_header_t));
499 r = nand_read(nand, offset, &cnt, (u_char *) addr);
501 puts("** Read error\n");
502 show_boot_progress (-58);
505 show_boot_progress (58);
507 /* Loading ok, update default load address */
511 /* Check if we should attempt an auto-start */
512 if (((ep = getenv("autostart")) != NULL) && (strcmp(ep, "yes") == 0)) {
514 extern int do_bootm(cmd_tbl_t *, int, int, char *[]);
517 local_args[1] = NULL;
519 printf("Automatic boot of image at addr 0x%08lx ...\n", addr);
521 do_bootm(cmdtp, 0, 1, local_args);
527 int do_nandboot(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
529 char *boot_device = NULL;
531 ulong addr, offset = 0;
532 #if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
533 struct mtd_device *dev;
534 struct part_info *part;
538 char *p = (argc == 2) ? argv[1] : argv[2];
539 if (!(str2long(p, &addr)) && (mtdparts_init() == 0) &&
540 (find_dev_and_part(p, &dev, &pnum, &part) == 0)) {
541 if (dev->id->type != MTD_DEV_TYPE_NAND) {
542 puts("Not a NAND device\n");
548 addr = simple_strtoul(argv[2], NULL, 16);
550 addr = CFG_LOAD_ADDR;
551 return nand_load_image(cmdtp, &nand_info[dev->id->num],
552 part->offset, addr, argv[0]);
557 show_boot_progress(52);
560 addr = CFG_LOAD_ADDR;
561 boot_device = getenv("bootdevice");
564 addr = simple_strtoul(argv[1], NULL, 16);
565 boot_device = getenv("bootdevice");
568 addr = simple_strtoul(argv[1], NULL, 16);
569 boot_device = argv[2];
572 addr = simple_strtoul(argv[1], NULL, 16);
573 boot_device = argv[2];
574 offset = simple_strtoul(argv[3], NULL, 16);
577 #if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
580 printf("Usage:\n%s\n", cmdtp->usage);
581 show_boot_progress(-53);
585 show_boot_progress(53);
587 puts("\n** No boot device **\n");
588 show_boot_progress(-54);
591 show_boot_progress(54);
593 idx = simple_strtoul(boot_device, NULL, 16);
595 if (idx < 0 || idx >= CFG_MAX_NAND_DEVICE || !nand_info[idx].name) {
596 printf("\n** Device %d not available\n", idx);
597 show_boot_progress(-55);
600 show_boot_progress(55);
602 return nand_load_image(cmdtp, &nand_info[idx], offset, addr, argv[0]);
605 U_BOOT_CMD(nboot, 4, 1, do_nandboot,
606 "nboot - boot from NAND device\n",
607 "[partition] | [[[loadAddr] dev] offset]\n");
611 #else /* CFG_NAND_LEGACY */
614 * Legacy NAND support - to be phased out
620 #include <watchdog.h>
622 #ifdef CONFIG_show_boot_progress
623 # include <status_led.h>
624 # define show_boot_progress(arg) show_boot_progress(arg)
626 # define show_boot_progress(arg)
629 #if defined(CONFIG_CMD_NAND)
630 #include <linux/mtd/nand_legacy.h>
632 #include <linux/mtd/nand_ids.h>
633 #include <jffs2/jffs2.h>
636 #ifdef CONFIG_OMAP1510
637 void archflashwp(void *archdata, int wp);
640 #define ROUND_DOWN(value,boundary) ((value) & (~((boundary)-1)))
645 /* ****************** WARNING *********************
646 * When ALLOW_ERASE_BAD_DEBUG is non-zero the erase command will
647 * erase (or at least attempt to erase) blocks that are marked
648 * bad. This can be very handy if you are _sure_ that the block
649 * is OK, say because you marked a good block bad to test bad
650 * block handling and you are done testing, or if you have
651 * accidentally marked blocks bad.
653 * Erasing factory marked bad blocks is a _bad_ idea. If the
654 * erase succeeds there is no reliable way to find them again,
655 * and attempting to program or erase bad blocks can affect
656 * the data in _other_ (good) blocks.
658 #define ALLOW_ERASE_BAD_DEBUG 0
660 #define CONFIG_MTD_NAND_ECC /* enable ECC */
661 #define CONFIG_MTD_NAND_ECC_JFFS2
663 /* bits for nand_legacy_rw() `cmd'; or together as needed */
664 #define NANDRW_READ 0x01
665 #define NANDRW_WRITE 0x00
666 #define NANDRW_JFFS2 0x02
667 #define NANDRW_JFFS2_SKIP 0x04
670 * Imports from nand_legacy.c
672 extern struct nand_chip nand_dev_desc[CFG_MAX_NAND_DEVICE];
673 extern int curr_device;
674 extern int nand_legacy_erase(struct nand_chip *nand, size_t ofs,
675 size_t len, int clean);
676 extern int nand_legacy_rw(struct nand_chip *nand, int cmd, size_t start,
677 size_t len, size_t *retlen, u_char *buf);
678 extern void nand_print(struct nand_chip *nand);
679 extern void nand_print_bad(struct nand_chip *nand);
680 extern int nand_read_oob(struct nand_chip *nand, size_t ofs,
681 size_t len, size_t *retlen, u_char *buf);
682 extern int nand_write_oob(struct nand_chip *nand, size_t ofs,
683 size_t len, size_t *retlen, const u_char *buf);
686 int do_nand (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
693 printf ("Usage:\n%s\n", cmdtp->usage);
696 if (strcmp (argv[1], "info") == 0) {
701 for (i = 0; i < CFG_MAX_NAND_DEVICE; ++i) {
702 if (nand_dev_desc[i].ChipID ==
704 continue; /* list only known devices */
705 printf ("Device %d: ", i);
706 nand_print (&nand_dev_desc[i]);
710 } else if (strcmp (argv[1], "device") == 0) {
711 if ((curr_device < 0)
712 || (curr_device >= CFG_MAX_NAND_DEVICE)) {
713 puts ("\nno devices available\n");
716 printf ("\nDevice %d: ", curr_device);
717 nand_print (&nand_dev_desc[curr_device]);
720 } else if (strcmp (argv[1], "bad") == 0) {
721 if ((curr_device < 0)
722 || (curr_device >= CFG_MAX_NAND_DEVICE)) {
723 puts ("\nno devices available\n");
726 printf ("\nDevice %d bad blocks:\n", curr_device);
727 nand_print_bad (&nand_dev_desc[curr_device]);
731 printf ("Usage:\n%s\n", cmdtp->usage);
734 if (strcmp (argv[1], "device") == 0) {
735 int dev = (int) simple_strtoul (argv[2], NULL, 10);
737 printf ("\nDevice %d: ", dev);
738 if (dev >= CFG_MAX_NAND_DEVICE) {
739 puts ("unknown device\n");
742 nand_print (&nand_dev_desc[dev]);
743 /*nand_print (dev); */
745 if (nand_dev_desc[dev].ChipID == NAND_ChipID_UNKNOWN) {
751 puts ("... is now current device\n");
754 } else if (strcmp (argv[1], "erase") == 0
755 && strcmp (argv[2], "clean") == 0) {
756 struct nand_chip *nand = &nand_dev_desc[curr_device];
758 ulong size = nand->totlen;
761 printf ("\nNAND erase: device %d offset %ld, size %ld ... ", curr_device, off, size);
763 ret = nand_legacy_erase (nand, off, size, 1);
765 printf ("%s\n", ret ? "ERROR" : "OK");
770 printf ("Usage:\n%s\n", cmdtp->usage);
773 /* at least 4 args */
775 if (strncmp (argv[1], "read", 4) == 0 ||
776 strncmp (argv[1], "write", 5) == 0) {
777 ulong addr = simple_strtoul (argv[2], NULL, 16);
778 ulong off = simple_strtoul (argv[3], NULL, 16);
779 ulong size = simple_strtoul (argv[4], NULL, 16);
780 int cmd = (strncmp (argv[1], "read", 4) == 0) ?
781 NANDRW_READ : NANDRW_WRITE;
783 char *cmdtail = strchr (argv[1], '.');
785 if (cmdtail && !strncmp (cmdtail, ".oob", 2)) {
786 /* read out-of-band data */
787 if (cmd & NANDRW_READ) {
788 ret = nand_read_oob (nand_dev_desc + curr_device,
789 off, size, (size_t *) & total,
792 ret = nand_write_oob (nand_dev_desc + curr_device,
793 off, size, (size_t *) & total,
797 } else if (cmdtail && !strncmp (cmdtail, ".jffs2", 2))
798 cmd |= NANDRW_JFFS2; /* skip bad blocks */
799 else if (cmdtail && !strncmp (cmdtail, ".jffs2s", 2)) {
800 cmd |= NANDRW_JFFS2; /* skip bad blocks (on read too) */
801 if (cmd & NANDRW_READ)
802 cmd |= NANDRW_JFFS2_SKIP; /* skip bad blocks (on read too) */
805 /* need ".e" same as ".j" for compatibility with older units */
806 else if (cmdtail && !strcmp (cmdtail, ".e"))
807 cmd |= NANDRW_JFFS2; /* skip bad blocks */
809 #ifdef CFG_NAND_SKIP_BAD_DOT_I
810 /* need ".i" same as ".jffs2s" for compatibility with older units (esd) */
811 /* ".i" for image -> read skips bad block (no 0xff) */
812 else if (cmdtail && !strcmp (cmdtail, ".i")) {
813 cmd |= NANDRW_JFFS2; /* skip bad blocks (on read too) */
814 if (cmd & NANDRW_READ)
815 cmd |= NANDRW_JFFS2_SKIP; /* skip bad blocks (on read too) */
817 #endif /* CFG_NAND_SKIP_BAD_DOT_I */
819 printf ("Usage:\n%s\n", cmdtp->usage);
823 printf ("\nNAND %s: device %d offset %ld, size %ld ...\n",
824 (cmd & NANDRW_READ) ? "read" : "write",
825 curr_device, off, size);
827 ret = nand_legacy_rw (nand_dev_desc + curr_device,
832 printf (" %d bytes %s: %s\n", total,
833 (cmd & NANDRW_READ) ? "read" : "written",
834 ret ? "ERROR" : "OK");
837 } else if (strcmp (argv[1], "erase") == 0 &&
838 (argc == 4 || strcmp ("clean", argv[2]) == 0)) {
839 int clean = argc == 5;
841 simple_strtoul (argv[2 + clean], NULL, 16);
843 simple_strtoul (argv[3 + clean], NULL, 16);
846 printf ("\nNAND erase: device %d offset %ld, size %ld ...\n",
847 curr_device, off, size);
849 ret = nand_legacy_erase (nand_dev_desc + curr_device,
852 printf ("%s\n", ret ? "ERROR" : "OK");
856 printf ("Usage:\n%s\n", cmdtp->usage);
866 "nand - legacy NAND sub-system\n",
867 "info - show available NAND devices\n"
868 "nand device [dev] - show or set current device\n"
869 "nand read[.jffs2[s]] addr off size\n"
870 "nand write[.jffs2] addr off size - read/write `size' bytes starting\n"
871 " at offset `off' to/from memory address `addr'\n"
872 "nand erase [clean] [off size] - erase `size' bytes from\n"
873 " offset `off' (entire device if not specified)\n"
874 "nand bad - show bad blocks\n"
875 "nand read.oob addr off size - read out-of-band data\n"
876 "nand write.oob addr off size - read out-of-band data\n"
879 int do_nandboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
881 char *boot_device = NULL;
889 show_boot_progress (52);
892 addr = CFG_LOAD_ADDR;
893 boot_device = getenv ("bootdevice");
896 addr = simple_strtoul(argv[1], NULL, 16);
897 boot_device = getenv ("bootdevice");
900 addr = simple_strtoul(argv[1], NULL, 16);
901 boot_device = argv[2];
904 addr = simple_strtoul(argv[1], NULL, 16);
905 boot_device = argv[2];
906 offset = simple_strtoul(argv[3], NULL, 16);
909 printf ("Usage:\n%s\n", cmdtp->usage);
910 show_boot_progress (-53);
914 show_boot_progress (53);
916 puts ("\n** No boot device **\n");
917 show_boot_progress (-54);
920 show_boot_progress (54);
922 dev = simple_strtoul(boot_device, &ep, 16);
924 if ((dev >= CFG_MAX_NAND_DEVICE) ||
925 (nand_dev_desc[dev].ChipID == NAND_ChipID_UNKNOWN)) {
926 printf ("\n** Device %d not available\n", dev);
927 show_boot_progress (-55);
930 show_boot_progress (55);
932 printf ("\nLoading from device %d: %s at 0x%lx (offset 0x%lx)\n",
933 dev, nand_dev_desc[dev].name, nand_dev_desc[dev].IO_ADDR,
936 if (nand_legacy_rw (nand_dev_desc + dev, NANDRW_READ, offset,
937 SECTORSIZE, NULL, (u_char *)addr)) {
938 printf ("** Read error on %d\n", dev);
939 show_boot_progress (-56);
942 show_boot_progress (56);
944 hdr = (image_header_t *)addr;
946 if (ntohl(hdr->ih_magic) == IH_MAGIC) {
948 print_image_hdr (hdr);
950 cnt = (ntohl(hdr->ih_size) + sizeof(image_header_t));
953 printf ("\n** Bad Magic Number 0x%x **\n", ntohl(hdr->ih_magic));
954 show_boot_progress (-57);
957 show_boot_progress (57);
959 if (nand_legacy_rw (nand_dev_desc + dev, NANDRW_READ,
960 offset + SECTORSIZE, cnt, NULL,
961 (u_char *)(addr+SECTORSIZE))) {
962 printf ("** Read error on %d\n", dev);
963 show_boot_progress (-58);
966 show_boot_progress (58);
968 /* Loading ok, update default load address */
972 /* Check if we should attempt an auto-start */
973 if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) {
975 extern int do_bootm (cmd_tbl_t *, int, int, char *[]);
977 local_args[0] = argv[0];
978 local_args[1] = NULL;
980 printf ("Automatic boot of image at addr 0x%08lx ...\n", addr);
982 do_bootm (cmdtp, 0, 1, local_args);
989 nboot, 4, 1, do_nandboot,
990 "nboot - boot from NAND device\n",
996 #endif /* CFG_NAND_LEGACY */