RK3399 系列 啟動檔案 Bootrom

重要參考範例 移植U-Boot思路和实践 | 基于RK3399

Boot option

Boot option翻譯 

Boot flow

芯片上电解复位之后执行的第一段程序,在芯片中称之为Bootrom loader。这部分程序在芯片制造过程中固化到其内部的ROM空间,具备只读属性,在实际使用过程中无法修改这部分内容,这部分程序的知识产权也仅归属于芯片公司所有。其实,你也可以将Bootrom loader称之为固件。

对于ARM架构的处理器而言,芯片上电解复位后的PC通常是指向0x000000000xffff0000地址,也就是说,它会去该地址处取第一条指令、译码、执行。CPU能支持的启动模式通过硬件拨码的方式告知CPU,CPU上电解复位后内部逻辑会识别bootmode依据识别出的bootmode决定去何处取第一条指令。假设解析bootmode后发现并不是从bootrom启动,而是从其他存储外设启动,例如norflashnandflashqspiflash等,这些外设就会变为CPU的一级启动设备,而CPU内部逻辑也会将这些启动外设的地址空间进行remap处理。

RK3399内部包含4个ARM cortex-A53以及2个cortex-A72,典型的cluster结构,cortex-A53作为小核而cortex-A72作为大核。当系统上电解复位之后,cortex-A53的core0作为第一个启动的核心,执行0xffff0000处的Bootrom loader程序

RK3399的二级启动设备支持SPI NOR FLASHSPI NAND FLASHeMMCSD以及USB load,可以将二级启动程序放置于上述静态存储设备中,RK3399通过读取ID BLOCK信息决定当前启动程序是否有效。

參考 CPU上电后加载程序的流程 | 基于RK3399

- use U-Boot TPL/SPL from upsream or rockchip U-Boot, fully source code;

TPL/SPL在 u-boot source code

- use Rockchp idbLoader which is combinded by Rockchip ddr init bin and miniloader bin from Rockchip rkbin project;

+--------+----------------+----------+-------------+---------+
| Boot   | Terminology #1 | Actual   | Rockchip    | Image   |
| stage  |                | program  |  Image      | Location|
| number |                | name     |   Name      | (sector)|
+--------+----------------+----------+-------------+---------+
| 1      |  Primary       | ROM code | BootRom     |         |
|        |  Program       |          |             |         |
|        |  Loader        |          |             |         |
|        |                |          |             |         |
| 2      |  Secondary     | U-Boot   |idbloader.img| 0x40    | pre-loader
|        |  Program       | TPL/SPL  |             |         |
|        |  Loader (SPL)  |          |             |         |
|        |                |          |             |         |
| 3      |  -             | U-Boot   | u-boot.itb  | 0x4000  | including u-boot and atf
|        |                |          | uboot.img   |         |only used with miniloader
|        |                |          |             |         |
|        |                | ATF/TEE  | trust.img   | 0x6000  |only used with miniloader
|        |                |          |             |         |
| 4      |  -             | kernel   | boot.img    | 0x8000  |
|        |                |          |             |         |
| 5      |  -             | rootfs   | rootfs.img  | 0x40000 |
+--------+----------------+----------+-------------+---------+

Boot option - Rockchip open source Document

 Rockchip_RK3399TRM_V1.4_Part1-20170408.pdf

TWO FLOW

Boot Flow 1 是典型的使用 Rockchip miniloader 的 Rockchip 启动流程;

Boot Flow 2 用于大多数 SOCs,U-Boot TPL 用于 ddr 初始化,SPL用于 trust(ATF/OP-TEE)加载并运行到下一阶段;

 打包选项

在我们知道启动阶段之后,

以下是第2~4阶段打包前的文件列表:

  • 源代码:
    • u-boot:u-boot-spl.binu-boot.bin(可使用 u-boot-nodtb.bin 和 u-boot.dtb 代替)
    • kernel:kernel Image/zImage 文件、kernel dtb,
    • ATF:bl31.elf
  • Rockchip binary:
    • ddr、usbplug、miniloader、bl31/op-tee(均带有“rkxx_”前缀和“_x.xx.bin”版本后缀);

您可以使用以下方法获取 idbloader。

1)从 Rockchip release loader 获取用于 eMMC 的 idbloader

对于eMMC,不需要打包 idbloader.img 文件,如果您使用的是 Rockchip release loader,则可以使用以下命令在 eMMC 上获取 idbloader:

  1. rkdeveloptool db rkxx_loader_vx.xx.bin

  2. rkdeveloptool ul rkxx_loader_vx.xx.bin

2)打包 idbloader.img 文件来自 Rockchip binary:

对于SD boot 或 eMMC(使用 rockusb wl 命令更新),您需要一个idbloader(与 ddr 和 miniloader 结合使用)。

  1. tools/mkimage -n rkxxxx -T rksd -d rkxx_ddr_vx.xx.bin idbloader.img

  2. cat rkxx_miniloader_vx.xx.bin >> idbloader.img

打包 idbloader.img 文件从 U-Boot TPL/SPL(它们完全开源):

  1. tools/mkimage -n rkxxxx -T rksd -d tpl/u-boot-tpl.bin idbloader.img

  2. cat spl/u-boot-spl.bin >> idbloader.img

Rockchip | 启动引导的各个阶段及其对应固件_Neutionwei的博客-CSDN博客

Boot option - Rockchip open source Document

Rockchip Platform啟動流程 MASKROM----> TPL ---> SPL ----> U-Boot / optee ----> Linux kernel ----> rootfs(buildroot/yocto/debian)--> others partitions[oem, userdata]

為芯片固化的loader,也可以理解為bootrom,芯片tapeout後無法更改。

RK不同芯片MASKROM 支持Flash啟動順序不一樣,一般都支持SD卡、U盤、eMMC、SPI Flash、NandC Flash

分區介紹(parmater)

TPL(Third Program Loader) 為U-Boot upstream的概念,主要用來初始化DDR,在RK平台也可以理解為DDR.bin

SPL(secondary program loader) -為U-Boot upstream的概念,主要是用來做較為前級的板級初始化,以及加載U-Boot。

SPL存在的 意義在於部分芯片固化的bootrom無法加載太大的鏡像,你也可以將SPL理解為tiny U-Boot。在RK 平台,通常將TPL和SPL合併為一個miniloader

U-Boot(不在贅訴) U-Boot社區較早引入DM及FDT的概念,所以在U-Boot的驅動都是基於DM框架進行編寫,且包含 dts的功能。官方引入CONFIG_OF_LIVE的功能,可以講Kernel的dtb overlay到u-boot,對於RK平 台(4.4內核以上版本開始支持),導入u-boot官方源碼(對應分支為next-dev)。

u-boot源碼同 時也包含TPL、SPL。 U-Boot此外還有一個功能,加載後級鏡像。通過misc分區標誌位判斷下級鏡像

1. Normal (kernel+rootfs)

2. Recovery (kernel+ramdisk)用於OTA升級 optee 也稱trust/ATF。

對於ARMV8實際上才開始引入ATF的概念,但是由於ARMV7也有安全總線的概念,為 了訪問安全,在ARMV7也引入了trust。 RK平台Kernel態只能訪問非安全總線,需要訪問安全總線需調 用smc call 到ATF階段處理。

Kernel RK平台目前Kernel支持4個大版本:3.10、4.4、4.19、5.10 ROOTFS 官方默認支持buildroot、yocto、debian。 Ubuntu社區要求使用snap構建嵌入式鏡像,RK沒有支持snap,有lincense要求,對此RK對外不支持ubuntu系統。 RK Linux SDK默認使用buildroot構建。

===================================================================

整理

1.Primary Program Loader,

ROM code, BootRom 
芯片制造过程中固化到其内部的ROM空间,具备只读属性

2.Secondary Program Loader (SPL),

U-Boot TPL/SPL, idbloader.img, 0x40 pre-loader 

TPL(Tiny Program Loader)和 SPL(Secondary Program Loader)是比 U-Boot 更早阶段的
bootloader,
TPL:运行在 sram 中,负责完成 ddr 初始化;
SPL:运行在 ddr 中,负责完成系统的 lowlevel 初始化、后级固件加载trust.img 和
          uboot.img);

启动流程:

BOOTROM => TPL(ddr bin) => SPL(miniloader) => TRUST => U-BOOT => KERNEL

TPL 相当于 ddr bin,SPL 相当于 miniloader,所以

SPL+TPL 的组合实现了跟 Rockchip  ddr.bin + miniloader 完全一致的功能,可相互替换。

idbloader.img編譯

Boot flow1

(1)Package the idbloader.img from Rockchip binary:

For SD boot or eMMC(update with rockusb wl cmd), you need a idbloader(combinded with ddr and miniloader) .对于SD boot 或 eMMC(使用 rockusb wl 命令更新)

tools/mkimage -n rkxxxx -T rksd -d rkxx_ddr_vx.xx.bin idbloader.img
cat rkxx_miniloader_vx.xx.bin >> idbloader.img

rkbin/bin/rk33/rk3399_ddr_800MHz_v1.24.bin + rkbin/bin/rk33/rk3399_miniloader_v1.24.bin

Boot flow2

(2)Package the idbloader.img from U-Boot TPL/SPL(which is fully open source):

tools/mkimage -n rkxxxx -T rksd -d tpl/u-boot-tpl.bin idbloader.img
cat spl/u-boot-spl.bin >> idbloader.img

load1  idbloader.img 燒錄位置 0x40

3.U-Boot , u-boot.itb  uboot.img ,

   0x4000 ,  including u-boot and ATF  only used with miniloader

Boot flow1

uboot.img

tools/loaderimage --pack --uboot u-boot.bin uboot.img $SYS_TEXT_BASE

./tools/loaderimage --pack --uboot [input bin] [output image] [load_addr]
<output size>
Example :
./tools/loaderimage --pack --uboot ./u-boot.bin uboot.img 0x60000000 --size 1024

Boot flow2

u-boot.itb // SPL itb

./make.sh itb // 打包u-boot.itb(64位平台只支持打包ATF和U-Boot,OP-TEE不打包)

64 位平台:ATF 是 ARMv8 必需的,OP-TEE 是可选项;32 位平台:只有 OP-TEE;

make.sh :    cp ${RKBIN}/${bl31} bl31.elf
                     make CROSS_COMPILE=${TOOLCHAIN_GCC} u-boot.itb
 

./make.sh itb  =  make u-boot.itb

 

spl / u-boot-spl.bin和u-boot.itb

load2 uboot.img / u-boot.itb燒錄位置 0x4000

3.1Trust    ATF/TEE | trust.img | 0x6000

使用 Rockchip miniloader 的 idbloader 时,需要使用 Rockchip tool trustmerge 将 bl31.bin 打包成可加载的 miniloader 格式。

Boot flow1

tools/trustmerge tools/rk_tools/RKTRUST_RKXXXXTRUST.ini

./tools/trust_merger --rsa 3 --sha 2 ./ RKTRUST/RK3399TRUST.ini

rkbin/RKTRUST/RK3399TRUST.ini

rkbin/bin/rk33/rk3399_bl31_v1.32.elf
rkbin/bin/rk33/rk3399_bl32_v1.21.bin

trust.img燒錄位置 0x6000

4. kernel ,boot.img ,  0x8000

The output will be as below, boot.img is ramdisk with rockchip header, kernel is zImage/Image with rockchip header, resource is dtb and boot logo with rockchip header.

此 image 将 kernel Image 和 dtb 文件打包到已知的文件系统(FAT 或 EXT2)image 中,以便进行启动发行版。

有关从 kernel zImage/Image、dtb 生成 boot.img 的详细信息,请参见的 Install kernel 。

kernel/
├── boot.img
├── kernel.img
└── resource.img

5. rootfs ,rootfs.img , 0x40000

rootfs.img

Flash the rootfs.img to offset 0x40000 which is stage 5. As long as the kernel you chosen can support that filesystem, there is not limit in the format of the image.

下载 rootfs.img 到第5阶段的 0x40000 地址偏移处。只要您选择的 kernel 能够支持该文件系统,image 的格式就没有限制。

rkxx_loader_vx.xx.xxx.bin

这是 Rockchip 以 binary 方式提供的,用于使用 rkdeveloptool 升级固件到 eMMC,不能直接连接到媒体设备。

这是来自 ddr.bin, usbplug.bin, miniloader.bin 的包,Rockchip tool DB 命令将使 usbplug.bin 作为 Rockusb 设备在目标中运行。您可以跳过打包此 image,Rockchip 将在大多数时间提供此 image

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值