单板选择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。
简易bootloader重定位问题,布布扣,bubuko.com
原文:http://blog.csdn.net/wu20093346/article/details/26824401