1、U-boot-1.16 基于s3c6410 start.S 流程分析

u-boot-1.1.6 Start.S 流程分析 基于S3c6410

start.S 文件位于srcPath/cpu/s3c64xx/ 目录
作为uboot运行的第一段程序,它做了一些具体的初始化流程,具体工作如下:

1.设置中断向量表

.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相关段定义

/*在 /board/samung/mini6410/config.mk 定义,代码运行时的地址

_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.设置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、关闭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、设置外围基地址

/* Peri port setup */
ldr r0, =0x70000000
orr r0, r0, #0x13
mcr p15,0,r0,c15,c2,4       @ 256M(0x70000000-0x7fffffff)

7、跳转到 lowlevel_init.S (/src/board/samsung/mini6410/lowlevel_init.S)

下面的动作均是在lowlevel_init.s 中所做:

  • 1.点亮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.关闭看门狗
    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.关闭所有中断
    @ Disable all interrupts (VIC0 and VIC1)
    mvn r3, #0x0
    str r3, [r0, #oINTMSK]
    str r3, [r1, #oINTMSK]

  • 5.设置所有中断为IRQ
    @ Set all interrupts as IRQ
    mov r3, #0x0
    str r3, [r0, #oINTMOD]
    str r3, [r1, #oINTMOD]

  • 6、清零所有中断挂起状态
    @ Pending Interrupt Clear
    mov r3, #0x0
    str r3, [r0, #oVECTADDR]
    str r3, [r1, #oVECTADDR]

  • 7、系统时钟初始化
    bl system_clock_init

  • 8、串口初始化
    bl uart_asm_init

  • 9、NandFlash初始化
    bl nand_asm_init

  • 10、内存初始化
    bl mem_ctrl_asm_init

  • 11、判断是否为休眠唤醒
    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、拷贝代码到内存

#ifdef CONFIG_BOOT_NAND
mov r0, #0x1000   @4K
bl  copy_from_nand
#endif

9.使能MMU开关

#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、设置堆栈

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、跳转到start_armboot()

ldr pc, _start_armboot

_start_armboot:
.word start_armboot

你可能感兴趣的:(1、U-boot-1.16 基于s3c6410 start.S 流程分析)