diff --git a/components/dfs/filesystems/jffs2/cyg/fileio/fileio.h b/components/dfs/filesystems/jffs2/cyg/fileio/fileio.h index 43ab1e803399fd34c9b53c16d3eac56cefd6017a..69c0783d182cc4e9460fd06ff038fa2980b3ea2f 100644 --- a/components/dfs/filesystems/jffs2/cyg/fileio/fileio.h +++ b/components/dfs/filesystems/jffs2/cyg/fileio/fileio.h @@ -438,7 +438,7 @@ __externC void cyg_selwakeup( struct CYG_SELINFO_TAG *sip ); // Provides the current time as a time_t timestamp for use in filesystem // data strucures. -__externC time_t cyg_timestamp(void); +__externC time_t jffs2_get_timestamp(void); //============================================================================= // Miscellaneous functions. diff --git a/components/dfs/filesystems/jffs2/dfs_jffs2.c b/components/dfs/filesystems/jffs2/dfs_jffs2.c index d84a69bf8831a05dbfec82b102b6a9d6915dc9a1..77c0a71f1d716b46858993f5fefbebdb3e4c2afd 100644 --- a/components/dfs/filesystems/jffs2/dfs_jffs2.c +++ b/components/dfs/filesystems/jffs2/dfs_jffs2.c @@ -12,6 +12,7 @@ * 2012-1-7 prife the first version */ #include +#include #include "cyg/infra/cyg_type.h" #include "cyg/fileio/fileio.h" @@ -22,13 +23,10 @@ #include #include "dfs_jffs2.h" +#include "jffs2_config.h" #include "porting.h" #include -#define FILE_PATH_MAX 256 /* the longest file path */ - -#define DEVICE_PART_MAX 1 /* the max partions on a nand deivce*/ - #if DEVICE_PART_MAX > 1 #error "support only one jffs2 partition on a flash device!" #endif @@ -36,7 +34,7 @@ /* make sure the following struct var had been initilased to 0! */ //fixme struct device_part { - rt_device_t dev; + struct rt_mtd_device *dev; struct cyg_mtab_entry * mte; }; static struct device_part device_partition[DEVICE_PART_MAX] = {0}; @@ -132,7 +130,6 @@ static int jffs2_result_to_dfs(int result) /* * RT-Thread DFS Interface for jffs2 */ - static int dfs_jffs2_mount(struct dfs_filesystem* fs, unsigned long rwflag, const void* data) @@ -164,7 +161,7 @@ static int dfs_jffs2_mount(struct dfs_filesystem* fs, */ mte->data = (CYG_ADDRWORD)fs->dev_id; - device_partition[index].dev = fs->dev_id; + device_partition[index].dev = RT_MTD_DEVICE(fs->dev_id); /* after jffs2_mount, mte->data will not be dev_id any more */ result = jffs2_mount(NULL, mte); if (result != 0) @@ -182,7 +179,7 @@ static int _find_fs(struct cyg_mtab_entry ** mte, rt_device_t dev_id) /* find device index */ for (index = 0; index < DEVICE_PART_MAX; index++) { - if (device_partition[index].dev == dev_id) + if (device_partition[index].dev == RT_MTD_DEVICE(dev_id)) { *mte = device_partition[index].mte; return 0; @@ -199,7 +196,7 @@ static int dfs_jffs2_unmount(struct dfs_filesystem* fs) /* find device index, then umount it */ for (index = 0; index < DEVICE_PART_MAX; index++) { - if (device_partition[index].dev == fs->dev_id) + if (device_partition[index].dev == RT_MTD_DEVICE(fs->dev_id)) { result = jffs2_umount(device_partition[index].mte); if (result) diff --git a/components/dfs/filesystems/jffs2/jffs2_config.h b/components/dfs/filesystems/jffs2/jffs2_config.h index 18b01b8ae5618cb22db52a2f988c0bb5e42edb45..4bec81902556458151e1d9188afe11814dc4446d 100644 --- a/components/dfs/filesystems/jffs2/jffs2_config.h +++ b/components/dfs/filesystems/jffs2/jffs2_config.h @@ -3,6 +3,10 @@ #define __ECOS /* must be defined */ +#define FILE_PATH_MAX 256 /* the longest file path */ + +#define DEVICE_PART_MAX 1 /* the max partions on a nand deivce*/ + #define CYGPKG_FS_JFFS2_RET_DIRENT_DTYPE /* should be enabled */ #if defined(CYGPKG_FS_JFFS2_RET_DIRENT_DTYPE) #define CYGPKG_FILEIO_DIRENT_DTYPE @@ -11,7 +15,7 @@ #define CYGOPT_FS_JFFS2_WRITE /* if not defined, jffs2 is read only*/ /* jffs2 debug output opion */ -#define CONFIG_JFFS2_FS_DEBUG 0 /* 1 or 2 */ +#define CONFIG_JFFS2_FS_DEBUG 0 /* 1 or 2 */ /* jffs2 gc thread section */ #define CYGOPT_FS_JFFS2_GCTHREAD diff --git a/components/dfs/filesystems/jffs2/kernel/linux/kernel.h b/components/dfs/filesystems/jffs2/kernel/linux/kernel.h index f215cd56856a820b6c710752371d355e8a572c82..09b8b4dde90be65ccdcca3538b9e9c9145c64589 100644 --- a/components/dfs/filesystems/jffs2/kernel/linux/kernel.h +++ b/components/dfs/filesystems/jffs2/kernel/linux/kernel.h @@ -10,7 +10,7 @@ #define PTR_ERR(err) ((unsigned long)(err)) #define IS_ERR(err) ((unsigned long)err > (unsigned long)-1000L) -#define CURRENT_TIME cyg_timestamp() +#define CURRENT_TIME jffs2_get_timestamp() #define KERN_EMERG "<0>" // system is unusable #define KERN_ALERT "<1>" // action must be taken immediately diff --git a/components/dfs/filesystems/jffs2/kernel/linux/slab.h b/components/dfs/filesystems/jffs2/kernel/linux/slab.h index c950123debc532136b5b161b0378d37b80973f28..f5c5745b0ee9802ec24761316ed14a9754db60f8 100644 --- a/components/dfs/filesystems/jffs2/kernel/linux/slab.h +++ b/components/dfs/filesystems/jffs2/kernel/linux/slab.h @@ -5,10 +5,10 @@ #include /* Don't ask. Linux headers are a mess. */ -#define kmalloc(x, y) malloc(x) -#define kfree(x) free(x) -#define vmalloc(x) malloc(x) -#define vfree(x) free(x) +#define kmalloc(x, y) rt_malloc(x) +#define kfree(x) rt_free(x) +#define vmalloc(x) rt_malloc(x) +#define vfree(x) rt_free(x) #endif /* __LINUX_SLAB_H__ */ diff --git a/components/dfs/filesystems/jffs2/pkgconf/infra.h b/components/dfs/filesystems/jffs2/pkgconf/infra.h deleted file mode 100644 index cb207080c54354f73c72ace713539e8d27dae613..0000000000000000000000000000000000000000 --- a/components/dfs/filesystems/jffs2/pkgconf/infra.h +++ /dev/null @@ -1,113 +0,0 @@ -#ifndef CYGONCE_PKGCONF_INFRA_H -# define CYGONCE_PKGCONF_INFRA_H - -//====================================================================== -// -// infra.h -// -// Host side implementation of the infrastructure configuration -// header. -// -//====================================================================== -// ####ECOSHOSTGPLCOPYRIGHTBEGIN#### -// ------------------------------------------- -// This file is part of the eCos host tools. -// Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc. -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 or (at your option) any -// later version. -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the -// Free Software Foundation, Inc., 51 Franklin Street, -// Fifth Floor, Boston, MA 02110-1301, USA. -// ------------------------------------------- -// ####ECOSHOSTGPLCOPYRIGHTEND#### -//====================================================================== -//#####DESCRIPTIONBEGIN#### -// -// Author(s): bartv -// Contact(s): bartv -// Date: 1998/07/13 -// Version: 0.01 -// -//####DESCRIPTIONEND#### -//====================================================================== - -// The purpose of this header file is to replicate appropriate -// functionality from the target-side header file . -// This header file is intended to contain configuration options -// related to the implementation of the infrastructure, as opposed -// to how that infrastructure gets used by other packages. A good -// example would be a configuration option to control the size -// of the circular trace buffer. -// -// On the host side these things are handled by autoconf, and in -// particular the configure.in script will offer command-line -// arguments allowing the relevant options to be controlled. -// The relevant information will end up in -# include - -// Some options should always be enabled in this header file. -#define CYGDBG_INFRA_DIAG_PRINTF_USE_VARARG -#define CYGDBG_INFRA_DEBUG_ASSERT_MESSAGE -#define CYGDBG_INFRA_DEBUG_TRACE_MESSAGE - -// Other options should be decided on a package by package basis, -// e.g. whether or not assertions are used. On the host side it is -// not appropriate to control these globally, instead the infrastructure -// always provides the necessary functionality and it is up to the -// other parts of the system to decide whether or not the facilities -// get used. - -// A third set of options deal with the environment, e.g. the sizes -// of various data types. autoconf macros take care of most of the -// work, but some translation is needed into eCos-style names to -// avoid namespace pollution. - -// Process the definitions of SIZEOF_INT_P and SIZEOF_LONG to work -// out a sensible data type for CYG_ADDRESS and CYG_ADDRWORD. - -#if (!defined(SIZEOF_INT_P) || !defined(SIZEOF_LONG)) -# error "Configure problem: data type sizes not set" -#endif - -#if (SIZEOF_INT_P == 4) - // The default, nothing needs to be done -#elif (SIZEOF_INT_P == 8) -# define cyg_haladdress cyg_halint64 -#else -# error "Only 32 and 64 bit pointers are supported" -#endif - -#if ((SIZEOF_INT_P == 4) && (SIZEOF_LONG == 4)) - // The default, nothing needs to be done -#elif ((SIZEOF_INT_P <= 8) && (SIZEOF_LONG <= 8)) - // cyg_halint64 will have been defined appropriately. -# define cyg_haladdrword cyg_halint64 -#else -# error "Only 32 and 64 bit machine word sizes are supported" -#endif - -// Any symbols defined in which have been processed -// here should no longer be of any interest, and in the interests of -// reducing name space pollution they get undef'ed here. - -// In addition there are two #define's in the config.h header file -// which are always present and which have names that are rather too -// generic. These get removed here as well. The version is worth -// preserving under a different name. -#undef SIZEOF_INT_P -#undef SIZEOF_LONG -#undef PACKAGE -#undef VERSION - -#endif // CYGONCE_PKGCONF_INFRA_H -// End of infra.h diff --git a/components/dfs/filesystems/jffs2/porting.c b/components/dfs/filesystems/jffs2/porting.c index 03963c8a8cf0afa1adf2897e12be7e67707a6eeb..c94072733a32cda5ffa41c512ac1da436455e3d8 100644 --- a/components/dfs/filesystems/jffs2/porting.c +++ b/components/dfs/filesystems/jffs2/porting.c @@ -3,7 +3,7 @@ #include "porting.h" -time_t cyg_timestamp(void) +time_t jffs2_get_timestamp(void) { return 0; } diff --git a/components/dfs/filesystems/jffs2/porting.h b/components/dfs/filesystems/jffs2/porting.h index 3a8f3a8719fccd28e3824cff2d9aacb4c8bb6eef..019812b86a93c71f61b3793841ccc8cdfbb4d566 100644 --- a/components/dfs/filesystems/jffs2/porting.h +++ b/components/dfs/filesystems/jffs2/porting.h @@ -42,8 +42,9 @@ extern cyg_fileops jffs2_fileops; extern cyg_fileops jffs2_dirops; extern struct cyg_fstab_entry jffs2_fste; -extern void jffs2_get_info_from_sb(void * data, struct jffs2_fs_info * info); -extern int jffs2_porting_stat(cyg_mtab_entry * mte, cyg_dir dir, const char *name, +time_t jffs2_get_timestamp(void); +void jffs2_get_info_from_sb(void * data, struct jffs2_fs_info * info); +int jffs2_porting_stat(cyg_mtab_entry * mte, cyg_dir dir, const char *name, void * stat_buf); #endif diff --git a/components/dfs/filesystems/jffs2/porting/flash_file.c b/components/dfs/filesystems/jffs2/porting/flash_file.c deleted file mode 100644 index ac35b29ab3fe69e4b5ad449db8a6a908cb0242dc..0000000000000000000000000000000000000000 --- a/components/dfs/filesystems/jffs2/porting/flash_file.c +++ /dev/null @@ -1,20 +0,0 @@ -#include -//#include -//#include -//#include -#include "flash.h" -int file_handle; -int FLASH_SIZE; -int flash_file_init(void) -{ -// file_handle = open(FILE_NAME, O_RDWR |O_BINARY| O_CREAT, S_IREAD | S_IWRITE); -// if(file_handle >= 0) { -// printf("read file ok\n"); -// } else { -// printf("read file error\n"); -// return -1; -// } -// FLASH_SIZE = lseek(file_handle, 0, SEEK_END) ;// / BLOCK_SIZE * BLOCK_SIZE; /*取整数*/ -// printf("the size of jffs bin file is %d", FLASH_SIZE); - return 0; -} diff --git a/components/dfs/filesystems/jffs2/porting/stub.c b/components/dfs/filesystems/jffs2/porting/stub.c deleted file mode 100644 index 010b311abbd8c22999f33d19487b7d44b26b7b27..0000000000000000000000000000000000000000 --- a/components/dfs/filesystems/jffs2/porting/stub.c +++ /dev/null @@ -1,89 +0,0 @@ -#include -#include "nodelist.h" -#include -#include -#include "compr.h" -//#include -#include - - - - -extern struct cyg_fstab_entry jffs2_fste; - -MTAB_ENTRY(jffs2_mte, - "/", - "jffs2", - NULL, - 0); - -#include "flash.h" -extern int file_handle; -extern int FLASH_SIZE; -extern int flash_file_init(void); - -extern int jffs2_mount(cyg_fstab_entry * fste, cyg_mtab_entry * mte); - - -extern int jffs2_open(cyg_mtab_entry * mte, cyg_dir dir, const char *name, - int mode, cyg_file * file); -extern int jffs2_fo_read(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio); - -char buffer[1024]; -int jffs2_main() -{ - int res; - cyg_file file; - struct CYG_UIO_TAG uio_s; - struct CYG_IOVEC_TAG iovec; -// res = flash_file_init(); - if (res != 0) - goto out; - - //mount file system - res = jffs2_mount(&jffs2_fste, &jffs2_mte); - if (res < 0) - { - printf("jffs2_mount error!\n"); - goto out; - } - printf("jffs2 mount ok!\n"); - - - //read a file or dirs "src/dfs.c" - //res = jffs2_open(&jffs2_mte, 0, "dfs_uffs.c", O_RDWR, &file); - //res = jffs2_open(&jffs2_mte, 0, "SConscript", O_RDWR, &file); -// res = jffs2_open(&jffs2_mte, 0, "filesystems/devfs/console.c" , O_RDWR, &file); - if (res != 0) - { - printf("jffs2_open file error: %d", res); - goto out; - } - - memset(buffer, 0, sizeof(buffer)); - uio_s.uio_iov = &iovec; - uio_s.uio_iov->iov_base = buffer; - uio_s.uio_iov->iov_len = 1024; - uio_s.uio_iovcnt = 1; //must be 1 - //uio_s.uio_offset //not used... - uio_s.uio_resid = uio_s.uio_iov->iov_len; //seem no use in ecos; - //uio_s.uio_segflg = UIO_USERSPACE; - //uio_s.uio_rw = ; - - res = jffs2_fo_read(&file, &uio_s); - if (res != 0) - { - printf("jffs2_fo_read file error: %d", res); - goto out; - } - printf("\n\n=====================================================================\n"); - printf("the uffs/dfs_uffs.c file content is:\n\n"); - printf("%s", buffer); - -out: -#if defined (MSVC) - printf("\n\npress any key to colose this console...\n"); - getch(); -#endif - return 0; -} diff --git a/components/dfs/filesystems/jffs2/porting/stub.h b/components/dfs/filesystems/jffs2/porting/stub.h deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/components/dfs/filesystems/jffs2/src/dir-ecos.c b/components/dfs/filesystems/jffs2/src/dir-ecos.c index 16b62cc15fd4adad5dc3e0508a9f07f4bb9e60a7..b52b89928fba1536e11216be01660f3ba5ad4256 100644 --- a/components/dfs/filesystems/jffs2/src/dir-ecos.c +++ b/components/dfs/filesystems/jffs2/src/dir-ecos.c @@ -21,7 +21,6 @@ struct _inode *jffs2_lookup(struct _inode *dir_i, const unsigned char *d_name, int namelen) { struct jffs2_inode_info *dir_f; - struct jffs2_sb_info *c; struct jffs2_full_dirent *fd = NULL, *fd_list; uint32_t ino = 0; uint32_t hash = full_name_hash(d_name, namelen); @@ -30,7 +29,6 @@ struct _inode *jffs2_lookup(struct _inode *dir_i, const unsigned char *d_name, i D1(printk("jffs2_lookup()\n")); dir_f = JFFS2_INODE_INFO(dir_i); - c = JFFS2_SB_INFO(dir_i->i_sb); down(&dir_f->sem); @@ -242,7 +240,7 @@ int jffs2_mkdir (struct _inode *dir_i, const unsigned char *d_name, int mode) rd->pino = cpu_to_je32(dir_i->i_ino); rd->version = cpu_to_je32(++dir_f->highest_version); rd->ino = cpu_to_je32(inode->i_ino); - rd->mctime = cpu_to_je32(cyg_timestamp()); + rd->mctime = cpu_to_je32(jffs2_get_timestamp()); rd->nsize = namelen; rd->type = DT_DIR; rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); diff --git a/components/dfs/filesystems/jffs2/src/flashio.c b/components/dfs/filesystems/jffs2/src/flashio.c index fb0d967983f73ee4dc473f2d868986381a0ca772..88b87891f7e3b1b920f494772b2cc89e28d4813b 100644 --- a/components/dfs/filesystems/jffs2/src/flashio.c +++ b/components/dfs/filesystems/jffs2/src/flashio.c @@ -14,95 +14,75 @@ #include #include "nodelist.h" +#include -//#include mod by prife -//#include -//#include +#define PAGE_SIZE 1024 -// #include -// #include +int jffs2_flash_read(struct jffs2_sb_info * c, cyg_uint32 offset, + const size_t size, + size_t * return_size, + unsigned char *buffer) +{ + struct super_block *sb = OFNI_BS_2SFFJ(c); + + *return_size = rt_mtd_read(RT_MTD_DEVICE(sb->s_dev), offset, buffer, size); -//#include -//#include -// #include -//#include + //rt_kprintf("fread: offset %d, size %d, ret size %d\n", + // offset, size, *return_size); -#include + return ENOERR; +} -cyg_bool jffs2_flash_read(struct jffs2_sb_info * c, - cyg_uint32 read_buffer_offset, const size_t size, - size_t * return_size, unsigned char *write_buffer) +int jffs2_flash_write(struct jffs2_sb_info * c, + cyg_uint32 offset, const size_t size, + size_t * return_size, unsigned char *buffer) { - cyg_uint32 len; struct super_block *sb = OFNI_BS_2SFFJ(c); - D2(printf("FLASH READ\n")); - D2(printf("read address = %x\n", CYGNUM_FS_JFFS2_BASE_ADDRESS + read_buffer_offset)); - D2(printf("write address = %x\n", write_buffer)); - D2(printf("size = %x\n", size)); -// err = cyg_io_bread(sb->s_dev, write_buffer, &len, read_buffer_offset); - len = rt_device_read(sb->s_dev, read_buffer_offset, write_buffer, size); + *return_size = rt_mtd_write(RT_MTD_DEVICE(sb->s_dev), offset, buffer, size); -// lseek(file_handle, read_buffer_offset, SEEK_SET); -// len = read(file_handle, write_buffer, size); - if (len != size) - return -EIO; + rt_kprintf("fwrite: offset %d, size %d, ret size %d\n", + offset, size, *return_size); - *return_size = (size_t) len; return ENOERR; } -cyg_bool jffs2_flash_write(struct jffs2_sb_info * c, - cyg_uint32 write_buffer_offset, const size_t size, - size_t * return_size, unsigned char *read_buffer) +int jffs2_flash_erase(struct jffs2_sb_info * c, + struct jffs2_eraseblock * jeb) { - cyg_uint32 len; + rt_err_t result; struct super_block *sb = OFNI_BS_2SFFJ(c); - D2(printf("FLASH WRITE ENABLED!!!\n")); - D2(printf("write address = %x\n", CYGNUM_FS_JFFS2_BASE_ADDRESS + write_buffer_offset)); - D2(printf("read address = %x\n", read_buffer)); - D2(printf("size = %x\n", size)); + rt_kprintf("erase: offset %d\n", jeb->offset); - len = rt_device_write(sb->s_dev, write_buffer_offset, read_buffer, size); - *return_size = (size_t) len; - if (len != size) + result = rt_mtd_erase_block(RT_MTD_DEVICE(sb->s_dev), jeb->offset); + if (result != RT_EOK) return -EIO; - return ENOERR; - //return ((err == ENOERR) ? ENOERR : -EIO); - - // Cyg_ErrNo err; - // cyg_uint32 len; - // struct super_block *sb = OFNI_BS_2SFFJ(c); - // lseek(file_handle, write_buffer_offset, SEEK_SET); - // len = write(file_handle, read_buffer, size); - // if (len < 0) - // return -EIO; - - // *return_size = (size_t) len; - // return ENOERR; + return ENOERR; } -int -jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct iovec *vecs, - unsigned long count, loff_t to, size_t * retlen) +int jffs2_flash_direct_writev(struct jffs2_sb_info *c, + const struct iovec *vecs, unsigned long count, loff_t to, + size_t * retlen) { unsigned long i; size_t totlen = 0, thislen; int ret = 0; - for (i = 0; i < count; i++) { + for (i = 0; i < count; i++) + { // writes need to be aligned but the data we're passed may not be // Observation suggests most unaligned writes are small, so we // optimize for that case. - if (((vecs[i].iov_len & (sizeof (int) - 1))) || - (((unsigned long) vecs[i]. - iov_base & (sizeof (unsigned long) - 1)))) { + if (((vecs[i].iov_len & (sizeof(int) - 1))) || + (((unsigned long) vecs[i].iov_base & (sizeof(unsigned long) - 1)))) + { // are there iov's after this one? Or is it so much we'd need // to do multiple writes anyway? - if ((i + 1) < count || vecs[i].iov_len > 256) { + if ((i + 1) < count || vecs[i].iov_len > 256) + { // cop out and malloc unsigned long j; ssize_t sizetomalloc = 0, totvecsize = 0; @@ -112,91 +92,62 @@ jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct iovec *vecs, totvecsize += vecs[j].iov_len; // pad up in case unaligned - sizetomalloc = totvecsize + sizeof (int) - 1; - sizetomalloc &= ~(sizeof (int) - 1); - cbuf = (char *) malloc(sizetomalloc); + sizetomalloc = totvecsize + sizeof(int) - 1; + sizetomalloc &= ~(sizeof(int) - 1); + cbuf = (char *) rt_malloc(sizetomalloc); // malloc returns aligned memory - if (!cbuf) { + if (!cbuf) + { ret = -ENOMEM; goto writev_out; } cbufptr = cbuf; - for (j = i; j < count; j++) { - memcpy(cbufptr, vecs[j].iov_base, - vecs[j].iov_len); + for (j = i; j < count; j++) + { + memcpy(cbufptr, vecs[j].iov_base, vecs[j].iov_len); cbufptr += vecs[j].iov_len; } - ret = - jffs2_flash_write(c, to, sizetomalloc, - &thislen, (unsigned char *)cbuf); - if (thislen > totvecsize) // in case it was aligned up + rt_kprintf("direct_write: offset %d, size %d\n", to, sizetomalloc); + ret = jffs2_flash_write(c, to, sizetomalloc, &thislen, + (unsigned char *) cbuf); + if (thislen > totvecsize) // in case it was aligned up thislen = totvecsize; totlen += thislen; - free(cbuf); + rt_free(cbuf); goto writev_out; - } else { + } + else + { // otherwise optimize for the common case - int buf[256 / sizeof (int)]; // int, so int aligned + int buf[256/sizeof(int)]; // int, so int aligned size_t lentowrite; lentowrite = vecs[i].iov_len; // pad up in case its unaligned - lentowrite += sizeof (int) - 1; - lentowrite &= ~(sizeof (int) - 1); + lentowrite += sizeof(int) - 1; + lentowrite &= ~(sizeof(int) - 1); memcpy(buf, vecs[i].iov_base, lentowrite); - ret = - jffs2_flash_write(c, to, lentowrite, - &thislen, (unsigned char *) &buf); + rt_kprintf("direct_write: offset %d, size %d\n", to, lentowrite); + ret = jffs2_flash_write(c, to, lentowrite, &thislen, + (unsigned char *) &buf); if (thislen > vecs[i].iov_len) thislen = vecs[i].iov_len; - } // else - } else - ret = - jffs2_flash_write(c, to, vecs[i].iov_len, &thislen, - vecs[i].iov_base); + } + } + else + { + rt_kprintf("direct_writev: offset %d, size %d\n", to, vecs[i].iov_len); + ret = jffs2_flash_write(c, to, vecs[i].iov_len, &thislen, + vecs[i].iov_base); + } totlen += thislen; - if (ret || thislen != vecs[i].iov_len) - break; + if (ret || thislen != vecs[i].iov_len) break; to += vecs[i].iov_len; } - writev_out: - if (retlen) - *retlen = totlen; - - return ret; -} -cyg_bool jffs2_flash_erase(struct jffs2_sb_info * c, - struct jffs2_eraseblock * jeb) -{ - int res; - struct super_block *sb = OFNI_BS_2SFFJ(c); +writev_out: + if (retlen) *retlen = totlen; - D2(printf("FLASH ERASE ENABLED!!!\n")); - D2(printf("erase address = %x\n", CYGNUM_FS_JFFS2_BASE_ADDRESS + jeb->offset)); - D2(printf("size = %x\n", c->sector_size)); - - // err = cyg_io_get_config(sb->s_dev, CYG_IO_GET_CONFIG_FLASH_ERASE, - // &e, &len); - - res = rt_device_control(sb->s_dev, RT_DEVICE_CTRL_BLK_ERASE, (void *)(jeb->offset)); - return ((res == RT_EOK) ? ENOERR : -EIO); - - //这里 jeb数据结构 - // int i; - // char block_buf[4096]; - // cyg_uint32 len; - // struct super_block *sb = OFNI_BS_2SFFJ(c); - - // lseek(file_handle, jeb->offset, SEEK_SET); - - // c->sector_size 是sector大小还是block大小呢?? //fixme - // 这里的jeb->offset 是字节为偏移地址吗??? //fixme - // memset(&block_buf, 0xff, sizeof(block_buf) ); - // for(i=0; i<(BLOCK_SIZE/4096); i++) - // write(file_handle, &block_buf, sizeof(block_buf)); - - // return ENOERR; + return ret; } - diff --git a/components/dfs/filesystems/jffs2/src/fs-ecos.c b/components/dfs/filesystems/jffs2/src/fs-ecos.c index d40955a670361a7bbbedef82fe00d242d31d42b9..31047ec0d47566adc90c1eaa50c52658788be02d 100644 --- a/components/dfs/filesystems/jffs2/src/fs-ecos.c +++ b/components/dfs/filesystems/jffs2/src/fs-ecos.c @@ -18,18 +18,12 @@ #include #include #include "compr.h" -//#include //prife #include -//#include //prife -#if (__GNUC__ == 3) && (__GNUC_MINOR__ == 2) && \ - (defined (__arm__) || defined (_mips)) -#error This compiler is known to be broken. Please see: -#error "http://ecos.sourceware.org/ml/ecos-patches/2003-08/msg00006.html" -#endif +#include //-------------------------------------------- -cyg_mtab_entry *cyg_cdir_mtab_entry = NULL; // prife add +cyg_mtab_entry *cyg_cdir_mtab_entry = NULL; cyg_dir cyg_cdir_dir = CYG_DIR_NULL; //========================================================================== // Default functions @@ -219,7 +213,7 @@ static void icache_evict(struct _inode *root_i, struct _inode *i) this->i_cache_prev->i_cache_next = this->i_cache_next; jffs2_clear_inode(this); memset(this, 0x5a, sizeof(*this)); - free(this); + rt_free(this); if (parent && parent != this) { parent->i_count--; this = root_i; @@ -453,59 +447,24 @@ static int jffs2_pathconf(struct _inode *node, struct cyg_pathconf_info *info) // filesystem. static int jffs2_read_super(struct super_block *sb) { -// struct jffs2_sb_info *c; -// Cyg_ErrNo err; -// cyg_uint32 len; -// cyg_io_flash_getconfig_devsize_t ds; -// cyg_io_flash_getconfig_blocksize_t bs; -// -// D1(printk(KERN_DEBUG "jffs2: read_super\n")); -// -// c = JFFS2_SB_INFO(sb); -// -// len = sizeof (ds); -// err = cyg_io_get_config(sb->s_dev, -// CYG_IO_GET_CONFIG_FLASH_DEVSIZE, &ds, &len); -// if (err != ENOERR) { -// D1(printf -// ("jffs2: cyg_io_get_config failed to get dev size: %d\n", -// err)); -// return err; -// } -// len = sizeof (bs); -// bs.offset = 0; -// err = cyg_io_get_config(sb->s_dev, -// CYG_IO_GET_CONFIG_FLASH_BLOCKSIZE, &bs, &len); -// if (err != ENOERR) { -// D1(printf -// ("jffs2: cyg_io_get_config failed to get block size: %d\n", -// err)); -// return err; -// } -// -// c->sector_size = bs.block_size; -// c->flash_size = ds.dev_size; -// c->cleanmarker_size = sizeof(struct jffs2_unknown_node); Cyg_ErrNo err; struct jffs2_sb_info *c; - struct rt_device_blk_geometry geometry; //fixme need a new struct type! + struct rt_mtd_device *device; c = JFFS2_SB_INFO(sb); + device = RT_MTD_DEVICE(sb->s_dev); -//init some block + /* initialize mutex lock */ init_MUTEX(&c->alloc_sem); init_MUTEX(&c->erase_free_sem); - - rt_memset(&geometry, 0, sizeof(geometry)); - rt_device_control(sb->s_dev, RT_DEVICE_CTRL_BLK_GETGEOME, &geometry); - - c->sector_size = geometry.block_size; - c->flash_size = (geometry.sector_count) * (geometry.bytes_per_sector); + + /* sector size is the erase block size */ + c->sector_size = device->block_size; + c->flash_size = (device->block_end - device->block_start) * device->block_size; c->cleanmarker_size = sizeof(struct jffs2_unknown_node); err = jffs2_do_mount_fs(c); - if (err) - return -err; + if (err) return -err; D1(printk(KERN_DEBUG "jffs2_read_super(): Getting root inode\n")); sb->s_root = jffs2_iget(sb, 1); @@ -520,7 +479,7 @@ static int jffs2_read_super(struct super_block *sb) out_nodes: jffs2_free_ino_caches(c); jffs2_free_raw_node_refs(c); - free(c->blocks); + rt_free(c->blocks); return err; } @@ -558,7 +517,7 @@ int jffs2_mount(cyg_fstab_entry * fste, cyg_mtab_entry * mte) jffs2_sb = NULL; t = (cyg_io_handle_t)mte->data; //get from dfs_jffs2; if (jffs2_sb == NULL) { - jffs2_sb = malloc(sizeof (struct super_block)); + jffs2_sb = rt_malloc(sizeof (struct super_block)); if (jffs2_sb == NULL) return ENOMEM; @@ -567,9 +526,9 @@ int jffs2_mount(cyg_fstab_entry * fste, cyg_mtab_entry * mte) memset(jffs2_sb, 0, sizeof (struct super_block)); jffs2_sb->s_dev = t; - c->inocache_list = malloc(sizeof(struct jffs2_inode_cache *) * INOCACHE_HASHSIZE); + c->inocache_list = rt_malloc(sizeof(struct jffs2_inode_cache *) * INOCACHE_HASHSIZE); if (!c->inocache_list) { - free(jffs2_sb); + rt_free(jffs2_sb); return ENOMEM; } memset(c->inocache_list, 0, sizeof(struct jffs2_inode_cache *) * INOCACHE_HASHSIZE); @@ -586,8 +545,8 @@ int jffs2_mount(cyg_fstab_entry * fste, cyg_mtab_entry * mte) jffs2_compressors_exit(); } - free(jffs2_sb); - free(c->inocache_list); + rt_free(jffs2_sb); + rt_free(c->inocache_list); return err; } @@ -677,16 +636,16 @@ static int jffs2_umount(cyg_mtab_entry * mte) jffs2_free_full_dirent(fd); } - free(root); + rt_free(root); //Clear root inode //root_i = NULL; // Clean up the super block and root inode jffs2_free_ino_caches(c); jffs2_free_raw_node_refs(c); - free(c->blocks); - free(c->inocache_list); - free(jffs2_sb); + rt_free(c->blocks); + rt_free(c->inocache_list); + rt_free(jffs2_sb); // Clear superblock & root pointer mte->root = CYG_DIR_NULL; mte->data = 0; @@ -986,7 +945,7 @@ static int jffs2_ops_rename(cyg_mtab_entry * mte, cyg_dir dir1, if (!err) ds1.dir->i_ctime = ds1.dir->i_mtime = - ds2.dir->i_ctime = ds2.dir->i_mtime = cyg_timestamp(); + ds2.dir->i_ctime = ds2.dir->i_mtime = jffs2_get_timestamp(); out: jffs2_iput(ds1.dir); if (S_ISDIR(ds1.node->i_mode)) { @@ -1066,7 +1025,7 @@ static int jffs2_ops_link(cyg_mtab_entry * mte, cyg_dir dir1, const char *name1, if (err == 0) ds1.node->i_ctime = - ds2.dir->i_ctime = ds2.dir->i_mtime = cyg_timestamp(); + ds2.dir->i_ctime = ds2.dir->i_mtime = jffs2_get_timestamp(); jffs2_iput(ds1.dir); jffs2_iput(ds1.node); @@ -1294,7 +1253,7 @@ int jffs2_fo_read(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio) // We successfully read some data, update the node's access time // and update the file offset and transfer residue. - inode->i_atime = cyg_timestamp(); + inode->i_atime = jffs2_get_timestamp(); uio->uio_resid = resid; fp->f_offset = pos; @@ -1403,7 +1362,7 @@ static int jffs2_truncate_file (struct _inode *inode) ri->mode = cpu_to_jemode(inode->i_mode); ri->isize = cpu_to_je32(0); ri->atime = cpu_to_je32(inode->i_atime); - ri->mtime = cpu_to_je32(cyg_timestamp()); + ri->mtime = cpu_to_je32(jffs2_get_timestamp()); ri->offset = cpu_to_je32(0); ri->csize = ri->dsize = cpu_to_je32(0); ri->compr = JFFS2_COMPR_NONE; @@ -1419,7 +1378,7 @@ static int jffs2_truncate_file (struct _inode *inode) } /* It worked. Update the inode */ - inode->i_mtime = cyg_timestamp(); + inode->i_mtime = jffs2_get_timestamp(); inode->i_size = 0; old_metadata = f->metadata; jffs2_truncate_fragtree (c, &f->fragtree, 0); @@ -1460,7 +1419,7 @@ static int jffs2_fo_write(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio) ri.mode = cpu_to_jemode(inode->i_mode); ri.uid = cpu_to_je16(inode->i_uid); ri.gid = cpu_to_je16(inode->i_gid); - ri.atime = ri.ctime = ri.mtime = cpu_to_je32(cyg_timestamp()); + ri.atime = ri.ctime = ri.mtime = cpu_to_je32(jffs2_get_timestamp()); if (pos > inode->i_size) { int err; @@ -1682,7 +1641,6 @@ static int jffs2_fo_dirread(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio) int nlen = sizeof (ent->d_name) - 1; off_t len = uio->uio_iov[0].iov_len; struct jffs2_inode_info *f; - struct jffs2_sb_info *c; struct _inode *inode = d_inode; struct jffs2_full_dirent *fd; unsigned long offset, curofs; @@ -1695,7 +1653,6 @@ static int jffs2_fo_dirread(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio) (KERN_DEBUG "jffs2_readdir() for dir_i #%lu\n", d_inode->i_ino)); f = JFFS2_INODE_INFO(inode); - c = JFFS2_SB_INFO(inode->i_sb); offset = fp->f_offset; @@ -1823,19 +1780,14 @@ void jffs2_gc_release_page(struct jffs2_sb_info *c, static struct _inode *new_inode(struct super_block *sb) { - - // Only called in write.c jffs2_new_inode - // Always adds itself to inode cache - struct _inode *inode; struct _inode *cached_inode; - inode = malloc(sizeof (struct _inode)); + inode = rt_malloc(sizeof (struct _inode)); if (inode == NULL) return 0; - D2(printf - ("malloc new_inode %x ####################################\n", + D2(printf("malloc new_inode %x ####################################\n", inode)); memset(inode, 0, sizeof (struct _inode)); @@ -1945,7 +1897,7 @@ void jffs2_iput(struct _inode *i) parent = i->i_parent; jffs2_clear_inode(i); memset(i, 0x5a, sizeof(*i)); - free(i); + rt_free(i); if (parent && parent != i) { i = parent; @@ -2021,7 +1973,7 @@ struct _inode *jffs2_new_inode (struct _inode *dir_i, int mode, struct jffs2_raw up(&(f->sem)); jffs2_clear_inode(inode); memset(inode, 0x6a, sizeof(*inode)); - free(inode); + rt_free(inode); return ERR_PTR(ret); } inode->i_nlink = 1; @@ -2029,7 +1981,7 @@ struct _inode *jffs2_new_inode (struct _inode *dir_i, int mode, struct jffs2_raw inode->i_mode = jemode_to_cpu(ri->mode); inode->i_gid = je16_to_cpu(ri->gid); inode->i_uid = je16_to_cpu(ri->uid); - inode->i_atime = inode->i_ctime = inode->i_mtime = cyg_timestamp(); + inode->i_atime = inode->i_ctime = inode->i_mtime = jffs2_get_timestamp(); ri->atime = ri->mtime = ri->ctime = cpu_to_je32(inode->i_mtime); inode->i_size = 0; diff --git a/components/dfs/filesystems/jffs2/src/malloc-ecos.c b/components/dfs/filesystems/jffs2/src/malloc-ecos.c index a06cf5f16dbe7fa0e367911f65bd688c738a1ea6..df6e3c0f5d92aff0b10606a69a7bda8594b3dc1b 100644 --- a/components/dfs/filesystems/jffs2/src/malloc-ecos.c +++ b/components/dfs/filesystems/jffs2/src/malloc-ecos.c @@ -21,62 +21,62 @@ struct jffs2_full_dirent *jffs2_alloc_full_dirent(int namesize) { - return malloc(sizeof(struct jffs2_full_dirent) + namesize); + return rt_malloc(sizeof(struct jffs2_full_dirent) + namesize); } void jffs2_free_full_dirent(struct jffs2_full_dirent *x) { - free(x); + rt_free(x); } struct jffs2_full_dnode *jffs2_alloc_full_dnode(void) { - return malloc(sizeof(struct jffs2_full_dnode)); + return rt_malloc(sizeof(struct jffs2_full_dnode)); } void jffs2_free_full_dnode(struct jffs2_full_dnode *x) { - free(x); + rt_free(x); } struct jffs2_raw_dirent *jffs2_alloc_raw_dirent(void) { - return malloc(sizeof(struct jffs2_raw_dirent)); + return rt_malloc(sizeof(struct jffs2_raw_dirent)); } void jffs2_free_raw_dirent(struct jffs2_raw_dirent *x) { - free(x); + rt_free(x); } struct jffs2_raw_inode *jffs2_alloc_raw_inode(void) { - return malloc(sizeof(struct jffs2_raw_inode)); + return rt_malloc(sizeof(struct jffs2_raw_inode)); } void jffs2_free_raw_inode(struct jffs2_raw_inode *x) { - free(x); + rt_free(x); } struct jffs2_tmp_dnode_info *jffs2_alloc_tmp_dnode_info(void) { - return malloc(sizeof(struct jffs2_tmp_dnode_info)); + return rt_malloc(sizeof(struct jffs2_tmp_dnode_info)); } void jffs2_free_tmp_dnode_info(struct jffs2_tmp_dnode_info *x) { - free(x); + rt_free(x); } struct jffs2_node_frag *jffs2_alloc_node_frag(void) { - return malloc(sizeof(struct jffs2_node_frag)); + return rt_malloc(sizeof(struct jffs2_node_frag)); } void jffs2_free_node_frag(struct jffs2_node_frag *x) { - free(x); + rt_free(x); } #if CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE == 0 @@ -92,12 +92,12 @@ void jffs2_destroy_slab_caches(void) struct jffs2_raw_node_ref *jffs2_alloc_raw_node_ref(void) { - return malloc(sizeof(struct jffs2_raw_node_ref)); + return rt_malloc(sizeof(struct jffs2_raw_node_ref)); } void jffs2_free_raw_node_ref(struct jffs2_raw_node_ref *x) { - free(x); + rt_free(x); } #else // CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE == 0 @@ -150,7 +150,7 @@ void jffs2_free_raw_node_ref(struct jffs2_raw_node_ref *x) struct jffs2_inode_cache *jffs2_alloc_inode_cache(void) { - struct jffs2_inode_cache *ret = malloc(sizeof(struct jffs2_inode_cache)); + struct jffs2_inode_cache *ret = rt_malloc(sizeof(struct jffs2_inode_cache)); D1(printk(KERN_DEBUG "Allocated inocache at %p\n", ret)); return ret; } @@ -158,6 +158,6 @@ struct jffs2_inode_cache *jffs2_alloc_inode_cache(void) void jffs2_free_inode_cache(struct jffs2_inode_cache *x) { D1(printk(KERN_DEBUG "Freeing inocache at %p\n", x)); - free(x); + rt_free(x); } diff --git a/components/dfs/filesystems/jffs2/src/os-ecos.h b/components/dfs/filesystems/jffs2/src/os-ecos.h index 0a04233126ac67307964ecaa7539cad2b0c0caaf..77b9632c14fdd5e55077af0a3f22374abf7bb52d 100644 --- a/components/dfs/filesystems/jffs2/src/os-ecos.h +++ b/components/dfs/filesystems/jffs2/src/os-ecos.h @@ -15,8 +15,6 @@ #define __JFFS2_OS_ECOS_H__ #include "jffs2_config.h" #include -#define malloc rt_malloc -#define free rt_free #define printf rt_kprintf //#include @@ -117,7 +115,7 @@ static inline unsigned int full_name_hash(const unsigned char * name, unsigned i #define JFFS2_F_I_RDEV_MIN(f) ((OFNI_EDONI_2SFFJ(f)->i_rdev)&0xff) #define JFFS2_F_I_RDEV_MAJ(f) ((OFNI_EDONI_2SFFJ(f)->i_rdev)>>8) -#define get_seconds cyg_timestamp +#define get_seconds jffs2_get_timestamp struct _inode { cyg_uint32 i_ino; @@ -215,13 +213,13 @@ uint32_t jffs2_to_os_mode (uint32_t jmode); /* flashio.c */ -cyg_bool jffs2_flash_read(struct jffs2_sb_info *c, cyg_uint32 read_buffer_offset, +int jffs2_flash_read(struct jffs2_sb_info *c, cyg_uint32 read_buffer_offset, const size_t size, size_t * return_size, unsigned char * write_buffer); -cyg_bool jffs2_flash_write(struct jffs2_sb_info *c, cyg_uint32 write_buffer_offset, +int jffs2_flash_write(struct jffs2_sb_info *c, cyg_uint32 write_buffer_offset, const size_t size, size_t * return_size, unsigned char * read_buffer); int jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct iovec *vecs, unsigned long count, loff_t to, size_t *retlen); -cyg_bool jffs2_flash_erase(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb); +int jffs2_flash_erase(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb); // dir-ecos.c struct _inode *jffs2_lookup(struct _inode *dir_i, const unsigned char *name, int namelen); diff --git a/components/dfs/filesystems/jffs2/src/os-rtthread.h b/components/dfs/filesystems/jffs2/src/os-rtthread.h index e1c4d55a5f9880fd16f98deeb27495aa1e768267..c42e12ab6918adb1422fa180fb393e6598c9af50 100644 --- a/components/dfs/filesystems/jffs2/src/os-rtthread.h +++ b/components/dfs/filesystems/jffs2/src/os-rtthread.h @@ -15,8 +15,6 @@ #define __JFFS2_OS_RTTHREAD_H__ #include "jffs2_config.h" #include -#define free rt_free -#define printf rt_kprintf #define printf rt_kprintf //#include @@ -115,7 +113,7 @@ static inline unsigned int full_name_hash(const unsigned char * name, unsigned i #define JFFS2_F_I_RDEV_MIN(f) ((OFNI_EDONI_2SFFJ(f)->i_rdev)&0xff) #define JFFS2_F_I_RDEV_MAJ(f) ((OFNI_EDONI_2SFFJ(f)->i_rdev)>>8) -#define get_seconds cyg_timestamp +#define get_seconds jffs2_get_timestamp struct _inode { cyg_uint32 i_ino; @@ -213,13 +211,13 @@ uint32_t jffs2_to_os_mode (uint32_t jmode); /* flashio.c */ -cyg_bool jffs2_flash_read(struct jffs2_sb_info *c, cyg_uint32 read_buffer_offset, +int jffs2_flash_read(struct jffs2_sb_info *c, cyg_uint32 read_buffer_offset, const size_t size, size_t * return_size, unsigned char * write_buffer); -cyg_bool jffs2_flash_write(struct jffs2_sb_info *c, cyg_uint32 write_buffer_offset, +int jffs2_flash_write(struct jffs2_sb_info *c, cyg_uint32 write_buffer_offset, const size_t size, size_t * return_size, unsigned char * read_buffer); int jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct iovec *vecs, unsigned long count, loff_t to, size_t *retlen); -cyg_bool jffs2_flash_erase(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb); +int jffs2_flash_erase(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb); // dir-ecos.c struct _inode *jffs2_lookup(struct _inode *dir_i, const unsigned char *name, int namelen);