yaffs: Change __uxx types to uxx
[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_trace_mask = 
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_dev_s ram1Dev;
110 struct yaffs_dev_s flashDev;
111 struct yaffs_dev_s m18_1Dev;
112
113 int yaffs_start_up(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.total_bytes_per_chunk = 512;
124         ram1Dev.param.chunks_per_block = 32;
125         ram1Dev.param.n_reserved_blocks = 2; // Set this smaller for RAM
126         ram1Dev.param.start_block = 0; // Can use block 0
127         ram1Dev.param.end_block = 127; // Last block in 2MB.    
128         //ram1Dev.param.use_nand_ecc = 1;
129         ram1Dev.param.n_caches = 0;     // Disable caching on this device.
130         ram1Dev.driver_context = (void *) 0;    // Used to identify the device in fstat.
131         ram1Dev.param.write_chunk_tags_fn = yramdisk_wr_chunk;
132         ram1Dev.param.read_chunk_tags_fn = yramdisk_rd_chunk;
133         ram1Dev.param.erase_fn = yramdisk_erase;
134         ram1Dev.param.initialise_flash_fn = yramdisk_initialise;
135         
136         yaffs_add_device(&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.total_bytes_per_chunk = 1024;
142         m18_1Dev.param.chunks_per_block =248;
143         m18_1Dev.param.n_reserved_blocks = 2;
144         m18_1Dev.param.start_block = 0; // Can use block 0
145         m18_1Dev.param.end_block = 31; // Last block
146         m18_1Dev.param.use_nand_ecc = 0; // use YAFFS's ECC
147         m18_1Dev.param.n_caches = 10; // Use caches
148         m18_1Dev.driver_context = (void *) 1;   // Used to identify the device in fstat.
149         m18_1Dev.param.write_chunk_fn = ynorif1_WriteChunkToNAND;
150         m18_1Dev.param.read_chunk_fn = ynorif1_ReadChunkFromNAND;
151         m18_1Dev.param.erase_fn = ynorif1_EraseBlockInNAND;
152         m18_1Dev.param.initialise_flash_fn = ynorif1_InitialiseNAND;
153         m18_1Dev.param.deinitialise_flash_fn = ynorif1_Deinitialise_flash_fn;
154
155 //      m18_1Dev.param.disable_soft_del = 1;
156
157         yaffs_add_device(&m18_1Dev);
158
159         // /yaffs2  yaffs2 file emulation
160         // 2kpage/64chunk per block
161         //
162         memset(&flashDev,0,sizeof(flashDev));
163         flashDev.param.name = "yaffs2";
164         flashDev.param.total_bytes_per_chunk = 2048;
165         flashDev.param.chunks_per_block = 64;
166         flashDev.param.n_reserved_blocks = 5;
167         flashDev.param.inband_tags = 0;
168         flashDev.param.start_block = 0;
169         flashDev.param.end_block = yflash2_GetNumberOfBlocks()-1;
170         flashDev.param.is_yaffs2 = 1;
171         flashDev.param.use_nand_ecc=1;
172         flashDev.param.wide_tnodes_disabled=0;
173         flashDev.param.refresh_period = 1000;
174         flashDev.param.n_caches = 10; // Use caches
175         flashDev.driver_context = (void *) 2;   // Used to identify the device in fstat.
176         flashDev.param.write_chunk_tags_fn = yflash2_WriteChunkWithTagsToNAND;
177         flashDev.param.read_chunk_tags_fn = yflash2_ReadChunkWithTagsFromNAND;
178         flashDev.param.erase_fn = yflash2_EraseBlockInNAND;
179         flashDev.param.initialise_flash_fn = yflash2_InitialiseNAND;
180         flashDev.param.bad_block_fn = yflash2_MarkNANDBlockBad;
181         flashDev.param.query_block_fn = yflash2_QueryNANDBlock;
182         flashDev.param.enable_xattr = 1;
183
184         yaffs_add_device(&flashDev);
185
186 // todo yaffs_initialise(yaffsfs_config);
187         
188         return 0;
189 }
190
191
192