單闆選擇NandFlash啟動,則硬體上電後,系統會自動将NandFlash中的前4K内容拷貝到STEPSTONE即4K SRAM中,然後從SRAM中的0X0位址啟動。基于mini2440的簡易bootloader制作方法在上一篇文章中有提到,它編譯出的boot.bin隻有1.96KB,小于STEPSTONE的4KB,是以我們可以考慮将bootloader從nandflash拷貝到記憶體這一步給省略掉。
一、編輯start.S:
.text
.global _start
_start:
/* close the watchdog */
ldr r0, =0x53000000
mov r1, #0
str r1, [r0]
/* close the watchdog */
@關閉看門狗
@資料手冊:WTCON 0x53000000 R/W Watchdog timer control register
/* set the clock */
ldr r0, =0x4c000014
mov r1, #0x03; @ FCLK:HCLK:PCLK=1:2:4, HDIVN=1,PDIVN=1
str r1, [r0]
mrc p15, 0, r1, c1, c0, 0 /* read */
orr r1, r1, #0xc0000000 /* set asynchronous bus mode */
mcr p15, 0, r1, c1, c0, 0 /* write */
ldr r0, =0x4c000004
ldr r1, =((0x5c<<12)|(0x01<<4)|(0x02)) @MPLL:200MHz
str r1, [r0]
/* set the clock */
@設定系統時鐘
@如果HDIVN不是0,CPU的總線模式應該設定成asynchronous bus mode
/* enable the ICACHE */
mrc p15, 0, r0, c1, c0, 0 @ read control register
orr r0, r0, #(1<<12)
mcr p15, 0, r0, c1, c0, 0 @ write back
/* enable the ICACHE */
@使能高速緩存,為系統提速,此段可不要,但程式執行速度要慢
/* init the SDRAM */
ldr r0, =0x48000000 @MEM_CTL_BASE
adr r1, config /* sdram config address */
add r3, r0, #(52) @13*4
1:
ldr r2, [r1], #4
str r2, [r0], #4
cmp r0, r3
bne 1b
/* init the SDRAM */
@初始化SDRAM
@根據資料手冊對與SDRAM有關的13個寄存器進行配置
/* relocate */
ldr sp, =0x34000000
bl nand_init
/* mov r0, #0
ldr r1, =_start
ldr r2, =__bss_start
sub r2, r2, r1
bl copy_code_to_sdram */
bl clear_bss
/* relocate */
@把bootloader本身的代碼從nandflash複制到它的連結位址去
/* go to main */
ldr lr, =halt
ldr pc, =main
halt:
b halt
/* go to main */
@跳轉到main函數執行
config:
.long 0x22011110 @BWSCON
.long 0x00000700 @BANKCON0
.long 0x00000700 @BANKCON1
.long 0x00000700 @BANKCON2
.long 0x00000700 @BANKCON3
.long 0x00000700 @BANKCON4
.long 0x00000700 @BANKCON5
.long 0x00018005 @BANKCON6
.long 0x00018005 @BANKCON7
.long 0x008C04F4 @REFRESH
.long 0x000000B1 @BANKSIZE
.long 0x00000030 @MRSRB6
.long 0x00000030 @MRSRB7
注釋掉:
/* mov r0, #0
ldr r1, =_start
ldr r2, =__bss_start
sub r2, r2, r1
bl copy_code_to_sdram */
二、編輯boot.lds:
SECTIONS {
. = 0x00000000;
.text : { *(.text) }
. = ALIGN(4);
.rodata : {*(.rodata*)}
. = ALIGN(4);
.data : { *(.data) }
. = ALIGN(4);
__bss_start = .;
.bss : { *(.bss) *(COMMON) }
__bss_end = .;
}
将 0x33f80000改為0x00000000。
三、 make之後将生成的boot.bin下載下傳到nandflash中,可以成功引導核心。