diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2013-09-12 16:46:51 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2013-09-19 13:16:06 +0200 |
commit | 672038b174456ff89d46a5f16ecac90f43e364f3 (patch) | |
tree | 3970a083f83ee0d4e6af96db6f894710c36b837d /cpukit/libfs/src/jffs2/src/flashio.c | |
parent | JFFS2: Import from Linux (diff) | |
download | rtems-672038b174456ff89d46a5f16ecac90f43e364f3.tar.bz2 |
JFFS2: Import from eCos
Import of Linux compatibility layer and JFFS2 file system support from
eCos.
The files are imported from eCos CVS on 2013-09-16.
cvs -d :pserver:anoncvs@ecos.sourceware.org:/cvs/ecos login
cvs -z3 -d :pserver:anoncvs@ecos.sourceware.org:/cvs/ecos co -P ecos
The files
"ecos/packages/compat/linux/current/asm/atomic.h",
"ecos/packages/compat/linux/current/asm/bug.h",
"ecos/packages/compat/linux/current/asm/page.h",
"ecos/packages/compat/linux/current/cyg/crc/crc.h",
"ecos/packages/compat/linux/current/cyg/infra/cyg_type.h",
"ecos/packages/compat/linux/current/linux/compiler.h",
"ecos/packages/compat/linux/current/linux/completion.h",
"ecos/packages/compat/linux/current/linux/config.h",
"ecos/packages/compat/linux/current/linux/crc32.h",
"ecos/packages/compat/linux/current/linux/errno.h",
"ecos/packages/compat/linux/current/linux/fs.h",
"ecos/packages/compat/linux/current/linux/kernel.h",
"ecos/packages/compat/linux/current/linux/list.h",
"ecos/packages/compat/linux/current/linux/mtd/compatmac.h",
"ecos/packages/compat/linux/current/linux/mtd/mtd.h",
"ecos/packages/compat/linux/current/linux/pagemap.h",
"ecos/packages/compat/linux/current/linux/rbtree.h",
"ecos/packages/compat/linux/current/linux/rwsem.h",
"ecos/packages/compat/linux/current/linux/sched.h",
"ecos/packages/compat/linux/current/linux/slab.h",
"ecos/packages/compat/linux/current/linux/spinlock.h",
"ecos/packages/compat/linux/current/linux/stat.h",
"ecos/packages/compat/linux/current/linux/string.h",
"ecos/packages/compat/linux/current/linux/timer.h",
"ecos/packages/compat/linux/current/linux/types.h",
"ecos/packages/compat/linux/current/linux/version.h",
"ecos/packages/compat/linux/current/linux/vmalloc.h",
"ecos/packages/compat/linux/current/linux/wait.h",
"ecos/packages/compat/linux/current/linux/workqueue.h", and
"ecos/packages/compat/linux/current/linux/zlib.h"
"ecos/packages/compat/linux/current/linux/zutil.h"
are copied to "cpukit/libfs/src/jffs2/include".
The file "ecos/packages/services/crc/current/src/crc32.c" is copied to
"cpukit/libfs/src/jffs2/src/compat-crc32.c".
The file "ecos/packages/compat/linux/current/src/rbtree.c" is copied to
"cpukit/libfs/src/jffs2/src/compat-rbtree.c".
The file "ecos/packages/fs/jffs2/current/src/dir-ecos.c" is copied to
"cpukit/libfs/src/jffs2/src/dir-rtems.c".
The file "ecos/packages/fs/jffs2/current/src/flashio.c" is copied to
"cpukit/libfs/src/jffs2/src/flashio.c".
The file "ecos/packages/fs/jffs2/current/src/fs-ecos.c" is copied to
"cpukit/libfs/src/jffs2/src/fs-rtems.c".
The file "ecos/packages/fs/jffs2/current/src/malloc-ecos.c" is copied to
"cpukit/libfs/src/jffs2/src/malloc-rtems.c".
The file "ecos/packages/fs/jffs2/current/src/os-ecos.h" is copied to
"cpukit/libfs/src/jffs2/src/os-rtems.h".
The LICENSE file referenced in some files of this patch set is part of a
previous patch set imported from Linux.
Diffstat (limited to '')
-rw-r--r-- | cpukit/libfs/src/jffs2/src/flashio.c | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/cpukit/libfs/src/jffs2/src/flashio.c b/cpukit/libfs/src/jffs2/src/flashio.c new file mode 100644 index 0000000000..13a12e35b3 --- /dev/null +++ b/cpukit/libfs/src/jffs2/src/flashio.c @@ -0,0 +1,165 @@ +/* + * JFFS2 -- Journalling Flash File System, Version 2. + * + * Copyright (C) 2001-2003 Red Hat, Inc. + * + * Created by Dominic Ostrowski <dominic.ostrowski@3glab.com> + * Contributors: David Woodhouse, Nick Garnett, Richard Panton. + * + * For licensing information, see the file 'LICENCE' in this directory. + * + * $Id: flashio.c,v 1.1 2003/11/26 14:09:29 dwmw2 Exp $ + * + */ + +#include <linux/kernel.h> +#include "nodelist.h" + +#include <cyg/io/io.h> +#include <cyg/io/config_keys.h> +#include <cyg/io/flash.h> + +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) +{ + Cyg_ErrNo err; + cyg_uint32 len = size; + 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); + + *return_size = (size_t) len; + return ((err == ENOERR) ? ENOERR : -EIO); +} + +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) +{ + + Cyg_ErrNo err; + cyg_uint32 len = size; + 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)); + + err = cyg_io_bwrite(sb->s_dev, read_buffer, &len, write_buffer_offset); + *return_size = (size_t) len; + + return ((err == ENOERR) ? ENOERR : -EIO); +} + +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++) { + // 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)))) { + // 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) { + // cop out and malloc + unsigned long j; + ssize_t sizetomalloc = 0, totvecsize = 0; + char *cbuf, *cbufptr; + + for (j = i; j < count; j++) + totvecsize += vecs[j].iov_len; + + // pad up in case unaligned + sizetomalloc = totvecsize + sizeof (int) - 1; + sizetomalloc &= ~(sizeof (int) - 1); + cbuf = (char *) malloc(sizetomalloc); + // malloc returns aligned memory + 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); + cbufptr += vecs[j].iov_len; + } + ret = + jffs2_flash_write(c, to, sizetomalloc, + &thislen, cbuf); + if (thislen > totvecsize) // in case it was aligned up + thislen = totvecsize; + totlen += thislen; + free(cbuf); + goto writev_out; + } else { + // otherwise optimize for the common case + 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); + memcpy(buf, vecs[i].iov_base, lentowrite); + + ret = + jffs2_flash_write(c, to, lentowrite, + &thislen, (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); + totlen += thislen; + 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) +{ + cyg_io_flash_getconfig_erase_t e; + cyg_flashaddr_t err_addr; + Cyg_ErrNo err; + cyg_uint32 len = sizeof (e); + struct super_block *sb = OFNI_BS_2SFFJ(c); + + e.offset = jeb->offset; + e.len = c->sector_size; + e.err_address = &err_addr; + + // 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); + + return (err != ENOERR || e.flasherr != 0); +} + |