全部博文(1159)
分类: 嵌入式
2011-06-17 15:17:27
嵌入式移植三步曲
班级:09级计算机应用二班 姓名:郑明莉 学号:0906042007
BootLoader的移植、Linux的移植、根文件系统的移植
前提:创建交叉编译环境
1、[root@localhost opt]# ll arm-linux-*
-rwxr-xr-x 1 root root 36273634 06-13 12:21 arm-linux-gcc-2.95.3.tar.bz2
-rwxr-xr-x 1 root root 42745480 06-13 12:22 arm-linux-gcc-3.4.1.tar.bz2
2、[root@localhost opt]# tar -xjvf arm-linux-gcc-2.95.3.tar.bz2 -C /usr/local/arm
tar: /usr/local/arm:无法 chdir: 没有那个文件或目录
tar: 错误不可恢复:现在退出
要先在/usr/local下创建一个arm文件夹,再执行tar -xjvf arm-linux-gcc-2.95.3.tar.bz2 -C /usr/local/arm
3、[root@localhost opt]# gedit /etc/profile
在文件profile中添加
PATH=$PATH:/usr/local/arm/2.95.3/bin
设置编译环境是2.95.3
4、[root@localhost opt]# source /etc/profile //使/etc/profile中添加的一行生效
[root@localhost opt]# arm-linux-gcc -v //查看编译器
Reading specs from /usr/local/arm/2.95.3/lib/gcc-lib/arm-linux/2.95.3/specs
gcc version 2.95.3 20010315 (release)
[root@localhost opt]#
(2)、skyeye的安装
1、[root@localhost opt]# tar -xjvf skyeye-1.2.6_rc1.tar.bz2 -C ./
2、[root@localhost opt]# cd skyeye-1.2.6_rc1
3、[root@localhost skyeye-1.2.6_rc1]# ls
aclocal.m4 ChangeLog configure depcomp LICENSE misc REPORTING-BUGS
arch config.guess configure.in device MAINTAINERS missing TODO
AUTHORS config.h.in COPYING INSTALL Makefile.am NEWS utils
autom4te.cache config.sub dbct install-sh Makefile.in README
4、[root@localhost skyeye-1.2.6_rc1]# ./configure //配置
5、[root@localhost skyeye-1.2.6_rc1]# make //编译
6、[root@localhost skyeye-1.2.6_rc1]# make install //将skyeye安装到/usr/local/bin/
7、[root@localhost skyeye-1.2.6_rc1]# mv /usr/local/bin/skyeye /usr/local/bin/skye1.2.6
//将/usr/local/bin/skyeye改名为:/usr/local/bin/skye1.2.6
一、BootLoder的移植
1、编辑u-boot根目录中的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
2、编辑ok2410.h头文件
3、编辑board/ok2410/Makefile文件
[root@localhost u-boot-1.1.4]# gedit board/ok2410/Makefile
将
OBJS := smdk2410.o flash.o
改为
OBJS := ok2410.o flash.o
4、配置、编译u-boot
# make ok2410_config
# make
错误:
........................................
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
修改:# 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,))
将原文件的第58行开始的内容:
SREC = hello_world.srec
BIN = hello_world.bin hello_world
改为
SREC = hello_world.o
BIN = hello_world.o hello_world
[root@bogon u-boot-1.1.4]# ll u-boot*
-rwxr-xr-x 1 root root 396137 06-15 08:26 u-boot
-rwxr-xr-x 1 root root 100156 06-15 08:26 u-boot.bin
-rw-r—r— 1 root root 48690 06-15 08:26 u-boot.map
-rwxr-xr-x 1 root root 300538 06-15 08:26 u-boot.srec
5、编写skyeye1.2.6文件:
[root@bogon u-boot-1.1.4]# gedit skyeye.conf
[root@bogon 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
Init nandflash dump file.
file size:69206016
finish init nandflash dump
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 15 2011 - 08:26:05)
U-Boot code: 33F80000 -> 33F9873C BSS: -> 33F9C814
RAM Configuration:
Bank #0: 30000000 64 MB
Flash: 512 kB
*** Warning - bad CRC, using default environment
In: serial
Out: serial
Err: serial
OK2410 #
6、移植nand:
7、修改board/ok2410/Makefile:
将
OBJS := ok2410.o flash.o
改为
OBJS := ok2410.o flash.o nand_read.o
8、编辑include/configs/ok2410.h文件
在文件后部添加:/****************** me add begin *******************/
/*
* Nandflash Boot
*/
#define CONFIG_S3C2410_NAND_BOOT 1
#define STACK_BASE 0x33f00000
#define STACK_SIZE 0x8000
//#define UBOOT_RAM_BASE 0x33f80000
/* NAND Flash Controller */
#define NAND_CTL_BASE 0x4E000000
#define bINT_CTL(Nb) __REG(INT_CTL_BASE + (Nb))
/* Offset */
#define oNFCONF 0x00
#define oNFCMD 0x04
#define oNFADDR 0x08
#define oNFDATA 0x0c
#define oNFSTAT 0x10
#define oNFECC 0x14
/****************** me add end *******************/
9、编译测试u-boot:
执行skyeye1.26.:
[root@bogon 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
到此停止不动:需要执行命令:gcc -g mknandflashdump.c
./a.out u-boot.bin nand.dump 0x0
[root@bogon u-boot-1.1.4]# gcc -g mknandflashdump.c
[root@bogon u-boot-1.1.4]# ./a.out u-boot.bin nand.dump 0x0
offset: 0x0 = 0
1 pos: 0x0 = 0
2 pos: 0x0 = 0
finish
11、编辑include/configs/ok2410.h文件
12、修改 common/cmd_nand.c文件
[root@bogon u-boot-1.1.4]# ./mknandflashdump u-boot.bin nand.dump 0
offset: 0x0 = 0
1 pos: 0x0 = 0
2 pos: 0x0 = 0
finish
[root@bogon 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 15 2011 - 09:06:00)
U-Boot code: 33F80000 -> 33F9C308 BSS: -> 33FA03E4
RAM Configuration:
Bank #0: 30000000 64 MB
Flash: 512 kB
NAND: 64 MB
*** Warning - bad CRC or NAND, using default environment
In: serial
Out: serial
Err: serial
Hit any key to stop autoboot: 0
OK2410 #
二、根据硬件环境编译原程序.是用linux-2.6.14.7.tar.bz2,将其解压之后修改 Makefile文件,然后再对网上进行移植,用cs8900,接着编辑arch/arm/mach-s3c2410/mach- smdk2410.c文件。设置flash分区.
内核的编译中出现的错误:[root@bogon linux-2.6.14.7]# make
make: /usr/local/arm/3.4.1/bin/arm-linux-:命令未找到
CHK include/linux/version.h
UPD include/linux/version.h
SPLIT include/linux/autoconf.h -> include/config/*
SYMLINK include/asm-arm/arch -> include/asm-arm/arch-s3c2410
Generating include/asm-arm/mach-types.h
SYMLINK include/asm -> include/asm-arm
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
修改:[root@bogon linux-2.6.14.7]# gedit Makefile
AS = /usr/local/arm/3.4.1/bin/arm-linux-as
LD = /usr/local/arm/3.4.1/bin/arm-linux-ld
CC = /usr/local/arm/3.4.1/bin/arm-linux-gcc
CPP = $(CC) -E
AR = /usr/local/arm/3.4.1/bin/arm-linux-ar
NM = /usr/local/arm/3.4.1/bin/arm-linux-nm
STRIP = /usr/local/arm/3.4.1/bin/arm-linux-strip
OBJCOPY = /usr/local/arm/3.4.1/bin/arm-linux-objcopy
OBJDUMP = /usr/local/arm/3.4.1/bin/arm-linux-objdump
[root@bogon linux-2.6.14.7]# gedit arch/arm/mach-s3c2410/devs.c
将devs.c中的/*nand*/内容移动到文件前面
三、根文件系统的移植
将
CROSS_COMPILE ?=
改为
CROSS_COMPILE ?=/usr/local/arm/3.4.1/bin/arm-linux-
将
ARCH ?= $(SUBARCH)
改为
ARCH ?= arm
[root@localhost busybox-1.13.4]# make defconfig
//恢复config的默认配置
2、修改配置信息
3、再次编译时出现的错误
编译
[root@localhost busybox-1.13.4]# make
networking/interface.c:818: error: (near initialization for `ib_hwtype.type')
make[1]: *** [networking/interface.o] 错误 1
make: *** [networking] 错误 2
修改:将networking/interface.c文件的818行修改为“.type = -1即可:
[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.
-----------------------------------------------------------------------------------
4、创建配置文件
编写etc/init.d/rcS文件、修改其权限
[root@localhost nfs]# gedit etc/init.d/rcS#!/bin/sh
# mount all filesystem defined in "fstab"
echo "#mount all......."
/bin/mount -a
/bin/mknod -m 600 /dev/console c 5 1
/bin/mknod -m 666 /dev/null c 1 3
/bin/mknod -m 666 /dev/tty0 c 4 0
/bin/mknod -m 666 /dev/mtdblock0 b 31 0
/bin/mknod -m 666 /dev/mtdblock1 b 31 1
/bin/mknod -m 666 /dev/mtdblock2 b 31 2
/bin/mknod -m 666 /dev/mtdblock3 b 31 3
#/bin/mount -t ext2 /dev/mtdblock3 /mnt/temp/
echo "******************************************************************"
echo " OK 2410 Rootfs made by zml, 2009.05"
echo "******************************************************************"
编写etc/fstab和etc/profile文件、修改其权限
创建密码文件,并修改权限
[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
5、完整启动。
(1)编辑/etc/xinetd.d/tftp文件
(2)重启tftp服务器
(3)编辑/etc/exports文件
(4)重启NFS服务器
(5)完整的启动过程(u-boot、内核、文件系统、用户程序),使用NFS文件系统
[root@bogon 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.
***********************************************************************
....................................................
Bank #0: 30000000 64 MB
Flash: 512 kB
NAND: 64 MB
*** Warning - bad CRC or NAND, using default environment
In: serial
Out: serial
Err: serial
Hit any key to stop autoboot: 0
TFTP from server 10.0.0.1; our IP address is 10.0.0.110
Filename 'uImage'.
Load address: 0x31000000
Loading: checksum bad
T T T T
修改以上问题:
搭建tftp,并修改其权限
#chmod -R 777/tftpboot
[root@bogon u-boot-1.1.4]# iptables -F
[root@bogon u-boot-1.1.4]# exporfts
[root@localhost u-boot-1.1.4]# exportfs -ra
[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
zml2410 # 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
………………………………....省略
**********************************************************************************
OK 2410 Rootfs made by zml, 2009.05
**********************************************************************************
10.0.0.110login: root
login[25]:
[root@wsf /root]# less test.c //查看文件内容
#include
#include
int main (int argc,char* argv[])
{
int i;
printf("===== main =====\n");
printf ("Hello world!\n");
for(i=0;i
{
printf("argv[%d]=%s\n",i,argv[i]);
}
printf("==== exit main ====\n");
return 0;
}
**************************** 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,
...................................................
U-Boot 1.1.4 (Jun 15 2011 - 09:06:00)
U-Boot code: 33F80000 -> 33F9C308 BSS: -> 33FA03E4
RAM Configuration:
Bank #0: 30000000 64 MB
Flash: 512 kB
NAND: 64 MB
*** Warning - bad CRC or NAND, using default environment
In: serial
Out: serial
Err: serial
Hit any key to stop autoboot: 0
zmlOK2410 #
http://blog.chinaunix.net/space.php?uid=14735472&do=blog&id=110947