搞过uboot移植的人都知道,要想让系统从NandFlash启动,第一步就是要在start.s中屏蔽掉从Nor Flash启动的代码,然后自己添加从Nand Flash启动的代码,我添加的代码如下:
/****** NAND_BOOT ********/
#define LENGTH_UBOOT 0x60000
#define NAND_CTL_BASE 0x4E000000
#ifdef CONFIG_S3C2440
/* Offset */
#define oNFCONF 0x00
#define oNFCONT 0x04
#define oNFCMD 0x08
#define oNFSTAT 0x20
@ reset NAND
mov r1, #NAND_CTL_BASE
ldr r2, =( (7<<12)|(7<<8)|(7<<4)|(0<<0) )
str r2, [r1, #oNFCONF]
ldr r2, =( (1<<4)|(0<<1)|(1<<0) ) @ Active low CE Control
str r2, [r1, #oNFCONT]
ldr r2, =(0x6) @ RnB Clear
str r2, [r1, #oNFSTAT]
mov r2, #0xff @ RESET command
strb r2, [r1, #oNFCMD]
//等待一段时间,当r3=0xa时,等待结束
mov r3, #0 @ wait
nand1:
add r3, r3, #0x1
cmp r3, #0xa
blt nand1
nand2:
ldr r2, [r1, #oNFSTAT] @ wait ready
tst r2, #0x4
beq nand2
//等待NandFlsh复位
ldr r2, [r1, #oNFCONT]
orr r2, r2, #0x2 @ Flash Memory Chip Disable
str r2, [r1, #oNFCONT]
@ 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 复制到RAM中 TEXT_BASE这个位置,即0x33F8 0000
mov r1, #0x0 Nand Flash的起始地址
mov r2, #LENGTH_UBOOT uboot的大小
bl nand_read_ll
tst r0, #0x0
beq ok_nand_read 读取成功
bad_nand_read:
loop2:
b loop2 @ infinite loop
ok_nand_read:
@ verify 校验前4K代码搬移是否成功
mov r0, #0 Nand Flash 中uboot的起始地址
ldr r1, =TEXT_BASE RAM中的起始地址
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