现在的位置: 首页 > 综合 > 正文

移植Linux根文件系统之yaffs2

2014年06月10日 ⁄ 综合 ⁄ 共 3280字 ⁄ 字号 评论关闭

软硬件环境: ubuntu9.10 Linux 3.4.2 busybox1.20.0 yaffs2

下载好yaffs2之后,请看文档里面的说明README-linux,按照如下步骤操作

ntegrating YAFFS2 into a Linux 2.6.x kernel
--------------------------------------------

We'll start by assuming you have a building linux 2.6.x source tree called
linux-dir and have the
yaffs2 source code in a directory calls yaffs-dir. 

yaffs-dir has a handy shell script called patch-ker.sh will painlessly do all the patching
for you. //你可以手动使用以下脚本来进行安装

patch-ker.sh takes three parameters:
c/l	copy or link: c will copy yaffs files into the kernel tree, l will  
create symbolic links.     //c 直接复制到内核目录中 l是创建一个链接符,这里使用c
m/s	multi-version or single version vfs glue layer. Suggest you use m.
linux-tree  //m 支持多个vfs版本或者单个vfs版本 ,这里使用建议的m

eg.

cd yaffs-dir
./patch-ker.sh  c m linux-tree

You will now have to do "make menuconfig" or similar in the Linux tree to
set up the yaffs2 configs. The configs are found under:
File systems/Miscellaneous file systems/ yaffs2

什么意思呢?里面总结后的步骤

1. 这里我的文档yaffs2和linux3.4.2在同一个文件下,假设在这个两个文件夹上一级,如下就是使用的脚本命令:

cd yaffs2
./patch-ker.sh  c m ../linux-3.4.2/

2.make menuconfig

   File systems/Miscellaneous file systems/

 在上面目录下进行选中yaffs2,Linux 3.4.2内核里面是yaffs2 file system support,使用Y就可,里面有个分页文件的大小,我的开发板使用的nand page 就是2048,退出使用默认设置即可,编译之后却出现了以下问题

fs/yaffs2/yaffs_vfs.c: In function 'yaffs_mtd_put_super':
fs/yaffs2/yaffs_vfs.c:2514: error: 'struct mtd_info' has no member named 'sync'
fs/yaffs2/yaffs_vfs.c:2515: error: 'struct mtd_info' has no member named 'sync'
fs/yaffs2/yaffs_vfs.c: In function 'yaffs_internal_read_super':
fs/yaffs2/yaffs_vfs.c:2702: error: 'struct mtd_info' has no member named 'erase'
fs/yaffs2/yaffs_vfs.c:2703: error: 'struct mtd_info' has no member named 'read'
fs/yaffs2/yaffs_vfs.c:2704: error: 'struct mtd_info' has no member named 'write'
fs/yaffs2/yaffs_vfs.c:2705: error: 'struct mtd_info' has no member named 'read_oob'

这里找到struct mtd_info发现的确没有这个成员,但是却有前面加一个_*的类似成员,为什么呢?

结果里面有明确说明如下

	/*
	 * Do not call via these pointers, use corresponding mtd_*()
	 * wrappers instead.
	 */

意思就是必须使用mtd_sync这种类似的结构,找个例子看下,

static inline void mtd_sync(struct mtd_info *mtd)
{
	if (mtd->_sync)
		mtd->_sync(mtd);
}

可以防止损坏结构体成员,也便于保护成员,看了其他代码,还有些安全性的检查以及其他代码的,所以接下来就按照这个进行修改吧,不过还有一个问题,如下

fs/yaffs2/yaffs_vfs.c:2967: error: implicit declaration of function 'd_alloc_root'

这个函数d_alloc_root没有定义,搜索下这个玩意,找到如下说明

[mandatory]
	d_alloc_root() is gone, along with a lot of bugs caused by code
misusing it.  Replacement: d_make_root(inode).  The difference is,
d_make_root() drops the reference to inode if dentry allocation fails. 

于是乎我们用下面这个函数进行替换

root = d_make_root(inode); //从字面意思理解应该是分配一个根节点的空间,具体没有去看,有此爱好可以进行研究

接下来仍然是按照此步骤修改,然后最终就编译成功了,另外还需修改启动参数

set bootargs console=ttySAC0,115200 root=/dev/mtdblock3

这里默认启动是使用yaffs,所以不用指定,但是启动后弹出没有初始化init选项,如下:

这里是采用韦东山视频中的修改uboot的方式,在divers/mtd/nand/Nand_util,具体原因暂未明,如下加入oob的检查


下面一段有启发意思(还是README-linux):

Formatting a YAFFS device is simply done by erasing it.

Making an initial filesystem can be tricky because YAFFS uses the OOB
and thus the bytes that get written depend on the YAFFS data (tags),
and the ECC bytes and bad block markers which are dictated by the
hardware and/or the MTD subsystem. The data layout also depends on the
device page size (512b or 2K). Because YAFFS is only responsible for
some of the OOB data, generating a filesystem offline requires
detailed knowledge of what the other parts (MTD and NAND
driver/hardware) are going to do.

To make a YAFFS filesystem you have 3 options:

1) Boot the system with an empty NAND device mounted as YAFFS and copy
   stuff on.

2) Make a filesystem image offline, then boot the system and use
   MTDutils to write an image to flash.

3) Make a filesystem image offline and use some tool like a bootloader to
   write it to flash

抱歉!评论已关闭.