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