From 90ef117b68387d66763291af0117677644166611 Mon Sep 17 00:00:00 2001 From: William Juul Date: Thu, 15 Nov 2007 12:23:57 +0100 Subject: Incorporate yaffs2 into U-boot To use YAFFS2 define CONFIG_YAFFS2 Signed-off-by: William Juul Signed-off-by: Scott Wood --- fs/yaffs2/direct/Makefile | 58 ++++---- fs/yaffs2/direct/dtest.c | 2 + fs/yaffs2/direct/yaffs_fileem.c | 5 +- fs/yaffs2/direct/yaffs_fileem2k.c | 4 +- fs/yaffs2/direct/yaffs_flashif.c | 3 +- fs/yaffs2/direct/yaffs_malloc.h | 5 +- fs/yaffs2/direct/yaffs_ramdisk.c | 5 +- fs/yaffs2/direct/yaffs_ramem2k.c | 3 +- fs/yaffs2/direct/yaffscfg.c | 303 ++++++++++++++++++++++++++++++++++++-- fs/yaffs2/direct/yaffscfg.h | 1 + fs/yaffs2/direct/yaffscfg2k.c | 4 +- fs/yaffs2/direct/yaffsfs.c | 15 +- fs/yaffs2/direct/ydirectenv.h | 8 +- 13 files changed, 355 insertions(+), 61 deletions(-) (limited to 'fs/yaffs2/direct') diff --git a/fs/yaffs2/direct/Makefile b/fs/yaffs2/direct/Makefile index 6315117cdf..0ee18e5c8a 100644 --- a/fs/yaffs2/direct/Makefile +++ b/fs/yaffs2/direct/Makefile @@ -17,50 +17,46 @@ # $Id: Makefile,v 1.15 2007/07/18 19:40:38 charles Exp $ #EXTRA_COMPILE_FLAGS = -DYAFFS_IGNORE_TAGS_ECC +include $(TOPDIR)/config.mk -CFLAGS = -Wall -DCONFIG_YAFFS_DIRECT -DCONFIG_YAFFS_SHORT_NAMES_IN_RAM -DCONFIG_YAFFS_YAFFS2 -g $(EXTRA_COMPILE_FLAGS) -DNO_Y_INLINE -CFLAGS+= -fstack-check -O0 +LIB = $(obj)libyaffs2.a -#CFLAGS+= -Wshadow -Wpointer-arith -Wwrite-strings -Wstrict-prototypes -Wmissing-declarations -#CFLAGS+= -Wmissing-prototypes -Wredundant-decls -Wnested-externs -Winline +COBJS-$(CONFIG_YAFFS2) := \ + yaffscfg.o yaffs_ecc.o yaffsfs.o yaffs_guts.o yaffs_packedtags1.o \ + yaffs_tagscompat.o yaffs_packedtags2.o yaffs_tagsvalidity.o \ + yaffs_nand.o yaffs_checkptrw.o yaffs_qsort.o yaffs_mtdif.o \ + yaffs_mtdif2.o - -DIRECTTESTOBJS = dtest.o yaffscfg2k.o yaffs_ecc.o yaffs_fileem2k.o yaffsfs.o yaffs_guts.o \ - yaffs_packedtags1.o yaffs_ramdisk.o yaffs_ramem2k.o \ - yaffs_tagscompat.o yaffs_packedtags2.o yaffs_tagsvalidity.o yaffs_nand.o \ - yaffs_checkptrw.o yaffs_qsort.o \ -# yaffs_checkptrwtest.o\ - - -BOOTTESTOBJS = bootldtst.o yboot.o yaffs_fileem.o nand_ecc.o - -#ALLOBJS = dtest.o nand_ecc.o yaffscfg.o yaffs_fileem.o yaffsfs.o yaffs_ramdisk.o bootldtst.o yboot.o yaffs_ramem2k.o - -ALLOBJS = $(DIRECTTESTOBJS) $(BOOTTESTOBJS) +SRCS := $(COBJS-y:.o=.c) +OBJS := $(addprefix $(obj),$(COBJS-y)) SYMLINKS = devextras.h yaffs_ecc.c yaffs_ecc.h yaffs_guts.c yaffs_guts.h yaffsinterface.h yportenv.h yaffs_tagscompat.c yaffs_tagscompat.h \ yaffs_packedtags1.c yaffs_packedtags1.h yaffs_packedtags2.c yaffs_packedtags2.h yaffs_nandemul2k.h \ - yaffs_nand.c yaffs_nand.h \ + yaffs_nand.c yaffs_nand.h yaffs_mtdif.c yaffs_mtdif.h \ yaffs_tagsvalidity.c yaffs_tagsvalidity.h yaffs_checkptrw.h yaffs_checkptrw.c \ - yaffs_qsort.c yaffs_qsort.h + yaffs_qsort.c yaffs_qsort.h yaffs_mtdif2.c yaffs_mtdif2.h -#all: directtest2k boottest +# -DCONFIG_YAFFS_NO_YAFFS1 +CFLAGS += -DCONFIG_YAFFS_DIRECT -DCONFIG_YAFFS_SHORT_NAMES_IN_RAM -DCONFIG_YAFFS_YAFFS2 -DNO_Y_INLINE -DLINUX_VERSION_CODE=0x20616 -all: directtest2k +all: $(LIB) -$(ALLOBJS): %.o: %.c - gcc -c $(CFLAGS) $< -o $@ +$(LIB): $(obj).depend $(OBJS) + $(AR) $(ARFLAGS) $@ $(OBJS) -$(SYMLINKS): - ln -s ../$@ $@ +.PHONY: clean distclean +clean: + rm -f $(OBJS) -directtest2k: $(SYMLINKS) $(DIRECTTESTOBJS) - gcc -o $@ $(DIRECTTESTOBJS) +distclean: clean + rm -f $(LIB) core *.bak .depend +######################################################################### -boottest: $(SYMLINKS) $(BOOTTESTOBJS) - gcc -o $@ $(BOOTTESTOBJS) +# defines $(obj).depend target +include $(SRCTREE)/rules.mk +sinclude $(obj).depend + +######################################################################### -clean: - rm -f $(ALLOBJS) core diff --git a/fs/yaffs2/direct/dtest.c b/fs/yaffs2/direct/dtest.c index be492b47c9..a9156ca190 100644 --- a/fs/yaffs2/direct/dtest.c +++ b/fs/yaffs2/direct/dtest.c @@ -15,6 +15,8 @@ * Test code for the "direct" interface. */ +/* XXX U-BOOT XXX */ +#include #include #include diff --git a/fs/yaffs2/direct/yaffs_fileem.c b/fs/yaffs2/direct/yaffs_fileem.c index e3cc30eb8a..5779d7ebc3 100644 --- a/fs/yaffs2/direct/yaffs_fileem.c +++ b/fs/yaffs2/direct/yaffs_fileem.c @@ -16,6 +16,9 @@ * This is only intended as test code to test persistence etc. */ +/* XXX U-BOOT XXX */ +#include + const char *yaffs_flashif_c_version = "$Id: yaffs_fileem.c,v 1.3 2007/02/14 01:09:06 wookey Exp $"; @@ -214,5 +217,3 @@ int yflash_InitialiseNAND(yaffs_Device *dev) return YAFFS_OK; } - - diff --git a/fs/yaffs2/direct/yaffs_fileem2k.c b/fs/yaffs2/direct/yaffs_fileem2k.c index 7a3b299996..34a4e87b3d 100644 --- a/fs/yaffs2/direct/yaffs_fileem2k.c +++ b/fs/yaffs2/direct/yaffs_fileem2k.c @@ -16,6 +16,9 @@ * This is only intended as test code to test persistence etc. */ +/* XXX U-BOOT XXX */ +#include + const char *yaffs_flashif_c_version = "$Id: yaffs_fileem2k.c,v 1.12 2007/02/14 01:09:06 wookey Exp $"; @@ -438,4 +441,3 @@ int yflash_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo, yaffs_Blo } return YAFFS_OK; } - diff --git a/fs/yaffs2/direct/yaffs_flashif.c b/fs/yaffs2/direct/yaffs_flashif.c index 5178cb2ac3..8d51dc6af7 100644 --- a/fs/yaffs2/direct/yaffs_flashif.c +++ b/fs/yaffs2/direct/yaffs_flashif.c @@ -11,6 +11,8 @@ * published by the Free Software Foundation. */ +/* XXX U-BOOT XXX */ +#include const char *yaffs_flashif_c_version = "$Id: yaffs_flashif.c,v 1.3 2007/02/14 01:09:06 wookey Exp $"; @@ -226,4 +228,3 @@ int yflash_InitialiseNAND(yaffs_Device *dev) { return YAFFS_OK; } - diff --git a/fs/yaffs2/direct/yaffs_malloc.h b/fs/yaffs2/direct/yaffs_malloc.h index 245f9c9634..122fb4c06f 100644 --- a/fs/yaffs2/direct/yaffs_malloc.h +++ b/fs/yaffs2/direct/yaffs_malloc.h @@ -14,8 +14,11 @@ * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. */ +/* XXX U-BOOT XXX */ +#if 0 #include - +#endif + void *yaffs_malloc(size_t size); void yaffs_free(void *ptr); diff --git a/fs/yaffs2/direct/yaffs_ramdisk.c b/fs/yaffs2/direct/yaffs_ramdisk.c index 6afee81f4c..57f27ce07c 100644 --- a/fs/yaffs2/direct/yaffs_ramdisk.c +++ b/fs/yaffs2/direct/yaffs_ramdisk.c @@ -18,6 +18,9 @@ * Use this with dev->useNANDECC enabled, then ECC overheads are not required. */ +/* XXX U-BOOT XXX */ +#include + const char *yaffs_ramdisk_c_version = "$Id: yaffs_ramdisk.c,v 1.4 2007/02/14 01:09:06 wookey Exp $"; @@ -230,5 +233,3 @@ int yramdisk_InitialiseNAND(yaffs_Device *dev) return YAFFS_OK; } - - diff --git a/fs/yaffs2/direct/yaffs_ramem2k.c b/fs/yaffs2/direct/yaffs_ramem2k.c index 1ab053c467..8161789280 100644 --- a/fs/yaffs2/direct/yaffs_ramem2k.c +++ b/fs/yaffs2/direct/yaffs_ramem2k.c @@ -15,6 +15,8 @@ * yaffs_ramem2k.c: RAM emulation in-kernel for 2K pages (YAFFS2) */ +/* XXX U-BOOT XXX */ +#include const char *yaffs_ramem2k_c_version = "$Id: yaffs_ramem2k.c,v 1.3 2007/02/14 01:09:06 wookey Exp $"; @@ -360,4 +362,3 @@ int nandemul2k_GetNumberOfBlocks(void) {return nandemul2k_CalcNBlocks();} #endif //YAFFS_RAM_ENABLED - diff --git a/fs/yaffs2/direct/yaffscfg.c b/fs/yaffs2/direct/yaffscfg.c index b1d311e569..a4a0924ef9 100644 --- a/fs/yaffs2/direct/yaffscfg.c +++ b/fs/yaffs2/direct/yaffscfg.c @@ -18,17 +18,34 @@ * There is no need to redistribute this file. */ +/* XXX U-BOOT XXX */ +#include + +#include +#include "nand.h" #include "yaffscfg.h" #include "yaffsfs.h" +#include "yaffs_packedtags2.h" +#include "yaffs_mtdif.h" +#include "yaffs_mtdif2.h" +#if 0 #include +#else +#include "malloc.h" +#endif unsigned yaffs_traceMask = 0xFFFFFFFF; - +static int yaffs_errno = 0; void yaffsfs_SetError(int err) { //Do whatever to set error - errno = err; + yaffs_errno = err; +} + +int yaffsfs_GetError(void) +{ + return yaffs_errno; } void yaffsfs_Lock(void) @@ -71,27 +88,47 @@ void yaffsfs_LocalInitialisation(void) #include "yaffs_ramdisk.h" #include "yaffs_flashif.h" +static int isMounted = 0; +#define MOUNT_POINT "/flash" +extern nand_info_t nand_info[]; + +/* XXX U-BOOT XXX */ +#if 0 static yaffs_Device ramDev; static yaffs_Device bootDev; static yaffs_Device flashDev; +#endif static yaffsfs_DeviceConfiguration yaffsfs_config[] = { - +/* XXX U-BOOT XXX */ +#if 0 { "/ram", &ramDev}, { "/boot", &bootDev}, { "/flash", &flashDev}, +#else + { MOUNT_POINT, 0}, +#endif {(void *)0,(void *)0} }; int yaffs_StartUp(void) { + struct mtd_info *mtd = &nand_info[0]; + int yaffsVersion = 2; + int nBlocks; + + yaffs_Device *flashDev = calloc(1, sizeof(yaffs_Device)); + yaffsfs_config[0].dev = flashDev; + // Stuff to configure YAFFS // Stuff to initialise anything special (eg lock semaphore). yaffsfs_LocalInitialisation(); // Set up devices +/* XXX U-BOOT XXX */ +#if 0 // /ram ramDev.nBytesPerChunk = 512; ramDev.nChunksPerBlock = 32; @@ -119,20 +156,50 @@ int yaffs_StartUp(void) bootDev.readChunkFromNAND = yflash_ReadChunkFromNAND; bootDev.eraseBlockInNAND = yflash_EraseBlockInNAND; bootDev.initialiseNAND = yflash_InitialiseNAND; +#endif // /flash - flashDev.nBytesPerChunk = 512; - flashDev.nChunksPerBlock = 32; - flashDev.nReservedBlocks = 5; - flashDev.startBlock = 128; // First block after 2MB - flashDev.endBlock = 1023; // Last block in 16MB - flashDev.useNANDECC = 0; // use YAFFS's ECC - flashDev.nShortOpCaches = 10; // Use caches - flashDev.genericDevice = (void *) 2; // Used to identify the device in fstat. - flashDev.writeChunkToNAND = yflash_WriteChunkToNAND; - flashDev.readChunkFromNAND = yflash_ReadChunkFromNAND; - flashDev.eraseBlockInNAND = yflash_EraseBlockInNAND; - flashDev.initialiseNAND = yflash_InitialiseNAND; + flashDev->nReservedBlocks = 5; +// flashDev->nShortOpCaches = (options.no_cache) ? 0 : 10; + flashDev->nShortOpCaches = 10; // Use caches + flashDev->useNANDECC = 0; // do not use YAFFS's ECC + + if (yaffsVersion == 2) + { + flashDev->writeChunkWithTagsToNAND = nandmtd2_WriteChunkWithTagsToNAND; + flashDev->readChunkWithTagsFromNAND = nandmtd2_ReadChunkWithTagsFromNAND; + flashDev->markNANDBlockBad = nandmtd2_MarkNANDBlockBad; + flashDev->queryNANDBlock = nandmtd2_QueryNANDBlock; + flashDev->spareBuffer = YMALLOC(mtd->oobsize); + flashDev->isYaffs2 = 1; +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) + flashDev->nDataBytesPerChunk = mtd->writesize; + flashDev->nChunksPerBlock = mtd->erasesize / mtd->writesize; +#else + flashDev->nDataBytesPerChunk = mtd->oobblock; + flashDev->nChunksPerBlock = mtd->erasesize / mtd->oobblock; +#endif + nBlocks = mtd->size / mtd->erasesize; + + flashDev->nCheckpointReservedBlocks = 10; + flashDev->startBlock = 0; + flashDev->endBlock = nBlocks - 1; + } + else + { + flashDev->writeChunkToNAND = nandmtd_WriteChunkToNAND; + flashDev->readChunkFromNAND = nandmtd_ReadChunkFromNAND; + flashDev->isYaffs2 = 0; + nBlocks = mtd->size / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK); + flashDev->startBlock = 320; + flashDev->endBlock = nBlocks - 1; + flashDev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK; + flashDev->nDataBytesPerChunk = YAFFS_BYTES_PER_CHUNK; + } + + /* ... and common functions */ + flashDev->eraseBlockInNAND = nandmtd_EraseBlockInNAND; + flashDev->initialiseNAND = nandmtd_InitialiseNAND; yaffs_initialise(yaffsfs_config); @@ -140,5 +207,211 @@ int yaffs_StartUp(void) } +void make_a_file(char *yaffsName,char bval,int sizeOfFile) +{ + int outh; + int i; + unsigned char buffer[100]; + + outh = yaffs_open(yaffsName, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE); + if (outh < 0) + { + printf("Error opening file: %d\n", outh); + return; + } + + memset(buffer,bval,100); + + do{ + i = sizeOfFile; + if(i > 100) i = 100; + sizeOfFile -= i; + + yaffs_write(outh,buffer,i); + + } while (sizeOfFile > 0); + + + yaffs_close(outh); +} + +void read_a_file(char *fn) +{ + int h; + int i = 0; + unsigned char b; + + h = yaffs_open(fn, O_RDWR,0); + if(h<0) + { + printf("File not found\n"); + return; + } + + while(yaffs_read(h,&b,1)> 0) + { + printf("%02x ",b); + i++; + if(i > 32) + { + printf("\n"); + i = 0;; + } + } + printf("\n"); + yaffs_close(h); +} + +void cmd_yaffs_mount(char *mp) +{ + yaffs_StartUp(); + int retval = yaffs_mount(mp); + if( retval != -1) + isMounted = 1; + else + printf("Error mounting %s, return value: %d\n", mp, yaffsfs_GetError()); +} + +static void checkMount(void) +{ + if( !isMounted ) + { + cmd_yaffs_mount(MOUNT_POINT); + } +} + +void cmd_yaffs_umount(char *mp) +{ + checkMount(); + if( yaffs_unmount(mp) == -1) + printf("Error umounting %s, return value: %d\n", mp, yaffsfs_GetError()); +} + +void cmd_yaffs_write_file(char *yaffsName,char bval,int sizeOfFile) +{ + checkMount(); + make_a_file(yaffsName,bval,sizeOfFile); +} +void cmd_yaffs_read_file(char *fn) +{ + checkMount(); + read_a_file(fn); +} + + +void cmd_yaffs_mread_file(char *fn, char *addr) +{ + int h; + struct yaffs_stat s; + + checkMount(); + + yaffs_stat(fn,&s); + + printf ("Copy %s to 0x%08x... ", fn, addr); + h = yaffs_open(fn, O_RDWR,0); + if(h<0) + { + printf("File not found\n"); + return; + } + + yaffs_read(h,addr,(int)s.st_size); + printf("\t[DONE]\n"); + + yaffs_close(h); +} + + +void cmd_yaffs_mwrite_file(char *fn, char *addr, int size) +{ + int outh; + + checkMount(); + outh = yaffs_open(fn, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE); + if (outh < 0) + { + printf("Error opening file: %d\n", outh); + } + + yaffs_write(outh,addr,size); + + yaffs_close(outh); +} + + +void cmd_yaffs_ls(const char *mountpt, int longlist) +{ + int i; + yaffs_DIR *d; + yaffs_dirent *de; + struct yaffs_stat stat; + char tempstr[255]; + + checkMount(); + d = yaffs_opendir(mountpt); + + if(!d) + { + printf("opendir failed\n"); + } + else + { + for(i = 0; (de = yaffs_readdir(d)) != NULL; i++) + { + if (longlist) + { + sprintf(tempstr, "%s/%s", mountpt, de->d_name); + yaffs_stat(tempstr, &stat); + printf("%-25s\t%7d\n",de->d_name, stat.st_size); + } + else + { + printf("%s\n",de->d_name); + } + } + } +} + + +void cmd_yaffs_mkdir(const char *dir) +{ + checkMount(); + + int retval = yaffs_mkdir(dir, 0); + + if ( retval < 0) + printf("yaffs_mkdir returning error: %d\n", retval); +} + +void cmd_yaffs_rmdir(const char *dir) +{ + checkMount(); + + int retval = yaffs_rmdir(dir); + + if ( retval < 0) + printf("yaffs_rmdir returning error: %d\n", retval); +} + +void cmd_yaffs_rm(const char *path) +{ + checkMount(); + + int retval = yaffs_unlink(path); + + if ( retval < 0) + printf("yaffs_unlink returning error: %d\n", retval); +} + +void cmd_yaffs_mv(const char *oldPath, const char *newPath) +{ + checkMount(); + + int retval = yaffs_rename(newPath, oldPath); + + if ( retval < 0) + printf("yaffs_unlink returning error: %d\n", retval); +} diff --git a/fs/yaffs2/direct/yaffscfg.h b/fs/yaffs2/direct/yaffscfg.h index 2a60dc132c..6ae169612b 100644 --- a/fs/yaffs2/direct/yaffscfg.h +++ b/fs/yaffs2/direct/yaffscfg.h @@ -40,6 +40,7 @@ void yaffsfs_Unlock(void); __u32 yaffsfs_CurrentTime(void); void yaffsfs_SetError(int err); +int yaffsfs_GetError(void); #endif diff --git a/fs/yaffs2/direct/yaffscfg2k.c b/fs/yaffs2/direct/yaffscfg2k.c index 6d5f542fc4..1daede181e 100644 --- a/fs/yaffs2/direct/yaffscfg2k.c +++ b/fs/yaffs2/direct/yaffscfg2k.c @@ -18,6 +18,9 @@ * There is no need to redistribute this file. */ +/* XXX U-BOOT XXX */ +#include + #include "yaffscfg.h" #include "yaffsfs.h" #include "yaffs_fileem2k.h" @@ -226,4 +229,3 @@ void SetCheckpointReservedBlocks(int n) { flashDev.nCheckpointReservedBlocks = n; } - diff --git a/fs/yaffs2/direct/yaffsfs.c b/fs/yaffs2/direct/yaffsfs.c index a8519c28e7..f62c952ddc 100644 --- a/fs/yaffs2/direct/yaffsfs.c +++ b/fs/yaffs2/direct/yaffsfs.c @@ -11,12 +11,20 @@ * published by the Free Software Foundation. */ +/* XXX U-BOOT XXX */ +#include +#include + #include "yaffsfs.h" #include "yaffs_guts.h" #include "yaffscfg.h" -#include // for memset #include "yportenv.h" +/* XXX U-BOOT XXX */ +#if 0 +#include // for memset +#endif + #define YAFFSFS_MAX_SYMLINK_DEREFERENCES 5 #ifndef NULL @@ -925,7 +933,7 @@ int yaffs_fstat(int fd, struct yaffs_stat *buf) static int yaffsfs_DoChMod(yaffs_Object *obj,mode_t mode) { - int result; + int result = YAFFS_FAIL; if(obj) { @@ -1158,8 +1166,6 @@ void yaffs_initialise(yaffsfs_DeviceConfiguration *cfgList) cfg->dev->removeObjectCallback = yaffsfs_RemoveObjectCallback; cfg++; } - - } @@ -1502,4 +1508,3 @@ int yaffs_DumpDevStruct(const char *path) } return 0; } - diff --git a/fs/yaffs2/direct/ydirectenv.h b/fs/yaffs2/direct/ydirectenv.h index 0c2820579e..adcc0b5468 100644 --- a/fs/yaffs2/direct/ydirectenv.h +++ b/fs/yaffs2/direct/ydirectenv.h @@ -24,13 +24,19 @@ #include "devextras.h" +/* XXX U-BOOT XXX */ +#if 0 #include "stdlib.h" #include "stdio.h" #include "string.h" +#include "assert.h" +#endif #include "yaffs_malloc.h" -#include "assert.h" +/* XXX U-BOOT XXX */ +#if 0 #define YBUG() assert(1) +#endif #define YCHAR char #define YUCHAR unsigned char -- cgit