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 * yaffscfg2k.c The configuration for the "direct" use of yaffs.
17 * This file is intended to be modified to your requirements.
18 * There is no need to redistribute this file.
26 #include "yaffs_fileem2k.h"
27 #include "yaffs_nandemul2k.h"
31 unsigned yaffs_traceMask =
34 YAFFS_TRACE_GC | YAFFS_TRACE_GC_DETAIL |
37 YAFFS_TRACE_ALLOCATE |
38 YAFFS_TRACE_CHECKPOINT |
39 YAFFS_TRACE_BAD_BLOCKS |
41 YAFFS_TRACE_VERIFY_NAND |
42 YAFFS_TRACE_VERIFY_FULL |
49 void yaffsfs_SetError(int err)
51 //Do whatever to set error
55 void yaffsfs_Lock(void)
59 void yaffsfs_Unlock(void)
63 __u32 yaffsfs_CurrentTime(void)
69 static int yaffs_kill_alloc = 0;
70 static size_t total_malloced = 0;
71 static size_t malloc_limit = 0 & 6000000;
73 void *yaffs_malloc(size_t size)
78 if(malloc_limit && malloc_limit <(total_malloced + size) )
83 total_malloced += size;
87 void yaffs_free(void *ptr)
92 void yaffsfs_LocalInitialisation(void)
94 // Define locking semaphore.
99 // /boot 2MB boot disk (flash)
100 // /flash 14MB flash disk (flash)
101 // NB Though /boot and /flash occupy the same physical device they
102 // are still disticnt "yaffs_Devices. You may think of these as "partitions"
103 // using non-overlapping areas in the same device.
106 #include "yaffs_ramdisk.h"
107 #include "yaffs_flashif.h"
108 #include "yaffs_nandemul2k.h"
110 static yaffs_Device ramDev;
111 static yaffs_Device bootDev;
112 static yaffs_Device flashDev;
113 static yaffs_Device ram2kDev;
115 static yaffsfs_DeviceConfiguration yaffsfs_config[] = {
118 { "/boot", &bootDev},
119 { "/flash/", &flashDev},
120 { "/ram2k", &ram2kDev},
121 {(void *)0,(void *)0}
124 { "/flash/boot", &bootDev},
125 { "/flash/flash", &flashDev},
126 { "/ram2k", &ram2kDev},
127 {(void *)0,(void *)0} /* Null entry to terminate list */
132 int yaffs_StartUp(void)
134 // Stuff to configure YAFFS
135 // Stuff to initialise anything special (eg lock semaphore).
136 yaffsfs_LocalInitialisation();
140 memset(&ramDev,0,sizeof(ramDev));
141 ramDev.nDataBytesPerChunk = 512;
142 ramDev.nChunksPerBlock = 32;
143 ramDev.nReservedBlocks = 2; // Set this smaller for RAM
144 ramDev.startBlock = 0; // Can use block 0
145 ramDev.endBlock = 127; // Last block in 2MB.
146 //ramDev.useNANDECC = 1;
147 ramDev.nShortOpCaches = 0; // Disable caching on this device.
148 ramDev.genericDevice = (void *) 0; // Used to identify the device in fstat.
149 ramDev.writeChunkWithTagsToNAND = yramdisk_WriteChunkWithTagsToNAND;
150 ramDev.readChunkWithTagsFromNAND = yramdisk_ReadChunkWithTagsFromNAND;
151 ramDev.eraseBlockInNAND = yramdisk_EraseBlockInNAND;
152 ramDev.initialiseNAND = yramdisk_InitialiseNAND;
155 memset(&bootDev,0,sizeof(bootDev));
156 bootDev.nDataBytesPerChunk = 512;
157 bootDev.nChunksPerBlock = 32;
158 bootDev.nReservedBlocks = 5;
159 bootDev.startBlock = 0; // Can use block 0
160 bootDev.endBlock = 63; // Last block
161 //bootDev.useNANDECC = 0; // use YAFFS's ECC
162 bootDev.nShortOpCaches = 10; // Use caches
163 bootDev.genericDevice = (void *) 1; // Used to identify the device in fstat.
164 bootDev.writeChunkWithTagsToNAND = yflash_WriteChunkWithTagsToNAND;
165 bootDev.readChunkWithTagsFromNAND = yflash_ReadChunkWithTagsFromNAND;
166 bootDev.eraseBlockInNAND = yflash_EraseBlockInNAND;
167 bootDev.initialiseNAND = yflash_InitialiseNAND;
168 bootDev.markNANDBlockBad = yflash_MarkNANDBlockBad;
169 bootDev.queryNANDBlock = yflash_QueryNANDBlock;
174 // Set this puppy up to use
175 // the file emulation space as
176 // 2kpage/64chunk per block/128MB device
177 memset(&flashDev,0,sizeof(flashDev));
179 flashDev.nDataBytesPerChunk = 2048;
180 flashDev.nChunksPerBlock = 64;
181 flashDev.nReservedBlocks = 5;
182 flashDev.nCheckpointReservedBlocks = 5;
183 //flashDev.checkpointStartBlock = 1;
184 //flashDev.checkpointEndBlock = 20;
185 flashDev.startBlock = 0;
186 flashDev.endBlock = 200; // Make it smaller
187 //flashDev.endBlock = yflash_GetNumberOfBlocks()-1;
188 flashDev.isYaffs2 = 1;
189 flashDev.wideTnodesDisabled=0;
190 flashDev.nShortOpCaches = 10; // Use caches
191 flashDev.genericDevice = (void *) 2; // Used to identify the device in fstat.
192 flashDev.writeChunkWithTagsToNAND = yflash_WriteChunkWithTagsToNAND;
193 flashDev.readChunkWithTagsFromNAND = yflash_ReadChunkWithTagsFromNAND;
194 flashDev.eraseBlockInNAND = yflash_EraseBlockInNAND;
195 flashDev.initialiseNAND = yflash_InitialiseNAND;
196 flashDev.markNANDBlockBad = yflash_MarkNANDBlockBad;
197 flashDev.queryNANDBlock = yflash_QueryNANDBlock;
200 // Set this puppy up to use
201 // the file emulation space as
202 // 2kpage/64chunk per block/128MB device
203 memset(&ram2kDev,0,sizeof(ram2kDev));
205 ram2kDev.nDataBytesPerChunk = nandemul2k_GetBytesPerChunk();
206 ram2kDev.nChunksPerBlock = nandemul2k_GetChunksPerBlock();
207 ram2kDev.nReservedBlocks = 5;
208 ram2kDev.startBlock = 0; // First block after /boot
209 //ram2kDev.endBlock = 127; // Last block in 16MB
210 ram2kDev.endBlock = nandemul2k_GetNumberOfBlocks() - 1; // Last block in 512MB
211 ram2kDev.isYaffs2 = 1;
212 ram2kDev.nShortOpCaches = 10; // Use caches
213 ram2kDev.genericDevice = (void *) 3; // Used to identify the device in fstat.
214 ram2kDev.writeChunkWithTagsToNAND = nandemul2k_WriteChunkWithTagsToNAND;
215 ram2kDev.readChunkWithTagsFromNAND = nandemul2k_ReadChunkWithTagsFromNAND;
216 ram2kDev.eraseBlockInNAND = nandemul2k_EraseBlockInNAND;
217 ram2kDev.initialiseNAND = nandemul2k_InitialiseNAND;
218 ram2kDev.markNANDBlockBad = nandemul2k_MarkNANDBlockBad;
219 ram2kDev.queryNANDBlock = nandemul2k_QueryNANDBlock;
221 yaffs_initialise(yaffsfs_config);
228 void SetCheckpointReservedBlocks(int n)
230 flashDev.nCheckpointReservedBlocks = n;