From: "Brian Norris" <computersforpeace@gmail.com>
To: "Artem Bityutskiy" <dedekind1@gmail.com>
Cc: Brian Norris <computersforpeace@gmail.com>,
linux-mtd@lists.infradead.org,
Mike Frysinger <vapier.adi@gmail.com>
Subject: [PATCH 1/6] nanddump: add --bb=METHOD option
Date: Mon, 13 Jun 2011 16:31:58 -0700 [thread overview]
Message-ID: <1308007923-6820-1-git-send-email-computersforpeace@gmail.com> (raw)
We have too many separate bad block handling methods:
--omitbad
--noskipbad
--skipbad
On top of these, we have the default option: that bad blocks are
replaced with 0xFF.
These options will be unified under --bb=METHOD. The end goal will be
something like:
----------------------------------------------------------------------------------------------
Old option New option Comment
----------------------------------------------------------------------------------------------
<default> --bb=padbad dump flash data, substituting 0xFF for any bad blocks
--noskipbad --bb=dumpbad dump flash data, including any bad blocks
--skipbad --bb=skipbad dump good data, completely skipping any bad blocks (new default)
--omitbad --bb=omitbad dump flash data, substituting nothing for any bad blocks
The BB options are all mutually exclusive, so we check that we do not
have more than one BB option explicitly enabled on the command line.
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
---
nanddump.c | 81 +++++++++++++++++++++++++++++++++++++++++------------------
1 files changed, 56 insertions(+), 25 deletions(-)
diff --git a/nanddump.c b/nanddump.c
index c9d7e8b..c3771c5 100644
--- a/nanddump.c
+++ b/nanddump.c
@@ -47,6 +47,12 @@ static void display_help(void)
"\n"
" --help Display this help and exit\n"
" --version Output version information and exit\n"
+" --bb=METHOD Choose a bad block handling method.\n"
+" METHOD can be:\n"
+" padbad (default)\n"
+" dumpbad\n"
+" skipbad\n"
+" omitbad\n"
"-a --forcebinary Force printing of binary data to tty\n"
"-b --omitbad Omit bad blocks from the dump\n"
"-c --canonicalprint Print canonical Hex+ASCII dump\n"
@@ -60,11 +66,11 @@ static void display_help(void)
"-q --quiet Don't display progress and status messages\n"
"-s addr --startaddress=addr Start address\n"
"\n"
-"Notes on --omitbad and --skipbad:\n"
+"Notes on --bb=omitbad and --bb=skipbad:\n"
" With either option, we stop dumping data when we encounter a bad block\n"
-" and resume dumping at the next good block. However, with --omitbad, we\n"
+" and resume dumping at the next good block. However, with `omitbad', we\n"
" count the bad block as part of the total dump length, whereas with\n"
-" --skipbad, the bad block is 'skipped,' that is, not counted toward the\n"
+" `skipbad', the bad block is skipped, that is, not counted toward the\n"
" total dump length.\n",
PROGRAM_NAME);
exit(EXIT_SUCCESS);
@@ -88,21 +94,26 @@ static void display_version(void)
static bool pretty_print = false; // print nice
static bool noecc = false; // don't error correct
-static bool noskipbad = false; // don't skip bad blocks
static bool omitoob = false; // omit oob data
static long long start_addr; // start address
static long long length; // dump length
static const char *mtddev; // mtd device name
static const char *dumpfile; // dump file name
-static bool omitbad = false;
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 skipbad = false; // skip over bad blocks
+
+static enum {
+ padbad, // dump flash data, substituting 0xFF for any bad blocks
+ dumpbad, // dump flash data, including any bad blocks
+ skipbad, // dump good data, completely skipping any bad blocks
+ omitbad // dump flash data, substituting nothing for any bad blocks
+} bb_method = padbad;
static void process_options(int argc, char * const argv[])
{
int error = 0;
+ bool bb_default = true;
for (;;) {
int option_index = 0;
@@ -110,6 +121,7 @@ static void process_options(int argc, char * const argv[])
static const struct option long_options[] = {
{"help", no_argument, 0, 0},
{"version", no_argument, 0, 0},
+ {"bb", required_argument, 0, 0},
{"forcebinary", no_argument, 0, 'a'},
{"canonicalprint", no_argument, 0, 'c'},
{"file", required_argument, 0, 'f'},
@@ -140,10 +152,30 @@ static void process_options(int argc, char * const argv[])
case 1:
display_version();
break;
+ case 2:
+ /* Handle --bb=METHOD */
+ if (!strcmp(optarg, "padbad"))
+ bb_method = padbad;
+ else if (!strcmp(optarg, "dumpbad"))
+ bb_method = dumpbad;
+ else if (!strcmp(optarg, "skipbad"))
+ bb_method = skipbad;
+ else if (!strcmp(optarg, "omitbad"))
+ bb_method = omitbad;
+ else
+ error++;
+ bb_default = false;
+ break;
}
break;
case 'b':
- omitbad = true;
+ /* Check if bb_method was already set explicitly */
+ if (bb_default) {
+ bb_default = false;
+ bb_method = omitbad;
+ } else {
+ error++;
+ }
break;
case 's':
start_addr = simple_strtoll(optarg, &error);
@@ -175,10 +207,22 @@ static void process_options(int argc, char * const argv[])
noecc = true;
break;
case 'N':
- noskipbad = true;
+ /* Check if bb_method was already set explicitly */
+ if (bb_default) {
+ bb_default = false;
+ bb_method = dumpbad;
+ } else {
+ error++;
+ }
break;
case 'k':
- skipbad = true;
+ /* Check if bb_method was already set explicitly */
+ if (bb_default) {
+ bb_default = false;
+ bb_method = skipbad;
+ } else {
+ error++;
+ }
break;
case '?':
error++;
@@ -206,19 +250,6 @@ static void process_options(int argc, char * const argv[])
exit(EXIT_FAILURE);
}
- if (noskipbad && skipbad) {
- fprintf(stderr, "The noskipbad and skipbad options are "
- "mutually-exclusive.\n"
- "Choose one or the other.\n");
- exit(EXIT_FAILURE);
- }
-
- if (omitbad && skipbad) {
- fprintf(stderr, "The omitbad and skipbad options are mutually-"
- "exclusive.\nChoose one or the other.\n");
- exit(EXIT_FAILURE);
- }
-
if ((argc - optind) != 1 || error)
display_help();
@@ -416,7 +447,7 @@ int main(int argc, char * const argv[])
/* Dump the flash contents */
for (ofs = start_addr; ofs < end_addr; ofs += bs) {
/* Check for bad block */
- if (noskipbad) {
+ if (bb_method == dumpbad) {
badblock = 0;
} else if (blockstart != (ofs & (~mtd.eb_size + 1)) ||
firstblock) {
@@ -430,14 +461,14 @@ int main(int argc, char * const argv[])
if (badblock) {
/* skip bad block, increase end_addr */
- if (skipbad) {
+ if (bb_method == skipbad) {
end_addr += mtd.eb_size;
ofs += mtd.eb_size - bs;
if (end_addr > mtd.size)
end_addr = mtd.size;
continue;
}
- if (omitbad)
+ if (bb_method == omitbad)
continue;
memset(readbuf, 0xff, bs);
} else {
--
1.7.0.4
next reply other threads:[~2011-06-13 23:36 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-13 23:31 Brian Norris [this message]
2011-06-13 23:31 ` [PATCH 2/6] nanddump: remove --skipbad, leaving --bb=skipbad Brian Norris
2011-06-13 23:32 ` [PATCH 3/6] nanddump: deprecation messages for old BB options Brian Norris
2011-06-13 23:32 ` [PATCH 4/6] nanddump: warn about changing default badblock method Brian Norris
2011-06-13 23:32 ` [PATCH 5/6] feature-removal-schedule: describe nanddump changes Brian Norris
2011-06-13 23:32 ` [PATCH 6/6] nanddump: warn about future default --nooob Brian Norris
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1308007923-6820-1-git-send-email-computersforpeace@gmail.com \
--to=computersforpeace@gmail.com \
--cc=dedekind1@gmail.com \
--cc=linux-mtd@lists.infradead.org \
--cc=vapier.adi@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).