马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 john-rgt 于 2017-6-21 14:38 编辑
Bootloader在嵌入式Linux系统中,起到助推作用,在内核运行之前,先对各个硬件进行初始化,建立一个空间系统蓝图(映射图),说白了,就好比盖楼,在修楼之前得打好地基,才能进行下一步操作。
本人现在也是小白菜,观点不一定对,勿喷
在学习bootloader之前,我先对它的大概的框架进行了了解,大致架构看图;
今天我先说一下,第一个初始化前四步。
1.异常向量表
何为异常:Exceptions are generated by internal and external sources to cause the processor to handle an event, such as an externally generated interrupt or an attempt to execute an Undefined instruction. The processor state just before handling the exception is normally preserved so that the original program can be resumed when the
exception routine has completed. More than one exception can arise at the same time.(这里可以练练大家的英语能力 ,试着翻译哈哈)
而异常向量表就是由7个异常向量及其函数跳转关系组成的表,具体的看ARM手册。
2.设置处理器模式为SVC模式
3.关闭看门狗
WATCHDOG:The S3C2440A watchdog timer is used to resume the controller operation whenever it is disturbed by malfunctions
such as noise and system errors. It can be used as a normal 16-bit interval timer to request interrupt service. The
watchdog timer generates the reset signal for 128 PCLK cycles.
4.关闭中断
The interrupt controller in the S3C2440A receives the request from 60 interrupt sources. These interrupt sources are
provided by internal peripherals such as DMA controller, UART, IIC, and others. In these interrupt sources, the
UARTn, AC97 and EINTn interrupts are 'OR'ed to the interrupt controller.
启动代码:
- .text
- .global _start
- _start:
- b reset
- ldr pc,_undefined_instruction
- ldr pc,_software_interrupt
- ldr pc,_prefetch_abort
- ldr pc,_data_used
- 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_used: .word data_used
- _not_used: .word not_used
- _irq: .word irq
- _fiq: .word fiq
- _reset: .word reset
- undefined_instruction:
- nop
- software_interrupt:
- nop
- prefetch_abort:
- nop
- data_used:
- nop
- not_used:
- nop
- irq:
- nop
- fiq:
- nop
- reset:
- bl set_svc
- bl disable_watchdog
- bl disable_interrupt
- set_svc:
- mrs r0,cpsr
- bic r0,r0,#0x1f
- orr r0,r0,#0xd3
- msr cpsr,r0
- #define pWTCON 0X53000000
- disable_watchdog:
- ldr r0,=pWTCON
- mov r1,#0x0]
- str r1,[r0]
- disable_interrupt:
- mvn r1,#0x0
- ldr r0,#0x4a000008
- str r1,[r0]
复制代码
链接脚本:
- OUTPUT_ARCH(arm)
- ENTRY(_start)
- SECTIONS{
- . = 0x30000000;
- . = ALIGN(4);
- .text :
- {
- start.o(.text)
- *(.text)
- }
- . = ALIGN(4);
- .data :
- {
- *(.data)
- }
- . = ALIGN(4);
- bss_start = .;
- .bss :
- {
- *(.bss)
- }
- bss_end = .;
- }
复制代码
Makefile:
- all : start.o
- arm-linux-ld -Tgboot.lds -o gboot.elf $^
- arm-linux-objcopy -O binary gboot.elf gboot.bin
- %.o : %.S
- arm-linux-gcc -g -c $^
- %.o : %.c
- arm-linux-gcc -g -c $^
复制代码 |