summaryrefslogtreecommitdiff
path: root/nand-utils/nanddump.c
diff options
context:
space:
mode:
Diffstat (limited to 'nand-utils/nanddump.c')
-rw-r--r--nand-utils/nanddump.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/nand-utils/nanddump.c b/nand-utils/nanddump.c
index a8ad334..bebb48e 100644
--- a/nand-utils/nanddump.c
+++ b/nand-utils/nanddump.c
@@ -52,6 +52,8 @@ static void display_help(int status)
"-p --prettyprint Print nice (hexdump)\n"
"-q --quiet Don't display progress and status messages\n"
"-s addr --startaddress=addr Start address\n"
+" --skip-bad-blocks-to-start\n"
+" Skip bad blocks when seeking to the start address\n"
"\n"
"--bb=METHOD, where METHOD can be `padbad', `dumpbad', or `skipbad':\n"
" padbad: dump flash data, substituting 0xFF for any bad blocks\n"
@@ -86,6 +88,7 @@ static const char *dumpfile; // dump file name
static bool quiet = false; // suppress diagnostic output
static bool canonical = false; // print nice + ascii
static bool forcebinary = false; // force printing binary to tty
+static bool skip_bad_blocks_to_start = false;
static enum {
padbad, // dump flash data, substituting 0xFF for any bad blocks
@@ -105,6 +108,7 @@ static void process_options(int argc, char * const argv[])
{"version", no_argument, 0, 'V'},
{"bb", required_argument, 0, 0},
{"omitoob", no_argument, 0, 0},
+ {"skip-bad-blocks-to-start", no_argument, 0, 0 },
{"help", no_argument, 0, 'h'},
{"forcebinary", no_argument, 0, 'a'},
{"canonicalprint", no_argument, 0, 'c'},
@@ -146,6 +150,9 @@ static void process_options(int argc, char * const argv[])
errmsg_die("--oob and --oomitoob are mutually exclusive");
}
break;
+ case 3: /* --skip-bad-blocks-to-start */
+ skip_bad_blocks_to_start = true;
+ break;
}
break;
case 'V':
@@ -397,6 +404,22 @@ int main(int argc, char * const argv[])
mtd.min_io_size);
goto closeall;
}
+ if (skip_bad_blocks_to_start) {
+ long long bbs_offset = 0;
+ while (bbs_offset < start_addr) {
+ err = mtd_is_bad(&mtd, fd, bbs_offset / mtd.eb_size);
+ if (err < 0) {
+ sys_errmsg("%s: MTD get bad block failed", mtddev);
+ goto closeall;
+ } else if (err == 1) {
+ if (!quiet)
+ fprintf(stderr, "Bad block at %llx\n", bbs_offset);
+ start_addr += mtd.eb_size;
+ }
+ bbs_offset += mtd.eb_size;
+ }
+ }
+
if (length)
end_addr = start_addr + length;
if (!length || end_addr > mtd.size)