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