xref: /nrf52832-nimble/rt-thread/components/dfs/filesystems/uffs/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 MAX_DIRTY_BUF_GROUPS
99  */
100 #define MAX_DIRTY_BUF_GROUPS	3
101 
102 /**
103  * \def CONFIG_ENABLE_UFFS_DEBUG_MSG
104  * \note Enable debug message output. You must call uffs_InitDebugMessageOutput()
105  *      to initialize debug apart from enable debug feature.
106  */
107 #define CONFIG_ENABLE_UFFS_DEBUG_MSG
108 
109 /**
110  * \def CONFIG_USE_GLOBAL_FS_LOCK
111  * \note use global lock instead of per-device lock.
112  *       this is required if you use fd APIs in multi-thread environment.
113  */
114 #define CONFIG_USE_GLOBAL_FS_LOCK
115 
116 
117 /**
118  * \def CONFIG_USE_PER_DEVICE_LOCK
119  * \note use per-device lock.
120  *		 this is required if you use fs APIs in multi-thread environment.
121  */
122 //#define CONFIG_USE_PER_DEVICE_LOCK
123 
124 
125 
126 /**
127  * \def CONFIG_USE_STATIC_MEMORY_ALLOCATOR
128  * \note uffs will use static memory allocator if this is defined.
129  *       to use static memory allocator, you need to provide memory
130  *       buffer when creating uffs_Device.
131  *
132  *       use UFFS_STATIC_BUFF_SIZE() to calculate memory buffer size.
133  */
134 #define CONFIG_USE_STATIC_MEMORY_ALLOCATOR 0
135 
136 /**
137  * \def CONFIG_USE_SYSTEM_MEMORY_ALLOCATOR
138  * \note  using system platform's 'malloc' and 'free'.
139  */
140 #define CONFIG_USE_SYSTEM_MEMORY_ALLOCATOR 1
141 
142 
143 
144 /**
145  * \def CONFIG_FLUSH_BUF_AFTER_WRITE
146  * \note UFFS will write all data directly into flash in
147  *       each 'write' call if you enable this option.
148  *       (which means lesser data lost when power failure but
149  *		 poorer writing performance).
150  *		 It's not recommended to open this define for normal applications.
151  */
152 #define CONFIG_FLUSH_BUF_AFTER_WRITE
153 
154 
155 /**
156  * \def CONFIG_UFFS_AUTO_LAYOUT_MTD_COMP
157  * \note Use Linux MTD compatiable spare placement for UFFS_LAYOUT_AUTO,
158  *       only valid for page data size 512 or 2048.
159  */
160 //#define CONFIG_UFFS_AUTO_LAYOUT_USE_MTD_SCHEME
161 
162 
163 /**
164  * \def MAX_OBJECT_HANDLE
165  * maximum number of object handle
166  */
167 #define MAX_OBJECT_HANDLE	50
168 #define FD_SIGNATURE_SHIFT	6
169 
170 
171 /**
172  * \def MAX_DIR_HANDLE
173  * maximum number of uffs_DIR
174  */
175 #define MAX_DIR_HANDLE 10
176 
177 /**
178  * \def MINIMUN_ERASED_BLOCK
179  *  UFFS will not allow appending or creating new files when the free/erased block
180  *  is lower then MINIMUN_ERASED_BLOCK.
181  */
182 #define MINIMUN_ERASED_BLOCK 2
183 
184 /**
185  * \def CONFIG_CHANGE_MODIFY_TIME
186  * \note If defined, closing a file which is opened for writing/appending will
187  *       update the file's modify time as well. Disable this feature will save a
188  *       lot of writing activities if you frequently open files for write and close it.
189  */
190 //#define CONFIG_CHANGE_MODIFY_TIME
191 
192 
193 /**
194  * \def CONFIG_ENABLE_BAD_BLOCK_VERIFY
195  * \note allow erase and verify block marked as 'bad' when format UFFS partition.
196  *		it's not recommended for most NAND flash.
197  */
198 #define CONFIG_ENABLE_BAD_BLOCK_VERIFY
199 
200 /**
201  * \def CONFIG_ERASE_BLOCK_BEFORE_MARK_BAD
202  * \note erase block again before mark bad block
203  */
204 //#define CONFIG_ERASE_BLOCK_BEFORE_MARK_BAD
205 
206 /**
207  * \def CONFIG_PAGE_WRITE_VERIFY
208  * \note verify page data after write, for extra safe data storage.
209  */
210 #define CONFIG_PAGE_WRITE_VERIFY
211 
212 /**
213  * \def CONFIG_BAD_BLOCK_POLICY_STRICT
214  * \note If this is enabled, UFFS will report the block as 'bad' if any bit-flips found;
215  *       otherwise, UFFS report bad block only when ECC failed or reported
216  *		 by low level flash driver.
217  *
218  * \note Enable this will ensure your data always be stored on completely good blocks.
219  */
220 #define CONFIG_BAD_BLOCK_POLICY_STRICT
221 
222 
223 /**
224  * \def CONFIG_ENABLE_PAGE_DATA_CRC
225  * \note If this is enabled, UFFS save page data CRC16 sum in mini header,
226  *       it provides extra protection for data integrity.
227  */
228 #define CONFIG_ENABLE_PAGE_DATA_CRC
229 
230 
231 /** micros for calculating buffer sizes */
232 
233 /**
234  *	\def UFFS_BLOCK_INFO_BUFFER_SIZE
235  *	\brief calculate memory bytes for block info caches
236  */
237 #define UFFS_BLOCK_INFO_BUFFER_SIZE(n_pages_per_block)	\
238 			(											\
239 				(										\
240 					sizeof(uffs_BlockInfo) +			\
241 					sizeof(uffs_PageSpare) * n_pages_per_block \
242 				 ) * MAX_CACHED_BLOCK_INFO				\
243 			)
244 
245 /**
246  *	\def UFFS_PAGE_BUFFER_SIZE
247  *	\brief calculate memory bytes for page buffers
248  */
249 #define UFFS_PAGE_BUFFER_SIZE(n_page_size)	\
250 			(								\
251 				(							\
252 					sizeof(uffs_Buf) + n_page_size	\
253 				) * MAX_PAGE_BUFFERS		\
254 			)
255 
256 /**
257  *	\def UFFS_TREE_BUFFER_SIZE
258  *	\brief calculate memory bytes for tree nodes
259  */
260 #define UFFS_TREE_BUFFER_SIZE(n_blocks) (sizeof(TreeNode) * n_blocks)
261 
262 
263 #define UFFS_SPARE_BUFFER_SIZE (MAX_SPARE_BUFFERS * UFFS_MAX_SPARE_SIZE)
264 
265 
266 /**
267  *	\def UFFS_STATIC_BUFF_SIZE
268  *	\brief calculate total memory usage of uffs system
269  */
270 #define UFFS_STATIC_BUFF_SIZE(n_pages_per_block, n_page_size, n_blocks) \
271 			(		\
272 				UFFS_BLOCK_INFO_BUFFER_SIZE(n_pages_per_block) + \
273 				UFFS_PAGE_BUFFER_SIZE(n_page_size) + \
274 				UFFS_TREE_BUFFER_SIZE(n_blocks) + \
275 				UFFS_SPARE_BUFFER_SIZE \
276 			 )
277 
278 
279 
280 /* config check */
281 #if (MAX_PAGE_BUFFERS - CLONE_BUFFERS_THRESHOLD) < 3
282 #error "MAX_PAGE_BUFFERS is too small"
283 #endif
284 
285 #if (MAX_DIRTY_PAGES_IN_A_BLOCK < 2)
286 #error "MAX_DIRTY_PAGES_IN_A_BLOCK should >= 2"
287 #endif
288 
289 #if (MAX_PAGE_BUFFERS - CLONE_BUFFERS_THRESHOLD - 1 < MAX_DIRTY_PAGES_IN_A_BLOCK)
290 #error "MAX_DIRTY_PAGES_IN_A_BLOCK should < (MAX_PAGE_BUFFERS - CLONE_BUFFERS_THRESHOLD)"
291 #endif
292 
293 #if defined(CONFIG_PAGE_WRITE_VERIFY) && (CLONE_BUFFERS_THRESHOLD < 2)
294 #error "CLONE_BUFFERS_THRESHOLD should >= 2 when CONFIG_PAGE_WRITE_VERIFY is enabled."
295 #endif
296 
297 #if CONFIG_USE_STATIC_MEMORY_ALLOCATOR + CONFIG_USE_SYSTEM_MEMORY_ALLOCATOR > 1
298 #error "Please enable ONLY one memory allocator"
299 #endif
300 
301 #if CONFIG_USE_STATIC_MEMORY_ALLOCATOR + CONFIG_USE_SYSTEM_MEMORY_ALLOCATOR == 0
302 #error "Please enable ONE of memory allocators"
303 #endif
304 
305 #if defined(CONFIG_USE_GLOBAL_FS_LOCK) && defined(CONFIG_USE_PER_DEVICE_LOCK)
306 #error "enable either CONFIG_USE_GLOBAL_FS_LOCK or CONFIG_USE_PER_DEVICE_LOCK, not both"
307 #endif
308 
309 #if (MAX_OBJECT_HANDLE > (1 << FD_SIGNATURE_SHIFT))
310 #error "Please increase FD_SIGNATURE_SHIFT !"
311 #endif
312 
313 #ifdef WIN32
314 # pragma warning(disable : 4996)
315 # pragma warning(disable : 4244)
316 # pragma warning(disable : 4214)
317 # pragma warning(disable : 4127)
318 # pragma warning(disable : 4389)
319 # pragma warning(disable : 4100)
320 #endif
321 
322 #endif
323