2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
4 * Copyright (C) 2002-2007 Aleph One Ltd.
5 * for Toby Churchill Ltd and Brightstar Engineering
7 * Created by Charles Manning <charles@aleph1.co.uk>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
15 * yaffs_ramdisk.c: yaffs ram disk component
16 * This provides a ram disk under yaffs.
17 * NB this is not intended for NAND emulation.
18 * Use this with dev->useNANDECC enabled, then ECC overheads are not required.
24 const char *yaffs_ramdisk_c_version = "$Id: yaffs_ramdisk.c,v 1.4 2007/02/14 01:09:06 wookey Exp $";
29 #include "yaffs_ramdisk.h"
30 #include "yaffs_guts.h"
31 #include "devextras.h"
32 #include "yaffs_packedtags1.h"
38 #define BLOCK_SIZE (32 * 528)
39 #define BLOCKS_PER_MEG ((1024*1024)/(32 * 512))
47 __u8 data[528]; // Data + spare
52 yramdisk_Page page[32]; // The pages in the block
60 yramdisk_Block **block;
64 static yramdisk_Device ramdisk;
66 static int CheckInit(yaffs_Device *dev)
68 static int initialised = 0;
83 ramdisk.nBlocks = (SIZE_IN_MB * 1024 * 1024)/(16 * 1024);
85 ramdisk.block = YMALLOC(sizeof(yramdisk_Block *) * ramdisk.nBlocks);
87 if(!ramdisk.block) return 0;
89 for(i=0; i <ramdisk.nBlocks; i++)
91 ramdisk.block[i] = NULL;
94 for(i=0; i <ramdisk.nBlocks && !fail; i++)
96 if((ramdisk.block[i] = YMALLOC(sizeof(yramdisk_Block))) == 0)
102 yramdisk_EraseBlockInNAND(dev,i);
109 for(i = 0; i < nAllocated; i++)
111 YFREE(ramdisk.block[i]);
113 YFREE(ramdisk.block);
115 T(YAFFS_TRACE_ALWAYS,("Allocation failed, could only allocate %dMB of %dMB requested.\n",
116 nAllocated/64,ramdisk.nBlocks * 528));
124 int yramdisk_WriteChunkWithTagsToNAND(yaffs_Device *dev,int chunkInNAND,const __u8 *data, yaffs_ExtendedTags *tags)
132 blk = chunkInNAND/32;
138 memcpy(ramdisk.block[blk]->page[pg].data,data,512);
144 yaffs_PackedTags1 pt;
146 yaffs_PackTags1(&pt,tags);
147 memcpy(&ramdisk.block[blk]->page[pg].data[512],&pt,sizeof(pt));
155 int yramdisk_ReadChunkWithTagsFromNAND(yaffs_Device *dev,int chunkInNAND, __u8 *data, yaffs_ExtendedTags *tags)
163 blk = chunkInNAND/32;
169 memcpy(data,ramdisk.block[blk]->page[pg].data,512);
175 yaffs_PackedTags1 pt;
177 memcpy(&pt,&ramdisk.block[blk]->page[pg].data[512],sizeof(pt));
178 yaffs_UnpackTags1(tags,&pt);
186 int yramdisk_CheckChunkErased(yaffs_Device *dev,int chunkInNAND)
195 blk = chunkInNAND/32;
199 for(i = 0; i < 528; i++)
201 if(ramdisk.block[blk]->page[pg].data[i] != 0xFF)
211 int yramdisk_EraseBlockInNAND(yaffs_Device *dev, int blockNumber)
216 if(blockNumber < 0 || blockNumber >= ramdisk.nBlocks)
218 T(YAFFS_TRACE_ALWAYS,("Attempt to erase non-existant block %d\n",blockNumber));
223 memset(ramdisk.block[blockNumber],0xFF,sizeof(yramdisk_Block));
229 int yramdisk_InitialiseNAND(yaffs_Device *dev)
231 //dev->useNANDECC = 1; // force on useNANDECC which gets faked.
232 // This saves us doing ECC checks.