下图提供了 HSM 模式启动镜像的图示。
针对 AMD Zynq™ UltraScale+™ MPSoC 器件使用 HSM 模式创建启动镜像的过程与使用标准流程利用以下 BIF 文件创建启动镜像的过程类似。这些示例按需使用 OpenSSL 程序来生成散列文件。
all:
{
[fsbl_config] bh_auth_enable
[keysrc_encryption] bbram_red_key
[pskfile] primary0.pem
[sskfile] secondary0.pem
[
bootloader,
destination_cpu=a53-0,
encryption=aes,
aeskeyfile=aes0.nky,
authentication=rsa
] fsbl.elf
[
destination_device=pl,
encryption=aes,
aeskeyfile=aes1.nky,
authentication=rsa
] system.bit
[
destination_cpu=a53-0,
authentication=rsa,
exception_level=el-3,
trustzone=secure
] bl31.elf
[
destination_cpu=a53-0,
authentication=rsa,
exception_level=el-2
] u-boot.elf
}
阶段 0:为 SPK 生成散列
以下是来自 BIF 文件的代码片段。
stage0:
{
[ppkfile]primary.pub
[spkfile]secondary.pub
}
以下是 Bootgen 命令:
bootgen -arch zynqmp -image stage0.bif -generate_hashes -w on -log error
阶段 1:签署 SPK 散列(对分区进行加密)
以下是使用 OpenSSL 生成 SPK 散列的代码片段:
openssl rsautl -raw -sign -inkey primary0.pem -in secondary.pub.sha384 > secondary.pub.sha384.sig
此命令的输出为 secondary.pub.sha384.sig。
阶段 2a:对 FSBL 进行加密
在 BIF 文件中使用以下代码片段对 FSBL 进行加密。
Stage 2a:
{
[keysrc_encryption] bbram_red_key
[
bootloader,destination_cpu=a53-0,
encryption=aes,
aeskeyfile=aes0.nky
] fsbl.elf
}
Bootgen 命令为:
bootgen -arch zynqmp -image stage2a.bif -o fsbl_e.bin -w on -log error
阶段 2b:对比特流进行加密
生成以下 BIF 文件条目:
stage2b:
{
[
encryption=aes,
aeskeyfile=aes1.nky,
destination_device=pl,
pid=1
] system.bit
}
Bootgen 命令为:
bootgen -arch zynqmp -image stage2b.bif -o system_e.bin -w on -log error
阶段 3:生成启动头文件散列
使用以下 BIF 文件生成启动头文件散列:
stage3:
{
[fsbl_config] bh_auth_enable
[ppkfile] primary.pub
[spkfile] secondary.pub
[spksignature]secondary.pub.sha384.sig
[bootimage,authentication=rsa]fsbl_e.bin
}
Bootgen 命令为:
bootgen -arch zynqmp -image stage3.bif -generate_hashes -w on -log error
阶段 4:对启动头文件散列进行签名
使用以下 OpenSSL 命令生成启动头文件散列:
openssl rsautl -raw -sign -inkey secondary0.pem -in bootheader.sha384 > bootheader.sha384.sig
阶段 5:获取分区散列
在 BIF 文件中使用以下命令获取分区散列:
stage5:
{
[ppkfile]primary.pub
[spkfile]secondary.pub
[spksignature]secondary.pub.sha384.sig
[bhsignature]bootheader.sha384.sig
[bootimage,authentication=rsa]fsbl_e.bin
[bootimage,authentication=rsa]system_e.bin
[
destination_cpu=a53-0,
authentication=rsa,
exception_level=el-3,
trustzone=secure
] bl31.elf
[
destination_cpu=a53-0,
authentication=rsa,
exception_level=el-2
] u-boot.elf
}
Bootgen 命令为:
bootgen -arch zynqmp -image stage5.bif -generate_hashes -w on -log error
针对每个比特流分区都会生成多个散列。欲知详情,请参阅 使用外部存储器执行比特流身份验证。
启动头文件散列同样在此阶段 5 中生成;它不同于阶段 3 中生成的散列,因为在阶段 5 中不使用 bh_auth_enable
参数。如果需要,可在阶段 5 中添加该参数,但这并没有显著影响,因为使用阶段 3 生成的启动头文件散列会在阶段 4 中签名,此签名仅在 HSM 模式流程中使用。
阶段 6:对分区散列进行签名
使用 OpenSSL 创建以下文件:
openssl rsautl -raw -sign -inkey secondary0.pem -in fsbl.elf.0.sha384 > fsbl.elf.0.sha384.sig
openssl rsautl -raw -sign -inkey secondary0.pem -in system.bit.0.sha384 > system.bit.0.sha384.sig
openssl rsautl -raw -sign -inkey secondary0.pem -in system.bit.1.sha384 > system.bit.1.sha384.sig
openssl rsautl -raw -sign -inkey secondary0.pem -in system.bit.2.sha384 > system.bit.2.sha384.sig
openssl rsautl -raw -sign -inkey secondary0.pem -in system.bit.3.sha384 > system.bit.3.sha384.sig
openssl rsautl -raw -sign -inkey secondary0.pem -in u-boot.elf.0.sha384 > u-boot.elf.0.sha384.sig
openssl rsautl -raw -sign -inkey secondary0.pem -in bl31.elf.0.sha384 > bl31.elf.0.sha384.sig
openssl rsautl -raw -sign -inkey secondary0.pem -in bl31.elf.1.sha384 > bl31.elf.1.sha384.sig
阶段 7:将分区签名插入身份验证证书
阶段 7a:在 BIF 文件中添加以下代码以插入 FSBL 签名:
Stage7a:
{
[fsbl_config] bh_auth_enable
[ppkfile] primary.pub
[spkfile] secondary.pub
[spksignature]secondary.pub.sha384.sig
[bhsignature]bootheader.sha384.sig
[bootimage,authentication=rsa,presign=fsbl.elf.0.sha384.sig]fsbl_e.bin
}
Bootgen 命令如下所示:bootgen -arch zynqmp -image stage7a.bif -o fsbl_e_ac.bin -efuseppkbits
efuseppkbits.txt -nonbooting -w on -log error
阶段 7b:在 BIF 文件中添加以下代码以插入比特流签名:
stage7b:
{
[ppkfile]primary.pub
[spkfile]secondary.pub
[spksignature]secondary.pub.sha384.sig
[bhsignature]bootheader.sha384.sig
[
bootimage,
authentication=rsa,
presign=system.bit.0.sha384.sig
] system_e.bin
}
Bootgen 命令为:
bootgen -arch zynqmp -image stage7b.bif -o system_e_ac.bin -nonbooting -w on -log error
阶段 7c:在 BIF 文件中添加以下代码以插入 U-Boot 签名:
stage7c:
{
[ppkfile] primary.pub
[spkfile] secondary.pub
[spksignature]secondary.pub.sha384.sig
[bhsignature]bootheader.sha384.sig
[
destination_cpu=a53-0,
authentication=rsa,
exception_level=el-2,
presign=u-boot.elf.0.sha384.sig
] u-boot.elf
}
Bootgen 命令为:
bootgen -arch zynqmp -image stage7c.bif -o u-boot_ac.bin -nonbooting -w on -log error
阶段 7d:在 BIF 文件中输入以下代码以插入 ATF 签名:
stage7d:
{
[ppkfile] primary.pub
[spkfile] secondary.pub
[spksignature]secondary.pub.sha384.sig
[bhsignature]bootheader.sha384.sig
[
destination_cpu=a53-0,
authentication=rsa,
exception_level=el-3,
trustzone=secure,
presign=bl31.elf.0.sha384.sig
] bl31.elf
}
Bootgen 命令为:
bootgen -arch zynqmp -image stage7d.bif -o bl31_ac.bin -nonbooting -w on -log error
阶段 8:将分区加以组合并获取头文件表散列
在 BIF 文件中输入以下代码:
stage8:
{
[bootimage]fsbl_e_ac.bin
[bootimage]system_e_ac.bin
[bootimage]bl31_ac.bin
[bootimage]u-boot_ac.bin
}
Bootgen 命令为:
bootgen -arch zynqmp -image stage8.bif -generate_hashes -o stage8.bin -w on -log error
阶段 9:签署头文件表散列
使用 OpenSSL 生成以下文件:
openssl rsautl -raw -sign -inkey secondary0.pem -in ImageHeaderTable.sha384 > ImageHeaderTable.sha384.sig
阶段 10:将分区加以组合并插入头文件表签名
在 BIF 文件中输入以下代码:
stage10:
{
[headersignature]ImageHeaderTable.sha384.sig
[bootimage]fsbl_e_ac.bin
[bootimage]system_e_ac.bin
[bootimage]bl31_ac.bin
[bootimage]u-boot_ac.bin
}
Bootgen 命令为:
bootgen -arch zynqmp -image stage10.bif -o final.bin -w on -log error