[000-u-boot-Exynos4412] RP4412 IROM Booting

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/pengfei240/article/details/75308150

0. 前言

本文以Exynos4412芯片为例,介绍了CPU的启动过程。

1. 启动介质

Exynos 4412可以选择下列启动介质:

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

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

2. 启动顺序

由手册“5 Booting Sequence”的描述可知,Exynos 4412内部拥有64K-iROM和256KB-iRAM用于系统启动,其上电复位的流程如下:

步骤1 执行内部只读存储器iROM中的代码(该代码由厂家固化在CPU内部)。初始化一些系统的基本配置,比如初始化时钟、iRAM上的堆栈。然后根据启动模式,将BL1(由厂家提供二进制文件)从外部存储器拷贝到iRAM中,并校验BL1的完整性。

步骤2 执行内部iRAM中的代码,初始化系统时钟和DRAM控制器,将Firmware/OS镜像拷贝到内存中。并校验镜像文件的完整性。

步骤3 跳转到Firmware/OS中执行。

注意:在手册中提到的引导程序只有BL1,但实际上为了区分chip-dependant和platform-dependent,实际的引导程序分为了BL1和BL2。两者的主要功能如下:

  • BL1是为了解决安全问题,它只初始化芯片本身(不使用外部RAM),会校验下一阶段代码的数字签名,判断代码是否合法(secure boot)。
  • BL2是为了解决iRAM空间较小的问题(iRAM只有256KB),它会初始化外部DRAM,并将用户的启动代码(u-boot)完整搬运到DRAM中。

iROM flow

iROM内部的代码是由厂家固化在iROM中(被称为Initial Program Loader,IPL)。

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

BL1 flow

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

BL2 flow

  1. BL2 code copies the OS image(BL3) to external DRAM area and checks the integrity of OS code.
  2. 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.
  3. 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.

3. 内存映射

  1. SRAM的起始地址开始5KB是为iROM预留的。
  2. BL1的大小是8KB,BL1代码安全上下文存储在0x0202_3000的位置。
  3. 在三星给的BL1中指定的BL2最大是14KB - 4B,4B是存放BL2的校验码的,如果BL2不满14KB-4,则空余的地方应该填0,BL2的签名位于0x0202_6C00,校验值位于0x0202_6BFC。
  4. 0x0202_0030 到 0x0202_0070这些地址为iROM功能的入口地址,包括镜像拷贝,校验等功能。

4. 存储器映射

Exynos 4412的启动介质有很多,在这以SD卡为例,列出它的存储器映射。

  • Block0:Reserved
  • Block1 ~Block16:BL1 + Signature
  • Block17 ~ Block48:BL2 + Signature

5. SDK提供的制作工具

在SDK中,我们使用的是sd_fuse/smdk5250/sd_fusing.sh制作启动脚本,BL1使用的是SDK提供的默认镜像。但这里有两个问题:

  1. SDK默认提供的BL1的镜像有15.5K,远远大于文档中描述的8K大小。
  2. BL2是从u-boot中分离出来的,每次编译出来的校验和应该不一样,但是我们却没有修改BL1中的校验和。

于是我们分析BL1的镜像文件,发现:

  • 0x0000 ~ 0x1643 有数据
  • 0x1644 ~ 0x1FFF 尾部有一组时间戳,其它位置全0
  • 0x2000 ~ 0x379B 有数据
  • 0X379C ~ 0x3BFF 全0

在此,我们猜测SDK中BL1镜像其实已经包含了三星提供的BL1(0x000 ~ 0x1FFF)和BL2(0x2000 ~ 0x3BFF),而从u-boot分离出来的BL2实际上已经是BL3了,这样做可以保证在开发阶段绕过安全的相关问题,不需要频繁修改BL1。

对应于这个变化,SD卡的分区也应该会有相应的变化,这在sd_fusing.sh中可以看见:

signed_bl1_position=1
bl2_position=31
uboot_position=63
tzsw_position=719

猜你喜欢

转载自blog.csdn.net/pengfei240/article/details/75308150
今日推荐