public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Pantelis Antoniou <panto@intracom.gr>
To: linux-mtd@lists.infradead.org,
	David Woodhouse <dwmw2@infradead.org>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: MTD util patch for NAND
Date: Tue, 04 May 2004 12:18:18 +0300	[thread overview]
Message-ID: <40975FDA.3080904@intracom.gr> (raw)

[-- Attachment #1: Type: text/plain, Size: 258 bytes --]

Hello

The following patch fixes nandwrite/eraseall to work correctly on NANDs with
the current mtd code.

There is a new option for nandwrite -a/--autoplace which places the OOB
bytes according to the autoplaced OOB of the current code.

Regards

Pantelis


[-- Attachment #2: mtd-util-nand.diff --]
[-- Type: text/x-patch, Size: 3442 bytes --]

diff -ruN mtd-original/util/eraseall.c mtd-work/util/eraseall.c
--- mtd-original/util/eraseall.c	2003-05-03 01:00:10.000000000 +0300
+++ mtd-work/util/eraseall.c	2004-05-04 12:09:23.543752712 +0300
@@ -111,8 +111,20 @@
 			struct mtd_oob_buf oob;
 			oob.ptr = (unsigned char *) &cleanmarker;
 			oob.start = erase.start;
-			oob.start += meminfo.oobsize == 16 ? 8 : 6;
-			oob.length = meminfo.oobsize == 16 ? 8 : 2;
+			switch (meminfo.oobsize) {
+				case 8:
+					oob.start += 6;
+					oob.length = 2;
+					break;
+				case 16:
+					oob.start += 8;
+					oob.length = 8;
+					break;
+				case 64:
+					oob.start += 2;
+					oob.length = 8;
+					break;
+			}
 			if (ioctl (fd, MEMWRITEOOB, &oob) != 0) {
 				fprintf(stderr, "\n%s: %s: MTD writeoob failure: %s\n", exe_name, mtd_device, strerror(errno));
 				continue;
diff -ruN mtd-original/util/nandwrite.c mtd-work/util/nandwrite.c
--- mtd-original/util/nandwrite.c	2003-05-01 01:00:28.000000000 +0300
+++ mtd-work/util/nandwrite.c	2004-05-03 15:03:43.045463248 +0300
@@ -47,24 +47,29 @@
 
 // oob layouts to pass into the kernel as default
 struct nand_oobinfo none_oobinfo = { 
-	useecc: 0,
+	.useecc = MTD_NANDECC_OFF,
 };
 
 struct nand_oobinfo jffs2_oobinfo = { 
-	useecc: 1,
-	eccpos:	{ 0, 1, 2, 3, 6, 7}
+	.useecc = MTD_NANDECC_PLACE,
+	.eccpos = { 0, 1, 2, 3, 6, 7 }
 };
 
 struct nand_oobinfo yaffs_oobinfo = { 
-	useecc: 1,
-	eccpos:	{ 8, 9, 10, 13, 14, 15}
+	.useecc = MTD_NANDECC_PLACE,
+	.eccpos = { 8, 9, 10, 13, 14, 15}
+};
+
+struct nand_oobinfo autoplace_oobinfo = {
+	.useecc = MTD_NANDECC_AUTOPLACE
 };
 
 void display_help (void)
 {
 	printf("Usage: nandwrite [OPTION] MTD_DEVICE INPUTFILE\n"
-	       "Erases all of the specified MTD device.\n"
+	       "Writes to the specified MTD device.\n"
 	       "\n"
+	       "  -a, --autoplace  	Use auto oob layout\n"
 	       "  -j, --jffs2  	 	force jffs2 oob layout\n"
 	       "  -y, --yaffs  	 	force yaffs oob layout\n"
 	       "  -n, --noecc		write without ecc\n"
@@ -95,6 +100,7 @@
 int 	mtdoffset = 0;
 int 	quiet = 0;
 int	writeoob = 0;
+int	autoplace = 0;
 int	forcejffs2 = 0;
 int	forceyaffs = 0;
 int	noecc = 0;
@@ -105,12 +111,13 @@
 
 	for (;;) {
 		int option_index = 0;
-		static const char *short_options = "os:jynq";
+		static const char *short_options = "os:ajynq";
 		static const struct option long_options[] = {
 			{"help", no_argument, 0, 0},
 			{"version", no_argument, 0, 0},
 			{"oob", no_argument, 0, 'o'},
 			{"start", required_argument, 0, 's'},
+			{"autoplace", no_argument, 0, 'a'},
 			{"jffs2", no_argument, 0, 'j'},
 			{"yaffs", no_argument, 0, 'y'},
 			{"noecc", no_argument, 0, 'n'},
@@ -138,6 +145,9 @@
 		case 'q':
 			quiet = 1;
 			break;
+		case 'a':
+			autoplace = 1;
+			break;
 		case 'j':
 			forcejffs2 = 1;
 			break;
@@ -166,14 +176,13 @@
 	img = argv[optind];
 }
 
-
 /*
  * Main program
  */
 int main(int argc, char **argv)
 {
 	int cnt, fd, ifd, imglen, pagelen, blockstart = -1;
-	mtd_info_t meminfo;
+	struct mtd_info_user meminfo;
 	struct mtd_oob_buf oob;
 
 	process_options(argc, argv);
@@ -208,6 +217,15 @@
 		} 
 	}
 
+	// autoplace ECC ?
+	if (autoplace) {
+		if (ioctl (fd, MEMSETOOBSEL, &autoplace_oobinfo) != 0) {
+			perror ("MEMSETOOBSEL");
+			close (fd);
+			exit (1);
+		} 
+	}
+
 	// force oob layout for jffs2 or yaffs ?
 	if (forcejffs2 || forceyaffs) {
 		struct nand_oobinfo *oobsel = forcejffs2 ? &jffs2_oobinfo : &yaffs_oobinfo;

                 reply	other threads:[~2004-05-04  9:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=40975FDA.3080904@intracom.gr \
    --to=panto@intracom.gr \
    --cc=dwmw2@infradead.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=tglx@linutronix.de \
    /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