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 1/2] nandwrite: Add --output-skip
Date: Tue,  6 Dec 2016 18:04:16 +0000	[thread overview]
Message-ID: <1481047457-25427-2-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
writing. This differs from --start when there are bad blocks: --start
always seeks to the specified offset in the flash, --output-skip works its
way through the flash a page at a time from the specified start, skipping
bad blocks provided --noskipbad was not also passed.

This can be useful when writing part way through a partition that will be
read using a simple bad-block-skipping algorithm.
---
 nand-utils/nandwrite.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/nand-utils/nandwrite.c b/nand-utils/nandwrite.c
index b376869..b4a6d8c 100644
--- a/nand-utils/nandwrite.c
+++ b/nand-utils/nandwrite.c
@@ -60,6 +60,7 @@ static void display_help(int status)
 "  -b, --blockalign=1|2|4  Set multiple of eraseblocks to align to\n"
 "      --input-skip=length Skip |length| bytes of the input file\n"
 "      --input-size=length Only read |length| bytes of the input file\n"
+"      --output-skip=length Skip |length| bytes before writing\n"
 "  -q, --quiet             Don't display progress messages\n"
 "  -h, --help              Display this help and exit\n"
 "  -V, --version           Output version information and exit\n"
@@ -87,6 +88,7 @@ static const char	*mtd_device, *img;
 static long long	mtdoffset = 0;
 static long long	inputskip = 0;
 static long long	inputsize = 0;
+static long long	outputskip = 0;
 static bool		quiet = false;
 static bool		writeoob = false;
 static bool		onlyoob = false;
@@ -110,6 +112,7 @@ static void process_options(int argc, char * const argv[])
 			{"version", no_argument, 0, 'V'},
 			{"input-skip", required_argument, 0, 0},
 			{"input-size", required_argument, 0, 0},
+			{"output-skip", required_argument, 0, 0},
 			{"help", no_argument, 0, 'h'},
 			{"blockalign", required_argument, 0, 'b'},
 			{"markbad", no_argument, 0, 'm'},
@@ -139,6 +142,9 @@ static void process_options(int argc, char * const argv[])
 			case 2: /* --input-size */
 				inputsize = simple_strtoll(optarg, &error);
 				break;
+			case 3: /* --output-skip */
+				outputskip = simple_strtoll(optarg, &error);
+				break;
 			}
 			break;
 		case 'V':
@@ -286,6 +292,11 @@ int main(int argc, char * const argv[])
 			   "The pagesize of this NAND Flash is 0x%x.\n",
 			   mtd.min_io_size);
 
+	if (outputskip % ebsize_aligned)
+		errmsg_die("The output skip length is not page-aligned !\n"
+			   "The pagesize of this NAND flash is 0x%x.\n",
+			   mtd.min_io_size);
+
 	/* Select OOB write mode */
 	if (noecc)
 		write_mode = MTD_OPS_RAW;
@@ -350,7 +361,7 @@ int main(int argc, char * const argv[])
 	}
 
 	/* Check, if length fits into device */
-	if ((imglen / pagelen) * mtd.min_io_size > mtd.size - mtdoffset) {
+	if ((imglen / pagelen) * mtd.min_io_size > mtd.size - mtdoffset - outputskip) {
 		fprintf(stderr, "Image %lld bytes, NAND page %d bytes, OOB area %d"
 				" bytes, device size %lld bytes\n",
 				imglen, pagelen, mtd.oob_size, mtd.size);
@@ -400,7 +411,7 @@ int main(int argc, char * const argv[])
 			}
 
 			baderaseblock = false;
-			if (!quiet)
+			if (!quiet && (outputskip == 0))
 				fprintf(stdout, "Writing data to block %lld at offset 0x%llx\n",
 						 blockstart / ebsize_aligned, blockstart);
 
@@ -432,7 +443,12 @@ int main(int argc, char * const argv[])
 
 				offs +=  ebsize_aligned / blockalign;
 			} while (offs < blockstart + ebsize_aligned);
+		}
 
+		if (outputskip > 0) {
+			mtdoffset += mtd.min_io_size;
+			outputskip -= mtd.min_io_size;
+			continue;
 		}
 
 		/* Read more data from the input if there isn't enough in the buffer */
-- 
2.1.4

  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 ` Mike Crowe [this message]
2016-12-06 18:04 ` [PATCH 2/2] nanddump: Add --input-skip Mike Crowe
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-2-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).