2 * YAFFS: Yet another FFS. A NAND-flash specific file system.
3 * yaffs_fileem.c NAND emulation on top of files
5 * Copyright (C) 2002 Aleph One Ltd.
6 * for Toby Churchill Ltd and Brightstar Engineering
8 * Created by Charles Manning <charles@aleph1.co.uk>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
17 #include "yaffs_nandif.h"
18 #include "yaffs_guts.h"
19 #include "yaffsinterface.h"
24 #include <sys/types.h>
29 #define FILE_SIZE_IN_MEG 2
31 #define BLOCK_SIZE (32 * 528)
32 #define BLOCKS_PER_MEG ((1024*1024)/(32 * 512))
33 #define FILE_SIZE_IN_BLOCKS (FILE_SIZE_IN_MEG * BLOCKS_PER_MEG)
34 #define FILE_SIZE_IN_BYTES (FILE_SIZE_IN_BLOCKS * BLOCK_SIZE)
38 static __u8 ffChunk[528];
42 static void CheckInit(void)
44 static int initialised = 0;
51 memset(ffChunk,0xFF,528);
53 h = open("yaffs-em-file" , O_RDWR | O_CREAT, S_IREAD | S_IWRITE);
56 perror("Fatal error opening yaffs emulation file");
61 length = lseek(h,0,SEEK_END);
62 if(length != FILE_SIZE_IN_BYTES)
64 // Create file contents
67 printf("Creating emulation file...\n");
68 for(i = 0; i < FILE_SIZE_IN_BLOCKS; i++)
70 yaffs_EraseBlockInNAND(i);
76 int yaffs_WriteChunkToNAND(int chunkInNAND,__u8 *data, yaffs_Spare *spare)
80 pos = chunkInNAND * 528;
87 lseek(h,pos,SEEK_SET);
95 lseek(h,pos,SEEK_SET);
103 int yaffs_ReadChunkFromNAND(int chunkInNAND, __u8 *data, yaffs_Spare *spare)
107 pos = chunkInNAND * 528;
114 lseek(h,pos,SEEK_SET);
122 lseek(h,pos,SEEK_SET);
130 int yaffs_EraseBlockInNAND(int blockInNAND)
136 printf("Erasing block %d\n",blockInNAND);
138 lseek(h,blockInNAND * BLOCK_SIZE,SEEK_SET);
139 for(i = 0; i < 32; i++)
141 write(h,ffChunk,528);