| 论坛注册| 加入收藏 | 设为首页| RSS
Google
您当前的位置:首页 > Linux频道 > Linux开发区 > 嵌入应用

嵌入式linux下常见的文件系统

时间:2007-04-09 11:27:25  来源:Linux联盟收集整理  作者:
• RomFS:只读文件系统,可以放在ROM空间,也txxLinux联盟
可以在系统的RAM中,嵌入式linux中常用来作txxLinux联盟
根文件系统txxLinux联盟
• RamFS:利用VFS自身结构而形成的内存文件系txxLinux联盟
统,使用系统的RAM空间txxLinux联盟
• JFFS/JFFS2:为Flash设计的日志文件系统txxLinux联盟
• Yaffs:专门为Nand Flash设计
txxLinux联盟
• proc:为内核和内核模块将信息发送给进程提txxLinux联盟
供一种机制,可以查看系统模块装载的信息txxLinux联盟
• devFS:设备文件系统txxLinux联盟
Linux上的Ext2fstxxLinux联盟
• 支持4 TB 存储、文件名称最长1012 字符txxLinux联盟
• 可选择逻辑块txxLinux联盟
• 快速符号链接txxLinux联盟
• Ext2不适合flash设备txxLinux联盟
• 是为象IDE 设备那样的块设备设计的,逻辑块大小必txxLinux联盟
须是512 byte、1 KB、2KB等txxLinux联盟
• 没有提供对基于扇区的擦除/写操作的良好管理txxLinux联盟
• 如果在一个扇区中擦除单个字节,必须将整个扇区复制到txxLinux联盟
RAM,然后擦除,再重写入txxLinux联盟
• 在出现电源故障时,Ext2fs 是不能防止崩溃的txxLinux联盟
• 文件系统不支持损耗平衡,缩短了flash的寿命txxLinux联盟
jffs/jffs2文件系统的优缺点txxLinux联盟
• 日志文件系统txxLinux联盟
• 提供了更好的崩溃、掉电安全保护txxLinux联盟
• jffs2支持对flash的均匀磨损txxLinux联盟
• 在扇区级别上执行闪存擦除/写/读操作要txxLinux联盟
比Ext2文件系统好txxLinux联盟
• 文件系统接近满时,JFFS2 会大大放慢运行txxLinux联盟
速度——垃圾收集txxLinux联盟
Nand上yaffs文件系统的优势txxLinux联盟
• 专门为Nand flash设计的日志文件系统txxLinux联盟
• jffs/jffs2不适合大容量的Nand flashtxxLinux联盟
• jffs的日志通过jffs_node建立在RAM中,占用txxLinux联盟
RAM空间:对于128MB的Nand大概需要4MB的空间txxLinux联盟
来维护节点txxLinux联盟
• 启动的时候需要扫描日志节点,不适合大容量txxLinux联盟
的Nand flashtxxLinux联盟
• FAT系统没有日志txxLinux联盟
编译yaffs文件系统txxLinux联盟
• mtd的最新补丁升级?txxLinux联盟
• 接口更新,适合与yaffstxxLinux联盟
• 与原有的mtd驱动程序不兼容,需要重写txxLinux联盟
• 如果使用旧mtd驱动需要定义Makefile中txxLinux联盟
MTD_OLD = -DCONFIG_YAFFS_USE_OLD_MTDtxxLinux联盟
• 参考文档: yaffs-rootfs-howtotxxLinux联盟
• 最新版的yaffs网站:txxLinux联盟
http://www.aleph1.co.uk/armlinux/projects/yaffstxxLinux联盟
使用yaffs文件系统txxLinux联盟
• 通过cat /proc/yaffs命令可以看到yaffs系txxLinux联盟
统的相关信息txxLinux联盟
• mount -t yaffs /dev/mtdblock/0 /mnt/yatxxLinux联盟
ffs
txxLinux联盟
txxLinux联盟
txxLinux联盟
关于Linux文件系统txxLinux联盟
txxLinux联盟
JFFS 全称为:The Journalling Flash File System(日志闪存文件系统)最初由瑞典的 Axis Communications 开发,Red Hat 的 David Woodhouse 对它进行了改进。作为用于微型嵌入式设备的原始闪存芯片的实际文件系统而出现。JFFS文件系统是日志结构化的,这意味着它基本上是一长列节点。每个节点包含有关文件的部分信息 — 可能是文件的名称、也许是一些数据。相对于 Ext2 fs,JFFS 因为有以下这些优点而在无盘嵌入式设备中越来越受欢迎:txxLinux联盟
  txxLinux联盟
   1 JFFS 在扇区级别上执行闪存擦除/写/读操作要比 Ext2 文件系统好。txxLinux联盟
   2 JFFS 提供了比 Ext2 更好的崩溃/掉电安全保护。当需要更改少量数据时,Ext2 文件系统将整个扇区复制到内存(DRAM)中,在内存中合并新数据,并写回整个扇区。这意味着为了更改单个字,必须对整个扇区(64 KB)执行读/擦除/写例程 — 这样做的效率非常低。要是运气差,当正在 DRAM 中合并数据时,发生了电源故障或其它事故,那么将丢失整个数据集合,因为在将数据读入 DRAM 后就擦除了闪存扇区。JFFS 附加文件而不是重写整个扇区,并且具有崩溃/掉电安全保护这一功能。txxLinux联盟
   3 这可能是最重要的一点:JFFS 是专门为象闪存芯片那样的嵌入式设备创建的,所以它的整个设计提供了更好的闪存管理。txxLinux联盟
   要构建JFFS文件系统,首先要有硬件设备FLASH及支持JFFS文件系统的操作系统。
txxLinux联盟
txxLinux联盟
txxLinux联盟
摘要:本文主要分析了uclinux 2.4内核的jffs文件系统机制。希望能对基于uclinux开发产品的广大工程师有所帮助。txxLinux联盟
txxLinux联盟
关键词:uclinux vfs jffstxxLinux联盟
txxLinux联盟
申明:这份文档是按照自由软件开放源代码的精神发布的,任何人可以免费获得、使用和重新发布,但是你没有限制别人重新发布你发布内容的权利。发布本文的目的是希望它能对读者有用,但没有任何担保,甚至没有适合特定目的的隐含的担保。更详细的情况请参阅 GNU 通用公共许可证(GPL),以及GNU 自由文档协议(GFDL)。txxLinux联盟
txxLinux联盟
你应该已经和文档一起收到一份GNU 通用公共许可证(GPL)的副本。如果还没有,写信给:txxLinux联盟
The Free Software Foundation, Inc., 675 Mass Ave, Cambridge,MA02139, USAtxxLinux联盟
txxLinux联盟
欢迎各位指出文档中的错误与疑问txxLinux联盟
txxLinux联盟
txxLinux联盟
一、flash读写的特殊性txxLinux联盟
对于嵌入式系统,flash是很常见的一种设备,而大部分的嵌入式系统都是把文件系统建立在flash之上,由于对flash操作的特殊性,使得在flash上的文件系统和普通磁盘上的文件系统有很大的差别,对flash操作的特殊性包括:txxLinux联盟
(1) 不能对单个字节进行擦除,最小的擦写单位是一个block,有时候也称为一个扇区。典型的一个block的大小是64k。不同的flash会有不同,具体参考flash芯片的规范。txxLinux联盟
(2) 写操作只能对一个原来是空(也就是该地址的内容是全f)的位置操作,如果该位置非空,写操作不起作用,也就是说如果要改写一个原来已经有内容的空间,只能是读出该sector到ram,在ram中改写,然后写整个sector。txxLinux联盟
由于这些特殊写,所以在flash这样的设备上建立文件也有自己独特的特点,下面我们就以jffs为例进行分析。txxLinux联盟
txxLinux联盟
二、jffs体系结构介绍txxLinux联盟
1、存储结构txxLinux联盟
在jffs中,所有的文件和目录是一样对待的,都是用一个jffs_raw_inode来表示txxLinux联盟
txxLinux联盟
txxLinux联盟
整个flash上就是由一个一个的raw inode排列组成,一个目录只有一个raw inode,对于文件则是由一个或多个raw inode组成。txxLinux联盟
txxLinux联盟
2、文件组成txxLinux联盟
在文件系统mount到flash设备上的时候,会扫描flash,从而根据flash上的所有属于一个文件的raw inode建立一个jffs_file结构以及node list。txxLinux联盟
下面的图显示了一个文件的组成txxLinux联盟
txxLinux联盟
txxLinux联盟
一个文件是由若干个jffs_node组成,每一个jffs_node是根据flash上得jffs_raw_inode而建立的,jffs_file主要维护两个链表txxLinux联盟
版本链表:主要是描述该node创建的早晚,就是说version_head指向的是一个最老的node,也就意味着垃圾回收的时候最该回收的就是这个最老的node。txxLinux联盟
区域链表:这个链表主要是为读写文件创建的,version_head指向的node代表的文件数据区域是0~~~n-1 之后依次的节点分别是 n~~~m-1 m~~~~o-1 …….其中n<M<="" p="" />txxLinux联盟
txxLinux联盟
3、操作txxLinux联盟
对文件的读操作应该是比较简单,但是写操作,包括更改文件名等操作都是引起一个新的jffs_node的诞生,同时要写一个相映的raw inode到flash上,这样的操作有可能导致前面的某个jffs_node上面的数据完全失效,从而导致对应flash上的raw inode的空间成为dirty。txxLinux联盟
下面举一个例子可能会更清楚一些。txxLinux联盟
txxLinux联盟
一个文件的range list是由上面的三个jffs_node组成,当我们做如下写操作的时候txxLinux联盟
lseek( fd, 10, SEEK_SET );txxLinux联盟
write( fd, buf,40 );txxLinux联盟
第一个和最后一个node被截短了,第二个node完全被新数据替换,该node会从链表上摘下来,flash上空间变成dirty。如果做如下写操作的时候txxLinux联盟
lseek( fd, 23, SEEK_SET );txxLinux联盟
write( fd, buf,5 );txxLinux联盟
此时,第二个node被分裂成两个node,同时产生一个新的node,range链表的元素变成五个。
txxLinux联盟
txxLinux联盟
txxLinux联盟
txxLinux联盟
txxLinux联盟
基于Linux2.6的YAFFS文件系统移植txxLinux联盟
v1.0,2005-6-6txxLinux联盟
一、YAFFS文件系统简介txxLinux联盟
YAFFS,Yet Another Flash File System,是一种类似于JFFS/JFFS2的专门为Flash设计的嵌入式文件系统。与JFFS相比,它减少了一些功能,因此速度更快、占用内存更少。txxLinux联盟
YAFFS和JFFS都提供了写均衡,垃圾收集等底层操作。它们的不同之处在于:txxLinux联盟
(1)、JFFS是一种日志文件系统,通过日志机制保证文件系统的稳定性。YAFFS仅仅借鉴了日志系统的思想,不提供日志机能,所以稳定性不如JAFFS,但是资源占用少。txxLinux联盟
(2)、JFFS中使用多级链表管理需要回收的脏块,并且使用系统生成伪随机变量决定要回收的块,通过这种方法能提供较好的写均衡,在YAFFS中是从头到尾对块搜索,所以在垃圾收集上JFFS的速度慢,但是能延长NAND的寿命。txxLinux联盟
(3)、JFFS支持文件压缩,适合存储容量较小的系统;YAFFS不支持压缩,更适合存储容量大的系统。txxLinux联盟
YAFFS 还带有NAND芯片驱动,并为嵌入式系统提供了直接访问文件系统的API,用户可以不使用Linux中的MTD和VFS,直接对文件进行操作。NAND Flash大多采用MTD+YAFFS的模式。MTD( Memory Technology Devices,内存技术设备)是对Flash操作的接口,提供了一系列的标准函数,将硬件驱动设计和系统程序设计分开。txxLinux联盟
二、YAFFS文件系统的移植txxLinux联盟
yaffs代码可以从
http://www.aleph1.co.uk/armlinux/projects/下载(yaffs代码包括yaffs_ecctxxLinux联盟
.c,yaffs_fileem.c,yaffs_fs.c,yaffs_guts.c,yaffs_mtdif.c,yaffs_ramem.c。)txxLinux联盟
表一 Yaffs文件系统源代码相关文件及功能描述txxLinux联盟
文件名 功   能txxLinux联盟
yaffs_ecc.c ECC校验算法txxLinux联盟
yaffs_fileem.c 测试flashtxxLinux联盟
yaffs_fs.c 文件系统接口函数txxLinux联盟
yaffs_guts.c Yaffs文件系统算法txxLinux联盟
yaffs_mtdif.c NAND函数txxLinux联盟
yaffs_ramem.c Ramdisk实现txxLinux联盟
1.内核中没有YAFFS,所以需要自己建立YAFFS目录,并把下载的YAFFS代码复制到该目录下面。txxLinux联盟
#mkdir fs/yaffstxxLinux联盟
#cp *.c(yaffs source code) fs/yaffstxxLinux联盟
2.修改fs/Kconfig,使得可以配置yaffs :txxLinux联盟
source "fs/yaffs/Kconfig"txxLinux联盟
3.修改fs/makefile,添加如下内容:txxLinux联盟
obj-$(CONFIG_YAFFS_FS)       += yaffs/txxLinux联盟
4.在fs目录下生成yaffs目录,并在里面生成一个makefile 和KconfigtxxLinux联盟
Makefile 内容为:txxLinux联盟
yaffs-objs := yaffs_fs.o yaffs_guts.o yaffs_mtdif.o yaffs_ecc.otxxLinux联盟
EXTRA_CFLAGS += $(YAFFS_CONFIGS) -DCONFIG_KERNEL_2_6txxLinux联盟
Kconfig内容为:txxLinux联盟
#txxLinux联盟
# YAFFS file system configurationstxxLinux联盟
#txxLinux联盟
config YAFFS_FStxxLinux联盟
tristate "Yet Another Flash Filing System(YAFFS) file system support"txxLinux联盟
helptxxLinux联盟
  YAFFS, for Yet Another Flash Filing System, is a filing systemtxxLinux联盟
  optimised for NAND Flash chips.txxLinux联盟
txxLinux联盟
  To compile the YAFFS file system support as a module, choose M here:txxLinux联盟
  the module will be called yaffs.txxLinux联盟
txxLinux联盟
  If unsure, say N.txxLinux联盟
txxLinux联盟
  Further information on YAFFS is available attxxLinux联盟
  <
http://www.aleph1.co.uk/yaffs/>.txxLinux联盟
txxLinux联盟
config YAFFS_MTD_ENABLEDtxxLinux联盟
bool "NAND mtd support"txxLinux联盟
depends on YAFFS_FStxxLinux联盟
helptxxLinux联盟
  This adds the yaffs file system support for working with a NAND mtd.txxLinux联盟
txxLinux联盟
  If unsure, say Y.txxLinux联盟
txxLinux联盟
config YAFFS_RAM_ENABLEDtxxLinux联盟
bool "yaffsram file system support"txxLinux联盟
depends on YAFFS_FStxxLinux联盟
helptxxLinux联盟
  This adds the yaffsram file system support. Nice for testing on x86,txxLinux联盟
  but uses 2MB of RAM. Don't enable for NAND-based targets.txxLinux联盟
txxLinux联盟
  If unsure, say N.txxLinux联盟
txxLinux联盟
comment "WARNING: mtd and/or yaffsram support should be selected"txxLinux联盟
depends on YAFFS_FS && !YAFFS_MTD_ENABLED && !YAFFS_RAM_ENABLEDtxxLinux联盟
txxLinux联盟
config YAFFS_USE_OLD_MTDtxxLinux联盟
bool "Old mtd support"txxLinux联盟
depends on YAFFS_FS && 0txxLinux联盟
helptxxLinux联盟
  Enable this to use the old MTD stuff that did not have yaffs support.txxLinux联盟
  You can use this to get around compilation problems, but the besttxxLinux联盟
  thing to do is to upgrade your MTD support. You will get better speed.txxLinux联盟
txxLinux联盟
  If unsure, say N.txxLinux联盟
txxLinux联盟
config YAFFS_USE_NANDECCtxxLinux联盟
bool "Use ECC functions of the generic MTD-NAND driver"txxLinux联盟
depends on YAFFS_FStxxLinux联盟
default ytxxLinux联盟
helptxxLinux联盟
  This enables the ECC functions of the generic MTD-NAND driver.txxLinux联盟
  This will not work if you are using the old mtd.txxLinux联盟
txxLinux联盟
  NB Use NAND ECC does not work at present with yaffsram.txxLinux联盟
txxLinux联盟
  If unsure, say Y.txxLinux联盟
txxLinux联盟
config YAFFS_ECC_WRONG_ORDERtxxLinux联盟
bool "Use the same ecc byte order as Steven Hill's nand_ecc.c"txxLinux联盟
depends on YAFFS_FStxxLinux联盟
helptxxLinux联盟
  This makes yaffs_ecc.c use the same ecc byte order astxxLinux联盟
  Steven Hill's nand_ecc.c. If not set, then you get thetxxLinux联盟
  same ecc byte order as SmartMedia.txxLinux联盟
txxLinux联盟
  If unsure, say N.txxLinux联盟
txxLinux联盟
config YAFFS_USE_GENERIC_RWtxxLinux联盟
bool "Use Linux file caching layer"txxLinux联盟
default ytxxLinux联盟
depends on YAFFS_FStxxLinux联盟
helptxxLinux联盟
  Use generic_read/generic_write for reading/writing files. ThistxxLinux联盟
  enables the use of the Linux file caching layer.txxLinux联盟
txxLinux联盟
  If you disable this, then caching is disabled and file read/writetxxLinux联盟
  is direct.txxLinux联盟
txxLinux联盟
  If unsure, say Y.txxLinux联盟
txxLinux联盟
config YAFFS_USE_HEADER_FILE_SIZEtxxLinux联盟
bool "Use object header size"txxLinux联盟
depends on YAFFS_FStxxLinux联盟
helptxxLinux联盟
  When the flash is scanned, two file sizes are constructed:txxLinux联盟
  * The size taken from the object header for the file.txxLinux联盟
  * The size figured out by scanning the data chunks.txxLinux联盟
  If this option is enabled, then the object header size is used,txxLinux联盟
  otherwise the scanned size is used.txxLinux联盟
txxLinux联盟
  If unsure, say N.txxLinux联盟
txxLinux联盟
config YAFFS_DISABLE_CHUNK_ERASED_CHECKtxxLinux联盟
bool "Turn off debug chunk erase check"txxLinux联盟
depends on YAFFS_FStxxLinux联盟
default ytxxLinux联盟
helptxxLinux联盟
  Enabling this turns off the test that chunks are erased in flashtxxLinux联盟
  before writing to them. This is safe, since the write verificationtxxLinux联盟
  will fail. Suggest enabling the test (ie. say N)txxLinux联盟
  during development to help debug things.txxLinux联盟
txxLinux联盟
  If unsure, say Y.txxLinux联盟
txxLinux联盟
#config YAFFS_DISABLE_WRITE_VERIFYtxxLinux联盟
# bool "Disable write verify (DANGEROUS)"txxLinux联盟
# depends on YAFFS_FS && EXPERIMENTALtxxLinux联盟
# helptxxLinux联盟
#   I am severely reluctant to provide this config. Disabling thetxxLinux联盟
#   verification is not a good thing to do since NAND writes cantxxLinux联盟
#   fail silently. Disabling the write verification will cause yourtxxLinux联盟
#   teeth to rot, rats to eat your corn and give you split ends.txxLinux联盟
#   You have been warned. ie. Don't uncomment the following line.txxLinux联盟
#txxLinux联盟
#   If unsure, say N.txxLinux联盟
#txxLinux联盟
txxLinux联盟
config YAFFS_SHORT_NAMES_IN_RAMtxxLinux联盟
bool "Cache short names in RAM"txxLinux联盟
depends on YAFFS_FStxxLinux联盟
default ytxxLinux联盟
helptxxLinux联盟
  If this config is set, then short names are stored with thetxxLinux联盟
  yaffs_Object. This costs an extra 16 bytes of RAM per object,txxLinux联盟
  but makes look-ups faster.txxLinux联盟
txxLinux联盟
  If unsure, say Y.txxLinux联盟
5.在/arch/arm/mach-s3c2410/mach-smdk2410.c找到smdk_default_nand_part结构,修改nand分区,如下:txxLinux联盟
struct mtd_partition smdk_default_nand_part[] = {txxLinux联盟
    [0] = {txxLinux联盟
          .name   = "vivi",txxLinux联盟
          .size   = 0x00020000,txxLinux联盟
          .offset = 0x00000000,txxLinux联盟
    },txxLinux联盟
    [1] = {txxLinux联盟
          .name   = "param",txxLinux联盟
          .size   = 0x00010000,txxLinux联盟
          .offset = 0x00020000,txxLinux联盟
    },txxLinux联盟
    [2] = {txxLinux联盟
          .name   = "kernel",txxLinux联盟
          .size   = 0x00100000,txxLinux联盟
          .offset = 0x00030000,txxLinux联盟
    },txxLinux联盟
    [3] = {txxLinux联盟
          .name   = "root",txxLinux联盟
          .size   = 0x01900000,txxLinux联盟
          .offset = 0x00130000,txxLinux联盟
    },txxLinux联盟
    [4] = {txxLinux联盟
          .name   = "user",txxLinux联盟
          .size   = 0x025d0000,txxLinux联盟
          .offset = 0x01a30000,txxLinux联盟
    }txxLinux联盟
};txxLinux联盟
注:此分区要结合vivi里面的分区来进行设置。txxLinux联盟
6.配置内核时选中MTD支持:txxLinux联盟
Memory Technology Devices (MTD) --->txxLinux联盟
<*> Memory Technology Device (MTD) supporttxxLinux联盟
  •   MTD partitioning supporttxxLinux联盟
      ……txxLinux联盟
    --- User Modules And Translation LayerstxxLinux联盟
    <*> Direct char device access to MTD devicestxxLinux联盟
    <*> Caching block device access to MTD devicestxxLinux联盟
    ……txxLinux联盟
    NAND Flash Device Drivers --->txxLinux联盟
    <*> NAND Device SupporttxxLinux联盟
    <*> NAND Flash support for S3C2410 SoCtxxLinux联盟
  •   S3C2410 NAND driver debug txxLinux联盟
    7.配置内核时选中YAFFS支持:txxLinux联盟
    File systems --->txxLinux联盟
    Miscellaneous filesystems --->txxLinux联盟
    <*> Yet Another Flash Filing System(YAFFS) file system supporttxxLinux联盟
  •   NAND mtd supporttxxLinux联盟
  •   Use ECC functions of the generic MTD-NAND drivertxxLinux联盟
  •   Use Linux file caching layertxxLinux联盟
  •   Turn off debug chunk erase checktxxLinux联盟
  •   Cache short names in RAMtxxLinux联盟
    8.编译内核并将内核下载到开发板的flash中。txxLinux联盟
    三、Yaffs文件系统测试:txxLinux联盟
    1.内核启动之后,在启动信息里面可以看到如下内容:txxLinux联盟
    NAND device: Manufacturer ID: 0xec, Chip ID: 0x76 (Samsung NAND 64MiB 3,3V 8-bit)txxLinux联盟
    Scanning device for bad blockstxxLinux联盟
    Creating 5 MTD partitions on "NAND 64MiB 3,3V 8-bit":txxLinux联盟
    0x00000000-0x00020000 : "vivi"txxLinux联盟
    0x00020000-0x00030000 : "param"txxLinux联盟
    0x00030000-0x00130000 : "kernel"txxLinux联盟
    0x00130000-0x01a30000 : "root"txxLinux联盟
    0x01a30000-0x04100000 : "user"txxLinux联盟
    2.如果在内核里面添加了proc文件系统的支持那么你在proc里面可以看到有关yaffs的信息txxLinux联盟
    ~ # cat proc/filesystemstxxLinux联盟
    nodev   sysfstxxLinux联盟
    nodev   rootfstxxLinux联盟
    nodev   bdevtxxLinux联盟
    nodev   proctxxLinux联盟
    nodev   sockfstxxLinux联盟
    nodev   pipefstxxLinux联盟
    nodev   futexfstxxLinux联盟
    nodev   tmpfstxxLinux联盟
    nodev   eventpollfstxxLinux联盟
    nodev   devptstxxLinux联盟
    nodev   ramfstxxLinux联盟
        vfattxxLinux联盟
    nodev   devfstxxLinux联盟
    nodev   nfstxxLinux联盟
        yaffstxxLinux联盟
    nodev   rpc_pipefstxxLinux联盟
    3.查看dev目录下相关目录可以看到:txxLinux联盟
    ~ # ls dev/mtd -altxxLinux联盟
    drwxr-xr-x   1 root   root         0 Jan 1 00:00 .txxLinux联盟
    drwxr-xr-x   1 root   root         0 Jan 1 00:00 ..txxLinux联盟
    crw-rw-rw-   1 root   root     90,   0 Jan 1 00:00 0txxLinux联盟
    cr--r--r--   1 root   root     90,   1 Jan 1 00:00 0rotxxLinux联盟
    crw-rw-rw-   1 root   root     90,   2 Jan 1 00:00 1txxLinux联盟
    cr--r--r--   1 root   root     90,   3 Jan 1 00:00 1rotxxLinux联盟
    crw-rw-rw-   1 root   root     90,   4 Jan 1 00:00 2txxLinux联盟
    cr--r--r--   1 root   root     90,   5 Jan 1 00:00 2rotxxLinux联盟
    crw-rw-rw-   1 root   root     90,   6 Jan 1 00:00 3txxLinux联盟
    cr--r--r--   1 root   root     90,   7 Jan 1 00:00 3rotxxLinux联盟
    crw-rw-rw-   1 root   root     90,   8 Jan 1 00:00 4txxLinux联盟
    cr--r--r--   1 root   root     90,   9 Jan 1 00:00 4rotxxLinux联盟
    txxLinux联盟
    ~ # ls dev/mtdblock/ -altxxLinux联盟
    drwxr-xr-x   1 root   root         0 Jan 1 00:00 .txxLinux联盟
    drwxr-xr-x   1 root   root         0 Jan 1 00:00 ..txxLinux联盟
    brw-------   1 root   root     31,   0 Jan 1 00:00 0txxLinux联盟
    brw-------   1 root   root     31,   1 Jan 1 00:00 1txxLinux联盟
    brw-------   1 root   root     31,   2 Jan 1 00:00 2txxLinux联盟
    brw-------   1 root   root     31,   3 Jan 1 00:00 3txxLinux联盟
    brw-------   1 root   root     31,   4 Jan 1 00:00 4txxLinux联盟
    4.mount、umounttxxLinux联盟
    建立mount目录txxLinux联盟
    ~ #mkdir /mnt/flash0txxLinux联盟
    ~ #mkdir /mnt/flash1txxLinux联盟
    Mountblockdevice设备txxLinux联盟
    ~ #mount –t yaffs /dev/mtdblock/3 /mnt/flash0txxLinux联盟
    ~ #mount –t yaffs /dev/mtdblock/4 /mnt/flash1txxLinux联盟
    ~ #cp 1.txt /mnt/flash0txxLinux联盟
    ~ #cp 2.txt /mnt/flash1txxLinux联盟
    查看mount上的目录,可以看到该目录下有刚才拷贝的文件,将其umount后,再次mount上来可以发现拷贝的文件仍然存在,这时删除该文件然后umount,再次mount后,可以发现拷贝的文件已经被删除,由此可以该分区可以正常读写。txxLinux联盟
    5.在flash上建立根文件系统txxLinux联盟
    ~ # mount –t yaffs /dev/mtdblock/3 /mnt/flash0txxLinux联盟
    ~ #cp (your rootfs) /mnt/flash0txxLinux联盟
    ~ #umount /mnt/flash0txxLinux联盟
    重新启动,改变启动参数:txxLinux联盟
    param set linux_cmd_line "noinitrd root=/dev/mtdblock3 init=/linuxrc console=ttySAC0"txxLinux联盟
    重新启动,开发板就可以从flash启动根文件系统了。txxLinux联盟
    注:这里你得在内核中添加devfs文件系统的支持,否则内核无法找到/dev/mtdblock/3目录
  • txxLinux联盟
    txxLinux联盟
    txxLinux联盟
    目前flash的文件系统比较多,用的比较多的就是JFFS2文件系统。基于NOR flash上的JFFS2文件系统可以说算是比较成熟了,支持NAND flash的JFFS2也已经发布了。源代码可以到http://www.linux-mtd.infradead.org上面下载。但是在我的测试过程中,在nand flash上挂接的JFFS2文件系统很不稳定,经常有CRC错误产生。特别是进行写操作的时候,每次复位都会产生CRC错误,可以说支持NAND flash的JFFS2文件系统目前还不成熟。而YAFFS文件系统则是专门针对NAND flash的,源代码可以到txxLinux联盟
    http://www.aleph1.co.uk/yaffs/index.html上下载。在测试过程中稳定性能比JFFS2文件系统要稳定的多,而且mount分区的时间也比JFFS2文件系统少的多。用JFFS2 mount一个2m的文件系统大约需要1s。下面分别介绍在uclinux下面使用JFFS2和YAFFS文件系统。txxLinux联盟
    1、JFFS2txxLinux联盟
    http://www.linux-mtd.infradead.org上面下载最新的MTD和JFFS2压缩包。压缩包里面还有有关的内核补丁和一些MTD的相关工具。主要的补丁就是ilookup- 2.4.23.patch,因为最新的MTD驱动中要用到一个ilookup()函数。打完补丁、更新了MTD驱动和JFFS2文件系统之后就开始写自己 nand flash驱动了。如果不想把JFFS2作为根文件系统的话,还需要修改MTD_BLOCK_MAJOR。驱动可以参考里面的例子,最简单的就是参考 spia.c。txxLinux联盟
    写驱动主要工作是定义flash分区结构、定义flash读写地址、写控制flash的**_hwcontrol()函数。具体的操作要看所用的nand flash的芯片资料。相对NOR flash来说驱动要简单多了。:)txxLinux联盟
    改完之后再配置txxLinux联盟
    Memory Technology Devices(MTD)下txxLinux联盟
      CONFIG_MTD=YtxxLinux联盟
      CONFIG_MTD_DEBUG=YtxxLinux联盟
      CONFIG_MTD_DEBUG_VERBOSE=3 txxLinux联盟
      CONFIG_MTD_PARTITIONS=YtxxLinux联盟
      CONFIG_MTD_CHAR=YtxxLinux联盟
      CONFIG_MTD_BLOCK=Y txxLinux联盟
    NAND Flash Device Drivers下txxLinux联盟
      CONFIG_MTD_NAND=YtxxLinux联盟
      定义自己的驱动文件 txxLinux联盟
    File systems下txxLinux联盟
    CONFIG_JFFS2_FS=YtxxLinux联盟
      CONFIG_JFFS2_FS_DEBUG=2txxLinux联盟
    CONFIG_JFFS2_FS_NAND=y /*这个是新加的*/txxLinux联盟
    在uClinux v1.3.4 Configuration下txxLinux联盟
    Flash Tools下txxLinux联盟
    CONFIG_USER_MTDUTILS=YtxxLinux联盟
      CONFIG_USER_MTDUTILS_ERASE=YtxxLinux联盟
      CONFIG_USER_MTDUTILS_ERASEALL=YtxxLinux联盟
      CONFIG_USER_MTDUTILS_MKFSJFFS2=YtxxLinux联盟
    最后就是辛苦了调试工作了。:(MTD驱动调试完之后,就可以在上面挂接JFFS2文件系统了。参看flash分区情况:cat /proc/mtd,擦除分区:eraseall /dev/mtd*.例如把第一个分区mount到/mnt目录下面:txxLinux联盟
    先:eraseall /dev/mtd0txxLinux联盟
    然后:mount -t jffs2 /dev/mtdblock0 /mnttxxLinux联盟
    2、YAFFStxxLinux联盟
    YAFFS意义为'yet another flash file system',也是一个开源的文件系统。YAFFS是目前为止唯一一个专门为NAND flash设计的文件系统,具有很好的可移植性,能够在linux,uclinux,和wincetxxLinux联盟
    下面运行。txxLinux联盟
    http://www.aleph1.co.uk/yaffs/index.html上下载源代码。压缩包里面也包含YAFFS的说明文档。YAFFS文件系统的源文件就devextras.h,yaffs_ecc.c, yaffs_ecc.h,yaffs_guts.c,yaffs_guts.h,yaffs_mtdif.h,yaffs_mtdif.c和 yportenv.htxxLinux联盟
    另外需要配置的宏:CONFIG_YAFFS_FS 和CONFIG_YAFFS_MTD_ENABLED,就是配置在mtd上面挂接YAFFS,其它还有一些辅助配置需要时也可以配置。txxLinux联盟
    在fs目录下面建一个yaffs目录,把以上说的文件考里面去,新建一个makefile:txxLinux联盟
    O_TARGET := yaffs.otxxLinux联盟
    obj-y := yaffs_fs.o yaffs_guts.o yaffs_mtdif.o yaffs_ecc.otxxLinux联盟
    obj-m := $(O_TARGET)txxLinux联盟
    include $(TOPDIR)/Rules.maketxxLinux联盟
    接下来就是改fs目录下面config.in和makefile,在配置YAFFS的时候,把YAFFS连接进去。txxLinux联盟
    如果像前面一样已经把NAND MTD驱动调好了,加YAFFS就很简单了。因为YAFFS是自己做ECC校验的,所以要把MTD驱动里面的ECC去掉。在驱动里面改成this->eccmode = NAND_ECC_NONE就可以了。txxLinux联盟
    另外YAFFS是用mkyaffs来擦除flash,所以在mtd-utils中加上mkyaffs.c,一起编译进去。txxLinux联盟
    最后就是编译了,呵呵。中间会有一些警告没有关系的,就是写没有用的变量和函数,不过话说回来YAFFS的代码写的确实不太规范。当然它的性能确实没话说。有兴趣的可以试一下。
    来顶一下
    近回首页
    返回首页
    发表评论 共有条评论
    用户名: 密码:
    验证码: 匿名发表
    相关文章
    栏目更新
    栏目热门