All of lore.kernel.org
 help / color / mirror / Atom feed
* MTD util patch for NAND
@ 2004-05-04  9:18 Pantelis Antoniou
  0 siblings, 0 replies; only message in thread
From: Pantelis Antoniou @ 2004-05-04  9:18 UTC (permalink / raw)
  To: linux-mtd, David Woodhouse, Thomas Gleixner

[-- 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;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-05-04  9:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-05-04  9:18 MTD util patch for NAND Pantelis Antoniou

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.