xref: /nrf52832-nimble/rt-thread/components/dfs/filesystems/uffs/src/platform/win32/uffs_config.h (revision 104654410c56c573564690304ae786df310c91fc)
1 /*
2   This file is part of UFFS, the Ultra-low-cost Flash File System.
3 
4   Copyright (C) 2005-2009 Ricky Zheng <[email protected]>
5 
6   UFFS is free software; you can redistribute it and/or modify it under
7   the GNU Library General Public License as published by the Free Software
8   Foundation; either version 2 of the License, or (at your option) any
9   later version.
10 
11   UFFS is distributed in the hope that it will be useful, but WITHOUT
12   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14   or GNU Library General Public License, as applicable, for more details.
15 
16   You should have received a copy of the GNU General Public License
17   and GNU Library General Public License along with UFFS; if not, write
18   to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19   Boston, MA  02110-1301, USA.
20 
21   As a special exception, if other files instantiate templates or use
22   macros or inline functions from this file, or you compile this file
23   and link it with other works to produce a work based on this file,
24   this file does not by itself cause the resulting work to be covered
25   by the GNU General Public License. However the source code for this
26   file must still be made available in accordance with section (3) of
27   the GNU General Public License v2.
28 
29   This exception does not invalidate any other reasons why a work based
30   on this file might be covered by the GNU General Public License.
31 */
32 
33 /**
34  * \file uffs_config.h
35  * \brief basic configuration of uffs
36  * \author Ricky Zheng
37  */
38 
39 #ifndef _UFFS_CONFIG_H_
40 #define _UFFS_CONFIG_H_
41 
42 /**
43  * \def UFFS_MAX_PAGE_SIZE
44  * \note maximum page size UFFS support
45  */
46 #define UFFS_MAX_PAGE_SIZE		2048
47 
48 /**
49  * \def UFFS_MAX_SPARE_SIZE
50  */
51 #define UFFS_MAX_SPARE_SIZE ((UFFS_MAX_PAGE_SIZE / 256) * 8)
52 
53 /**
54  * \def UFFS_MAX_ECC_SIZE
55  */
56 #define UFFS_MAX_ECC_SIZE  ((UFFS_MAX_PAGE_SIZE / 256) * 5)
57 
58 /**
59  * \def MAX_CACHED_BLOCK_INFO
60  * \note uffs cache the block info for opened directories and files,
61  *       a practical value is 5 ~ MAX_OBJECT_HANDLE
62  */
63 #define MAX_CACHED_BLOCK_INFO	50
64 
65 /**
66  * \def MAX_PAGE_BUFFERS
67  * \note the bigger value will bring better read/write performance.
68  *       but few writing performance will be improved when this
69  *       value is become larger than 'max pages per block'
70  */
71 #define MAX_PAGE_BUFFERS		40
72 
73 
74 /**
75  * \def CLONE_BUFFER_THRESHOLD
76  * \note reserve buffers for clone. 1 or 2 should be enough.
77  */
78 #define CLONE_BUFFERS_THRESHOLD	2
79 
80 /**
81  * \def MAX_SPARE_BUFFERS
82  * \note spare buffers are used for lower level flash operations,
83  *		 5 should be enough.
84  */
85 #define MAX_SPARE_BUFFERS		5
86 
87 
88 /**
89  * \def MAX_DIRTY_PAGES_IN_A_BLOCK
90  * \note this value should be between '2' and the lesser of
91  *		 'max pages per block' and (MAX_PAGE_BUFFERS - CLONE_BUFFERS_THRESHOLD - 1).
92  *
93  *       the smaller the value the frequently the buffer will be flushed.
94  */
95 #define MAX_DIRTY_PAGES_IN_A_BLOCK	32
96 
97 /**
98  * \def CONFIG_ENABLE_UFFS_DEBUG_MSG
99  * \note Enable debug message output. You must call uffs_InitDebugMessageOutput()
100  *      to initialize debug apart from enable debug feature.
101  */
102 #define CONFIG_ENABLE_UFFS_DEBUG_MSG
103 
104 /**
105  * \def CONFIG_USE_GLOBAL_FS_LOCK
106  * \note use global lock instead of per-device lock.
107  *       this is required if you use fd APIs in multi-thread environment.
108  */
109 #define CONFIG_USE_GLOBAL_FS_LOCK
110 
111 
112 /**
113  * \def CONFIG_USE_PER_DEVICE_LOCK
114  * \note use per-device lock.
115  *		 this is required if you use fs APIs in multi-thread environment.
116  */
117 //#define CONFIG_USE_PER_DEVICE_LOCK
118 
119 
120 
121 /**
122  * \def CONFIG_USE_STATIC_MEMORY_ALLOCATOR
123  * \note uffs will use static memory allocator if this is defined.
124  *       to use static memory allocator, you need to provide memory
125  *       buffer when creating uffs_Device.
126  *
127  *       use UFFS_STATIC_BUFF_SIZE() to calculate memory buffer size.
128  */
129 #define CONFIG_USE_STATIC_MEMORY_ALLOCATOR 0
130 
131 /**
132  * \def CONFIG_USE_SYSTEM_MEMORY_ALLOCATOR
133  * \note  using system platform's 'malloc' and 'free'.
134  */
135 #define CONFIG_USE_SYSTEM_MEMORY_ALLOCATOR 1
136 
137 
138 
139 /**
140  * \def CONFIG_FLUSH_BUF_AFTER_WRITE
141  * \note UFFS will write all data directly into flash in
142  *       each 'write' call if you enable this option.
143  *       (which means lesser data lost when power failure but
144  *		 poorer writing performance).
145  *		 It's not recommended to open this define for normal applications.
146  */
147 //#define CONFIG_FLUSH_BUF_AFTER_WRITE
148 
149 
150 /**
151  * \def CONFIG_UFFS_AUTO_LAYOUT_MTD_COMP
152  * \note Use Linux MTD compatiable spare placement for UFFS_LAYOUT_AUTO,
153  *       only valid for page data size 512 or 2048.
154  */
155 //#define CONFIG_UFFS_AUTO_LAYOUT_USE_MTD_SCHEME
156 
157 
158 /**
159  * \def MAX_OBJECT_HANDLE
160  * maximum number of object handle
161  */
162 #define MAX_OBJECT_HANDLE	50
163 #define FD_SIGNATURE_SHIFT	6
164 
165 
166 /**
167  * \def MAX_DIR_HANDLE
168  * maximum number of uffs_DIR
169  */
170 #define MAX_DIR_HANDLE	10
171 
172 /**
173  * \def MINIMUN_ERASED_BLOCK
174  *  UFFS will not allow appending or creating new files when the free/erased block
175  *  is lower then MINIMUN_ERASED_BLOCK.
176  */
177 #define MINIMUN_ERASED_BLOCK 2
178 
179 /**
180  * \def CONFIG_CHANGE_MODIFY_TIME
181  * \note If defined, closing a file which is opened for writing/appending will
182  *       update the file's modify time as well. Disable this feature will save a
183  *       lot of writing activities if you frequently open files for write and close it.
184  */
185 //#define CONFIG_CHANGE_MODIFY_TIME
186 
187 
188 /**
189  * \def CONFIG_ENABLE_BAD_BLOCK_VERIFY
190  * \note allow erase and verify block marked as 'bad' when format UFFS partition.
191  *		it's not recommended for most NAND flash.
192  */
193 #define CONFIG_ENABLE_BAD_BLOCK_VERIFY
194 
195 /**
196  * \def CONFIG_ERASE_BLOCK_BEFORE_MARK_BAD
197  * \note erase block again before mark bad block
198  */
199 //#define CONFIG_ERASE_BLOCK_BEFORE_MARK_BAD
200 
201 /**
202  * \def CONFIG_PAGE_WRITE_VERIFY
203  * \note verify page data after write, for extra safe data storage.
204  */
205 #define CONFIG_PAGE_WRITE_VERIFY
206 
207 /**
208  * \def CONFIG_BAD_BLOCK_POLICY_STRICT
209  * \note If this is enabled, UFFS will report the block as 'bad' if any bit-flips found;
210  *       otherwise, UFFS report bad block only when ECC failed or reported
211  *		 by low level flash driver.
212  *
213  * \note Enable this will ensure your data always be stored on completely good blocks.
214  */
215 #define CONFIG_BAD_BLOCK_POLICY_STRICT
216 
217 
218 /**
219  * \def CONFIG_ENABLE_PAGE_DATA_CRC
220  * \note If this is enabled, UFFS save page data CRC16 sum in mini header,
221  *       it provides extra protection for data integrity.
222  */
223 //#define CONFIG_ENABLE_PAGE_DATA_CRC
224 
225 
226 /** micros for calculating buffer sizes */
227 
228 /**
229  *	\def UFFS_BLOCK_INFO_BUFFER_SIZE
230  *	\brief calculate memory bytes for block info caches
231  */
232 #define UFFS_BLOCK_INFO_BUFFER_SIZE(n_pages_per_block)	\
233 			(											\
234 				(										\
235 					sizeof(uffs_BlockInfo) +			\
236 					sizeof(uffs_PageSpare) * n_pages_per_block \
237 				 ) * MAX_CACHED_BLOCK_INFO				\
238 			)
239 
240 /**
241  *	\def UFFS_PAGE_BUFFER_SIZE
242  *	\brief calculate memory bytes for page buffers
243  */
244 #define UFFS_PAGE_BUFFER_SIZE(n_page_size)	\
245 			(								\
246 				(							\
247 					sizeof(uffs_Buf) + n_page_size	\
248 				) * MAX_PAGE_BUFFERS		\
249 			)
250 
251 /**
252  *	\def UFFS_TREE_BUFFER_SIZE
253  *	\brief calculate memory bytes for tree nodes
254  */
255 #define UFFS_TREE_BUFFER_SIZE(n_blocks) (sizeof(TreeNode) * n_blocks)
256 
257 
258 #define UFFS_SPARE_BUFFER_SIZE (MAX_SPARE_BUFFERS * UFFS_MAX_SPARE_SIZE)
259 
260 
261 /**
262  *	\def UFFS_STATIC_BUFF_SIZE
263  *	\brief calculate total memory usage of uffs system
264  */
265 #define UFFS_STATIC_BUFF_SIZE(n_pages_per_block, n_page_size, n_blocks) \
266 			(		\
267 				UFFS_BLOCK_INFO_BUFFER_SIZE(n_pages_per_block) + \
268 				UFFS_PAGE_BUFFER_SIZE(n_page_size) + \
269 				UFFS_TREE_BUFFER_SIZE(n_blocks) + \
270 				UFFS_SPARE_BUFFER_SIZE \
271 			 )
272 
273 
274 
275 /* config check */
276 #if (MAX_PAGE_BUFFERS - CLONE_BUFFERS_THRESHOLD) < 3
277 #error "MAX_PAGE_BUFFERS is too small"
278 #endif
279 
280 #if (MAX_DIRTY_PAGES_IN_A_BLOCK < 2)
281 #error "MAX_DIRTY_PAGES_IN_A_BLOCK should >= 2"
282 #endif
283 
284 #if (MAX_PAGE_BUFFERS - CLONE_BUFFERS_THRESHOLD - 1 < MAX_DIRTY_PAGES_IN_A_BLOCK)
285 #error "MAX_DIRTY_PAGES_IN_A_BLOCK should < (MAX_PAGE_BUFFERS - CLONE_BUFFERS_THRESHOLD)"
286 #endif
287 
288 #if defined(CONFIG_PAGE_WRITE_VERIFY) && (CLONE_BUFFERS_THRESHOLD < 2)
289 #error "CLONE_BUFFERS_THRESHOLD should >= 2 when CONFIG_PAGE_WRITE_VERIFY is enabled."
290 #endif
291 
292 #if CONFIG_USE_STATIC_MEMORY_ALLOCATOR + CONFIG_USE_SYSTEM_MEMORY_ALLOCATOR > 1
293 #error "Please enable ONLY one memory allocator"
294 #endif
295 
296 #if CONFIG_USE_STATIC_MEMORY_ALLOCATOR + CONFIG_USE_SYSTEM_MEMORY_ALLOCATOR == 0
297 #error "Please enable ONE of memory allocators"
298 #endif
299 
300 #if defined(CONFIG_USE_GLOBAL_FS_LOCK) && defined(CONFIG_USE_PER_DEVICE_LOCK)
301 #error "enable either CONFIG_USE_GLOBAL_FS_LOCK or CONFIG_USE_PER_DEVICE_LOCK, not both"
302 #endif
303 
304 #if (MAX_OBJECT_HANDLE > (1 << FD_SIGNATURE_SHIFT))
305 #error "Please increase FD_SIGNATURE_SHIFT !"
306 #endif
307 
308 #ifdef WIN32
309 # pragma warning(disable : 4996)
310 # pragma warning(disable : 4244)
311 # pragma warning(disable : 4214)
312 # pragma warning(disable : 4127)
313 # pragma warning(disable : 4389)
314 # pragma warning(disable : 4100)
315 #endif
316 
317 #endif
318