yaffs: Add xattrib support
[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
101
102 #include "yaffs_ramdisk.h"
103 #include "yaffs_flashif.h"
104 #include "yaffs_flashif2.h"
105 #include "yaffs_nandemul2k.h"
106
107 static yaffs_Device ram1Dev;
108 static yaffs_Device flashDev;
109 static yaffs_Device ram2kDev;
110 static yaffs_Device m18_1Dev;
111
112 static yaffsfs_DeviceConfiguration yaffsfs_config[] = {
113
114         { "/ram1", &ram1Dev},
115         { "/M18-1", &m18_1Dev},
116         { "/yaffs2", &flashDev},
117         { "/ram2k", &ram2kDev},
118         { NULL, NULL } /* Null entry to terminate list */
119 };
120
121
122 int yaffs_StartUp(void)
123 {
124         // Stuff to configure YAFFS
125         // Stuff to initialise anything special (eg lock semaphore).
126         yaffsfs_LocalInitialisation();
127         
128         // Set up devices
129         // /ram1   ram, yaffs1
130         memset(&ram1Dev,0,sizeof(ram1Dev));
131         ram1Dev.param.totalBytesPerChunk = 512;
132         ram1Dev.param.nChunksPerBlock = 32;
133         ram1Dev.param.nReservedBlocks = 2; // Set this smaller for RAM
134         ram1Dev.param.startBlock = 0; // Can use block 0
135         ram1Dev.param.endBlock = 127; // Last block in 2MB.     
136         //ram1Dev.param.useNANDECC = 1;
137         ram1Dev.param.nShortOpCaches = 0;       // Disable caching on this device.
138         ram1Dev.context = (void *) 0;   // Used to identify the device in fstat.
139         ram1Dev.param.writeChunkWithTagsToNAND = yramdisk_WriteChunkWithTagsToNAND;
140         ram1Dev.param.readChunkWithTagsFromNAND = yramdisk_ReadChunkWithTagsFromNAND;
141         ram1Dev.param.eraseBlockInNAND = yramdisk_EraseBlockInNAND;
142         ram1Dev.param.initialiseNAND = yramdisk_InitialiseNAND;
143
144         // /M18-1 yaffs1 on M18 nor sim
145         memset(&m18_1Dev,0,sizeof(m18_1Dev));
146         m18_1Dev.param.totalBytesPerChunk = 1024;
147         m18_1Dev.param.nChunksPerBlock =248;
148         m18_1Dev.param.nReservedBlocks = 2;
149         m18_1Dev.param.startBlock = 0; // Can use block 0
150         m18_1Dev.param.endBlock = 31; // Last block
151         m18_1Dev.param.useNANDECC = 0; // use YAFFS's ECC
152         m18_1Dev.param.nShortOpCaches = 10; // Use caches
153         m18_1Dev.context = (void *) 1;  // Used to identify the device in fstat.
154         m18_1Dev.param.writeChunkToNAND = ynorif1_WriteChunkToNAND;
155         m18_1Dev.param.readChunkFromNAND = ynorif1_ReadChunkFromNAND;
156         m18_1Dev.param.eraseBlockInNAND = ynorif1_EraseBlockInNAND;
157         m18_1Dev.param.initialiseNAND = ynorif1_InitialiseNAND;
158         m18_1Dev.param.deinitialiseNAND = ynorif1_DeinitialiseNAND;
159
160
161         // /yaffs2  yaffs2 file emulation
162         // 2kpage/64chunk per block
163         //
164         memset(&flashDev,0,sizeof(flashDev));
165
166         flashDev.param.totalBytesPerChunk = 2048;
167         flashDev.param.nChunksPerBlock = 64;
168         flashDev.param.nReservedBlocks = 5;
169         flashDev.param.inbandTags = 0;
170         flashDev.param.startBlock = 0;
171         flashDev.param.endBlock = yflash2_GetNumberOfBlocks()-1;
172         flashDev.param.isYaffs2 = 1;
173         flashDev.param.useNANDECC=1;
174         flashDev.param.wideTnodesDisabled=0;
175         flashDev.param.refreshPeriod = 1000;
176         flashDev.param.nShortOpCaches = 10; // Use caches
177         flashDev.context = (void *) 2;  // Used to identify the device in fstat.
178         flashDev.param.writeChunkWithTagsToNAND = yflash2_WriteChunkWithTagsToNAND;
179         flashDev.param.readChunkWithTagsFromNAND = yflash2_ReadChunkWithTagsFromNAND;
180         flashDev.param.eraseBlockInNAND = yflash2_EraseBlockInNAND;
181         flashDev.param.initialiseNAND = yflash2_InitialiseNAND;
182         flashDev.param.markNANDBlockBad = yflash2_MarkNANDBlockBad;
183         flashDev.param.queryNANDBlock = yflash2_QueryNANDBlock;
184         flashDev.param.enableXattr = 1;
185
186
187         yaffs_initialise(yaffsfs_config);
188         
189         return 0;
190 }
191
192
193