From: "Brian Norris" <computersforpeace@gmail.com>
To: linux-mtd@lists.infradead.org
Cc: Brian Norris <computersforpeace@gmail.com>,
Jehan Bing <jehan@orb.com>, David Woodhouse <dwmw2@infradead.org>,
Mike Frysinger <vapier.adi@gmail.com>,
Artem Bityutskiy <dedekind1@gmail.com>
Subject: [PATCH 03/10] mtd-utils: nandwrite: Clarify usage of aligned "erasesize"
Date: Wed, 3 Nov 2010 01:27:20 -0700 [thread overview]
Message-ID: <1288772847-8120-3-git-send-email-computersforpeace@gmail.com> (raw)
In-Reply-To: <1288772847-8120-1-git-send-email-computersforpeace@gmail.com>
Due to the presence of the "--block-align" flag, nandwrite uses a
blocksize throughout that, depeding on the execution parameters, may
not be the actual erasesize of the NAND flash. In order to clarify
this situation for the untrained viewer of nandwrite's code, we should
not change the value of "meminfo.erasesize" itself; rather, we can
utilize a separate, calculated "ebsize_aligned". Then, when a user
actually wants to refer to the physical erasesize, it's straightforward.
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
---
nandwrite.c | 30 +++++++++++++++++-------------
1 files changed, 17 insertions(+), 13 deletions(-)
diff --git a/nandwrite.c b/nandwrite.c
index 3fbfca9..66a9ef7 100644
--- a/nandwrite.c
+++ b/nandwrite.c
@@ -275,6 +275,7 @@ int main(int argc, char * const argv[])
// points to the OOB for the current page in filebuf
unsigned char *oobreadbuf = NULL;
unsigned char *oobbuf = NULL;
+ int ebsize_aligned;
process_options(argc, argv);
@@ -296,9 +297,12 @@ int main(int argc, char * const argv[])
exit(EXIT_FAILURE);
}
- /* Set erasesize to specified number of blocks - to match jffs2
- * (virtual) block size */
- meminfo.erasesize *= blockalign;
+ /*
+ * Pretend erasesize is specified number of blocks - to match jffs2
+ * (virtual) block size
+ * Use this value throughout unless otherwise necessary
+ */
+ ebsize_aligned = meminfo.erasesize * blockalign;
if (mtdoffset & (meminfo.writesize - 1)) {
fprintf(stderr, "The start address is not page-aligned !\n"
@@ -435,7 +439,7 @@ int main(int argc, char * const argv[])
}
// Allocate a buffer big enough to contain all the data (OOB included) for one eraseblock
- filebuf_max = pagelen * meminfo.erasesize / meminfo.writesize;
+ filebuf_max = pagelen * ebsize_aligned / meminfo.writesize;
filebuf = xmalloc(filebuf_max);
erase_buffer(filebuf, filebuf_max);
@@ -459,8 +463,8 @@ int main(int argc, char * const argv[])
* skipped block(s) is also bad (number of blocks depending on
* the blockalign).
*/
- while (blockstart != (mtdoffset & (~meminfo.erasesize + 1))) {
- blockstart = mtdoffset & (~meminfo.erasesize + 1);
+ while (blockstart != (mtdoffset & (~ebsize_aligned + 1))) {
+ blockstart = mtdoffset & (~ebsize_aligned + 1);
offs = blockstart;
// if writebuf == filebuf, we are rewinding so we must not
@@ -474,7 +478,7 @@ int main(int argc, char * const argv[])
baderaseblock = false;
if (!quiet)
fprintf(stdout, "Writing data to block %d at offset 0x%x\n",
- blockstart / meminfo.erasesize, blockstart);
+ blockstart / ebsize_aligned, blockstart);
/* Check all the blocks in an erase block for bad blocks */
if (noskipbad)
@@ -492,10 +496,10 @@ int main(int argc, char * const argv[])
}
if (baderaseblock) {
- mtdoffset = blockstart + meminfo.erasesize;
+ mtdoffset = blockstart + ebsize_aligned;
}
- offs += meminfo.erasesize / blockalign;
- } while (offs < blockstart + meminfo.erasesize);
+ offs += ebsize_aligned / blockalign;
+ } while (offs < blockstart + ebsize_aligned);
}
@@ -642,7 +646,7 @@ int main(int argc, char * const argv[])
writebuf = filebuf;
erase.start = blockstart;
- erase.length = meminfo.erasesize;
+ erase.length = ebsize_aligned;
fprintf(stderr, "Erasing failed write from %08lx-%08lx\n",
(long)erase.start, (long)erase.start+erase.length-1);
if (ioctl(fd, MEMERASE, &erase) != 0) {
@@ -654,14 +658,14 @@ int main(int argc, char * const argv[])
}
if (markbad) {
- loff_t bad_addr = mtdoffset & (~(meminfo.erasesize / blockalign) + 1);
+ loff_t bad_addr = mtdoffset & (~meminfo.erasesize + 1);
fprintf(stderr, "Marking block at %08lx bad\n", (long)bad_addr);
if (ioctl(fd, MEMSETBADBLOCK, &bad_addr)) {
perror("MEMSETBADBLOCK");
goto closeall;
}
}
- mtdoffset = blockstart + meminfo.erasesize;
+ mtdoffset = blockstart + ebsize_aligned;
continue;
}
--
1.7.0.4
next prev parent reply other threads:[~2010-11-03 8:30 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-03 8:27 [PATCH 01/10] mtd-utils: nanddump: Allow 64-bit lengths Brian Norris
2010-11-03 8:27 ` [PATCH 02/10] mtd-utils: nandwrite: Comment, style fixups Brian Norris
2010-11-03 8:27 ` Brian Norris [this message]
2010-11-03 8:27 ` [PATCH 04/10] mtd-utils: nandwrite: switch "oobsize" for "writesize" Brian Norris
2010-11-03 8:27 ` [PATCH 05/10] mtd-utils: nandwrite: Use libmtd to get correct mtd parameters Brian Norris
2010-11-03 8:27 ` [PATCH 06/10] mtd-utils: nandwrite: Use 64-bit offset Brian Norris
2010-11-13 11:48 ` Artem Bityutskiy
2010-11-13 22:45 ` Mike Frysinger
2010-11-14 7:49 ` Artem Bityutskiy
2010-11-03 8:27 ` [PATCH 07/10] mtd-utils: nandwrite: avoid NULL buffer pointers Brian Norris
2010-11-03 8:27 ` [PATCH 08/10] mtd-utils: nandwrite: prevent 32-bit overflow Brian Norris
2010-11-09 9:48 ` Mike Frysinger
2010-11-11 6:31 ` [PATCH v2 " Brian Norris
2010-11-09 12:20 ` [PATCH " Artem Bityutskiy
2010-11-03 8:27 ` [PATCH 09/10] mtd-utils: nanddump: type consistency Brian Norris
2010-11-09 9:51 ` Mike Frysinger
2010-11-09 18:19 ` Brian Norris
2010-11-10 0:00 ` Mike Frysinger
2010-11-11 6:39 ` [PATCH v2 09/10] mtd-utils: nandwrite: full 64-bit support w/ libmtd Brian Norris
2010-11-13 11:53 ` Artem Bityutskiy
2010-11-16 17:06 ` Brian Norris
2010-11-16 19:57 ` Mike Frysinger
2010-11-11 6:39 ` [PATCH v2 10/10] mtd-utils: nandwrite: type consistency Brian Norris
2010-11-03 8:27 ` [PATCH 10/10] mtd-utils: nandwrite: full 64-bit support w/ libmtd Brian Norris
2010-11-09 9:54 ` [PATCH 01/10] mtd-utils: nanddump: Allow 64-bit lengths Mike Frysinger
2010-11-13 11:31 ` Artem Bityutskiy
2010-11-13 11:37 ` Artem Bityutskiy
2010-11-13 11:55 ` Artem Bityutskiy
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=1288772847-8120-3-git-send-email-computersforpeace@gmail.com \
--to=computersforpeace@gmail.com \
--cc=dedekind1@gmail.com \
--cc=dwmw2@infradead.org \
--cc=jehan@orb.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).