Linux+yaffs文件系统移植
一.linux 2.6内核的移植
1)从http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.14.1.tar.bz2
下载linux-2.6.14.1内核至/usr/src/
[root@localhost src]#tar xzvf linux-2.6.14.1.tar.gz
[root@localhost src]# cd linux-2.6.14
2)修改Makefile
修改内核目录树根下的的Makefile,指明交叉编译器
[root@localhost linux-2.6.14]# vi Makefile
找到ARCH和CROSS_COMPILE,修改
ARCH = arm
CROSS_COMPILE = arm-linux-
[arm@localhost linux-2.6.14]# export PATH=/usr/local/arm/3.4.4/bin:$PATH
(假设你的交叉编译工具在/usr/local/arm/3.4.4/bin下)
3)修改内核
在arch/arm/mach-s3c2410/devs.c文件中:
[root@localhost linux-2.6.14]$ vi arch/arm/mach-s3c2410/devs.c
添加如下内容:
#include <linux/mtd/partitions.h>
#include <linux/mtd/nand.h>
#include <asm/arch/nand.h>
...
/* NAND Controller */
1.建立Nand Flash分区表
/* 一个Nand Flash总共64MB, 按如下大小进行分区 */
static struct mtd_partition partition_info[] ={
{
name: "vivi",
size: 0x00020000,
offset: 0x00000000,
},{
name: "param",
size: 0x00010000,
offset: 0x00020000,
}, {
name: "kernel",
size: 0x00100000,
offset: 0x00030000,
}, { /* 20MB */
name: "root",
size: 0x03ec0000,
offset: 0x00130000,
},
};
name: 代表分区名字
size: 代表flash分区大小(单位:字节)
offset: 代表flash分区的起始地址(相对于0x0的偏移)
2. 加入Nand Flash分区
struct s3c2410_nand_set nandset ={
nr_partitions: 4, /* the number of partitions */
partitions: partition_info, /* partition table */
};
nr_partitions: 指明partition_info中定义的分区数目
partitions: 分区信息表
3. 建立Nand Flash芯片支持
struct s3c2410_platform_nand superlpplatform={
tacls:0,
twrph0:30,
twrph1:0,
sets: &nandset,
nr_sets: 1,
};
tacls, twrph0, twrph1的意思见S3C2410手册的6-3, 这3个值最后会被设置到NFCONF中,见S3C2410手册6-6.
sets: 支持的分区集
nr_set:分区集的个数
4. 加入Nand Flash芯片支持到Nand Flash驱动
另外,还要修改此文件中的s3c_device_nand结构体变量,添加对dev成员的赋值
struct platform_device s3c_device_nand = {
.name = "s3c2410-nand", /* Device name */
.id = -1, /* Device ID */
.num_resources = ARRAY_SIZE(s3c_nand_resource),
.resource = s3c_nand_resource, /* Nand Flash Controller Registers */
/* Add the Nand Flash device */
.dev = {
.platform_data = &superlpplatform
},
};
name: 设备名称
id: 有效设备编号,如果只有唯一的一个设备为-1, 有多个设备从0开始计数.
num_resource: 有几个寄存器区
resource: 寄存器区数组首地址
dev: 支持的Nand Flash设备
修改arch/arm/mach-s3c2410/mach-smdk2410.c文件
[root@localhost linux-2.6.14]$ vi arch/arm/mach-s3c2410/mach-smdk2410.c
修改smdk2410_devices[].指明初始化时包括我们在前面所设置的flash分区信息
static struct platform_device *smdk2410_devices[] __initdata = {
&s3c_device_usb,
&s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c,
&s3c_device_iis, (93行)
/* 添加如下语句即可 */
&s3c_device_nand,
};
保存,退出。
修改drivers/mtd/nand/s3c2410.c 文件:
[root@localhost linux-2.6.14]$ vi drivers/mtd/nand/s3c2410.c
找到s3c2410_nand_init_chip()函数(509行),在该函数体最后加上一条语句:
chip->eccmode = NAND_ECC_NONE;
保存,退出。
为了我们的内核支持devfs以及在启动时并在/sbin/init运行之前能自动挂载/dev为devfs文件系统,修改
fs/Kconfig文件
[root@localhost linux-2.6.14]$ vi fs/Kconfig
找到menu "Pseudo filesystems" (734行)
添加如下语句:
config DEVFS_FS
bool "/dev file system support (OBSOLETE)"
default y
config DEVFS_MOUNT
bool "Automatically mount at boot"
default y
depends on DEVFS_FS
为了使我们的内核支持yaffs及yaffs2文件系统,从http://www.aleph1.co.uk/cgi-bin/viewcvs.cgi/yaffs2.tar.gz?view=tar下载yaffs2.tar.gz,并解压到/tmp。
[root@localhost tmp]# cd yaffs2
[root@localhost yaffs2]# sh patch-ker.sh /usr/src/linux-2.6.14
执行完后,我们的yaffs2已经加入到了内核。
4)配置内核产生.config文件
[root@localhost linux-2.6.14]$ make smdk2410_defconfig
[root@localhost linux-2.6.14]$ make menuconfig
在smdk2410_defconfig基础上,我所增删的内核配置项如下:
Loadable module support --->
[*] Enable loadable module support
[*] Automatic kernel module loading
System Type ---> [*] S3C2410 DMA support
Boot options ---> Default kernel command string:
noinitrd root=/dev/mtdblock/3 init=/linuxrc console=ttySAC0,115200
#说明:mtdblock/3代表我的第4个root分区,它是我的rootfs
# console=ttySAC0,115200使kernel启动期间的信息全部输出到串口0上.
# 2.6内核对于串口的命名改为ttySAC0.
Floating point emulation --->
[*] NWFPE math emulation
This is necessary to run most binaries!!!
#接下来要做的是对内核MTD子系统的设置
Device Drivers --->
Memory Technology Devices (MTD) --->
[*] MTD partitioning support
#支持MTD分区,这样我们在前面设置的分区才有意义
[*] Command line partition table parsing
#支持从命令行设置flash分区信息,灵活
[*] Direct char device access to MTD devices
[*] Caching block device access to MTD devices
RAM/ROM/Flash chip drivers --->
<*> Detect flash chips by Common Flash Interface (CFI) probe
<*> Detect non-CFI AMD/JEDEC-compatible flash chips
<*> Support for Intel/Sharp flash chips
<*> Support for AMD/Fujitsu flash chips
<*> Support for ROM chips in bus mapping
NAND Flash Device Drivers --->
<*> NAND Device Support
<*> NAND Flash support for S3C2410/S3C2440 SoC
Character devices --->
[*] Non-standard serial port support
[*] S3C2410 RTC Driver
File systems --->
<> Second extended fs support #去除对ext2的支持
Pseudo filesystems --->
[*] /proc file system support
[*] Virtual memory file system support (former shm fs)
[*] /dev file system support (OBSOLETE)
[*] Automatically mount at boot (NEW)
Miscellaneous filesystems --->
[*] YAFFS2 file system support
512 byte / page devices
[*] Lets Yaffs do its own ECC
[*] Use the same ecc byte order as Steven Hill's nand_ecc.c
--- 2048 byte (or larger) / page devices
[*] Autoselect yaffs2 format
[*] Disable lazy loading
[*] Turn off wide tnodes
[*] Turn off debug chunk erase check
[*] Cache short names in RAM
Network File Systems --->
<*> NFS file system support
保存退出,产生.config文件.
5)编译内核
[root@localhost linux-2.6.14]$ make
注意:若编译内核出现如下情况
LD .tmp_vmlinux1
arm-linux-ld:arch/arm/kernel/vmlinux.lds:1439: parse error
make: *** [.tmp_vmlinux1] Error 1
解决方法:修改arch/arm/kernel/vmlinux.lds
[root@localhost linux-2.6.14]$ vi arch/arm/kernel/vmlinux.lds
将文件尾2条的ASSERT注释掉(1439行)
/* ASSERT((__proc_info_end - __proc_info_begin), "missing CPU support") */
/* ASSERT((__arch_info_end - __arch_info_begin), "no machine record defined") */
然后重新make即可
成功后在arch/arm/boot/下产生zImage
�