[Linux]简易BootLoader
[Linux]简易BootLoader
艾恩凝
2021/5/25
Introduction
最简单的BootLoader,说白了就是裸机程序,用来启动内核。
BootLoader相当于windows中的bios,引导windows
Code

start.S
.text
.global _start
_start:
/* 1. 关闭看门狗 */
ldr r0, =0x53000000
mov r1, #0
str r1, [r0]
/* 2. 设置时钟 */
/* CLKDIVN(0x4C000014) = 0X5, tFCLK:tHCLK:tPCLK = 1:4:8 */
ldr r0, =0x4C000014
ldr r1, =0x5
str r1, [r0]
/* 设置CPU工作于异步模式 */
mrc p15,0,r0,c1,c0,0
orr r0,r0,#0xc0000000 //R1_nF:OR:R1_iA
mcr p15,0,r0,c1,c0,0
/* 设置MPLLCON(0x4C000004) = (92<<12)|(1<<4)|(1<<0)
* m = MDIV+8 = 92+8=100
* p = PDIV+2 = 1+2 = 3
* s = SDIV = 1
* FCLK = 2*m*Fin/(p*2^s) = 2*100*12/(3*2^1)=400M
*/
ldr r0, =0x4C000004
ldr r1, =(92<<12)|(1<<4)|(1<<0)
str r1, [r0]
/* 启动ICACHE */
mrc p15, 0, r0, c1, c0, 0 @ read control reg
orr r0, r0, #(1<<12)
mcr p15, 0, r0, c1, c0, 0 @ write it back
/* 3. 初始化SDRAM*/
ldr r0, =0x48000000
adr r1, sdram_config
add r3, r0, #52
1:
ldr r2, [r1], #4
str r2, [r0], #4
cmp r0, r3
bne 1b
/* 4. 重定位*/
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 clean_bss
/* 5. 执行main*/
ldr lr, =halt
ldr pc, =main
halt:
b halt
sdram_config:
.long 0x22111110 //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 0x008e07a3 //REFRESH,HCLK=12MHz:0x008e07a3,HCLK=100MHz:0x008e04f4
.long 0x000000b2 //BANKSIZE
.long 0x00000030 //MRSRB6
.long 0x00000030 //MRSRB7
Conclusion
BootLoader需要学习的地方有很多,主要部分明白了,uboot学习的地方有很多。
BootLoader下载链接 这是学习写的BootLoader
吾心信其可行,
则移山填海之难,
终有成功之日!
——孙文
则移山填海之难,
终有成功之日!
——孙文
评论
0 评论