Incorporate yaffs2 into U-boot
authorWilliam Juul <william.juul@datarespons.no>
Thu, 15 Nov 2007 11:23:57 +0000 (12:23 +0100)
committerScott Wood <scottwood@freescale.com>
Tue, 12 Aug 2008 16:31:19 +0000 (11:31 -0500)
To use YAFFS2 define CONFIG_YAFFS2

Signed-off-by: William Juul <william.juul@tandberg.com>
Signed-off-by: Scott Wood <scottwood@freescale.com>
31 files changed:
Makefile
common/Makefile
common/cmd_yaffs2.c [new file with mode: 0644]
fs/Makefile
fs/yaffs2/devextras.h
fs/yaffs2/direct/Makefile
fs/yaffs2/direct/dtest.c
fs/yaffs2/direct/yaffs_fileem.c
fs/yaffs2/direct/yaffs_fileem2k.c
fs/yaffs2/direct/yaffs_flashif.c
fs/yaffs2/direct/yaffs_malloc.h
fs/yaffs2/direct/yaffs_ramdisk.c
fs/yaffs2/direct/yaffs_ramem2k.c
fs/yaffs2/direct/yaffscfg.c
fs/yaffs2/direct/yaffscfg.h
fs/yaffs2/direct/yaffscfg2k.c
fs/yaffs2/direct/yaffsfs.c
fs/yaffs2/direct/ydirectenv.h
fs/yaffs2/yaffs_checkptrw.c
fs/yaffs2/yaffs_ecc.c
fs/yaffs2/yaffs_guts.c
fs/yaffs2/yaffs_guts.h
fs/yaffs2/yaffs_mtdif.c
fs/yaffs2/yaffs_mtdif2.c
fs/yaffs2/yaffs_nand.c
fs/yaffs2/yaffs_packedtags1.c
fs/yaffs2/yaffs_packedtags2.c
fs/yaffs2/yaffs_qsort.c
fs/yaffs2/yaffs_tagscompat.c
fs/yaffs2/yaffs_tagsvalidity.c
fs/yaffs2/yportenv.h

index 082b08e..b204884 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -210,7 +210,7 @@ LIBS += cpu/ixp/npe/libnpe.a
 endif
 LIBS += lib_$(ARCH)/lib$(ARCH).a
 LIBS += fs/cramfs/libcramfs.a fs/fat/libfat.a fs/fdos/libfdos.a fs/jffs2/libjffs2.a \
-       fs/reiserfs/libreiserfs.a fs/ext2/libext2fs.a
+       fs/reiserfs/libreiserfs.a fs/ext2/libext2fs.a fs/yaffs2/direct/libyaffs2.a
 LIBS += net/libnet.a
 LIBS += disk/libdisk.a
 LIBS += drivers/bios_emulator/libatibiosemu.a
@@ -378,6 +378,7 @@ TAG_SUBDIRS += fs/cramfs
 TAG_SUBDIRS += fs/fat
 TAG_SUBDIRS += fs/fdos
 TAG_SUBDIRS += fs/jffs2
+TAG_SUBDIRS += fs/yaffs2/direct
 TAG_SUBDIRS += net
 TAG_SUBDIRS += disk
 TAG_SUBDIRS += common
index 4287108..ecf755f 100644 (file)
@@ -98,6 +98,7 @@ COBJS-$(CONFIG_CMD_TERMINAL) += cmd_terminal.o
 COBJS-$(CONFIG_CMD_UNIVERSE) += cmd_universe.o
 COBJS-$(CONFIG_CMD_USB) += cmd_usb.o
 COBJS-$(CONFIG_CMD_XIMG) += cmd_ximg.o
+COBJS-$(CONFIG_YAFFS2) += cmd_yaffs2.o
 COBJS-y += cmd_vfd.o
 COBJS-y += command.o
 COBJS-y += console.o
diff --git a/common/cmd_yaffs2.c b/common/cmd_yaffs2.c
new file mode 100644 (file)
index 0000000..ac4a518
--- /dev/null
@@ -0,0 +1,215 @@
+#include <common.h>
+
+#include <config.h>
+#include <command.h>
+
+#ifdef  YAFFS2_DEBUG
+#define PRINTF(fmt,args...) printf (fmt ,##args)
+#else
+#define PRINTF(fmt,args...)
+#endif
+
+extern void cmd_yaffs_mount(char *mp);
+extern void cmd_yaffs_umount(char *mp);
+extern void cmd_yaffs_read_file(char *fn);
+extern void cmd_yaffs_write_file(char *fn,char bval,int sizeOfFile);
+extern void cmd_yaffs_ls(const char *mountpt, int longlist);
+extern void cmd_yaffs_mwrite_file(char *fn, char *addr, int size);
+extern void cmd_yaffs_mread_file(char *fn, char *addr);
+extern void cmd_yaffs_mkdir(const char *dir);
+extern void cmd_yaffs_rmdir(const char *dir);
+extern void cmd_yaffs_rm(const char *path);
+extern void cmd_yaffs_mv(const char *oldPath, const char *newPath);
+
+extern int yaffs_DumpDevStruct(const char *path);
+
+
+int do_ymount (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+    char *mtpoint = argv[1];
+    cmd_yaffs_mount(mtpoint);
+    
+    return(0);
+}
+
+int do_yumount (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+    char *mtpoint = argv[1];
+    cmd_yaffs_umount(mtpoint);
+    
+    return(0);
+}
+
+int do_yls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+    char *dirname = argv[argc-1];
+    
+    cmd_yaffs_ls(dirname, (argc>2)?1:0);
+
+    return(0);
+}
+
+int do_yrd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+    char *filename = argv[1];
+    printf ("Reading file %s ", filename);
+
+    cmd_yaffs_read_file(filename);
+
+    printf ("done\n");
+    return(0);
+}
+
+int do_ywr (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+    char *filename = argv[1];
+    ulong value = simple_strtoul(argv[2], NULL, 16);
+    ulong numValues = simple_strtoul(argv[3], NULL, 16);
+
+    printf ("Writing value (%x) %x times to %s... ", value, numValues, filename);
+
+    cmd_yaffs_write_file(filename,value,numValues);
+
+    printf ("done\n");
+    return(0);
+}
+
+int do_yrdm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+    char *filename = argv[1];
+    ulong addr = simple_strtoul(argv[2], NULL, 16);
+
+    cmd_yaffs_mread_file(filename, (char *)addr);
+
+    return(0);
+}
+
+int do_ywrm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+    char *filename = argv[1];
+    ulong addr = simple_strtoul(argv[2], NULL, 16);
+    ulong size = simple_strtoul(argv[3], NULL, 16);
+
+    cmd_yaffs_mwrite_file(filename, (char *)addr, size);
+
+    return(0);
+}
+
+int do_ymkdir (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+    char *dirname = argv[1];
+
+    cmd_yaffs_mkdir(dirname);
+
+    return(0);
+}
+
+int do_yrmdir (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+    char *dirname = argv[1];
+
+    cmd_yaffs_rmdir(dirname);
+
+    return(0);
+}
+
+int do_yrm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+    char *path = argv[1];
+
+    cmd_yaffs_rm(path);
+
+    return(0);
+}
+
+int do_ymv (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+    char *oldPath = argv[1];
+    char *newPath = argv[2];
+
+    cmd_yaffs_mv(newPath, oldPath);
+
+    return(0);
+}
+
+int do_ydump (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+    char *dirname = argv[1];
+    if (yaffs_DumpDevStruct(dirname) != 0)
+        printf("yaffs_DumpDevStruct returning error when dumping path: , %s\n", dirname);
+    return 0;
+}
+
+
+
+U_BOOT_CMD(
+    ymount, 3,  0,  do_ymount,
+    "ymount\t- mount yaffs\n",
+    "\n"
+);
+
+U_BOOT_CMD(
+    yumount, 3,  0,  do_yumount,
+    "yumount\t- unmount yaffs\n",
+    "\n"
+);
+
+U_BOOT_CMD(
+    yls,    4,  0,  do_yls,
+    "yls\t- yaffs ls\n",
+    "[-l] name\n"
+);
+
+U_BOOT_CMD(
+    yrd,    2,  0,  do_yrd,
+    "yrd\t- read file from yaffs\n",
+    "filename\n"
+);
+
+U_BOOT_CMD(
+    ywr,    4,  0,  do_ywr,
+    "ywr\t- write file to yaffs\n",
+    "filename value num_vlues\n"
+);
+
+U_BOOT_CMD(
+    yrdm,   3,  0,  do_yrdm,
+    "yrdm\t- read file to memory from yaffs\n",
+    "filename offset\n"
+);
+
+U_BOOT_CMD(
+    ywrm,   4,  0,  do_ywrm,
+    "ywrm\t- write file from memory to yaffs\n",
+    "filename offset size\n"
+);
+
+U_BOOT_CMD(
+    ymkdir, 2,  0,  do_ymkdir,
+    "ymkdir\t- YAFFS mkdir\n",
+    "dirname\n"
+);
+
+U_BOOT_CMD(
+    yrmdir, 2,  0,  do_yrmdir,
+    "yrmdir\t- YAFFS rmdir\n",
+    "dirname\n"
+);
+
+U_BOOT_CMD(
+    yrm,    2,  0,  do_yrm,
+    "yrm\t- YAFFS rm\n",
+    "path\n"
+);
+
+U_BOOT_CMD(
+    ymv,    4,  0,  do_ymv,
+    "ymv\t- YAFFS mv\n",
+    "oldPath newPath\n"
+);
+
+U_BOOT_CMD(
+    ydump,  2,  0,  do_ydump,
+    "ydump\t- YAFFS device struct\n",
+    "dirname\n"
+);
index 273d90e..48cf1d2 100644 (file)
@@ -22,7 +22,7 @@
 #
 #
 
-SUBDIRS        := jffs2 cramfs fdos fat reiserfs ext2
+SUBDIRS        := jffs2 cramfs fdos fat reiserfs ext2 yaffs2/direct
 
 $(obj).depend all:
        @for dir in $(SUBDIRS) ; do \
index 9635c7a..9acda79 100644 (file)
 #define new newHack
 #endif
 
-#if !(defined __KERNEL__) || (defined WIN32)
+/* XXX U-BOOT XXX */
+#if 1 /* !(defined __KERNEL__) || (defined WIN32) */
 
 /* User space defines */
 
+/* XXX U-BOOT XXX */
+#if 0
 typedef unsigned char __u8;
 typedef unsigned short __u16;
 typedef unsigned __u32;
+#endif
+
+#include <asm/types.h>
 
 /*
  * Simple doubly linked list implementation.
@@ -213,7 +219,12 @@ static __inline__ void list_splice(struct list_head *list,
 #define DT_WHT         14
 
 #ifndef WIN32
+/* XXX U-BOOT XXX */
+#if 0
 #include <sys/stat.h>
+#else
+#include "common.h"
+#endif
 #endif
 
 /*
index 6315117..0ee18e5 100644 (file)
 # $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
index be492b4..a9156ca 100644 (file)
@@ -15,6 +15,8 @@
 * Test code for the "direct" interface. 
 */
 
+/* XXX U-BOOT XXX */
+#include <common.h>
 
 #include <stdio.h>
 #include <string.h>
index e3cc30e..5779d7e 100644 (file)
@@ -16,6 +16,9 @@
  * This is only intended as test code to test persistence etc.
  */
 
+/* XXX U-BOOT XXX */
+#include <common.h>
+
 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;
 }
-
-
index 7a3b299..34a4e87 100644 (file)
@@ -16,6 +16,9 @@
  * This is only intended as test code to test persistence etc.
  */
 
+/* XXX U-BOOT XXX */
+#include <common.h>
+
 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;
 }
-
index 5178cb2..8d51dc6 100644 (file)
@@ -11,6 +11,8 @@
  * published by the Free Software Foundation.
  */
 
+/* XXX U-BOOT XXX */
+#include <common.h>
 
 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;
 }
-
index 245f9c9..122fb4c 100644 (file)
  * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
  */
  
+/* XXX U-BOOT XXX */
+#if 0
 #include <stdlib.h>
+#endif 
+
 void *yaffs_malloc(size_t size); 
 void yaffs_free(void *ptr);
  
index 6afee81..57f27ce 100644 (file)
@@ -18,6 +18,9 @@
  * Use this with dev->useNANDECC enabled, then ECC overheads are not required.
  */
 
+/* XXX U-BOOT XXX */
+#include <common.h>
+
 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;
 }
-
-
index 1ab053c..8161789 100644 (file)
@@ -15,6 +15,8 @@
  * yaffs_ramem2k.c: RAM emulation in-kernel for 2K pages (YAFFS2)
  */
 
+/* XXX U-BOOT XXX */
+#include <common.h>
 
 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
-
index b1d311e..a4a0924 100644 (file)
  * There is no need to redistribute this file.
  */
 
+/* XXX U-BOOT XXX */
+#include <common.h>
+
+#include <config.h>
+#include "nand.h"
 #include "yaffscfg.h"
 #include "yaffsfs.h"
+#include "yaffs_packedtags2.h"
+#include "yaffs_mtdif.h"
+#include "yaffs_mtdif2.h"
+#if 0
 #include <errno.h>
+#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);
+}
index 2a60dc1..6ae1696 100644 (file)
@@ -40,6 +40,7 @@ void yaffsfs_Unlock(void);
 __u32 yaffsfs_CurrentTime(void);
 
 void yaffsfs_SetError(int err);
+int yaffsfs_GetError(void);
 
 #endif
 
index 6d5f542..1daede1 100644 (file)
@@ -18,6 +18,9 @@
  * There is no need to redistribute this file.
  */
 
+/* XXX U-BOOT XXX */
+#include <common.h>
+
 #include "yaffscfg.h"
 #include "yaffsfs.h"
 #include "yaffs_fileem2k.h"
@@ -226,4 +229,3 @@ void SetCheckpointReservedBlocks(int n)
 {
        flashDev.nCheckpointReservedBlocks = n;
 }
-
index a8519c2..f62c952 100644 (file)
  * published by the Free Software Foundation.
  */
  
+/* XXX U-BOOT XXX */
+#include <common.h>
+#include <malloc.h>
+
 #include "yaffsfs.h"
 #include "yaffs_guts.h"
 #include "yaffscfg.h"
-#include <string.h> // for memset
 #include "yportenv.h"
 
+/* XXX U-BOOT XXX */
+#if 0
+#include <string.h> // 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;
 }
-
index 0c28205..adcc0b5 100644 (file)
 
 #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
index d3a811e..f97ba4b 100644 (file)
  * published by the Free Software Foundation.
  */
 
+/* XXX U-BOOT XXX */
+#include <common.h>
+#include <malloc.h>
+
 const char *yaffs_checkptrw_c_version =
     "$Id: yaffs_checkptrw.c,v 1.14 2007/05/15 20:07:40 charles Exp $";
 
@@ -399,6 +403,3 @@ int yaffs_CheckpointInvalidateStream(yaffs_Device *dev)
 
        return yaffs_CheckpointErase(dev);
 }
-
-
-
index d0b405f..a05a6b5 100644 (file)
@@ -28,6 +28,9 @@
  * this bytes influence on the line parity.
  */
 
+/* XXX U-BOOT XXX */
+#include <common.h>
+
 const char *yaffs_ecc_c_version =
     "$Id: yaffs_ecc.c,v 1.9 2007/02/14 01:09:06 wookey Exp $";
 
@@ -328,4 +331,3 @@ int yaffs_ECCCorrectOther(unsigned char *data, unsigned nBytes,
        return -1;
 
 }
-
index 134ed01..7dc62ef 100644 (file)
  * published by the Free Software Foundation.
  */
 
+/* XXX U-BOOT XXX */
+#include <common.h>
+
 const char *yaffs_guts_c_version =
     "$Id: yaffs_guts.c,v 1.52 2007/10/16 00:45:05 charles Exp $";
 
 #include "yportenv.h"
+#include "linux/stat.h"
 
 #include "yaffsinterface.h"
+#include "yaffsfs.h"
 #include "yaffs_guts.h"
 #include "yaffs_tagsvalidity.h"
 
@@ -31,6 +36,7 @@ const char *yaffs_guts_c_version =
 #include "yaffs_nand.h"
 #include "yaffs_packedtags2.h"
 
+#include "malloc.h"
 
 #ifdef CONFIG_YAFFS_WINCE
 void yfsd_LockYAFFS(BOOL fsLockOnly);
@@ -597,7 +603,6 @@ static int yaffs_VerifyTnodeWorker(yaffs_Object * obj, yaffs_Tnode * tn,
        int i;
        yaffs_Device *dev = obj->myDev;
        int ok = 1;
-       int nTnodeBytes = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8;
 
        if (tn) {
                if (level > 0) {
@@ -646,7 +651,6 @@ static void yaffs_VerifyFile(yaffs_Object *obj)
        __u32 lastChunk;
        __u32 x;
        __u32 i;
-       int ok;
        yaffs_Device *dev;
        yaffs_ExtendedTags tags;
        yaffs_Tnode *tn;
@@ -854,7 +858,10 @@ static void yaffs_VerifyObjects(yaffs_Device *dev)
  
 static Y_INLINE int yaffs_HashFunction(int n)
 {
-       n = abs(n);
+/* XXX U-BOOT XXX */
+       /*n = abs(n); */
+       if (n < 0)
+               n = -n;
        return (n % YAFFS_NOBJECT_BUCKETS);
 }
 
@@ -1954,6 +1961,8 @@ static void yaffs_FreeObject(yaffs_Object * tn)
 
        yaffs_Device *dev = tn->myDev;
 
+/* XXX U-BOOT XXX */
+#if 0
 #ifdef  __KERNEL__
        if (tn->myInode) {
                /* We're still hooked up to a cached inode.
@@ -1963,7 +1972,7 @@ static void yaffs_FreeObject(yaffs_Object * tn)
                return;
        }
 #endif
-
+#endif
        yaffs_UnhashObject(tn);
 
        /* Link into the free list. */
@@ -1972,6 +1981,8 @@ static void yaffs_FreeObject(yaffs_Object * tn)
        dev->nFreeObjects++;
 }
 
+/* XXX U-BOOT XXX */
+#if 0
 #ifdef __KERNEL__
 
 void yaffs_HandleDeferedFree(yaffs_Object * obj)
@@ -1981,6 +1992,7 @@ void yaffs_HandleDeferedFree(yaffs_Object * obj)
        }
 }
 
+#endif
 #endif
 
 static void yaffs_DeinitialiseObjects(yaffs_Device * dev)
@@ -2107,12 +2119,14 @@ yaffs_Object *yaffs_FindObjectByNumber(yaffs_Device * dev, __u32 number)
                if (i) {
                        in = list_entry(i, yaffs_Object, hashLink);
                        if (in->objectId == number) {
+/* XXX U-BOOT XXX */
+#if 0
 #ifdef __KERNEL__
                                /* Don't tell the VFS about this one if it is defered free */
                                if (in->deferedFree)
                                        return NULL;
 #endif
-
+#endif
                                return in;
                        }
                }
@@ -5085,11 +5099,14 @@ static int yaffs_UnlinkFile(yaffs_Object * in)
        int immediateDeletion = 0;
 
        if (1) {
+/* XXX U-BOOT XXX */
+#if 0
 #ifdef __KERNEL__
                if (!in->myInode) {
                        immediateDeletion = 1;
 
                }
+#endif
 #else
                if (in->inUse <= 0) {
                        immediateDeletion = 1;
index 87b539b..ecf701f 100644 (file)
@@ -446,9 +446,10 @@ struct yaffs_ObjectStruct {
        YCHAR shortName[YAFFS_SHORT_NAME_LENGTH + 1];
 #endif
 
-#ifndef __KERNEL__
+/* XXX U-BOOT XXX */
+/* #ifndef __KERNEL__ */
        __u32 inUse;
-#endif
+/* #endif */
 
 #ifdef CONFIG_YAFFS_WINCE
        __u32 win_ctime[2];
@@ -464,10 +465,10 @@ struct yaffs_ObjectStruct {
 
        __u32 yst_rdev;
 
-#ifdef __KERNEL__
+/* XXX U-BOOT XXX */
+/* #ifndef __KERNEL__ */
        struct inode *myInode;
-
-#endif
+/* #endif */
 
        yaffs_ObjectType variantType;
 
@@ -626,15 +627,18 @@ struct yaffs_DeviceStruct {
        __u32 chunkMask;
        
 
-#ifdef __KERNEL__
+/* XXX U-BOOT XXX */
+#if 0
+#ifndef __KERNEL__
 
        struct semaphore sem;   /* Semaphore for waiting on erasure.*/
        struct semaphore grossLock;     /* Gross locking semaphore */
+       void (*putSuperFunc) (struct super_block * sb);
+#endif
+#endif
        __u8 *spareBuffer;      /* For mtdif2 use. Don't know the size of the buffer 
                                 * at compile time so we have to allocate it.
                                 */
-       void (*putSuperFunc) (struct super_block * sb);
-#endif
 
        int isMounted;
        
@@ -883,10 +887,12 @@ yaffs_Object *yaffs_LostNFound(yaffs_Device * dev);
 void yfsd_WinFileTimeNow(__u32 target[2]);
 #endif
 
-#ifdef __KERNEL__
-
+/* XXX U-BOOT XXX */
+#if 0
+#ifndef __KERNEL__
 void yaffs_HandleDeferedFree(yaffs_Object * obj);
 #endif
+#endif
 
 /* Debug dump  */
 int yaffs_DumpObject(yaffs_Object * obj);
index 031827e..407ef2b 100644 (file)
@@ -11,6 +11,9 @@
  * published by the Free Software Foundation.
  */
 
+/* XXX U-BOOT XXX */
+#include <common.h>
+
 const char *yaffs_mtdif_c_version =
     "$Id: yaffs_mtdif.c,v 1.19 2007/02/14 01:09:06 wookey Exp $";
 
@@ -224,7 +227,10 @@ int nandmtd_EraseBlockInNAND(yaffs_Device * dev, int blockNumber)
 
        /* Todo finish off the ei if required */
 
+/* XXX U-BOOT XXX */
+#if 0
        sema_init(&dev->sem, 0);
+#endif
 
        retval = mtd->erase(mtd, &ei);
 
@@ -238,4 +244,3 @@ int nandmtd_InitialiseNAND(yaffs_Device * dev)
 {
        return YAFFS_OK;
 }
-
index 5a18725..cd2a2a1 100644 (file)
 
 /* mtd interface for YAFFS2 */
 
+/* XXX U-BOOT XXX */
+#include <common.h>
+#include "asm/errno.h"
+
 const char *yaffs_mtdif2_c_version =
     "$Id: yaffs_mtdif2.c,v 1.17 2007/02/14 01:09:06 wookey Exp $";
 
@@ -229,4 +233,3 @@ int nandmtd2_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo,
        else
                return YAFFS_FAIL;
 }
-
index 6a1585d..b201655 100644 (file)
@@ -11,6 +11,9 @@
  * published by the Free Software Foundation.
  */
  
+/* XXX U-BOOT XXX */
+#include <common.h>
+
 const char *yaffs_nand_c_version =
     "$Id: yaffs_nand.c,v 1.7 2007/02/14 01:09:06 wookey Exp $";
 
@@ -129,6 +132,3 @@ int yaffs_InitialiseNAND(struct yaffs_DeviceStruct *dev)
 {
        return dev->initialiseNAND(dev);
 }
-
-
index f480bf1..a149431 100644 (file)
@@ -11,6 +11,9 @@
  * published by the Free Software Foundation.
  */
 
+/* XXX U-BOOT XXX */
+#include <common.h>
+
 #include "yaffs_packedtags1.h"
 #include "yportenv.h"
 
index 6860876..467d5ac 100644 (file)
@@ -11,6 +11,9 @@
  * published by the Free Software Foundation.
  */
 
+/* XXX U-BOOT XXX */
+#include <common.h>
+
 #include "yaffs_packedtags2.h"
 #include "yportenv.h"
 #include "yaffs_tagsvalidity.h"
index 0429838..a74709f 100644 (file)
@@ -27,6 +27,9 @@
  * SUCH DAMAGE.
  */
 
+/* XXX U-BOOT XXX */
+#include <common.h>
+
 #include "yportenv.h"
 //#include <linux/string.h>
 
index 7622b1a..70a8a8c 100644 (file)
@@ -11,6 +11,9 @@
  * published by the Free Software Foundation.
  */
 
+/* XXX U-BOOT XXX */
+#include <common.h>
+
 #include "yaffs_guts.h"
 #include "yaffs_tagscompat.h"
 #include "yaffs_ecc.h"
index 9e0bd1c..f588d3a 100644 (file)
@@ -11,6 +11,9 @@
  * published by the Free Software Foundation.
  */
 
+/* XXX U-BOOT XXX */
+#include <common.h>
+
 #include "yaffs_tagsvalidity.h"
 
 void yaffs_InitialiseTags(yaffs_ExtendedTags * tags)
index 8b80c6d..b316b16 100644 (file)
 #ifndef __YPORTENV_H__
 #define __YPORTENV_H__
 
+/* XXX U-BOOT XXX */
+#ifndef CONFIG_YAFFS_DIRECT
+#define CONFIG_YAFFS_DIRECT
+#endif
+
 #if defined CONFIG_YAFFS_WINCE
 
 #include "ywinceenv.h"
 
-#elif  defined __KERNEL__
+/* XXX U-BOOT XXX */
+#elif  0 /* defined __KERNEL__ */
 
 #include "moduleconfig.h"