the_ROM_image: { [keysrc_encryption] efuse_red_key [bootloader, encryption=aes,aeskeyfile = aes.nky, destination_cpu = a53-0] fsbl.elf }
bootgen -p zcu1eg -arch zynqmp -image key_aes_gen.bif
这一步骤,只是为了生成AES Key,用户如果有自己的密钥,可以跳过该步骤,直接到1.2 步骤生成Obfuscate Key。 bootgen可以使用其他seed来产生AES Key,如果不指定,默认使用时间 Seed。
使用上面一部产生的AES 密钥,生成Obfuscate key。 这里用户也可以使用自己的AES key。
obf_key: { [aeskeyfile] aes.nky [familykey] zynq_fmk.cfg [bh_key_iv] bhiv.txt
}
bhiv.txt: Initialization vector used when decrypting the obfuscated。 ex:575CED7D77EBDD88E8BD73B3 用户可以根据自己需要修改。
使用从Xilinx申请到的family key
bootgen -arch zynqmp -image key_obfuscated_gen.bif -generate_keys obfuscatedkey
cat obfuscatedkey.txt
在bif文件头部增加如下关键字段: [keysrc_encryption] bh_gry_key [bh_keyfile] obfuscatedkey.txt [bh_key_iv] bhiv.txt obfuscatedkey.txt : 我们前面步骤生成的Gray Key。 bhiv.txt : 我们前面生成Gray Key时,使用的IV。
在每个模块中增加 encryption = aes,aeskeyfile = module-name.nky 这里需要注意: fsbl使用的aes.nky,就是第一步中生成obfuscatedkey的red key,这个文件必须存在。 其他模块的nky文件,可以不存在,bootgen会自动生成。
For Example: the_ROM_image: { [keysrc_encryption] bh_gry_key [bh_keyfile] obfuscatedkey.txt [bh_key_iv] bhiv.txt [bootloader, encryption = aes, aeskeyfile = aes.nky, destination_cpu=a53-0] /proj/zynqmp_fsbl/fsbl_a53.elf [destination_cpu = pmu,encryption = aes,aeskeyfile = pmu.nky] /proj/images/linux/efuse_linux_pmu.elf [destination_device=pl,encryption = aes,aeskeyfile = pl.nky] /proj/images/linux/system.bit [destination_cpu=a53-0,encryption = aes,aeskeyfile = bl31.nky, exception_level=el-3, trustzone] /proj/images/linux/bl31.elf [destination_cpu=a53-0,encryption = aes,aeskeyfile = dtb.nky, load=0x00100000] /proj/images/linux/system.dtb [destination_cpu=a53-0,encryption = aes,aeskeyfile = uboot.nky, exception_level=el-2] /proj/mages/linux/u-boot.elf }
bootgen -arch zynqmp -image bootgen_obfuscated.bif -o BOOT.BIN -w on
bootgen -arch zynqmp -read BOOT.BIN 可以看到encryption字段是yes
为了方便观察,可以将fsbl中xfsbl_config.h中的FSBL_DEBUG_DETAILED_VAL设置为1,这样fsbl启动过程中,会有解密成功的提示; 如果不使能DETAILED 日志级别,则无解密相关的打印。
建议在FSBL启动初始阶段,将JTAG功能打开; 如果不打开,JTAG功能会被禁用,JTAG将无法使用。类似如下的情况:
在fsbl中添加如下函数,并在最开始的地方进行调用。 int XFsbl_EnableJtag() { Xil_Out32(0xffca0038,0x3F);
Xil_Out32(0xffca003C,0xFF);
Xil_Out32(0xffca0030,0x3);
Xil_Out32(0xFF5E00B0,0x01002002);
Xil_Out32(0xFF5E0240,0x0);
Xil_Out32(0xFFCA3000,0x1);
return 0;
}
注:如果密钥有问题,CSU无法解析Boot Header,将会导致板子无法启动,即使再FSBL中使能了JTAG,由于FSBL没有被执行,JTAG仍无法使用。必须通过其他方式将异常的BOOT.BIN清除掉,板子才可以继续使用。
将BOOT.BIN 烧写进EMMC,如果能够检验通过,会有高亮部分的显示: 如果密钥异常,CSU无法解析BOOT.BIN,串口无任何输出。
Xilinx Zynq MP First Stage Boot Loader Release 2022.2 Oct 30 2024 - 07:51:33 MultiBootOffset: 0x0 Reset Mode : System Reset Platform: Silicon (4.0), Cluster ID 0x80000000 Running on A53-0 (64-bit) Processor, Device Name: XCZUUNKNEG Processor Initialization Done ================= In Stage 2 ============ Enable JTAG In Fsbl eMMC Boot Mode SD: rc= 0 File name is BOOT.BIN Multiboot Reg : 0x0 Image Header Table Offset 0x8C0 Image Header Table Details*** Boot Gen Ver: 0x1020000 No of Partitions: 0x8 Partition Header Address: 0x440 Partition Present Device: 0x0 Initialization Success ======= In Stage 3, Partition No:1 ======= UnEncrypted data Length: 0x6038 Data word offset: 0x6058 Total Data word length: 0x6058 Destination Load Address: 0xFFDC0000 Execution Address: 0xFFDD19B8 Data word offset: 0x76C0 Partition Attributes: 0x8B6 IsEncryptionEnabled TRUE Aes initialized Decryption Enabled Decryption Successful Partition 1 Load Success ======= In Stage 3, Partition No:2 ======= UnEncrypted data Length: 0x247 Data word offset: 0x267 Total Data word length: 0x267 Destination Load Address: 0xFFDDBE1C Execution Address: 0x0 Data word offset: 0xD720 Partition Attributes: 0x8B6 IsEncryptionEnabled TRUE Aes initialized Decryption Enabled Decryption Successful Partition 2 Load Success
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。