没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
How YAFFS Works
Charles Manning
2007-2010
Table of Contents
1 Purpose...................................................................................................................................................2
2 What Is YAFFS?....................................................................................................................................2
3 Design and coding strategies..................................................................................................................2
4 Terminology: YAFFS vs YAFFS1 vs YAFFS2....................................................................................3
5 Objects...................................................................................................................................................3
6 The YAFFS NAND Model....................................................................................................................4
7 How YAFFS1 Stores Files.....................................................................................................................4
8 Garbage collection.................................................................................................................................7
9 YAFFS1 Serial numbers........................................................................................................................8
10 YAFFS2 NAND model........................................................................................................................9
10.1.YAFFS2 Extended tags...............................................................................................................11
11 Bad block handling NAND error handling........................................................................................11
12 RAM structures..................................................................................................................................12
12.1.yaffs_Object................................................................................................................................13
12.2.ObjectId look-up..........................................................................................................................13
12.3.Directory structure.......................................................................................................................14
12.4.Hard links....................................................................................................................................15
12.5.Symbolic link and special object.................................................................................................16
12.6.File object....................................................................................................................................16
12.6.1 Tnode tree...........................................................................................................................16
13 How various mechanisms work.........................................................................................................17
13.1.Block and Chunk Management...................................................................................................17
13.1.1 Block States........................................................................................................................17
13.1.2 Block and Chunk Allocation..............................................................................................19
13.1.3 A word about wear leveling................................................................................................20
13.1.4 yaffs_Tnode and yaffs_Object Management......................................................................20
13.2.Internal Cache..............................................................................................................................21
13.3.Scanning......................................................................................................................................22
13.3.1 YAFFS1 Scanning..............................................................................................................22
13.3.2 YAFFS2 Scanning..............................................................................................................22
13.4.Checkpoint...................................................................................................................................23
13.5.Extended Tags and Packed Tags.................................................................................................24
13.6.Inband tags..................................................................................................................................24
13.7.Soft Deletion................................................................................................................................25
Page 1/25
1 Purpose
The purpose of this document is to give a reasonable explanation of most of the core mechanisms that make yaffs work. As
of the time of writing this, the yaffs2 code base includes approximately 19,000 lines of code making a very detailed
discussion impractical.
This document should serve as a first port of call for understanding yaffs. Further detailed questions and discussions are
welcomed on the yaffs discussion list.
This document is updated periodically. Yaffs mechanism design changes from time to time and this document will not
always reflect the most up to date code.
2 What Is YAFFS?
YAFFS stands for Yet Another Flash File System, a term coined by Charles Manning in 2001 when suggesting that the
already cluttered flash file system space could do with yet another offering – this time a flash file system designed from the
ground up to work with NAND flash.
The first release of YAFFS was developed during the end of 2001 and the beginning of 2002. By mid-2002, YAFFS was
being trialled in various products. In May 2002, YAFFS was announced and a few more projects started playing with it. In
June, porting to other OSs started. In September 2002, YAFFS was announced on linuxdevices.com which started a far
wider uptake of YAFFS.
YAFFS1, the original version of YAFFS, supported 512-byte page NAND devices with a SmartMedia-like memory layout.
YAFFS2 is a follow-up to YAFFS1 extending YAFFS1 to support larger and different devices with different constraints.
YAFFSis highly portable and has been used in many different products and applications as varied as sewing machines,
point of sale, phones and aerospace. YAFFS has been used with multiple different operating systems. Native support is
available for Linux, WindowsCE and eCOS while yaffs Direct Interface provides a layer that can be used in other
applications such as RTOSs. YAFFS has been used with multiple different CPUs and compilers.
YAFFS has also been used as a NOR file system and even as a RAM file system.
3 Design and coding strategies
YAFFS is designed to work in multiple environments which drives the need for portability. Portability also improves the
debugging and testing since it is easier to develop and debug code in an application environment than within an OS kernel.
This generally allows YAFFS to progress faster with less programming resources. Primary strategies that improve
portability include:
● No OS-specific features used in main code body.
● No compiler-specific features used in the main code body.
● Abstract types and functions used to allow Unicode or ASCII operation.
Page 2/25
Simplicity is another key goal. Complexity is limited to those situations that provide significant improvements to
performance or utility. Simplicity improves robustness and the ease of integration and development. Primary strategies that
improve simplicity are:
● Single threaded model. YAFFS is locked on a per-partition basis at a high level. This is simpler than tracking
lower-level locking. Yaffs Direct Interface uses a single lock for all partitions.
● Log structure makes for a simpler garbage collector and allocation methodology.
● Abstractions that build layered code which is easier to understand and debug.
4 Terminology: YAFFS vs YAFFS1 vs YAFFS2
Before we embark on our quest to understand what YAFFS is, a terminology explanation is in order.
There are two versions of YAFFS code: the original yaffs code-base and the current yaffs2 code-base. The yaffs2 code-base
supports functionality provided by the yaffs code-base as well as being extended with new functionality to provide extra
modes of operation, most importantly those required to work with larger and more modern NAND parts. The yaffs2 code-
base supports the yaffs1 mode of operation through a backward compatibility mode.
Unless explicitly mentioned, this text refers to the yaffs2 code-base.
This text uses three terms YAFFS, YAFFS1 and YAFFS2 depending on various modes of operation.
•YAFFS1 is a simpler mode of operation that uses deletion markers to track state.
•YAFFS2 is a more complex mode of operating that was developed to support larger flash types that cannot used deletion
markers.
•YAFFS means operations common to both.
YAFFS1 originally only worked with 512-byte page devices but has been extended to support larger flash pages such as
Intel M18 flash with 1k pages.
YAFFS2 was originally designed for 1k or larger page sizes but can be used with smaller pages by using in-band tags.
Since the YAFFS1 mode of operation is simpler to understand than the YAFFS2 mode of operation, YAFFS1 will be
described first and readers interested in YAFFS2 operation should first fully acquaint themselves with the YAFFS1 mode of
operation. It is suggested that this document be read sequentially rather than browsing it.
5 Objects
In YAFFS-speak, an Object is anything that is stored in the file system. These are:
● Regular data files
● Directories
● Hard-links
● Symbolic links
Page 3/25
● Special objects (pipes, devices etc).
All objects are identified by a unique integer objectId.
In the standard POSIX model, as used by Linux, there are inodes and directory entries (dentries).
An inode may be a regular file, directory, or special file.
Directory entries provide the naming mechanism that is used to locate inodes.
Under POSIX, each inode may have zero, one or many dentries:
● One dentry per inode is commonly understood.
● Multiple dentries per inode allow the same inode to be accessed via multiple names. This is achieved through hard
links.
● Zero dentries per inode is less often understood. This happens when an inode is unlinked while there is still a
handle open to the inode. The unlinking deletes the dentry but the inode still exists. As soon as the handle is closed
the inode is deleted too.
6 The YAFFS NAND Model
The memory in NAND flash is arranged in pages. A page is the unit of allocation and programming. In YAFFS, the unit of
allocation is the chunk. Typically a chunk will be the same as a NAND page, but there is flexibility to use chunks which
map to multiple pages (eg. A system may have two NAND chips in parallel requiring 2x512 = 1024 byte chunks) . This
distinction gives a lot of flexibility in how the system can be configured. In this text the term page and chunk are
synonymous unless stated otherwise.
Many, typically 32 to 128 but as many as a few hundred, chunks form a block. A block is the unit of erasure.
NAND flash may be shipped with bad blocks and further blocks may go bad during the operation of the device. Thus,
YAFFS is aware of bad blocks and needs to be able to detect and mark bad blocks.
NAND flash also typically requires the use of some sort of error detection and correction code (ECC). YAFFS can either
use existing ECC logic or provide its own.
7 How YAFFS1 Stores Files
YAFFS1 has a modified log structure, while YAFFS2 (see below) has a true log structure. A true log structured file system
only ever writes sequentially. YAFFS1 uses deletion markers, which breaks the sequential write rule. YAFFS2 does not use
deletion markers and is thus a true log structured file system.
Instead of writing data in locations specific to the files, the file system data is written in the form of a sequential log, The
entries in the log are all one chunk in size and can hold one of two types of chunk:
● Data chunk: A chunk holding regular data file contents.
● Object Header: A descriptor for an object (directory,regular data file, hard link, soft link, special descriptor,...).
This holds details such as the identifier for the parent directory, object name, etc.
Page 4/25
Each chunk has tags associated with it. The tags comprise the following important fields (others being ignored for now):
● ObjectId: Identifies which object the chunk belongs to.
● ChunkId: Identifies where in the file this chunk belongs. A chunkId of zero signifies that this chunk contains an
objectHeader. ChunkId==1 signifies the first chunk in the file (ie. At file offset 0), chunkId==2 is the next chunk
and so on.
● Deletion Marker: (YAFFS1 only) Shows that this chunk is no longer in use.
● Byte Count: Number of bytes of data if this is a data chunk.
● Serial Number: (YAFFS1 only) Serial number used to differentiate chunks with the same objectId and chunkId.
Now let's bring that all together in an explanation. This is a simplified explanation and skips over issues such as Soft
Deletion (mentioned later in the document). For explanation purposes, we shall consider usage of fictitious NAND type that
has 4 chunks per block, starting with an empty (erased) flash.
First we'll create a file.
Block Chunk ObjectId ChunkId Deletion Comment
1 0 500 0 Live Object Header for this file (length 0)
Next we write a few chunks of data to the file.
Block Chunk ObjectId ChunkId Deletion Comment
1 0 500 0 Live Object Header for this file (length 0)
1 1 500 1 Live First chunk of data
1 2 500 2 Live Second chunk of data
1 3 500 3 Live Third chunk of data
Next we close the file. This writers a new object header for the file. Notice how the previous object header is deleted.
Block Chunk ObjectId ChunkId Deletion Comment
1 0 500 0 Deleted Obsoleted object header (length 0)
1 1 500 1 Live First chunk of data
1 2 500 2 Live Second chunk of data
1 3 500 3 Live Third chunk of data
Page 5/25
剩余24页未读,继续阅读
资源评论
ee230
- 粉丝: 63
- 资源: 63
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功