单板选择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中。能够成功引导内核。