u-boot-1.1.6 Start.S 流程分析 基于S3c6410
start.S 文件位于srcPath/cpu/s3c64xx/ 目錄
作為uboot運(yùn)行的第一段程序剪验,它做了一些具體的初始化流程待牵,具體工作如下:
1.設(shè)置中斷向量表
.globl _start
_start: b reset
ldr pc, _undefined_instruction
ldr pc, _software_interrupt
ldr pc, _prefetch_abort
ldr pc, _data_abort
ldr pc, _not_used
ldr pc, _irq
ldr pc, _fiq
_undefined_instruction:
.word undefined_instruction
_software_interrupt:
.word software_interrupt
_prefetch_abort:
.word prefetch_abort
_data_abort:
.word data_abort
_not_used:
.word not_used
_irq:
.word irq
_fiq:
.word fiq
_pad:
.word 0x12345678 /* now 16*4=64 */
.global _end_vect
_end_vect:
.balignl 16,0xdeadbeef @deadbeef 壞的牛肉
2.uboot相關(guān)段定義
/*在 /board/samung/mini6410/config.mk 定義次慢,代碼運(yùn)行時(shí)的地址
_TEXT_BASE:
.word TEXT_BASE
/*
* Below variable is very important because we use MMU in U-Boot.
* Without it, we cannot run code correctly before MMU is ON.
* by scsuh.
*/
_TEXT_PHY_BASE:
.word CFG_PHY_UBOOT_BASE
.globl _armboot_start
_armboot_start:
.word _start
/*
* These are defined in the board-specific linker script.
*/
.globl _bss_start
_bss_start:
.word __bss_start
.globl _bss_end
_bss_end:
.word _end
#ifdef CONFIG_USE_IRQ
/* IRQ stack memory (calculated at run-time) */
.globl IRQ_STACK_START
IRQ_STACK_START:
.word 0x0badc0de @badcode 壞代碼
/* IRQ stack memory (calculated at run-time) */
.globl FIQ_STACK_START
FIQ_STACK_START:
.word 0x0badc0de @badcode 壞代碼
#endif
3.設(shè)置cpu的工作模式為SVC32
* set the cpu to SVC32 mode
mrs r0,cpsr
bic r0,r0,#0x1f
orr r0,r0,#0xd3
msr cpsr,r0
4旁涤、刷新I/D Cache
/*
* flush v4 I/D caches
*/
mov r0, #0
mcr p15, 0, r0, c7, c7, 0 /* flush v3/v4 cache */
mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */
5、關(guān)閉MMU與Cache
/*
* disable MMU stuff and caches
*/
mrc p15, 0, r0, c1, c0, 0
bic r0, r0, #0x00002300 @ clear bits 13, 9:8 (--V- --RS)
bic r0, r0, #0x00000087 @ clear bits 7, 2:0 (B--- -CAM)
orr r0, r0, #0x00000002 @ set bit 2 (A) Align
orr r0, r0, #0x00001000 @ set bit 12 (I) I-Cache
mcr p15, 0, r0, c1, c0, 0
6迫像、設(shè)置外圍基地址
/* Peri port setup */
ldr r0, =0x70000000
orr r0, r0, #0x13
mcr p15,0,r0,c15,c2,4 @ 256M(0x70000000-0x7fffffff)
7劈愚、跳轉(zhuǎn)到 lowlevel_init.S (/src/board/samsung/mini6410/lowlevel_init.S)
下面的動(dòng)作均是在lowlevel_init.s 中所做:
-
1.點(diǎn)亮led
/* LED on only #8 */
ldr r0, =ELFIN_GPIO_BASE
ldr r1, =0x55540000
str r1, [r0, #GPNCON_OFFSET]ldr r1, =0x55555555 str r1, [r0, #GPNPUD_OFFSET] ldr r1, =0xf000 str r1, [r0, #GPNDAT_OFFSET] ldr r0, =ELFIN_GPIO_BASE ldr r1, =0x1 str r1, [r0, #GPECON_OFFSET] ldr r1, =0x0 str r1, [r0, #GPEDAT_OFFSET] ldr r0, =ELFIN_GPIO_BASE ldr r1, =0x2A5AAAAA str r1, [r0, #GPPCON_OFFSET] ldr r1, =0x0 str r1, [r0, #GPPDAT_OFFSET] ldr r1, =0x55555555 str r1, [r0, #MEM1DRVCON_OFFSET]
2.關(guān)閉看門狗
ldr r0, =0x7e000000 @0x7e004000
orr r0, r0, #0x4000
mov r1, #0
str r1, [r0]-
3.清楚外部中斷
@ External interrupt pending clear
ldr r0, =(ELFIN_GPIO_BASE+EINTPEND_OFFSET) /EINTPEND/
ldr r1, [r0]
str r1, [r0]ldr r0, =ELFIN_VIC0_BASE_ADDR @0x71200000 ldr r1, =ELFIN_VIC1_BASE_ADDR @0x71300000
4.關(guān)閉所有中斷
@ Disable all interrupts (VIC0 and VIC1)
mvn r3, #0x0
str r3, [r0, #oINTMSK]
str r3, [r1, #oINTMSK]5.設(shè)置所有中斷為IRQ
@ Set all interrupts as IRQ
mov r3, #0x0
str r3, [r0, #oINTMOD]
str r3, [r1, #oINTMOD]6、清零所有中斷掛起狀態(tài)
@ Pending Interrupt Clear
mov r3, #0x0
str r3, [r0, #oVECTADDR]
str r3, [r1, #oVECTADDR]
7闻妓、系統(tǒng)時(shí)鐘初始化
bl system_clock_init8菌羽、串口初始化
bl uart_asm_init9、NandFlash初始化
bl nand_asm_init10由缆、內(nèi)存初始化
bl mem_ctrl_asm_init11注祖、判斷是否為休眠喚醒
ldr r0, =(ELFIN_CLOCK_POWER_BASE+RST_STAT_OFFSET)
ldr r1, [r0]
bic r1, r1, #0xfffffff7
cmp r1, #0x8
beq wakeup_reset-
12猾蒂、返回Start.S
ldr r0, =ELFIN_UART_BASE
ldr r1, =0x4b4b4b4b
str r1, [r0, #UTXH_OFFSET]mov lr, r12 mov pc, lr
8、拷貝代碼到內(nèi)存
#ifdef CONFIG_BOOT_NAND
mov r0, #0x1000 @4K
bl copy_from_nand
#endif
9.使能MMU開關(guān)
#ifdef CONFIG_ENABLE_MMU
enable_mmu:
/* enable domain access */
ldr r5, =0x0000ffff
mcr p15, 0, r5, c3, c0, 0 @ load domain access register
/* Set the TTB register */
ldr r0, _mmu_table_base
ldr r1, =CFG_PHY_UBOOT_BASE
ldr r2, =0xfff00000
bic r0, r0, r2
orr r1, r0, r1
mcr p15, 0, r1, c2, c0, 0
/* Enable the MMU */
mmu_on:
mrc p15, 0, r0, c1, c0, 0
orr r0, r0, #1 /* Set CR_M to enable MMU */
mcr p15, 0, r0, c1, c0, 0
nop
nop
nop
nop
#endif
10是晨、設(shè)置堆棧
stack_setup:
#ifdef CONFIG_MEMORY_UPPER_CODE
ldr sp, =(CFG_UBOOT_BASE + CFG_UBOOT_SIZE - 0xc)
#else
11肚菠、清零BSS段
clear_bss:
ldr r0, _bss_start /* find start of bss segment */
ldr r1, _bss_end /* stop here */
mov r2, #0x00000000 /* clear */
clbss_l:
str r2, [r0] /* clear loop... */
add r0, r0, #4
cmp r0, r1
ble clbss_l
12、跳轉(zhuǎn)到start_armboot()
ldr pc, _start_armboot
_start_armboot:
.word start_armboot