u-boot移植前的准备工作:
1 下载源码,建立工作目录
Uboot的源码可以从以下网址下载:http://downloads.sourceforge.net/u-boot/u-boot-1.1.4.tar.bz2?modtime=1134752480&big_mirror=0
我们这里下载的是u-boot-1.1.4.tar.bz2
建立工作目录:
mkdir /root/build_uboot
cd /root/build_uboot
把下载的源码拷贝到该目录,解压;
tar jxvf u-boot-1.1.4.tar.bz2
mv u-boot-1.1.4 u-boot
2 确定分区:
u-boot移植的具体步骤:
一 建立适合的board平台
参照board/smdk2410目录,我们在源码的board下建立自己的自己的平台gec2410,步骤如下.
1 修改顶层Makefile
cd /root/build_uboot/u-boot
vi Makefile
找到:
smdk2410_config : unconfig
@./mkconfig $(@:_config=) arm arm920t smdk2410 NULL s3c24x0
在其后面添加:
gec2410_config : unconfig
@./mkconfig $(@:_config=) arm arm920t gec2410 NULL s3c24x0
各项的意思如下:
arm:??????? CPU的架构(ARCH)
arm920t:??? CPU的类型(CPU),其对应于cpu/arm920t子目录。
gec2410:??? 开发板的型号(BOARD),对应于board/gec2410目录。
NULL:?????? 开发者/或经销商(vender)。
s3c24x0:??? 片上系统(SOC)。
我把我的板子起名叫gec2410,可以依自己的喜好修改
2 建立board/gec2410目录,拷贝board/smdk2410下的文件到board/gec2410目录,将smdk2410.c更名为gec2410.c
cp -r board/smdk2410 board/gec2410
3 修改board/gec2410/Makefile
将:
OBJS??? := smdk2410.o flash.o
改为:
OBJS???? := gec2410.o flash.o
4 cp include/configs/smdk2410.h include/configs/gec2410.h
5 修改cpu/arm920t/config.mk文件
将:
PLATFORM_CPPFLAGS +=$(call cc-option,-mapcs-32,-mabi=apcs-gnu)
改为:
PLATFORM_CPPFLAGS +=$(call cc-option,$(call cc-option,-mabi=apcs-gnu),)
6 设置交叉编译环境变量
export PATH=/usr/local/arm/2.95.3/bin:$PATH
7 测试编译能否成功:
make gec2410_config
make all ARCH=arm
生成u-boot.bin就OK了
二 支持网络和 nand flash操作命令
1 添加网络命令
在include/configs/gec2410.h
只要在
#define CONFIG_COMMANDS
添加定义
????????????????????????? CFG_CMD_NET
????????????????????????? CFG_CMD_PING
就可以了
??? 说明:include/configs/gec2410.h文件是与开发板相关的配置头文件。
2 支持nand flash启动和读写
(1) 支持从nand flash 启动
a 添加nandflash寄存器的定义
修改include/configs/gec2410.h文件,添加如下内容:
***********************************************************************************************
/*
* 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
************************************************************************************************
b 在start.S加入搬运代码
修改cpu/arm920t/start.S文件
在ldr pc,_start_armboot之前加入:
************************************************************************************************
#ifdef CONFIG_S3C2410_NAND_BOOT
bl??? copy_myself
@ jump to ram
ldr?? r1,=on_the_ram
add pc,r1,#0
nop
nop
1:??? b???? 1b????????? @ infinite loop
on_the_ram:
#endif
************************************************************************************************
在_start_armboot: .word start_armboot之后加入:
************************************************************************************************
#ifdef CONFIG_S3C2410_NAND_BOOT
copy_myself:
mov r10,lr
@ reset NAND
mov r1,#NAND_CTL_BASE
ldr?? r2,=0xf830?????????? @ initial value
str?? r2,[r1,#oNFCONF]
ldr?? r2,#oNFCONF]
bic r2,r2,#0x800????????????? @ enable chip
str?? r2,#oNFCONF]
mov r2,#0xff???????? @ RESET command
strb r2,#oNFCMD]
mov r3,#0?????????????????? @ wait
1:add r3,r3,#0x1
cmp r3,#0xa
blt?? 1b
2:ldr?? r2,#oNFSTAT]????? @ wait ready
tst??? r2,#0x1
beq 2b
ldr?? r2,#oNFCONF]
orr r2,#0x800????????????? @ disable chip
str?? r2,#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 vivi to RAM
ldr?? r0,=UBOOT_RAM_BASE
mov???? r1,#0x0
mov r2,#0x20000
bl??? nand_read_ll
tst??? r0,#0x0
beq ok_nand_read
#ifdef CONFIG_DEBUG_LL
bad_nand_read:
ldr?? r0,STR_FAIL
ldr?? r1,SerBase
bl??? PrintWord
1:b???? 1b????????? @ infinite loop
#endif
ok_nand_read:
#ifdef CONFIG_DEBUG_LL
ldr?? r0,STR_OK
ldr?? r1,SerBase
bl??? PrintWord
#endif
@ verify
mov r0,#0
ldr?? r1,=UBOOT_RAM_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,#4
beq done_nand_read
bne go_next
notmatch:
#ifdef CONFIG_DEBUG_LL
sub r0,r0,#4
ldr?? r1,SerBase
bl??? PrintHexWord
ldr?? r0,SerBase
bl??? PrintWord
#endif
1:b???? 1b
done_nand_read:
#ifdef CONFIG_DEBUG_LL
ldr?? r0,SerBase
bl??? PrintWord
#endif
mov pc,r10
@ clear memory
@ r0: start address
@ r1: length
mem_clear:
mov r2,#0
mov r3,r2
mov r4,r2
mov r5,r2
mov r6,r2
mov r7,r2
mov r8,r2
mov r9,r2
clear_loop:
stmia????? r0!,{r2-r9}
subs r1,#(8 * 4)
bne clear_loop
mov pc,lr
#endif @ CONFIG_S3C2410_NAND_BOOT
************************************************************************************************
在文件的最后加入如下,堆栈地址:
*************************************************************************************************
?? .align???? 2
DW_STACK_START:
.word????? STACK_BASE+STACK_SIZE-4
*************************************************************************************************
c 添加nand_read_ll函数的实现
在board/gec2410/建立nand_read.c,加入如下内容(copy from vivi):
*************************************************************************************************
#include <config.h>
#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
inline void wait_idle(void) {
??? int i;
??? while(!(NFSTAT & BUSY))
????? for(i=0; i<10; i++);
}
#define NAND_SECTOR_SIZE 512
#define NAND_BLOCK_MASK (NAND_SECTOR_SIZE - 1)
/* 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;
}
************************************************************************************************
修改board/gec2410/Makefile为
OBJS := gec2410.o flash.o nand_read.o
以上步骤就可以把u-boot烧写到nandflash上了
2) 支持nand flash操作命令
a 在/include/configs/gec2410.h文件中添加宏定义
#define CONFIG_COMMANDS
添加定义
????????????????????????? CFG_CMD_NAND
??????????????????????? CFG_CMD_ENV????????
b 定义环境变量宏
#define CFG_ENV_IS_IN_FLASH 1
#define CFG_ENV_SIZE?????????????? 0x10000 /* Total Size of Environment Sector */
改为
#define CFG_ENV_IS_IN_NAND??????? 1
#define CFG_ENV_OFFSET???????????? 0x030000
#define CFG_NAND_BASE??? 0x4E000000
#define CMD_SAVEENV
#define CFG_NAND_LEGACY
#define CFG_ENV_SIZE?????????????? 0x10000 /* Total Size of Environment Sector */???????????????????????
/*set env*/
#define CFG_MONITOR_BASE PHYS_SDRAM_1
c 修改common/cmd_nand.c文件,添加nand flash初始化函数
添加
**************************************************************************************************
#define rNFCONF (*(volatile unsigned *)0x4E000000)
#define rNFCMD (*(volatile unsigned *)0x4E000004)
#define rNFADDR (*(volatile unsigned *)0x4E000008)
#define rNFDATA (*(volatile unsigned *)0x4E00000C)
#define rNFSTAT (*(volatile unsigned *)0x4E000010)
#define rNFECC (*(volatile unsigned *)0x4E000014)
#define CFG_NAND_BASE??? 0x4E000000
#define CFG_MAX_NAND_DEVICE 1 /* Max number of NAND devices */
#define SECTORSIZE 512
#define ADDR_COLUMN 1
#define ADDR_PAGE 2
#define ADDR_COLUMN_PAGE 3
#define NAND_ChipID_UNKNOWN 0x00
#define NAND_MAX_FLOORS 1
#define NAND_MAX_CHIPS 1
#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);}
#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)
/* 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_init()函数的实现
*******************************************************************************************************
void nand_init(void)
{
???????? int i;
???????? unsigned long j;
???????? rNFCONF=(1<<15)|(1<<14)|(1<<13)|(1<<12)|(1<<11)|(0<<8)|(3<<4)|(0<<0);
????????
???????? rNFCONF=rNFCONF&~(1<<11);
???????? rNFCMD=0xff;
????????????????
???????? for(i=0;i<10;i++);
???????? while(!(rNFSTAT&(1<<0)));
????????
???????? rNFCONF=rNFCONF|(1<<11);
???????? j=nand_probe(0x4e000000);
???????? printf("nand flash : %4lu MBn",j>>20);
}
********************************************************************************************************
d 在nand_probe函数中添加一行
********************************************************************************************************
#endif
???????? oob_config.badblock_pos = 5;
??????? nand_dev_desc[0].ChipID = 0x00;
********************************************************************************************************
uboot移植完成!
配置编译
export PATH=/usr/local/arm/2.95.3/bin:$PATH
make gec2410_config
make ARCH=arm all
u-boot的测试
把u-boot烧写到nand flash上
启动信息:
*************************************************************
U-Boot 1.1.4 (Feb 10 2007 - 23:56:56)???????????????
????????????????????????????????????????????????????
U-Boot code: 33F80000 -> 33F9C5D0 BSS: -> 33FA06B8
RAM Configuration:
Bank #0: 30000000 64 MB
Flash: 512 kB
nand flash :?? 64 MB
In:??? serial
Out:?? serial
Err:?? serial
GEC2410#
**************************************************************
tftp 30008000 zImage
go 300080000
出现错误,因为go命令的实现函数不完整。
下面完善go命令的实现函数do_go()
三 完善do_go函数
gedit common/cmd_boot.c
添加
/*添加call_linux函数*/
********************************************************************************
void call_linux(long a0,long a1,long a2)
{??
__asm__(
???????????? "?? mov r1,#0n"
???????????? "?? mov r1,#7 << 5n"??????? /* 8 segments */
???????????? "1: orr r3,#63 << 26n"????? /* 64 entries */
???????????? "2: mcr p15,c7,c14,2n" /* clean & invalidate D index */
???????????? "?? subs??? r3,#1 << 26n"
???????????? "?? bcs 2bn"???????????? /* entries 64 to 0 */
???????????? "?? subs??? r1,#1 << 5n"
???????????? "?? bcs 1bn"???????????? /* segments 7 to 0 */
???????????? "?? mcr p15,c5,0n" /* invalidate I cache */
???????????? "?? mcr p15,c10,4n" /* drain WB */
);
__asm__(
"mov??? r0,#0n"
"mcr??? p15,4n"?? /* drain WB */
"mcr??? p15,c8,0n"??? /* invalidate I & D TLBs */
);
__asm__(
"mov??? r0,%0n"
"mov??? r1,#0x0c1n"
"mov??? r2,%2n"
"mov??? ip,ip,c13,c0,0n"?? /* zero PID */
"mcr??? p15,0n"??? /* invalidate I,D caches */
"mcr??? p15,4n"?? /* drain write buffer */
"mcr??? p15,D TLBs */
"mrc??? p15,c1,0n"??? /* get control register */
"bic??? ip,#0x0001n"????? /* disable MMU */
"mcr??? p15,0n"??? /* write control register */
"mov??? pc,r2n"
"nopn"
"nopn"
: /* no outpus */
: "r" (a0),"r" (a1),"r" (a2)
);
}
****************************************************************************
添加setup_linux_param函数
****************************************************************************
static void setup_linux_param(ulong param_base)
{??
struct param_struct *params = (struct param_struct *)param_base;
char *linux_cmd;
//linux_cmd = "noinitrd root=/dev/mtdblock/2 init=/linuxrc console=ttyS0";
linux_cmd = getenv("bootargs");
memset(params,sizeof(struct param_struct));
params->u1.s.page_size = 0x00001000;
params->u1.s.nr_pages = (0x04000000 >> 12);
/* set linux command line */
memcpy(params->commandline,linux_cmd,strlen(linux_cmd) + 1);
}
****************************************************************************
在do_go()函数中添加
****************************************************************************
printf ("## Starting application at 0x%08lX ...n",addr);
???????? setup_linux_param(0x30000100);
???????? call_linux(0,0x0c1,0x30008000);
???????? printf("okn");
****************************************************************************
3重新编译u-boot
make all ARCH=arm
通过jtag将u-boot烧写到flash中就可以从NAND flash启动了
U-BOOT常用命令介绍
printenv?? 打印环境变量
setenv???? 设置环境变量
如:setenv ipaddr 172.22.60.44
????? Setenv serverip 172.22.60.88
saveenv??????? 保存设定的环境变量
我们经常要设置的环境变量有ipaddr,serverip,bootcmd,bootargs。
tftp?????? 即将内核镜像文件从PC中下载到SDRAM的指定地址,然后通过bootm来引导内核,前提是所用PC要安装设置tftp服务。
如: tftp 30008000 zImage
nand erase 擦除nand flash中数据块 如:nand erase 0x40000 0x1c0000 ?????????????? 起始地址 大小 nand write 把RAM中的数据写到Nand Flash中 如:nand write 0x30008000 0x40000 0x1c0000 nand read?? 从nand flash中读取数据到RAM 如:nand read 0x30008000 0x40000 0x1c0000 go????????? 直接跳转到可执行文件的入口地址,执行可执行文件。 下载并烧写内核如下 1 用网线连接开发板和PC机 2 启动U-BOOT并设置环境变量 setenv ipaddr 172.22.60.32 //设置开发板的IP setenv serverip 172.22.60.99 //设置PC机的IP setenv ethaddr 11.22.33.44.55.66 //设置开发板的物理地址 saveenv //保存 3 在PC机端打开TFTP服务器,并且把要下载的文件拷贝到tftp服务器程序所在的目录下 4 下载和烧写 在u-boot下用以下命令 ??? tftp 30008000 zImage nand erase 40000 1c0000 nand write 30008000 40000 1c0000