xref: /nrf52832-nimble/rt-thread/components/dfs/filesystems/uffs/README (revision 104654410c56c573564690304ae786df310c91fc)
1*10465441SEvalZeroUFFS: Ultra-low-cost Flash File System
2*10465441SEvalZero
3*10465441SEvalZeroProject: http://uffs.sf.net/
4*10465441SEvalZeroBlog:    http://all-about-uffs.blogspot.com/
5*10465441SEvalZeroQ/A:     http://groups.google.com/group/uffs/
6*10465441SEvalZero
7*10465441SEvalZeroAuthor: Ricky Zheng <[email protected]>
8*10465441SEvalZero
9*10465441SEvalZeroINTRODUCTION
10*10465441SEvalZero------------
11*10465441SEvalZero
12*10465441SEvalZeroUFFS is a nand flash file system designed for embedded system.
13*10465441SEvalZero
14*10465441SEvalZeroUFFS have some unique and advanced features:
15*10465441SEvalZero  * Low cost: e.g. it needs only 41K bytes RAM for 64MB NAND flash (page size 2048).
16*10465441SEvalZero
17*10465441SEvalZero  * Fast booting: it reads only a few spares from each block, typically
18*10465441SEvalZero    mounting a fully filled file system (Gbits) within one second.
19*10465441SEvalZero
20*10465441SEvalZero  * Superb Reliability:
21*10465441SEvalZero    - The file system is designed for the embedded system which may
22*10465441SEvalZero        frequently lost power/reset without care.
23*10465441SEvalZero    - Journal file system, the file system will automatically rollback
24*10465441SEvalZero        to the last state when lost power on the middle of flash programing.
25*10465441SEvalZero    - When 'write' return without error, the data is guarenteed been
26*10465441SEvalZero        saved on flash.
27*10465441SEvalZero
28*10465441SEvalZero  * Fast file create/read/write/seek.
29*10465441SEvalZero  * Bad-block tolerant, ECC enable and good ware-leveling.
30*10465441SEvalZero  * There is no garbage collection needed for UFFS.
31*10465441SEvalZero  * Support multiple NAND flash class in one system.
32*10465441SEvalZero  * Support bare flash hardware, no operating system needed.
33*10465441SEvalZero  * Support static memory allocation (works without 'malloc').
34*10465441SEvalZero  * Fully simulated on PC (Windows/Linux) platform.
35*10465441SEvalZero
36*10465441SEvalZeroDisadvantage:
37*10465441SEvalZero  * space inefficency for small files: UFFS use at least one
38*10465441SEvalZero   'block'(the minial erase unit for NAND flash, e.g. 16K ) for a file.
39*10465441SEvalZero  * maximum supported blocks: 2^16 = 65535
40*10465441SEvalZero
41*10465441SEvalZeroMemory consuming example:
42*10465441SEvalZero    For page size = 512:
43*10465441SEvalZero        [VARY]Tree nodes: 16 * total_blocks
44*10465441SEvalZero        [CONST]Page Bufs: MAX_CACHED_BUFFERS(10) * (40 + pageSize(512)) = 5.4K
45*10465441SEvalZero        [CONST]Block Info caches: (24 + 14 * pages_per_block (32)) * MAX_CACHED_BLOCK_INFO (10) = 4.6K
46*10465441SEvalZero
47*10465441SEvalZero        Example 1: 128M bytes NAND, 8192 blocks, total memory cost:
48*10465441SEvalZero            (16 * 8192)128K + 5.4K + 4.6K = 138K bytes.
49*10465441SEvalZero
50*10465441SEvalZero        Example 2: 32M Bytes NAND, 2048 blocks, total memory cost:
51*10465441SEvalZero            (16 * 2048)32K + 5.4K + 4.6K = 42K bytes.
52*10465441SEvalZero
53*10465441SEvalZero        Example 3: 16M bytes NAND, 1024 blocks, total memory cost:
54*10465441SEvalZero            (16 * 1024)16K + 5.4K + 4.6K = 26K bytes.
55*10465441SEvalZero
56*10465441SEvalZero    For page size = 2048:
57*10465441SEvalZero        [VARY]Tree nodes: 16 * total_blocks
58*10465441SEvalZero        [CONST]Page Bufs: MAX_CACHED_BUFFERS(10) * (40 + pageSize(2048)) = 20.4K
59*10465441SEvalZero        [CONST]Block Info caches: (24 + 14 * pages_per_block (32)) * MAX_CACHED_BLOCK_INFO (10) = 4.6K
60*10465441SEvalZero
61*10465441SEvalZero        Example 1: 512M bytes NAND, 8192 blocks, total memory cost:
62*10465441SEvalZero            (16 * 8192)128K + 20.4K + 4.6K = 153K bytes.
63*10465441SEvalZero
64*10465441SEvalZero        Example 2: 128M Bytes NAND, 2048 blocks, total memory cost:
65*10465441SEvalZero            (16 * 2048)32K + 20.4K + 4.6K = 57K bytes.
66*10465441SEvalZero
67*10465441SEvalZero        Example 3: 64M bytes NAND, 1024 blocks, total memory cost:
68*10465441SEvalZero            (16 * 1024)16K + 20.4K + 4.6K = 41K bytes.
69*10465441SEvalZero
70*10465441SEvalZero
71*10465441SEvalZeroBUILD SIMULATOR REQUIREMENT
72*10465441SEvalZero---------------------------
73*10465441SEvalZeroFrom V1.2.0, build uffs simulator requires 'cmake'.
74*10465441SEvalZero'cmake' can be downloaded from: http://www.cmake.org/
75*10465441SEvalZero
76*10465441SEvalZeroor, under Debian/Ubuntu:
77*10465441SEvalZero  sudo apt-get install cmake
78*10465441SEvalZero
79*10465441SEvalZeroBUILD SIMULATOR ON LINUX
80*10465441SEvalZero------------------------
81*10465441SEvalZero1) create a 'build' dir:
82*10465441SEvalZero
83*10465441SEvalZeromkdir -p ~/build/uffs
84*10465441SEvalZero
85*10465441SEvalZero2) create Makefiles and build:
86*10465441SEvalZero  cd ~/build/uffs
87*10465441SEvalZero  cmake <path_to_uffs>
88*10465441SEvalZero  make
89*10465441SEvalZero
90*10465441SEvalZero5) run simulator (interactive mode):
91*10465441SEvalZero  src/utils/mkuffs
92*10465441SEvalZero
93*10465441SEvalZero
94*10465441SEvalZeroBUILD SIMULATOR ON WINDOWS
95*10465441SEvalZero--------------------------
96*10465441SEvalZero
97*10465441SEvalZero1) create a 'build' dir along with uffs source dir,
98*10465441SEvalZero d:\build\uffs
99*10465441SEvalZero
100*10465441SEvalZero2) Create VC project files:
101*10465441SEvalZero  cd build\uffs
102*10465441SEvalZero  cmake <path_to_uffs>
103*10465441SEvalZero
104*10465441SEvalZero3) Open uffs.dsw (or uffs.sln for VC > 6 ), compile & run.
105*10465441SEvalZero
106*10465441SEvalZero
107*10465441SEvalZeroLATEST SOURCE CODE
108*10465441SEvalZero------------------
109*10465441SEvalZeroYou can get the latest source code from git repository:
110*10465441SEvalZero  git clone git://uffs.git.sourceforge.net/gitroot/uffs/uffs
111*10465441SEvalZero
112*10465441SEvalZero
113*10465441SEvalZeroCURRENT STATUS
114*10465441SEvalZero--------------
115*10465441SEvalZeroUFFS 0.1.x is a working version on PC simulator, also has been ported to
116*10465441SEvalZerouBase embedded OS as a 'real world' product for thousands of copies,
117*10465441SEvalZeroit works fine so far.
118*10465441SEvalZero
119*10465441SEvalZeroUFFS 0.2.0 implementes full directory.
120*10465441SEvalZero
121*10465441SEvalZeroUFFS 1.0.0 is the first stable release at sf.net.
122*10465441SEvalZero
123*10465441SEvalZeroUFFS 1.1.0: support NAND flash with large page size (up to 2K).
124*10465441SEvalZero
125*10465441SEvalZeroUFFS 1.1.1: bug fixes. a tool for making uffs disk image.
126*10465441SEvalZero
127*10465441SEvalZeroUFFS 1.1.2: bug fixes. add more Flash Class. change Licence from GNU GPLv2 to GNU LGPLv2
128*10465441SEvalZero
129*10465441SEvalZeroUFFS 1.2.0:
130*10465441SEvalZero  - eliminate 'current path' and relatives. Now you should use absolute path in all
131*10465441SEvalZero    uffs APIs. For dir, the fullname should end with '/'.
132*10465441SEvalZero  - allow using static memory allocation, 'malloc' is no longer needed.
133*10465441SEvalZero  - using cmake for building simulator.
134*10465441SEvalZero  - bug fixes & minor changes.
135*10465441SEvalZero
136*10465441SEvalZeroUFFS 1.2.1:
137*10465441SEvalZero  - improve bad block management
138*10465441SEvalZero  - bug fixes
139*10465441SEvalZero  - change Licence to modified GNU GPLv2.
140*10465441SEvalZero
141*10465441SEvalZeroUFFS 1.3.0:
142*10465441SEvalZero  - improved flash interface
143*10465441SEvalZero  - support hardware ECC
144*10465441SEvalZero  - support user defined spare layout (for customized NAND flash controller)
145*10465441SEvalZero  - support 4K page size
146*10465441SEvalZero  - no partial page program required, support MLC NAND flash
147*10465441SEvalZero  - reduced buffer flushes by grouping buffers
148*10465441SEvalZero  - structual improvments and bug fixes
149*10465441SEvalZero
150*10465441SEvalZeroUFFS v1.3.1:
151*10465441SEvalZero  - Tidy up three memory allocators: static, native and system.
152*10465441SEvalZero  - Fix bugs in flash interface example.
153*10465441SEvalZero  - Fix memory allocation bugs when using static memory allocator.
154*10465441SEvalZero  - Add flash driver interface 'WriteFullPage()'.
155*10465441SEvalZero  - Fix compilation errors for BlackFin DSP compiler.
156*10465441SEvalZero
157*10465441SEvalZeroUFFS v1.3.2:
158*10465441SEvalZero  - Add POSIX like file system APIs.
159*10465441SEvalZero  - Bug fixes.
160*10465441SEvalZero
161*10465441SEvalZeroUFFS v1.3.3:
162*10465441SEvalZero  - Change Flash Interface, simplify interface.
163*10465441SEvalZero  - Improved bad block handling.
164*10465441SEvalZero  - Better support for MLC NAND flash.
165*10465441SEvalZero  - Added hardware ECC and RS-ECC controller emulator.
166*10465441SEvalZero  - Bug fixes.
167*10465441SEvalZero
168*10465441SEvalZeroUFFS v1.3.4
169*10465441SEvalZero  - New UO_NOECC option for skipping ECC (fast reading).
170*10465441SEvalZero  - POSIX compliance uffs_seek().
171*10465441SEvalZero  - Improved unclean page detection (add new 'seal' byte in spare area).
172*10465441SEvalZero  - Optional page data CRC.
173*10465441SEvalZero  - Bug fixes.
174*10465441SEvalZero  - Other improvements.
175*10465441SEvalZero
176*10465441SEvalZeroLICENCE
177*10465441SEvalZero-------
178*10465441SEvalZero  From v1.2.1, UFFS is released under a modified GNU GPLv2. (the same as eCos Licence)
179*10465441SEvalZero  The full licence text can be found in the header of source files:
180*10465441SEvalZero
181*10465441SEvalZero	  UFFS is free software; you can redistribute it and/or modify it under
182*10465441SEvalZero	  the GNU Library General Public License as published by the Free Software
183*10465441SEvalZero	  Foundation; either version 2 of the License, or (at your option) any
184*10465441SEvalZero	  later version.
185*10465441SEvalZero
186*10465441SEvalZero	  UFFS is distributed in the hope that it will be useful, but WITHOUT
187*10465441SEvalZero	  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
188*10465441SEvalZero	  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
189*10465441SEvalZero	  or GNU Library General Public License, as applicable, for more details.
190*10465441SEvalZero
191*10465441SEvalZero	  You should have received a copy of the GNU General Public License
192*10465441SEvalZero	  and GNU Library General Public License along with UFFS; if not, write
193*10465441SEvalZero	  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
194*10465441SEvalZero	  Boston, MA  02110-1301, USA.
195*10465441SEvalZero
196*10465441SEvalZero	  As a special exception, if other files instantiate templates or use
197*10465441SEvalZero	  macros or inline functions from this file, or you compile this file
198*10465441SEvalZero	  and link it with other works to produce a work based on this file,
199*10465441SEvalZero	  this file does not by itself cause the resulting work to be covered
200*10465441SEvalZero	  by the GNU General Public License. However the source code for this
201*10465441SEvalZero	  file must still be made available in accordance with section (3) of
202*10465441SEvalZero	  the GNU General Public License v2.
203*10465441SEvalZero
204*10465441SEvalZero	  This exception does not invalidate any other reasons why a work based
205*10465441SEvalZero	  on this file might be covered by the GNU General Public License.
206*10465441SEvalZero
207*10465441SEvalZero
208*10465441SEvalZeroTESTING UFFS WITH SQLITE3 REGRESSION TEST CASES
209*10465441SEvalZero-----------------------------------------------
210*10465441SEvalZeroUFFS can be tested with sqlite3 regression test cases (on Linux).
211*10465441SEvalZero
212*10465441SEvalZero1) install tcl8.5-dev on host PC:
213*10465441SEvalZero	apt-get install tcl8.5 tcl8.5-dev
214*10465441SEvalZero
215*10465441SEvalZero    # make sure your Linux is using tcl8.5 as the default tclsh:
216*10465441SEvalZero		sudo update-alternatives --config tclsh
217*10465441SEvalZero		(select "tclsh8.5" from the list.)
218*10465441SEvalZero
219*10465441SEvalZero2) build uffs:
220*10465441SEvalZero	mkdir -p ~/build/uffs
221*10465441SEvalZero	cd ~/build/uffs
222*10465441SEvalZero	cmake <path_to_uffs>
223*10465441SEvalZero
224*10465441SEvalZero3) build sqlite3:
225*10465441SEvalZero	cd <path_to_uffs>/src/test/sqlite3/sqlite-src-3070900
226*10465441SEvalZero	./configure        					 # create some build support files
227*10465441SEvalZero	git checkout -f Makefile config.h    # restore modified Makefile and config.h
228*10465441SEvalZero	make test                            # start build 'testfixture' program.
229*10465441SEvalZero
230*10465441SEvalZero	# now you'll see something like:
231*10465441SEvalZero	Connect: Connection refused
232*10465441SEvalZero	Assert (uffs_ret == ret && ret == bak_ret) fail at /home/.../src/test/api_test/os_uffs.c:os_unlink:329: unlink("/home/.../src/test/sqlite3/sqlite-src-3070900/./test.db-journal"), unix return 0, uffs return -1, bak return -1
233*10465441SEvalZero	make: *** [test] Error 1
234*10465441SEvalZero
235*10465441SEvalZero4) run test cases:
236*10465441SEvalZero	Open two terminals.
237*10465441SEvalZero	on termional A:
238*10465441SEvalZero		cd ~/build/uffs
239*10465441SEvalZero		src/utils/mkuffs -t 1024
240*10465441SEvalZero
241*10465441SEvalZero		#on uffs simulator command line, enter:
242*10465441SEvalZero		format /
243*10465441SEvalZero		apisrv
244*10465441SEvalZero
245*10465441SEvalZero	on terminal B:
246*10465441SEvalZero		cd <path_to_uffs>/src/test/sqlite3/sqlite-src-3070900
247*10465441SEvalZero		./test-uffs.sh
248*10465441SEvalZero
249*10465441SEvalZero	Note: if you want to run mkuffs on another PC, for example, a Windows PC, you need to specify the IP address in test-uffs.sh.
250*10465441SEvalZero
251*10465441SEvalZero	The test will take 1~4 hours, depends on how fast your Linux box is.
252*10465441SEvalZero
253*10465441SEvalZero
254*10465441SEvalZeroACKNOWLEDGMENT
255*10465441SEvalZero---------------
256*10465441SEvalZeroSpecial thanks for your contributions to:
257*10465441SEvalZero(list in no particular order)
258*10465441SEvalZero
259*10465441SEvalZero* Chen Jun <[email protected]>
260*10465441SEvalZero* Michail <[email protected]>
261*10465441SEvalZero* Sjpu <[email protected]>
262*10465441SEvalZero* RobertGray <[email protected]>
263*10465441SEvalZero* Dongbo <[email protected]>
264*10465441SEvalZero* Cag <[email protected]>
265*10465441SEvalZero* Sergey <[email protected]>
266*10465441SEvalZero* Chris Conrad <[email protected]>
267*10465441SEvalZero* Vladimir <[email protected]>
268*10465441SEvalZero* Thien Pham <[email protected]>
269*10465441SEvalZero* Emmanuel Blot <[email protected]>
270*10465441SEvalZero* Michael <[email protected]>
271*10465441SEvalZero* Mick D <[email protected]>
272*10465441SEvalZero* Paul <[email protected]>
273*10465441SEvalZero* Rogerz <[email protected]>
274*10465441SEvalZero
275*10465441SEvalZero
276