#include
#include
#if defined(CONFIG_OMAP1610)
#include <./configs/omap1510.h>
#elif defined(CONFIG_OMAP730)
#include <./configs/omap730.h>
#elif defined(CONFIG_HISILICON)
#include
#endif
/*
*************************************************************************
*
* Jump vector table as in table 3.1 in [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
.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 /*应该表示在当前位置定义一个字的变量,变量的内容紧跟其后,.word为GCC汇编伪指令*/
.globl _armboot_start
_armboot_start:
.word _start
.globl _img_end
_img_end:
.word __img_end
/*
* 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
#ifdef CONFIG_HISILICON
_clr_remap_rom_entry:
.word ROM_TEXT_ADRS + do_clr_remap - TEXT_BASE
_clr_remap_nand_entry:
.word NAND_TEXT_ADRS + do_clr_remap - TEXT_BASE
#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
/*
* 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 */
mcr p15, 0, r0, c1, c0, 0
ldr r0, =REG_BASE_SCTL
ldr r1, [r0, #0x8c]
and r1, r1, #0x60
lsr r4, r1, #5 /*以上获取BOOT状态到R4*/
@Check if I need jump to rom
@movs r0, pc, lsr#24 /* Z flag if r0 == 0 then 1 else 0 */
@bne do_clr_remap
mov r0, pc, lsr#24
cmp r0, #0x0
bne do_clr_remap /*检测是否需要跳转,PC的高八位如果不为0(已经在ram中运行了)则跳转*/
cmp r4, #2 /* boot from nand flash*/
ldreq pc, _clr_remap_nand_entry
cmp r4, #0 /* boot from nor flash */
ldreq pc, _clr_remap_rom_entry
do_clr_remap:
ldr r4, =REG_BASE_SCTL
@ldr r0, =REG_VALUE_SC_NOLOCK
@str r0, [r4, #REG_VALUE_SC_LOCKED]
ldr r0, [r4, #REG_SC_CTRL]
@Set clear remap bit.
orr r0, #(1<<8)
str r0, [r4, #REG_SC_CTRL]
@Setup ITCM (ENABLED, 2KB)
ldr r0, =( 1 | (MEM_CONF_ITCM_SIZE<<2) | MEM_BASE_ITCM)
mcr p15, 0, r0, c9, c1, 1 /*以上清除重映射,清除重映射后地址0x000000处安排为ITCM,此处有一个疑问,既然还运行在flash里面那么清重映射后就会运行在ITCM里面,但是ITCM里面保存有代码吗?*/
@enable I-Cache now
mrc p15, 0, r0, c1, c0, 0
orr r0, r0, #0x00001000 /* set bit 12 (I) I-Cache */
mcr p15, 0, r0, c1, c0, 0
@Setup lowlevel sp
ldr sp, =(MEM_BASE_ITCM + MEM_SIZE_ITCM)
@Check if I'm running in static mem bank
mov r0, pc, lsr#28
cmp r0, #(TEXT_BASE>>28)
/*
* Go setup Memory and board specific bits prior to relocation.
*/
beq relocate
bl lowlevel_init /* go setup pll,mux,memory */
#endif
#ifndef CONFIG_SKIP_RELOCATE_UBOOT
relocate: /* relocate U-Boot to RAM */ /* 将U-Boot复制到RAM中 */
ldr r0, =REG_BASE_SCTL
ldr r6, [r0, #0x8c]
and r6, #0x60
lsr r4, r6, #5
adr r0, _start /* r0 <- current position of code r0 = 当前代码的开始地址 */
ldr r1, _TEXT_BASE /* test if we run from flash or RAM r1 = 代码段的连接地址 */
cmp r0, r1 /* don't reloc during debug 测试现在是在Flash中还是在RAM中 */
beq stack_setup /* 如果已经在RAM中(这通常是调试时,直接下载到RAM中), * 则不需要复制 */
ldr r2, _armboot_start /* _armboot_start在前面定义,是第一条指令的运行地址 */
ldr r3, _img_end /* 在连接脚本u-boot.lds中定义,是代码段的结束地址 */
sub r2, r3, r2 /* r2 <- size of armboot */ /* r2 = 代码段长度 */
cmp r4, #2
ldreq r2, =(CFG_NAND_U_BOOT_ONE_PART)
add r2, r0, r2 /* r2 <- source end address */ /* r2 = NOR Flash上代码段的结束地址 */
copy_loop:
ldmia r0!, {r3-r10} /* copy from source address [r0] */ }/* 从地址[r0]处获得数据 */
stmia r1!, {r3-r10} /* copy to target address [r1] 复制到地址[r1]处 */
cmp r0, r2 /* until source end addreee [r2] 判断是否复制完毕 */
ble copy_loop /* 没复制完,则继续 */
#endif /* CONFIG_SKIP_RELOCATE_UBOOT */
/*以上重定位代码,既把代码段复制到ram空间里面*/
/* Set up the stack */
stack_setup:
ldr r0, _TEXT_BASE /* upper 128 KiB: relocated uboot */ /* _TEXT_BASE为代码段的开始地址,值为 */
sub r0, r0, #CFG_MALLOC_LEN /* malloc area 代码段下面,留出一段内存以实现malloc */
sub r0, r0, #CFG_GBL_DATA_SIZE /* bdinfo 再留出一段内存,存一些全局参数 */
#ifdef CONFIG_USE_IRQ
sub r0, r0, #(CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ) /* IRQ、FIQ模式的栈 */
#endif
sub sp, r0, #12 /* leave 3 words for abort-stack 最后,留出12字节的内存给abort异常, * 往下的内存就都是栈了 */
/*以上设置堆栈*/
clear_bss:
ldr r0, _bss_start /* find start of bss segment BSS段的开始地址,它的值在连接脚本u-boot.lds中确定 */
ldr r1, _bss_end /* stop here BSS段的结束地址,它的值在连接脚本u-boot.lds中确定 */
mov r2, #0x00000000 /* clear */
clbss_l:str r2, [r0] /* clear loop... 往BSS段中写入0值 */
add r0, r0, #4
cmp r0, r1
ble clbss_l
/*以上清除BSS*/
ldr pc, _start_armboot
_start_armboot:
.word start_armboot
/*以上跳转到第二段*/
待续……………………