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