嵌入式系统移植三部曲 吴素芬
Posted ztguang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了嵌入式系统移植三部曲 吴素芬相关的知识,希望对你有一定的参考价值。
计算机与信息工程学院 09级嵌入式 吴素芬
嵌入式系统移植三部曲
一、BootLoader的移植
二、linux的移植
三、根文件系统的移植
一、准备工作
(1)、创建交叉编译环境
1、[[email protected] 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、[[email protected] 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、[[email protected] opt]# gedit /etc/profile
在文件profile中添加
PATH=$PATH:/usr/local/arm/2.95.3/bin
设置编译环境是2.95.3
4、[[email protected] opt]# source /etc/profile //使/etc/profile中添加的一行生效
[[email protected] 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)
[[email protected] opt]#
(2)、skyeye的安装
1、[[email protected] opt]# tar -xjvf skyeye-1.2.6_rc1.tar.bz2 -C ./
2、[[email protected] opt]# cd skyeye-1.2.6_rc1
3、[[email protected] 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、[[email protected] skyeye-1.2.6_rc1]# ./configure //配置
5、[[email protected] skyeye-1.2.6_rc1]# make //编译
6、[[email protected] skyeye-1.2.6_rc1]# make install //将skyeye安装到/usr/local/bin/
7、[[email protected] 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
二、BootLoader的移植
1.解压u-boot-1.1.4.tar.bz2
[[email protected] opt]# tar -xjvf u-boot-1.1.4.tar.bz2 -C ./
[[email protected] opt]# cd u-boot-1.1.4
2.编辑u-boot根目录中的Makefile文件
[[email protected] 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
后面添加
sf2410_config : unconfig
@./mkconfig $(@:_config=) arm arm920t sf2410 NULL s3c24x0
3.复制必要的文件,编辑sf2410.h头文件
[[email protected] u-boot-1.1.4]# mkdir board/sf2410
[[email protected] u-boot-1.1.4]# cp board/smdk2410/* board/sf2410
[[email protected] u-boot-1.1.4]# dir board/sf2410/
config.mk flash.c lowlevel_init.S Makefile smdk2410.c u-boot.lds
[[email protected] u-boot-1.1.4]# mv board/sf2410/smdk2410.c board/sf2410/sf2410.c
[[email protected] u-boot-1.1.4]# cp include/configs/smdk2410.h include/configs/sf2410.h
[[email protected] u-boot-1.1.4]# gedit include/configs/sf2410.h
将
#define CFG_PROMPT "SMDK2410 # " /* Monitor Command Prompt */
改为
#define CFG_PROMPT "SF2410 # " /* Monitor Command Prompt */
4.编辑board/sf2410/Makefile文件
[[email protected] u-boot-1.1.4]# gedit board/sf2410/Makefile
将
OBJS := smdk2410.o flash.o
改为
OBJS := sf2410.o flash.o
5.配置u-boot
[[email protected] u-boot-1.1.4]# make sf2410_config
Configuring for sf2410 board...
(1)、修改cpu/arm920t/config.mk文件
[[email protected] 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,))
(2)、修改cpu/arm920t/config.mk文件
[[email protected] u-boot-1.1.4]# gedit cpu/arm920t/config.mk
将原文件的第58行开始的内容:
SREC = hello_world.srec
BIN = hello_world.bin hello_world
改为
SREC = hello_world.o
BIN = hello_world.o hello_world
6、编译u-boot
[[email protected] u-boot-1.1.4]# make
[[email protected] u-boot-1.1.4]# ll u-boot*
-rwxr-xr-x 1 root root 395773 06-14 17:49 u-boot
-rwxr-xr-x 1 root root 100156 06-14 17:49 u-boot.bin
-rw-r--r-- 1 root root 48690 06-14 17:49 u-boot.map
-rwxr-xr-x 1 root root 300538 06-14 17:49 u-boot.srec
7、编辑skyeye.conf文件
[[email protected] 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
8、执行skyeye1.2.6
[[email protected] u-boot-1.1.4]# skyeye1.2.6
...
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
SF2410 #
9、开始移植nand
[[email protected] u-boot-1.1.4]# gedit cpu/arm920t/start.S
将从NOR Flash启动改成从NAND Flash启动。
将以下U-Boot的重定向语句段:
#ifndef CONFIG_SKIP_RELOCATE_UBOOT
relocate: /* relocate U-Boot to RAM */
adr r0, _start /* r0 <- current position of code */
ldr r1, _TEXT_BASE /* test if we run from flash or RAM */
cmp r0, r1 /* don‘t reloc during debug */
beq stack_setup
ldr r2, _armboot_start
ldr r3, _bss_start
sub r2, r3, r2 /* r2 <- size of armboot */
add r2, r0, r2 /* r2 <- source end address */
copy_loop:
ldmia r0!, {r3-r10} /* copy from source address [r0] */
stmia r1!, {r3-r10} /* copy to target address [r1] */
cmp r0, r2 /* until source end addreee [r2] */
ble copy_loop
#endif /* CONFIG_SKIP_RELOCATE_UBOOT */
替换成:
#ifdef CONFIG_S3C2410_NAND_BOOT
@ reset NAND
mov r1, #NAND_CTL_BASE
ldr r2, =0xf830 @ initial value
str r2, [r1, #oNFCONF]
ldr r2, [r1, #oNFCONF]
bic r2, r2, #0x800 @ enable chip
str r2, [r1, #oNFCONF]
mov r2, #0xff @ RESET command
strb r2, [r1, #oNFCMD]
mov r3, #0 @ wait
nand1:
add r3, r3, #0x1
cmp r3, #0xa
blt nand1
nand2:
ldr r2, [r1, #oNFSTAT] @ wait ready
tst r2, #0x1
beq nand2
ldr r2, [r1, #oNFCONF]
orr r2, r2, #0x800 @ disable chip
str r2, [r1, #oNFCONF]
@ get read to call C functions (for nand_read())
ldr sp, DW_STACK_START @ setup stack pointer
mov fp, #0 @ no previous frame, so fp=0
@ copy U-Boot to RAM
ldr r0, =TEXT_BASE
mov r1, #0x0
mov r2, #0x20000
bl nand_read_ll
tst r0, #0x0
beq ok_nand_read
bad_nand_read:
loop2: b loop2 @ infinite loop
ok_nand_read:
@ verify
mov r0, #0
ldr r1, =TEXT_BASE
mov r2, #0x400 @ 4 bytes * 1024 = 4K-bytes
go_next:
ldr r3, [r0], #4
ldr r4, [r1], #4
teq r3, r4
bne notmatch
subs r2, r2, #4
beq stack_setup
bne go_next
notmatch:
loop3: b loop3 @ infinite loop
#endif /* CONFIG_S3C2410_NAND_BOOT */
在
_start_armboot: .word start_armboot
后面加入
.align 2
DW_STACK_START: .word STACK_BASE+STACK_SIZE-4
10、修改board/sf2410/Makefile
[[email protected] u-boot-1.1.4]# gedit board/sf2410/Makefile
将
OBJS := sf2410.o flash.o
改为
OBJS := sf2410.o flash.o nand_read.o
11、创建board/sf2410/nand_read.c文件
[[email protected] u-boot-1.1.4]# gedit board/sf2410/nand_read.c
内容是:
#include
#define __REGb(x) (*(volatile unsigned char *)(x))
#define __REGi(x) (*(volatile unsigned int *)(x))
#define NF_BASE 0x4e000000
#define NFCONF __REGi(NF_BASE + 0x0)
#define NFCMD __REGb(NF_BASE + 0x4)
#define NFADDR __REGb(NF_BASE + 0x8)
#define NFDATA __REGb(NF_BASE + 0xc)
#define NFSTAT __REGb(NF_BASE + 0x10)
#define BUSY 1
#ifndef NAND_SECTOR_SIZE
#define NAND_SECTOR_SIZE 512
#endif
#ifndef NAND_BLOCK_MASK
#define NAND_BLOCK_MASK 511
#endif
inline void wait_idle(void) {
int i;
while(!(NFSTAT & BUSY))
for(i=0; i<10; i++);
}
/* low level nand read function */
int nand_read_ll(unsigned char *buf, unsigned long start_addr, int size)
{
int i, j;
if ((start_addr & NAND_BLOCK_MASK) || (size & NAND_BLOCK_MASK)) {
return -1; /* invalid alignment */
}
/* chip Enable */
NFCONF &= ~0x800;
for(i=0; i<10; i++);
for(i=start_addr; i < (start_addr + size);) {
/* READ0 */
NFCMD = 0;
/* Write Address */
NFADDR = i & 0xff;
NFADDR = (i >> 9) & 0xff;
NFADDR = (i >> 17) & 0xff;
NFADDR = (i >> 25) & 0xff;
wait_idle();
for(j=0; j < NAND_SECTOR_SIZE; j++, i++) {
*buf = (NFDATA & 0xff);
buf++;
}
}
/* chip Disable */
NFCONF |= 0x800; /* chip disable */
return 0;
}
12、编辑include/configs/sf2410.h文件
[[email protected] u-boot-1.1.4]# gedit include/configs/sf2410.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 *******************/
13、编译u-boot,然后测试u-boot是否可以从nand启动
[[email protected] u-boot-1.1.4]# make
...
/opt/u-boot-1.1.4/cpu/arm920t/start.S
/opt/u-boot-1.1.4/cpu/arm920t/start.S: Assembler messages:
/opt/u-boot-1.1.4/cpu/arm920t/start.S:285: Error: bad instruction `align 2‘
make: *** [cpu/arm920t/start.o] 错误 1
出现错误。是因为在修改/opt/u-boot-1.1.4/cpu/arm920t/start.S文件时,.align 2的点丢失了!:
[[email protected] u-boot-1.1.4]# ll u-boot*
-rwxr-xr-x 1 root root 397852 06-14 18:11 u-boot
-rwxr-xr-x 1 root root 100564 06-14 18:11 u-boot.bin
-rw-r--r-- 1 root root 49189 06-14 18:11 u-boot.map
-rwxr-xr-x 1 root root 301770 06-14 18:11 u-boot.srec
14、执行如下命令:
此时如果直接执行skyeye1.2.6会出现错误,所以先执行下边命令:
[[email protected] u-boot-1.1.4]# mknandflashdump u-boot.bin nand.dump 0
出现如下错误:
bash: mknandflashdump: command not found
把mknandflashdump和mknandflashdump.c移到/opt/u-boot-1.1.4/下,然后执行下边命令
[[email protected] u-boot-1.1.4]# cp /opt/u-boot-1.1.4/mknandflashdump /bin
//把mknandflashdump放到自动搜索路径的文件夹下,再次执行mknandflashdump u-boot.bin nand.dump 0这条命令即可
[[email protected] u-boot-1.1.4]# mknandflashdump u-boot.bin nand.dump 0
finish
[[email protected] u-boot-1.1.4]# ll nand.dump
---------- 1 root root 69206016 06-14 18:16 nand.dump
[[email protected] u-boot-1.1.4]# ll nand.dump
-rw-rw-rw- 1 root root 69206016 06-14 18:16 nand.dump
[[email protected] u-boot-1.1.4]# skyeye1.2.6 //执行skyeye1.2.6
...
Bank #0: 30000000 64 MB
Flash: 512 kB
*** Warning - bad CRC, using default environment
In: serial
Out: serial
Err: serial
SF2410 #
15、编辑include/configs/sf2410.h文件
[[email protected] u-boot-1.1.4]# gedit include/configs/sf2410.h
修改内容:
在
#define CONFIG_BAUDRATE 115200
后面添加
/*********************** me add begin *************************************/
/* enable passing of ATAGs */
#define CONFIG_CMDLINE_TAG 1
#define CONFIG_SETUP_MEMORY_TAGS 1
#define CONFIG_INITRD_TAG 1
/*********************** me add end *************************************/
将
/*CFG_CMD_NAND |*/ \
改为
CFG_CMD_NAND | \
将
/*#define CONFIG_BOOTARGS "root=ramfs devfs=mount console=ttySA0,9600" */
改为
#define CONFIG_BOOTARGS "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"
将
/*#define CONFIG_BOOTCOMMAND "tftp; bootm" */
改为
#define CONFIG_BOOTCOMMAND "tftp 0x31000000 uImage;bootm 0x31000000"
将第十一步在文件尾添加的内容替换成下边内容:
/****************** me add begin *******************/
// #define CFG_ENV_IS_IN_FLASH 1 /*将该行注释,添加下面一行*/
#define CFG_ENV_IS_IN_NAND 1 /*该行很重要,没有该行,saveenv命令将失效*/
#define CFG_ENV_SIZE 0x10000 /* Total Size of Environment Sector */
#define CFG_NAND_LEGACY 1
#define CFG_ENV_OFFSET 0X20000 /*环境变量在Nand Flash的0x20000处*/
#if (CONFIG_COMMANDS & CFG_CMD_NAND)
#define CFG_NAND_BASE 0x4E000000 /* physical address to access nand at CS0*/
&n 以上是关于嵌入式系统移植三部曲 吴素芬的主要内容,如果未能解决你的问题,请参考以下文章