(二)u-boot启动流程分析(汇编部分)

来源:互联网 发布:淘宝上买电视可靠吗 编辑:程序博客网 时间:2024/05/16 09:26

下面的代码基于amlogicSDKcode示例。

start.S为整个u-boot的入口

start.S arch\arm\cpu\armv8\start.S

#include <asm-offsets.h>#include <config.h>#include <version.h>#include <linux/linkage.h>#include <asm/macro.h>#include <asm/armv8/mmu.h>/************************************************************************* * * Startup Code (reset vector) * *************************************************************************/.globl_start_start:breset.align 3.globl_TEXT_BASE_TEXT_BASE:.quadCONFIG_SYS_TEXT_BASE/* * These are defined in the linker script. */.globl_end_ofs_end_ofs:.quad_end - _start.globl_bss_start_ofs_bss_start_ofs:.quad__bss_start - _start.globl_bss_end_ofs_bss_end_ofs:.quad__bss_end - _startreset:/* * Could be EL3/EL2/EL1, Initial State: * Little Endian, MMU Disabled, i/dCache Disabled */adrx0, vectorsswitch_el x1, 3f, 2f, 1f3:msrvbar_el3, x0mrsx0, scr_el3orrx0, x0, #0xf/* SCR_EL3.NS|IRQ|FIQ|EA */msrscr_el3, x0msrcptr_el3, xzr/* Enable FP/SIMD */ldrx0, =COUNTER_FREQUENCYmsrcntfrq_el0, x0/* Initialize CNTFRQ */b0f2:msrvbar_el2, x0movx0, #0x33ffmsrcptr_el2, x0/* Enable FP/SIMD */b0f1:msrvbar_el1, x0movx0, #3 << 20msrcpacr_el1, x0/* Enable FP/SIMD */0:/* * Cache/BPB/TLB Invalidate * i-cache is invalidated before enabled in icache_enable() * tlb is invalidated before mmu is enabled in dcache_enable() * d-cache is invalidated before enabled in dcache_enable() *//* Processor specific initialization */bllowlevel_initbranch_if_master x0, x1, master_cpu/* * Slave CPUs */slave_cpu:wfeldrx1, =CPU_RELEASE_ADDRldrx0, [x1]cbzx0, slave_cpubrx0/* branch to the given address *//* * Master CPU */master_cpu:bl_main

主要的流程如下:

(1)根据当前的EL级别,配置中断向量、MMU、Endian、i/d Cache等。

(2)配置ARM的勘误表,具体可参考apply_core_errata函数。

(3)调用lowlevel_init。

(4)如果是多CPU的场景,处理其它的CPU的boot。

(5)跳转到arm公共的_main中执行。


跳转到crt0_64.S(arch\arm\lib\crt0_64.S)中:

#include <config.h>#include <asm-offsets.h>#include <asm/macro.h>#include <linux/linkage.h>ENTRY(_main)/* * Set up initial C runtime environment and call board_init_f(0). */ldrx0, =(CONFIG_SYS_INIT_SP_ADDR)subx0, x0, #GD_SIZE/* allocate one GD above SP */bicsp, x0, #0xf/* 16-byte alignment for ABI compliance */movx18, sp/* GD is above SP */movx0, #0blboard_init_f/* * Set up intermediate environment (new sp and gd) and call * relocate_code(addr_moni). Trick here is that we'll return * 'here' but relocated. */ldrx0, [x18, #GD_START_ADDR_SP]/* x0 <- gd->start_addr_sp */bicsp, x0, #0xf/* 16-byte alignment for ABI compliance */ldrx18, [x18, #GD_BD]/* x18 <- gd->bd */subx18, x18, #GD_SIZE/* new GD is below bd */adrlr, relocation_returnldrx9, [x18, #GD_RELOC_OFF]/* x9 <- gd->reloc_off */addlr, lr, x9/* new return address after relocation */ldrx0, [x18, #GD_RELOCADDR]/* x0 <- gd->relocaddr */brelocate_coderelocation_return:/* * Set up final (full) environment */blc_runtime_cpu_setup/* still call old routine *//* * Clear BSS section */ldrx0, =__bss_start/* this is auto-relocated! */ldrx1, =__bss_end/* this is auto-relocated! */movx2, #0clear_loop:strx2, [x0]addx0, x0, #8cmpx0, x1b.loclear_loop/* call board_init_r(gd_t *id, ulong dest_addr) */movx0, x18/* gd_t */ldrx1, [x18, #GD_RELOCADDR]/* dest_addr */bboard_init_r/* PC relative jump *//* NOTREACHED - board_init_r() does not return */ENDPROC(_main)

主要流程如下(源码注释翻译):

(1)设置board_init_f()初始化环境。

(2)调用board_init_f()。

如果是非SPL,则执行(3)-(6)

(3)设置board_init_f()在系统内存中分配的堆栈和GD中间环境,BSS 和非常量数据任然不可用。

(4)调用relocate_code()。

(5)设置calling board_init_r()调用环境。

(6)调用calling board_init_r()。


后续board_init_f()及board_init_r()都是C语言实现了,汇编部分到此为止,喜欢深入研究的可以多了解,下节我们分析C语言实现部分,也是我们日常经常需要修改的地方。

参考:

http://www.wowotech.net/u-boot/boot_flow_1.html

https://www.2cto.com/kf/201607/527936.html


原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 高铁喷雾扣留后怎么办 高铁没收的东西怎么办 安检被收的东西怎么办 我的律师骗我怎么办 没婆婆生了小孩怎么办 没人帮你带孩子怎么办 亲戚在家里不走怎么办 穷人家的孩子该怎么办 空腹吃李子胃疼怎么办 情侣空间农场谷仓空间不够怎么办 王者荣耀情侣解除对方不同意怎么办 oppo手机进了水怎么办 淘宝卖号被骗了怎么办 淘宝买号被骗了怎么办 后脑偏头疼怎么办最快最有效 脸两边的骨头大怎么办 做b超胎儿老盘腿怎么办 裤子白边染色了怎么办 异地恋要分手了怎么办 异地恋没话题了怎么办 陪婆婆聊天心情超级郁闷怎么办? 他不想理你了怎么办 陌陌看到信息不回怎么办 qq的文档看不了怎么办 怀孕了分手了怎么办啊 qq节日祝福关了怎么办 微信欠款不还怎么办 qq文件记录删除了怎么办 qq漫游记录删了怎么办 换了新手机微信怎么办 新手机了微信怎么办 微信收藏空间已满怎么办 微信收藏空间满了怎么办 qq步数上传不了怎么办 qq发送的文件失效了怎么办 苹果手机微信数据损坏怎么办 微信文件被清理怎么办 老婆与别人聊暧昧话题怎么办 微信不小心删了聊天记录怎么办 当聊天没话题了怎么办 老婆和别人频繁聊天老公怎么办