From: "Brian Norris" <computersforpeace@gmail.com>
To: linux-mtd@lists.infradead.org
Cc: Brian Norris <computersforpeace@gmail.com>,
David Woodhouse <dwmw2@infradead.org>,
Mike Frysinger <vapier.adi@gmail.com>,
Artem Bityutskiy <dedekind1@gmail.com>
Subject: [PATCH v2 3/3] mtd-utils: nandwrite: Large page+oob support
Date: Fri, 15 Oct 2010 19:12:25 -0700 [thread overview]
Message-ID: <1287195145-10054-1-git-send-email-computersforpeace@gmail.com> (raw)
In-Reply-To: <AANLkTik2v8=Lx+HKFTQdgh4czjYuz6P5uevThvAOFcAE@mail.gmail.com>
Dynamic allocation of the oob buffer provides the necessary
support for removing the oob size check. Now, new unknown OOB
sizes can be handled correctly (for example, 8KB page + 448B
OOB).
Included common.h for the use of xmalloc.
Memory freeing should occur on "restoreoob" as well as on
"closeall."
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
---
nandwrite.c | 36 +++++++++---------------------------
1 files changed, 9 insertions(+), 27 deletions(-)
diff --git a/nandwrite.c b/nandwrite.c
index e0f5f44..1403378 100644
--- a/nandwrite.c
+++ b/nandwrite.c
@@ -41,9 +41,7 @@
#include <asm/types.h>
#include "mtd/mtd-user.h"
-
-#define MAX_PAGE_SIZE 4096
-#define MAX_OOB_SIZE 128
+#include "common.h"
// oob layouts to pass into the kernel as default
static struct nand_oobinfo none_oobinfo = {
@@ -276,12 +274,10 @@ int main(int argc, char * const argv[])
unsigned char *writebuf = NULL;
// points to the OOB for the current page in filebuf
unsigned char *oobreadbuf = NULL;
- unsigned char oobbuf[MAX_OOB_SIZE];
+ unsigned char *oobbuf = NULL;
process_options(argc, argv);
- erase_buffer(oobbuf, sizeof(oobbuf));
-
if (pad && writeoob) {
fprintf(stderr, "Can't pad when oob data is present.\n");
exit(EXIT_FAILURE);
@@ -304,17 +300,6 @@ int main(int argc, char * const argv[])
* (virtual) block size */
meminfo.erasesize *= blockalign;
- /* Make sure device page sizes are valid */
- if (!(meminfo.oobsize == 16 && meminfo.writesize == 512) &&
- !(meminfo.oobsize == 8 && meminfo.writesize == 256) &&
- !(meminfo.oobsize == 64 && meminfo.writesize == 2048) &&
- !(meminfo.oobsize == 64 && meminfo.writesize == 4096) &&
- !(meminfo.oobsize == 128 && meminfo.writesize == 4096)) {
- fprintf(stderr, "Unknown flash (not normal NAND)\n");
- close(fd);
- exit(EXIT_FAILURE);
- }
-
if (mtdoffset & (meminfo.writesize - 1)) {
fprintf(stderr, "The start address is not page-aligned !\n"
"The pagesize of this NAND Flash is 0x%x.\n",
@@ -452,14 +437,12 @@ 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 = (unsigned char *)malloc(filebuf_max);
- if (!filebuf) {
- fprintf(stderr, "Failed to allocate memory for file buffer (%d bytes)\n",
- pagelen * meminfo.erasesize / meminfo.writesize);
- goto closeall;
- }
+ filebuf = xmalloc(filebuf_max);
erase_buffer(filebuf, filebuf_max);
+ oobbuf = xmalloc(meminfo.oobsize);
+ erase_buffer(oobbuf, meminfo.oobsize);
+
/*
* Get data from input and write to the device while there is
* still input to read and we are still within the device
@@ -688,13 +671,12 @@ int main(int argc, char * const argv[])
failed = false;
closeall:
- if (filebuf) {
- free(filebuf);
- }
-
close(ifd);
restoreoob:
+ free(filebuf);
+ free(oobbuf);
+
if (oobinfochanged == 1) {
if (ioctl(fd, MEMSETOOBSEL, &old_oobinfo) != 0) {
perror("MEMSETOOBSEL");
--
1.7.0.4
next prev parent reply other threads:[~2010-10-16 2:12 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-15 7:44 [PATCH 1/3] mtd-utils: nanddump/nandwrite: Style fixups Brian Norris
2010-10-15 7:44 ` [PATCH 2/3] mtd-utils: nanddump: Dynamic buffer, increase pagesize/oobsize Brian Norris
2010-10-15 17:55 ` Mike Frysinger
2010-10-15 7:44 ` [PATCH 3/3] mtd-utils: nandwrite: Large page+oob support Brian Norris
2010-10-15 18:58 ` Mike Frysinger
2010-10-16 2:12 ` Brian Norris [this message]
2010-10-16 19:28 ` [PATCH 1/3] mtd-utils: nanddump/nandwrite: Style fixups 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=1287195145-10054-1-git-send-email-computersforpeace@gmail.com \
--to=computersforpeace@gmail.com \
--cc=dedekind1@gmail.com \
--cc=dwmw2@infradead.org \
--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).