summaryrefslogtreecommitdiff
path: root/fs/yaffs2/direct/yaffs_ramdisk.c
diff options
context:
space:
mode:
authorWilliam Juul <william.juul@datarespons.no>2007-11-15 11:13:05 +0100
committerScott Wood <scottwood@freescale.com>2008-08-12 11:31:18 -0500
commit0e8cc8bd92257da2e1df88cbc985e166e472ce61 (patch)
treed5a8e0f4263a58eeb6cecc423b02b019a15eb56d /fs/yaffs2/direct/yaffs_ramdisk.c
parent3043c045d5a9897faba7d5c7218c2f4d06cd0038 (diff)
downloadu-boot-imx-0e8cc8bd92257da2e1df88cbc985e166e472ce61.zip
u-boot-imx-0e8cc8bd92257da2e1df88cbc985e166e472ce61.tar.gz
u-boot-imx-0e8cc8bd92257da2e1df88cbc985e166e472ce61.tar.bz2
YAFFS2 import
Direct import of yaffs as a tarball as of 20071113 from their public CVS-web at http://www.aleph1.co.uk/cgi-bin/viewcvs.cgi/yaffs2/ The code can also be imported on the command line with: export CVSROOT=:pserver:anonymous@cvs.aleph1.co.uk:/home/aleph1/cvs cvs logon (Hit return when asked for a password) cvs checkout yaffs2 Signed-off-by: William Juul <william.juul@tandberg.com> Signed-off-by: Stig Olsen <stig.olsen@tandberg.com>
Diffstat (limited to 'fs/yaffs2/direct/yaffs_ramdisk.c')
-rw-r--r--fs/yaffs2/direct/yaffs_ramdisk.c234
1 files changed, 234 insertions, 0 deletions
diff --git a/fs/yaffs2/direct/yaffs_ramdisk.c b/fs/yaffs2/direct/yaffs_ramdisk.c
new file mode 100644
index 0000000..6afee81
--- /dev/null
+++ b/fs/yaffs2/direct/yaffs_ramdisk.c
@@ -0,0 +1,234 @@
+/*
+ * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
+ *
+ * Copyright (C) 2002-2007 Aleph One Ltd.
+ * for Toby Churchill Ltd and Brightstar Engineering
+ *
+ * Created by Charles Manning <charles@aleph1.co.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+/*
+ * yaffs_ramdisk.c: yaffs ram disk component
+ * This provides a ram disk under yaffs.
+ * NB this is not intended for NAND emulation.
+ * Use this with dev->useNANDECC enabled, then ECC overheads are not required.
+ */
+
+const char *yaffs_ramdisk_c_version = "$Id: yaffs_ramdisk.c,v 1.4 2007/02/14 01:09:06 wookey Exp $";
+
+
+#include "yportenv.h"
+
+#include "yaffs_ramdisk.h"
+#include "yaffs_guts.h"
+#include "devextras.h"
+#include "yaffs_packedtags1.h"
+
+
+
+#define SIZE_IN_MB 2
+
+#define BLOCK_SIZE (32 * 528)
+#define BLOCKS_PER_MEG ((1024*1024)/(32 * 512))
+
+
+
+
+
+typedef struct
+{
+ __u8 data[528]; // Data + spare
+} yramdisk_Page;
+
+typedef struct
+{
+ yramdisk_Page page[32]; // The pages in the block
+
+} yramdisk_Block;
+
+
+
+typedef struct
+{
+ yramdisk_Block **block;
+ int nBlocks;
+} yramdisk_Device;
+
+static yramdisk_Device ramdisk;
+
+static int CheckInit(yaffs_Device *dev)
+{
+ static int initialised = 0;
+
+ int i;
+ int fail = 0;
+ //int nBlocks;
+ int nAllocated = 0;
+
+ if(initialised)
+ {
+ return YAFFS_OK;
+ }
+
+ initialised = 1;
+
+
+ ramdisk.nBlocks = (SIZE_IN_MB * 1024 * 1024)/(16 * 1024);
+
+ ramdisk.block = YMALLOC(sizeof(yramdisk_Block *) * ramdisk.nBlocks);
+
+ if(!ramdisk.block) return 0;
+
+ for(i=0; i <ramdisk.nBlocks; i++)
+ {
+ ramdisk.block[i] = NULL;
+ }
+
+ for(i=0; i <ramdisk.nBlocks && !fail; i++)
+ {
+ if((ramdisk.block[i] = YMALLOC(sizeof(yramdisk_Block))) == 0)
+ {
+ fail = 1;
+ }
+ else
+ {
+ yramdisk_EraseBlockInNAND(dev,i);
+ nAllocated++;
+ }
+ }
+
+ if(fail)
+ {
+ for(i = 0; i < nAllocated; i++)
+ {
+ YFREE(ramdisk.block[i]);
+ }
+ YFREE(ramdisk.block);
+
+ T(YAFFS_TRACE_ALWAYS,("Allocation failed, could only allocate %dMB of %dMB requested.\n",
+ nAllocated/64,ramdisk.nBlocks * 528));
+ return 0;
+ }
+
+
+ return 1;
+}
+
+int yramdisk_WriteChunkWithTagsToNAND(yaffs_Device *dev,int chunkInNAND,const __u8 *data, yaffs_ExtendedTags *tags)
+{
+ int blk;
+ int pg;
+
+
+ CheckInit(dev);
+
+ blk = chunkInNAND/32;
+ pg = chunkInNAND%32;
+
+
+ if(data)
+ {
+ memcpy(ramdisk.block[blk]->page[pg].data,data,512);
+ }
+
+
+ if(tags)
+ {
+ yaffs_PackedTags1 pt;
+
+ yaffs_PackTags1(&pt,tags);
+ memcpy(&ramdisk.block[blk]->page[pg].data[512],&pt,sizeof(pt));
+ }
+
+ return YAFFS_OK;
+
+}
+
+
+int yramdisk_ReadChunkWithTagsFromNAND(yaffs_Device *dev,int chunkInNAND, __u8 *data, yaffs_ExtendedTags *tags)
+{
+ int blk;
+ int pg;
+
+
+ CheckInit(dev);
+
+ blk = chunkInNAND/32;
+ pg = chunkInNAND%32;
+
+
+ if(data)
+ {
+ memcpy(data,ramdisk.block[blk]->page[pg].data,512);
+ }
+
+
+ if(tags)
+ {
+ yaffs_PackedTags1 pt;
+
+ memcpy(&pt,&ramdisk.block[blk]->page[pg].data[512],sizeof(pt));
+ yaffs_UnpackTags1(tags,&pt);
+
+ }
+
+ return YAFFS_OK;
+}
+
+
+int yramdisk_CheckChunkErased(yaffs_Device *dev,int chunkInNAND)
+{
+ int blk;
+ int pg;
+ int i;
+
+
+ CheckInit(dev);
+
+ blk = chunkInNAND/32;
+ pg = chunkInNAND%32;
+
+
+ for(i = 0; i < 528; i++)
+ {
+ if(ramdisk.block[blk]->page[pg].data[i] != 0xFF)
+ {
+ return YAFFS_FAIL;
+ }
+ }
+
+ return YAFFS_OK;
+
+}
+
+int yramdisk_EraseBlockInNAND(yaffs_Device *dev, int blockNumber)
+{
+
+ CheckInit(dev);
+
+ if(blockNumber < 0 || blockNumber >= ramdisk.nBlocks)
+ {
+ T(YAFFS_TRACE_ALWAYS,("Attempt to erase non-existant block %d\n",blockNumber));
+ return YAFFS_FAIL;
+ }
+ else
+ {
+ memset(ramdisk.block[blockNumber],0xFF,sizeof(yramdisk_Block));
+ return YAFFS_OK;
+ }
+
+}
+
+int yramdisk_InitialiseNAND(yaffs_Device *dev)
+{
+ //dev->useNANDECC = 1; // force on useNANDECC which gets faked.
+ // This saves us doing ECC checks.
+
+ return YAFFS_OK;
+}
+
+