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