👹
Carlos's Tech Blog
  • 🧔ECUs
    • ZYNQ_Documents
      • [ZYNQ] 构建ZYNQ的BSP工程
      • [ZYNQ] 启动流程
      • [ZYNQ] Secure Boot Flow
      • [ZYNQ] Provisioning Guideline
      • [ZYNQ] Decrypting Partition by the Decrypt Agent Using PUF key
      • [ZYNQ] enabling the cryptsetup on ramdisk
      • [ZYNQ] Encrypt external files based on file system using PUF key
      • [ZYNQ] Loading an Encrypted Linux kernel at U-Boot with a KUP Key
      • [ZYNQ] cross-compile the cryptsetup on Xilinx ZYNQ aarch64 platform
      • [ZYNQ] Linux Linaro系统镜像制作SD卡启动
    • S32G_Documents
      • [S32G] Going through the s32g hard/soft platform
      • [S32G] S32g247's Secure Boot using HSE firmware
        • S32g2 HSE key config
        • How S32g verify secure boot image
        • S32g secure boot signature generation
        • How to download and build S32g Secure boot image
        • [S32G] OTA with Secure Boot
    • RT117x_Documents
      • [RT-117x]IMX RT1170 Provisioning Guideline
      • [RT-117x] Going through the MX-RT1170 hard/soft platform
      • [RT-117x] i.MX-RT1170's Secure Boot
        • [RT-117x]Signing image with the HSM (SignServer)
    • LS104x_Documents
      • [LS104x] bsp project
      • [LS104x] boot flow
      • [LS104x] secure boot
      • [LS104x] Application Note, Using the PKCS#11 in TCU platform
      • [LS104x] 使用ostree更新rootfs
      • [LS104x] ostree的移植
      • [LS104x] Starting with Yocto
      • [LS104x] 使用FIT的kernel格式和initramfs
    • IMX6/8_Documents
      • [IMX6] Defining A U-Boot Command
      • NXP IMX6 嵌入式板子一些笔记
      • NXP-imx6 initialization
    • Vehicle_Apps
      • [SecOC] Tree
        • [SecOC] SecOC Freshness and MAC Truncation
  • 😾TECH
    • Rust Arm OS
      • ARMv7m_Using_The_RUST_Cross_Compiler
    • ARM
      • ARM-v7-M
        • 01_ARMv7-M_处理器架构技术综述
        • 02_ARMv7-M_编程模型与模式
        • 03_ARMv7-M_存储系统结构
        • 04_ARMv7-M_异常处理及中断处理
      • ARM-v8-A
        • 02_ARMv8_基本概念
        • 03_ARMv8_指令集介绍_加载指令集和存储指令集
        • 04_ARMv8_指令集_运算指令集
        • 05_ARMv8_指令集_跳转_比较与返回指令
        • 06_ARMv8_指令集_一些重要的指令
        • 0X_ARMv8_指令集_基于汇编的UART驱动
        • 07_ARMv8_汇编器Using as
        • 08_ARMv8_链接器和链接脚本
        • 09_ARMv8_内嵌汇编(内联汇编)Inline assembly
        • 10_ARMv8_异常处理(一) - 入口与返回、栈选择、异常向量表
        • 11_ARMv8_异常处理(二)- Legacy 中断处理
        • 12_ARMv8_异常处理(三)- GICv1/v2中断处理
        • 13_ARMv8_内存管理(一)-内存管理要素
        • 14_ARMv8_内存管理(二)-ARM的MMU设计
        • 15_ARMv8_内存管理(三)-MMU恒等映射及Linux实现
        • 16_ARMv8_高速缓存(一)cache要素
        • 17_ARMv8_高速缓存(二)ARM cache设计
        • 18_ARMv8_高速缓存(三)多核与一致性要素
        • 19_ARMv8_TLB管理(Translation Lookaside buffer)
        • 20_ARMv8_barrier(一)流水线和一致性模型
        • 21_ARMv8_barrier(二)内存屏障案例
      • ARM Boot Flow
        • 01_Embedded_ARMv7/v8 non-secure Boot Flow
        • 02_Embedded_ARMv8 ATF Secure Boot Flow (BL1/BL2/BL31)
        • 03_Embedded_ARMv8 BL33 Uboot Booting Flow
      • ARM Compiler
        • Compiler optimization and the volatile keyword
      • ARM Development
        • 在MACBOOK上搭建ARMv8架构的ARM开发环境
        • Starting with JLink debugger or QEMU
    • Linux
      • Kernel
        • 0x01_LinuxKernel_内核的启动(一)之启动前准备
        • 0x02_LinuxKernel_内核的启动(二)SMP多核处理器启动过程分析
        • 0x21_LinuxKernel_内核活动(一)之系统调用
        • 0x22_LinuxKernel_内核活动(二)中断体系结构(中断上文)
        • 0x23_LinuxKernel_内核活动(三)中断体系结构(中断下文)
        • 0x24_LinuxKernel_进程(一)进程的管理(生命周期、进程表示)
        • 0x25_LinuxKernel_进程(二)进程的调度器的实现
        • 0x26_LinuxKernel_设备驱动(一)综述与文件系统关联
        • 0x27_LinuxKernel_设备驱动(二)字符设备操作
        • 0x28_LinuxKernel_设备驱动(三)块设备操作
        • 0x29_LinuxKernel_设备驱动(四)资源与总线系统
        • 0x30_LinuxKernel_设备驱动(五)模块
        • 0x31_LinuxKernel_内存管理(一)物理页面、伙伴系统和slab分配器
        • 0x32_LinuxKernel_内存管理(二)虚拟内存管理、缺页与调试工具
        • 0x33_LinuxKernel_同步管理_原子操作_内存屏障_锁机制等
        • 01_LinuxDebug_调试理论和基础综述
      • Userspace
        • Linux-用户空间-多线程与同步
        • Linux进程之间的通信-管道(上)
        • Linux进程之间的通信-管道(下)
        • Linux进程之间的通信-信号量(System V)
        • Linux进程之间的通信-内存共享(System V)
        • Linux进程之间的通信-消息队列(System V)
        • Linux应用调试(一)方法、技巧和工具 - 综述
        • Linux应用调试(二)工具之coredump
        • Linux应用调试(三)工具之Valgrind
        • Linux机制之内存池
        • Linux机制之对象管理和引用计数(kobject/ktype/kset)
        • Linux机制copy_{to, from}_user
        • Linux设备树 - DTS语法、节点、设备树解析等
        • Linux System : Managing Linux Services - inittab & init.d
        • Linux System : Managing Linux Services - initramfs
      • Kernel Examples
        • Linux Driver - GPIO键盘驱动开发记录_OMAPL138
        • 基于OMAPL138的Linux字符驱动_GPIO驱动AD9833(一)之miscdevice和ioctl
        • 基于OMAPL138的Linux字符驱动_GPIO驱动AD9833(二)之cdev与read、write
        • 基于OMAPL138的字符驱动_GPIO驱动AD9833(三)之中断申请IRQ
        • Linux内核调用SPI驱动_实现OLED显示功能
        • Linux内核调用I2C驱动_驱动嵌套驱动方法MPU6050
    • OPTEE
      • 01_OPTEE-OS_基础之(一)功能综述、简要介绍
      • 02_OPTEE-OS_基础之(二)TrustZone和ATF功能综述、简要介绍
      • 03_OPTEE-OS_系统集成之(一)编译、实例、在QEMU上执行
      • 05_OPTEE-OS_系统集成之(三)ATF启动过程
      • 06_OPTEE-OS_系统集成之(四)OPTEE镜像启动过程
      • 07_OPTEE-OS_系统集成之(五)REE侧上层软件
      • 08_OPTEE-OS_系统集成之(六)TEE的驱动
      • 09_OPTEE-OS_内核之(一)ARM核安全态和非安全态的切换
      • 10_OPTEE-OS_内核之(二)对安全监控模式的调用的处理
      • 11_OPTEE-OS_内核之(三)中断与异常的处理
      • 12_OPTEE-OS_内核之(四)对TA请求的处理
      • 13_OPTEE-OS_内核之(五)内存和cache管理
      • 14_OPTEE-OS_内核之(六)线程管理与并发
      • 15_OPTEE-OS_内核之(七)系统调用及IPC机制
      • 16_OPTEE-OS_应用之(一)TA镜像的签名和加载
      • 17_OPTEE-OS_应用之(二)密码学算法和安全存储
      • 18_OPTEE-OS_应用之(三)可信应用的开发
      • 19_OPTEE-OS_应用之(四)安全驱动开发
      • 20_OPTEE-OS_应用之(五)终端密钥在线下发系统
    • Binary
      • 01_ELF文件_目标文件格式
      • 02_ELF文件结构_浅析内部文件结构
      • 03_ELF文件_静态链接
      • 04_ELF文件_加载进程虚拟地址空间
      • 05_ELF文件_动态链接
      • 06_Linux的动态共享库
      • 07_ELF文件_堆和栈调用惯例以ARMv8为例
      • 08_ELF文件_运行库(入口、库、多线程)
      • 09_ELF文件_基于ARMv7的Linux系统调用原理
      • 10_ELF文件_ARM的镜像文件(.bin/.hex/.s19)
    • Build
      • 01_Script_makefile_summary
    • Rust
      • 02_SYS_RUST_文件IO
    • Security
      • Crypto
        • 1.0_Security_计算机安全概述及安全需求
        • 2.0_Security_随机数(伪随机数)
        • 3.0_Security_对称密钥算法加解密
        • 3.1_Security_对称密钥算法之AES
        • 3.2_Security_对称密钥算法之MAC(CMAC/HMAC)
        • 3.3_Security_对称密钥算法之AEAD
        • 8.0_Security_pkcs7(CMS)_embedded
        • 9.0_Security_pkcs11(HSM)_embedded
      • Tools
        • Openssl EVP to implement RSA and SM2 en/dec sign/verify
        • 基于Mac Silicon M1 的OpenSSL 编译
        • How to compile mbedtls library on Linux/Mac/Windows
    • Embedded
      • eMMC启动介质
  • 😃Design
    • Secure Boot
      • JY Secure Boot Desgin
    • FOTA
      • [FOTA] Module of ECUs' FOTA unit design
        • [FOTA] Tech key point: OSTree Deployment
        • [FOTA] Tech key point: repositories role for onboard
        • [FOTA] Tech key point: metadata management
        • [FOTA] Tech key point: ECU verifying and Decrpting
        • [FOTA] Tech key point: time server
      • [FOTA] Local-OTA for Embedded Linux System
    • Provisioning
      • [X-Shield] Module of the Embedded Boards initialization
    • Report
由 GitBook 提供支持
在本页
  • 1. Overview
  • 2. HSE Firmware
  • 3. Secure Boot
  • 3.1 Secure Boot Flow
  • 4. Procedure Secure Boot
  • 4.1 Notes for TF-A
  1. ECUs
  2. S32G_Documents

[S32G] S32g247's Secure Boot using HSE firmware

上一页[S32G] Going through the s32g hard/soft platform下一页S32g2 HSE key config

最后更新于1年前

1. Overview

  • HSE Firmware

  • Secure Boot Flow

2. HSE Firmware

The NXP Hardware Security Engine is a security subsystem aimed at running relevant security functions for applications with stringent confidentiality and authenticity requirements.

The HSE Firmware is required to support the following features. The following firmware versions are supported:

  • HSE_FW_S32G2_0_1_0_0

  • HSE_FW_S32G2_0_1_0_1

  • HSE_FW_S32G2_0_1_0_5 (current)

  • HSE_FW_S32G2_1_1_0_0

  • HSE_FW_S32G2_1_1_0_1

  • HSE_FW_S32G3_0_0_21_0

  • HSE_FW_S32G3_1_0_21_0

  • HSE_FW_S32R45_0_1_0_1

Information on how to configure the HSE Firmware is available in the HSE Reference Manual. More information regarding the HSE API is available in the HSE Service API Reference Manual, available on

3. Secure Boot

Secure boot refers to a two-stage process of successive authentication of the U-Boot and Linux kernel images. This process requires a "root of trust", which is known to be secure. In this case, the root of trust is HSE itself.

Each image is authenticated by the preceding step. Thus, the secure boot flow is the following:

  • BootROM passes control over to HSE FW;

  • HSE FW authenticates the U-Boot image;

  • Boot authenticates the Kernel image.

Note,

  • U-Boot authentication is currently only supported when booting from an SD card!

  • Currently, enabling secure boot cannot be done via Yocto. As such, U-Boot must be built manually with HSE-provided secure boot options enabled!

3.1 Secure Boot Flow

3.1.1 U-Boot Authentication

Signing

Since the FIP signature is stored in the FIP, space is reserved within it. As such, the fip.bin must be signed without the reserved space. First, determine how much of the FIP must be signed:

tools/fiptool/fiptool info fip.bin
Trusted Boot Firmware BL2: offset=0x100, size=0x7D6AC, cmdline="--tb-fw"
EL3 Runtime Firmware BL31: offset=0x7D7B0, size=0x2FF5D, cmdline="--soc-fw"
Non-Trusted Firmware BL33: offset=0xAD710, size=0xAADD0, cmdline="--nt-fw"
SOC_FW_CONFIG: offset=0x1584E0, size=0x5C1F, cmdline="--soc-fw-config"
Trusted Boot Firmware BL2 certificate: offset=0x15E100, size=0x100, cmdline="--tb-fw-cert"

The relevant part of the FIP can be extracted and signed with the private key. In this example, the first 0x15E100 bytes of the FIP must be signed:

dd if=fip.bin of=tosign-fip.bin bs=1 count=`printf "%d" 0x15e100` conv=notrunc
openssl dgst -sha1 -sign rsa2048_private.pem -out fip-signature.bin tosign-fip.bin

The resulting fip-signature.bin must be written back into the fip.bin:

tools/fiptool/fiptool update --align 16 --tb-fw-cert fip-signature.bin fip.bin

The public RSA key must be copied to the boot partition of the SD Card, next to the Linux Kernel Image and DTB file. fip.s32 and fip.bin must be written to the SD Card. fip.bin must be written at the address pointed to by the Application label in the compile log; in this example, the address is 0x5e640.

For shell seek=`printf "%d" 0x5e640`, please convert the hex to decimal manually.

dd if=build/<board>/release/fip.s32 of=/dev/<sdcard_dev> seek=512 skip=512 \
iflag=skip_bytes oflag=seek_bytes conv=notrunc,fsync
dd if=build/<board>/release/fip.bin of=/dev/<sdcard_dev> seek=`printf "%d" 0x5e640` \
conv=notrunc,fsync

Please note (limitation):

For some old EVB boards. The HSE hardware feature cannot be enabled.

The old EVB boards (chips) haven’t HSE hardware IP, named CSE3 Security. As the result, the secure boot feature (HSE features) cannot be supported on the CSE3 Security related platform.

How to test it?

When you type hse_secboot_enable rsa2048_public.der in the uboot console, uboot returns ERROR: HSE not initialised or missing firmware!, which can help you testing wether the HSE features enabled or not.

The sign process should be finished by sign server, the code can be found by:

Verifying

HSE FW authenticates the U-Boot image.

Self-provisioning Public Key

The secure boot is enabled in the default configuration of the Bootloader. For the First time boot after image deployment on S32G2, the secure boot is not enabled, which means, the BOOT_SEQ in the IVT is set to zero. When the bootloader runs for the first time, it detects this condition and configures the HSE for secure boot, and then set BOOT_SEQ=1. After setting BOOT_SEQ=1, the bootloader issues a functional reset.

Note, The command can be called from the U-Boot command line:

=> hse_secboot_enable rsa2048_public.der

<public_key_file>.der refers to the public RSA key on the SD Card boot partition, generated in the chapter.

After the command is finished, simply reset the board to boot in secure mode. To verify if the board has booted in secure mode, check the BOOT_SEQ bit in the IVT, at offset 0x28:

Verify U-Boot

To authenticate the U-Boot image, HSE uses Advanced Secure Boot (ASB).

The SD card contains:

  • Signed Boot Image (IVT + signed FIP.bin) in the raw partition;

  • RSA Public key in DER format.

The self-provisioning process loaded the RSA Public Key into the HSE Key catalog. The RSA HSE engine loads the public key from HSE key catalog directly while the RSA engine calculates the RSA digest.

3.1.2 Kernel Authentication

PKI

The public key is:

Signing

Sign the kernel image and pack it into a FIT image. After the kernel has been compiled, from the u-boot directory, run:

tools/mkimage -f ../linux/<its-filename>.its
-K ../arm-trusted-firmware/build/<board>/release/fdts/<dtb-filename>.dtb
-k ../kernel_keys
-r <itb-filename>.itb

The options for mkimage specify:

Verifying

U-Boot must use the bootm command to boot, not booti. Trying to boot using booti will display the "Bad Linux ARM64 Image magic!" error, since the header for the FIT image is not recognized by booti.

To optionally enable U-Boot secure boot, run:

=> hse_secboot_enable <rsa_public_key>.der

Copy the FIT image from the SD Card to memory:

=> fatload mmc 0:1 <load-address> <fit-image-name>
=> run mmcargs
=> bootm <load-address>

To check if the FIT image loaded on the board is correct, run:

iminfo

The command will check the hashes of the image, dtb, and configuration, but will not check if the FIT image is properly signed.

4. Procedure Secure Boot

4.1 Notes for TF-A

To build ATF with support for HSE Secure Boot, the following make command needs to be run from the ATF repo: make ARCH=aarch64 CROSS_COMPILE=aarch64-none-linux-gnu- PLAT=s32g2xxaevb BL33=u-boot-nodtb.bin HSE_SECBOOT=1 -j8

BL2 uses FIP_MEMORY_OFFSET as the address from which to read the FIP Header. In the case of Secure Boot, ATF is compiled with HSE_SECBOOT=1, which configures the IVT header to set the entire FIP as an Application boot code. BootROM loads the entire FIP at the Load Address. The FIP_MEMORY_OFFSET must be set to have the same value as the Load Address, and it is computed as:

FIP_MEMORY_OFFSET = BL2_ENTRY - BL2_DTB_SIZE - FIP_TOC_HEADER_SIZE

To avoid manually computing FIP_MEMORY_OFFSET, it is possible to first compile without the FIP_MEMORY_OFFSET option, but with HSE_SECBOOT enabled (optionally, with DEBUG enabled, as well), to get the correct Load Address.

Since the FIP signature is stored in the FIP, space is reserved within it. As such, the fip.bin must be signed without the reserved space. First, determine how much of the FIP must be signed:

The relevant part of the FIP can be extracted and signed with the private key. In this example, the first 0x15E100 bytes of the FIP must be signed:

dd if=fip.bin of=tosign-fip.bin bs=1 count=printf "%d" 0x15e100 conv=notrunc openssl dgst -sha1 -sign rsa2048_private.pem -out fip-signature.bin tosign-fip.bin

fiptool update --align 16 --tb-fw-cert fip-signature.bin fip.bin

The public RSA key must be copied to the boot partition of the SD Card, next to the Linux Kernel Image and DTB file. fip.s32 and fip.bin must be written to the SD Card. fip.bin must be written at the address pointed to by the Application label in the compile log; in this example, the address is 0x5e440.

dd if=build/<board>/release/fip.s32 of=/dev/<sdcard_dev> seek=512 skip=512 \
iflag=skip_bytes oflag=seek_bytes conv=notrunc,fsync
dd if=build/<board>/release/fip.bin of=/dev/<sdcard_dev> seek=`printf "%d" 0x5e440` \
conv=notrunc,fsync

The U-Boot image is populated into the fip.s32 that is generated by the TF-A firmware. When the device is booting, the HSE firmware loads the fip.s32 and fip.bin (signature file) from the SD card. Then put the RSA public key in the SD card into the NVM key catalog (). Then verify the U-Boot image in fip.s32 with the fip.bin signature using the RSA public key in NVM key catalog.

For more information, please refer to .

Kernel image authentication is provided by U-Boot, using the upstream verified boot method. This method will use an .its file, which defines a dtb/kernel configuration and a signing scheme. Please refer to the link and

The output of the mkimage command should display the parts of the FIT image: the kernel, dtb and configuration. The kernel and dtb will have a hash value, while the configuration will have a signed hash, if using the configuration signing method. Otherwise, the kernel and fdt will have a signed hash. The sign format please refer to .

For the signing information, please refer to

For the signing information, please refer to

Please refer to the link:

🧔
https://drive.google.com/file/d/1Rgf4kMXKEcfVVmGLXYbr4j5-rejWtLU6/view?usp=drive_link
doc
https://github.com/carloscn/s32g-bsp/blob/master/secure_boot/sign_server/plain_sign.sh
https://github.com/carloscn/s32g-bsp/blob/master/secure_boot/build_sign.sh
doc
https://lwn.net/Articles/571031/
https://github.com/ARM-software/u-boot/blob/master/doc/uImage.FIT/signature.txt
https://github.com/carloscn/blog/issues/186
https://app.gitbook.com/o/eTBeA3vhkOtihTJASkhd/s/tqiX1ZbXhRorHX3bwk1r/~/changes/12/s32g_documents/s32g-s32g247s-secure-boot-using-hse-firmware/s32g-secure-boot-signature-generation
https://app.gitbook.com/o/eTBeA3vhkOtihTJASkhd/s/tqiX1ZbXhRorHX3bwk1r/~/changes/12/s32g_documents/s32g-s32g247s-secure-boot-using-hse-firmware/s32g-secure-boot-signature-generation
https://app.gitbook.com/o/eTBeA3vhkOtihTJASkhd/s/tqiX1ZbXhRorHX3bwk1r/~/changes/12/s32g_documents/s32g-s32g247s-secure-boot-using-hse-firmware/how-to-download-and-build-s32g-secure-boot-image