From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from relay101b.appriver.com ([207.97.230.15] helo=relay.appriver.com) by merlin.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cOmP5-0006uD-TM for linux-mtd@lists.infradead.org; Wed, 04 Jan 2017 14:19:00 +0000 From: Mike Crowe To: linux-mtd@lists.infradead.org Cc: Mike Crowe Subject: [PATCH 2/2] nanddump: Add --skip-bad-blocks-to-start option Date: Wed, 4 Jan 2017 14:18:06 +0000 Message-Id: <1483539486-16165-3-git-send-email-mac@mcrowe.com> In-Reply-To: <1483539486-16165-1-git-send-email-mac@mcrowe.com> References: <1483539486-16165-1-git-send-email-mac@mcrowe.com> List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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. --- nand-utils/nanddump.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/nand-utils/nanddump.c b/nand-utils/nanddump.c index a8ad334..eaaf331 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) { + unsigned 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) -- 2.1.4