//注意:在上一篇Nor Flash启动中,我们为了把u-boot用supervivi下载到内存中运行而屏蔽掉这段有关CPU初始化的代码。而现在我们要把u-boot下载到Nand Flash中,从Nand Flash启动,所以现在要恢复这段代码。
#ifndef CONFIG_SKIP_LOWLEVEL_INIT bl cpu_init_crit #endif
#if 0 //屏蔽掉u-boot中的从Nor Flash启动部分 #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 */ #endif
//下面添加2440中u-boot从Nand Flash启动
#ifdef CONFIG_S3C2440_NAND_BOOT mov r1, #NAND_CTL_BASE //复位Nand Flash ldr r2, =( (7<<12)|(7<<8)|(7<<4)|(0<<0) ) str r2, [r1, #oNFCONF] //设置配置寄存器的初始值,参考s3c2440手册 ldr r2, [r1, #oNFCONF]
ldr r2, =( (1<<4)|(0<<1)|(1<<0) ) str r2, [r1, #oNFCONT] //设置控制寄存器 ldr r2, [r1, #oNFCONT]
ldr r2, =(0x6) //RnB Clear str r2, [r1, #oNFSTAT] ldr r2, [r1, #oNFSTAT] mov r2, #0xff //复位command strb r2, [r1, #oNFCMD]
mov r3, #0 //等待 nand1: add r3, r3, #0x1 cmp r3, #0xa blt nand1
nand2: ldr r2, [r1, #oNFSTAT] //等待就绪 tst r2, #0x4 beq nand2
ldr r2, [r1, #oNFCONT] orr r2, r2, #0x2 //取消片选 str r2, [r1, #oNFCONT]
//get read to call C functions (for nand_read()) ldr sp, DW_STACK_START //为C代码准备堆栈,DW_STACK_START定义在下面 mov fp, #0
//copy U-Boot to RAM ldr r0, =TEXT_BASE//传递给C代码的第一个参数:u-boot在RAM中的起始地址 mov r1, #0x0 //传递给C代码的第二个参数:Nand Flash的起始地址 mov r2, #0x30000 //传递给C代码的第三个参数:u-boot的长度大小(128k) bl nand_read_ll //此处调用C代码中读Nand的函数,现在还没有要自己编写实现 tst r0, #0x0 beq ok_nand_read
bad_nand_read: loop2: b loop2 //infinite loop
ok_nand_read: //检查搬移后的数据,如果前4k完全相同,表示搬移成功 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_S3C2440_NAND_BOOT
_start_armboot: .word start_armboot //在这一句的下面加上DW_STACK_START的定义
.align 2 DW_STACK_START: .word STACK_BASE+STACK_SIZE-4
|