aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Crowe <mac@mcrowe.com>2017-01-17 11:54:04 +0000
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2017-01-18 14:42:25 +0100
commit44558d1de053cd2772b419bb306a926f07365ae6 (patch)
treee05fbb86c063fc2324f290381a2b7657f6e4b6ec
parent2fc8058291e07f6ec143179db377a7d53f6dfa04 (diff)
nanddump: Add --skip-bad-blocks-to-start option
The --skip-bad-blocks-to-start option will increase the start address by the size of each bad block encountered between the start of the partition and the specified start address. This can be useful if other readers of the partition will be reading using a simple bad-block-skipping algorithm. Signed-off-by: Mike Crowe <mac@mcrowe.com> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-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)