一、 Bootloader的移植
交叉编译器:arm-linux-gcc2.95.3
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
4.编辑board/ok2410/Makefile文件
[root@localhost u-boot-1.1.4]# gedit board/ok2410/Makefile
5.配置、编译u-boot
[root@localhost u-boot-1.1.4]# make ok2410_config
Configuring for ok2410 board...
[root@localhost u-boot-1.1.4]# make
出现如下错误:
......
make -C examples all
make[1]: Entering directory `/root/Desktop/u-boot-1.1.4/examples'
/usr/local/arm/2.95.3/bin/arm-linux-gcc -g -Os -fno-strict-aliasing -fno-common -ffixed-r8 -msoft-float -D__KERNEL__ -DTEXT_BASE=0x33F80000 -I/root/Desktop/u-boot-1.1.4/include -fno-builtin -ffreestanding -nostdinc -isystem /usr/local/arm/2.95.3/lib/gcc-lib/arm-linux/2.95.3/include -pipe -DCONFIG_ARM -D__ARM__ -march=armv4 -mabi=apcs-gnu -Wall -Wstrict-prototypes -c -o hello_world.o hello_world.c
cc1: Invalid option `abi=apcs-gnu'
make[1]: *** [hello_world.o] 错误 1
make[1]: Leaving directory `/root/Desktop/u-boot-1.1.4/examples'
make: *** [examples] 错误 2
解决方法:
[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]# make
接着出现了如下的错误:
……
/usr/local/arm/2.95.3/bin/arm-linux-ar crv libstubs.a stubs.o
a - stubs.o
make[1]: *** 没有规则可以创建“all”需要的目标“hello_world.srec”。 停止。
make[1]: Leaving directory `/root/Desktop/u-boot-1.1.4/examples'
make: *** [examples] 错误 2
解决方法:
[root@localhost u-boot-1.1.4]# gedit examples/Makefile
[root@localhost u-boot-1.1.4]# make
[root@localhost u-boot-1.1.4]# ll u-boot*
6.编辑skyeye.conf文件
[root@localhost u-boot-1.1.4]# gedit skyeye.conf
7.执行skyeye1.2.6[root@localhost u-boot-1.1.4]# skyeye1.2.6
8.开始移植nand[root@localhost u-boot-1.1.4]# gedit cpu/arm920t/start.S
将从NOR Flash启动改成从NAND Flash启动。
9.修改board/ok2410/Makefile[root@localhost u-boot-1.1.4]# gedit board/ok2410/Makefile
10.创建board/ok2410/nand_read.c文件[root@localhost u-boot-1.1.4]# gedit board/ok2410/nand_read.c
11.编辑include/configs/ok2410.h文件[root@localhost u-boot-1.1.4]# gedit include/configs/ok2410.h
12.编译u-boot,然后测试u-boot是否可以从nand启动[root@localhost u-boot-1.1.4]# make
[root@localhost u-boot-1.1.4]# ll u-boot*
[root@localhost u-boot-1.1.4]# skyeye1.2.6 //再次执行skyeye1.2.6
[root@localhost u-boot-1.1.4]# mknandflashdump u-boot.bin nand.dump 0
[root@localhost u-boot-1.1.4]# ll nand.dump
[root@localhost u-boot-1.1.4]# chmod 666 nand.dump
[root@localhost u-boot-1.1.4]# skyeye1.2.6 //再次执行skyeye1.2.6
13.编辑include/configs/ok2410.h文件[root@localhost u-boot-1.1.4]# gedit include/configs/ok2410.h
再次修改修改在第11步(编辑include/configs/ok2410.h文件)修改过的内容。
14.编辑board/ok2410/ok2410.c文件[root@localhost u-boot-1.1.4]# gedit board/ok2410/ok2410.c
15.修改 common/cmd_nand.c文件
[root@localhost u-boot-1.1.4]# gedit common/cmd_nand.c
16.编译、测试[root@localhost u-boot-1.1.4]# make
[root@localhost u-boot-1.1.4]# ll u-boot*
[root@localhost u-boot-1.1.4]# ./mknandflashdump u-boot.bin nand.dump 0
出现错误:
bash: ./mknandflashdump: is a directory
解决方法:
将mknandflashdump文件 复制到当前目录下。
然后执行skyeye1.2.6:
[root@localhost u-boot-1.1.4]# skyeye1.2.6
二、Linux的移植
1.解压linux-2.6.14.7.tar.bz2[root@localhost Desktop]# tar -xjvf linux-2.6.14.7.tar.bz2 -C ./
2.编辑Makefile文件[root@localhost Desktop]# cd linux-2.6.14.7
[root@localhost linux-2.6.14.7]# dir
[root@localhost linux-2.6.14.7]# gedit Makefile
3.复制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]# ls drivers/net/arm
4.修改drivers/net/arm/目录下的Kconfig文件[root@localhost linux-2.6.14.7]# gedit drivers/net/arm/Kconfig
5.修改drivers/net/arm/目录下的Makefile文件,
[root@localhost linux-2.6.14.7]# gedit drivers/net/arm/Makefile
6.编辑arch/arm/mach-s3c2410/mach-smdk2410.c文件
[root@localhost linux-2.6.14.7]# gedit arch/arm/mach-s3c2410/mach-smdk2410.c
7.在include/asm-arm/arch-s3c2410/目录下创建smdk2410.h文件
[root@localhost linux-2.6.14.7]# gedit include/asm-arm/arch-s3c2410/smdk2410.h
8.设置Flash分区(1)编辑devs.c文件
[root@localhost linux-2.6.14.7]# gedit arch/arm/mach-s3c2410/devs.c
(2)编辑mach-smdk2410.c文件,指定启动时初始化kernel启动时依据对分区的设置进行初始化。
[root@localhostlinux-2.6.14.7]# gedit arch/arm/mach-s3c2410/mach-smdk2410.c
(3)编辑s3c2410.c文件
[root@localhost linux-2.6.14.7]# gedit drivers/mtd/nand/s3c2410.c
9.配置内核(1)[root@localhost linux-2.6.14.7]# gedit fs/Kconfig
(2)配置内核,产生.config文件
[root@localhost linux-2.6.14.7]# cp arch/arm/configs/smdk2410_defconfig .config
[root@localhost linux-2.6.14.7]# make menuconfig //开始配置内核
保存退出,产生.config文件。
10.编译内核[root@localhost linux-2.6.14.7]# make
出现错误:
make: /usr/local/arm/3.4.1/bin/arm-linux-:命令未找到
CHK include/linux/version.h
SPLIT include/linux/autoconf.h -> include/config/*
SYMLINK include/asm-arm/arch -> include/asm-arm/arch-s3c2410
make[1]: “include/asm-arm/mach-types.h”是最新的。
CC arch/arm/kernel/asm-offsets.s
/bin/sh: /usr/local/arm/3.4.1/bin/arm-linux-: 没有那个文件或目录
make[1]: *** [arch/arm/kernel/asm-offsets.s] 错误 1
make: *** [prepare0] 错误 2
解决方法:
修改第9步,[root@localhost linux-2.6.14.7]# gedit arch/arm/mach-s3c2410/devs.c
然后将添加内容 添加到头文件后 。并将Makefile文件中的路径改为绝对路径。
[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
[root@localhost tools]# cp uImage ../
[root@localhost tools]# cp initrd.img ../
[root@localhost tools]# cp uImage /tftpboot/
[root@localhost tools]# cp initrd.img /tftpboot/
[root@localhost tools]# cp ../u-boot.bin /tftpboot/
[root@localhost tools]# cp initrd.img /tmp/nfs/
[root@localhost tools]#
[root@localhost tools]# cd ..
11.执行skyeye1.2.6[root@localhost u-boot-1.1.4]# skyeye1.2.6
出现错误:
Starting kernel ...
Uncompressing Linux........................................................................ done, booting the kernel.
Error: unrecognized/unsupported machine ID (r1 = 0x00000000).
Available machine support:
ID (hex) NAME
000000c1 SMDK2410
Please check your kernel config and/or bootloader.
解决方法:
修改内核的arch/arm/kernel/head.S
首先,在u-boot命令行中执行bdinfo命令,查看板卡信息。
OK2410 # bdinfo
arch_number = 0x000000C1
env_t = 0x00000000
boot_params = 0x30000100
DRAM bank = 0x00000000
-> start = 0x30000000
-> size = 0x04000000
ethaddr = 08:00:3E:26:0A:5B
ip_addr = 10.0.0.110
baudrate = 115200 bps
OK2410 # 然后,编辑Linux内核的arch/arm/kernel/head.S文件,将s3c2410的参数赋给内核。
[root@localhost linux-2.6.14.7]# gedit arch/arm/kernel/head.S
ENTRY(stext)
/************ me add begin ************/
mov r0, #0
mov r1, #0xc1
ldr r2, =0x30000100
/************ me add end ************/
msr cpsr_c, #PSR_F_BIT | PSR_I_BIT | MODE_SVC @ ensure svc mode
@ and irqs disabled
bl __lookup_processor_type @ r5=procinfo r9=cpuid
movs r10, r5 @ invalid processor (r5=0)?
beq __error_p @ yes, error 'p'
bl __lookup_machine_type @ r5=machinfo
movs r8, r5 @ invalid machine (r5=0)?
beq __error_a @ yes, error 'a'
bl __create_page_tables
三、根文件系统的移植 1.解压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
[root@localhost busybox-1.13.4]#
2.编辑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.编译[root@localhost busybox-1.13.4]# make
[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]# ll busybox*
[root@localhost busybox-1.13.4]# make install
成功,出现如下信息:
--------------------------------------------------
You will probably need to make your busybox binary
setuid root to ensure all configured applets will
work properly.
--------------------------------------------------
解决办法是修改_install/bin/busybox文件的属性。
[root@localhost busybox-1.13.4]# ll _install/bin/busybox
[root@localhost busybox-1.13.4]# chmod 4755 ./_install/bin/busybox //修改busybox属性
[root@localhost busybox-1.13.4]# ll _install/bin/busybox
[root@localhost busybox-1.13.4]# ll _install/
[root@localhost busybox-1.13.4]# cd _install/
[root@localhost _install]# pwd
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
[root@localhost nfs]# chmod 1777 tmp
[root@localhost nfs]# chmod 1777 var/tmp
[root@localhost nfs]# cd dev/
[root@localhost dev]# pwd
[root@localhost dev]# mknod -m 600 console c 5 1
[root@localhost dev]# mknod -m 666 null c 1 3
(2)复制文件到/tmp/nfs中
[root@localhost _install]# pwd
[root@localhost _install]# cp -a bin /tmp/nfs/
[root@localhost _install]# cp -a sbin /tmp/nfs/
[root@localhost _install]# ll linuxrc
[root@localhost _install]# cp -a linuxrc /tmp/nfs/
[root@localhost _install]# ll /tmp/nfs/linuxrc
[root@localhost _install]# cd ..
[root@localhost busybox-1.13.4]# pwd
[root@localhost busybox-1.13.4]# cp -a examples/bootfloppy/etc/* /tmp/nfs/etc/
[root@localhost busybox-1.13.4]# ls /tmp/nfs/etc/
[root@localhost busybox-1.13.4]#
8.创建配置文件(1)编写etc/inittab文件、修改其权限
[root@localhost nfs]# gedit etc/inittab
[root@localhost nfs]# ll etc/inittab
[root@localhost nfs]# chmod 755 etc/inittab
(2)编写etc/init.d/rcS文件、修改其权限
[root@localhost nfs]# gedit etc/init.d/rcS
[root@localhost nfs]# ll etc/init.d/rcS
[root@localhost nfs]# chmod 755 etc/init.d/rcS
(3)编写etc/fstab文件、修改其权限
[root@localhost nfs]# gedit etc/fstab
[root@localhost nfs]# ll etc/fstab
[root@localhost nfs]# chmod 755 etc/fstab
(4)编写etc/proflie文件、修改其权限
[root@localhost nfs]# gedit etc/proflie
(5)创建密码文件、修改其权限
[root@localhost nfs]# cp /etc/passwd etc/ ;cp /etc/shadow etc/ ;cp /etc/group etc/
[root@localhost nfs]# chmod 600 etc/shadow
[root@localhost nfs]# gedit etc/passwd
内容是:root:x:0:0:root:/root:/bin/sh
[root@localhost nfs]# gedit etc/shadow
内容是:root:$1$zs2zr2N4$15U99ll5tUm3DwOvKnCVV1:14335:0:99999:7:::
[root@localhost nfs]# gedit etc/group
内容是:root:x:0:root
(6)为mdev创建配置文件
[root@localhost nfs]# gedit etc/mdev.conf
内容是:空
[root@localhost nfs]# ll etc/
(7)删除备份文件
[root@localhost nfs]# rm etc/*~ etc/init.d/*~
9.复制常用的库文件编写脚本文件copy_lib.sh。
[root@localhost nfs]# gedit copy_lib.sh
[root@localhost nfs]# ll 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
[root@localhost lib]# cd -
[root@localhost nfs]# ll lib
[root@localhost nfs]#
根文件系统(通过NFS挂载)构建完成。
10.完整的启动过程(u-boot、内核、文件系统)(1)编辑/etc/xinetd.d/tftp文件
[root@localhost Desktop]# gedit /etc/xinetd.d/tftp
(2)重启tftp服务器
[root@localhost Desktop]# service xinetd restart
(3)编辑/etc/exports文件
[root@localhost Desktop]# gedit /etc/exports
(4)重启NFS服务器
[root@localhost u-boot-1.1.4]# service nfs restart
[root@localhost u-boot-1.1.4]# exportfs
[root@localhost u-boot-1.1.4]# exportfs -ra //重新扫描配置文件
(5)完整的启动过程(u-boot、内核、文件系统、用户程序),使用NFS文件系统
[root@localhost u-boot-1.1.4]# skyeye1.2.6
(6)完整的启动过程(u-boot、内核、文件系统),使用/dev/mtdblock2中的文件系统
创建cramfs文件系统
[root@localhost tmp]# pwd
[root@localhost tmp]# mkfs.cramfs nfs ok2410.cramfs
[root@localhost tmp]# ll ok2410.cramfs
复制ok2410.cramfs到tftp服务器根目录
[root@localhost tmp]# cp ok2410.cramfs /tftpboot/
执行skyeye1.2.6,启动系统
[root@localhost u-boot-1.1.4]# pwd
[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.
***********************************************************************
…… //部分启动信息省略
Hit any key to stop autoboot: 0
OK2410 # run bootcmd
TFTP from server 10.0.0.1; our IP address is 10.0.0.110
Filename 'uImage'.
Load address: 0x31000000
Loading: checksum bad
checksum bad
#################################################################
#################################################################
#################################################################
################################
done
Bytes transferred = 1161416 (11b8c8 hex)
## Booting image at 31000000 ...
Image Name: linux-2.6.14.7
Created: 2009-05-24 11:22:39 UTC
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 1161352 Bytes = 1.1 MB
Load Address: 30008000
Entry Point: 30008000
Verifying Checksum ... OK
OK
Starting kernel ...
Uncompressing Linux.......................................................................... done, booting the kernel.
Linux version 2.6.14.7 (root@localhost.localdomain) (gcc version 3.4.1) #6 Sun May 24 19:22:08 CST 2009
CPU: ARM920Tid(wb) [41009200] revision 0 (ARMvundefined/unknown)
Machine: SMDK2410
Memory policy: ECC disabled, Data cache writeback
CPU S3C2410 (id 0x32410000)
S3C2410: core 202.800 MHz, memory 101.400 MHz, peripheral 50.700 MHz
S3C2410 Clocks, (c) 2004 Simtec Electronics
CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on
CPU0: D VIVT write-back cache
CPU0: I cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets
CPU0: D cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets
Built 1 zonelists
Kernel command line: noinitrd root=/dev/nfs rw nfsroot=10.0.0.1:/tmp/nfs ip=10.0.0.110:10.0.0.1:10.0.0.1:255.255.255.0 init=linuxrc console=ttySAC0,115200 mem=64M
…… //部分启动信息省略
Memory: 64MB = 64MB total
Memory: 62464KB available (1888K code, 393K data, 92K init)
…… //部分启动信息省略
JFFS version 1.0, (C) 1999, 2000 Axis Communications AB
JFFS2 version 2.2. (NAND) (C) 2001-2003 Red Hat, Inc.
yaffs May 24 2009 19:21:42 Installing.
Console: switching to colour frame buffer device 80x25
fb0: Virtual frame buffer device, using 1024K of video memory
…… //部分启动信息省略
RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize
Cirrus Logic CS8900A driver for Linux (Modified for SMDK2410)
eth0: CS8900A rev D at 0xe0000300 irq=53, no eeprom , addr: 08: 0:3E:26:0A:5B
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c2410-nand: mapped registers at c4980000
s3c2410-nand: timing: Tacls 10ns, Twrph0 30ns, Twrph1 10ns
NAND device: Manufacturer ID: 0xec, Chip ID: 0x76 (Samsung NAND 64MiB 3,3V 8-bit)
NAND_ECC_NONE selected by board driver. This is not recommended !!
Scanning device for bad blocks
Bad eraseblock 7 at 0x0001c000
Creating 4 MTD partitions on "NAND 64MiB 3,3V 8-bit":
0x00000000-0x00100000 : "bootloader"
0x00100000-0x00400000 : "kernel"
0x00400000-0x02c00000 : "root"
0x02d00000-0x03c00000 : "user"
mice: PS/2 mouse device common for all mice
NET: Registered protocol family 2
…… //部分启动信息省略
IP-Config: Complete:
device=eth0, addr=10.0.0.110, mask=255.255.255.0, gw=10.0.0.1,
host=10.0.0.110, domain=, nis-domain=(none),
bootserver=10.0.0.1, rootserver=10.0.0.1, rootpath=
Looking up port of RPC 100003/2 on 10.0.0.1
Looking up port of RPC 100005/1 on 10.0.0.1
VFS: Mounted root (nfs filesystem).
Mounted devfs on /dev
Freeing init memory: 92K
#mount all.......
******************************************************************
OK 2410 Rootfs made by zcw, 2011.06
******************************************************************
zcwlogin:
http://blog.chinaunix.net/space.php?uid=14735472&do=blog&id=110947