全部博文(1159)
分类: 嵌入式
2011-06-17 08:30:10
班级:09计应一班 姓名:闫俊霖
一、Bootloader的移植
二、linux 内核的编译
三、linux根文件系统移植
设置实验环境
安装SkyEye操作系统:CentOS 5.6。
从下面网址可以下载到最新版本的skyeye。
下面以skyeye-1.2.6_rc1为例介绍SkyEye的安装。
[root@localhost Desktop]# ll skyeye-1.2.*
-rwxr-xr-x 1 root root 885160 01-16 16:28 skyeye-1.2.6_rc1.tar.bz2 |
(1)解压源码包
[root@localhost Desktop]# tar -xjvf skyeye-1.2.6_rc1.tar.bz2 -C ./
(2)编译skyeye-1.2.6
[root@localhost Desktop]# cd skyeye-1.2.6_rc1
[root@localhost skyeye-1.2.6_rc1]# gedit INSTALL //该文件包含安装帮助信息
[root@localhost skyeye-1.2.6_rc1]# ./configure //配置
[root@localhost skyeye-1.2.6_rc1]# make //编译
[root@localhost skyeye-1.2.6_rc1]# make install //将skyeye安装到/usr/local/bin/
[root@localhost skyeye-1.2.6_rc1]# mv /usr/local/bin/skyeye /usr/local/bin/skyeye1.2.6 //将skyeye改名为skyeye1.2.6
(3)查看skyeye命令
[root@localhost skyeye-1.2.6_rc1]# ll /usr/local/bin/skyeye*
-rwxr-xr-x 1 root root 2544308 05-17 17:59 /usr/local/bin/skyeye1.2.6 |
创建交叉编译环境
在实验中需要用到交叉编译器arm-linux-gcc-2.95.3和arm-linux-gcc-3.4.1
下载arm-linux-gcc-2.95.3.tar.bz2,arm-linux-gcc-3.4.1.tar.bz2,
下载后解压到/usr/local/arm:
[root@localhost Desktop]# tar -xjvf arm-linux-gcc-2.95.3.tar.bz2 -C /usr/local/arm/
[root@localhost Desktop]# tar -xjvf arm-linux-gcc-3.4.1.tar.bz2 -C /usr/local/arm/
一、Bootloader的移植
1.解压u-boot-1.1.4.tar.bz2
[root@localhost Desktop]# tar -xjvf u-boot-1.1.4.tar.bz2 -C ./
[root@localhost Desktop]# cd u-boot-1.1.4
2.编辑u-boot根目录中的Makefile文件[root@localhost u-boot-1.1.4]# gedit Makefile
将
ifeq ($(ARCH),arm)
CROSS_COMPILE = arm-linux-
endif
改为
ifeq ($(ARCH),arm)
CROSS_COMPILE=/usr/local/arm/2.95.3/bin/arm-linux-
endif
在
smdk2410_config : unconfig
@./mkconfig $(@:_config=) arm arm920t smdk2410 NULL s3c24x0
后面添加
ok2410_config : unconfig
@./mkconfig $(@:_config=) arm arm920t ok2410 NULL s3c24x0
3.复制必要的文件,编辑ok2410.h头文件[root@localhost u-boot-1.1.4]# mkdir board/ok2410
[root@localhost u-boot-1.1.4]# cp board/smdk2410/* board/ok2410/
[root@localhost u-boot-1.1.4]# dir board/ok2410/
[root@localhost u-boot-1.1.4]# mv board/ok2410/smdk2410.c board/ok2410/ok2410.c
[root@localhost u-boot-1.1.4]# cp include/configs/smdk2410.h include/configs/ok2410.h
[root@localhost u-boot-1.1.4]# gedit include/configs/ok2410.h
将
#define CFG_PROMPT "SMDK2410 # " /* Monitor Command Prompt */
改为
#define CFG_PROMPT "OK2410 # " /* Monitor Command Prompt */
4.编辑board/ok2410/Makefile文件[root@localhost u-boot-1.1.4]# gedit board/ok2410/Makefile
将
OBJS := smdk2410.o flash.o
改为
OBJS := ok2410.o flash.o
5.配置、编译u-boot[root@localhost u-boot-1.1.4]# make ok2410_config
[root@localhost u-boot-1.1.4]# gedit cpu/arm920t/config.mk
将
PLATFORM_CPPFLAGS +=$(call cc-option,-mapcs-32,-mabi=apcs-gnu)
改成:
PLATFORM_CPPFLAGS +=$(call cc-option,-mapcs-32,$(call cc-option,-mabi=apcs-gnu,))
[root@localhost u-boot-1.1.4]# gedit examples/Makefile
将原文件的第58行开始的内容:
SREC = hello_world.srec
BIN = hello_world.bin hello_world
改为
SREC = hello_world.o
BIN = hello_world.o hello_world
即可重新编译。
[root@localhost u-boot-1.1.4]# make
6.编辑skyeye.conf文件[root@localhost u-boot-1.1.4]# gedit skyeye.conf
内容为:
# skyeye config file for S3C2410X
cpu: arm920t
mach: s3c2410x
# physical memory
mem_bank: map=M, type=RW, addr=0x00000000, size=0x00800000, file=./u-boot.bin ,boot=yes
mem_bank: map=M, type=RW, addr=0x30000000, size=0x00800000
mem_bank: map=M, type=RW, addr=0x30800000, size=0x00800000
mem_bank: map=M, type=RW, addr=0x31000000, size=0x03000000
# all peripherals I/O mapping area
mem_bank: map=I, type=RW, addr=0x48000000, size=0x20000000
mem_bank: map=I, type=RW, addr=0x19000300, size=0x00000020
net: type=cs8900a, base=0x19000300, size=0x20,int=9, mac=08:00:3E:26:0A:5B, ethmod=tuntap, hostip=10.0.0.1
nandflash: type=s3c2410x,name=K9F1208U0B,dump=./nand.dump
#lcd:type=s3c2410x, mod=gtk
dbct:state=on
7.执行skyeye1.2.6[root@localhost u-boot-1.1.4]# skyeye1.2.6
In: serial
Out: serial
Err: serial
Hit any key to stop autoboot: 0
OK2410 #
8.开始移植NAND Flash
[root@localhost u-boot-1.1.4]# gedit cpu/arm920t/start.S
将从NOR Flash启动改成从NAND Flash启动。
执行skyeye1.2.6
二、Linux的移植
1.下载linux-2.6.14.7.tar.bz2网址如下:
2.解压linux-2.6.14.7.tar.bz2
[root@localhost Desktop]# tar -xjvf linux-2.6.14.7.tar.bz2 -C ./
3.编辑Makefile文件[root@localhost Desktop]# cd linux-2.6.14.7
[root@localhost linux-2.6.14.7]# gedit Makefile
4.cs8900网卡的移植
[root@localhost linux-2.6.14.7]# cp ../cs8900/cs8900.c drivers/net/arm/
[root@localhost linux-2.6.14.7]# cp ../cs8900/cs8900.h drivers/net/arm/
[root@localhost linux-2.6.14.7]# gedit drivers/net/arm/Kconfig
[root@localhost linux-2.6.14.7]# gedit drivers/net/arm/Makefile
5.编辑arch/arm/mach-s3c2410/mach-smdk2410.c文件
[root@localhost linux-2.6.14.7]# gedit arch/arm/mach-s3c2410/mach-smdk2410.c
在文件最后添加如下内容:
obj-$(CONFIG_ARM_CS8900) += cs8900.o
6.在include/asm-arm/arch-s3c2410/目录下创建smdk2410.h文件[root@localhost linux-2.6.14.7]# gedit include/asm-arm/arch-s3c2410/smdk2410.h
文件的内容如下:
#ifndef _INCLUDE_SMDK2410_H_
#define _INCLUDE_SMDK2410_H_
#include
#define pSMDK2410_ETH_IO 0x19000000
#define vSMDK2410_ETH_IO 0xE0000000
#define SMDK2410_ETH_IRQ IRQ_EINT9
#endif // _INCLUDE_SMDK2410_H_
7.设置Flash分区在此要编辑3个文件:devs.c、mach-smdk2410.c、s3c2410.c
8.配置内核
9.编译内核,创建uImage,将uImage复制到tftp服务器的根目录(/tftpboot/)
[root@localhost linux-2.6.14.7]# make
[root@localhost linux-2.6.14.7]# cp arch/arm/boot/compressed/vmlinux ../u-boot-1.1.4/tools/
[root@localhost linux-2.6.14.7]# cd ../u-boot-1.1.4/tools/
[root@localhost tools]# ./mkimage -A arm -O linux -T kernel -C none -a 30008000 -e 30008000 -n linux-2.6.14.7 -d vmlinux uImage
注意:bootm命令引导的只能是用U-BOOT的mkimage工具转换过的内核映像(uImage),所以要用mkimage将内核映像(vmlinux)进行转换。mkimage工具位于U-BOOT的tools子目录中。uImage是U-BOOT使用bootm命令引导的Linux压缩内核映像文件格式,使用工具mkimage对普通的压缩内核映像文件(vmlinux)加工而得。可以由bootm命令从任意地址解压启动内核。
10.执行skyeye1.2.6,通过u-boot-1.1.4引导linux-2.6.14.7[root@localhost u-boot-1.1.4]# skyeye1.2.6
三、根文件系统的移植
1.下载busybox-1.13.4.tar.bz2网址:
2.解压busybox-1.13.4.tar.bz2到桌面[root@localhost Desktop]# tar -xjvf busybox-1.13.4.tar.bz2 -C ./
[root@localhost Desktop]# cd busybox-1.13.4
3.编辑Makefile文件[root@localhost busybox-1.13.4]# gedit Makefile
4.进行默认配置[root@localhost busybox-1.13.4]# make defconfig //恢复默认配置
5.对配置信息进行修改[root@localhost busybox-1.13.4]# make menuconfig
设置完毕后,保存、退出。
6.编译编辑networking/interface.c文件。
[root@localhost busybox-1.13.4]# gedit networking/interface.c
将networking/interface.c文件的818行修改为“.type = -1”,然后编译。
[root@localhost busybox-1.13.4]# make
[root@localhost busybox-1.13.4]# chmod 4755 ./_install/bin/busybox //修改busybox属性
[root@localhost busybox-1.13.4]# make install
7.对配置信息进行修改
1)在/tmp/nfs中创建所需的目录
[root@localhost nfs]# mkdir -p bin sbin lib/modules etc/init.d dev usr/bin usr/sbin usr/lib proc sys home root boot mnt/etc mnt/jffs2 mnt/yaffs mnt/data mnt/temp var/lib var/lock var/log var/run var/tmp tmp
注意:其中bin、dev、etc、lib、proc、sbin、sys、usr是必备的8个目录。
[root@localhost nfs]# chmod 1777 tmp
[root@localhost nfs]# chmod 1777 var/tmp
[root@localhost nfs]# cd dev/
[root@localhost dev]# mknod -m 600 console c 5 1
[root@localhost dev]# mknod -m 666 null c 1 3
(2)复制文件到/tmp/nfs中
将/root/Desktop/busybox-1.13.4/_install中的内容复制到/tmp/nfs中。
[root@localhost _install]# cp -a bin /tmp/nfs/
[root@localhost _install]# cp -a sbin /tmp/nfs/
[root@localhost _install]# cp -a linuxrc /tmp/nfs/
[root@localhost _install]# cd ..
[root@localhost busybox-1.13.4]# cp -a examples/bootfloppy/etc/* /tmp/nfs/etc/
8.创建配置文件(1)编写etc/inittab文件、修改其权限
[root@localhost nfs]# gedit etc/inittab
2)编写etc/init.d/rcS文件、修改其权限
[root@localhost nfs]# gedit etc/init.d/rcS
3)编写etc/fstab文件、修改其权限
[root@localhost nfs]# gedit etc/fstab
4)编写etc/proflie文件、修改其权限
[root@localhost nfs]# gedit etc/profile
5)创建密码文件、修改其权限
6)为mdev创建配置文件
[root@localhost nfs]# gedit etc/mdev.conf
内容是:空
9.复制常用的库文件编写脚本文件copy_lib.sh。
[root@localhost nfs]# gedit copy_lib.sh
[root@localhost nfs]# chmod a+x copy_lib.sh
[root@localhost nfs]# cp copy_lib.sh /usr/local/arm/3.4.1/arm-linux/lib/
[root@localhost nfs]# cd /usr/local/arm/3.4.1/arm-linux/lib/
[root@localhost lib]# ./copy_lib.sh
至此,一个基本的根文件系统(通过NFS挂载)构建完成。
搭建nfs服务器:
[root@localhost Desktop]# gedit /etc/exports
文件内容如下:/tmp/nfs *(rw,sync)
创建共享目录[root@localhost Desktop]# mkdir -p /tmp/nfs/temp
[root@localhost Desktop]# exportfs -rv
exporting *:/tmp/nfs
[root@localhost Desktop]# chmod a+w /tmp/nfs/temp
[root@localhost Desktop]# chmod a+w /tmp/nfs/
重启NFS服务器
[root@localhost u-boot-1.1.4]# service nfs restart
nfs服务器搭建完毕;
搭建tftp服务器:
编辑/etc/xinetd.d/tftp文件
[root@localhost Desktop]# gedit /etc/xinetd.d/tftp
重启tftp服务器
[root@localhost Desktop]# service xinetd restart
创建完毕后,通过tptp下载到内存,然后可以写到nand flash的固定分区上!这里要记住写的位置所代表的分区,进而修改环境变量bootargs,调整所使用的文件系统!
启动流程如下:
[root@localhost u-boot-1.1.4]# skyeye1.2.6
**************************** WARNING **********************************
If you want to run ELF image, you should use -e option to indicate
your elf-format image filename. Or you only want to run binary image,
you need to set the filename of the image and its entry in skyeye.conf.
***********************************************************************
Your elf file is little endian.
arch: arm
cpu info: armv4, arm920t, 41009200, ff00fff0, 2
mach info: name s3c2410x, mach_init addr 0x806bae0
ethmod num=1, mac addr=8:0:3e:26:a:5b, hostip=10.0.0.1
nandflash: dump ./nand.dump
file size:69206016
dbct info: turn on dbct!
uart_mod:0, desc_in:, desc_out:, converter:
SKYEYE: use arm920t mmu ops
Loaded RAM ./u-boot.bin
ERROR: s3c2410x_io_write_word(0x4c000000) = 0x00ffffff
ERROR: s3c2410x_io_write_word(0x4c000008) = 0x00048032
U-Boot 1.1.4 (Jun 12 2011 - 10:21:09)
U-Boot code: 33F80000 -> 33F9C304 BSS: -> 33FA03E0
RAM Configuration:
Bank #0: 30000000 64 MB
Flash: 512 kB
NAND: 64 MB
In: serial
Out: serial
Err: serial
Hit any key to stop autoboot: 0
NAND read: device 0 offset 1048576, size 3145728 ...
启动到这里会从nandflash的第二个分区读取uimage到加载内存的0x31000000处执行;
wxf2410 # printenv
bootdelay=3
baudrate=115200
ethaddr=08:00:3E:26:0A:5B
filesize=11f568
fileaddr=31000000
netmask=255.255.255.0
ipaddr=10.0.0.110
serverip=10.0.0.1
bootcmd=nand read 0x31000000 0x00100000 0x00300000;bootm 0x31000000
bootargs=noinitrd mem=64M root=/dev/mtdblock2 init=/linuxrc console=ttySAC0,115200
由环境变量bootargs=noinitrd mem=64M root=/dev/mtdblock2 init=/linuxrc可知设置主文件系统为第三个分区烧写的cramfs文件系统
Reading data from NAND FLASH without ECC is not recommended
VFS: Mounted root (cramfs filesystem) readonly.
Mounted devfs on /dev
Freeing init memory: 96K
Reading data from NAND FLASH without ECC is not recommended
Reading data from NAND FLASH without ECC is not recommended
Reading data from NAND FLASH without ECC is not recommended
Reading data from NAND FLASH without ECC is not recommended
#mount all.......
******************************************************************
YAN 2410 Rootfs made by yjl, 2009.05
******************************************************************
10.0.0.110 login login: root
Password:
login[25]: root login on 'console'
Processing /etc/profile... Set search library path in /etc/profile
Set user path in /etc/profile
Configure net done
All Done
[root@10 ~]#
四、错误状况及错误分析
1.通过tftp下载时可能会遇到selinux提供的安全机制问题,导致下载不成,这时进行如下设置:
[root@localhost ~]# getsebool -a|grep tftp
allow_tftp_anon_write --> off
tftpd_disable_trans --> off
[root@localhost ~]# setsebool allow_tftp_anon_write=1
[root@localhost ~]# setsebool tftpd_disable_trans =1
2.在烧写的时候会提示说mknandflashdump 命令找不到,这时需要在u-boot目录下添加一个可执行的mknandflashdump 命令,并修改权限使能够执行:
[root@localhost u-boot-1.1.4]#chmod 755 mknandflashdump
[root@localhost u-boot-1.1.4]# ./mknandflashdump u-boot.bin nand.dump 0
3.有时执行skyeye1.2.6 ,会出现T(表示try)
可能是tftp服务器没有搭建,需要对tftp进行搭建,同时对其权限进行修改,
[root@localhost tools]#chmod-R 755 /tftpboot
也可能是防火墙问题,此时可执行iptables命令清除防火墙规则
[root@localhost tools]# iptables -F
4.每次重新启动电脑后,以前能够正确执行的skyeye会出现出误,此时只要清除防火墙规则并开启nfs服务即可
[root@localhost u-boot-1.1.4]# service nfs restart
[root@localhost tools]# iptables -F
http://blog.chinaunix.net/space.php?uid=14735472&do=blog&id=110947