[Yaffs-archive] NAND changes

Thomas Gleixner tglx@linutronix.de
Tue, 18 Feb 2003 14:30:30 +0100


--Boundary_(ID_rteukJiMx3XE6u/hUzVUkg)
Content-type: text/plain; charset=us-ascii
Content-transfer-encoding: 7BIT

As you can see in my previous mail, there are some minor changes too 
oob-layout selection. See patch against current yaffs-cvs.

If you want to use the new functionality for mkyaffs too, set the ecc bytes in 
your image to 0xff and select the layout by ioctl (fd, MEMSETOOBSEL, 
&newsel). See patch.

-- 
Thomas
________________________________________________________________________
linutronix - competence in embedded & realtime linux
http://www.linutronix.de
mail: tglx@linutronix.de

--Boundary_(ID_rteukJiMx3XE6u/hUzVUkg)
Content-type: text/x-diff; charset=us-ascii; name=yaffs.diff
Content-transfer-encoding: 7BIT
Content-disposition: attachment; filename=yaffs.diff

Index: yaffs/yaffs_mtdif.c
===================================================================
RCS file: /home/aleph1/cvs/yaffs/yaffs_mtdif.c,v
retrieving revision 1.7
diff -u -r1.7 yaffs_mtdif.c
--- yaffs/yaffs_mtdif.c	17 Jan 2003 04:19:08 -0000	1.7
+++ yaffs/yaffs_mtdif.c	18 Feb 2003 12:28:10 -0000
@@ -29,6 +29,9 @@
 #include "linux/mtd/nand.h"
 #endif
 
+int yaffs_oob = NAND_YAFFS_OOB;
+int none_oob = NAND_NONE_OOB;
+
 int nandmtd_WriteChunkToNAND(yaffs_Device *dev,int chunkInNAND,const __u8 *data, yaffs_Spare *spare)
 {
 	struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
@@ -43,9 +46,9 @@
 	if(data && spare)
 	{
 		if(dev->useNANDECC)
-			mtd->write_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,spareAsBytes,NAND_YAFFS_OOB);
+			mtd->write_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,spareAsBytes,&yaffs_oob);
 		else
-			mtd->write_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,spareAsBytes,NAND_NONE_OOB);
+			mtd->write_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,spareAsBytes,&none_oob);
 	}
 	else
 	{
@@ -80,12 +83,12 @@
 		if(dev->useNANDECC)
 		{
 		        u8 tmpSpare[ YAFFS_BYTES_PER_SPARE + (2*sizeof(int)) ];
-			retval = mtd->read_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,tmpSpare,NAND_YAFFS_OOB);
+			retval = mtd->read_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,tmpSpare,&yaffs_oob);
 		        memcpy(spareAsBytes, tmpSpare, YAFFS_BYTES_PER_SPARE);
 		}
 		else
 		{
-			retval = mtd->read_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,spareAsBytes,NAND_NONE_OOB);
+			retval = mtd->read_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,spareAsBytes,&none_oob);
 		}
 	}
 	else
Index: yaffs/utils/mkyaffs.c
===================================================================
RCS file: /home/aleph1/cvs/yaffs/utils/mkyaffs.c,v
retrieving revision 1.5
diff -u -r1.5 mkyaffs.c
--- yaffs/utils/mkyaffs.c	13 Dec 2002 00:13:06 -0000	1.5
+++ yaffs/utils/mkyaffs.c	18 Feb 2003 12:28:10 -0000
@@ -76,19 +76,26 @@
 	unsigned long offset;
 	int fd;
 	int img=-1;
+	int optcnt = 1;
+	int usemtdecc = 0;
 	int imglen = 0;
 	struct mtd_oob_buf oob = {0, 16, (unsigned char *) &oobbuf};
 	mtd_info_t meminfo;
 	erase_info_t erase;
+	int oobsel;
 
+	if (strcmp (argv[optcnt], "-e") == 0) {
+		optcnt++;
+		usemtdecc = 1;
+	}
+	
 	/* Make sure a device was specified */
-	if(argc < 2) {
-		printf("usage: %s <mtdname> [image name]\n", argv[0]);
+	if(argc < (optcnt + 2)) {
+		printf("usage: %s -e <mtdname> <image name>\n", argv[0]);
 		exit(1);
 	}
-	
-	if(argc > 2 && 
-	   (img = open(argv[2],O_RDONLY)) == -1)	{
+
+	if((img = open(argv[optcnt + 1],O_RDONLY)) == -1) {
 		perror("opening image file");
 		exit(1);
 	}
@@ -104,7 +111,7 @@
 	lseek(img,0,SEEK_SET);
 
 	/* Open the device */
-	if((fd = open(argv[1], O_RDWR)) == -1) {
+	if((fd = open(argv[optcnt], O_RDWR)) == -1) {
 		perror("opening flash");
 		exit(1);
 	}
@@ -116,6 +123,14 @@
 		exit(1);
 	}
 
+	// set the appropriate oob layout selector
+	oobsel = usemtdecc ? NAND_YAFFS_OOB : NAND_NONE_OOB;
+	if (ioctl (fd, MEMSETOOBSEL, &oobsel) != 0) {
+		perror ("MEMSETOOBSEL");
+		close (fd);
+		exit (1);
+	} 
+
 	/* Make sure device page sizes are valid */
 	if( !(meminfo.oobsize == 16 && meminfo.oobblock == 512)) 
 	{
@@ -171,12 +186,21 @@
 				for(offset = 0; offset <meminfo.erasesize; offset+=512)
 				{
 					if(read(img,imgpage,528) == 528){
-						lseek(fd,addr+offset,SEEK_SET);
-						write(fd,imgpage,512);
+						if (usemtdecc) {
+							imgpage[512+8] = 0xff;
+							imgpage[512+9] = 0xff;
+							imgpage[512+10] = 0xff;
+							imgpage[512+13] = 0xff;
+							imgpage[512+14] = 0xff;
+							imgpage[512+15] = 0xff;
+						}
 						oob.start = addr+offset;
 						oob.length=16;
 						oob.ptr=&imgpage[512];
 						ioctl(fd,MEMWRITEOOB,&oob);
+
+						lseek(fd,addr+offset,SEEK_SET);
+						write(fd,imgpage,512);
 					}
 				}
 			}

--Boundary_(ID_rteukJiMx3XE6u/hUzVUkg)--

---------------------------------------------------------------------------------------
This mailing list is hosted by Toby Churchill open software (www.toby-churchill.org).
If mailing list membership is no longer wanted you can remove yourself from the list by 
sending an email to yaffs-request@toby-churchill.org with the text "unsubscribe" 
(without the quotes) as the subject.