b4a45902e821a2a656b916445d1d205e5e2d483f
[yaffs2.git] / direct / basic-test / 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 "yaffs_guts.h"
23 #include "yaffsfs.h"
24 #include "yaffs_fileem2k.h"
25 #include "yaffs_nandemul2k.h"
26 #include "yaffs_norif1.h"
27 #include "yaffs_trace.h"
28
29
30 #include <errno.h>
31
32 unsigned yaffs_traceMask = 
33
34         YAFFS_TRACE_SCAN |  
35         YAFFS_TRACE_GC |
36         YAFFS_TRACE_ERASE | 
37         YAFFS_TRACE_ERROR | 
38         YAFFS_TRACE_TRACING | 
39         YAFFS_TRACE_ALLOCATE | 
40         YAFFS_TRACE_BAD_BLOCKS |
41         YAFFS_TRACE_VERIFY | 
42         
43         0;
44         
45
46 static int yaffsfs_lastError;
47
48 void yaffsfs_SetError(int err)
49 {
50         //Do whatever to set error
51         yaffsfs_lastError = err;
52 }
53
54
55 int yaffsfs_GetLastError(void)
56 {
57         return yaffsfs_lastError;
58 }
59
60 void yaffsfs_Lock(void)
61 {
62 }
63
64 void yaffsfs_Unlock(void)
65 {
66 }
67
68 __u32 yaffsfs_CurrentTime(void)
69 {
70         return 0;
71 }
72
73
74 static int yaffs_kill_alloc = 0;
75 static size_t total_malloced = 0;
76 static size_t malloc_limit = 0 & 6000000;
77
78 void *yaffs_malloc(size_t size)
79 {
80         void * this;
81         if(yaffs_kill_alloc)
82                 return NULL;
83         if(malloc_limit && malloc_limit <(total_malloced + size) )
84                 return NULL;
85
86         this = malloc(size);
87         if(this)
88                 total_malloced += size;
89         return this;
90 }
91
92 void yaffs_free(void *ptr)
93 {
94         free(ptr);
95 }
96
97 void yaffsfs_LocalInitialisation(void)
98 {
99         // Define locking semaphore.
100 }
101
102 // Configuration
103
104 #include "yaffs_ramdisk.h"
105 #include "yaffs_flashif.h"
106 #include "yaffs_flashif2.h"
107 #include "yaffs_nandemul2k.h"
108
109 struct yaffs_DeviceStruct ram1Dev;
110 struct yaffs_DeviceStruct flashDev;
111 struct yaffs_DeviceStruct m18_1Dev;
112
113 int yaffs_StartUp(void)
114 {
115         // Stuff to configure YAFFS
116         // Stuff to initialise anything special (eg lock semaphore).
117         yaffsfs_LocalInitialisation();
118         
119         // Set up devices
120         // /ram1   ram, yaffs1
121         memset(&ram1Dev,0,sizeof(ram1Dev));
122         ram1Dev.param.name = "ram1";
123         ram1Dev.param.totalBytesPerChunk = 512;
124         ram1Dev.param.nChunksPerBlock = 32;
125         ram1Dev.param.nReservedBlocks = 2; // Set this smaller for RAM
126         ram1Dev.param.startBlock = 0; // Can use block 0
127         ram1Dev.param.endBlock = 127; // Last block in 2MB.     
128         //ram1Dev.param.useNANDECC = 1;
129         ram1Dev.param.nShortOpCaches = 0;       // Disable caching on this device.
130         ram1Dev.driverContext = (void *) 0;     // Used to identify the device in fstat.
131         ram1Dev.param.writeChunkWithTagsToNAND = yramdisk_WriteChunkWithTagsToNAND;
132         ram1Dev.param.readChunkWithTagsFromNAND = yramdisk_ReadChunkWithTagsFromNAND;
133         ram1Dev.param.eraseBlockInNAND = yramdisk_EraseBlockInNAND;
134         ram1Dev.param.initialiseNAND = yramdisk_InitialiseNAND;
135         
136         yaffs_AddDevice(&ram1Dev);
137
138         // /M18-1 yaffs1 on M18 nor sim
139         memset(&m18_1Dev,0,sizeof(m18_1Dev));
140         m18_1Dev.param.name = "M18-1";
141         m18_1Dev.param.totalBytesPerChunk = 1024;
142         m18_1Dev.param.nChunksPerBlock =248;
143         m18_1Dev.param.nReservedBlocks = 2;
144         m18_1Dev.param.startBlock = 0; // Can use block 0
145         m18_1Dev.param.endBlock = 31; // Last block
146         m18_1Dev.param.useNANDECC = 0; // use YAFFS's ECC
147         m18_1Dev.param.nShortOpCaches = 10; // Use caches
148         m18_1Dev.driverContext = (void *) 1;    // Used to identify the device in fstat.
149         m18_1Dev.param.writeChunkToNAND = ynorif1_WriteChunkToNAND;
150         m18_1Dev.param.readChunkFromNAND = ynorif1_ReadChunkFromNAND;
151         m18_1Dev.param.eraseBlockInNAND = ynorif1_EraseBlockInNAND;
152         m18_1Dev.param.initialiseNAND = ynorif1_InitialiseNAND;
153         m18_1Dev.param.deinitialiseNAND = ynorif1_DeinitialiseNAND;
154
155         yaffs_AddDevice(&m18_1Dev);
156
157         // /yaffs2  yaffs2 file emulation
158         // 2kpage/64chunk per block
159         //
160         memset(&flashDev,0,sizeof(flashDev));
161         flashDev.param.name = "yaffs2";
162         flashDev.param.totalBytesPerChunk = 2048;
163         flashDev.param.nChunksPerBlock = 64;
164         flashDev.param.nReservedBlocks = 5;
165         flashDev.param.inbandTags = 0;
166         flashDev.param.startBlock = 0;
167         flashDev.param.endBlock = yflash2_GetNumberOfBlocks()-1;
168         flashDev.param.isYaffs2 = 1;
169         flashDev.param.useNANDECC=1;
170         flashDev.param.wideTnodesDisabled=0;
171         flashDev.param.refreshPeriod = 1000;
172         flashDev.param.nShortOpCaches = 10; // Use caches
173         flashDev.driverContext = (void *) 2;    // Used to identify the device in fstat.
174         flashDev.param.writeChunkWithTagsToNAND = yflash2_WriteChunkWithTagsToNAND;
175         flashDev.param.readChunkWithTagsFromNAND = yflash2_ReadChunkWithTagsFromNAND;
176         flashDev.param.eraseBlockInNAND = yflash2_EraseBlockInNAND;
177         flashDev.param.initialiseNAND = yflash2_InitialiseNAND;
178         flashDev.param.markNANDBlockBad = yflash2_MarkNANDBlockBad;
179         flashDev.param.queryNANDBlock = yflash2_QueryNANDBlock;
180         flashDev.param.enableXattr = 1;
181
182         yaffs_AddDevice(&flashDev);
183
184 // todo yaffs_initialise(yaffsfs_config);
185         
186         return 0;
187 }
188
189
190