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 * 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.
11 * Added 16-bit nand support
12 * (C) 2004 Texas Instruments
14 * Copyright 2010, 2012 Freescale Semiconductor
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.
23 #include <linux/mtd/mtd.h>
28 #include <asm/byteorder.h>
29 #include <jffs2/jffs2.h>
32 #if defined(CONFIG_CMD_MTDPARTS)
34 /* partition handling routines */
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,
38 u8 *part_num, struct part_info **part);
41 static int nand_dump(nand_info_t *nand, ulong off, int only_oob, int repeat)
44 u_char *datbuf, *oobbuf, *p;
49 off = last + nand->writesize;
53 datbuf = memalign(ARCH_DMA_MINALIGN, nand->writesize);
55 puts("No memory for page buffer\n");
59 oobbuf = memalign(ARCH_DMA_MINALIGN, nand->oobsize);
61 puts("No memory for page buffer\n");
65 off &= ~(nand->writesize - 1);
66 loff_t addr = (loff_t) off;
67 struct mtd_oob_ops ops;
68 memset(&ops, 0, sizeof(ops));
71 ops.len = nand->writesize;
72 ops.ooblen = nand->oobsize;
73 ops.mode = MTD_OPS_RAW;
74 i = mtd_read_oob(nand, addr, &ops);
76 printf("Error (%d) reading page %08lx\n", i, off);
80 printf("Page %08lx dump:\n", off);
83 i = nand->writesize >> 4;
87 printf("\t%02x %02x %02x %02x %02x %02x %02x %02x"
88 " %02x %02x %02x %02x %02x %02x %02x %02x\n",
89 p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],
90 p[8], p[9], p[10], p[11], p[12], p[13], p[14],
97 i = nand->oobsize >> 3;
100 printf("\t%02x %02x %02x %02x %02x %02x %02x %02x\n",
101 p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
113 /* ------------------------------------------------------------------------- */
115 static int set_dev(int dev)
117 if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE ||
118 !nand_info[dev].name) {
119 puts("No such device\n");
123 if (nand_curr_device == dev)
126 printf("Device %d: %s", dev, nand_info[dev].name);
127 puts("... is now current device\n");
128 nand_curr_device = dev;
130 #ifdef CONFIG_SYS_NAND_SELECT_DEVICE
131 board_nand_select_device(nand_info[dev].priv, dev);
137 #ifdef CONFIG_CMD_NAND_LOCK_UNLOCK
138 static void print_status(ulong start, ulong end, ulong erasesize, int status)
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.
146 printf("%08lx - %08lx: %08lx blocks %s%s%s\n",
149 (end - start) / erasesize,
150 ((status & NAND_LOCK_STATUS_TIGHT) ? "TIGHT " : ""),
151 (!(status & NAND_LOCK_STATUS_UNLOCK) ? "LOCK " : ""),
152 ((status & NAND_LOCK_STATUS_UNLOCK) ? "UNLOCK " : ""));
155 static void do_nand_status(nand_info_t *nand)
157 ulong block_start = 0;
159 int last_status = -1;
161 struct nand_chip *nand_chip = nand->priv;
162 /* check the WP bit */
163 nand_chip->cmdfunc(nand, NAND_CMD_STATUS, -1, -1);
164 printf("device is %swrite protected\n",
165 (nand_chip->read_byte(nand) & 0x80 ?
168 for (off = 0; off < nand->size; off += nand->erasesize) {
169 int s = nand_get_lock_status(nand, off);
171 /* print message only if status has changed */
172 if (s != last_status && off != 0) {
173 print_status(block_start, off, nand->erasesize,
179 /* Print the last block info */
180 print_status(block_start, off, nand->erasesize, last_status);
184 #ifdef CONFIG_ENV_OFFSET_OOB
185 unsigned long nand_env_oob_offset;
187 int do_nand_env_oob(cmd_tbl_t *cmdtp, int argc, char *const argv[])
190 uint32_t oob_buf[ENV_OFFSET_SIZE/sizeof(uint32_t)];
191 nand_info_t *nand = &nand_info[0];
194 if (CONFIG_SYS_MAX_NAND_DEVICE == 0 || !nand->name) {
195 puts("no devices available\n");
201 if (!strcmp(cmd, "get")) {
202 ret = get_nand_env_oob(nand, &nand_env_oob_offset);
206 printf("0x%08lx\n", nand_env_oob_offset);
207 } else if (!strcmp(cmd, "set")) {
210 struct mtd_oob_ops ops;
216 /* We don't care about size, or maxsize. */
217 if (mtd_arg_off(argv[2], &idx, &addr, &maxsize, &maxsize,
218 MTD_DEV_TYPE_NAND, nand_info[idx].size)) {
219 puts("Offset or partition name expected\n");
223 puts("Offset or partition name expected\n");
228 puts("Partition not on first NAND device\n");
232 if (nand->oobavail < ENV_OFFSET_SIZE) {
233 printf("Insufficient available OOB bytes:\n"
234 "%d OOB bytes available but %d required for "
236 nand->oobavail, ENV_OFFSET_SIZE);
240 if ((addr & (nand->erasesize - 1)) != 0) {
241 printf("Environment offset must be block-aligned\n");
246 ops.mode = MTD_OOB_AUTO;
248 ops.ooblen = ENV_OFFSET_SIZE;
249 ops.oobbuf = (void *) oob_buf;
251 oob_buf[0] = ENV_OOB_MARKER;
252 oob_buf[1] = addr / nand->erasesize;
254 ret = nand->write_oob(nand, ENV_OFFSET_SIZE, &ops);
256 printf("Error writing OOB block 0\n");
260 ret = get_nand_env_oob(nand, &nand_env_oob_offset);
262 printf("Error reading env offset in OOB\n");
266 if (addr != nand_env_oob_offset) {
267 printf("Verification of env offset in OOB failed: "
268 "0x%08llx expected but got 0x%08lx\n",
269 (unsigned long long)addr, nand_env_oob_offset);
279 return CMD_RET_USAGE;
284 static void nand_print_and_set_info(int idx)
286 nand_info_t *nand = &nand_info[idx];
287 struct nand_chip *chip = nand->priv;
289 printf("Device %d: ", idx);
290 if (chip->numchips > 1)
291 printf("%dx ", chip->numchips);
292 printf("%s, sector size %u KiB\n",
293 nand->name, nand->erasesize >> 10);
294 printf(" Page size %8d b\n", nand->writesize);
295 printf(" OOB size %8d b\n", nand->oobsize);
296 printf(" Erase size %8d b\n", nand->erasesize);
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);
301 /* Set geometry info */
302 setenv_hex("nand_writesize", nand->writesize);
303 setenv_hex("nand_oobsize", nand->oobsize);
304 setenv_hex("nand_erasesize", nand->erasesize);
307 static int raw_access(nand_info_t *nand, ulong addr, loff_t off, ulong count,
314 mtd_oob_ops_t ops = {
315 .datbuf = (u8 *)addr,
316 .oobbuf = ((u8 *)addr) + nand->writesize,
317 .len = nand->writesize,
318 .ooblen = nand->oobsize,
323 ret = mtd_read_oob(nand, off, &ops);
325 ret = mtd_write_oob(nand, off, &ops);
327 ret = nand_verify_page_oob(nand, &ops, off);
331 printf("%s: error at offset %llx, ret %d\n",
332 __func__, (long long)off, ret);
336 addr += nand->writesize + nand->oobsize;
337 off += nand->writesize;
343 /* Adjust a chip/partition size down for bad blocks so we don't
344 * read/write past the end of a chip/partition by accident.
346 static void adjust_size_for_badblocks(loff_t *size, loff_t offset, int dev)
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.
351 nand_info_t *nand = &nand_info[dev];
352 loff_t maxoffset = offset + *size;
355 /* count badblocks in NAND from offset to offset + size */
356 for (; offset < maxoffset; offset += nand->erasesize) {
357 if (nand_block_isbad(nand, offset))
360 /* adjust size if any bad blocks found */
362 *size -= badblocks * nand->erasesize;
363 printf("size adjusted to 0x%llx (%d bad blocks)\n",
364 (unsigned long long)*size, badblocks);
368 static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
372 loff_t off, size, maxsize;
375 #ifdef CONFIG_SYS_NAND_QUIET
376 int quiet = CONFIG_SYS_NAND_QUIET;
380 const char *quiet_str = getenv("quiet");
381 int dev = nand_curr_device;
382 int repeat = flag & CMD_FLAG_REPEAT;
384 /* at least two arguments please */
389 quiet = simple_strtoul(quiet_str, NULL, 0) != 0;
393 /* Only "dump" is repeatable. */
394 if (repeat && strcmp(cmd, "dump"))
397 if (strcmp(cmd, "info") == 0) {
400 for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) {
401 if (nand_info[i].name)
402 nand_print_and_set_info(i);
407 if (strcmp(cmd, "device") == 0) {
410 if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE)
411 puts("no devices available\n");
413 nand_print_and_set_info(dev);
417 dev = (int)simple_strtoul(argv[2], NULL, 10);
423 #ifdef CONFIG_ENV_OFFSET_OOB
424 /* this command operates only on the first nand device */
425 if (strcmp(cmd, "env.oob") == 0)
426 return do_nand_env_oob(cmdtp, argc - 1, argv + 1);
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.
435 if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE ||
436 !nand_info[dev].name) {
437 puts("\nno devices available\n");
440 nand = &nand_info[dev];
442 if (strcmp(cmd, "bad") == 0) {
443 printf("\nDevice %d bad blocks:\n", dev);
444 for (off = 0; off < nand->size; off += nand->erasesize)
445 if (nand_block_isbad(nand, off))
446 printf(" %08llx\n", (unsigned long long)off);
453 * nand erase [clean] [off size]
455 if (strncmp(cmd, "erase", 5) == 0 || strncmp(cmd, "scrub", 5) == 0) {
456 nand_erase_options_t opts;
457 /* "clean" at index 2 means request to write cleanmarker */
458 int clean = argc > 2 && !strcmp("clean", argv[2]);
459 int scrub_yes = argc > 2 && !strcmp("-y", argv[2]);
460 int o = (clean || scrub_yes) ? 3 : 2;
461 int scrub = !strncmp(cmd, "scrub", 5);
464 const char *scrub_warn =
466 "scrub option will erase all factory set bad blocks!\n"
468 "There is no reliable way to recover them.\n"
470 "Use this command only for testing purposes if you\n"
472 "are sure of what you are doing!\n"
473 "\nReally scrub this NAND flash? <y/N>\n";
476 if (!strcmp(&cmd[5], ".spread")) {
478 } else if (!strcmp(&cmd[5], ".part")) {
480 } else if (!strcmp(&cmd[5], ".chip")) {
488 * Don't allow missing arguments to cause full chip/partition
489 * erases -- easy to do accidentally, e.g. with a misspelled
492 if (argc != o + args)
495 printf("\nNAND %s: ", cmd);
496 /* skip first two or three arguments, look for offset and size */
497 if (mtd_arg_off_size(argc - o, argv + o, &dev, &off, &size,
498 &maxsize, MTD_DEV_TYPE_NAND,
499 nand_info[dev].size) != 0)
505 nand = &nand_info[dev];
507 memset(&opts, 0, sizeof(opts));
512 opts.spread = spread;
519 if (confirm_yesno()) {
522 puts("scrub aborted\n");
527 ret = nand_erase_opts(nand, &opts);
528 printf("%s\n", ret ? "ERROR" : "OK");
530 return ret == 0 ? 0 : 1;
533 if (strncmp(cmd, "dump", 4) == 0) {
537 off = (int)simple_strtoul(argv[2], NULL, 16);
538 ret = nand_dump(nand, off, !strcmp(&cmd[4], ".oob"), repeat);
540 return ret == 0 ? 1 : 0;
543 if (strncmp(cmd, "read", 4) == 0 || strncmp(cmd, "write", 5) == 0) {
552 addr = (ulong)simple_strtoul(argv[2], NULL, 16);
554 read = strncmp(cmd, "read", 4) == 0; /* 1 = read, 0 = write */
555 printf("\nNAND %s: ", read ? "read" : "write");
557 s = strchr(cmd, '.');
559 if (s && !strcmp(s, ".raw")) {
562 if (mtd_arg_off(argv[3], &dev, &off, &size, &maxsize,
564 nand_info[dev].size))
570 nand = &nand_info[dev];
572 if (argc > 4 && !str2long(argv[4], &pagecount)) {
573 printf("'%s' is not a number\n", argv[4]);
577 if (pagecount * nand->writesize > size) {
578 puts("Size exceeds partition or device limit\n");
582 rwsize = pagecount * (nand->writesize + nand->oobsize);
584 if (mtd_arg_off_size(argc - 3, argv + 3, &dev, &off,
587 nand_info[dev].size) != 0)
593 /* size is unspecified */
595 adjust_size_for_badblocks(&size, off, dev);
599 nand = &nand_info[dev];
601 if (!s || !strcmp(s, ".jffs2") ||
602 !strcmp(s, ".e") || !strcmp(s, ".i")) {
604 ret = nand_read_skip_bad(nand, off, &rwsize,
608 ret = nand_write_skip_bad(nand, off, &rwsize,
612 #ifdef CONFIG_CMD_NAND_TRIMFFS
613 } else if (!strcmp(s, ".trimffs")) {
615 printf("Unknown nand command suffix '%s'\n", s);
618 ret = nand_write_skip_bad(nand, off, &rwsize, NULL,
619 maxsize, (u_char *)addr,
620 WITH_DROP_FFS | WITH_WR_VERIFY);
622 } else if (!strcmp(s, ".oob")) {
623 /* out-of-band data */
624 mtd_oob_ops_t ops = {
625 .oobbuf = (u8 *)addr,
631 ret = mtd_read_oob(nand, off, &ops);
633 ret = mtd_write_oob(nand, off, &ops);
635 ret = raw_access(nand, addr, off, pagecount, read);
637 printf("Unknown nand command suffix '%s'.\n", s);
641 printf(" %zu bytes %s: %s\n", rwsize,
642 read ? "read" : "written", ret ? "ERROR" : "OK");
644 return ret == 0 ? 0 : 1;
647 #ifdef CONFIG_CMD_NAND_TORTURE
648 if (strcmp(cmd, "torture") == 0) {
652 if (!str2off(argv[2], &off)) {
653 puts("Offset is not a valid number\n");
657 printf("\nNAND torture: device %d offset 0x%llx size 0x%x\n",
658 dev, off, nand->erasesize);
659 ret = nand_torture(nand, off);
660 printf(" %s\n", ret ? "Failed" : "Passed");
662 return ret == 0 ? 0 : 1;
666 if (strcmp(cmd, "markbad") == 0) {
674 addr = simple_strtoul(*argv, NULL, 16);
676 if (mtd_block_markbad(nand, addr)) {
677 printf("block 0x%08lx NOT marked "
678 "as bad! ERROR %d\n",
682 printf("block 0x%08lx successfully "
692 if (strcmp(cmd, "biterr") == 0) {
697 #ifdef CONFIG_CMD_NAND_LOCK_UNLOCK
698 if (strcmp(cmd, "lock") == 0) {
702 if (!strcmp("tight", argv[2]))
704 if (!strcmp("status", argv[2]))
708 do_nand_status(nand);
710 if (!nand_lock(nand, tight)) {
711 puts("NAND flash successfully locked\n");
713 puts("Error locking NAND flash\n");
720 if (strncmp(cmd, "unlock", 5) == 0) {
723 s = strchr(cmd, '.');
725 if (s && !strcmp(s, ".allexcept"))
728 if (mtd_arg_off_size(argc - 2, argv + 2, &dev, &off, &size,
729 &maxsize, MTD_DEV_TYPE_NAND,
730 nand_info[dev].size) < 0)
736 if (!nand_unlock(&nand_info[dev], off, size, allexcept)) {
737 puts("NAND flash successfully unlocked\n");
739 puts("Error unlocking NAND flash, "
740 "write and erase will probably fail\n");
748 return CMD_RET_USAGE;
751 #ifdef CONFIG_SYS_LONGHELP
752 static char nand_help_text[] =
753 "info - show available NAND devices\n"
754 "nand device [dev] - show or set current device\n"
755 "nand read - addr off|partition size\n"
756 "nand write - addr off|partition size\n"
757 " read/write 'size' bytes starting at offset 'off'\n"
758 " to/from memory address 'addr', skipping bad blocks.\n"
759 "nand read.raw - addr off|partition [count]\n"
760 "nand write.raw - addr off|partition [count]\n"
761 " Use read.raw/write.raw to avoid ECC and access the flash as-is.\n"
762 #ifdef CONFIG_CMD_NAND_TRIMFFS
763 "nand write.trimffs - addr off|partition size\n"
764 " write 'size' bytes starting at offset 'off' from memory address\n"
765 " 'addr', skipping bad blocks and dropping any pages at the end\n"
766 " of eraseblocks that contain only 0xFF\n"
768 "nand erase[.spread] [clean] off size - erase 'size' bytes "
769 "from offset 'off'\n"
770 " With '.spread', erase enough for given file size, otherwise,\n"
771 " 'size' includes skipped bad blocks.\n"
772 "nand erase.part [clean] partition - erase entire mtd partition'\n"
773 "nand erase.chip [clean] - erase entire chip'\n"
774 "nand bad - show bad blocks\n"
775 "nand dump[.oob] off - dump page\n"
776 #ifdef CONFIG_CMD_NAND_TORTURE
777 "nand torture off - torture block at offset\n"
779 "nand scrub [-y] off size | scrub.part partition | scrub.chip\n"
780 " really clean NAND erasing bad blocks (UNSAFE)\n"
781 "nand markbad off [...] - mark bad block(s) at offset (UNSAFE)\n"
782 "nand biterr off - make a bit error at offset (UNSAFE)"
783 #ifdef CONFIG_CMD_NAND_LOCK_UNLOCK
785 "nand lock [tight] [status]\n"
786 " bring nand to lock state or display locked pages\n"
787 "nand unlock[.allexcept] [offset] [size] - unlock section"
789 #ifdef CONFIG_ENV_OFFSET_OOB
791 "nand env.oob - environment offset in OOB of block 0 of"
793 "nand env.oob set off|partition - set enviromnent offset\n"
794 "nand env.oob get - get environment offset"
800 nand, CONFIG_SYS_MAXARGS, 1, do_nand,
801 "NAND sub-system", nand_help_text
804 static int nand_load_image(cmd_tbl_t *cmdtp, nand_info_t *nand,
805 ulong offset, ulong addr, char *cmd)
810 #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
813 #if defined(CONFIG_FIT)
814 const void *fit_hdr = NULL;
817 s = strchr(cmd, '.');
819 (strcmp(s, ".jffs2") && strcmp(s, ".e") && strcmp(s, ".i"))) {
820 printf("Unknown nand load suffix '%s'\n", s);
821 bootstage_error(BOOTSTAGE_ID_NAND_SUFFIX);
825 printf("\nLoading from %s, offset 0x%lx\n", nand->name, offset);
827 cnt = nand->writesize;
828 r = nand_read_skip_bad(nand, offset, &cnt, NULL, nand->size,
831 puts("** Read error\n");
832 bootstage_error(BOOTSTAGE_ID_NAND_HDR_READ);
835 bootstage_mark(BOOTSTAGE_ID_NAND_HDR_READ);
837 switch (genimg_get_format ((void *)addr)) {
838 #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
839 case IMAGE_FORMAT_LEGACY:
840 hdr = (image_header_t *)addr;
842 bootstage_mark(BOOTSTAGE_ID_NAND_TYPE);
843 image_print_contents (hdr);
845 cnt = image_get_image_size (hdr);
848 #if defined(CONFIG_FIT)
849 case IMAGE_FORMAT_FIT:
850 fit_hdr = (const void *)addr;
851 puts ("Fit image detected...\n");
853 cnt = fit_get_size (fit_hdr);
857 bootstage_error(BOOTSTAGE_ID_NAND_TYPE);
858 puts ("** Unknown image type\n");
861 bootstage_mark(BOOTSTAGE_ID_NAND_TYPE);
863 r = nand_read_skip_bad(nand, offset, &cnt, NULL, nand->size,
866 puts("** Read error\n");
867 bootstage_error(BOOTSTAGE_ID_NAND_READ);
870 bootstage_mark(BOOTSTAGE_ID_NAND_READ);
872 #if defined(CONFIG_FIT)
873 /* This cannot be done earlier, we need complete FIT image in RAM first */
874 if (genimg_get_format ((void *)addr) == IMAGE_FORMAT_FIT) {
875 if (!fit_check_format (fit_hdr)) {
876 bootstage_error(BOOTSTAGE_ID_NAND_FIT_READ);
877 puts ("** Bad FIT image format\n");
880 bootstage_mark(BOOTSTAGE_ID_NAND_FIT_READ_OK);
881 fit_print_contents (fit_hdr);
885 /* Loading ok, update default load address */
889 return bootm_maybe_autostart(cmdtp, cmd);
892 static int do_nandboot(cmd_tbl_t *cmdtp, int flag, int argc,
895 char *boot_device = NULL;
897 ulong addr, offset = 0;
898 #if defined(CONFIG_CMD_MTDPARTS)
899 struct mtd_device *dev;
900 struct part_info *part;
904 char *p = (argc == 2) ? argv[1] : argv[2];
905 if (!(str2long(p, &addr)) && (mtdparts_init() == 0) &&
906 (find_dev_and_part(p, &dev, &pnum, &part) == 0)) {
907 if (dev->id->type != MTD_DEV_TYPE_NAND) {
908 puts("Not a NAND device\n");
914 addr = simple_strtoul(argv[1], NULL, 16);
916 addr = CONFIG_SYS_LOAD_ADDR;
917 return nand_load_image(cmdtp, &nand_info[dev->id->num],
918 part->offset, addr, argv[0]);
923 bootstage_mark(BOOTSTAGE_ID_NAND_PART);
926 addr = CONFIG_SYS_LOAD_ADDR;
927 boot_device = getenv("bootdevice");
930 addr = simple_strtoul(argv[1], NULL, 16);
931 boot_device = getenv("bootdevice");
934 addr = simple_strtoul(argv[1], NULL, 16);
935 boot_device = argv[2];
938 addr = simple_strtoul(argv[1], NULL, 16);
939 boot_device = argv[2];
940 offset = simple_strtoul(argv[3], NULL, 16);
943 #if defined(CONFIG_CMD_MTDPARTS)
946 bootstage_error(BOOTSTAGE_ID_NAND_SUFFIX);
947 return CMD_RET_USAGE;
949 bootstage_mark(BOOTSTAGE_ID_NAND_SUFFIX);
952 puts("\n** No boot device **\n");
953 bootstage_error(BOOTSTAGE_ID_NAND_BOOT_DEVICE);
956 bootstage_mark(BOOTSTAGE_ID_NAND_BOOT_DEVICE);
958 idx = simple_strtoul(boot_device, NULL, 16);
960 if (idx < 0 || idx >= CONFIG_SYS_MAX_NAND_DEVICE || !nand_info[idx].name) {
961 printf("\n** Device %d not available\n", idx);
962 bootstage_error(BOOTSTAGE_ID_NAND_AVAILABLE);
965 bootstage_mark(BOOTSTAGE_ID_NAND_AVAILABLE);
967 return nand_load_image(cmdtp, &nand_info[idx], offset, addr, argv[0]);
970 U_BOOT_CMD(nboot, 4, 1, do_nandboot,
971 "boot from NAND device",
972 "[partition] | [[[loadAddr] dev] offset]"