1 基础介绍
FIT(flattened image tree)是U-Boot⽀持的⼀种新固件类型的引导⽅案,⽀持任意多个image打包和校
验。FIT 使⽤ its (image source file) ⽂件描述image信息,最后通过mkimage⼯具⽣成 itb (flattened image
tree blob) 镜像。its⽂件使⽤ DTS 的语法规则,⾮常灵活,可以直接使⽤libfdt 库和相关⼯具。
FIT 是U-Boot默认⽀持且主推的固件格式,SPL和U-Boot阶段都⽀持对FIT格式的固件引导。更多信息请
参考:
因为官⽅的FIT功能⽆法满⾜实际产品需求,所以RK平台对FIT进⾏了适配和优化。所以FIT⽅案中必须
使⽤RK U-Boot编译⽣的mkimage⼯具,不能使⽤PC⾃带的mkimage。
2 范例介绍
如下以u-boot.its和u-boot.itb作为范例进⾏介绍。
/images :静态定义了所有的资源,相当于⼀个 dtsi⽂件;
/configurations :每个 config 节点都描述了⼀套可启动的配置,相当于⼀个板级dts⽂件。
default = :指明默认启⽤的config;
./doc/uImage.FIT/
/dts-v1/;
/ {
description = "Simple image with OP-TEE support";
#address-cells = <1>;
images {
uboot {
description = "U-Boot";
data = /incbin/("./u-boot-nodtb.bin");
type = "standalone";
os = "U-Boot";
arch = "arm";
compression = "none";
使⽤mkimage⼯具和its⽂件可以⽣成itb⽂件:
fdtdump 命令可以查看 itb⽂件内容:
load = <0x00400000>;
hash {
algo = "sha256";
};
};
optee {
description = "OP-TEE";
data = /incbin/("./tee.bin");
type = "firmware";
arch = "arm";
os = "op-tee";
compression = "none";
load = <0x8400000>;
entry = <0x8400000>;
hash {
algo = "sha256";
};
};
fdt {
description = "U-Boot dtb";
data = /incbin/("./u-boot.dtb");
type = "flat_dt";
compression = "none";
hash {
algo = "sha256";
};
};
};
// configurations 节点下可以定义任意多个不同的conf节点,但实际产品⽅案上我们只需要⼀个
conf即可。
configurations {
default = "conf";
conf {
description = "Rockchip armv7 with OP-TEE";
rollback-index = <0x0>;
firmware = "optee";
loadables = "uboot";
fdt = "fdt";
signature {
algo = "sha256,rsa2048";
padding = "pss";
key-name-hint = "dev";
sign-images = "fdt", "firmware", "loadables";
};
};
};
};
mkimage + dtc
[u-boot.its] + [images] =========> [u-boot.itb]
cjh@ubuntu:~/uboot-nextdev/u-boot$ fdtdump fit/u-boot.itb | less
/dts-v1/;
// magic: 0xd00dfeed
// totalsize: 0x600 (1536)
// off_dt_struct: 0x48
// off_dt_strings: 0x48c
// off_mem_rsvmap: 0x28
// version: 17
// last_comp_version: 16
// boot_cpuid_phys: 0x0
// size_dt_strings: 0xc3
// size_dt_struct: 0x444
/memreserve/ 7f34d3411000 600;
/ {
version = <0x00000001>; // 新增固件版本号
totalsize = <0x000bb600>; // 新增字段描述整个itb⽂件的⼤小
timestamp = <0x5ecb3553>; // 新增当前固件⽣成时刻的时间戳
description = "Simple image with OP-TEE support";
#address-cells = <0x00000001>;
images {
uboot {
data-size = <0x0007ed54>; // 新增字段描述固件⼤小
data-position = <0x00000a00>; // 新增字段描述固件偏移
description = "U-Boot";
type = "standalone";
os = "U-Boot";
arch = "arm";
compression = "none";
load = <0x00400000>;
hash {
// 新增固件的sha256校验和
value = <0xeda8cd52 0x8f058118 0x00000003 0x35360000 0x6f707465
0x0000009f 0x00000091 0x00000000>;
algo = "sha256";
};
};
optee {
data-size = <0x0003a058>;
data-position = <0x0007f800>;
description = "OP-TEE";
type = "firmware";
arch = "arm";
os = "op-tee";
compression = "none";
load = <0x08400000>;
entry = <0x08400000>;
hash {
value = <0xa569b7fc 0x2450ed39 0x00000003 0x35360000 0x66647400
0x00001686 0x000b9a00 0x552d426f>;
algo = "sha256";
};
};
fdt {
3 itb结构
itb本质是fdt_blob + images的⽂件集合,有如下两种打包⽅式,RK平台⽅案采⽤结构2⽅式。
data-size = <0x00001686>;
data-position = <0x000b9a00>;
description = "U-Boot dtb";
type = "flat_dt";
compression = "none";
hash {
value = <0x0f718794 0x78ece7b2 0x00000003 0x35360000 0x00000001
0x6e730000 0x636f6e66 0x00000000>;
algo = "sha256";
};
};
};
configurations {
default = "conf";
conf {
description = "Rockchip armv7 with OP-TEE";
rollback-index = <0x00000001>; // 固件防回滚版本号,没有⼿动指定时默认为0
firmware = "optee";
loadables = "uboot";
fdt = "fdt";
signature {
algo = "sha256,rsa2048";
padding = "pss";
key-name-hint = "dev";
sign-images = "fdt", "firmware", "loadables";
};
};
};
};
fdt blob
|-----------------------------------|
| |------| |------| |------| |
| | img0 | | img1 | | img2 | | 结构1:image在fdt_blob内,即:itb = fdt_blob(含
img)
| |------| |------| |------| |
|-----------------------------------|
|--------------|------|------|------|
| | | | |
| fdt blob | img0 | img1 | img2 | 结构2:image在fdt_blob外,即itb = fdt_blob +
img
| | | | |
|--------------|------|------|------|