(二)u-boot启动流程分析(汇编部分)
来源:互联网 发布:淘宝上买电视可靠吗 编辑:程序博客网 时间:2024/05/16 09:26
下面的代码基于amlogic的SDK的code示例。
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
阅读全文
0 0
- (二)u-boot启动流程分析(汇编部分)
- u-boot移植(一)---u-boot启动流程分析
- (一)u-boot启动流程分析
- (三)u-boot启动流程分析(C语言部分board_f.c)
- (四)u-boot启动流程分析(C语言部分board_r.c)
- U-boot启动流程分析 Start.s 汇编文件
- u-boot启动流程分析(1)_平台相关部分
- u-boot启动流程分析(2)_板级(board)部分
- u-boot启动流程分析(1)_平台相关部分
- u-boot启动流程分析(2)_板级(board)部分
- U-Boot启动流程(Linux内核)的分析(二转)
- u-boot分析(二)-----工作流程分析
- U-Boot启动流程(Linux内核)的分析
- U-Boot启动流程(Linux内核)的分析
- u-boot移植启动流程详细分析(2)
- u-boot启动流程分析
- u-boot启动流程分析
- u-boot启动流程分析
- Map集合day_16
- 一些想法(17.11.23)
- Android本地音乐播放器
- 为selenium配置webdriver
- 在JavaScript中typeof的用途介绍
- (二)u-boot启动流程分析(汇编部分)
- MQ消息序列化失败排查
- poj2528线段树+数据离散化
- Linux安装Mysql
- OpenCV 下载驿站(百度云盘下载,同步更新)
- 逆 向入 门
- 【Scikit-Learn 中文文档】多类和多标签算法
- Android日志工具Log
- python: TODO 助记符