2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
4 * Copyright (C) 2002-2011 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.
22 #include "yaffs_trace.h"
24 #include "yaffs_ramdisk.h"
25 #include "yaffs_guts.h"
26 #include "yaffs_packedtags1.h"
32 #define BLOCK_SIZE (32 * 528)
33 #define BLOCKS_PER_MEG ((1024*1024)/(32 * 512))
41 u8 data[528]; // Data + spare
46 yramdisk_page page[32]; // The pages in the block
54 yramdisk_block **block;
58 static yramdisk_device ramdisk;
60 static int CheckInit(struct yaffs_dev *dev)
62 static int initialised = 0;
77 ramdisk.nBlocks = (SIZE_IN_MB * 1024 * 1024)/(16 * 1024);
79 ramdisk.block = malloc(sizeof(yramdisk_block *) * ramdisk.nBlocks);
81 if(!ramdisk.block) return 0;
83 for(i=0; i <ramdisk.nBlocks; i++)
85 ramdisk.block[i] = NULL;
88 for(i=0; i <ramdisk.nBlocks && !fail; i++)
90 if((ramdisk.block[i] = malloc(sizeof(yramdisk_block))) == 0)
96 yramdisk_erase(dev,i);
103 for(i = 0; i < nAllocated; i++)
105 kfree(ramdisk.block[i]);
107 kfree(ramdisk.block);
109 yaffs_trace(YAFFS_TRACE_ALWAYS,
110 "Allocation failed, could only allocate %dMB of %dMB requested.\n",
111 nAllocated/64,ramdisk.nBlocks * 528);
119 int yramdisk_wr_chunk(struct yaffs_dev *dev,int nand_chunk,const u8 *data, const struct yaffs_ext_tags *tags)
133 memcpy(ramdisk.block[blk]->page[pg].data,data,512);
139 struct yaffs_packed_tags1 pt;
141 yaffs_pack_tags1(&pt,tags);
142 memcpy(&ramdisk.block[blk]->page[pg].data[512],&pt,sizeof(pt));
150 int yramdisk_rd_chunk(struct yaffs_dev *dev,int nand_chunk, u8 *data, struct yaffs_ext_tags *tags)
164 memcpy(data,ramdisk.block[blk]->page[pg].data,512);
170 struct yaffs_packed_tags1 pt;
172 memcpy(&pt,&ramdisk.block[blk]->page[pg].data[512],sizeof(pt));
173 yaffs_unpack_tags1(tags,&pt);
181 int yramdisk_check_chunk_erased(struct yaffs_dev *dev,int nand_chunk)
194 for(i = 0; i < 528; i++)
196 if(ramdisk.block[blk]->page[pg].data[i] != 0xFF)
206 int yramdisk_erase(struct yaffs_dev *dev, int blockNumber)
211 if(blockNumber < 0 || blockNumber >= ramdisk.nBlocks)
213 yaffs_trace(YAFFS_TRACE_ALWAYS,
214 "Attempt to erase non-existant block %d\n",
220 memset(ramdisk.block[blockNumber],0xFF,sizeof(yramdisk_block));
226 int yramdisk_initialise(struct yaffs_dev *dev)
228 //dev->use_nand_ecc = 1; // force on use_nand_ecc which gets faked.
229 // This saves us doing ECC checks.