基于Linux2.6的YAFFS文件系统移植

一、yaffs文件系统简介
yaffs,yet another flash file system,是一种类似于jffs/jffs2的专门为flash设计的嵌入式文件系统。与jffs相比,它减少了一些功能,因此速度更快、占用内存更少。
yaffs和jffs都提供了写均衡,垃圾收集等底层操作。它们的不同之处在于:
(1)jffs是一种日志文件系统,通过日志机制保证文件系统的稳定性。yaffs仅仅借鉴了日志系统的思想,不提供日志机能,所以稳定性不如jaffs,但是资源占用少。
(2)jffs中使用多级链表管理需要回收的脏块,并且使用系统生成伪随机变量决定要回收的块,通过这种方法能提供较好的写均衡,在yaffs中是从头到尾对块搜索,所以在垃圾收集上jffs的速度慢,但是能延长nand的寿命。
(3)jffs支持文件压缩,适合存储容量较小的系统;yaffs不支持压缩,更适合存储容量大的系统。
yaffs 还带有nand芯片驱动,并为嵌入式系统提供了直接访问文件系统的api,用户可以不使用linux中的mtd和vfs,直接对文件进行操作。nand flash大多采用mtd+yaffs的模式。mtd( memory technology devices,内存技术设备)是对flash操作的接口,提供了一系列的标准函数,将硬件驱动设计和系统程序设计分开。
二、yaffs文件系统的移植
yaffs代码可以从http://www.aleph1.co.uk/armlinux/projects/下载(yaffs代码包括yaffs_ecc.c,yaffs_fileem.c,yaffs_fs.c,yaffs_guts.c,yaffs_mtdif.c,yaffs_ramem.c。)
表一 yaffs文件系统源代码相关文件及功能描述
文件名功 能
yaffs_ecc.cecc校验算法
yaffs_fileem.c测试flash
yaffs_fs.c文件系统接口函数
yaffs_guts.cyaffs文件系统算法
yaffs_mtdif.cnand函数
yaffs_ramem.cramdisk实现
1.内核中没有yaffs,所以需要自己建立yaffs目录,并把下载的yaffs代码复制到该目录下面。
#mkdir fs/yaffs
#cp *.c(yaffs source code) fs/yaffs
2.修改fs/kconfig,使得可以配置yaffs :
source fs/yaffs/kconfig
3.修改fs/makefile,添加如下内容:
obj-$(config_yaffs_fs) += yaffs/
4.在fs目录下生成yaffs目录,并在里面生成一个makefile 和kconfig
makefile 内容为:
yaffs-objs := yaffs_fs.o yaffs_guts.o yaffs_mtdif.o yaffs_ecc.o
extra_cflags += $(yaffs_configs) -dconfig_kernel_2_6
kconfig内容为:
#
# yaffs file system configurations
#
config yaffs_fs
tristate yet another flash filing system(yaffs) file system support
help
yaffs, for yet another flash filing system, is a filing system
optimised for nand flash chips.
to compile the yaffs file system support as a module, choose m here:
the module will be called yaffs.
if unsure, say n.
further information on yaffs is available at
.
config yaffs_mtd_enabled
bool nand mtd support
depends on yaffs_fs
help
this adds the yaffs file system support for working with a nand mtd.
if unsure, say y.
config yaffs_ram_enabled
bool yaffsram file system support
depends on yaffs_fs
help
this adds the yaffsram file system support. nice for testing on x86,
but uses 2mb of ram. don't enable for nand-based targets.
if unsure, say n.
comment warning: mtd and/or yaffsram support should be selected
depends on yaffs_fs && !yaffs_mtd_enabled && !yaffs_ram_enabled
config yaffs_use_old_mtd
bool old mtd support
depends on yaffs_fs && 0
help
enable this to use the old mtd stuff that did not have yaffs support.
you can use this to get around compilation problems, but the best
thing to do is to upgrade your mtd support. you will get better speed.
if unsure, say n.
config yaffs_use_nandecc
bool use ecc functions of the generic mtd-nand driver
depends on yaffs_fs
default y
help
this enables the ecc functions of the generic mtd-nand driver.
this will not work if you are using the old mtd.
nb use nand ecc does not work at present with yaffsram.
if unsure, say y.
config yaffs_ecc_wrong_order
bool use the same ecc byte order as steven hill's nand_ecc.c
depends on yaffs_fs
help
this makes yaffs_ecc.c use the same ecc byte order as
steven hill's nand_ecc.c. if not set, then you get the
same ecc byte order as smartmedia.
if unsure, say n.
config yaffs_use_generic_rw
bool use linux file caching layer
default y
depends on yaffs_fs
help
use generic_read/generic_write for reading/writing files. this
enables the use of the linux file caching layer.
if you disable this, then caching is disabled and file read/write
is direct.
if unsure, say y.
config yaffs_use_header_file_size
bool use object header size
depends on yaffs_fs
help
when the flash is scanned, two file sizes are constructed:
* the size taken from the object header for the file.
* the size figured out by scanning the data chunks.
if this option is enabled, then the object header size is used,
otherwise the scanned size is used.
if unsure, say n.
config yaffs_disable_chunk_erased_check
bool turn off debug chunk erase check
depends on yaffs_fs
default y
help
enabling this turns off the test that chunks are erased in flash
before writing to them. this is safe, since the write verification
will fail. suggest enabling the test (ie. say n)
during development to help debug things.
if unsure, say y.
#config yaffs_disable_write_verify
#bool disable write verify (dangerous)
#depends on yaffs_fs && experimental
#help
# i am severely reluctant to provide this config. disabling the
# verification is not a good thing to do since nand writes can
# fail silently. disabling the write verification will cause your
# teeth to rot, rats to eat your corn and give you split ends.
# you have been warned. ie. don't uncomment the following line.
#
# if unsure, say n.
#
config yaffs_short_names_in_ram
bool cache short names in ram
depends on yaffs_fs
default y
help
if this config is set, then short names are stored with the
yaffs_object. this costs an extra 16 bytes of ram per object,
but makes look-ups faster.
if unsure, say y.
5.在/arch/arm/mach-s3c2410/mach-smdk2410.c找到smdk_default_nand_part结构,修改nand分区,如下:
struct mtd_partition smdk_default_nand_part[] = {
[0] = {
.name = vivi,
.size = 0x00020000,
.offset = 0x00000000,
},
[1] = {
.name = param,
.size = 0x00010000,
.offset = 0x00020000,
},
[2] = {
.name = kernel,
.size = 0x00100000,
.offset = 0x00030000,
},
[3] = {
.name = root,
.size = 0x01900000,
.offset = 0x00130000,
},
[4] = {
.name = user,
.size = 0x025d0000,
.offset = 0x01a30000,
}
};
注:此分区要结合vivi里面的分区来进行设置。
6.配置内核时选中mtd支持:
memory technology devices (mtd) --->
memory technology device (mtd) support
[*] mtd partitioning support
……
--- user modules and translation layers
direct char device access to mtd devices
caching block device access to mtd devices
……
nand flash device drivers --->
nand device support
nand flash support for s3c2410 soc
[*] s3c2410 nand driver debug
7.配置内核时选中yaffs支持:
file systems --->
miscellaneous filesystems --->
yet another flash filing system(yaffs) file system support
[*] nand mtd support
[*] use ecc functions of the generic mtd-nand driver
[*] use linux file caching layer
[*] turn off debug chunk erase check
[*] cache short names in ram
8.编译内核并将内核下载到开发板的flash中。
三、yaffs文件系统测试:
1.内核启动之后,在启动信息里面可以看到如下内容:
nand device: manufacturer id: 0xec, chip id: 0x76 (samsung nand 64mib 3,3v 8-bit)
scanning device for bad blocks
creating 5 mtd partitions on nand 64mib 3,3v 8-bit:
0x00000000-0x00020000 : vivi
0x00020000-0x00030000 : param
0x00030000-0x00130000 : kernel
0x00130000-0x01a30000 : root
0x01a30000-0x04100000 : user
2.如果在内核里面添加了proc文件系统的支持那么你在proc里面可以看到有关yaffs的信息
~ # cat proc/filesystems
nodev sysfs
nodev rootfs
nodev bdev
nodev proc
nodev sockfs
nodev pipefs
nodev futexfs
nodev tmpfs
nodev eventpollfs
nodev devpts
nodev ramfs
vfat
nodev devfs
nodev nfs
yaffs
nodev rpc_pipefs
3.查看dev目录下相关目录可以看到:
~ # ls dev/mtd -al
drwxr-xr-x 1 root root 0 jan 1 00:00 .
drwxr-xr-x 1 root root 0 jan 1 00:00 ..
crw-rw-rw- 1 root root 90, 0 jan 1 00:00 0
cr--r--r-- 1 root root 90, 1 jan 1 00:00 0ro
crw-rw-rw- 1 root root 90, 2 jan 1 00:00 1
cr--r--r-- 1 root root 90, 3 jan 1 00:00 1ro
crw-rw-rw- 1 root root 90, 4 jan 1 00:00 2
cr--r--r-- 1 root root 90, 5 jan 1 00:00 2ro
crw-rw-rw- 1 root root 90, 6 jan 1 00:00 3
cr--r--r-- 1 root root 90, 7 jan 1 00:00 3ro
crw-rw-rw- 1 root root 90, 8 jan 1 00:00 4
cr--r--r-- 1 root root 90, 9 jan 1 00:00 4ro
~ # ls dev/mtdblock/ -al
drwxr-xr-x 1 root root 0 jan 1 00:00 .
drwxr-xr-x 1 root root 0 jan 1 00:00 ..
brw------- 1 root root 31, 0 jan 1 00:00 0
brw------- 1 root root 31, 1 jan 1 00:00 1
brw------- 1 root root 31, 2 jan 1 00:00 2
brw------- 1 root root 31, 3 jan 1 00:00 3
brw------- 1 root root 31, 4 jan 1 00:00 4
4.mount、umount
建立mount目录
~ #mkdir /mnt/flash0
~ #mkdir /mnt/flash1
mountblockdevice设备
~ #mount –t yaffs /dev/mtdblock/3 /mnt/flash0
~ #mount –t yaffs /dev/mtdblock/4 /mnt/flash1
~ #cp 1.txt /mnt/flash0
~ #cp 2.txt /mnt/flash1
查看mount上的目录,可以看到该目录下有刚才拷贝的文件,将其umount后,再次mount上来可以发现拷贝的文件仍然存在,这时删除该文件然后umount,再次mount后,可以发现拷贝的文件已经被删除,由此可以该分区可以正常读写。
5.在flash上建立根文件系统
~ # mount –t yaffs /dev/mtdblock/3 /mnt/flash0
~ #cp (your rootfs) /mnt/flash0
~ #umount /mnt/flash0
重新启动,改变启动参数:
param set linux_cmd_line noinitrd root=/dev/mtdblock3 init=/linuxrc console=ttysac0
重新启动,开发板就可以从flash启动根文件系统了。
注:这里你得在内核中添加devfs文件系统的支持,否则内核无法找到/dev/mtdblock/3目录

The Freestyle三星投影仪:强大的投影功能和高清画质技术
毫米波人体成像设备将取代金属探测门用于民用机场
纳智捷锐3 旗舰版全方位测评
苹果正在研发折叠屏iPhone可能会在5G手机之后推出
详解卷积神经网络卷积过程
基于Linux2.6的YAFFS文件系统移植
人类历史上推力最大的火箭,在发射前几分钟突然被叫停!
传新版Model3即将上市,特斯拉在国内促销清库存?
ARM微处理器对异常中断的响应过程
荣耀9什么时候上市?荣耀9最新消息:荣耀9曝光:玻璃机身+前置指纹配与华为Mate 9同规格双摄
物联网 vs 区块链 vs 人工智能, 哪个才是你的菜?
你知道国产双机热备与双机冷备的意思吗
变压器过励磁
超140家零售商与科技公司联手改善AR/VR购物体验
机器视觉知识要点
百度推出小度电视伴侣 朝着家居控制中心的战略前行
虹科新闻 |2022元宇宙荣誉榜创新硬件榜单新鲜出炉,虹科榜上有名
Redis可以实现消息中间件MQ的功能
是德科技推出新的800G测试解决方案
关于移动AR产品的应用场景与方案及开发设计