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 <bootstage.h>
25 #include <asm/cache.h>
26 #include <linux/mtd/mtd.h>
32 #include <asm/byteorder.h>
33 #include <jffs2/jffs2.h>
36 #include "legacy-mtd-utils.h"
38 #if defined(CONFIG_CMD_MTDPARTS)
40 /* partition handling routines */
41 int mtdparts_init(void);
42 int find_dev_and_part(const char *id, struct mtd_device **dev,
43 u8 *part_num, struct part_info **part);
46 static int nand_dump(struct mtd_info *mtd, ulong off, int only_oob,
50 u_char *datbuf, *oobbuf, *p;
55 off = last + mtd->writesize;
59 datbuf = memalign(ARCH_DMA_MINALIGN, mtd->writesize);
61 puts("No memory for page buffer\n");
65 oobbuf = memalign(ARCH_DMA_MINALIGN, mtd->oobsize);
67 puts("No memory for page buffer\n");
71 off &= ~(mtd->writesize - 1);
72 loff_t addr = (loff_t) off;
73 struct mtd_oob_ops ops;
74 memset(&ops, 0, sizeof(ops));
77 ops.len = mtd->writesize;
78 ops.ooblen = mtd->oobsize;
79 ops.mode = MTD_OPS_RAW;
80 i = mtd_read_oob(mtd, addr, &ops);
82 printf("Error (%d) reading page %08lx\n", i, off);
86 printf("Page %08lx dump:\n", off);
89 i = mtd->writesize >> 4;
93 printf("\t%02x %02x %02x %02x %02x %02x %02x %02x"
94 " %02x %02x %02x %02x %02x %02x %02x %02x\n",
95 p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],
96 p[8], p[9], p[10], p[11], p[12], p[13], p[14],
103 i = mtd->oobsize >> 3;
106 printf("\t%02x %02x %02x %02x %02x %02x %02x %02x\n",
107 p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
119 /* ------------------------------------------------------------------------- */
121 static int set_dev(int dev)
123 struct mtd_info *mtd = get_nand_dev_by_index(dev);
128 if (nand_curr_device == dev)
131 printf("Device %d: %s", dev, mtd->name);
132 puts("... is now current device\n");
133 nand_curr_device = dev;
135 #ifdef CONFIG_SYS_NAND_SELECT_DEVICE
136 board_nand_select_device(mtd_to_nand(mtd), dev);
142 #ifdef CONFIG_CMD_NAND_LOCK_UNLOCK
143 static void print_status(ulong start, ulong end, ulong erasesize, int status)
146 * Micron NAND flash (e.g. MT29F4G08ABADAH4) BLOCK LOCK READ STATUS is
147 * not the same as others. Instead of bit 1 being lock, it is
148 * #lock_tight. To make the driver support either format, ignore bit 1
149 * and use only bit 0 and bit 2.
151 printf("%08lx - %08lx: %08lx blocks %s%s%s\n",
154 (end - start) / erasesize,
155 ((status & NAND_LOCK_STATUS_TIGHT) ? "TIGHT " : ""),
156 (!(status & NAND_LOCK_STATUS_UNLOCK) ? "LOCK " : ""),
157 ((status & NAND_LOCK_STATUS_UNLOCK) ? "UNLOCK " : ""));
160 static void do_nand_status(struct mtd_info *mtd)
162 ulong block_start = 0;
164 int last_status = -1;
166 struct nand_chip *nand_chip = mtd_to_nand(mtd);
167 /* check the WP bit */
168 nand_chip->cmdfunc(mtd, NAND_CMD_STATUS, -1, -1);
169 printf("device is %swrite protected\n",
170 (nand_chip->read_byte(mtd) & 0x80 ?
173 for (off = 0; off < mtd->size; off += mtd->erasesize) {
174 int s = nand_get_lock_status(mtd, off);
176 /* print message only if status has changed */
177 if (s != last_status && off != 0) {
178 print_status(block_start, off, mtd->erasesize,
184 /* Print the last block info */
185 print_status(block_start, off, mtd->erasesize, last_status);
189 #ifdef CONFIG_ENV_OFFSET_OOB
190 unsigned long nand_env_oob_offset;
192 int do_nand_env_oob(struct cmd_tbl *cmdtp, int argc, char *const argv[])
195 uint32_t oob_buf[ENV_OFFSET_SIZE/sizeof(uint32_t)];
196 struct mtd_info *mtd = get_nand_dev_by_index(0);
199 if (CONFIG_SYS_MAX_NAND_DEVICE == 0 || !mtd) {
200 puts("no devices available\n");
206 if (!strcmp(cmd, "get")) {
207 ret = get_nand_env_oob(mtd, &nand_env_oob_offset);
211 printf("0x%08lx\n", nand_env_oob_offset);
212 } else if (!strcmp(cmd, "set")) {
215 struct mtd_oob_ops ops;
221 mtd = get_nand_dev_by_index(idx);
222 /* We don't care about size, or maxsize. */
223 if (mtd_arg_off(argv[2], &idx, &addr, &maxsize, &maxsize,
224 MTD_DEV_TYPE_NAND, mtd->size)) {
225 puts("Offset or partition name expected\n");
229 puts("Offset or partition name expected\n");
234 puts("Partition not on first NAND device\n");
238 if (mtd->oobavail < ENV_OFFSET_SIZE) {
239 printf("Insufficient available OOB bytes:\n"
240 "%d OOB bytes available but %d required for "
242 mtd->oobavail, ENV_OFFSET_SIZE);
246 if ((addr & (mtd->erasesize - 1)) != 0) {
247 printf("Environment offset must be block-aligned\n");
252 ops.mode = MTD_OOB_AUTO;
254 ops.ooblen = ENV_OFFSET_SIZE;
255 ops.oobbuf = (void *) oob_buf;
257 oob_buf[0] = ENV_OOB_MARKER;
258 oob_buf[1] = addr / mtd->erasesize;
260 ret = mtd->write_oob(mtd, ENV_OFFSET_SIZE, &ops);
262 printf("Error writing OOB block 0\n");
266 ret = get_nand_env_oob(mtd, &nand_env_oob_offset);
268 printf("Error reading env offset in OOB\n");
272 if (addr != nand_env_oob_offset) {
273 printf("Verification of env offset in OOB failed: "
274 "0x%08llx expected but got 0x%08lx\n",
275 (unsigned long long)addr, nand_env_oob_offset);
285 return CMD_RET_USAGE;
290 static void nand_print_and_set_info(int idx)
292 struct mtd_info *mtd;
293 struct nand_chip *chip;
295 mtd = get_nand_dev_by_index(idx);
299 chip = mtd_to_nand(mtd);
300 printf("Device %d: ", idx);
301 if (chip->numchips > 1)
302 printf("%dx ", chip->numchips);
303 printf("%s, sector size %u KiB\n",
304 mtd->name, mtd->erasesize >> 10);
305 printf(" Page size %8d b\n", mtd->writesize);
306 printf(" OOB size %8d b\n", mtd->oobsize);
307 printf(" Erase size %8d b\n", mtd->erasesize);
308 printf(" subpagesize %8d b\n", chip->subpagesize);
309 printf(" options 0x%08x\n", chip->options);
310 printf(" bbt options 0x%08x\n", chip->bbt_options);
312 /* Set geometry info */
313 env_set_hex("nand_writesize", mtd->writesize);
314 env_set_hex("nand_oobsize", mtd->oobsize);
315 env_set_hex("nand_erasesize", mtd->erasesize);
318 static int raw_access(struct mtd_info *mtd, ulong addr, loff_t off,
319 ulong count, int read, int no_verify)
325 mtd_oob_ops_t ops = {
326 .datbuf = (u8 *)addr,
327 .oobbuf = ((u8 *)addr) + mtd->writesize,
328 .len = mtd->writesize,
329 .ooblen = mtd->oobsize,
334 ret = mtd_read_oob(mtd, off, &ops);
336 ret = mtd_write_oob(mtd, off, &ops);
337 if (!ret && !no_verify)
338 ret = nand_verify_page_oob(mtd, &ops, off);
342 printf("%s: error at offset %llx, ret %d\n",
343 __func__, (long long)off, ret);
347 addr += mtd->writesize + mtd->oobsize;
348 off += mtd->writesize;
354 /* Adjust a chip/partition size down for bad blocks so we don't
355 * read/write past the end of a chip/partition by accident.
357 static void adjust_size_for_badblocks(loff_t *size, loff_t offset, int dev)
359 /* We grab the nand info object here fresh because this is usually
360 * called after arg_off_size() which can change the value of dev.
362 struct mtd_info *mtd = get_nand_dev_by_index(dev);
363 loff_t maxoffset = offset + *size;
366 /* count badblocks in NAND from offset to offset + size */
367 for (; offset < maxoffset; offset += mtd->erasesize) {
368 if (nand_block_isbad(mtd, offset))
371 /* adjust size if any bad blocks found */
373 *size -= badblocks * mtd->erasesize;
374 printf("size adjusted to 0x%llx (%d bad blocks)\n",
375 (unsigned long long)*size, badblocks);
379 static int do_nand(struct cmd_tbl *cmdtp, int flag, int argc,
384 loff_t off, size, maxsize;
386 struct mtd_info *mtd;
387 #ifdef CONFIG_SYS_NAND_QUIET
388 int quiet = CONFIG_SYS_NAND_QUIET;
392 const char *quiet_str = env_get("quiet");
393 int dev = nand_curr_device;
394 int repeat = flag & CMD_FLAG_REPEAT;
396 /* at least two arguments please */
401 quiet = simple_strtoul(quiet_str, NULL, 0) != 0;
405 /* Only "dump" is repeatable. */
406 if (repeat && strcmp(cmd, "dump"))
409 if (strcmp(cmd, "info") == 0) {
412 for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
413 nand_print_and_set_info(i);
417 if (strcmp(cmd, "device") == 0) {
420 if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE)
421 puts("no devices available\n");
423 nand_print_and_set_info(dev);
427 dev = (int)simple_strtoul(argv[2], NULL, 10);
433 #ifdef CONFIG_ENV_OFFSET_OOB
434 /* this command operates only on the first nand device */
435 if (strcmp(cmd, "env.oob") == 0)
436 return do_nand_env_oob(cmdtp, argc - 1, argv + 1);
439 /* The following commands operate on the current device, unless
440 * overridden by a partition specifier. Note that if somehow the
441 * current device is invalid, it will have to be changed to a valid
442 * one before these commands can run, even if a partition specifier
443 * for another device is to be used.
445 mtd = get_nand_dev_by_index(dev);
447 puts("\nno devices available\n");
451 if (strcmp(cmd, "bad") == 0) {
452 printf("\nDevice %d bad blocks:\n", dev);
453 for (off = 0; off < mtd->size; off += mtd->erasesize)
454 if (nand_block_isbad(mtd, off))
455 printf(" %08llx\n", (unsigned long long)off);
462 * nand erase [clean] [off size]
464 if (strncmp(cmd, "erase", 5) == 0 || strncmp(cmd, "scrub", 5) == 0) {
465 nand_erase_options_t opts;
466 /* "clean" at index 2 means request to write cleanmarker */
467 int clean = argc > 2 && !strcmp("clean", argv[2]);
468 int scrub_yes = argc > 2 && !strcmp("-y", argv[2]);
469 int o = (clean || scrub_yes) ? 3 : 2;
470 int scrub = !strncmp(cmd, "scrub", 5);
473 const char *scrub_warn =
475 "scrub option will erase all factory set bad blocks!\n"
477 "There is no reliable way to recover them.\n"
479 "Use this command only for testing purposes if you\n"
481 "are sure of what you are doing!\n"
482 "\nReally scrub this NAND flash? <y/N>\n";
485 if (!strcmp(&cmd[5], ".spread")) {
487 } else if (!strcmp(&cmd[5], ".part")) {
489 } else if (!strcmp(&cmd[5], ".chip")) {
497 * Don't allow missing arguments to cause full chip/partition
498 * erases -- easy to do accidentally, e.g. with a misspelled
501 if (argc != o + args)
504 printf("\nNAND %s: ", cmd);
505 /* skip first two or three arguments, look for offset and size */
506 if (mtd_arg_off_size(argc - o, argv + o, &dev, &off, &size,
507 &maxsize, MTD_DEV_TYPE_NAND,
514 mtd = get_nand_dev_by_index(dev);
516 memset(&opts, 0, sizeof(opts));
521 opts.spread = spread;
528 if (confirm_yesno()) {
531 puts("scrub aborted\n");
536 ret = nand_erase_opts(mtd, &opts);
537 printf("%s\n", ret ? "ERROR" : "OK");
539 return ret == 0 ? 0 : 1;
542 if (strncmp(cmd, "dump", 4) == 0) {
546 off = (int)simple_strtoul(argv[2], NULL, 16);
547 ret = nand_dump(mtd, off, !strcmp(&cmd[4], ".oob"), repeat);
549 return ret == 0 ? 1 : 0;
552 if (strncmp(cmd, "read", 4) == 0 || strncmp(cmd, "write", 5) == 0) {
562 addr = (ulong)simple_strtoul(argv[2], NULL, 16);
564 read = strncmp(cmd, "read", 4) == 0; /* 1 = read, 0 = write */
565 printf("\nNAND %s: ", read ? "read" : "write");
567 s = strchr(cmd, '.');
569 if (s && !strncmp(s, ".raw", 4)) {
572 if (!strcmp(s, ".raw.noverify"))
575 if (mtd_arg_off(argv[3], &dev, &off, &size, &maxsize,
583 mtd = get_nand_dev_by_index(dev);
585 if (argc > 4 && !str2long(argv[4], &pagecount)) {
586 printf("'%s' is not a number\n", argv[4]);
590 if (pagecount * mtd->writesize > size) {
591 puts("Size exceeds partition or device limit\n");
595 rwsize = pagecount * (mtd->writesize + mtd->oobsize);
597 if (mtd_arg_off_size(argc - 3, argv + 3, &dev, &off,
606 /* size is unspecified */
608 adjust_size_for_badblocks(&size, off, dev);
612 mtd = get_nand_dev_by_index(dev);
614 if (!s || !strcmp(s, ".jffs2") ||
615 !strcmp(s, ".e") || !strcmp(s, ".i")) {
617 ret = nand_read_skip_bad(mtd, off, &rwsize,
621 ret = nand_write_skip_bad(mtd, off, &rwsize,
625 #ifdef CONFIG_CMD_NAND_TRIMFFS
626 } else if (!strcmp(s, ".trimffs")) {
628 printf("Unknown nand command suffix '%s'\n", s);
631 ret = nand_write_skip_bad(mtd, off, &rwsize, NULL,
632 maxsize, (u_char *)addr,
633 WITH_DROP_FFS | WITH_WR_VERIFY);
635 } else if (!strcmp(s, ".oob")) {
636 /* out-of-band data */
637 mtd_oob_ops_t ops = {
638 .oobbuf = (u8 *)addr,
644 ret = mtd_read_oob(mtd, off, &ops);
646 ret = mtd_write_oob(mtd, off, &ops);
648 ret = raw_access(mtd, addr, off, pagecount, read,
651 printf("Unknown nand command suffix '%s'.\n", s);
655 printf(" %zu bytes %s: %s\n", rwsize,
656 read ? "read" : "written", ret ? "ERROR" : "OK");
658 return ret == 0 ? 0 : 1;
661 #ifdef CONFIG_CMD_NAND_TORTURE
662 if (strcmp(cmd, "torture") == 0) {
664 unsigned int failed = 0, passed = 0;
669 if (!str2off(argv[2], &off)) {
670 puts("Offset is not a valid number\n");
674 size = mtd->erasesize;
676 if (!str2off(argv[3], &size)) {
677 puts("Size is not a valid number\n");
683 if (endoff > mtd->size) {
684 puts("Arguments beyond end of NAND\n");
688 off = round_down(off, mtd->erasesize);
689 endoff = round_up(endoff, mtd->erasesize);
691 printf("\nNAND torture: device %d offset 0x%llx size 0x%llx (block size 0x%x)\n",
692 dev, off, size, mtd->erasesize);
693 while (off < endoff) {
694 ret = nand_torture(mtd, off);
697 printf(" block at 0x%llx failed\n", off);
701 off += mtd->erasesize;
703 printf(" Passed: %u, failed: %u\n", passed, failed);
708 if (strcmp(cmd, "markbad") == 0) {
716 addr = simple_strtoul(*argv, NULL, 16);
718 if (mtd_block_markbad(mtd, addr)) {
719 printf("block 0x%08lx NOT marked "
720 "as bad! ERROR %d\n",
724 printf("block 0x%08lx successfully "
734 if (strcmp(cmd, "biterr") == 0) {
739 #ifdef CONFIG_CMD_NAND_LOCK_UNLOCK
740 if (strcmp(cmd, "lock") == 0) {
744 if (!strcmp("tight", argv[2]))
746 if (!strcmp("status", argv[2]))
752 if (!nand_lock(mtd, tight)) {
753 puts("NAND flash successfully locked\n");
755 puts("Error locking NAND flash\n");
762 if (strncmp(cmd, "unlock", 5) == 0) {
765 s = strchr(cmd, '.');
767 if (s && !strcmp(s, ".allexcept"))
770 if (mtd_arg_off_size(argc - 2, argv + 2, &dev, &off, &size,
771 &maxsize, MTD_DEV_TYPE_NAND,
778 mtd = get_nand_dev_by_index(dev);
780 if (!nand_unlock(mtd, off, size, allexcept)) {
781 puts("NAND flash successfully unlocked\n");
783 puts("Error unlocking NAND flash, "
784 "write and erase will probably fail\n");
792 return CMD_RET_USAGE;
795 #ifdef CONFIG_SYS_LONGHELP
796 static char nand_help_text[] =
797 "info - show available NAND devices\n"
798 "nand device [dev] - show or set current device\n"
799 "nand read - addr off|partition size\n"
800 "nand write - addr off|partition size\n"
801 " read/write 'size' bytes starting at offset 'off'\n"
802 " to/from memory address 'addr', skipping bad blocks.\n"
803 "nand read.raw - addr off|partition [count]\n"
804 "nand write.raw[.noverify] - addr off|partition [count]\n"
805 " Use read.raw/write.raw to avoid ECC and access the flash as-is.\n"
806 #ifdef CONFIG_CMD_NAND_TRIMFFS
807 "nand write.trimffs - addr off|partition size\n"
808 " write 'size' bytes starting at offset 'off' from memory address\n"
809 " 'addr', skipping bad blocks and dropping any pages at the end\n"
810 " of eraseblocks that contain only 0xFF\n"
812 "nand erase[.spread] [clean] off size - erase 'size' bytes "
813 "from offset 'off'\n"
814 " With '.spread', erase enough for given file size, otherwise,\n"
815 " 'size' includes skipped bad blocks.\n"
816 "nand erase.part [clean] partition - erase entire mtd partition'\n"
817 "nand erase.chip [clean] - erase entire chip'\n"
818 "nand bad - show bad blocks\n"
819 "nand dump[.oob] off - dump page\n"
820 #ifdef CONFIG_CMD_NAND_TORTURE
821 "nand torture off - torture one block at offset\n"
822 "nand torture off [size] - torture blocks from off to off+size\n"
824 "nand scrub [-y] off size | scrub.part partition | scrub.chip\n"
825 " really clean NAND erasing bad blocks (UNSAFE)\n"
826 "nand markbad off [...] - mark bad block(s) at offset (UNSAFE)\n"
827 "nand biterr off - make a bit error at offset (UNSAFE)"
828 #ifdef CONFIG_CMD_NAND_LOCK_UNLOCK
830 "nand lock [tight] [status]\n"
831 " bring nand to lock state or display locked pages\n"
832 "nand unlock[.allexcept] [offset] [size] - unlock section"
834 #ifdef CONFIG_ENV_OFFSET_OOB
836 "nand env.oob - environment offset in OOB of block 0 of"
838 "nand env.oob set off|partition - set enviromnent offset\n"
839 "nand env.oob get - get environment offset"
845 nand, CONFIG_SYS_MAXARGS, 1, do_nand,
846 "NAND sub-system", nand_help_text
849 static int nand_load_image(struct cmd_tbl *cmdtp, struct mtd_info *mtd,
850 ulong offset, ulong addr, char *cmd)
855 #if defined(CONFIG_LEGACY_IMAGE_FORMAT)
858 #if defined(CONFIG_FIT)
859 const void *fit_hdr = NULL;
862 s = strchr(cmd, '.');
864 (strcmp(s, ".jffs2") && strcmp(s, ".e") && strcmp(s, ".i"))) {
865 printf("Unknown nand load suffix '%s'\n", s);
866 bootstage_error(BOOTSTAGE_ID_NAND_SUFFIX);
870 printf("\nLoading from %s, offset 0x%lx\n", mtd->name, offset);
872 cnt = mtd->writesize;
873 r = nand_read_skip_bad(mtd, offset, &cnt, NULL, mtd->size,
876 puts("** Read error\n");
877 bootstage_error(BOOTSTAGE_ID_NAND_HDR_READ);
880 bootstage_mark(BOOTSTAGE_ID_NAND_HDR_READ);
882 switch (genimg_get_format ((void *)addr)) {
883 #if defined(CONFIG_LEGACY_IMAGE_FORMAT)
884 case IMAGE_FORMAT_LEGACY:
885 hdr = (image_header_t *)addr;
887 bootstage_mark(BOOTSTAGE_ID_NAND_TYPE);
888 image_print_contents (hdr);
890 cnt = image_get_image_size (hdr);
893 #if defined(CONFIG_FIT)
894 case IMAGE_FORMAT_FIT:
895 fit_hdr = (const void *)addr;
896 puts ("Fit image detected...\n");
898 cnt = fit_get_size (fit_hdr);
902 bootstage_error(BOOTSTAGE_ID_NAND_TYPE);
903 puts ("** Unknown image type\n");
906 bootstage_mark(BOOTSTAGE_ID_NAND_TYPE);
908 r = nand_read_skip_bad(mtd, offset, &cnt, NULL, mtd->size,
911 puts("** Read error\n");
912 bootstage_error(BOOTSTAGE_ID_NAND_READ);
915 bootstage_mark(BOOTSTAGE_ID_NAND_READ);
917 #if defined(CONFIG_FIT)
918 /* This cannot be done earlier, we need complete FIT image in RAM first */
919 if (genimg_get_format ((void *)addr) == IMAGE_FORMAT_FIT) {
920 if (fit_check_format(fit_hdr, IMAGE_SIZE_INVAL)) {
921 bootstage_error(BOOTSTAGE_ID_NAND_FIT_READ);
922 puts ("** Bad FIT image format\n");
925 bootstage_mark(BOOTSTAGE_ID_NAND_FIT_READ_OK);
926 fit_print_contents (fit_hdr);
930 /* Loading ok, update default load address */
932 image_load_addr = addr;
934 return bootm_maybe_autostart(cmdtp, cmd);
937 static int do_nandboot(struct cmd_tbl *cmdtp, int flag, int argc,
940 char *boot_device = NULL;
942 ulong addr, offset = 0;
943 struct mtd_info *mtd;
944 #if defined(CONFIG_CMD_MTDPARTS)
945 struct mtd_device *dev;
946 struct part_info *part;
950 char *p = (argc == 2) ? argv[1] : argv[2];
951 if (!(str2long(p, &addr)) && (mtdparts_init() == 0) &&
952 (find_dev_and_part(p, &dev, &pnum, &part) == 0)) {
953 if (dev->id->type != MTD_DEV_TYPE_NAND) {
954 puts("Not a NAND device\n");
960 addr = simple_strtoul(argv[1], NULL, 16);
962 addr = CONFIG_SYS_LOAD_ADDR;
964 mtd = get_nand_dev_by_index(dev->id->num);
965 return nand_load_image(cmdtp, mtd, part->offset,
971 bootstage_mark(BOOTSTAGE_ID_NAND_PART);
974 addr = CONFIG_SYS_LOAD_ADDR;
975 boot_device = env_get("bootdevice");
978 addr = simple_strtoul(argv[1], NULL, 16);
979 boot_device = env_get("bootdevice");
982 addr = simple_strtoul(argv[1], NULL, 16);
983 boot_device = argv[2];
986 addr = simple_strtoul(argv[1], NULL, 16);
987 boot_device = argv[2];
988 offset = simple_strtoul(argv[3], NULL, 16);
991 #if defined(CONFIG_CMD_MTDPARTS)
994 bootstage_error(BOOTSTAGE_ID_NAND_SUFFIX);
995 return CMD_RET_USAGE;
997 bootstage_mark(BOOTSTAGE_ID_NAND_SUFFIX);
1000 puts("\n** No boot device **\n");
1001 bootstage_error(BOOTSTAGE_ID_NAND_BOOT_DEVICE);
1004 bootstage_mark(BOOTSTAGE_ID_NAND_BOOT_DEVICE);
1006 idx = simple_strtoul(boot_device, NULL, 16);
1008 mtd = get_nand_dev_by_index(idx);
1010 printf("\n** Device %d not available\n", idx);
1011 bootstage_error(BOOTSTAGE_ID_NAND_AVAILABLE);
1014 bootstage_mark(BOOTSTAGE_ID_NAND_AVAILABLE);
1016 return nand_load_image(cmdtp, mtd, offset, addr, argv[0]);
1019 U_BOOT_CMD(nboot, 4, 1, do_nandboot,
1020 "boot from NAND device",
1021 "[partition] | [[[loadAddr] dev] offset]"