2 * YAFFS: Yet another FFS. A NAND-flash specific file system.
3 * yaffs_ramdisk.c: yaffs ram disk component
5 * Copyright (C) 2002 Aleph One Ltd.
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 // This provides a rma disk under yaffs.
16 // NB this is not intended for NAND emulation.
17 // Use this with dev->useNANDECC enabled, then ECC overheads are not required.
19 const char *yaffs_ramdisk_c_version = "$Id: yaffs_ramdisk.c,v 1.1 2004-11-03 08:29:28 charles Exp $";
24 #include "yaffs_ramdisk.h"
25 #include "yaffs_guts.h"
26 #include "devextras.h"
27 #include "yaffs_packedtags.h"
33 #define BLOCK_SIZE (32 * 528)
34 #define BLOCKS_PER_MEG ((1024*1024)/(32 * 512))
42 __u8 data[528]; // Data + spare
47 yramdisk_Page page[32]; // The pages in the block
55 yramdisk_Block **block;
59 static yramdisk_Device ramdisk;
61 static int CheckInit(yaffs_Device *dev)
63 static int initialised = 0;
78 ramdisk.nBlocks = (SIZE_IN_MB * 1024 * 1024)/(16 * 1024);
80 ramdisk.block = YMALLOC(sizeof(yramdisk_Block *) * ramdisk.nBlocks);
82 if(!ramdisk.block) return 0;
84 for(i=0; i <ramdisk.nBlocks; i++)
86 ramdisk.block[i] = NULL;
89 for(i=0; i <ramdisk.nBlocks && !fail; i++)
91 if((ramdisk.block[i] = YMALLOC(sizeof(yramdisk_Block))) == 0)
97 yramdisk_EraseBlockInNAND(dev,i);
104 for(i = 0; i < nAllocated; i++)
106 YFREE(ramdisk.block[i]);
108 YFREE(ramdisk.block);
110 T(YAFFS_TRACE_ALWAYS,("Allocation failed, could only allocate %dMB of %dMB requested.\n",
111 nAllocated/64,ramdisk.nBlocks * 528));
119 int yramdisk_WriteChunkWithTagsToNAND(yaffs_Device *dev,int chunkInNAND,const __u8 *data, yaffs_ExtendedTags *tags)
127 blk = chunkInNAND/32;
133 memcpy(ramdisk.block[blk]->page[pg].data,data,512);
141 yaffs_PackTags(&pt,tags);
142 memcpy(&ramdisk.block[blk]->page[pg].data[512],&pt,sizeof(pt));
150 int yramdisk_ReadChunkWithTagsFromNAND(yaffs_Device *dev,int chunkInNAND, __u8 *data, yaffs_ExtendedTags *tags)
158 blk = chunkInNAND/32;
164 memcpy(data,ramdisk.block[blk]->page[pg].data,512);
172 memcpy(&pt,&ramdisk.block[blk]->page[pg].data[512],sizeof(pt));
173 yaffs_UnpackTags(tags,&pt);
181 int yramdisk_CheckChunkErased(yaffs_Device *dev,int chunkInNAND)
190 blk = chunkInNAND/32;
194 for(i = 0; i < 528; i++)
196 if(ramdisk.block[blk]->page[pg].data[i] != 0xFF)
206 int yramdisk_EraseBlockInNAND(yaffs_Device *dev, int blockNumber)
211 if(blockNumber < 0 || blockNumber >= ramdisk.nBlocks)
213 T(YAFFS_TRACE_ALWAYS,("Attempt to erase non-existant block %d\n",blockNumber));
218 memset(ramdisk.block[blockNumber],0xFF,sizeof(yramdisk_Block));
224 int yramdisk_InitialiseNAND(yaffs_Device *dev)
226 //dev->useNANDECC = 1; // force on useNANDECC which gets faked.
227 // This saves us doing ECC checks.