嵌入式系统移植三部曲 李炎朔
Posted ztguang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了嵌入式系统移植三部曲 李炎朔相关的知识,希望对你有一定的参考价值。
嵌入式系统移植三部曲李炎朔 09机应一班 学号0906041053
三部曲《bootloader的移植》《linux的移植》《根文件系统的移植》
一 bootloader的移植
(1)安装skyeye-1.2.6_rc1
[[email protected] Desktop]# tar -xjvf skyeye-1.2.6_rc1.tar.bz2 -C ./
[[email protected] Desktop]# cd skyeye-1.2.6_rc1
[[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
*/
[[email protected] skyeye-1.2.6_rc1]# ./configure //配置
[[email protected] skyeye-1.2.6_rc1]# make //编译
[[email protected] skyeye-1.2.6_rc1]# make install //将skyeye安装到/usr/local/bin/
[[email protected] skyeye-1.2.6_rc1]# ll /usr/local/bin/skyeye
// -rwxr-xr-x 1 root root 2544308 05-17 17:59 /usr/local/bin/skyeye
[[email protected] skyeye-1.2.6_rc1]# mv /usr/local/bin/skyeye /usr/local/bin/skyeye1.2.6 //改名
(2)创建交叉编译环境
[[email protected] Desktop]# tar -xjvf arm-linux-gcc2.95.3.tar.bz2 -C ./ //交叉编译器:arm-linux-gcc2.95.3
(3)bootloader移植
[[email protected] Desktop]# tar -xjvf u-boot-1.1.4.tar.bz2 -C ./ //Bootloader:u-boot-1.1.4
[[email protected] Desktop]# cd u-boot-1.1.4
[[email protected] u-boot-1.1.4]# gedit Makefile //编辑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
*/
[[email protected] u-boot-1.1.4]# mkdir board/ok2410 //创建ok2410移植目录
[[email protected] u-boot-1.1.4]# cp board/smdk2410/* board/ok2410/ //复制必要的文件 */
[[email protected] u-boot-1.1.4]# dir board/ok2410/
// config.mk flash.c lowlevel_init.S Makefile smdk2410.c u-boot.lds
[[email protected] u-boot-1.1.4]# mv board/ok2410/smdk2410.c board/ok2410/ok2410.c
[[email protected] u-boot-1.1.4]# cp include/configs/smdk2410.h include/configs/ok2410.h
[[email protected] u-boot-1.1.4]# gedit include/configs/ok2410.h //编辑ok2410.h头文件
/*
将
#define CFG_PROMPT "SMDK2410 # " /* Monitor Command Prompt */
改为
#define CFG_PROMPT "OK2410 # " /* Monitor Command Prompt */
*/
[[email protected] u-boot-1.1.4]# gedit board/ok2410/Makefile
/*
将
OBJS := smdk2410.o flash.o
改为
OBJS := ok2410.o flash.o
*/
[[email protected] u-boot-1.1.4]# make ok2410_config //编译配置文件
// Configuring for ok2410 board...
[[email protected] 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
*/
//编译出现了如上错误 通过修改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,))
*/
[[email protected] 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
*/
//又出现错误了 不怕 修改examples目录下的Makefile文件就解决啦
[[email protected] 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
*/
[[email protected] u-boot-1.1.4]# make
/*
make[1]: Leaving directory `/root/Desktop/u-boot-1.1.4/common‘
UNDEF_SYM=`/usr/local/arm/2.95.3/bin/arm-linux-objdump -x lib_generic/libgeneric.a board/ok2410/libok2410.a cpu/arm920t/libarm920t.a cpu/arm920t/s3c24x0/libs3c24x0.a lib_arm/libarm.a fs/cramfs/libcramfs.a fs/fat/libfat.a fs/fdos/libfdos.a fs/jffs2/libjffs2.a fs/reiserfs/libreiserfs.a fs/ext2/libext2fs.a net/libnet.a disk/libdisk.a rtc/librtc.a dtt/libdtt.a drivers/libdrivers.a drivers/sk98lin/libsk98lin.a post/libpost.a post/cpu/libcpu.a common/libcommon.a |sed -n -e ‘s/.*\(__u_boot_cmd_.*\)/-u\1/p‘|sort|uniq`;\
/usr/local/arm/2.95.3/bin/arm-linux-ld -Bstatic -T /root/Desktop/u-boot-1.1.4/board/ok2410/u-boot.lds -Ttext 0x33F80000 $UNDEF_SYM cpu/arm920t/start.o \
--start-group lib_generic/libgeneric.a board/ok2410/libok2410.a cpu/arm920t/libarm920t.a cpu/arm920t/s3c24x0/libs3c24x0.a lib_arm/libarm.a fs/cramfs/libcramfs.a fs/fat/libfat.a fs/fdos/libfdos.a fs/jffs2/libjffs2.a fs/reiserfs/libreiserfs.a fs/ext2/libext2fs.a net/libnet.a disk/libdisk.a rtc/librtc.a dtt/libdtt.a drivers/libdrivers.a drivers/sk98lin/libsk98lin.a post/libpost.a post/cpu/libcpu.a common/libcommon.a --end-group -L /usr/local/arm/2.95.3/lib/gcc-lib/arm-linux/2.95.3 -lgcc \
-Map u-boot.map -o u-boot
/usr/local/arm/2.95.3/bin/arm-linux-objcopy --gap-fill=0xff -O srec u-boot u-boot.srec
/usr/local/arm/2.95.3/bin/arm-linux-objcopy --gap-fill=0xff -O binary u-boot u-boot.bin
*/ //第一小步成功了...
[[email protected] u-boot-1.1.4]# ll u-boot*
/*
-rwxr-xr-x 1 root root 396429 05-03 18:32 u-boot
-rwxr-xr-x 1 root root 100156 05-03 18:32 u-boot.bin
-rw-r--r-- 1 root root 48690 05-03 18:32 u-boot.map
-rwxr-xr-x 1 root root 300538 05-03 18:32 u-boot.srec
*/
[[email protected] u-boot-1.1.4]# gedit skyeye.conf //编辑skyeye的配置文件 里面空白 添加如下内容(注释里面的)
/*
# 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
*/
[[email protected] u-boot-1.1.4]# skyeye1.2.6 //执行skyeye
/*
**************************** 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 (May 3 2009 - 18:31:55)
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 #
*/ //出现提示符OK2410 # 执行成功 可以输入"?"查看帮助
//开始移植nand
[[email protected] u-boot-1.1.4]# gedit cpu/arm920t/start.S
将以下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 */
替换成:
//#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
//以上将从NOR Flash启动改成从NAND Flash启动
[[email protected] u-boot-1.1.4]# gedit board/ok2410/Makefile //修改board/ok2410/Makefile
/*
将
OBJS := ok2410.o flash.o
改为
OBJS := ok2410.o flash.o nand_read.o
*/
[[email protected] u-boot-1.1.4]# gedit board/ok2410/nand_read.c //创建board/ok2410/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;
}
[[email protected] u-boot-1.1.4]# gedit include/configs/ok2410.h //编辑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 *******************/
[[email protected] u-boot-1.1.4]# make
[[email protected] u-boot-1.1.4]# skyeye1.2.6 //再次执行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
*/ //到此停止不动 只需执行如下命令即可
[[email protected] u-boot-1.1.4]# mknandflashdump u-boot.bin nand.dump 0 //这个命令需要从网上下载 复制到/bin/下即可
// finish
[[email protected] u-boot-1.1.4]# ll nand.dump
// -rw-r--r-- 1 root root 118272 05-10 22:29 nand.dump
[[email protected] u-boot-1.1.4]# skyeye1.2.6 //再次执行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 (May 3 2009 - 18:57:18)
U-Boot code: 33F80000 -> 33F988D4 BSS: -> 33F9C9AC
RAM Configuration:
Bank #0: 30000000 64 MB
Flash: 512 kB
*** Warning - bad CRC, using default environment
In: serial
Out: serial
Err: serial
OK2410 # ? //显示可以使用的u-boot命令
*/
以下对u-boot添加nand指令的支持
[[email protected] u-boot-1.1.4]# gedit include/configs/ok2410.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 *************************************/
为了能使U-BOOT正确引导Linux内核,必须传递合适的参数给内核。引导内核时可以将bootargs传递给内核。bootargs是指ok2410.h文件中的CONFIG_BOOTARGS宏
将
/*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"
[[email protected] u-boot-1.1.4]# gedit include/configs/ok2410.h
将原来的me add begin与me add end之间的内容替换成以下内容
/****************** 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*/
/* Nand Flash控制器在SFR区起始寄存器地址 */
#define CFG_MAX_NAND_DEVICE 1 /*支持Nand Flash设备的最大个数*/
#define SECTORSIZE 512
#define NAND_SECTOR_SIZE SECTORSIZE
#define NAND_BLOCK_MASK 511
#define ADDR_COLUMN 1
#define ADDR_PAGE 3
#define ADDR_COLUMN_PAGE 4
#define NAND_ChipID_UNKNOWN 0x00 /* 未知芯片的ID号 */
#define NAND_MAX_FLOORS 1
#define NAND_MAX_CHIPS 1下载linux-2.6.14.7.tar.bz2 /* 板子上NAND Flash芯片的最大个数 */
/*下面7行是Nand Flash命令层底层的接口函数 */
#define WRITE_NAND_COMMAND(d, adr) {rNFCMD = d;}
#define WRITE_NAND_ADDRESS(d, adr) {rNFADDR = d;}
#define WRITE_NAND(d, adr) {rNFDATA = d;}
#define READ_NAND(adr) (rNFDATA)
#define NAND_WAIT_READY(nand) {while(!(rNFSTAT&(1<<0)));}
#define NAND_DISABLE_CE(nand) {rNFCONF |= (1<<11);}
#define NAND_ENABLE_CE(nand) {rNFCONF &= ~(1<<11);}
/* the following functions are NOP‘s because S3C24X0 handles this in hardware */
#define NAND_CTL_CLRALE(nandptr)
#define NAND_CTL_SETALE(nandptr)
#define NAND_CTL_CLRCLE(nandptr)
#define NAND_CTL_SETCLE(nandptr)
#define CONFIG_MTD_NAND_VERIFY_WRITE 1 /* 允许Nand Flash写校验 */
/*
* Nandflash Boot
*/
#define CONFIG_S3C2410_NAND_BOOT 1
#define STACK_BASE 0x33f00000
#define STACK_SIZE 0x8000
//#define UBOOT_RAM_BASE 0x33f80000
/* NAND Fl
以上是关于嵌入式系统移植三部曲 李炎朔的主要内容,如果未能解决你的问题,请参考以下文章