使用 HSM 模式创建 Zynq 7000 SoC 器件启动镜像 - 2023.2 简体中文

Vitis 统一软件平台文档 嵌入式软件开发 (UG1400)

Document ID
UG1400
Release Date
2023-12-13
Version
2023.2 简体中文

下图提供了 AMD Zynq™ 7000 SoC 器件的 HSM 模式启动镜像图示。紧随在图示后提供了用于创建此启动镜像的步骤。

图 1. 启动流程阶段 0 到 8

使用 HSM 模式为 AMD Zynq™ 7000 SoC 器件创建启动镜像的过程与使用标准流程利用以下 BIF 文件创建启动镜像的过程类似。这些示例按需使用 OpenSSL 程序来生成散列文件。

all:
{
	[aeskeyfile]my_efuse.nky 
	[pskfile]primary.pem 
	[sskfile]secondary.pem
	[bootloader,encryption=aes,authentication=rsa] zynq_fsbl_0.elf
	[authentication=rsa]system.bit
}

阶段 0:为 SPK 生成散列

此阶段可生成 SPK 密钥的散列。

stage0:
{
	[ppkfile] primary.pub
	[spkfile] secondary.pub
}

以下是 Bootgen 命令。

bootgen -image stage0.bif –w -generate_hashes

阶段 1:签署的 SPK 散列

此阶段会通过签署 SPK 散列来创建签名

xil_rsa_sign.exe -gensig -sk primary.pem -data secondary.pub.sha256 -out secondary.pub.sha256.sig
或者通过使用以下 OpenSSL 程序来创建签名。
#Swap the bytes in SPK hash
objcopy -I binary -O binary --reverse-bytes=256 secondary.pub.sha256

#Generate SPK signature using OpenSSL
openssl rsautl -raw -sign -inkey primary.pem -in secondary.pub.sha256 > secondary.pub.sha256.sig

#Swap the bytes in SPK signature
objcopy -I binary -O binary --reverse-bytes=256 secondary.pub.sha256.sig

阶段 2:使用 AES 进行加密

此阶段可对分区进行加密。stage2.bif 如下所示。

stage2:
{
	[aeskeyfile] my_efuse.nky
	[bootloader, encryption=aes] zynq_fsbl_0.elf
}
Bootgen 命令如下所示。
bootgen -image stage2.bif -w -o fsbl_e.bin -encrypt efuse
输出为已加密的 fsbl_e.bin 文件。

阶段 3:生成分区散列

此阶段可生成不同分区的散列。

阶段 3a:生成 FSBL 散列

BIF 文件如下所示:

stage3a:
{
	[ppkfile] primary.pub
	[spkfile] secondary.pub
	[spksignature] secondary.pub.sha256.sig
	[bootimage, authentication=rsa] fsbl_e.bin
}
Bootgen 命令如下所示。
bootgen -image stage3a.bif -w -generate_hashes

输出为散列文件 zynq_fsbl_0.elf.0.sha256

阶段 3b:生成比特流散列

阶段 3b BIF 文件如下所示:

stage3b:
{
	[ppkfile] primary.pub
	[spkfile] secondary.pub
	[spksignature] secondary.pub.sha256.sig
	[authentication=rsa] system.bit
}
Bootgen 命令如下所示。
bootgen -image stage3b.bif -w -generate_hashes
输出为散列文件 system.bit.0.sha256

阶段 4:签署散列

此阶段会从创建的分区散列文件创建签名。

阶段 4a:签署 FSBL 分区散列
xil_rsa_sign.exe -gensig -sk secondary.pem -data zynq_fsbl_0.elf.0.sha256 -out zynq_fsbl_0.elf.0.sha256.sig
或者通过使用以下 OpenSSL 程序来创建签名。
#Swap the bytes in FSBL hash
objcopy -I binary -O binary --reverse-bytes=256 zynq_fsbl_0.elf.0.sha256

#Generate FSBL signature using OpenSSL
openssl rsautl -raw -sign -inkey secondary.pem -in zynq_fsbl_0.elf.0.sha256 > zynq_fsbl_0.elf.0.sha256.sig

#Swap the bytes in FSBL signature
objcopy -I binary -O binary --reverse-bytes=256 zynq_fsbl_0.elf.0.sha256.sig

输出为签名文件 zynq_fsbl_0.elf.0.sha256.sig

阶段 4b:签署比特流散列
xil_rsa_sign.exe -gensig -sk secondary.pem -data system.bit.0.sha256 -out system.bit.0.sha256.sig
或者通过使用以下 OpenSSL 程序来创建签名。
#Swap the bytes in bitstream hash
objcopy -I binary -O binary --reverse-bytes=256 system.bit.0.sha256

#Generate bitstream signature using OpenSSL
openssl rsautl -raw -sign -inkey secondary.pem -in system.bit.0.sha256 > system.bit.0.sha256.sig

#Swap the bytes in bitstream signature
objcopy -I binary -O binary --reverse-bytes=256 system.bit.0.sha256.sig
输出为签名文件 system.bit.0.sha256.sig

阶段 5:插入分区签名

将以上创建的分区签名更改并插入身份验证证书。

阶段 5a:插入 FSBL 签名

stage5a.bif 如下所示。

stage5a:
{
	[ppkfile] primary.pub
	[spkfile] secondary.pub
	[spksignature] secondary.pub.sha256.sig
	[bootimage, authentication=rsa, presign=zynq_fsbl_0.elf.0.sha256.sig] fsbl_e.bin
}
Bootgen 命令如下所示。
bootgen -image stage5a.bif -w -o fsbl_e_ac.bin -efuseppkbits efuseppkbits.txt -nonbooting
经过身份验证的输出文件为 fsbl_e_ac.binefuseppkbits.txt
阶段 5b:插入比特流签名
stage5b.bif 如下所示。
stage5b:
{
	[ppkfile] primary.pub
	[spkfile] secondary.pub
	[spksignature] secondary.pub.sha256.sig
	[authentication=rsa, presign=system.bit.0.sha256.sig] system.bit
}
Bootgen 命令如下所示。
bootgen -image stage5b.bif -o system_e_ac.bin –nonbooting
经过身份验证的输出文件为 system_e_ac.bin

阶段 6:生成头文件表散列

此阶段可生成头文件表的散列。

stage6.bif 如下所示。
stage6:
{
	[bootimage] fsbl_e_ac.bin
	[bootimage] system_e_ac.bin
}
Bootgen 命令如下所示。
bootgen -image stage6.bif -generate_hashes
输出散列文件为 ImageHeaderTable.sha256

阶段 7:生成头文件表签名

此阶段可生成头文件表签名。

xil_rsa_sign.exe -gensig -sk secondary.pem -data ImageHeaderTable.sha256 -out ImageHeaderTable.sha256.sig
或者通过使用以下 OpenSSL 程序来生成签名:
#Swap the bytes in header table hash
objcopy -I binary -O binary --reverse-bytes=256 ImageHeaderTable.sha256

#Generate header table signature using OpenSSL
openssl rsautl -raw -sign -inkey secondary.pem -in ImageHeaderTable.sha256 > ImageHeaderTable.sha256.sig

#Swap the bytes in header table signature
objcopy -I binary -O binary --reverse-bytes=256 ImageHeaderTable.sha256.sig
输出为签名文件 ImageHeaderTable.sha256.sig

阶段 8:将分区加以组合并插入头文件表签名

stage8.bif 如下所示:

stage8:
{
	[headersignature] ImageHeaderTable.sha256.sig
	[bootimage] fsbl_e_ac.bin
	[bootimage] system_e_ac.bin
}
Bootgen 命令如下所示:
bootgen -image stage8.bif -w -o final.bin
输出为启动镜像文件 final.bin