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