Adding fsx test to yaffs direct
[yaffs2.git] / direct / yaffscfg2k.c
1 /*
2  * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
3  *
4  * Copyright (C) 2002-2007 Aleph One Ltd.
5  *   for Toby Churchill Ltd and Brightstar Engineering
6  *
7  * Created by Charles Manning <charles@aleph1.co.uk>
8  *
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.
12  */
13
14 /*
15  * yaffscfg2k.c  The configuration for the "direct" use of yaffs.
16  *
17  * This file is intended to be modified to your requirements.
18  * There is no need to redistribute this file.
19  */
20
21 #include "yaffscfg.h"
22 #include "yaffsfs.h"
23 #include "yaffs_fileem2k.h"
24 #include "yaffs_nandemul2k.h"
25
26 #include <errno.h>
27
28 unsigned yaffs_traceMask = 
29
30         YAFFS_TRACE_SCAN |  
31         YAFFS_TRACE_GC | YAFFS_TRACE_GC_DETAIL | 
32         YAFFS_TRACE_ERASE | 
33         YAFFS_TRACE_TRACING | 
34         YAFFS_TRACE_ALLOCATE | 
35         YAFFS_TRACE_CHECKPOINT |
36         YAFFS_TRACE_BAD_BLOCKS |
37         YAFFS_TRACE_VERIFY |
38         YAFFS_TRACE_VERIFY_NAND |
39         YAFFS_TRACE_VERIFY_FULL |
40 //      (~0) |
41         
42         0;
43         
44
45
46 void yaffsfs_SetError(int err)
47 {
48         //Do whatever to set error
49         errno = err;
50 }
51
52 void yaffsfs_Lock(void)
53 {
54 }
55
56 void yaffsfs_Unlock(void)
57 {
58 }
59
60 __u32 yaffsfs_CurrentTime(void)
61 {
62         return 0;
63 }
64
65
66 static int yaffs_kill_alloc = 0;
67 static size_t total_malloced = 0;
68 static size_t malloc_limit = 0 & 6000000;
69
70 void *yaffs_malloc(size_t size)
71 {
72         size_t this;
73         if(yaffs_kill_alloc)
74                 return NULL;
75         if(malloc_limit && malloc_limit <(total_malloced + size) )
76                 return NULL;
77
78         this = malloc(size);
79         if(this)
80                 total_malloced += size;
81         return this;
82 }
83
84 void yaffs_free(void *ptr)
85 {
86         free(ptr);
87 }
88
89 void yaffsfs_LocalInitialisation(void)
90 {
91         // Define locking semaphore.
92 }
93
94 // Configuration for:
95 // /ram  2MB ramdisk
96 // /boot 2MB boot disk (flash)
97 // /flash 14MB flash disk (flash)
98 // NB Though /boot and /flash occupy the same physical device they
99 // are still disticnt "yaffs_Devices. You may think of these as "partitions"
100 // using non-overlapping areas in the same device.
101 // 
102
103 #include "yaffs_ramdisk.h"
104 #include "yaffs_flashif.h"
105 #include "yaffs_nandemul2k.h"
106
107 static yaffs_Device ramDev;
108 static yaffs_Device bootDev;
109 static yaffs_Device flashDev;
110 static yaffs_Device ram2kDev;
111
112 static yaffsfs_DeviceConfiguration yaffsfs_config[] = {
113 #if 0
114         { "/ram", &ramDev},
115         { "/boot", &bootDev},
116         { "/flash/", &flashDev},
117         { "/ram2k", &ram2kDev},
118         {(void *)0,(void *)0}
119 #else
120         { "/", &ramDev},
121         { "/flash/boot", &bootDev},
122         { "/flash/flash", &flashDev},
123         { "/ram2k", &ram2kDev},
124         {(void *)0,(void *)0} /* Null entry to terminate list */
125 #endif
126 };
127
128
129 int yaffs_StartUp(void)
130 {
131         // Stuff to configure YAFFS
132         // Stuff to initialise anything special (eg lock semaphore).
133         yaffsfs_LocalInitialisation();
134         
135         // Set up devices
136         // /ram
137         memset(&ramDev,0,sizeof(ramDev));
138         ramDev.nDataBytesPerChunk = 512;
139         ramDev.nChunksPerBlock = 32;
140         ramDev.nReservedBlocks = 2; // Set this smaller for RAM
141         ramDev.startBlock = 0; // Can use block 0
142         ramDev.endBlock = 127; // Last block in 2MB.    
143         //ramDev.useNANDECC = 1;
144         ramDev.nShortOpCaches = 0;      // Disable caching on this device.
145         ramDev.genericDevice = (void *) 0;      // Used to identify the device in fstat.
146         ramDev.writeChunkWithTagsToNAND = yramdisk_WriteChunkWithTagsToNAND;
147         ramDev.readChunkWithTagsFromNAND = yramdisk_ReadChunkWithTagsFromNAND;
148         ramDev.eraseBlockInNAND = yramdisk_EraseBlockInNAND;
149         ramDev.initialiseNAND = yramdisk_InitialiseNAND;
150
151         // /boot
152         memset(&bootDev,0,sizeof(bootDev));
153         bootDev.nDataBytesPerChunk = 512;
154         bootDev.nChunksPerBlock = 32;
155         bootDev.nReservedBlocks = 5;
156         bootDev.startBlock = 0; // Can use block 0
157         bootDev.endBlock = 63; // Last block
158         //bootDev.useNANDECC = 0; // use YAFFS's ECC
159         bootDev.nShortOpCaches = 10; // Use caches
160         bootDev.genericDevice = (void *) 1;     // Used to identify the device in fstat.
161         bootDev.writeChunkWithTagsToNAND = yflash_WriteChunkWithTagsToNAND;
162         bootDev.readChunkWithTagsFromNAND = yflash_ReadChunkWithTagsFromNAND;
163         bootDev.eraseBlockInNAND = yflash_EraseBlockInNAND;
164         bootDev.initialiseNAND = yflash_InitialiseNAND;
165         bootDev.markNANDBlockBad = yflash_MarkNANDBlockBad;
166         bootDev.queryNANDBlock = yflash_QueryNANDBlock;
167
168
169
170         // /flash
171         // Set this puppy up to use
172         // the file emulation space as
173         // 2kpage/64chunk per block/128MB device
174         memset(&flashDev,0,sizeof(flashDev));
175
176         flashDev.nDataBytesPerChunk = 2048;
177         flashDev.nChunksPerBlock = 64;
178         flashDev.nReservedBlocks = 5;
179         flashDev.nCheckpointReservedBlocks = 5;
180         //flashDev.checkpointStartBlock = 1;
181         //flashDev.checkpointEndBlock = 20;
182         flashDev.startBlock = 0;
183         flashDev.endBlock = 200; // Make it smaller
184         //flashDev.endBlock = yflash_GetNumberOfBlocks()-1;
185         flashDev.isYaffs2 = 1;
186         flashDev.wideTnodesDisabled=0;
187         flashDev.nShortOpCaches = 10; // Use caches
188         flashDev.genericDevice = (void *) 2;    // Used to identify the device in fstat.
189         flashDev.writeChunkWithTagsToNAND = yflash_WriteChunkWithTagsToNAND;
190         flashDev.readChunkWithTagsFromNAND = yflash_ReadChunkWithTagsFromNAND;
191         flashDev.eraseBlockInNAND = yflash_EraseBlockInNAND;
192         flashDev.initialiseNAND = yflash_InitialiseNAND;
193         flashDev.markNANDBlockBad = yflash_MarkNANDBlockBad;
194         flashDev.queryNANDBlock = yflash_QueryNANDBlock;
195
196         // /ram2k
197         // Set this puppy up to use
198         // the file emulation space as
199         // 2kpage/64chunk per block/128MB device
200         memset(&ram2kDev,0,sizeof(ram2kDev));
201
202         ram2kDev.nDataBytesPerChunk = nandemul2k_GetBytesPerChunk();
203         ram2kDev.nChunksPerBlock = nandemul2k_GetChunksPerBlock();
204         ram2kDev.nReservedBlocks = 5;
205         ram2kDev.startBlock = 0; // First block after /boot
206         //ram2kDev.endBlock = 127; // Last block in 16MB
207         ram2kDev.endBlock = nandemul2k_GetNumberOfBlocks() - 1; // Last block in 512MB
208         ram2kDev.isYaffs2 = 1;
209         ram2kDev.nShortOpCaches = 10; // Use caches
210         ram2kDev.genericDevice = (void *) 3;    // Used to identify the device in fstat.
211         ram2kDev.writeChunkWithTagsToNAND = nandemul2k_WriteChunkWithTagsToNAND;
212         ram2kDev.readChunkWithTagsFromNAND = nandemul2k_ReadChunkWithTagsFromNAND;
213         ram2kDev.eraseBlockInNAND = nandemul2k_EraseBlockInNAND;
214         ram2kDev.initialiseNAND = nandemul2k_InitialiseNAND;
215         ram2kDev.markNANDBlockBad = nandemul2k_MarkNANDBlockBad;
216         ram2kDev.queryNANDBlock = nandemul2k_QueryNANDBlock;
217
218         yaffs_initialise(yaffsfs_config);
219         
220         return 0;
221 }
222
223
224
225 void SetCheckpointReservedBlocks(int n)
226 {
227         flashDev.nCheckpointReservedBlocks = n;
228 }
229