关于bootloader的困惑-请高人指点
我想把UC/OS直接烧到板子里,但实验书里给的那个程序只能通过串口下载进去。我想是不是可以把系统初始化流程中的那个startup.s修改一下,从而达到目的。于是我将原来的startup.s改为如下所示,只是加入了一个中断前的处理代码,并在各个相关部分加入了一些点灯程序,实现调试目的。代码如下:AREA SelfBoot, CODE, READONLY
ENTRY
b ResetEntry
b .
b .
b .
b .
NOP
b irq_handler
b .
; <ResetEntry> here is the very entry for the whoe bootloader
ResetEntry
ldr r0, =0x03FF5000
ldr r1, =0x0003FFFF ; set all 18 gpios' direction to output
str r1,
; ++++++++++++++++++++++++++++++++
; here we light leds to value = "1000" to show bootloader start
ldr r1, =0x00020000
ldr r0, =0x03FF5008
str r1,
ldr r2, =0x2fffff
LOOP0
;mov r2,#1000
sub r2,r2,#1
cmp r2,#0
BNE LOOP0
; ++++++++++++++++++++++++++++++++
b SYS_RST_HANDLER
;**************************************************************************************************
; ASIC Address Definition
; <InitMemory> here we init memory register and setup SDRAM
BASE_ADDR EQU 0x3FF0000
; System Manager Registers
SYSCFG EQU (BASE_ADDR+0x0000)
SDRAM_ITF EQU 0x80000000
SFR_BASE EQU 0x3ff ;0x3ff0000
SRAM_BASE EQU 0x3f8 ;0x3f8<<6
CACHE_ALL EQU 0x10
CACHE_EN EQU 2
CLKCON EQU (BASE_ADDR+0x3000)
EXTACON0 EQU (BASE_ADDR+0x3008)
EXTACON1 EQU (BASE_ADDR+0x300C)
EXTDBWTH EQU (BASE_ADDR+0x3010)
ROMCON0 EQU (BASE_ADDR+0x3014)
InitMemory
; ++++++++++++++++++++++++++++++++
ldr r1, =0x00000010
ldr r0, =0x03FF5008
str r1,
ldr r2, =0x2fffff
LOOP1
;mov r2,#1000
sub r2,r2,#1
cmp r2,#0
BNE LOOP1
ldr r0, =SYSCFG
ldr r1, =SDRAM_ITF :OR: SFR_BASE<<16 :OR: SRAM_BASE<<6 :OR: CACHE_ALL :OR: CACHE_EN
str r1,
;;设置系统时钟控制寄存器的分频因子,FMCLK(内部系统时钟)=FICLK/(CLKCON+1)
ldr r0, =CLKCON
ldr r1, =0
str r1,
;;设置外部I/O访问控制寄存器,控制外部I/O的访问周期
ldr r0, =EXTACON0
ldr r1, =0x0fff0fff
str r1,
ldr r0, =EXTACON1
ldr r1, =0x0fff0fff
str r1,
;;设置数据总线宽度寄存器,可以参见
ldr r0, =EXTDBWTH
ldr r1, =0xffff556
str r1,
;;对各个地址控制寄存器进行配置
adr r0, MemCfgPara
ldmia r0, {r1-r11}
ldr r0, =ROMCON0
stmia r0, {r1-r11}
; ++++++++++++++++++++++++++++++++
ldr r1, =0x00000020
ldr r0, =0x03FF5008
str r1,
ldr r2, =0x2fffff
LOOP2
;mov r2,#1000
sub r2,r2,#1
cmp r2,#0
BNE LOOP2
; ++++++++++++++++++++++++++++++++
mov pc, r14
;**************************************************************************************************
RomBaseAddr EQU 0
RomEndAddr EQU &20
RamBaseAddr EQU &100
RamEndAddr EQU &200
MemCfgPara
DCD RomBaseAddr<<10 :OR: RomEndAddr<<20 :OR: &60 ;&10840060
DCD &10842060
DCD &10842060
DCD &10842060
DCD &10842060
DCD &10842060
DCD RamBaseAddr<<10 :OR: RamEndAddr<<20 :OR: &398 ;&10000398
DCD &10040398
DCD &10040398
DCD &10040398
DCD &ce2983fd
;**************************************************************************************************
; <InitSystem> here we begin to init system
InitSystem
; ++++++++++++++++++++++++++++++++
ldr r1, =0x00000040
ldr r0, =0x03FF5008
str r1,
ldr r2, =0x2fffff
LOOP3
;mov r2,#1000
sub r2,r2,#1
cmp r2,#0
BNE LOOP3
; ++++++++++++++++++++++++++++++++
mov r12, r14
bl InitMemory
mov pc, r12
;**************************************************************************************************
; <RemapMemory> here we begin to remap SDRAM and Flash address
RemapMemory
; ++++++++++++++++++++++++++++++++
ldr r1, =0x0000040
ldr r0, =0x03FF5008
str r1,
ldr r2, =0x2fffff
LOOP4
;mov r2,#1000
sub r2,r2,#1
cmp r2,#0
BNE LOOP4
; ++++++++++++++++++++++++++++++++
adr r0, RemapMemPara
ldmia r0, {r1-r11}
ldr r0, =ROMCON0
stmia r0, {r1-r11}
nop
nop
; ldr r0, =IRQ_SVC_VECTOR
; ldr r1, =IRQ_SERVICE ;IRQ_SVC_VECTOR in ram, so set it after remap
; str r1,
mov pc, r14
RemapMemPara
DCD &12040060
DCD &10842060
DCD &10842060
DCD &10842060
DCD &10842060
DCD &10842060
DCD &10000398
DCD &10040398
DCD &10040398
DCD &10040398
DCD &ce2983fd
;**************************************************************************************************
IMPORT |Image$$RO$$Base| ; ROM code start
IMPORT |Image$$RO$$Limit| ; RAM data starts after ROM program
IMPORT |Image$$RW$$Base| ; Pre-initialised variables
IMPORT |Image$$ZI$$Base| ; uninitialised variables
IMPORT |Image$$ZI$$Limit| ; End of variable RAM space
BaseOfROM DCD |Image$$RO$$Base|
TopOfROM DCD |Image$$RO$$Limit|
BaseOfBSS DCD |Image$$RW$$Base|
BaseOfZero DCD |Image$$ZI$$Base|
EndOfBSS DCD |Image$$ZI$$Limit|
SYS_RST_HANDLER
bl InitSystem
; ++++++++++++++++++++++++++++++++
ldr r1, =0x00020070
ldr r0, =0x03FF5008
str r1,
ldr r2, =0x2fffff
LOOP5
;mov r2,#1000
sub r2,r2,#1
cmp r2,#0
BNE LOOP5
; ++++++++++++++++++++++++++++++++
;将FLASH中程序与数据拷贝到SDRAM
adr r0, ResetEntry
mov r3, #(RamBaseAddr<<16) ;RamBaseAddr=&100,&100<<16==16MB?
ldr r1, BaseOfROM
ldr r2, TopOfROM
add r1, r1, r3
add r2, r2, r3
0 ;将RO段内容拷贝到SDRAM中,32位
ldmia r0!, {r4-r11}
stmia r1!, {r4-r11}
cmp r1, r2
bcc %B0
sub r1, r1, r2
sub r0, r0, r1
ldr r1, BaseOfBSS
ldr r2, BaseOfZero
add r1, r1, r3
add r2, r2, r3
1
cmp r1, r2 ;将RW段内容拷贝到SDRAM ?
ldrcc r4, , #4
strcc r4, , #4
bcc %B1
mov r0, #0
ldr r2, EndOfBSS
add r2, r2, r3
3 ;将ZI段内容拷贝到SDRAM ,并将其值全部初使化为0 ? ZI 段紧跟在RW 后
cmp r1, r2
strcc r0, , #4
bcc %B3
adr r0, ResetEntry
ldr r1, =RemapMemory
ldr r2, BaseOfROM
sub r2, r1, r2
add r0, r0, r2
add r1, r2, r3
mov r2, #32
0
ldr r3, , #4
str r3, , #4
subs r2, r2, #1
bne %B0
;################################
;set up IRQ stack
mov r0,#0xd2
msr cpsr_cxsf,r0
mov sp,#0x70000
;#######################
; Set up SVC stack
mov r0, #0xd3
msr cpsr_cxsf, r0
MOV sp, #0x80000
;###########################
;interrupt special register
;ldr r1,
EXPORT irq_handler
IMPORT do_irq
irq_handler
SUB lr, lr, #4
STMFD sp!, {r0-r12, lr} ; push r0-r12 register file and lr( pc return address )
MRS r4, spsr
STMFD sp!, {r4} ; push current spsr_cxsf_irq ( =cpsr_svc )
BL do_irq
LDMFD sp!, {r4} ; get cpsr_svc from stack
MSR spsr_cxsf, r4 ; prepare spsr_cxsf to return svc mode
LDMFD sp!, {r0-r12, pc}^ ; recover r0-r12 and pc from stack, cpsr also
F_Bit EQU 0x40
Mode_Svc EQU 0x13
MOV r0, #Mode_Svc:OR:F_Bit ; make svc mode with all irqs abled
MSR cpsr_c, r0
ldr lr, GotoMain
b RemapMemory
GBLS MainEntry
MainEntry SETS "main"
IMPORT $MainEntry
GotoMain DCD $MainEntry
;**************************************************************************************************
END
结果是remapmemory里的灯就是不亮,请各位高手帮忙看看问题在哪?
另外,对于以上代码,本人还有以下疑惑,也请高人指点:
1)SYS_RST_HANDLER中的
adr r0, ResetEntry
ldr r1, =RemapMemory
ldr r2, BaseOfROM
sub r2, r1, r2
add r0, r0, r2
add r1, r2, r3
mov r2, #32
0
ldr r3, , #4
str r3, , #4
subs r2, r2, #1
bne %B0
有何作用?
2)程序是如何进入remapmeory里执行的?
3)RomBaseAddr<<10 :OR: RomEndAddr<<20 :OR: &60的值是多少?我看后面的注释里写着;&10840060,我怎么算也不是这个值。
还有一些问题以后再发。 RomBaseAddr<<10 :OR: RomEndAddr<<20 :OR: &60
这种式子的计算在ADS带的pdf里有关于汇编的这些表示,你可以看看 btw: 如果要把 ucos-ii 内核 image 文件烧到 flash 中,可以通过 bootloader 1.6.0的 dn 命令先下载,然后通过 flashw 命令烧写,就能够实现加电后自动启动了。
页:
[1]