uboot的启动分析1
来源:互联网 发布:阿里云输入法 编辑:程序博客网 时间:2024/05/16 16:02
说明:主要介绍一下uboot的启动过程。通过汇编函数完成底层的初始化,并调用start_armboot进入c语言。
uboot的初始化采用汇编,区别与后面的c语言。一般称为这是uboot的启动第一阶段。uboot参考为韦东山教程中的uboot1.1.6
底阶段的主要函数:
中断向量表
进入管理模式、关闭中断、关闭data ache 与code ache,mmu
将代码拷贝到ram中
设置栈
调用c语言的函数
一、中断向量表
这是arm架构决定的,上电运行直接从0地址运行、当出现各种异常中断后,会进入各自的中断向量地址。.balignl 16表示16字节对齐。
.globl _start_start:b resetldrpc, _undefined_instructionldrpc, _software_interruptldrpc, _prefetch_abortldrpc, _data_abortldrpc, _not_usedldrpc, _irqldrpc, _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
二、进入管理模式、关闭看门狗、关闭中断、设置pll、关闭mmu、关闭cache
进入管理模式设置寄存器(架构要求);
uboot阶段不需要看门狗、中断;
设置pll可用可不用,在后面会对pll重新设置;
关闭MMU、cache。汇编中不需要,采用cache时,有可能回事cpu从cache中读取数据,而不是从外设,导致错误的出现。
reset:/* * set the cpu to SVC32 mode */mrsr0,cpsrbicr0,r0,#0x1forrr0,r0,#0xd3msrcpsr,r0/* turn off the watchdog */#if defined(CONFIG_S3C2400)# define pWTCON0x15300000# define INTMSK0x14400008/* Interupt-Controller base addresses */# define CLKDIVN0x14800014/* clock divisor register */#elif defined(CONFIG_S3C2410)# define pWTCON0x53000000# define INTMSK0x4A000008/* Interupt-Controller base addresses */# define INTSUBMSK0x4A00001C# define CLKDIVN0x4C000014/* clock divisor register */#endif#if defined(CONFIG_S3C2400) || defined(CONFIG_S3C2410)ldr r0, =pWTCONmov r1, #0x0str r1, [r0]/* * mask all IRQs by setting all bits in the INTMR - default */movr1, #0xffffffffldrr0, =INTMSKstrr1, [r0]# if defined(CONFIG_S3C2410)ldrr1, =0x3ffldrr0, =INTSUBMSKstrr1, [r0]# endif/* FCLK:HCLK:PCLK = 1:2:4 *//* default FCLK is 120 MHz ! */ldrr0, =CLKDIVNmovr1, #3strr1, [r0]#endif/* CONFIG_S3C2400 || CONFIG_S3C2410 *//* * we do sys-critical inits only at reboot, * not when booting from ram! */#ifndef CONFIG_SKIP_LOWLEVEL_INITblcpu_init_crit#endif#ifndef CONFIG_SKIP_RELOCATE_UBOOTrelocate:/* relocate U-Boot to RAM */adrr0, _start/* r0 <- current position of code */ldrr1, _TEXT_BASE/* test if we run from flash or RAM */cmp r0, r1 /* don't reloc during debug */beq stack_setupldrr2, _armboot_s三、拷贝程序
将程序从flash中拷贝到ram中,拷贝空间为代码段、数据段、只读数据段、u-boot-cmd段(自定义段)。BSS段不需要拷贝,运行后直接分配空间,并初始化为0.
#ifndef CONFIG_SKIP_RELOCATE_UBOOTrelocate:/* relocate U-Boot to RAM */adrr0, _start/* r0 <- current position of code */ldrr1, _TEXT_BASE/* test if we run from flash or RAM */cmp r0, r1 /* don't reloc during debug */beq stack_setupldrr2, _armboot_startldrr3, _bss_startsubr2, r3, r2/* r2 <- size of armboot */addr2, r0, r2/* r2 <- source end address */copy_loop:ldmiar0!, {r3-r10}/* copy from source address [r0] */stmiar1!, {r3-r10}/* copy to target address [r1] */cmpr0, r2/* until source end addreee [r2] */blecopy_loop#endif
四:设置栈顶。
uboot的代码段放在ram空间的最上端,bss也在ram的最上端,会对bss初始化。
在内存中,uboot下面空间会给堆、全局变量、中断栈等。进而是用户栈,sp的设置如下。
stack_setup:ldrr0, _TEXT_BASE/* upper 128 KiB: relocated uboot */subr0, r0, #CFG_MALLOC_LEN/* malloc area */subr0, r0, #CFG_GBL_DATA_SIZE /* bdinfo */#ifdef CONFIG_USE_IRQsubr0, r0, #(CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ)#endifsubsp, r0, #12/* leave 3 words for abort-stack */clear_bss:ldrr0, _bss_start/* find start of bss segment */ldrr1, _bss_end/* stop here */mov r2, #0x00000000/* clear */clbss_l:strr2, [r0]/* clear loop... */addr0, r0, #4cmpr0, r1bleclbss_l
设置sp后可以调用c函数。
ldrpc, _start_armboot_start_armboot:.word start_armboot
阅读全文
0 0
- uboot的启动分析1
- Uboot启动ARM的start.s分析
- 分析uboot是如何启动内核的
- 分析uboot是如何启动内核的
- 分析uboot是如何启动内核的
- uboot启动内核的流程分析
- 分析uboot是如何启动内核的
- 分析uboot是如何启动内核的
- 分析uboot是如何启动内核的
- 分析uboot是如何启动内核的
- 分析uboot是如何启动内核的
- 分析uboot是如何启动内核的 .
- uboot启动第二阶段详细分析(1)
- uboot源码分析1-启动第一阶段
- 2.5.uboot源码分析1-启动第一阶段
- UBOOT启动过程分析
- uboot 启动流程分析
- Uboot 启动分析
- 带搜索的下拉框
- python网络编程基础
- 根据判断PC浏览器类型和手机屏幕像素自动调用不同CSS的代码
- Java项目转变为Java Web项目
- Python [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed 解决方法【转】
- uboot的启动分析1
- Linux文件操作
- 字典序问题
- mysql数据库sequence使用
- 奥威Power-BI之人力资源管理驾驶舱
- 7、Ping和Traceroute程序
- 第15条:使可变性最小化
- Android自定义View(一) 画线段
- javaScript学习-动态为ul添加li