diff mbox

[RFC] nanddump: skip bad blocks, print full length with --omitbad

Message ID 1307038511-5968-1-git-send-email-computersforpeace@gmail.com
State RFC
Headers show

Commit Message

Brian Norris June 2, 2011, 6:15 p.m. UTC
I'm not sure the original intended use of nanddump's '--omitbad' option,
but as described below, it doesn't seem to make the most sense to me.
I'm curiouse whether this change should be implemented as yet another
new nanddump option (perhaps a '--skipbad' vs. '--omitbad'? this starts
getting confusing) or if we can simply modify the old behavior of
'--omitbad'.

Brian

----

If, for example, the following is executed on a device with a bad block
at block 0, we get an empty file:
    $ nanddump --length=131072 --omitbad --file=/tmp/foo /dev/mtd0

This does not make intuitive sense. Instead, nanddump should skip the
bad block and continue to dump good data from the next good block.

This patch adds an informative warning to let the user know that a bad
block was skipped to aid with those who may be used to the old method,
where we omit the bad block and simply dump nothing in its place.

---
 nanddump.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

Comments

Mike Frysinger June 2, 2011, 6:51 p.m. UTC | #1
On Thu, Jun 2, 2011 at 14:15, Brian Norris wrote:
> I'm not sure the original intended use of nanddump's '--omitbad' option,
> but as described below, it doesn't seem to make the most sense to me.
> I'm curiouse whether this change should be implemented as yet another
> new nanddump option (perhaps a '--skipbad' vs. '--omitbad'? this starts
> getting confusing) or if we can simply modify the old behavior of
> '--omitbad'.

pretty sure the opt operates as i intended.  sounds like you want to
add --skipbad.
-mike
Brian Norris June 2, 2011, 10:40 p.m. UTC | #2
On Thu, Jun 2, 2011 at 11:51 AM, Mike Frysinger <vapier.adi@gmail.com> wrote:
> pretty sure the opt operates as i intended.  sounds like you want to
> add --skipbad.

OK, thanks for the info. I might add a new "skipbad" option and try to
clarify the differences between the various "omit" and "skip" options.

BTW, is there good history for mtd-utils pre-April 2006? Git doesn't
have history for this option, as it was part of the "initial commit."

Thanks,
Brian
diff mbox

Patch

diff --git a/nanddump.c b/nanddump.c
index 214fb12..e19e16a 100644
--- a/nanddump.c
+++ b/nanddump.c
@@ -403,8 +403,15 @@  int main(int argc, char * const argv[])
 		}
 
 		if (badblock) {
-			if (omitbad)
+			if (omitbad) {
+				/* skip bad block, increase end_addr */
+				fprintf(stderr, "Skipping bad block at 0x%08llx\n", ofs);
+				end_addr += mtd.eb_size;
+				ofs += mtd.eb_size - bs;
+				if (end_addr > mtd.size)
+					end_addr = mtd.size;
 				continue;
+			}
 			memset(readbuf, 0xff, bs);
 		} else {
 			/* Read page data and exit on failure */