# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
-# $Id: Makefile,v 1.9 2002-12-13 00:13:06 charles Exp $
+# $Id: Makefile,v 1.10 2003-03-11 05:16:53 charles Exp $
#
## Change or override KERNELDIR to your kernel
KERNELDIR = /usr/src/kernel-headers-2.4.18
+## Change if you are using a cross-compiler
+MAKETOOLS =
+
+CC=$(MAKETOOLS)gcc
+LD=$(MAKETOOLS)ld
+
# Configurations...
# Comment out the stuff you don't want.
#
all: yaffs.o
$(OBJS): %.o: %.c Makefile
- gcc -c $(CFLAGS) $< -o $@
+ $(CC) -c $(CFLAGS) $< -o $@
yaffs.o: $(OBJS)
- ld -r $(OBJS) -o $@
+ $(LD) -r $(OBJS) -o $@
clean:
rm -f $(OBJS) core
#endif
-const char *yaffsfs_c_version="$Id: yaffsfs.c,v 1.4 2003-02-24 23:49:29 charles Exp $";
+const char *yaffsfs_c_version="$Id: yaffsfs.c,v 1.5 2003-03-11 05:16:53 charles Exp $";
// configurationList is the list of devices that are supported
static yaffsfs_DeviceConfiguration *yaffsfs_configurationList;
}
else
{
- } yaffsfs_SetError(-ENOTDIR);
+ yaffsfs_SetError(-ENOTDIR);
+ }
}
if(obj && !openDenied)
CFLAGS+= -Wshadow -Wpointer-arith -Wwrite-strings -Wstrict-prototypes -Wmissing-declarations
CFLAGS+= -Wmissing-prototypes -Wredundant-decls -Wnested-externs -Winline
+## Change if you are using a cross-compiler
+MAKETOOLS =
+
+CC=$(MAKETOOLS)gcc
MKYAFFSOBJS = mkyaffs.o
all: mkyaffs mkyaffsimage
$(MKYAFFSIMAGEOBJS): %.o: %.c
- gcc -c $(CFLAGS) $< -o $@
+ $(CC) -c $(CFLAGS) $< -o $@
mkyaffsimage: $(MKYAFFSIMAGEOBJS)
- gcc -o $@ $(MKYAFFSIMAGEOBJS)
+ $(CC) -o $@ $(MKYAFFSIMAGEOBJS)
$(MKYAFFSOBJS): %.o: %.c
- gcc -c $(CFLAGS) $< -o $@
+ $(CC) -c $(CFLAGS) $< -o $@
mkyaffs: $(MKYAFFSOBJS)
- gcc -o $@ $(MKYAFFSOBJS)
+ $(CC) -o $@ $(MKYAFFSOBJS)
nand_ecc.c:
ln -s ../nand_ecc.c nand_ecc.c
#include <linux/config.h>
#include <linux/mtd/mtd.h>
-const char *mkyaffs_c_version = "$Id: mkyaffs.c,v 1.5 2002-12-13 00:13:06 charles Exp $";
+const char *mkyaffs_c_version = "$Id: mkyaffs.c,v 1.6 2003-03-11 05:16:53 charles Exp $";
// countBits is a quick way of counting the number of bits in a byte.
// ie. countBits[n] holds the number of 1 bits in a byte with the value n.
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
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);
}
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);
}
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))
{
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);
}
}
}
*/
-const char *yaffs_fs_c_version = "$Id: yaffs_fs.c,v 1.24 2003-01-31 03:30:33 charles Exp $";
+const char *yaffs_fs_c_version = "$Id: yaffs_fs.c,v 1.25 2003-03-11 05:16:53 charles Exp $";
extern const char *yaffs_guts_c_version;
T(YAFFS_TRACE_OS,("yaffs_read_super: %s block size %d\n", useRam ? "RAM" : "MTD",(int)(sb->s_blocksize)));
#ifdef CONFIG_YAFFS_DISABLE_WRITE_VERIFY
- T(YAFFS_TRACE_OS,("yaffs: Write verification disabled. All guarantees null and void\n");
+ T(YAFFS_TRACE_OS,("yaffs: Write verification disabled. All guarantees null and void\n"));
#endif
*/
//yaffs_guts.c
-const char *yaffs_guts_c_version="$Id: yaffs_guts.c,v 1.21 2003-02-03 18:33:28 charles Exp $";
+const char *yaffs_guts_c_version="$Id: yaffs_guts.c,v 1.22 2003-03-11 05:16:53 charles Exp $";
#include "yportenv.h"
int retVal;
yaffs_Spare localSpare;
- __u8 calcEcc[3];
- int eccResult1,eccResult2;
- struct yaffs_NANDSpare nspare;
-
dev->nPageReads++;
{
// Do ECC correction
//Todo handle any errors
+ int eccResult1,eccResult2;
+ __u8 calcEcc[3];
+
nand_calculate_ecc(data,calcEcc);
eccResult1 = nand_correct_data (data,spare->ecc1, calcEcc);
nand_calculate_ecc(&data[256],calcEcc);
}
else
{
+ // Must allocate enough memory for spare+2*sizeof(int) for ecc results from device.
+ struct yaffs_NANDSpare nspare;
retVal = dev->readChunkFromNAND(dev,chunkInNAND,data,(yaffs_Spare*)&nspare);
memcpy (spare, &nspare, sizeof(yaffs_Spare));
if(data && doErrorCorrection)
T(YAFFS_TRACE_ERROR,(TSTR("**>>ecc error unfixed on chunk %d:1" TENDSTR),chunkInNAND));
}
- if(nspare.eccres2 || nspare.eccres2)
+ if(nspare.eccres1 || nspare.eccres2)
{
// Hoosterman, we had a data problem on this page
yaffs_HandleReadDataError(dev,chunkInNAND);
static int init = 0;
static __u8 cmpbuf[YAFFS_BYTES_PER_CHUNK];
static __u8 data[YAFFS_BYTES_PER_CHUNK];
- static __u8 spare[16];
-
-
- dev->readChunkFromNAND(dev,chunkInNAND,data,(yaffs_Spare *)spare);
-
-
+ // Might as well always allocate the larger size for dev->useNANDECC == true;
+ static __u8 spare[sizeof(struct yaffs_NANDSpare)];
+
+ dev->readChunkFromNAND(dev,chunkInNAND,data,(yaffs_Spare *)spare);
if(!init)
{
*
*/
-const char *yaffs_mtdif_c_version = "$Id: yaffs_mtdif.c,v 1.7 2003-01-17 04:19:08 charles Exp $";
+const char *yaffs_mtdif_c_version = "$Id: yaffs_mtdif.c,v 1.8 2003-03-11 05:16:53 charles Exp $";
#ifdef CONFIG_YAFFS_MTD_ENABLED
#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);
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
{
if(data && spare)
{
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);
- memcpy(spareAsBytes, tmpSpare, YAFFS_BYTES_PER_SPARE);
+ { // Careful, this call adds 2 ints to the end of the spare data. Calling function should
+ // allocate enough memory for spare, i.e. [YAFFS_BYTES_PER_SPARE+2*sizeof(int)].
+ retval = mtd->read_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,spareAsBytes,&yaffs_oobinfo);
}
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