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