文章目录BL2 和 TFM_S 的配置和编译flash 布局配置 tfm编译qemu 启动BL2 和 TFM_S 的配置和编译前面介绍了 bl2 的启动文件链接文件和启动流程等。flash 布局区域Flash offset物理地址大小用途BL20x000000000x100000000x80000512 KBMCUboot bootloaderPrimary image0x000800000x100800000x1000001 MBSecure 和 Non-Secure 主镜像Secondary image0x001800000x101800000x1000001 MBSecure 和 Non-Secure 升级镜像Scratch0x002800000x102800000x1000001 MB镜像交换的临时区域Protected Storage0x003800000x103800000x500020 KBPS 持久化数据Internal Trusted Storage0x003850000x103850000x400016 KBITS 持久化数据OTP / NV counters0x003890000x103890000x20008 KBOTP 和安全计数器未使用0x0038B0000x1038B000468 KB未分配空间镜像区域的前0x400字节由 BL2 image header 使用剩余空间存放镜像正文和 trailer。Secure 镜像的代码从 primary slot 的offset 0x400开始Non-Secure 镜像同理。所以 tfm_s 的镜像是从0x10080400开始的。配置 tfm按照之前bl2 tfm_s的配置命令如下cd/home/tyustli/Desktop/tyustli/study/code/qemu/trust_firmware/tfm/code/trusted-firmware-msource env/bin/activate cmake-S.-B build_an521_ninja-G Ninja \-DTFM_PLATFORMarm/mps2/an521 \-DCMAKE_BUILD_TYPEDebug \-DMCUBOOT_IMAGE_NUMBER1\-DTFM_PARTITION_CRYPTOON \-DTFM_PARTITION_INTERNAL_TRUSTED_STORAGEON \-DTFM_PARTITION_PROTECTED_STORAGEON \-DTFM_PARTITION_PLATFORMON配置效果如下-----------Secure Partitions------------------------Non-Secure Mailbox Agent OFF Protected Storage Partition ON TF-M Internal Trusted Storage Partition ON TFM Crypto Partition ON TFM Platform Partition ON TFM Initial Attestation Partition OFF TFM Firmware Update Partition OFF------------------------------------------------------如果想生成compile_commands.json供 clangd 等工具查询源文件的编译参数。可以使用如下命令cmake-S.-Bbuild_an521_make-DCMAKE_EXPORT_COMPILE_COMMANDSON-S .指定当前目录为源码目录。-B build_an521_make使用已有构建目录保留其中的其他配置。-DCMAKE_EXPORT_COMPILE_COMMANDSON开启编译命令导出生成compile_commands.json供 clangd 等工具查询源文件的编译参数。编译cmake--build build_an521_ninja--target install编译产物如下[58/73]Linking C executable bin/bl2.axf Memory region Used Size Region Size%age Used FLASH:49352B512KB9.41%RAM:25376B2MB1.21%[66/73]Generating../bin/secure_fw.hex Merged:/home/tyustli/Desktop/tyustli/study/code/qemu/trust_firmware/tfm/code/trusted-firmware-m/build_an521_ninja/bin/secure_fw.hex[68/73]Linking C executable bin/tfm_s.axf Memory region Used Size Region Size%age Used FLASH:153984B511KB29.43%RAM:45632B1MB4.35%[71/73]Generating tfm_s_signed.bin,../../../bin/tfm_s_signed.bin wrapper.py:PSA key ids provided:0x7fff816bimage.py:sign the payload[72/73]Install the project...--Install configuration:Debug从编译产物可以看到同时生成了 bl2 和 tfm_s 两个固件。可以分别看下 bl2 和 tfm_s 的 elf 布局查看 bl2 的布局arm-none-eabi-objdump-s-j.text build_an521_ninja/bin/bl2.elf|head-32bl2 的布局如下1000000020530038f51600109d140010 a3140010 S.8............10000010a9140010 af140010 b5140010 bb140010................10000020000000000000000000000000c1140010................10000030c714001000000000cd140010 d3140010................10000040d9140010 df140010 e5140010 eb140010................10000050f1140010 f7140010 fd14001003150010................1000006000000000091500100f15001015150010................查看 tfm_s 的布局arm-none-eabi-objdump-s-j.TFM_VECTORS build_an521_ninja/bin/tfm_s.elf|head-32tfm_s 的布局如下10080400f8150038 c1e6091069200a10 a5220a10...8....i.....10080410b5220a10 c5220a10 e5220a10 d5220a10............100804200000000000000000000000005dfb0910............]...100804306f200a100000000075200a107b200a10 o......u..{..1008044081200a1087200a108d200a1093200a10............1008045099200a109f200a10 a5200a10 ab200a10............1008046000000000b1200a10 b7200a10 bd200a10.............bl2 从 0x10000000 开始tfm_s 从 0x10080400 开始前面 0x400 放 image headerqemu 启动qemu-system-arm \-M mps2-an521 \-cpu cortex-m33 \-nographic \-device loader,file/home/tyustli/Desktop/tyustli/study/code/qemu/trust_firmware/tfm/code/trusted-firmware-m/build_an521_ninja/bin/bl2.hex\-device loader,file/home/tyustli/Desktop/tyustli/study/code/qemu/trust_firmware/tfm/code/trusted-firmware-m/build_an521_ninja/bin/tfm_s_signed.hex这里启动 bl2 tfm_s日志如下[INF]Starting bootloader[INF]Beginning BL2 provisioning[WRN]TFM_DUMMY_PROVISIONING is not suitableforproduction!This device is NOT SECURE[INF]PSA Crypto init done,sig_type:EC-P256,using builtin keys[INF]Image index:0,Swap type:none[INF]Bootloader chainload address offset:0x80000[INF]Image version:v2.3.0[INF]Jumping to the first image slot[NOT]Booting TF-M v2.3.0[NOT]Built Thu29Oct202609:12:54UTC[INF]Beginning TF-M provisioning[WRN]TFM_DUMMY_PROVISIONING is not suitableforproduction!This device is NOT SECURE[WRN]This device was provisioned with dummy keys.This device is NOT SECURE[VER]Isolation level is:1Creating an empty ITS flash layout.Creating an empty PS flash layout.[INF][Crypto]Provision entropy seed...[INF][Crypto]Provision entropy seed...complete.[VER][Crypto]Init TF-PSA-Crypto1.1.0...[VER][Crypto]Internal heap size is12288bytes[VER][Crypto]Init TF-PSA-Crypto1.1.0...complete.[INF][PS]Encryption alg:0x5500200
阅读完成 · 觉得有帮助?