2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
4 * Copyright (C) 2002-2007 Aleph One Ltd.
5 * for Toby Churchill Ltd and Brightstar Engineering
7 * Created by Charles Manning <charles@aleph1.co.uk>
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.
15 * yaffscfg2k.c The configuration for the "direct" use of yaffs.
17 * This file is intended to be modified to your requirements.
18 * There is no need to redistribute this file.
23 #include "yaffs_fileem2k.h"
24 #include "yaffs_nandemul2k.h"
25 #include "yaffs_norif1.h"
29 unsigned yaffs_traceMask =
36 YAFFS_TRACE_ALLOCATE |
37 YAFFS_TRACE_BAD_BLOCKS |
43 static int yaffsfs_lastError;
45 void yaffsfs_SetError(int err)
47 //Do whatever to set error
48 yaffsfs_lastError = err;
52 int yaffsfs_GetLastError(void)
54 return yaffsfs_lastError;
57 void yaffsfs_Lock(void)
61 void yaffsfs_Unlock(void)
65 __u32 yaffsfs_CurrentTime(void)
71 static int yaffs_kill_alloc = 0;
72 static size_t total_malloced = 0;
73 static size_t malloc_limit = 0 & 6000000;
75 void *yaffs_malloc(size_t size)
80 if(malloc_limit && malloc_limit <(total_malloced + size) )
85 total_malloced += size;
89 void yaffs_free(void *ptr)
94 void yaffsfs_LocalInitialisation(void)
96 // Define locking semaphore.
101 // /boot 2MB boot disk (flash)
102 // /flash 14MB flash disk (flash)
103 // NB Though /boot and /flash occupy the same physical device they
104 // are still disticnt "yaffs_Devices. You may think of these as "partitions"
105 // using non-overlapping areas in the same device.
108 #include "yaffs_ramdisk.h"
109 #include "yaffs_flashif.h"
110 #include "yaffs_flashif2.h"
111 #include "yaffs_nandemul2k.h"
113 static yaffs_Device ram1Dev;
114 static yaffs_Device nand2;
115 static yaffs_Device flashDev;
116 static yaffs_Device ram2kDev;
117 static yaffs_Device m18_1Dev;
119 static yaffsfs_DeviceConfiguration yaffsfs_config[] = {
121 { "/ram1", &ram1Dev},
122 { "/M18-1", &m18_1Dev},
123 { "/yaffs2", &flashDev},
124 { "/ram2k", &ram2kDev},
125 {(void *)0,(void *)0} /* Null entry to terminate list */
129 int yaffs_StartUp(void)
131 // Stuff to configure YAFFS
132 // Stuff to initialise anything special (eg lock semaphore).
133 yaffsfs_LocalInitialisation();
137 memset(&ram1Dev,0,sizeof(ram1Dev));
138 ram1Dev.totalBytesPerChunk = 512;
139 ram1Dev.nChunksPerBlock = 32;
140 ram1Dev.nReservedBlocks = 2; // Set this smaller for RAM
141 ram1Dev.startBlock = 0; // Can use block 0
142 ram1Dev.endBlock = 127; // Last block in 2MB.
143 //ram1Dev.useNANDECC = 1;
144 ram1Dev.nShortOpCaches = 0; // Disable caching on this device.
145 ram1Dev.genericDevice = (void *) 0; // Used to identify the device in fstat.
146 ram1Dev.writeChunkWithTagsToNAND = yramdisk_WriteChunkWithTagsToNAND;
147 ram1Dev.readChunkWithTagsFromNAND = yramdisk_ReadChunkWithTagsFromNAND;
148 ram1Dev.eraseBlockInNAND = yramdisk_EraseBlockInNAND;
149 ram1Dev.initialiseNAND = yramdisk_InitialiseNAND;
151 // /M18-1 yaffs1 on M18 nor sim
152 memset(&m18_1Dev,0,sizeof(m18_1Dev));
153 m18_1Dev.totalBytesPerChunk = 1024;
154 m18_1Dev.nChunksPerBlock =248;
155 m18_1Dev.nReservedBlocks = 2;
156 m18_1Dev.startBlock = 0; // Can use block 0
157 m18_1Dev.endBlock = 31; // Last block
158 m18_1Dev.useNANDECC = 0; // use YAFFS's ECC
159 m18_1Dev.nShortOpCaches = 10; // Use caches
160 m18_1Dev.genericDevice = (void *) 1; // Used to identify the device in fstat.
161 m18_1Dev.writeChunkToNAND = ynorif1_WriteChunkToNAND;
162 m18_1Dev.readChunkFromNAND = ynorif1_ReadChunkFromNAND;
163 m18_1Dev.eraseBlockInNAND = ynorif1_EraseBlockInNAND;
164 m18_1Dev.initialiseNAND = ynorif1_InitialiseNAND;
165 m18_1Dev.deinitialiseNAND = ynorif1_DeinitialiseNAND;
169 // Set this puppy up to use
170 // the file emulation space as
171 // 2kpage/64chunk per block
173 memset(&flashDev,0,sizeof(flashDev));
175 flashDev.totalBytesPerChunk = 2048;
176 flashDev.nChunksPerBlock = 64;
177 flashDev.nReservedBlocks = 5;
178 flashDev.inbandTags = 0;
179 flashDev.startBlock = 0;
180 flashDev.endBlock = yflash2_GetNumberOfBlocks()-1;
181 flashDev.isYaffs2 = 1;
182 flashDev.wideTnodesDisabled=0;
183 flashDev.nShortOpCaches = 10; // Use caches
184 flashDev.genericDevice = (void *) 2; // Used to identify the device in fstat.
185 flashDev.writeChunkWithTagsToNAND = yflash2_WriteChunkWithTagsToNAND;
186 flashDev.readChunkWithTagsFromNAND = yflash2_ReadChunkWithTagsFromNAND;
187 flashDev.eraseBlockInNAND = yflash2_EraseBlockInNAND;
188 flashDev.initialiseNAND = yflash2_InitialiseNAND;
189 flashDev.markNANDBlockBad = yflash2_MarkNANDBlockBad;
190 flashDev.queryNANDBlock = yflash2_QueryNANDBlock;
193 yaffs_initialise(yaffsfs_config);
200 void SetCheckpointReservedBlocks(int n)
202 // flashDev.nCheckpointReservedBlocks = n;