yaffs Fix incorrect handling of deletion flag
[yaffs2.git] / direct / yaffscfg2k.c
1 /*
2  * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
3  *
4  * Copyright (C) 2002-2010 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 #include "yaffs_norif1.h"
26 #include "yaffs_trace.h"
27
28 #include <errno.h>
29
30 unsigned yaffs_traceMask = 
31
32         YAFFS_TRACE_SCAN |  
33         YAFFS_TRACE_GC |
34         YAFFS_TRACE_ERASE | 
35         YAFFS_TRACE_ERROR | 
36         YAFFS_TRACE_TRACING | 
37         YAFFS_TRACE_ALLOCATE | 
38         YAFFS_TRACE_BAD_BLOCKS |
39         YAFFS_TRACE_VERIFY | 
40         
41         0;
42         
43
44 static int yaffsfs_lastError;
45
46 void yaffsfs_SetError(int err)
47 {
48         //Do whatever to set error
49         yaffsfs_lastError = err;
50 }
51
52
53 int yaffsfs_GetLastError(void)
54 {
55         return yaffsfs_lastError;
56 }
57
58 void yaffsfs_Lock(void)
59 {
60 }
61
62 void yaffsfs_Unlock(void)
63 {
64 }
65
66 __u32 yaffsfs_CurrentTime(void)
67 {
68         return 0;
69 }
70
71
72 static int yaffs_kill_alloc = 0;
73 static size_t total_malloced = 0;
74 static size_t malloc_limit = 0 & 6000000;
75
76 void *yaffs_malloc(size_t size)
77 {
78         void * this;
79         if(yaffs_kill_alloc)
80                 return NULL;
81         if(malloc_limit && malloc_limit <(total_malloced + size) )
82                 return NULL;
83
84         this = malloc(size);
85         if(this)
86                 total_malloced += size;
87         return this;
88 }
89
90 void yaffs_free(void *ptr)
91 {
92         free(ptr);
93 }
94
95 void yaffsfs_LocalInitialisation(void)
96 {
97         // Define locking semaphore.
98 }
99
100 // Configuration for:
101 // /ram  2MB ramdisk
102 // /boot 2MB boot disk (flash)
103 // /flash 14MB flash disk (flash)
104 // NB Though /boot and /flash occupy the same physical device they
105 // are still disticnt "yaffs_Devices. You may think of these as "partitions"
106 // using non-overlapping areas in the same device.
107 // 
108
109 #include "yaffs_ramdisk.h"
110 #include "yaffs_flashif.h"
111 #include "yaffs_flashif2.h"
112 #include "yaffs_nandemul2k.h"
113
114 static yaffs_Device ram1Dev;
115 static yaffs_Device nand2;
116 static yaffs_Device flashDev;
117 static yaffs_Device ram2kDev;
118 static yaffs_Device m18_1Dev;
119
120 static yaffsfs_DeviceConfiguration yaffsfs_config[] = {
121
122         { "/ram1", &ram1Dev},
123         { "/M18-1", &m18_1Dev},
124         { "/yaffs2", &flashDev},
125         { "/ram2k", &ram2kDev},
126         {(void *)0,(void *)0} /* Null entry to terminate list */
127 };
128
129
130 int yaffs_StartUp(void)
131 {
132         // Stuff to configure YAFFS
133         // Stuff to initialise anything special (eg lock semaphore).
134         yaffsfs_LocalInitialisation();
135         
136         // Set up devices
137         // /ram1   ram, yaffs1
138         memset(&ram1Dev,0,sizeof(ram1Dev));
139         ram1Dev.param.totalBytesPerChunk = 512;
140         ram1Dev.param.nChunksPerBlock = 32;
141         ram1Dev.param.nReservedBlocks = 2; // Set this smaller for RAM
142         ram1Dev.param.startBlock = 0; // Can use block 0
143         ram1Dev.param.endBlock = 127; // Last block in 2MB.     
144         //ram1Dev.param.useNANDECC = 1;
145         ram1Dev.param.nShortOpCaches = 0;       // Disable caching on this device.
146         ram1Dev.context = (void *) 0;   // Used to identify the device in fstat.
147         ram1Dev.param.writeChunkWithTagsToNAND = yramdisk_WriteChunkWithTagsToNAND;
148         ram1Dev.param.readChunkWithTagsFromNAND = yramdisk_ReadChunkWithTagsFromNAND;
149         ram1Dev.param.eraseBlockInNAND = yramdisk_EraseBlockInNAND;
150         ram1Dev.param.initialiseNAND = yramdisk_InitialiseNAND;
151
152         // /M18-1 yaffs1 on M18 nor sim
153         memset(&m18_1Dev,0,sizeof(m18_1Dev));
154         m18_1Dev.param.totalBytesPerChunk = 1024;
155         m18_1Dev.param.nChunksPerBlock =248;
156         m18_1Dev.param.nReservedBlocks = 2;
157         m18_1Dev.param.startBlock = 0; // Can use block 0
158         m18_1Dev.param.endBlock = 31; // Last block
159         m18_1Dev.param.useNANDECC = 0; // use YAFFS's ECC
160         m18_1Dev.param.nShortOpCaches = 10; // Use caches
161         m18_1Dev.context = (void *) 1;  // Used to identify the device in fstat.
162         m18_1Dev.param.writeChunkToNAND = ynorif1_WriteChunkToNAND;
163         m18_1Dev.param.readChunkFromNAND = ynorif1_ReadChunkFromNAND;
164         m18_1Dev.param.eraseBlockInNAND = ynorif1_EraseBlockInNAND;
165         m18_1Dev.param.initialiseNAND = ynorif1_InitialiseNAND;
166         m18_1Dev.param.deinitialiseNAND = ynorif1_DeinitialiseNAND;
167
168
169         // /yaffs2 
170         // Set this puppy up to use
171         // the file emulation space as
172         // 2kpage/64chunk per block
173         //
174         memset(&flashDev,0,sizeof(flashDev));
175
176         flashDev.param.totalBytesPerChunk = 2048;
177         flashDev.param.nChunksPerBlock = 64;
178         flashDev.param.nReservedBlocks = 5;
179         flashDev.param.inbandTags = 0;
180         flashDev.param.startBlock = 0;
181         flashDev.param.endBlock = yflash2_GetNumberOfBlocks()-1;
182         flashDev.param.isYaffs2 = 1;
183         flashDev.param.useNANDECC=1;
184         flashDev.param.wideTnodesDisabled=0;
185         flashDev.param.refreshPeriod = 1000;
186         flashDev.param.nShortOpCaches = 10; // Use caches
187         flashDev.context = (void *) 2;  // Used to identify the device in fstat.
188         flashDev.param.writeChunkWithTagsToNAND = yflash2_WriteChunkWithTagsToNAND;
189         flashDev.param.readChunkWithTagsFromNAND = yflash2_ReadChunkWithTagsFromNAND;
190         flashDev.param.eraseBlockInNAND = yflash2_EraseBlockInNAND;
191         flashDev.param.initialiseNAND = yflash2_InitialiseNAND;
192         flashDev.param.markNANDBlockBad = yflash2_MarkNANDBlockBad;
193         flashDev.param.queryNANDBlock = yflash2_QueryNANDBlock;
194
195
196         yaffs_initialise(yaffsfs_config);
197         
198         return 0;
199 }
200
201
202