uboot的start.S文件分析

来源:互联网 发布:android 淘宝筛选界面 编辑:程序博客网 时间:2024/05/21 14:59

.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

#endif /* CONFIG_PRELOADER */
 .balignl 16,0xdeadbeef


/*
 *************************************************************************
 *
 * Startup Code (reset vector)
 *
 * do important init only if we don't start from memory!
 * setup Memory and board specific bits prior to relocation.
 * relocate armboot to ram
 * setup stack
 *
 *************************************************************************
 */

_TEXT_BASE:
 .word TEXT_BASE   //定义一个变量存储
//TEXT_BASE是Uboot载入内存后物理的基地址。定义在board/xxx/config.mk里面,移植是需要修改。

.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

/* IRQ stack memory (calculated at run-time) */
.globl FIQ_STACK_START   //快速中断的地址。
FIQ_STACK_START:
 .word 0x0badc0de
#endif


/*
 * the actual reset code
 */

reset:
 /*
  * set the cpu to SVC32 mode
  */
 mrs r0,cpsr
 bic r0,r0,#0x1f
 orr r0,r0,#0xd3
 msr cpsr,r0

 /*
  * we do sys-critical inits only at reboot,
  * not when booting from ram!
  */
#ifndef CONFIG_SKIP_LOWLEVEL_INIT
 bl cpu_init_crit    //执行cpu_init_crit   
#endif

#ifndef CONFIG_SKIP_RELOCATE_UBOOT
relocate:    /* relocate U-Boot to RAM     */  将uboot复制到ram。
 adr r0, _start  /* r0 <- current position of code   */
 ldr r1, _TEXT_BASE  /* test if we run from flash or RAM */
 cmp     r0, r1                  /* don't reloc during debug         */
 beq     stack_setup
 ldr r2, _armboot_start
 ldr r3, _bss_start
 sub r2, r3, r2  /* r2 <- size of armboot            */
 add r2, r0, r2  /* r2 <- source end address         */

copy_loop:
 ldmia r0!, {r3-r10}  /* copy from source address [r0]    */
 stmia r1!, {r3-r10}  /* copy to   target address [r1]    */
 cmp r0, r2   /* until source end addreee [r2]    */
 ble copy_loop
#endif /* CONFIG_SKIP_RELOCATE_UBOOT */
 
 /* Set up the stack          */
stack_setup:        //设置程序栈
 ldr r0, _TEXT_BASE  /* upper 128 KiB: relocated uboot   */
 sub sp, r0, #128  /* leave 32 words for abort-stack   */
#ifndef CONFIG_PRELOADER
 sub r0, r0, #CONFIG_SYS_MALLOC_LEN /* malloc area                      */
 sub r0, r0, #CONFIG_SYS_GBL_DATA_SIZE /* bdinfo                        */
#ifdef CONFIG_USE_IRQ
 sub r0, r0, #(CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ)
#endif
#endif /* CONFIG_PRELOADER */
 sub sp, r0, #12  /* leave 3 words for abort-stack    */
 bic sp, sp, #7  /* 8-byte alignment for ABI compliance */

clear_bss:   //清空bss段
 ldr r0, _bss_start  /* find start of bss segment        */
 ldr r1, _bss_end  /* stop here                        */
 mov r2, #0x00000000  /* clear                            */

#ifndef CONFIG_PRELOADER  //循环中清空bss
clbss_l:str r2, [r0]  /* clear loop...                    */
 add r0, r0, #4
 cmp r0, r1
 ble clbss_l

 bl coloured_LED_init
 bl red_LED_on
#endif /* CONFIG_PRELOADER */

 ldr pc, _start_armboot  //执行_start_armboot,第一个C函数

_start_armboot:
#ifdef CONFIG_NAND_SPL   //如果是从spi_nand中启动
 .word nand_boot
#else
 .word start_armboot   //正常启动,进入C函数。
#endif /* CONFIG_NAND_SPL */

总结:

start.S中主要禁用cache、MMU,设置了中断向量,栈并清空bss段。为程序建立好C语言运行的环境之后,就将uboot复制到第二部分,去执行第一个C函数。

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/yuanlulu/archive/2011/03/17/6256811.aspx

0 0