我我的以为nandflash上用yaffs2文件系统是很好的方案,可是最新的Linux并不支持yaffs2文件系统,须要你本身给内核打补丁,不过话说在前面,因为内核间差别及兼容问题,在编译时确定会出现各类编译问题,须要你一一的去解决。node
1、准备工做linux
1. 下载源码git
使用git工具下载:$ git clone git://www.aleph1.co.uk/yaffs2 函数
2. 给内核打补丁工具
下载完成后,在该执行目录下会有yaffs2文件夹,进入该文件夹。ui
$ ./patch-ker.sh c m ../../kernel/test/linux-3.14.4this
Updating ../../kernel/test/linux-3.14.4/fs/Kconfig
Updating ../../kernel/test/linux-3.14.4/fs/Makefilespa
有以上两个信息,说明已经打好补丁,而且在fs/目录下,多了yaffs2文件夹,其实这是从yaffs2文件夹中复制过来的。debug
2、内核配置code
下面配置内核,在linux目录下make menuconfig
咱们发如今File system—>Miscellaneous filesystems—>下面并找不到yaffs2选项。原来是这样的
查看YAFFS2的Kconfig文件,须要先选择MTD_BLOCK才会有显示YAFFS2

#
# yaffs file system configurations
#
config YAFFS_FS
tristate "yaffs2 file system support"
default n
depends on MTD_BLOCK
select YAFFS_YAFFS1
select YAFFS_YAFFS2
help
也就说须要先选择Device Drivers-->MTD-->Caching block device access to MTD devices,而后才可以在File Systems--->Miscellaneous filesystem下面找到YAFFS2。


好的 ,配置完后,这下要执行make clean;make uImage了。剩下的工做就是解决一大堆编译错误了!!!!
下面看看编译的错误:

CC fs/yaffs2/yaffs_vfs.o
fs/yaffs2/yaffs_vfs.c: In function 'yaffs_mknod':
fs/yaffs2/yaffs_vfs.c:1228: error: incompatible types when initializing type 'uid_t' using type 'kuid_t'
fs/yaffs2/yaffs_vfs.c:1230: error: incompatible types when initializing type 'gid_t' using type 'const struct <anonymous>'
fs/yaffs2/yaffs_vfs.c: In function 'yaffs_symlink':
fs/yaffs2/yaffs_vfs.c:1427: error: incompatible types when initializing type 'uid_t' using type 'kuid_t'
fs/yaffs2/yaffs_vfs.c:1429: error: incompatible types when initializing type 'gid_t' using type 'const struct <anonymous>'
fs/yaffs2/yaffs_vfs.c: At top level:
fs/yaffs2/yaffs_vfs.c:1786: error: unknown field 'readdir' specified in initializer
fs/yaffs2/yaffs_vfs.c:1786: warning: initialization from incompatible pointer type
fs/yaffs2/yaffs_vfs.c: In function 'yaffs_fill_inode_from_obj':
fs/yaffs2/yaffs_vfs.c:1832: error: incompatible types when assigning to type 'kuid_t' from type 'u32'
fs/yaffs2/yaffs_vfs.c:1833: error: incompatible types when assigning to type 'kgid_t' from type 'u32'
fs/yaffs2/yaffs_vfs.c:1857: warning: format '%d' expects type 'int', but argument 3 has type 'kuid_t'
fs/yaffs2/yaffs_vfs.c:1857: warning: format '%d' expects type 'int', but argument 4 has type 'kgid_t'
fs/yaffs2/yaffs_vfs.c: In function 'yaffs_proc_debug_write':
fs/yaffs2/yaffs_vfs.c:3300: warning: comparison of distinct pointer types lacks a cast
fs/yaffs2/yaffs_vfs.c: In function 'init_yaffs_fs':
fs/yaffs2/yaffs_vfs.c:3394: error: implicit declaration of function 'create_proc_entry'
fs/yaffs2/yaffs_vfs.c:3395: warning: assignment makes pointer from integer without a cast
fs/yaffs2/yaffs_vfs.c:3398: error: dereferencing pointer to incomplete type
fs/yaffs2/yaffs_vfs.c:3399: error: dereferencing pointer to incomplete type
fs/yaffs2/yaffs_vfs.c:3400: error: dereferencing pointer to incomplete type
make[2]: *** [fs/yaffs2/yaffs_vfs.o] Error 1
make[1]: *** [fs/yaffs2] Error 2
make: *** [fs] Error 2
1. 出现error: incompatible types when initializing type 'uid_t' using type 'kuid_t' ,应该是不兼容问题致使,修改:
uid_t改成kuid_t和gid_t 改成kgid_t
剩下的关于这个变量的问题不少,可是都是关于兼容性的,你们在修改时只须要知道只要不兼容,那咱们就把全部用到的改到兼容的kuid_t为止。
这里修改的地方和文件有点多,我就不一一列出来了
2. error: implicit declaration of function 'create_proc_entry'
因为最新的内核不支持这个函数,须要注释掉并改成my_proc_entry = proc_create("yaffs",S_IRUGO | S_IFREG, YPROC_ROOT, &yaffs_fops);
最终修改以下:

mutex_init(&yaffs_context_lock);
my_proc_entry = proc_create("yaffs",
S_IRUGO | S_IFREG, YPROC_ROOT, &yaffs_fops);
#if 0
/* Install the proc_fs entries */
my_proc_entry = create_proc_entry("yaffs",
S_IRUGO | S_IFREG, YPROC_ROOT);
if (my_proc_entry) {
my_proc_entry->write_proc = yaffs_proc_write;
my_proc_entry->read_proc = yaffs_proc_read;
my_proc_entry->data = NULL;
} else {
return -ENOMEM;
}
#endif
3. error: unknown field 'readdir' specified in initializer
在init_yaffs_fs函数前添加如下代码

static const struct file_operations yaffs_fops = { .owner = THIS_MODULE, .read = yaffs_proc_read, .write = yaffs_proc_write, };
static int __init init_yaffs_fs(void)
修改了以上,咱们就能编译经过了。目前,内核就支持yaffs2文件系统了。
下一篇文件咱们来用busybox制做yaffs2文件系统。