[PATCH 2/2] nanddump: Add --input-skip

Mike Crowe mac at mcrowe.com
Tue Dec 6 10:04:17 PST 2016


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




More information about the linux-mtd mailing list