2009年5月6日星期三

linux2.6内核移植之二-----linux2.6.29.2内核的编译

移植前的准备工作:

1.安装交叉编译器,2.6内核需要3.0以上的编译器。
2.设置PATH环境变量export PATH=/usr/local/arm/3.4.1(编译器版本)/bin:$PATH
3.解压内核
4.在内核根目录下的Makefile文件中指定要用到的编译器和架构(arch),
方法:将ARCH?=(SUBARCH) 改为,ARCH ?=arm CROSS_COMPILE ?=arm-linux-

5.修改默认内核配置文件(./.config)
cp arch/arm/configs/smdk2410_defconfig ./.config

修改源代码

1.在arch/arm/plat-s3c24xx/common-smdk.c中修改smdk_default_nand_part[],注意这个一定要跟bootloader的一致。在我的板子中修改如下:

static struct mtd_partition smdk_default_nand_part[] = {
[0] = {
.name = "vivi",
.size = 0x00020000,//128K
.offset = 0,
},
[1] = {
.name = "param",
.offset = 0x00020000,
.size = 0x00010000,//64K
},
[2] = {
.name = "kernel",
.offset = 0x00030000,
.size = 0x001d0000,//1M+832K
},
[3] = {
.name = "root",
.offset = 0x00200000,
.size = 0x00100000,//4M
},
[4] = {
.name = "yaffs",
.offset = 0x00600000,
.size = 0x03ad0000,//58M
},
};

另外这个文件还要修改smdk_nand_info如下:
static struct s3c2410_platform_nand smdk_nand_info = {
.tacls = 0, //default is 20
.twrph0 = 30, //default is 60
.twrph1 = 0, //defualt is 20 changed by yangdk
.nr_sets = ARRAY_SIZE(smdk_nand_sets),
.sets = smdk_nand_sets,
};

2.修改nand Flash的校验方式,去掉ECC校验。
在drivers/mtd/nand/s3c2410.c 第669行
将chip->ecc.mode = NAND_ECC_SOFT;
改为 chip->ecc.mode = NAND_ECC_NONE;
注意:这个去掉ECC校验的问题,在内核中明确说明是不建议这样做的,因为这样就等于忽略了对NAND FLASH坏块的检测。而我一开始也是编译的时候就去掉了ECC校验的选项,原以为在编译选项中去掉就可以了,结果一直报这样的错:
end_request: I/O error, dev mtdblock2, sector 0
FAT: unable to read boot sector
VFS: Cannot open root device "mtdblock2" or unknown-block(31,2)
Please append a correct "root=" boot option; here are the available partitions:
1f00 192 mtdblock0 (driver?)
1f01 1856 mtdblock1 (driver?)
1f02 30720 mtdblock2 (driver?)
1f03 32768 mtdblock3 (driver?)
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(31,2)
郁闷了一个整天。后来发现配置中去掉的这个选项在代码中并没有完全去掉,只是去掉了硬件校验的方式,换成了软件校验。只有在代码中给改成NAND_ECC_NONE,才不会校验,但是这样是不提倡的。可是这有这样最后我的系统才起来,阿弥陀佛!


裁剪内核:make menuconfig

1.检查系统类型是不是s3c2410 选项:System Type,确定 S3C2410 DMA support被选中(此项不选在声卡驱动的加载是容易出错。)确定Support Thumb user binaries被选中。
2.检查模块加载支持(系统是否允许自动加载模块),这一项很重要
Loadable module support-> 下,确保Enable loadable module support 和Automatic kernel module loading被选中。
3.支持浮点运算,进入Floating point emulation -> 选中NWFPE math emulation被选中。
4.对可执行文件进行支持 Userspace binary formats -> 确保Kernel support for ELF binaries 和Kernel support for a.out and ECOFF binaries 被选中。
5.网络支持 Networking -> 选中 Networking support ,然后选择Networking options -> 下的 Unix domain sockets(支持unix网络)TCP/IP network
选中它下面的IP:Kernel level autoconfiguration 再选中它下面的IP:BOOTP support
6.内存技术设备支持 Device Drivers -> Memory Technology Devices (MTD) ->
选中 Memory Technology Device (MTD) support、MTD partitioning support(MTD分区支持)、Command line partition table  parsing(命令行分区支持)、Direct char device access to MTD devices(允许以字符设备方式访问内存技术设备)、Caching block device access to MTD devices
7.make zImage 进行编译,将内核复制到开发板上会发现不能正常运行,因
为还没有配置文件系统,继续执行make menuconfig 选择File systems-> 去除这一项下面的 Second extended fs support (扩展分区支持)和 Rom file system support (ROM文件系统支持,我们这里使用nand flash)两项的选择。
9.选择File systems -> Pseudo filesystems -> 下面的/dev file system support (OBSOLETE)、Auto matically mount at root、/proc file system support(支持内核镜像)、Virtual memory file system support (former shm fs) (虚拟内存文件系统)
10.设备的支持  选择Device Drivers -> Memory Technology Devices (MTD) -> ARM/ROM/Flash chip drivers -> 下面的 Detect flash chips by Common Flash Interface (CFI) probe (flash通用芯片接口)、Detect non-CFI AMD/JEDEC-compatible flash chips(非CFI接口芯片支持) 、Support for Intel/Sharp flash chips、Support for AMD/Fujitsu flash chips(富士通Flash芯片支持)、Support for RAM chips in bus mapping (支持RAM芯片总线映射)、Support for ROM chips in bus mapping(…ROM…)。
11.支持 2410/2440 Nand flash 设备
Device Drivers -> NAND Flash Device Drivers -> 选中NAND Device Support 和 NAND Flash support for S3C2410/S3C2410/S3C2440 SoC
12.支持块设备 Device Drivers -> Block devices -> 选择下面的 RAM disk support
选择Device Drivers -> Character devices -> 下的 Non-standard serial port support (支持非标准串口)、Legacy (BSD) PTY support(虚拟终端支持)、S3C2410 RTC Driver(支持实时时钟)
13.文件系统支持 File systems -> Miscellaneous filesystems -> 选中Compressed ROM file system support (cramfs)(cramfs支持)
14.File systems -> Network File Systms -> 选中NFS file system support、Provide NFSv3 client support、Provide client support for the NFSv3 ACL protocol extension (NFS扩展)、Root file system on NFS
15.编译: make zImage 将生成的内核放到开发板上运行,会发现提示,找不到/dev文件系统,必须修改内核使它支持/dev 文件系统才可以进行网络引导。

linux的内核目录结构:

1.arch   硬件体系结构相关的核心代码(arm)下arch/arm
2.include  核心头文件,每一个体系结构就会有一个对应的目录
3.init  内核的核心启动代码
4.ipc 进程以及进程间通信相关代码
5.mm 内存管理部分的代码
6.drivers  驱动程序目录(每个设备,在其中都有文件)
7.modules  放置已经编译好的模块(可缷载模块)
8.fs linux  文件系统支持代码
9.kernel  主要核心代码(与处理器结构无关)
10.arch/架构名/kernel 主要核心代码(与处理器结构相关)
11.net  核心网络代码
12.lib  核心库代码
13.scripts 内核配置脚本 
14.Documentation 所有文档

添加对/dev文件系统的支持

此版本的linux内核虽然不支持devfs,但内核中仍保留其代码。

方法:
在fs/kconfig文件中找到
menu "Pseudo filesystems"

source "fs/proc/Kconfig"
source "fs/sysfs/Kconfig"

在此后添加如下代码:
config DEVFS_FS
bool "/dev file system support (OBSOLETE)"
depends on EXPERIMENTAL
help
This is support for devfs, a virtual file system (like /proc) which
provides the file system interface to device drivers, normally found
in /dev. Devfs does not depend on major and minor number
allocations. Device drivers register entries in /dev which then
appear automatically, which means that the system administrator does
not have to create character and block special device files in the
/dev directory using the mknod command (or MAKEDEV script) anymore.
This is work in progress. If you want to use this, you *must* read
the material in , especially
the file README there.
Note that devfs no longer manages /dev/pts! If you are using UNIX98
ptys, you will also need to mount the /dev/pts filesystem (devpts).
Note that devfs has been obsoleted by udev,
.
It has been stripped down to a bare minimum and is only provided for
legacy installations that use its naming scheme which is
unfortunately different from the names normal Linux installations
use.
If unsure, say N.
config DEVFS_MOUNT
bool "Automatically mount at boot"
depends on DEVFS_FS
help
This option appears if you have CONFIG_DEVFS_FS enabled. Setting
this to 'Y' will make the kernel automatically mount devfs onto /dev
when the system is booted, before the init thread is started.
You can override this with the "devfs=nomount" boot option.
If unsure, say N.
config DEVFS_DEBUG
bool "Debug devfs"
depends on DEVFS_FS
help
If you say Y here, then the /dev file system code will generate
debugging messages. See the file
for more details.
If unsure, say N.

重新执行make menuconfig
在file system->Pseudo filesystems下已经可见devfs的相关选项

编译内核

make bzimage

在arch/arm/boot得到压缩后的内核镜像

没有评论:

发表评论