所谓技术

-----simple,sometimes naive!
posts - 11, comments - 0, trackbacks - 0, articles - 0
  IT博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

Uboot启动之start.S

Posted on 2008-03-29 22:08 vsolo 阅读(1175) 评论(0)  编辑 收藏 引用

/*
 *  armboot - Startup Code for ARM926EJS CPU-core
 *
 *  Copyright (c) 2003  Texas Instruments
 *
 *  ----- Adapted for OMAP1610 from ARM925t code ------
 *

#if defined(CONFIG_OMAP1610)
#include <./configs/omap1510.h>
#endif

/*
 *************************************************************************
 *
 * Jump vector table as in table 3.1 in [1]
 *
 *************************************************************************
 */


.globl _start
_start:                  //U-boot入口
 b reset                //跳到reset,下面是复位异常中断向量表,对应于interrupts.c中的各中断函数
 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

 .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  //分配给U-boot被搬运到RAM的起始地址
                         //OSK has 1 bank of 256 MB SDRAM
                         //Physical Address:
                         //1000'0000 to 2000'0000
                         //
                         // Linux-Kernel is expected to be at 1000'8000, entry 1000'8000
                         //(mem base + reserved)
                         //
                         // we load ourself to 1108'0000
                         // TEXT_BASE = 0x11080000

.globl _armboot_start    //下面是一些地址的全局符号
_armboot_start:    
 .word _start      //U-boot在ROM(flash)中的入口地址
                         //U-boot在ROM(flash)存储是由text段,data段,cmd参数区和bss段组成
                         //为了加快启动速度,stage1将把text段,data段和cmd参数区复制到RAM中运行
                         //并且对flash的设置代码不能在flash自己中运行
/*
 * These are defined in the board-specific linker script.
 */
.globl _bss_start
_bss_start:       
 .word __bss_start //bss段的起始地址(也就是U-boot执行代码的尾地址,可用于计算U-boot代码长度)

.globl _bss_end
_bss_end:
 .word _end


/*
 * 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!
  */
#ifdef CONFIG_INIT_CRITICAL       //开发调试过程中,当从RAM中启动时则此初始化不是必须的
 bl cpu_init_crit       //否则初始化CPU和RAM控制寄存器
#endif

relocate:    /* relocate U-Boot to 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         //如果相等即为开发过程,说明U-boot在RAM中启动(不是从flash启动),跳转

 ldr r2, _armboot_start  //否则从flash启动,将U-boot搬运到RAM中
 ldr r3, _bss_start      //确定源结束地址,此运算的必要性源自adr和ldr的区别
 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           //这样U-boot就可以在RAM中运行了

 /* Set up the stack          */
stack_setup:                      //在RAM中分配stack空间(包括动态内存区和boardinfo存储区)位于U-boot的下方
 ldr r0, _TEXT_BASE  /* upper 128 KiB: relocated uboot   */
 sub r0, r0, #CFG_MALLOC_LEN /* malloc area  = 128K +  128K      */
                                 //define CFG_MALLOC_LEN    (CFG_ENV_SIZE + 128*1024)
                                 //define CFG_ENV_SIZE 0x20000   /* Total Size of Environment Sector */
                                
 sub r0, r0, #CFG_GBL_DATA_SIZE /* bdinfo                        */
#ifdef CONFIG_USE_IRQ
 sub r0, r0, #(CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ)
#endif
 sub sp, r0, #12  /* leave 3 words for abort-stack    */

clear_bss:                        //bss段清零
 ldr r0, _bss_start  /* find start of bss segment        */
 add r0, r0, #4  /* start at first byte of bss       */
 ldr r1, _bss_end  /* stop here                        */
 mov  r2, #0x00000000  /* clear                            */

clbss_l:str r2, [r0]  /* clear loop...                    */
 add r0, r0, #4
 cmp r0, r1
 bne clbss_l

 ldr pc, _start_armboot  //stage1完成,转到stage2:C代码./lib_arm/broard.c中的start_armboot
                                  //stage1主要完成了CPU的配置,并将U-boot复制到RAM中运行
_start_armboot:
 .word start_armboot


/*
 *************************************************************************
 *
 * CPU_init_critical registers
 *
 * setup important registers
 * setup memory timing
 *
 *************************************************************************
 */


cpu_init_crit:
 /*
  * 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 */

 /*
  * 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

 /*
  * Go setup Memory and board specific bits prior to relocation.
  */
 mov ip, lr  /* perserve link reg across call */
 bl platformsetup /* go setup pll,mux,memory */
                           //跳到./board/<boardname>/platform.s中配置RAM控制寄存器,需要根据具体型号的RAM设置
 mov lr, ip  /* restore link */
 mov pc, lr  /* back to my caller */

只有注册用户登录后才能发表评论。