linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Mike Crowe <mac@mcrowe.com>
To: linux-mtd@lists.infradead.org
Cc: Mike Crowe <mac@mcrowe.com>
Subject: [PATCH 2/2] nanddump: Add --input-skip
Date: Tue,  6 Dec 2016 18:04:17 +0000	[thread overview]
Message-ID: <1481047457-25427-3-git-send-email-mac@mcrowe.com> (raw)
In-Reply-To: <1481047457-25427-1-git-send-email-mac@mcrowe.com>

Skip the specified number of bytes (which must be page aligned) before
dumping. This differs from --startaddress when there are bad blocks:
--startaddress always seeks to the specified offset in the partition,
--output-skip works its way through the partition a page at a time from the
specified start, skipping bad blocks as required by --bb.

This can be useful if other readers of the partition will be reading using
a simple bad-block-skipping algorithm.
---
 nand-utils/nanddump.c | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/nand-utils/nanddump.c b/nand-utils/nanddump.c
index a8ad334..bd0d420 100644
--- a/nand-utils/nanddump.c
+++ b/nand-utils/nanddump.c
@@ -46,6 +46,7 @@ static void display_help(int status)
 "-c         --canonicalprint     Print canonical Hex+ASCII dump\n"
 "-f file    --file=file          Dump to file\n"
 "-l length  --length=length      Length\n"
+"           --input-skip=length  Skip |length| bytes before dumping\n"
 "-n         --noecc              Read without error correction\n"
 "           --omitoob            Omit OOB data (default)\n"
 "-o         --oob                Dump OOB data\n"
@@ -81,6 +82,7 @@ static bool			noecc = false;		// don't error correct
 static bool			omitoob = true;		// omit oob data
 static long long		start_addr;		// start address
 static long long		length;			// dump length
+static long long		inputskip;              // skip bytes before dump
 static const char		*mtddev;		// mtd device name
 static const char		*dumpfile;		// dump file name
 static bool			quiet = false;		// suppress diagnostic output
@@ -105,6 +107,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},
+			{"input-skip", required_argument, 0, 0},
 			{"help", no_argument, 0, 'h'},
 			{"forcebinary", no_argument, 0, 'a'},
 			{"canonicalprint", no_argument, 0, 'c'},
@@ -146,6 +149,9 @@ static void process_options(int argc, char * const argv[])
 							errmsg_die("--oob and --oomitoob are mutually exclusive");
 						}
 						break;
+					case 3: /* --input-skip */
+						inputskip = simple_strtoll(optarg, &error);
+						break;
 				}
 				break;
 			case 'V':
@@ -404,13 +410,21 @@ int main(int argc, char * const argv[])
 
 	bs = mtd.min_io_size;
 
+	if (inputskip & (mtd.min_io_size - 1)) {
+		fprintf(stderr, "the input-skip parameter is not page-aligned!\n"
+			        "The pagesize of this NAND flash is 0x%x.\n",
+			        mtd.min_io_size);
+		goto closeall;
+	}
+
 	/* Print informative message */
 	if (!quiet) {
 		fprintf(stderr, "Block size %d, page size %d, OOB size %d\n",
 				mtd.eb_size, mtd.min_io_size, mtd.oob_size);
-		fprintf(stderr,
-				"Dumping data starting at 0x%08llx and ending at 0x%08llx...\n",
-				start_addr, end_addr);
+		if (!inputskip)
+			fprintf(stderr,
+				        "Dumping data starting at 0x%08llx and ending at 0x%08llx...\n",
+				        start_addr, end_addr);
 	}
 
 	/* Dump the flash contents */
@@ -463,6 +477,16 @@ int main(int argc, char * const argv[])
 			stat1 = stat2;
 		}
 
+		if (inputskip) {
+			inputskip -= bs;
+			end_addr += bs;
+			if (!inputskip && !quiet)
+				fprintf(stderr,
+					"Dumping data starting at 0x%08llx and ending at 0x%08llx...\n",
+					ofs + bs, end_addr);
+			continue;
+		}
+
 		/* Write out page data */
 		if (pretty_print) {
 			for (i = 0; i < bs; i += PRETTY_ROW_SIZE) {
-- 
2.1.4

  parent reply	other threads:[~2016-12-06 18:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-06 18:04 [PATCH 0/2] Support skipping a certain number of good blocks Mike Crowe
2016-12-06 18:04 ` [PATCH 1/2] nandwrite: Add --output-skip Mike Crowe
2016-12-06 18:04 ` Mike Crowe [this message]
2016-12-06 18:11 ` [PATCH 0/2] Support skipping a certain number of good blocks Mike Crowe
2016-12-07  8:53   ` David Oberhollenzer
2016-12-07  9:56     ` Mike Crowe
2016-12-14 18:15       ` Mike Crowe

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=1481047457-25427-3-git-send-email-mac@mcrowe.com \
    --to=mac@mcrowe.com \
    --cc=linux-mtd@lists.infradead.org \
    /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).