HSM モードを使用した Zynq UltraScale+ MPSoC デバイス ブート イメージの作成 - 2022.1 日本語

Vitis 統合ソフトウェア プラットフォームの資料: エンベデッド ソフトウェア開発 (UG1400)

Document ID
UG1400
Release Date
2022-04-26
Version
2022.1 日本語

次の図に、HSM モードのブート イメージの図を示します。

図 1. 0 〜 10 ステージのブート プロセス

HSM モードを使用した Zynq® UltraScale+™ MPSoC デバイスのブート イメージの作成は、次の 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
}
注記: HSM フローで pmufw_image を使用するには、上記の BIF に [pmufw_image] pmufw.elf を追加します。同様の行の場合、これは FSBL が暗号化される stage2a bif に追加する必要があります。フローの残りは、同じままになります。

ステージ 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 で生成されます。ステージ 5 では bh_auth_enable が使用されないので、このハッシュはステージ 3 で生成されたものとは異なります。これは必要に応じてステージ 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
注記: 現時点では、Versal デバイスでは HSM モードはサポートされていません。