大家好,欢迎来到IT知识分享网。
一、bl1是什么?
bootloader 1简称bl1,通常bl1就是存放在bootrom中的代码,CPU上电解复位后,会从0地址(具体启动地址,要看每个cpu自己的特性,一般是从0地址启动)取指令运行,所以一般bootrom的地址就是从0地址开始分布,将bl1放在bootrom中,并通过ld文件制定代码入口地址,就可以运行bl1的代码了。
二、bl1的主要作用
bl1是存放在rom中的代码,rom空间都比较小,通常64K或128K,因此对bl1镜像文件就存在大小限制。但bl1要实现加载bl2的作用,因此下述这些功能是必须的:
1. 初始化CPU相关;
2. 初始化基本外设(串口输出、存储设备读写。。。);
3. 从flash上读取bl2至ram;
4. 设置上下文,跳转至bl2入口;
三、代码分析
1. bl1入口
ENTRY(bl1_entrypoint)
从bl1的链接文件(bl1.ls.S)中可以知道bl1的代码入口是bl1_entrypoint,bl1_entrypoint定义在bl1_entrypoint.S中。
func bl1_entrypoint /* --------------------------------------------------------------------- * If the reset address is programmable then bl1_entrypoint() is * executed only on the cold boot path. Therefore, we can skip the warm * boot mailbox mechanism. * --------------------------------------------------------------------- */ el3_entrypoint_common \ _init_sctlr=1 \ _warm_boot_mailbox=!PROGRAMMABLE_RESET_ADDRESS \ _secondary_cold_boot=!COLD_BOOT_SINGLE_CPU \ _init_memory=1 \ _init_c_runtime=1 \ _exception_vectors=bl1_vector_table \ _pie_fixup_size=0 /* ----------------------------------------------------- * Perform BL1 setup * ----------------------------------------------------- */ bl bl1_setup /* ----------------------------------------------------- * Jump to main function. * ----------------------------------------------------- */ bl bl1_main /* ----------------------------------------------------- * Jump to next image. * ----------------------------------------------------- */ /* * Get the smc_context for next BL image, * program the gp/system registers and save it in `r4`. */ bl smc_get_next_ctx mov r4, r0 /* Only turn-off MMU if going to secure world */ ldr r5, [r4, #SMC_CTX_SCR] tst r5, #SCR_NS_BIT bne skip_mmu_off /* * MMU needs to be disabled because both BL1 and BL2/BL2U execute * in PL1, and therefore share the same address space. * BL2/BL2U will initialize the address space according to its * own requirement. */ bl disable_mmu_icache_secure stcopr r0, TLBIALL dsb sy isb skip_mmu_off: /* Restore smc_context from `r4` and exit secure monitor mode. */ mov r0, r4 monitor_exit endfunc bl1_entrypoint
bl1_entrypoint->bl1_setup->bl1_main
对上述代码主要流程整理,就可以得到简化的流程,从简化流程也可以看出,bl1_setup负责对bl1阶段需要用到的环境进行设置,包括对时钟、基本外设的配置;而bl1_main主要实现下一阶段文件的加载,以及如何跳到下一阶段代码去执行的流程。从这点来看,代码逻辑还是比较清晰的。
由于ATF支持的平台较多,相同的函数在很多文件中都有定义,因此需要选择一个平台来分析代码,其他平台的代码基本上都大同小异。这里我们以海思的hikey平台为例进行代码分析。
完整的代码框架图可在以下地址进行下载:
ATF_BL1.xmind-Linux文档类资源-CSDN下载
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/114865.html





