mtd/util nandwrite.c,1.27,1.28

gleixner at infradead.org gleixner at infradead.org
Thu Mar 24 15:39:54 EST 2005


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

Modified Files:
	nandwrite.c 
Log Message:
- Prevent accidental use of legacy formats with autoplacement. 
- Protect all reserved oob bytes with 0xff in autoplacement mode.



Index: nandwrite.c
===================================================================
RCS file: /home/cvs/mtd/util/nandwrite.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- nandwrite.c	24 Mar 2005 17:05:16 -0000	1.27
+++ nandwrite.c	24 Mar 2005 20:39:51 -0000	1.28
@@ -76,8 +76,9 @@
 	       "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"
+	       "  -j, --jffs2  	 	force jffs2 oob layout (legacy support)\n"
+	       "  -y, --yaffs  	 	force yaffs oob layout (legacy support)\n"
+	       "  -f, --forcelegacy     force legacy support on autoplacement enabled mtd device\n"
 	       "  -n, --noecc		write without ecc\n"
 	       "  -o, --oob    	 	image contains oob data\n"
 	       "  -s addr, --start=addr set start address (default is 0)\n"
@@ -111,6 +112,7 @@
 int	autoplace = 0;
 int	forcejffs2 = 0;
 int	forceyaffs = 0;
+int	forcelegacy = 0;
 int	noecc = 0;
 int	pad = 0;
 int	blockalign = 1; /*default to using 16K block size */
@@ -130,6 +132,7 @@
 			{"autoplace", no_argument, 0, 'a'},
 			{"jffs2", no_argument, 0, 'j'},
 			{"yaffs", no_argument, 0, 'y'},
+			{"forcelegacy", no_argument, 0, 'f'},
 			{"noecc", no_argument, 0, 'n'},
 			{"quiet", no_argument, 0, 'q'},
 			{"pad", no_argument, 0, 'p'},
@@ -166,6 +169,9 @@
 		case 'y':
 			forceyaffs = 1;
 			break;
+		case 'f':
+			forcelegacy = 1;
+			break;
 		case 'n':
 			noecc = 1;
 			break;
@@ -265,12 +271,23 @@
 			exit (1);
 		} 
 		oobinfochanged = 1;
-	}
+	} 
 
-	// force oob layout for jffs2 or yaffs ?
+	/* 
+	 * force oob layout for jffs2 or yaffs ?
+	 * Legacy support 
+	 */  
 	if (forcejffs2 || forceyaffs) {
 		struct nand_oobinfo *oobsel = forcejffs2 ? &jffs2_oobinfo : &yaffs_oobinfo;
-		
+
+		if (autoplace) {
+			fprintf("Autoplacement is not possible for legacy -j/-y options\n");
+			goto restoreoob;
+		}
+		if ((old_oobinfo.useecc == MTD_NANDECC_AUTOPLACE) && !forcelegacy) {
+			fprintf("Use -f option to enforce legacy placement on autoplacement enabled mtd device\n");
+			goto restoreoob;
+		}
 		if (meminfo.oobsize == 8) {
     			if (forceyaffs) {
 				fprintf (stderr, "YAFSS cannot operate on 256 Byte page size");
@@ -372,17 +389,25 @@
 				goto closeall;
 			}
 			if (!noecc) {
-				int i;
-				/* Set the ECC positions to 0xff 
-				 * Not sure, if we should also take care of the
-				 * reserved byte locations in case of autoplacement.
-				 * This makes only sense if we use the oob_info
-				 * which we read above. Not sure. The worst case
-				 * might be that the image contains some nonsense
-				 * at the bad block marker location.
-				 */
-				for (i = 0; i < old_oobinfo.eccbytes; i++)
-					oobbuf[old_oobinfo.eccpos[i]] = 0xff;
+				int i, j;
+				/* 
+				 *  We use autoplacement and have the oobinfo with the autoplacement
+				 * information from the kernel available 
+				 */  
+				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];
+					}
+				} else {
+					/* Set at least the ecc byte positions to 0xff */
+					for (i = 0; i < old_oobinfo.eccbytes; i++)
+						oobbuf[old_oobinfo.eccpos[i]] = 0xff;
+				}
 			}
 			/* Write OOB data first, as ecc will be placed in there*/
 			oob.start = mtdoffset;





More information about the linux-mtd-cvs mailing list