YAFFS2源码分析
DM9000驱动移植详解及问题点

OK6410、2.6.36内核移植,dm9000 驱动移植,详细!分类:嵌入式学习Linux学习2012-04-27 00:54 3004人阅读评论(7) 收藏举报interfaceccompressionresourcesstructtable还是先来吐槽:本来我是在上一个星期的周末已经把Linux2.6.34.11 的驱动已经成功的移植到,OK6410 的开发板上的,并且能够启动主机上的NFS 根文件系统,可是我在周一的时候,开始学习LCD 的驱动程序,在修改内核文件的时候,有几处错误修改,将原来自己做的2.6.34.11 的内核源码搞的乱七八糟的,在这里还是自己在修改内核的时候没有提注重注释,并且没有记录下来自己的操作步骤,以至于我没办法,恢复2.6.34 的内核,所以也就只能重新先开始最基础的内核移植了。
这次我选择的是2.6.36.2 的内核,谁知到一开始移植就出现一大堆问题。
在这里我不得不说,飞凌开发人员对内核修改的代码,管理真的是太扯了,自己在注销任何一个设备是没有一点点注释,就把这个设备原有的线性地址分配给其它设备了,让我让我们这些菜鸟干看着一大堆的报错信息顶个什么用,真的是伤不起。
好了不乱扯了,现在开始记录。
我的开发环境是:VMware Ubuntu 10.10 。
OK6410 A版256M+2G 的开发板。
主机系统:XP。
Uboot:飞凌提供的Uboot。
参考内核:飞凌提供的Forlinx 的2.6.36.2 内核操作步骤以下./ 均代表你的内核根目录1、修改./Makefile191 ARCH ?=arm // 指定cpu类型,arm后面不要有空格,要不然编译是会提醒ARCH 不能为一个目录192 CROSS_COMPILE ?=/usr/local/arm/4.2.2-eabi/usr/bin/arm-linux- // 指定交叉编译器的路径,按照你自己的进行指定路径2、先来说说nand flash 的驱动涉及到的文件:MTD 通用nand flash 驱动程序位置:./drivers/mtd/nand/.nand_base.cNAND Flash 的platform 设备信息: ./drivers/mtd/nand/s3c_nand.c有了上面的依赖驱动依赖程序、接下来修改./arch/arm/mach-s3c64xx/mach-smdk6410.c 1) nandflash 驱动,修改方法加载头文件[cpp]view plaincopyprint?1.#include <linux/mtd/mtd.h>2.#include <linux/mtd/partitions.h>3.#include <plat/nand.h> //这些头文件放在./arch/arm/plat-samsung/include/ 下面添加nand 结构体[cpp]view plaincopyprint?1.// add by acanoe first2.extern void s3c64xx_reserve_bootmem(void); //add by acanoe3.4.5.struct mtd_partition ok6410_nand_part[] = {6. {7. .name = "Bootloader",8. .offset = 0,9. .size = (1 * SZ_1M),10. .mask_flags = MTD_CAP_NANDFLASH,11. },12. {13. .name = "Kernel",14. .offset = (1 * SZ_1M),15. .size = (5*SZ_1M) ,16. .mask_flags = MTD_CAP_NANDFLASH,17. },18. {19. .name = "User",20. .offset = (6 * SZ_1M),21. .size = (120*SZ_1M) ,22. },23. {24. .name = "File System",25. .offset = MTDPART_OFS_APPEND,26. .size = MTDPART_SIZ_FULL,27. }28.};29.30.31.static struct s3c2410_nand_set ok6410_nand_sets[] = {32. [0] = {33. .name = "nand",34. .nr_chips = 1,35. .nr_partitions = ARRAY_SIZE(ok6410_nand_part),36. .partitions = ok6410_nand_part,37. },38.};39.40.41.static struct s3c2410_platform_nand ok6410_nand_info = {42. .tacls = 25,43. .twrph0 = 55,44. .twrph1 = 40,45. .nr_sets = ARRAY_SIZE(ok6410_nand_sets),46. .sets = ok6410_nand_sets,47.};48.//add by acanoe first修改 smdk6410_devices[] __initdata = {对照这个结构体将那些进行修改,注意 by acanoe 的语句为修改重点。
深入理解yaffs2文件系统(一)

深⼊理解yaffs2⽂件系统(⼀)深⼊理解yaffs2⽂件系统(⼀)1、Flash⽂件系统1.1、背景已经有多种flash⽂件系统(FFSs)或flash块驱动(在之上运⾏⼀个常规的FS),同时都有优点或缺点。
Flash存储器有⾮常多的限制,这⾥就不⼀⼀列举了。
已经有各种⽅法解决这些限制,以提供⼀个⽂件系统。
必须认识到,“flash”,包括NOR和NAND,各⾃有不同的限制。
很容易被专业术语“flash”误导,误以为⽤于NorFlash的⽅法也⽴即适⽤于NandFlash。
Nand块驱动⼀般采⽤FAT16作为⽂件系统,但不够健壮,也不够贴近Flash的特性。
这些块驱动通过⼀个“本地--物理”的映射层来仿真可写的、类似于磁盘扇区的块。
当使⽤FAT16时,这些⽂件系统⼯作的相当好,它们内存消耗⼩,代码尺⼨也很⼩。
但就像所有基于FAT 的系统⼀样,它们很容易损坏(如,丢失簇)。
其他的途径则是设计整个⽂件系统,不是基于块驱动,⽽且是flash友好的,这允许更多的余地来解决上述所提到的问题。
当前有两个linux⽂件系统能⾮常好的⽀持NorFLash,那就是JFFS以及它的升级版本JFFS2。
这两者都提供⽇志机制,⼤⼤的提升了健壮性,这也是嵌⼊式系统特别重要的⼀个特性。
不幸的是,它们在RAM消耗和启动时间⽅⾯都不是很好。
JFFS在flash中的每⼀个journalling⽇志节点,需要⼀个基于RAM的jffs_node结构,每⼀个节点为48字节。
JFFS2做了⼀个⼤改进,通过剪裁相关的结构体(jffs2_raw_node_ref)⽽减少到16字节。
即使如此,在512字节页⼤⼩128M的NandFlash,按平均节点⼤⼩来算,也需要250000字节约4M⼤⼩。
JFFS和JFFS2在启动时,需要扫描整个flash阵列来查找journaling节点,并决定⽂件结构。
由于NAND容量⼤、慢、连续访问、需要ECC校验,这些特性将导致不可接受的、很长的启动时间。
基于Linux的大容量Yaffs文件系统性能优化与实现

基于Linux的大容量Yaffs文件系统性能优化与实现刘翠玲;时兴;孙晓荣;梁明全【摘要】针对Yaffs文件系统应用在大容量存储设备时所产生挂载速度慢的问题,提出一种新的改进方法,并在Yaffs2文件系统中进行了实现。
通过在Yaffs2文件系统中增加适当的偏移量,使得在扫描挂载文件系统时减少了不必要的扫描时间,从而加快了挂载的速度。
在最新的Yaffs2文件系统当中,依据该方法修改Yaffs2源代码,同时,在Linux系统上加入了对改进后文件系统的支持。
对改进前后的性能进行分析和实验,表明了该方法的可行性。
%AimingattheproblemofslowmountspeedofYaffsfilesystemoccurredwh entobeappliedinstoragedeviceswithlarge capacity,we propose a new improved method,and implement it in Yaffs2 file system.By adding appropriate offset in Yaffss file system,the unnecessary scanning time is reduced when scanning the mounting file system,thereby the mounting speed is accelerated.In latest Yaffs2 file system,we modify the source code of Yaffs2.Meanwhile,we add the support to the modified Yaffs file systemin the Linux system,and analyse the performance before and after the modification.Experiments demonstrate the feasibility of the method.【期刊名称】《计算机应用与软件》【年(卷),期】2014(000)009【总页数】3页(P37-39)【关键词】Yaffs;文件系统;Linux;Flash【作者】刘翠玲;时兴;孙晓荣;梁明全【作者单位】北京工商大学计算机与信息工程学院北京 100048;北京工商大学计算机与信息工程学院北京 100048;北京工商大学计算机与信息工程学院北京100048;北京工商大学计算机与信息工程学院北京 100048【正文语种】中文【中图分类】TP3150 引言在科技高速发展的今天,尤其是以安卓系统为基础的一系列电子产品不断的发展,智能手机,平板电脑,智能电视,数码相机等等的一系列产品都离不开文件系统的支持。
基于YAFFS2文件系统的分区管理对载荷数据存储效率的研究

基于YAFFS2文件系统的分区管理对载荷数据存储效率的研究WU Can-qiang;RUI Ye;PAN Dong-mei【摘要】为了引入嵌入式文件系统以解决卫星载荷数据管理难的问题,同时针对新研文件系统可靠性和功能完整性缺乏验证等缺点,本文选用YAFFS2文件系统作为优化基础.然而由于在星栽环境下YAFFS2文件系统的类日志型结构存在对多载荷/多任务数据管理粒度粗、数据存储效率较低等问题,本文提出在YAFFS2文件系统中引入分区管理功能.通过改进YAFFS2文件系统数据结构、设计并实现分区内管理机制和分区间管理机制,实现对多载荷/任务数据的隔离管理,同时提高对复杂数据的检索效率.实验结果表明,分区YAFFS2文件系统在实现对不同文件数据的读写操作时,其读写速度稳定优于原YAFFS2文件系统.【期刊名称】《电子设计工程》【年(卷),期】2018(026)023【总页数】6页(P42-47)【关键词】YAFFS2文件系统;分区管理;载荷数据;存储效率【作者】WU Can-qiang;RUI Ye;PAN Dong-mei【作者单位】【正文语种】中文【中图分类】TP3如今我国航天技术不断提高,卫星应用需求也随之扩大,其存储的载荷数据种类、数据量逐渐增加,数据存储管理难度日益加大[1]。
虽然星载数据存储器经传统的基于FPGA的方式设计后将读写方式由最初以字节为单位线性编址的流读写方式发展为基于文件分配表的文件读写方式[2],但是为了解决Flash存储器应用存在的不覆盖写、磨损均衡问题并实现文件系统的完整功能,使用嵌入式文件系统管理星载数据存储器在未来星载数据存储技术的发展上显得尤为必要。
目前常用的嵌入式文件系统主要有两种:一种是JFFS/JFFS2文件系统[3-4],其专门针对NOR FLASH存储介质设计,因此用于NAND FLASH存储介质上效果不佳;另外一种则是YAFFS/YAFFS2文件系统[5-6],其专门针对NAND FLASH存储介质的特性设计,具有崩溃恢复、坏块管理、损耗均衡、垃圾回收及错误探测/错误更正(EDC/ECC)的FLASH文件系统必须具备的功能。
yaffs2根文件系统的制作

Yaffs2文件系统移植到mini2440现在大部分开发板都可以支持yaffs2 文件系统,它是专门针对嵌入式设备,特别是使用nand flash作为存储器的嵌入式设备而创建的一种文件系统,早先的yaffs仅支持小页(512byte/page)的nand flash,使用yaffs2 就可以支持大页的nand flash。
所谓的根文件系统,就是创建各个目录,并且在里面创建各种文件,比如在/bin,/sbin/目录下存放各种可执行的程序,在/etc目录下存放配置文件,在/lib目录下存放库文件,下面就开始文件系统的移植。
一、准备工作1.Yaffs2源代码的获取在bbb:///node/346可以下载到最新的yaffs2 源代码,如果使用git工具,在命令行输入:就可以下载到yaffs2的源代码,到当前目录下。
2.下载Busybox-1.13.3可以从bbb:///downloads/下载Busybox-1.13.3。
3.下载Yaffs2的整理工具可以到友善之臂的网站下载,mkyaffs2image.tgz,其中解压出来有两个可执行的文件,一个是针对小页的,一个是针对NandFlash大页的,其名字为mkyaffs2image-128M,一开始在这里犯了错误,我的NandFlash是128MB的,可以按照网上用的是mkyaffs2image文件,所以老是出来假坏块的提示,仔细一分析,NandFlash不可能一下子出来这么多的坏块,而且我用他们公司提供的根文件系统却没有任何的问题,所以问题处在了整理Yaffs2的工具上面。
因为这两种大小NandFlash的ECC校验是不一样的,也就是spare区的大小是不一样的,造成了ECC校验出错。
4.链接库整理根文件系统时,要使用到链接库,这里直接使用友善之臂根文件系统中的链接库。
从网站下载root_qtopia.tgz。
使用lib目录下的链接库。
5.给内核打上YAffs2补丁然后进入yaffs2源代码目录执行:#cd yaffs2#./patch-ker.sh c /opt/mini2440/linux-2.6.33.3此时进入linux-2.6.32.2/fs目录,可以看到已经多了一个yaffs2目录。
yaffs2分析(原)

yaffs2分析(原)文件系统的重要作用就是对文件或者文件夹的数据进行相应的管理,无论是文件数据还是文件夹里面的内容数据在文件系统看来就是一个个元数据(metadata)。
文件系统就是实现这些元数据的相应管理。
由于yaffs2 是一个相对比较简单的文件系统,下面通过yaffs的启动过程看看yaffs文件元数据的组织。
由于Yaffs是基于nand flash 的,由于nand所特有的一些特性,所以yaffs就有了一些自身文件系统所特有的一些特性。
如文件的结构信息是保存在spare 里面的,无论是文件夹数据还是文件数据,都是保存到spare数据的。
typedef struct {unsigned sequenceNumber;unsigned objectId;unsigned chunkId;unsigned byteCount;} yaffs_PackedTags2TagsPart;保存在spare 里面的yaffs2结构如上。
在yaffs启动时候,如果checkpoint没有响应的保存掉电时的结构的话,就需要进行一下全盘的扫描,其中的扫描主要是在yaffs_scan里面完成的,文件系统结构的创建就是主要在这个scan的过程中实现的。
static int yaffs_Scan(yaffs_Device *dev){1 首先就是要对全盘的block 块进行相应的扫描,主要就是扫描出坏的块/* Scan all the blocks to determine their state */bi = dev->blockInfo;for (blk = dev->internalStartBlock; blk <= dev->internalEndBlock; blk++) {}2 对于坏的块进行相应的标记玩之后,就是逐个对block 里面每一个page进行扫描,并建立相应的结构/* For each chunk in each block that needs scanning....*/for (c = 0; !alloc_failed && c < dev->param.nChunksPerBlock &&state == YAFFS_BLOCK_STATE_NEEDS_SCANNING; c++) {if (!tags.chunkUsed) {如果是一个未被使用的page的话由系统进行回收。
LinuxYAFFS文件系统实现机制分析

核心结构在内存中的建立—Mount过程
3.在内存中建立文件系统的目录结构。 基于“异域更新”的日志结构文件系统的特点
➢Tnode的始地址及高度: 保存在yaffs_FileStructure结构中,结构成员的值是在
文件系统Mount过程中获得的。文件结构指针地址最终 会提供给yaffs_object结构。
2020/4/20
• YAFFS的实现机制
➢核心结构在内存中的建立—Mount过程 ➢Linux下YAFFS文件系统的读写操作
YAFFS的基本特征
2) NAND Flash只能从1写为0,不能从0写为1; 3) 每个擦除块的可擦除次数有限,一般为100万 次;
➢YAFFS采用了日志结构文件系统的“异域更新 ”策略。每次按Flash页写入操作的时候,将新 的元数据和用户数据作为日志记录追加到日志。
➢ YAFFS对NAND Flash的废旧数据块回收的条 件:1)分配使用最早 2)存在的无效数据页最 多3)条件类似的情况下,进行随机选单位存的是16 位的物理Chunk的地址。
Level 1
…… Level 0
back
➢Tree的增高和增宽: 小于16*2K的文件, chunk ID<16,Tnode结构只有一级; 即internal level =0; 32K<file size< 256K, chunk ID<128,Tnode结构有两级 ; 即internal level =1; 类推,Tnode结构不超过六级。
,只是在面向VFS进行了一个封装。
back
2020/4/20
YAFFS通过多级树节点结构(Tnode)提供了对文件操作时 的Logical Address到Physical Address 的转换。
android镜像文件说明

android 源码编译完成后会生成三个镜像文件 system.img ->yaffs2格式 userdata.img ->yaffs2格式 ramdisk.img ->cpio 前两个文件可以挂载,但ubantu14.04默认不支持yaffs2格式,需编译内核。 windows下有解析此格式的软件 ramdisk.img 首先 file ramdisk.img ramdisk.img: gzip compressed data, from Unix 看出为gzip压缩过的文件,将ramdisk.img重命名为ramdisk.img.gz mv ramdisk.img ramdisk.img.gz 再用file来看一下ramdisk.img,此时为 ramdisk.img: ASCII cpio archive (SVR4 with no CRC) 这时候使用cpio来提取ramdisk.img中的内容 mkdir temp cp temp cpio -i -F ../ramdisk.img.gz 就解压开了 实际编译完成后out文件夹里 system.img ->system文件夹 userdata.img ->data文件夹 ramdisk.img -> root文件夹
ramdisk.img相当于根目录 system.img和userdata.img分别挂载到ramdisk的system和data文件夹。
Hale Waihona Puke
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
狗拿耗子YAFFS2———狗拿耗子第三篇 1、YAFFS2 的背景 YAFFS2 是Charles Manning开发的NAND Flash文件系统。
可以从获得详细的描 述和最新的版本。
关于Nand Flash与Nor Flash的不同之处,网上有很多文章叙述,这里不再 罗嗦。
反正是在嵌入式系统中,一般是Nor Flash存放在Boot程序,Nand Flash作为正式的存 储设备使用。
YAFFS (Yet Another Flash File System) was designed and written by Charles Manning, of Whitecliffs, New Zealand, for the company Aleph One. YAFFS is the first file system that was designed specifically for NAND flash. Yaffs1 is the first version of this file system and works on NAND chips that have 512 byte pages + 16 byte spare (OOB;Out-Of-Band) areas. These older chips also generally allow 2 or 3 write cycles per page, which YAFFS takes advantage of - i.e. dirty pages are marked by writing to a specific spare area byte. Newer NAND flash chips have larger pages, 2048 bytes + 64 bytes spare areas, and stricter write requirements. Each page within a block must be written to in sequential order, and each page must be written only once. YAFFS2 was designed to accommodate these newer chips. YAFFS2 is based on the YAFFS1 source code, with the major difference being that internal structures are not fixed to assume 512 byte sizing, and a block sequence number is placed on each written page. In this way older pages can be logically overwritten without violating the "write once" rule. YAFFS is a robust log-structured file system that holds data integrity as a high priority. A secondary YAFFS goal is high performance. YAFFS will typically outperform most alternatives. It is also designed to be portable and has been used on Linux, WinCE, pSOS, eCOS, ThreadX and various special-purpose OSes. A variant 'YAFFS/Direct' is used in situations where there is no OS, embedded OSes and bootloaders: it has the same core filesystem but simpler interfacing to the OS and NAND flash hardware. The filesystem is licensed both under the GPL and under per-product licences available from Aleph One. YAFFS1 YAFFS has no inherent formatting, an erased flash chip is formatted. It follows the smart media scheme of marking the 5th byte of the spare area for bad blocks, and ignores any blocks where the spare area byte 5 is not 0xFF. To write file data, YAFFS initially writes a whole page (chunk in YAFFS terminology) that describes the file metadata, such as timestamps, name, path, etc. The new file is assigned a unique object ID number; every data chunk within the file will contain this unique object ID within the spare area. YAFFS maintains a tree structure in RAM memory of the physical location of these1狗拿耗子chunks. When a chunk is no longer valid (the file is deleted, or parts of the file are overwritten), YAFFS marks a particular byte in the spare area of the chunk as ‘dirty’. When an entire block (32 pages) is marked as dirty, YAFFS can erase the block and reclaim the space. If free space on the device is low, YAFFS may need to choose a block that has some number of dirty pages and some number of good pages, move the good pages to a new block, mark the old pages as dirty and erase the block. The process of moving good pages & erasing blocks is called Garbage Collection. When a YAFFS system mounts a NAND flash device, it must scan the spare areas of every block to check for valid data, whereby it can then reconstitute the tree data structures. YAFFS2 YAFFS2 is similar in concept to YAFFS1, and shares much the same code; and the YAFFS2 code base supports YAFFS1 data formats through backward compatibility. The main difference is that YAFFS2 needs to jump through significant hoops to meet the "write once" requirement of modern NAND flash. YAFFS2 marks every newly written block with a sequence number that is monotonically increasing. The sequence of the chunks can be inferred from the block sequence number and the chunk offset within the block. Thereby when YAFFS2 scans the flash and detects multiple chunks that have identical ObjectIDs and ChunkNumbers, it can choose which to use by taking the greatest sequence number. For efficiency reasons YAFFS2 also introduces the concept of shrink headers. For example when a file is resized to a smaller size, YAFFS1 will mark all of the affected chunks as dirty - YAFFS2 cannot do this due to the "write once" rule. YAFFS2 instead writes a "shrink header", which indicates that a certain number of pages before that point are invalid. This lets YAFFS2 reconstruct the final state of the filesystem when the system reboots. YAFFS2 uses a more abstract definition of the NAND flash allowing it to be used with a wider variety of flash parts with different geometries, bad block handling rules etc. YAFFS2 now supports "checkpointing" which bypasses normal mount scanning, allowing very fast mount times. Mileage will vary, but mount times of c. 3 seconds for 2 GB have been reported.2狗拿耗子2、chunk 与 block K9F1208 是 64M 的 Nand Flash, 一个 chunk 包含 512byte 的 data area, 16byte 的 spare area, 与 32 个 chunk 构成了一个 block。