mtd/util nandwrite.c,1.29,1.30

dbrown at infradead.org dbrown at infradead.org
Thu Apr 7 10:17:49 EDT 2005


Update of /home/cvs/mtd/util
In directory phoenix.infradead.org:/tmp/cvs-serv21394

Modified Files:
	nandwrite.c 
Log Message:
Support out-of-order oobfree segments; used by diskonchip.


Index: nandwrite.c
===================================================================
RCS file: /home/cvs/mtd/util/nandwrite.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- nandwrite.c	24 Mar 2005 20:42:05 -0000	1.29
+++ nandwrite.c	7 Apr 2005 14:17:46 -0000	1.30
@@ -48,6 +48,7 @@
  */
 unsigned char writebuf[MAX_PAGE_SIZE];
 unsigned char oobbuf[MAX_OOB_SIZE];
+unsigned char oobreadbuf[MAX_OOB_SIZE];
 
 // oob layouts to pass into the kernel as default
 struct nand_oobinfo none_oobinfo = { 
@@ -215,6 +216,8 @@
 
 	process_options(argc, argv);
 
+	memset(oobbuf, 0xff, sizeof(oobbuf));
+
 	if (pad && writeoob) {
 		fprintf(stderr, "Can't pad when oob data is present.\n");
 		exit(1);
@@ -304,7 +307,7 @@
 	}
 
 	oob.length = meminfo.oobsize;
-	oob.ptr = oobbuf;
+	oob.ptr = noecc ? oobreadbuf : oobbuf;
 
 	/* Open the input file */
 	if ((ifd = open(img, O_RDONLY)) == -1) {
@@ -384,29 +387,35 @@
 
 		if (writeoob) {
 			/* Read OOB data from input file, exit on failure */
-			if ((cnt = read(ifd, oobbuf, meminfo.oobsize)) != meminfo.oobsize) {
+			if ((cnt = read(ifd, oobreadbuf, meminfo.oobsize)) != meminfo.oobsize) {
 				perror ("File I/O error on input file");
 				goto closeall;
 			}
 			if (!noecc) {
-				int i, j;
+				int i, start, len;
 				/* 
 				 *  We use autoplacement and have the oobinfo with the autoplacement
 				 * information from the kernel available 
+				 *
+				 * Modified to support out of order oobfree segments,
+				 * such as the layout used by diskonchip.c
 				 */  
 				if (!oobinfochanged && (old_oobinfo.useecc == MTD_NANDECC_AUTOPLACE)) {
-					j = 0;
 					for (i = 0;old_oobinfo.oobfree[i][1]; i++) {
 						/* Set the reserved bytes to 0xff */
-						for (; j < old_oobinfo.oobfree[i][0]; j++)
-							oobbuf[j] = 0xff;
-						/* Set j to the end of the free area */
-						j = old_oobinfo.oobfree[i][0] + old_oobinfo.oobfree[i][1];
+						start = old_oobinfo.oobfree[i][0];
+						len = old_oobinfo.oobfree[i][1];
+						memcpy(oobbuf + start,
+							oobreadbuf + start,
+							len);
 					}
 				} else {
 					/* Set at least the ecc byte positions to 0xff */
-					for (i = 0; i < old_oobinfo.eccbytes; i++)
-						oobbuf[old_oobinfo.eccpos[i]] = 0xff;
+					start = old_oobinfo.eccbytes;
+					len = meminfo.oobsize - start;
+					memcpy(oobbuf + start,
+						oobreadbuf + start,
+						len);
 				}
 			}
 			/* Write OOB data first, as ecc will be placed in there*/





More information about the linux-mtd-cvs mailing list