[PATCH] Adding NAND bad block managment to u-boot

Adds NAND driver support to u-boot with Bad Block management.

Signed-off-by: Syed Mohammed Khasim <khasim@ti.com>

This patch needs more cleanup to cmd_nand.c, we need to align with community on introducing new commands for Bad Block managment. We can keep this on our Test git for u-boot later take this up with community separately.

I will bundle up u-boot 1.3.3 with other test cases and latest x-loader and upload them on code.google.com hopefully by tomorrow.

Regards,
Khasim

Syed Mohammed, Khasim wrote:

Adds NAND driver support to u-boot with Bad Block management.

Signed-off-by: Syed Mohammed Khasim <khasim@ti.com>

checkpatch:

total: 164 errors, 45 warnings, 809 lines checked

The patch doesn't apply for me against Steve's git test head. Not sure
why, sometimes I have trouble with patch reformatting. Have to check...

Some comments:

+#if defined(CONFIG_OMAP) && (defined(CONFIG_3430LABRADOR) || defined(CONFIG_OMAP3EVM) || defined(CONFIG_OMAP3_BEAGLE))

Can we agree on only CONFIG_OMAP3_BEAGLE here?

+extern void omap_nand_switch_ecc(nand_info_t *nand, int hardware);
+#else
+#define omap_nand_switch_ecc(x, y) do {} while(0)
+#endif

Why not #ifdeffing the code using omap_nand_switch_ecc() ?

int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv)
{
        int i, dev, ret;
- ulong addr, off;
- size_t size;
+ ulong addr, off, size;

I think nand_read() expects size_t as third parameter? Why do you
change the type of size?

        char *cmd, *s;
        nand_info_t *nand;
-#ifdef CFG_NAND_QUIET
- int quiet = CFG_NAND_QUIET;
-#else
        int quiet = 0;
-#endif

Why do you remove this?

        const char *quiet_str = getenv("quiet");

        /* at least two arguments please */
@@ -209,23 +217,15 @@ int do_nand(cmd_tbl_t * cmdtp, int flag,
                printf("Device %d: %s", dev, nand_info[dev].name);
                puts("... is now current device\n");
                nand_curr_device = dev;
-
-#ifdef CFG_NAND_SELECT_DEVICE
- /*
- * Select the chip in the board/cpu specific driver
- */
- board_nand_select_device(nand_info[dev].priv, dev);
-#endif
-

Why do you remove this?

                return 0;
        }

- if (strcmp(cmd, "bad") != 0 && strcmp(cmd, "erase") != 0 &&
+ if (strncmp(cmd, "bad", 3) != 0 && strncmp(cmd, "erase", 5) != 0 &&
            strncmp(cmd, "dump", 4) != 0 &&
            strncmp(cmd, "read", 4) != 0 && strncmp(cmd, "write", 5) != 0 &&
- strcmp(cmd, "scrub") != 0 && strcmp(cmd, "markbad") != 0 &&
- strcmp(cmd, "biterr") != 0 &&
- strcmp(cmd, "lock") != 0 && strcmp(cmd, "unlock") != 0 )
+ strncmp(cmd, "scrub", 5) != 0 && strncmp(cmd, "markbad", 7) != 0 &&
+ strncmp(cmd, "biterr", 6) != 0 && strncmp(cmd, "ecc", 3) != 0 &&
+ strncmp(cmd, "lock", 4) != 0 && strncmp(cmd, "unlock", 6) != 0 )
                goto usage;

        /* the following commands operate on the current device */
@@ -308,6 +308,18 @@ int do_nand(cmd_tbl_t * cmdtp, int flag,
                return ret == 0 ? 1 : 0;

        }
+ if (strncmp(cmd, "ecc", 3) == 0) {
+ if (argc < 2)
+ goto usage;
+ if (strncmp(argv[2], "hw", 2) == 0)
+ omap_nand_switch_ecc(nand, 1);
+ else if (strncmp(argv[2], "sw", 2) == 0)
+ omap_nand_switch_ecc(nand, 0);
+ else
+ goto usage;
+
+ return 0;
+ }

        /* read write */
        if (strncmp(cmd, "read", 4) == 0 || strncmp(cmd, "write", 5) == 0) {
@@ -348,14 +360,6 @@ int do_nand(cmd_tbl_t * cmdtp, int flag,
                                opts.quiet = quiet;
                                ret = nand_write_opts(nand, &opts);
                        }
- } else if (s != NULL && !strcmp(s, ".oob")) {
- /* read out-of-band data */
- if (read)
- ret = nand->read_oob(nand, off, size, &size,
- (u_char *) addr);
- else
- ret = nand->write_oob(nand, off, size, &size,
- (u_char *) addr);
                } else {
                        if (read)
                                ret = nand_read(nand, off, &size, (u_char *)addr);
@@ -445,6 +449,9 @@ int do_nand(cmd_tbl_t * cmdtp, int flag,
                if (arg_off_size(argc - 2, argv + 2, nand, &off, &size) < 0)
                        return 1;

+ if (off == 0 && size == 0)
+ return 1;
+
                if (!nand_unlock(nand, off, size)) {
                        puts("NAND flash successfully unlocked\n");
                } else {
@@ -464,8 +471,8 @@ U_BOOT_CMD(nand, 5, 1, do_nand,
        "nand - NAND sub-system\n",
        "info - show available NAND devices\n"
        "nand device [dev] - show or set current device\n"
- "nand read[.jffs2] - addr off|partition size\n"
- "nand write[.jffs2] - addr off|partition size - read/write `size' bytes starting\n"
+ "nand read[.jffs2 /.i/.e] - addr off|partition size\n"
+ "nand write[.jffs2/.i/.e] - addr off|partiton size - read/write `size' bytes starting\n"
        " at offset `off' to/from memory address `addr'\n"
        "nand erase [clean] [off size] - erase `size' bytes from\n"
        " offset `off' (entire device if not specified)\n"
@@ -474,101 +481,47 @@ U_BOOT_CMD(nand, 5, 1, do_nand,
        "nand scrub - really clean NAND erasing bad blocks (UNSAFE)\n"
        "nand markbad off - mark bad block at offset (UNSAFE)\n"
        "nand biterr off - make a bit error at offset (UNSAFE)\n"
+ "nand ecc [hw/sw] - switch the ecc calculation algorithm \n"
        "nand lock [tight] [status] - bring nand to lock state or display locked pages\n"
- "nand unlock [offset] [size] - unlock section\n");
+ "nand unlock off size - unlock `size' bytes from\n"
+ " offset `off' (entire device if not specified)\n");

static int nand_load_image(cmd_tbl_t *cmdtp, nand_info_t *nand,
                           ulong offset, ulong addr, char *cmd)
{
        int r;
- char *ep, *s;
- size_t cnt;
+ char *ep;
+ ulong cnt;

Didn't check, but are you sure that type of cnt should be changed?

        image_header_t *hdr;
- int jffs2 = 0;
-#if defined(CONFIG_FIT)
- const void *fit_hdr;
-#endif
-
- s = strchr(cmd, '.');
- if (s != NULL &&
- (!strcmp(s, ".jffs2") || !strcmp(s, ".e") || !strcmp(s, ".i")))
- jffs2 = 1;

        printf("\nLoading from %s, offset 0x%lx\n", nand->name, offset);

        cnt = nand->oobblock;
- if (jffs2) {
- nand_read_options_t opts;
- memset(&opts, 0, sizeof(opts));
- opts.buffer = (u_char*) addr;
- opts.length = cnt;
- opts.offset = offset;
- opts.quiet = 1;
- r = nand_read_opts(nand, &opts);
- } else {
- r = nand_read(nand, offset, &cnt, (u_char *) addr);
- }
-
+ r = nand_read(nand, offset, &cnt, (u_char *) addr);
        if (r) {
                puts("** Read error\n");
- show_boot_progress (-56);
+ SHOW_BOOT_PROGRESS(-1);
                return 1;
        }
- show_boot_progress (56);

- switch (genimg_get_format ((void *)addr)) {
- case IMAGE_FORMAT_LEGACY:
- hdr = (image_header_t *)addr;
+ hdr = (image_header_t *) addr;

- show_boot_progress (57);
- image_print_contents (hdr);
-
- cnt = image_get_image_size (hdr);
- break;
-#if defined(CONFIG_FIT)
- case IMAGE_FORMAT_FIT:
- fit_hdr = (const void *)addr;
- if (!fit_check_format (fit_hdr)) {
- show_boot_progress (-150);
- puts ("** Bad FIT image format\n");
- return 1;
- }
- show_boot_progress (151);
- puts ("Fit image detected...\n");
-
- cnt = fit_get_size (fit_hdr);
- break;
-#endif
- default:
- show_boot_progress (-57);
- puts ("** Unknown image type\n");
+ if (ntohl(hdr->ih_magic) != IH_MAGIC) {
+ printf("\n** Bad Magic Number 0x%x **\n", hdr->ih_magic);
+ SHOW_BOOT_PROGRESS(-1);
                return 1;
        }

- if (jffs2) {
- nand_read_options_t opts;
- memset(&opts, 0, sizeof(opts));
- opts.buffer = (u_char*) addr;
- opts.length = cnt;
- opts.offset = offset;
- opts.quiet = 1;
- r = nand_read_opts(nand, &opts);
- } else {
- r = nand_read(nand, offset, &cnt, (u_char *) addr);
- }
+ //print_image_hdr(hdr);

Remove this if you don't need it.

+ cnt = (ntohl(hdr->ih_size) + sizeof (image_header_t));
+
+ r = nand_read(nand, offset, &cnt, (u_char *) addr);
        if (r) {
                puts("** Read error\n");
- show_boot_progress (-58);
+ SHOW_BOOT_PROGRESS(-1);
                return 1;
        }
- show_boot_progress (58);
-
-#if defined(CONFIG_FIT)
- /* This cannot be done earlier, we need complete FIT image in RAM first */
- if (genimg_get_format ((void *)addr) == IMAGE_FORMAT_FIT)
- fit_print_contents ((const void *)addr);
-#endif

        /* Loading ok, update default load address */

@@ -595,7 +548,7 @@ int do_nandboot(cmd_tbl_t * cmdtp, int f
        char *boot_device = NULL;
        int idx;
        ulong addr, offset = 0;
-#if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
+#if (CONFIG_COMMANDS & CFG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
        struct mtd_device *dev;
        struct part_info *part;
        u8 pnum;
@@ -611,7 +564,7 @@ int do_nandboot(cmd_tbl_t * cmdtp, int f
                        if (argc > 3)
                                goto usage;
                        if (argc == 3)
- addr = simple_strtoul(argv[1], NULL, 16);
+ addr = simple_strtoul(argv[2], NULL, 16);
                        else
                                addr = CFG_LOAD_ADDR;
                        return nand_load_image(cmdtp, &nand_info[dev->id->num],
@@ -620,7 +573,6 @@ int do_nandboot(cmd_tbl_t * cmdtp, int f
        }
#endif

- show_boot_progress(52);
        switch (argc) {
        case 1:
                addr = CFG_LOAD_ADDR;
@@ -640,39 +592,36 @@ int do_nandboot(cmd_tbl_t * cmdtp, int f
                offset = simple_strtoul(argv[3], NULL, 16);
                break;
        default:
-#if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
+#if (CONFIG_COMMANDS & CFG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
usage:
#endif
                printf("Usage:\n%s\n", cmdtp->usage);
- show_boot_progress(-53);
+ SHOW_BOOT_PROGRESS(-1);
                return 1;
        }

- show_boot_progress(53);
        if (!boot_device) {
                puts("\n** No boot device **\n");
- show_boot_progress(-54);
+ SHOW_BOOT_PROGRESS(-1);
                return 1;
        }
- show_boot_progress(54);

        idx = simple_strtoul(boot_device, NULL, 16);

        if (idx < 0 || idx >= CFG_MAX_NAND_DEVICE || !nand_info[idx].name) {
                printf("\n** Device %d not available\n", idx);
- show_boot_progress(-55);
+ SHOW_BOOT_PROGRESS(-1);
                return 1;
        }
- show_boot_progress(55);

        return nand_load_image(cmdtp, &nand_info[idx], offset, addr, argv[0]);
}

U_BOOT_CMD(nboot, 4, 1, do_nandboot,
        "nboot - boot from NAND device\n",
- "[.jffs2] [partition] | [[[loadAddr] dev] offset]\n");
+ "[partition] | [[[loadAddr] dev] offset]\n");

-#endif
+#endif /* (CONFIG_COMMANDS & CFG_CMD_NAND) */

#else /* CFG_NAND_LEGACY */
/*
@@ -685,14 +634,14 @@ U_BOOT_CMD(nboot, 4, 1, do_nandboot,
#include <asm/io.h>
#include <watchdog.h>

-#ifdef CONFIG_show_boot_progress
+#ifdef CONFIG_SHOW_BOOT_PROGRESS
# include <status_led.h>
-# define show_boot_progress(arg) show_boot_progress(arg)
+# define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg)
#else
-# define show_boot_progress(arg)
+# define SHOW_BOOT_PROGRESS(arg)
#endif

-#if defined(CONFIG_CMD_NAND)
+#if (CONFIG_COMMANDS & CFG_CMD_NAND)
#include <linux/mtd/nand_legacy.h>
#if 0

Can we remove this?

#include <linux/mtd/nand_ids.h>
@@ -749,183 +698,178 @@ extern int nand_write_oob(struct nand_ch
                                size_t len, size_t *retlen, const u_char *buf);

-int do_nand (cmd_tbl_t * cmdtp, int flag, int argc, char *argv)
+int do_nand (cmd_tbl_t *cmdtp, int flag, int argc, char *argv)
{
- int rcode = 0;
+ int rcode = 0;

- switch (argc) {
- case 0:
- case 1:
- printf ("Usage:\n%s\n", cmdtp->usage);
- return 1;
- case 2:
- if (strcmp (argv[1], "info") == 0) {
- int i;
-
- putc ('\n');
-
- for (i = 0; i < CFG_MAX_NAND_DEVICE; ++i) {
- if (nand_dev_desc[i].ChipID ==
- NAND_ChipID_UNKNOWN)
- continue; /* list only known devices */
- printf ("Device %d: ", i);
- nand_print (&nand_dev_desc[i]);
- }
- return 0;
+ switch (argc) {
+ case 0:
+ case 1:
+ printf ("Usage:\n%s\n", cmdtp->usage);
+ return 1;
+ case 2:
+ if (strcmp(argv[1],"info") == 0) {
+ int i;
+
+ putc ('\n');
+
+ for (i=0; i<CFG_MAX_NAND_DEVICE; ++i) {
+ if(nand_dev_desc[i].ChipID == NAND_ChipID_UNKNOWN)
+ continue; /* list only known devices */
+ printf ("Device %d: ", i);
+ nand_print(&nand_dev_desc[i]);
+ }
+ return 0;

- } else if (strcmp (argv[1], "device") == 0) {
- if ((curr_device < 0)
- || (curr_device >= CFG_MAX_NAND_DEVICE)) {
- puts ("\nno devices available\n");
- return 1;
- }
- printf ("\nDevice %d: ", curr_device);
- nand_print (&nand_dev_desc[curr_device]);
- return 0;
+ } else if (strcmp(argv[1],"device") == 0) {
+ if ((curr_device < 0) || (curr_device >= CFG_MAX_NAND_DEVICE)) {
+ puts ("\nno devices available\n");
+ return 1;
+ }
+ printf ("\nDevice %d: ", curr_device);
+ nand_print(&nand_dev_desc[curr_device]);
+ return 0;

- } else if (strcmp (argv[1], "bad") == 0) {
- if ((curr_device < 0)
- || (curr_device >= CFG_MAX_NAND_DEVICE)) {
- puts ("\nno devices available\n");
- return 1;
- }
- printf ("\nDevice %d bad blocks:\n", curr_device);
- nand_print_bad (&nand_dev_desc[curr_device]);
- return 0;
+ } else if (strcmp(argv[1],"bad") == 0) {
+ if ((curr_device < 0) || (curr_device >= CFG_MAX_NAND_DEVICE)) {
+ puts ("\nno devices available\n");
+ return 1;
+ }
+ printf ("\nDevice %d bad blocks:\n", curr_device);
+ nand_print_bad(&nand_dev_desc[curr_device]);
+ return 0;

+ }
+ printf ("Usage:\n%s\n", cmdtp->usage);
+ return 1;
+ case 3:
+ if (strcmp(argv[1],"device") == 0) {
+ int dev = (int)simple_strtoul(argv[2], NULL, 10);
+
+ printf ("\nDevice %d: ", dev);
+ if (dev >= CFG_MAX_NAND_DEVICE) {
+ puts ("unknown device\n");
+ return 1;
                }
- printf ("Usage:\n%s\n", cmdtp->usage);
- return 1;
- case 3:
- if (strcmp (argv[1], "device") == 0) {
- int dev = (int) simple_strtoul (argv[2], NULL, 10);
+ nand_print(&nand_dev_desc[dev]);
+ /*nand_print (dev);*/

- printf ("\nDevice %d: ", dev);
- if (dev >= CFG_MAX_NAND_DEVICE) {
- puts ("unknown device\n");
- return 1;
- }
- nand_print (&nand_dev_desc[dev]);
- /*nand_print (dev); */
+ if (nand_dev_desc[dev].ChipID == NAND_ChipID_UNKNOWN) {
+ return 1;
+ }

- if (nand_dev_desc[dev].ChipID == NAND_ChipID_UNKNOWN) {
- return 1;
- }
+ curr_device = dev;

- curr_device = dev;
+ puts ("... is now current device\n");

- puts ("... is now current device\n");
+ return 0;
+ }
+ else if (strcmp(argv[1],"erase") == 0 && strcmp(argv[2], "clean") == 0) {
+ struct nand_chip* nand = &nand_dev_desc[curr_device];
+ ulong off = 0;
+ ulong size = nand->totlen;
+ int ret;

- return 0;
- } else if (strcmp (argv[1], "erase") == 0
- && strcmp (argv[2], "clean") == 0) {
- struct nand_chip *nand = &nand_dev_desc[curr_device];
- ulong off = 0;
- ulong size = nand->totlen;
- int ret;
+ printf ("\nNAND erase: device %d offset %ld, size %ld ... ",
+ curr_device, off, size);

- printf ("\nNAND erase: device %d offset %ld, size %ld ... ", curr_device, off, size);
+ ret = nand_legacy_erase (nand, off, size, 1);

- ret = nand_legacy_erase (nand, off, size, 1);
+ printf("%s\n", ret ? "ERROR" : "OK");

- printf ("%s\n", ret ? "ERROR" : "OK");
+ return ret;
+ }

- return ret;
- }
+ printf ("Usage:\n%s\n", cmdtp->usage);
+ return 1;
+ default:
+ /* at least 4 args */

- printf ("Usage:\n%s\n", cmdtp->usage);
- return 1;
- default:
- /* at least 4 args */
+ if (strncmp(argv[1], "read", 4) == 0 ||
+ strncmp(argv[1], "write", 5) == 0) {
+ ulong addr = simple_strtoul(argv[2], NULL, 16);
+ ulong off = simple_strtoul(argv[3], NULL, 16);
+ ulong size = simple_strtoul(argv[4], NULL, 16);
+ int cmd = (strncmp(argv[1], "read", 4) == 0) ?
+ NANDRW_READ : NANDRW_WRITE;
+ int ret, total;
+ char* cmdtail = strchr(argv[1], '.');

- if (strncmp (argv[1], "read", 4) == 0 ||
- strncmp (argv[1], "write", 5) == 0) {
- ulong addr = simple_strtoul (argv[2], NULL, 16);
- off_t off = simple_strtoul (argv[3], NULL, 16);
- size_t size = simple_strtoul (argv[4], NULL, 16);
- int cmd = (strncmp (argv[1], "read", 4) == 0) ?
- NANDRW_READ : NANDRW_WRITE;
- size_t total;
- int ret;
- char *cmdtail = strchr (argv[1], '.');
-
- if (cmdtail && !strncmp (cmdtail, ".oob", 2)) {
- /* read out-of-band data */
- if (cmd & NANDRW_READ) {
- ret = nand_read_oob (nand_dev_desc + curr_device,
- off, size, &total,
- (u_char *) addr);
- } else {
- ret = nand_write_oob (nand_dev_desc + curr_device,
- off, size, &total,
- (u_char *) addr);
- }
- return ret;
- } else if (cmdtail && !strncmp (cmdtail, ".jffs2", 2))
- cmd |= NANDRW_JFFS2; /* skip bad blocks */
- else if (cmdtail && !strncmp (cmdtail, ".jffs2s", 2)) {
- cmd |= NANDRW_JFFS2; /* skip bad blocks (on read too) */
- if (cmd & NANDRW_READ)
- cmd |= NANDRW_JFFS2_SKIP; /* skip bad blocks (on read too) */
+ if (cmdtail && !strncmp(cmdtail, ".oob", 2)) {
+ /* read out-of-band data */
+ if (cmd & NANDRW_READ) {
+ ret = nand_read_oob(nand_dev_desc + curr_device,
+ off, size, (size_t *)&total,
+ (u_char*)addr);
+ }
+ else {
+ ret = nand_write_oob(nand_dev_desc + curr_device,
+ off, size, (size_t *)&total,
+ (u_char*)addr);
                        }
+ return ret;
+ }
+ else if (cmdtail && !strncmp(cmdtail, ".jffs2", 2))
+ cmd |= NANDRW_JFFS2; /* skip bad blocks */
+ else if (cmdtail && !strncmp(cmdtail, ".jffs2s", 2)) {
+ cmd |= NANDRW_JFFS2; /* skip bad blocks (on read too) */
+ if (cmd & NANDRW_READ)
+ cmd |= NANDRW_JFFS2_SKIP; /* skip bad blocks (on read too) */
+ }
#ifdef SXNI855T
- /* need ".e" same as ".j" for compatibility with older units */
- else if (cmdtail && !strcmp (cmdtail, ".e"))
- cmd |= NANDRW_JFFS2; /* skip bad blocks */
+ /* need ".e" same as ".j" for compatibility with older units */
+ else if (cmdtail && !strcmp(cmdtail, ".e"))
+ cmd |= NANDRW_JFFS2; /* skip bad blocks */
#endif
#ifdef CFG_NAND_SKIP_BAD_DOT_I
- /* need ".i" same as ".jffs2s" for compatibility with older units (esd) */
- /* ".i" for image -> read skips bad block (no 0xff) */
- else if (cmdtail && !strcmp (cmdtail, ".i")) {
- cmd |= NANDRW_JFFS2; /* skip bad blocks (on read too) */
- if (cmd & NANDRW_READ)
- cmd |= NANDRW_JFFS2_SKIP; /* skip bad blocks (on read too) */
- }
+ /* need ".i" same as ".jffs2s" for compatibility with older units (esd) */
+ /* ".i" for image -> read skips bad block (no 0xff) */
+ else if (cmdtail && !strcmp(cmdtail, ".i")) {
+ cmd |= NANDRW_JFFS2; /* skip bad blocks (on read too) */
+ if (cmd & NANDRW_READ)
+ cmd |= NANDRW_JFFS2_SKIP; /* skip bad blocks (on read too) */
+ }
#endif /* CFG_NAND_SKIP_BAD_DOT_I */
- else if (cmdtail) {
- printf ("Usage:\n%s\n", cmdtp->usage);
- return 1;
- }
-
- printf ("\nNAND %s: device %d offset %ld, size %ld ...\n",
- (cmd & NANDRW_READ) ? "read" : "write",
- curr_device, off, size);
-
- ret = nand_legacy_rw (nand_dev_desc + curr_device,
- cmd, off, size,
- &total,
- (u_char *) addr);
-
- printf (" %d bytes %s: %s\n", total,
- (cmd & NANDRW_READ) ? "read" : "written",
- ret ? "ERROR" : "OK");
-
- return ret;
- } else if (strcmp (argv[1], "erase") == 0 &&
- (argc == 4 || strcmp ("clean", argv[2]) == 0)) {
- int clean = argc == 5;
- ulong off =
- simple_strtoul (argv[2 + clean], NULL, 16);
- ulong size =
- simple_strtoul (argv[3 + clean], NULL, 16);
- int ret;
+ else if (cmdtail) {
+ printf ("Usage:\n%s\n", cmdtp->usage);
+ return 1;
+ }

- printf ("\nNAND erase: device %d offset %ld, size %ld ...\n",
- curr_device, off, size);
+ printf ("\nNAND %s: device %d offset %ld, size %ld ...\n",
+ (cmd & NANDRW_READ) ? "read" : "write",
+ curr_device, off, size);
+
+ ret = nand_legacy_rw(nand_dev_desc + curr_device, cmd, off, size,
+ (size_t *)&total, (u_char*)addr);
+
+ printf (" %d bytes %s: %s\n", total,
+ (cmd & NANDRW_READ) ? "read" : "written",
+ ret ? "ERROR" : "OK");
+
+ return ret;
+ } else if (strcmp(argv[1],"erase") == 0 &&
+ (argc == 4 || strcmp("clean", argv[2]) == 0)) {
+ int clean = argc == 5;
+ ulong off = simple_strtoul(argv[2 + clean], NULL, 16);
+ ulong size = simple_strtoul(argv[3 + clean], NULL, 16);
+ int ret;

- ret = nand_legacy_erase (nand_dev_desc + curr_device,
- off, size, clean);
+ printf ("\nNAND erase: device %d offset %ld, size %ld ...\n",
+ curr_device, off, size);

- printf ("%s\n", ret ? "ERROR" : "OK");
+ ret = nand_legacy_erase (nand_dev_desc + curr_device,
+ off, size, clean);

- return ret;
- } else {
- printf ("Usage:\n%s\n", cmdtp->usage);
- rcode = 1;
- }
+ printf("%s\n", ret ? "ERROR" : "OK");

- return rcode;
+ return ret;
+ } else {
+ printf ("Usage:\n%s\n", cmdtp->usage);
+ rcode = 1;
        }
+
+ return rcode;
+ }
}

U_BOOT_CMD(
@@ -953,11 +897,6 @@ int do_nandboot (cmd_tbl_t *cmdtp, int f
        ulong offset = 0;
        image_header_t *hdr;
        int rcode = 0;
-#if defined(CONFIG_FIT)
- const void *fit_hdr;
-#endif
-
- show_boot_progress (52);
        switch (argc) {
        case 1:
                addr = CFG_LOAD_ADDR;
@@ -978,27 +917,24 @@ int do_nandboot (cmd_tbl_t *cmdtp, int f
                break;
        default:
                printf ("Usage:\n%s\n", cmdtp->usage);
- show_boot_progress (-53);
+ SHOW_BOOT_PROGRESS (-1);
                return 1;
        }

- show_boot_progress (53);
        if (!boot_device) {
                puts ("\n** No boot device **\n");
- show_boot_progress (-54);
+ SHOW_BOOT_PROGRESS (-1);
                return 1;
        }
- show_boot_progress (54);

        dev = simple_strtoul(boot_device, &ep, 16);

        if ((dev >= CFG_MAX_NAND_DEVICE) ||
            (nand_dev_desc[dev].ChipID == NAND_ChipID_UNKNOWN)) {
                printf ("\n** Device %d not available\n", dev);
- show_boot_progress (-55);
+ SHOW_BOOT_PROGRESS (-1);
                return 1;
        }
- show_boot_progress (55);

        printf ("\nLoading from device %d: %s at 0x%lx (offset 0x%lx)\n",
                dev, nand_dev_desc[dev].name, nand_dev_desc[dev].IO_ADDR,
@@ -1007,54 +943,31 @@ int do_nandboot (cmd_tbl_t *cmdtp, int f
        if (nand_legacy_rw (nand_dev_desc + dev, NANDRW_READ, offset,
                        SECTORSIZE, NULL, (u_char *)addr)) {
                printf ("** Read error on %d\n", dev);
- show_boot_progress (-56);
+ SHOW_BOOT_PROGRESS (-1);
                return 1;
        }
- show_boot_progress (56);

- switch (genimg_get_format ((void *)addr)) {
- case IMAGE_FORMAT_LEGACY:
- hdr = (image_header_t *)addr;
- image_print_contents (hdr);
+ hdr = (image_header_t *)addr;

- cnt = image_get_image_size (hdr);
- cnt -= SECTORSIZE;
- break;
-#if defined(CONFIG_FIT)
- case IMAGE_FORMAT_FIT:
- fit_hdr = (const void *)addr;
- if (!fit_check_format (fit_hdr)) {
- show_boot_progress (-150);
- puts ("** Bad FIT image format\n");
- return 1;
- }
- show_boot_progress (151);
- puts ("Fit image detected...\n");
+ if (ntohl(hdr->ih_magic) == IH_MAGIC) {

- cnt = fit_get_size (fit_hdr);
- break;
-#endif
- default:
- show_boot_progress (-57);
- puts ("** Unknown image type\n");
+ //print_image_hdr (hdr);

Remove