准备工作:
1.主机--ubuntu10.04 2.编译工具--友善arm-linux-gcc-4.4.3 3.硬件--mini2440(预装友善的supervivi+kernel+root_fs,便于定位问题) 移植步骤: 1.获取源码 #wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.32.2.tar.gz 或者可以直接到官网下 2.指定交叉编译变量 cd /home/leon/work/linux-2.6.32.2 vi Makefile 修改总目录下的Makefile(默认是X86)
export KBUILD_BUILDHOST := $(SUBARCH)ARCH ?= $(SUBARCH)CROSS_COMPILE ?=
改为
export KBUILD_BUILDHOST := $(SUBARCH)ARCH ?= armCROSS_COMPILE ?= arm-linux-
接下来,测试一下linux 的编译是否能正常通过。 执行: #make s3c2410_defconfig ;s3c2410_defconfig 是SMDK2440 的缺省配置文件 #make -j4; 编译通过,继续一下步骤 3.关于机器码 内核在启动时,是通过bootloader 传入的机器码(MACH_TYPE)确定应启动哪种目标平台的,友善之臂已经为mini2440申请了机器码为1999,它位于linux-2.6.32.2/arch/arm/tools/mach_types 文件中,qq2440 MACH_QQ2440 QQ2440 1998mini2440 MACH_MINI2440 MINI2440 1999 //机器码colibri300 MACH_COLIBRI300 COLIBRI300 2000
如果内核的机器码和bootloader 传入的不匹配,常会经常出现下面的错误:
Uncompressing Linux................................................................................................................................. done, booting the kernel.运行到这就停住了。
另外, 目前U-boot 的 官方网站 从2009.06 版本开始,也已经加入了mini2440 的机器码定义--1999。 提示:在U-boot/include/asm-arm/mach-types.h 问题:在实际操作中,我注意到kernel的机器码定义是1999,但是任然会在这停住。 解决方法:将mach_types机器码的toto ARCH_TOTO TOTO 361379 s3c2440 ARCH_S3C2440 S3C2440 362380 ks8695p ARCH_KS8695P KS8695P 363
改为
toto ARCH_TOTO TOTO 361s3c2440 ARCH_S3C2440 S3C2440 1999ks8695p ARCH_KS8695P KS8695P 363
接下来, 我们注意到linux-2.6.32.2/arch/arm/mach-s3c2440 目录下有个mach-mini2440.c 文件,它是国外爱好者为mini2440移植添加的主要内容了,但我们不用它,直接删除。将linux-2.6.32.2/arch/arm/mach-s3c2440/目录下的mach-smdk2440.c 复制一份。命名为mach-mini2440.c , 找到MACHINE_START(S3C2440, "SMDK2440") , 修改为MACHINE_START(MINI2440, "leon's mini2440 board")。
提示:开发板运行后,在命令行终端输入:cat /proc/cpuinfo 可以看到我们添加的开发板信息[root@FriendlyARM /]# cat /proc/cpuinfoProcessor : ARM920T rev 0 (v4l)BogoMIPS : 201.93Features : swp half thumbCPU implementer : 0x41CPU architecture: 4TCPU variant : 0x1CPU part : 0x920CPU revision : 0
Hardware : leon's mini2440 board
Revision : 0000
Serial : 0000000000000000
4.修改时钟频率 在 mach-mini2440.c的static void __init smdk2440_map_io(void)函数中,把其中的 16934400(代表原 SMDK2440 目标板上的晶振是 16.9344MHz)改为 mini2440 开发板上实际使用的 12000000(代表 mini2440 开发板上的晶振 12MHz,元器件标号为 X2)
static void __init mini2440_map_io(void){ s3c24xx_init_io(mini2440_iodesc, ARRAY_SIZE(mini2440_iodesc)); s3c24xx_init_clocks(12000000); //修改为 12000000 s3c24xx_init_uarts(mini2440_uartcfgs, ARRAY_SIZE(mini2440_uartcfgs));}
用VI打开刚才复制得到的mach-mini2440.c文件,原来是smdk2440,所以将该文件中的所有的smdk2440替换成mini2440,可以在vim中,输入下面的命令进行替换;g表示全局替换,global.
1,$s/smdk2440/mini2440/g
除此之外,还有一个地方需要改动,在mini2440_machine_init(void)函数中,把 smdk_machine_init()函数调用注释掉,因为我们后面会编写自己的初始化函数,不需要调用static void __init mini2440_machine_init(void){ s3c24xx_fb_set_platdata(&mini2440_fb_info); s3c_i2c0_set_platdata(NULL);
platform_add_devices(mini2440_devices, ARRAY_SIZE(mini2440_devices)); //smdk_machine_init()}
编译测试
#make mini2440_defconfig //使用mini2440官方自带的配置文件#make zImage
把zImage(位于arch/arm/boot 目录)下到板子中,可以看到内核已经正常启动了,但此时大部分硬件驱动还没加。 5.移植Nand 驱动并更改分区信息 在mach-mini2440.c文件中添加NandFlash的分区信息,主要参考友善之臂的分区表。static struct mtd_partition mini2440_default_nand_part[] = { [0] = { .name = "U-boot",//这里是 bootloader所在的分区,放置bootloader .size = 0x00040000,//对应/dev/mtdblock0 .offset = 0, }, [1] = { .name = "param",// ;这里是U-boo的参数区,其实也属于bootloader的 .offset = 0x00040000,//一部分,如果u-boot 比较大,可以把此区域覆盖掉 .size = 0x00020000,//不会影响系统启动,对应/dev/mtdblock1 }, [2] = { .name = "Kernel",//内核所在的分区,大小为 5M,足够放下大部分自己定制的 .offset = 0x00060000,//巨型内核了,比如内核使用了更大的Linux Logo图片 .size = 0x00500000,//对应/dev/mtdblock2 等 }, [3] = { .name = "root",//文件系统分区,主要用来存放yaffs2 文件系统 .offset = 0x00560000,//内容,对应/dev/mtdblock3 .size = 0x07aa0000, // }, //此区域代表了整片的nand flash,主要是预留使用, [4] = { .name = "nand", .offset = 0x00000000, .size = 1024 * 1024 * 1024, // }};
这里是开发板的nand flash 设置表,因为板子上只有一片,因此也就只有一个表
static struct s3c2410_nand_set mini2440_nand_sets[] = { [0] = { .name = "NAND", .nr_chips = 1, .nr_partitions = ARRAY_SIZE(mini2440_default_nand_part), .partitions = mini2440_default_nand_part, },};
//这里是nand flash本身的一些特性,一般需要对照datasheet填写,大部分情况下按照以下参数填写即可
static struct s3c2410_platform_nand mini2440_nand_info = { .tacls = 20, .twrph0 = 60, .twrph1 = 20, .nr_sets = ARRAY_SIZE(mini2440_nand_sets), .sets = mini2440_nand_sets, .ignore_unset_ecc = 1,};
还需要把 nand flash 设备注册到系统中,static struct platform_device *mini2440_devices[] __initdata = { &s3c_device_usb, &s3c_device_lcd, &s3c_device_wdt, &s3c_device_i2c0, &s3c_device_iis, &s3c_device_nand,//把nand flash设备添加到开发板的设备列表结构 };
在mini2440_machine_init函数中添加平台的数据信息。
static void __init mini2440_machine_init(void){ s3c24xx_fb_set_platdata(&mini2440_fb_info); s3c_i2c0_set_platdata(NULL); s3c_device_nand.dev.platform_data = &mini2440_nand_info; //添加 platform_add_devices(mini2440_devices, ARRAY_SIZE(mini2440_devices));}
不过还要在该文件中添加几个头文件才能编译成功:
/*添加下面几个文件*/#include <linux/mtd/mtd.h>#include <linux/mtd/nand.h>#include <linux/mtd/nand_ecc.h>#include <linux/mtd/partitions.h>
#include <plat/nand.h> //添加
到这里就完成了NandFlash的驱动的移植,可以下载到开发板运行看看启动的信息了。
6.移植yaffs2 (1)获取yaffs2 源代码 在 http://www.yaffs.net/node/346 可以下载到最新的yaffs2 源代码,需要使用git工具,在命令行输入: #git clone git://www.aleph1.co.uk/yaffs2 (2)为内核打上yaffs2 补丁
cd yaffs2
先修改patch-ker.sh,找到modulerconfig.h,把这个删除语句注释掉./patch-ker.sh c m /home/leon/work/linux-2.6.32.2
此时进入linux-2.6.32.2/fs 目录,可以看到已经多了一个yaffs2目录(有的时候打补丁可能不成功,没关系,手动把yaffs2代码添加进内核树就可以了,修改Kconfig和Makefile)
(3)配置和编译带YAFFS2 支持的内核 make menuconfig 选上File Systems->Miscellaneous filesystems->YAFFS2 file system support 问题:移植中遇到一下错误
drivers/rtc/hctosys.c: unable to open rtc device (rtc0)yaffs: dev is 32505858 name is "mtdblock2" rwyaffs: passed flags ""VFS: Mounted root (yaffs filesystem) on device 31:2.Freeing init memory: 100KWarning: unable to open an initial console.Failed to execute /linuxrc. Attempting defaults...Kernel panic - not syncing: No init found. Try passing init= option to kernel.[<c0027d34>] (unwind_backtrace+0x0/0xdc) from [<c01f9a44>] (panic+0x40/0x120)[<c01f9a44>] (panic+0x40/0x120) from [<c00215b4>] (init_post+0xcc/0xf4)[<c00215b4>] (init_post+0xcc/0xf4) from [<c0008440>] (kernel_init+0xdc/0x10c)
网上搜到的大多是说:配置文件要选上Kernel Features->
Use the ARM EABI to compile the kernelAllow old ABI binaries to run with thie Kernel 这两项,why? 听Google说友善的根文件系统在编译的时候也启用了EABI特性,内核和文件系统需要对上,文件系统用了EABI 内核也要用EABI。 我照着改了之后,情况并没有得到改善,最后把yaffs2源码换成友善官方yaffs2文件夹(问题已经修正,需阅读yaffs2的shell脚本),居然成功了,害得我调了整整一个晚上。难道是版本匹配有问题?还是配置不对?以后有时间再来专门研究下yaffs2.
yaffs_read_super: isCheckpointed 0
VFS: Mounted root (yaffs filesystem) on device 31:3.
Freeing init memory: 132K
hwclock: can't open '/dev/misc/rtc': No such file or directory
[01/Jan/1970:00:00:11 +0000] boa: server version Boa/0.94.13
[01/Jan/1970:00:00:11 +0000] boa: server built Jul 26 2010 at 15:58:29.
[01/Jan/1970:00:00:11 +0000] boa: starting server pid=749, port 80
open device leds: No such file or directory
Try to bring eth0 interface up......ifconfig: SIOCGIFFLAGS: No such device
ifconfig: SIOCSIFHWADDR: No such device
ifconfig: SIOCSIFADDR: No such device
route: SIOCADDRT: No such process
Done
Please press Enter to activate this console.
[root@FriendlyARM /]#
bingo:万里长征终于走出了第一步,今天一个人在电脑前坐了十多个小时,总算没有白费。