Merge https://gitlab.denx.de/u-boot/custodians/u-boot-marvell
[oweals/u-boot.git] / cmd / mtd.c
index cda702d18b1636c6ec1ae3af0c599a85e1e45c0b..f407c5e4450ac438b0b62c685c37adbac99e14a8 100644 (file)
--- a/cmd/mtd.c
+++ b/cmd/mtd.c
@@ -14,6 +14,8 @@
 #include <malloc.h>
 #include <mapmem.h>
 #include <mtd.h>
+#include <dm/devres.h>
+#include <linux/err.h>
 
 #include <linux/ctype.h>
 
@@ -387,7 +389,7 @@ static int do_mtd_erase(cmd_tbl_t *cmdtp, int flag, int argc,
        struct mtd_info *mtd;
        u64 off, len;
        bool scrub;
-       int ret;
+       int ret = 0;
 
        if (argc < 2)
                return CMD_RET_USAGE;
@@ -423,22 +425,22 @@ static int do_mtd_erase(cmd_tbl_t *cmdtp, int flag, int argc,
 
        erase_op.mtd = mtd;
        erase_op.addr = off;
-       erase_op.len = len;
+       erase_op.len = mtd->erasesize;
        erase_op.scrub = scrub;
 
-       while (erase_op.len) {
+       while (len) {
                ret = mtd_erase(mtd, &erase_op);
 
-               /* Abort if its not a bad block error */
-               if (ret != -EIO)
-                       break;
-
-               printf("Skipping bad block at 0x%08llx\n", erase_op.fail_addr);
+               if (ret) {
+                       /* Abort if its not a bad block error */
+                       if (ret != -EIO)
+                               break;
+                       printf("Skipping bad block at 0x%08llx\n",
+                              erase_op.addr);
+               }
 
-               /* Skip bad block and continue behind it */
-               erase_op.len -= erase_op.fail_addr - erase_op.addr;
-               erase_op.len -= mtd->erasesize;
-               erase_op.addr = erase_op.fail_addr + mtd->erasesize;
+               len -= mtd->erasesize;
+               erase_op.addr += mtd->erasesize;
        }
 
        if (ret && ret != -EIO)
@@ -519,8 +521,8 @@ static int mtd_name_complete(int argc, char * const argv[], char last_char,
 }
 #endif /* CONFIG_AUTO_COMPLETE */
 
-static char mtd_help_text[] =
 #ifdef CONFIG_SYS_LONGHELP
+static char mtd_help_text[] =
        "- generic operations on memory technology devices\n\n"
        "mtd list\n"
        "mtd read[.raw][.oob]                  <name> <addr> [<off> [<size>]]\n"
@@ -541,9 +543,8 @@ static char mtd_help_text[] =
        "\t\t* must be a multiple of a block for erase\n"
        "\t\t* must be a multiple of a page otherwise (special case: default is a page with dump)\n"
        "\n"
-       "The .dontskipff option forces writing empty pages, don't use it if unsure.\n"
+       "The .dontskipff option forces writing empty pages, don't use it if unsure.\n";
 #endif
-       "";
 
 U_BOOT_CMD_WITH_SUBCMDS(mtd, "MTD utils", mtd_help_text,
                U_BOOT_SUBCMD_MKENT(list, 1, 1, do_mtd_list),