Exynos 4412的启动过程

1. 启动介质

在芯片手册 "Booting Sequence"一节说了Exynos 4412支持从以下设备介质启动:

  • NAND flash memory
  • SD/MMC memory card
  • eMMC memory
  • USB device

友善之臂Tiny4412 支持 SD 卡和 eMMC 两种启动模式,通过 S2 开头来进行切换启动模式。

CPU通过读取OM引脚寻找启动介质。软件可以通过OM寄存器获取当前的启动信息。

 2. 启动顺序

由三星的芯片手册可知 :系统复位时,程序从iROM开始执行。不仅在启动时复位系统,从低功率模式唤醒时也复位系统。因此,bootlod会根据复位状态执行适当的处理。

Exynos 4412启动加载(boot load)过程包含两个启动阶段,这两个阶段区别如下:

  • iROM:是一个启动SOC的小而简单的代码,固化在SOC内部的ROM上。
  • First boot loader (BL1):它是根据特定芯片实现的,存储在外部设备上,有三星提供,没有源码。
  • Second boot loader (BL2):根据特定单板平台实现的,也是存储在外部设备,三星不提供。

  •  iROM:这段代码是固化放置在SOC内部64K 的 iROM 里面,负责初始化基本的系统功能比如时钟和栈。
  • iROM:iROM 从指定启动设备加载 BL1 到内部 256KB 的 SRAM。启动设备通过操作模式(OM) 管脚选择,然后检查BL1的完整性。
  • BL1:BL1是为了解决安全问题,它只初始化芯片本身(不使用外部RAM),会校验下一阶段代码的数字签名,判断代码是否合法(secure boot)。然后又把启动设备上另一个特定位置处的 BL2 程序加载到 iROM 中去运行, 在手册中提到的引导程序只有BL1,但实际上为了区分chip-dependant和platform-dependent,实际的引导程序分为了BL1和BL2。,这里如Friendly的Superboot。
  • BL2:BL2是为了解决iRAM空间较小的问题(iRAM只有256KB),它会初始化外部DRAM,然后将u-boot加载到DRAM中并运行uboot。同样加载的时候也需要校验,这里需要将 uboot.bin 合并进BL2里面。

3.BL1和BL2的存储布局

在SD/MMC卡上的物理存储布局

在片内iRAM上的运行视图布局

 BL1 位于TF卡偏移地址 512字节处(即从第一个扇区开始,前面有一个扇区保留,每个扇区512字节,为什么保留第一个扇区,如果有同学对DOS分区表有过研究,就能明白其中的道理了,第一个扇区是分区表的配置区),iROM从这个位置读入8K 字节的数据,存在iRAM地址 0x02021400位置处。所以 BL1不能大于8K 。

    IROM计算校验和且验证通过后并解密BL1成功后就可以跳转到BL1了,至此IROM已执行完备,权限已交由BL1了,补充说明一下,解密BL1是加密模式启动时才需要的,非加密模式启动是无需解密BL1的。

    BL2 位于 TF 卡偏移地址 (512+8K)字节处,BL1从这个位置读入14K 字节的数据,存在iRAM 地址 0x02023400 处。 BL2 不能大于(14K – 4) 字节,最后 4字节用于存放较验码(在汇编流水灯试验中我们用mkbl2工具制作的BL2,其中mkbl2工具最主要的作用就是计算出校验码)。

如果我们的程序大于 (14K – 4) 字节,那么需要截取前面(14K – 4) 字节用来制作BL2并烧入SD卡偏移地址 (512 +8K) 字节处。当BL2启动后,由它来将存放在TF卡另外位置的、完整程序读入内存。

关于启动介质的存储映像从uboot的SD卡制作脚本(sd_fusing.sh)中也可以看出来,如下:

#<make bl2> 生成BL2
../mkbl2 ../../u-boot.bin bl2.bin 14336

#<BL1 fusing>
dd iflag=dsync oflag=dsync if=./E4412_N.bl1.bin of=$1 seek=1
#<BL2 fusing>
dd iflag=dsync oflag=dsync if=./bl2.bin of=$1 seek=17
#<u-boot fusing>
dd iflag=dsync oflag=dsync if=${E4412_UBOOT} of=$1 seek=49
#<TrustZone S/W fusing>
dd iflag=dsync oflag=dsync if=./E4412_tzsw.bin of=$1 seek=705

#<flush to disk>
sync
echo "U-boot image is fused successfully."
echo "Eject SD card and insert it again."

关于BL1

官方提供了BL1的固件 (E4412_N.bl1.bin)。BL1工作是做一些初始化并将BL2拷贝到片内内存运行。 
IROM代码已经定死,BL1大小只能是8K的代码,BL1可以使用官方提供的,也可以直接写。在官方的描述中,BL2的大小可以用户定义,但是,如果使用了官方的BL1的话,那也就只能按人家说的做,则BL2只能是(14K-4B),后面四个字节用来做校验。通过mkbl2工具(主要是截取代码和计算校验)来制作。

BL1的前16个字节就是提供给IROM用来标识BL1相关信息的,具体信息如下:

/*
* bl1 header infomation for iROM
*
* 0x0 - bl1 size
* 0x4 - reserved (should be 0)
* 0x8 - check sum
* 0xc - reserved (should be 0)
*/
.word 0x2000
.word 0x0
.word 0x0
.word 0x0

关于BL2

在三星给的BL1中指定的BL2最大是14KB - 4B,4B是存放BL2的校验码的,如果BL2不满14KB-4,则空余的地方应该填0。mkblk2是从一个u-boot.bin文件中复制出前14K内容,把前(14*1024-4)=14332字节做个和校验(checksum)得到一个4字节的校验码,再把它放到14332字节之后,输出一个新的14K的二进制文件,命名blk2.bin。

Internal memory of Exynos4212 has been configured as shown in Figure 3-1. The size of the secure BL1 is 8192B. In order to execute iROM properly, 5KB should be reserved at  the start of internal memory. The secure context for BL1 code should be located at  0x0202_3000 of internal memory. The size of BL2 code can be user defined and depends on BL1 code. However, in S.LSI?s reference code of BL1, the valid size of BL2 code  would be less than 14332B 14KB-4B, 4B is the checksum) and if the size of BL2 code is less than 14332B, the rest area up to 14332B should be filled with zeros. The signature for BL2 should be located 0x0202_6C00 of internal memory and the checksum for BL2 should be at 0x0202_6BFC in S.LSI?s reference code. 

但是如果不使用官方的BL1的话,也可以自己写,有很多的灵活性。BL2的长度就可以自己定,或者没有BL2,直接将uboot拷贝到内存运行了,只要BL1不超过8K并能完成你要做的工作就可以,不一定非要用官方的BL1。 但是使用官方的BL1有很多好处,比如制作BL1加头,加校验,加签名等工作就不要做了。所以一般都会使用官方的BL1。

4.片内程序初始化细节

iROM程序流程图:

  • iROM provides the basic environments for executing the arm codes.
  • The secure BL1 is downloaded from the booting devices: SD/MMC, eMMC4.3, eMMC4.4 and NAND.
  • iROM checks the integrity of the downloaded BL1. 

官方BL1执行流程:

è¿éåå¾çæè¿°

  • BL1 code copies the BL2 image to internal RAM and checks the integrity of the BL2 image.
  • BL1 code should be independent of external platform configuration.
  • The secure context data should be attached to the BL1 image and it contains public key for BL2 from set maker.
  • Secure context is generated by CodeSigner Server managed by chip maker. The address of secure context is predefined in the iROM.

BL2执行流程:

  • BL2 code copies the OS image(BL3) to external DRAM area and checks the integrity of OS code.
  • BL2 code configures the operating frequency and DRAM initialization. If there is necessary to configure additional setting to system, the set makers can configure it in the BL2 code.
  • BL2 code is independent of BL1 code. But the address of BL2 signature is fixed in BL1 and the size of BL2 image cannot exceed the BL1 secure context area.

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值