U-boot第一个开始文件arch\arm\cpu\arm1176\start.S
start.S文件分析:
/*
*armboot-StartupCodeforARM1176CPU-core
*
*Copyright(c)2007 SamsungElectronics
*
*Copyright(C)2008
*GuennadiLiakhovetki,DENXSoftwareEngineering,<[email protected]>
*
*SeefileCREDITSforlistofpeoplewhocontributedtothis
*project.
*
*Thisprogramisfreesoftware;youcanredistributeitand/or
*modifyitunderthetermsoftheGNUGeneralPublicLicenseas
*publishedbytheFreeSoftwareFoundation;eitherversion2of
*theLicense,or(atyouroption)anylaterversion.
*
*Thisprogramisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE. Seethe
*GNUGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense
*alongwiththisprogram;ifnot,writetotheFreeSoftware
*Foundation,Inc.,59TemplePlace,Suite330,Boston,
*MA02111-1307USA
*
*2007-09-21-Restructuredcodesbyjsgood([email protected])
*2007-09-21-AddedMoviNANDandOneNANDbootcodesby
*jsgood([email protected])
*Basecodesbyscsuh(sc.suh)
*/
#include<config.h>
#include<version.h>
#ifdefCONFIG_ENABLE_MMU
#include<asm/proc/domain.h>
#endif
#if!defined(CONFIG_ENABLE_MMU)&&!defined(CONFIG_SYS_PHY_UBOOT_BASE)
#defineCONFIG_SYS_PHY_UBOOT_BASE CONFIG_SYS_UBOOT_BASE
#endif
/*
*************************************************************************
*
*Jumpvectortableasintable3.1in[1]
*
*************************************************************************
*/
.globl_start
_start:b reset
/*异常向量表,为中断异常作准备*/
/*当异常发生pc会跳到.wrod后面的地址处处理异常*/
#ifndefCONFIG_NAND_SPL
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
/*未定义指令异常,程序从地址0x4处开始执行*/
_undefined_instruction:
.wordundefined_instruction
/*软件中断处理指令,,从0x8处开始执行*/
_software_interrupt:
.wordsoftware_interrupt
/*指令预取中止*/
_prefetch_abort:
.wordprefetch_abort
/*数据访问中止*/
_data_abort:
.worddata_abort
/**/
_not_used:
.wordnot_used
/*外部中断请求*/
_irq:
.wordirq
/*快速中断请求*/
_fiq:
.wordfiq
_pad:
.word0x12345678/*now16*4=64*/
#else
.=_start+64
#endif
.global_end_vect
_end_vect:
.balignl16,0xdeadbeef
/*
*************************************************************************
*
*StartupCode(resetvector)
*
*doimportantinitonlyifwedon'tstartfrommemory!
*setupMemoryandboardspecificbitspriortorelocation.
*relocatearmboottoram
*setupstack
*
*************************************************************************
*/
/*uboot代码的运行地址*/
_TEXT_BASE:
/*uboot程序的运行地址为0xc7e00000
即代码放到我们的sdram中*/
.word TEXT_BASE
/*
*BelowvariableisveryimportantbecauseweuseMMUinU-Boot.
*Withoutit,wecannotruncodecorrectlybeforeMMUisON.
*byscsuh.
*/
/*uboot会开启mmu,以下是开启mmu前uboot存放的真实物理地址
_TEXT_PHY_BASE:
.word CONFIG_SYS_PHY_UBOOT_BASE
/*_start标号和编译时运行的地址有关系,
text_base参数通知编译器程序运行在0xc7e00000
那么标号也是此值
*/
.globl_armboot_start
_armboot_start:
.word_start
/*
*Thesearedefinedintheboard-specificlinkerscript.
*/
/*在u-boot.lds中指定*/
.globl_bss_start
_bss_start:
.word__bss_start
.globl_bss_end
_bss_end:
.word_end
/*
*theactualresetcode
*/
reset:
/*
*setthecputoSVC32mode
*/
/*使cpu的模式为管理模式.即保证cpsr低五位的值为10011*/
mrs r0,cpsr/*r0=cpsr*/
bic r0,r0,#0x3f/*后后6位清零*/
orr r0,r0,#0xd3/*11010011*/
msr cpsr,r0
/*
*************************************************************************
*
*CPU_init_criticalregisters
*
*setupimportantregisters
*setupmemorytiming
*
*************************************************************************
*/
/*
*wedosys-criticalinitsonlyatreboot,
*notwhenbootingfromram!
*/
cpu_init_crit:
/*
*WhenbootingfromNAND-ithasdefinitelybeenareset,so,noneed
*toflushcachesanddisabletheMMU
*/
#ifndefCONFIG_NAND_SPL
/*
*flushv4I/Dcaches
*/
mov r0,#0
mcr p15,0,r0,c7,c7,0 /*flushv3/v4cache*/
mcr p15,0,r0,c8,c7,0 /*flushv4TLB*/
/*
*disableMMUstuffandcaches
*/
mrc p15,0,r0,c1,c0,0
bic r0,r0,#0x00002300 @clearbits13,9:8(--V---RS)
bic r0,r0,#0x00000087 @clearbits7,2:0(B----CAM)/*0为小端,1为大端*/
orr r0,r0,#0x00000002 @setbit2(A)Align/*打开地址对齐检察*/
orr r0,r0,#0x00001000 @setbit12(I)I-Cache/*打开指令缓存*/
/*PreparetodisabletheMMU*/
adr r2,mmu_disable_phys
sub r2,r2,#(CONFIG_SYS_PHY_UBOOT_BASE-TEXT_BASE)
b mmu_disable
.align5
/*Runinasinglecache-line*/
mmu_disable:
mcr p15,0,r0,c1,c0,0
nop
nop
mov pc,r2
mmu_disable_phys:
#ifdefCONFIG_DISABLE_TCM
/*
*DisabletheTCMs
*/
mrc p15,0,r0,c0,c0,2 /*ReturnTCMdetails*/
cmp r0,#0
beq skip_tcmdisable
mov r1,#0
mov r2,#1
tst r0,r2
mcrne p15,0,r1,c9,c1,1 /*DisableInstructionTCMifpresent*/
tst r0,r2,LSL#16
mcrne p15,0,r1,c9,c1,0 /*DisableDataTCMifpresent*/
skip_tcmdisable:
#endif
#endif
#ifdefCONFIG_PERIPORT_REMAP
/*Periportsetup*/
ldr r0,=CONFIG_PERIPORT_BASE
orr r0,r0,#CONFIG_PERIPORT_SIZE
mcr p15,0,r0,c15,c2,4
#endif
/*
*GosetupMemoryandboardspecificbitspriortorelocation.
*/
/*初始化工作:关看门狗、关闭中断、初始化时钟、
nandflash初始化、内存控制器初始化、
*/
bl lowlevel_init /*gosetuppll,mux,memory*/
#ifndefCONFIG_SKIP_RELOCATE_UBOOT
relocate: /*relocateU-BoottoRAM */
adr r0,_start /*r0<-currentpositionofcode*/
ldr r1,_TEXT_BASE /*testifwerunfromflashorRAM*/
cmpr0,r1/*don'trelocduringdebug*/
beqstack_setup
ldr r2,_armboot_start
ldr r3,_bss_start
sub r2,r3,r2 /*r2<-sizeofarmboot*/
add r2,r0,r2 /*r2<-sourceendaddress*/
copy_loop:
ldmia r0!,{r3-r10} /*copyfromsourceaddress[r0]*/
stmia r1!,{r3-r10} /*copytotargetaddress[r1]*/
cmp r0,r2 /*untilsourceendaddreee[r2]*/
ble copy_loop
#endif /*CONFIG_SKIP_RELOCATE_UBOOT*/
#ifdefCONFIG_ENABLE_MMU
enable_mmu:
/*enabledomainaccess*/
ldr r5,=0x0000ffff
mcr p15,0,r5,c3,c0,0 /*loaddomainaccessregister*/
/*SettheTTBregister*/
ldr r0,_mmu_table_base
ldr r1,=CONFIG_SYS_PHY_UBOOT_BASE
ldr r2,=0xfff00000
bic r0,r0,r2
orr r1,r0,r1
mcr p15,0,r1,c2,c0,0
/*EnabletheMMU*/
mrc p15,0,r0,c1,c0,0
orr r0,r0,#1 /*SetCR_MtoenableMMU*/
/*PreparetoenabletheMMU*/
adr r1,skip_hw_init
and r1,r1,#0x3fc
ldr r2,_TEXT_BASE
ldr r3,=0xfff00000
and r2,r2,r3
orr r2,r2,r1
b mmu_enable
.align5
/*Runinasinglecache-line*/
mmu_enable:
mcr p15,0,r0,c1,c0,0
nop
nop
mov pc,r2
skip_hw_init:
#endif
/*Setupthestack */
stack_setup:
ldr r0,=CONFIG_SYS_UBOOT_BASE /*baseofcopyinDRAM */
sub r0,r0,#CONFIG_SYS_MALLOC_LEN /*mallocarea*/
sub r0,r0,#CONFIG_SYS_GBL_DATA_SIZE/*bdinfo*/
sub sp,r0,#12 /*leave3wordsforabort-stack*/
bic sp,sp,#7 /*8-bytealignmentforABIcompliance*/
/*清bss段内容*/
clear_bss:
ldr r0,_bss_start /*findstartofbsssegment*/
ldr r1,_bss_end /*stophere*/
mov r2,#0 /*clear*/
clbss_l:
str r2,[r0] /*clearloop...*/
add r0,r0,#4
cmp r0,r1
ble clbss_l
#ifndefCONFIG_NAND_SPL
ldr pc,_start_armboot
_start_armboot:
.wordstart_armboot
#else
/*checkbootstatus*/
#defineMEM_CFG_STAT0x7E00F12C
ldr r1,=MEM_CFG_STAT /*addressofregMEM_CFG_STAT*/
ldr r0,[r1]
mov r1,#0x60
and r1,r0,r1 /*r1=MEM_CFG_STAT&CFG_BOOT_LOC*/
cmp r1,#0x60 /*InternalROM*/
beq boot_from_irom
cmp r1,#0x00 /*SteppingStoneareainNFCON*/
beq nand_boot
b reset
/* .wordnand_boot*/
boot_from_irom:
b mmc_boot_copy /*MINI6410bootfromInternalROM-->MMCboot*/
#endif
#ifdefCONFIG_ENABLE_MMU
_mmu_table_base:
.wordmmu_table
#endif
#ifndefCONFIG_NAND_SPL
/*
*weassumethatcacheoperationisdonebefore.(eg.cleanup_before_linux())
*actually,wedon'tneedtodoanythingaboutcacheifnotused-cachein
*U-Boot.So,inthisfunctionwecleanonlyMMU.byscsuh
*
*void theLastJump(void*kernel,intarch_num,uintboot_params);
*/
#ifdefCONFIG_ENABLE_MMU
.globltheLastJump
theLastJump:
mov r9,r0
ldr r3,=0xfff00000
ldr r4,_TEXT_PHY_BASE
adr r5,phy_last_jump
bic r5,r5,r3
orr r5,r5,r4
mov pc,r5
phy_last_jump:
/*
*disableMMUstuff
*/
mrc p15,0,r0,c1,c0,0
bic r0,r0,#0x00002300 /*clearbits13,9:8(--V---RS)*/
bic r0,r0,#0x00000087 /*clearbits7,2:0(B----CAM)*/
orr r0,r0,#0x00000002 /*setbit2(A)Align*/
orr r0,r0,#0x00001000 /*setbit12(I)I-Cache*/
mcr p15,0,r0,c1,c0,0
mcr p15,0,r0,c8,c7,0 /*flushv4TLB*/
mov r0,#0
mov pc,r9
#endif
/*
*************************************************************************
*
*Interrupthandling
*
*************************************************************************
*/
@
@IRQstackframe.
@
#defineS_FRAME_SIZE 72
#defineS_OLD_R0 68
#defineS_PSR 64
#defineS_PC 60
#defineS_LR 56
#defineS_SP 52
#defineS_IP 48
#defineS_FP 44
#defineS_R10 40
#defineS_R9 36
#defineS_R8 32
#defineS_R7 28
#defineS_R6 24
#defineS_R5 20
#defineS_R4 16
#defineS_R3 12
#defineS_R2 8
#defineS_R1 4
#defineS_R0 0
#defineMODE_SVC0x13
#defineI_BIT 0x80
/*
*usebad_save_user_regsforabort/prefetch/undef/swi...
*/
.macro bad_save_user_regs
/*carveoutaframeoncurrentuserstack*/
sub sp,sp,#S_FRAME_SIZE
/*Saveuserregisters(nowinsvcmode)r0-r12*/
stmia sp,{r0-r12}
ldr r2,_armboot_start
sub r2,r2,#(CONFIG_SYS_MALLOC_LEN)
/*setbase2wordsintoabortstack*/
sub r2,r2,#(CONFIG_SYS_GBL_DATA_SIZE+8)
/*getvaluesfor"aborted"pcandcpsr(intoparmregs)*/
ldmia r2,{r2-r3}
/*grabpointertooldstack*/
add r0,sp,#S_FRAME_SIZE
add r5,sp,#S_SP
mov r1,lr
/*savesp_SVC,lr_SVC,pc,cpsr*/
stmia r5,{r0-r3}
/*savecurrentstackintor0(paramregister)*/
mov r0,sp
.endm
.macroget_bad_stack
/*setupourmodestack(enterinbankedmode)*/
ldr r13,_armboot_start
/*movepastmallocpool*/
sub r13,r13,#(CONFIG_SYS_MALLOC_LEN)
/*movetoreservedacouplespotsforabortstack*/
sub r13,r13,#(CONFIG_SYS_GBL_DATA_SIZE+8)
/*savecallerlrinposition0ofsavedstack*/
str lr,[r13]
/*getthespsr*/
mrs lr,spsr
/*savespsrinposition1ofsavedstack*/
str lr,[r13,#4]
/*prepareSVC-Mode*/
mov r13,#MODE_SVC
@msr spsr_c,r13
/*switchmodes,makesuremoveswillexecute*/
msr spsr,r13
/*capturereturnpc*/
mov lr,pc
/*jumptonextinstruction&switchmodes.*/
movs pc,lr
.endm
.macroget_bad_stack_swi
/*spaceoncurrentstackforscratchreg.*/
sub r13,r13,#4
/*saveR0'svalue.*/
str r0,[r13]
/*getdataregionsstart*/
ldr r0,_armboot_start
/*movepastmallocpool*/
sub r0,r0,#(CONFIG_SYS_MALLOC_LEN)
/*movepastgblandacouplespotsforabortstack*/
sub r0,r0,#(CONFIG_SYS_GBL_DATA_SIZE+8)
/*savecallerlrinposition0ofsavedstack*/
str lr,[r0]
/*getthespsr*/
mrs r0,spsr
/*savespsrinposition1ofsavedstack*/
str lr,[r0,#4]
/*restorer0*/
ldr r0,[r13]
/*popstackentry*/
add r13,r13,#4
.endm
/*
*exceptionhandlers
*/
.align 5
undefined_instruction:
get_bad_stack
bad_save_user_regs
bl do_undefined_instruction
.align 5
software_interrupt:
get_bad_stack_swi
bad_save_user_regs
bl do_software_interrupt
.align 5
prefetch_abort:
get_bad_stack
bad_save_user_regs
bl do_prefetch_abort
.align 5
data_abort:
get_bad_stack
bad_save_user_regs
bl do_data_abort
.align 5
not_used:
get_bad_stack
bad_save_user_regs
bl do_not_used
.align 5
irq:
get_bad_stack
bad_save_user_regs
bl do_irq
.align 5
fiq:
get_bad_stack
bad_save_user_regs
bl do_fiq
#endif/*CONFIG_NAND_SPL*/
链接地址:\board\samsung\mini6410\u-boot-nand.lds
程序的一般步骤:
1初始化:关看门狗
初始化时钟
初始化sdram
2把程序从nandflash拷贝到sdram
3设置sp