[Yaffs-archive] Re: NAND changes

Thomas Gleixner tglx@linutronix.de
Tue, 18 Feb 2003 23:28:02 +0100


--Boundary_(ID_h4GhB29+MM6nsLwOoIsW4A)
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 7BIT

On Tuesday 18 February 2003 18:22, Thomas Gleixner wrote:
> Sorry for making noise. I was slightly brain damaged and confused of a lot
> of discussions. I'm going to change it again. Will make more noise, if
> finished.
Making noise again. Attached a patch against current CVS code.

Sorry for any disturbance or inconvenience.

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

--Boundary_(ID_h4GhB29+MM6nsLwOoIsW4A)
Content-type: text/x-diff; charset=iso-8859-1; 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 21:15:26 -0000
@@ -29,6 +29,16 @@
 #include "linux/mtd/nand.h"
 #endif
 
+struct nand_oobinfo yaffs_oobinfo = {
+	useecc: 1,
+	eccpos: {8, 9, 10, 13, 14, 15}
+};
+
+struct nand_oobinfo yaffs_noeccinfo = {
+	useecc: 0,
+};
+
+
 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 +53,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_oobinfo);
 		else
-			mtd->write_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,spareAsBytes,NAND_NONE_OOB);
+			mtd->write_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,spareAsBytes,&yaffs_noeccinfo);
 	}
 	else
 	{
@@ -80,12 +90,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_oobinfo);
 		        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,&yaffs_noeccinfo);
 		}
 	}
 	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 21:15:26 -0000
@@ -66,6 +66,19 @@
 unsigned char oobbuf[16];
 unsigned char imgpage[528];
 
+/*
+ * OOB layout
+ */
+
+struct nand_oobinfo yaffs_oobinfo = {
+	useecc: 1,
+	eccpos: {8, 9, 10, 13, 14, 15}
+};
+
+struct nand_oobinfo yaffs_noeccinfo = {
+	useecc: 0,
+};
+
 
 /*
  * Main program
@@ -76,19 +89,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;
+	struct nand_oobinfo 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 +124,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 +136,14 @@
 		exit(1);
 	}
 
+	// set the appropriate oob layout selector
+	oobsel = usemtdecc ? &yaffs_oobinfo : &yaffs_noeccinfo;
+	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 +199,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_h4GhB29+MM6nsLwOoIsW4A)--

---------------------------------------------------------------------------------------
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.