nand/onenand: Fix missing argument checking for "markbad" command
authorWolfgang Denk <wd@denx.de>
Sun, 24 May 2009 15:34:33 +0000 (17:34 +0200)
committerScott Wood <scottwood@freescale.com>
Tue, 7 Jul 2009 22:58:05 +0000 (17:58 -0500)
The "nand markbad" and "onenand markbad" commands did not check if an
argument was passed; if this was forgotten, no error was raised but
block 0 was marked as bad.

While fixing this bug, clean up the code a bit and allow to pass more
than one block address, thus allowing to mark several blocks as bad
in a single command invocation.

Signed-off-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Scott Wood <scottwood@freescale.com>
common/cmd_nand.c
common/cmd_onenand.c

index 94514160b5e547823b279f484361a8ca61aa5e5c..2f705212262aa9e5cd981f9b0c8f093acbd32f35 100644 (file)
@@ -414,18 +414,29 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
        }
 
        if (strcmp(cmd, "markbad") == 0) {
-               addr = (ulong)simple_strtoul(argv[2], NULL, 16);
+               argc -= 2;
+               argv += 2;
 
-               int ret = nand->block_markbad(nand, addr);
-               if (ret == 0) {
-                       printf("block 0x%08lx successfully marked as bad\n",
-                              (ulong) addr);
-                       return 0;
-               } else {
-                       printf("block 0x%08lx NOT marked as bad! ERROR %d\n",
-                              (ulong) addr, ret);
+               if (argc <= 0)
+                       goto usage;
+
+               while (argc > 0) {
+                       addr = simple_strtoul(*argv, NULL, 16);
+
+                       if (nand->block_markbad(nand, addr)) {
+                               printf("block 0x%08lx NOT marked "
+                                       "as bad! ERROR %d\n",
+                                       addr, ret);
+                               ret = 1;
+                       } else {
+                               printf("block 0x%08lx successfully "
+                                       "marked as bad\n",
+                                       addr);
+                       }
+                       --argc;
+                       ++argv;
                }
-               return 1;
+               return ret;
        }
 
        if (strcmp(cmd, "biterr") == 0) {
index 85bd2cb68e2b4e9c74e830824c5d3ba0310fb0a3..9090940aed7fefb154ba2a15e63037151db12ebb 100644 (file)
@@ -340,7 +340,7 @@ int do_onenand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
        int blocksize;
        ulong addr, ofs;
        size_t len, retlen = 0;
-       int ret;
+       int ret = 0;
        char *cmd, *s;
 
        mtd = &onenand_mtd;
@@ -434,18 +434,29 @@ int do_onenand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
                }
 
                if (strcmp(cmd, "markbad") == 0) {
-                       addr = (ulong)simple_strtoul(argv[2], NULL, 16);
+                       argc -= 2;
+                       argv += 2;
 
-                       int ret = mtd->block_markbad(mtd, addr);
-                       if (ret == 0) {
-                               printf("block 0x%08lx successfully marked as bad\n",
-                                               (ulong) addr);
-                               return 0;
-                       } else {
-                               printf("block 0x%08lx NOT marked as bad! ERROR %d\n",
-                                               (ulong) addr, ret);
+                       if (argc <= 0)
+                               goto usage;
+
+                       while (argc > 0) {
+                               addr = simple_strtoul(*argv, NULL, 16);
+
+                               if (mtd->block_markbad(mtd, addr)) {
+                                       printf("block 0x%08lx NOT marked "
+                                               "as bad! ERROR %d\n",
+                                               addr, ret);
+                                       ret = 1;
+                               } else {
+                                       printf("block 0x%08lx successfully "
+                                               "marked as bad\n",
+                                               addr);
+                               }
+                               --argc;
+                               ++argv;
                        }
-                       return 1;
+                       return ret;
                }
 
                if (strncmp(cmd, "dump", 4) == 0) {
@@ -474,7 +485,7 @@ usage:
 }
 
 U_BOOT_CMD(
-       onenand,        6,      1,      do_onenand,
+       onenand,        CONFIG_SYS_MAXARGS,     1,      do_onenand,
        "OneNAND sub-system",
        "info - show available OneNAND devices\n"
        "onenand bad - show bad blocks\n"