2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
4 * Copyright (C) 2002-2010 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->use_nand_ecc enabled, then ECC overheads are not required.
21 const char *yaffs_ramdisk_c_version = "$Id: yaffs_ramdisk.c,v 1.6 2010-01-11 04:06:47 charles Exp $";
25 #include "yaffs_trace.h"
27 #include "yaffs_ramdisk.h"
28 #include "yaffs_guts.h"
29 #include "devextras.h"
30 #include "yaffs_packedtags1.h"
36 #define BLOCK_SIZE (32 * 528)
37 #define BLOCKS_PER_MEG ((1024*1024)/(32 * 512))
45 __u8 data[528]; // Data + spare
50 yramdisk_page page[32]; // The pages in the block
58 yramdisk_block **block;
62 static yramdisk_device ramdisk;
64 static int CheckInit(yaffs_dev_t *dev)
66 static int initialised = 0;
81 ramdisk.nBlocks = (SIZE_IN_MB * 1024 * 1024)/(16 * 1024);
83 ramdisk.block = YMALLOC(sizeof(yramdisk_block *) * ramdisk.nBlocks);
85 if(!ramdisk.block) return 0;
87 for(i=0; i <ramdisk.nBlocks; i++)
89 ramdisk.block[i] = NULL;
92 for(i=0; i <ramdisk.nBlocks && !fail; i++)
94 if((ramdisk.block[i] = YMALLOC(sizeof(yramdisk_block))) == 0)
100 yramdisk_erase(dev,i);
107 for(i = 0; i < nAllocated; i++)
109 YFREE(ramdisk.block[i]);
111 YFREE(ramdisk.block);
113 T(YAFFS_TRACE_ALWAYS,("Allocation failed, could only allocate %dMB of %dMB requested.\n",
114 nAllocated/64,ramdisk.nBlocks * 528));
122 int yramdisk_wr_chunk(yaffs_dev_t *dev,int nand_chunk,const __u8 *data, const yaffs_ext_tags *tags)
136 memcpy(ramdisk.block[blk]->page[pg].data,data,512);
142 yaffs_PackedTags1 pt;
144 yaffs_PackTags1(&pt,tags);
145 memcpy(&ramdisk.block[blk]->page[pg].data[512],&pt,sizeof(pt));
153 int yramdisk_rd_chunk(yaffs_dev_t *dev,int nand_chunk, __u8 *data, yaffs_ext_tags *tags)
167 memcpy(data,ramdisk.block[blk]->page[pg].data,512);
173 yaffs_PackedTags1 pt;
175 memcpy(&pt,&ramdisk.block[blk]->page[pg].data[512],sizeof(pt));
176 yaffs_unpack_tags1(tags,&pt);
184 int yramdisk_check_chunk_erased(yaffs_dev_t *dev,int nand_chunk)
197 for(i = 0; i < 528; i++)
199 if(ramdisk.block[blk]->page[pg].data[i] != 0xFF)
209 int yramdisk_erase(yaffs_dev_t *dev, int blockNumber)
214 if(blockNumber < 0 || blockNumber >= ramdisk.nBlocks)
216 T(YAFFS_TRACE_ALWAYS,("Attempt to erase non-existant block %d\n",blockNumber));
221 memset(ramdisk.block[blockNumber],0xFF,sizeof(yramdisk_block));
227 int yramdisk_initialise(yaffs_dev_t *dev)
229 //dev->use_nand_ecc = 1; // force on use_nand_ecc which gets faked.
230 // This saves us doing ECC checks.