TQMa93-logo

TQMa93 Boot Aman

TQMa93-Secure-Boot-product

Informasi produk

Spesifikasi

  • Model: TQMa93xx
  • Sistem Operasi: Linux (Ubuntu 22.04)
  • Fitur Keamanan: Boot Aman

PERHATIAN: Fuses (One Time Programmable) are set in this How-to, this process is irreversible. It is therefore strongly recommended to use a development pattern for this guide.

tata cara

Pandhuan iki nerangake carane rantai kepercayaan bisa ditetepake saka boot loader liwat kernel Linux menyang partisi root kanthi dm-verity.
Tabel ing ngisor iki menehi katrangan sing disederhanakake babagan langkah-langkah nggawe rantai kepercayaan lan verifikasi sajrone proses boot:

TQMa93-Secure-Boot-01

Persiapan

The following projects are required to create a signed boot stream for TQMa93xx:

Bootstream kanggo TQMa93xx kasusun saka sawetara artefak. Kanggo entuk kabeh artefak kasebut saka sumber sing padha, disaranake nggunakake ruang kerja TQ Yocto ci-meta-tq. Pandhuan sing kalebu ing kono bisa ditindakake kanggo nggawe gambar lengkap (tq-image-weston-debug utawa tq-image-generic-debug) kanggo salah sawijining piranti adhedhasar TQMa93xx ing ngisor iki:

  • tqma93xx-mba91xxca.conf
  • tqma93xx-mba93xxca.conf
  • tqma93xxla-mba93xxla.conf

PERHATIAN: To create U-Boot with secure boot functionality (AHAB), the following line must be added to local.conf:
DISTRO_FEATURES:append = ”aman”
Sabanjure, stream boot kudu digawe maneh:
$ bitbake imx-boot

The TQ Yocto workspace can also be used to create an image of the complete chain of trust presented here. The settings required for this are described in section 5.2 .
The sources for the Linux kernel and U-Boot are optional but recommended. They can be downloaded from Github:

U-Boot

Generating keys
Signing and verification of the boot stream are carried out using a public key infrastructure (PKI). If not already available, the Code Signing Tool can be used to create a suitable PKI. The CST 3.4.x is a tar.gz archive that only needs to be unpacked. No further installation is necessary. The following steps can be used to generate the samptombol kanggo pandhuan iki:

PERHATIAN: Paths are relative to the folder extracted from the archive.

  1. Enter the serial number of the first certificate in keys/serial (file kudu digawe): 12345678
  2. Enter the passphrase twice in keys/key_pass.txt (file must be created):
    my_passphrase my_passphrase
  3. Create PKI tree:
    $ keys/ahab_pki_tree.sh -existing-ca n -kt ecc -kl p521 -da sha512 -duration 10 -srk-ca n
    For an explanation of the options, please refer to the User Guide contained in the CST (in the docs subfolder) or the –help option of the above script.
    Alternatively, the script can also be called without options and configured in interactive mode.
    The script generates keys in keys/ and certificates in crts/.
  4. Create SRK table and SRK hash table:
    $ linux64/bin/srktool -a -s sha512 -d sha256 -t SRK_1_2_3_4_table.bin \
    -e SRK_1_2_3_4_fuse.bin -f 1 -c
    crts/SRK1_sha512_secp521r1_v3_usr_crt.pem,crts/SRK2_sha512_secp521r1_v3_usr_crt. pem,crts/SRK3_sha512_secp521r1_v3_usr_crt.pem,crts/SRK4_sha512_secp521r1_v3_usr_ crt.pem
  5. Write SRK hash table in fuses:
    PERHATIAN: Langkah iki mung bisa sapisan lan ora bisa dibalèkaké. Nilai ing ngisor iki mung examples lan kudu diganti dening nilai dhewe.
    • Display hashes:
      $ hexdump -e ‘/4 “0x”‘ -e ‘/4 “%X””\n”‘ SRK_1_2_3_4_fuse.bin
      0x00000000
      0x11111111
      0x22222222
      0x33333333
      0x44444444
      0x55555555
      0x66666666
      0x77777777
    • Write hashes in fuses (TQMa93xx U-Boot):
      => fuse prog 16 0 0x00000000
      => fuse prog 16 1 0x11111111
      => fuse prog 16 2 0x22222222
      => fuse prog 16 3 0x33333333
      => fuse prog 16 4 0x44444444
      => fuse prog 16 5 0x55555555
      => fuse prog 16 6 0x66666666
      => fuse prog 16 7 0x77777777

 Creating a signed boot stream

 U-Boot Proper and ATF

  1. Nyalin sing dibutuhake files (successful build of a TQ image, see above, or the U-Boot sources is assumed):
    • ARM Trusted Firmware: ${DEPLOY_DIR_IMAGE}/bl31-imx93.bin, rename to bl31.bin
    • U-Boot Proper:
      ${DEPLOY_DIR_IMAGE}/u-boot.bin
      Iki file is a link, so copy it with cp –-dereference or display and copy the original file with ls –-long
      or
      saka sumber U-Boot sing disusun dhewe
      Iki files kudu disalin menyang imx-mkimage/iMX9/. imx-mkimage bisa dipikolehi saka gudang Github sing kasebut ing ndhuwur, ora perlu instalasi.
  2. Build container with U-Boot Proper and ATF (execute in folder imx-mkimage):
    $ make SOC=iMX9 REV=A1 u-boot-atf-container.img include autobuild.mak
    • CST: KONTAINER 0 offset: 0x0
    • CST: KONTAINER 0: Blok Teken: offset ana ing 0x110
    • Offsets = 0x0 0x110
    • Rampung.
    • Cathetan: Mangga nyalin gambar kanggo ngimbangi: IVT_OFFSET + IMAGE_OFFSET
      PERHATIAN: Offset kanggo wadhah lan blok teken dibutuhake ing langkah sabanjure.
    • Artefak imx-mkimage/iMX9/u-boot-atf-container.img banjur kudu disalin menyang folder CST unpacked ing langkah "3.1 Generating keys".
  3. Transfer offset of container and signature block to Command Sequence File (CSF):
    • [Header]
    • Target = AHAB
    • Versi = 1.0
    • [Pasang SRK]
    • File = “SRK_1_2_3_4_table.bin”
    • Source = “crts/SRK1_sha512_secp521r1_v3_usr_crt.pem”
    • Source index = 0
    • Source set = OEM
    • Revocations = 0x0
    • [Data otentikasi]
    • File = “u-boot-atf-container.img”
    • Offsets = 0x0 0x110
    • CSF based on: https://github.com/nxp-imx/uboot-imx/blob/lf_v2024.04/doc/imx/ahab/csf_examples/csf_uboot_atf.txt
    • The CSF is also stored in the CST folder with the name csf_uboot_atf.txt that was unpacked in step “3.1 Generating keys”.
  4. Sign container (path relative to the CST folder):
    $ linux64/bin/cst -i csf_uboot_atf.txt -o signed-u-boot-atf-container.img The signed container must then be copied back to imx-mkimage/iMX9/u-boot-atf-container.img. Note the renaming to u-boot-atf-container.img.

 Complete bootstream

  1. Nyalin sing dibutuhake files (successful build of a TQ image, see above, or of the U-Boot sources is assumed):
    • Edgelock Secure Enclave Firmware: ${DEPLOY_DIR_IMAGE}/mx93a1-ahab-container.img
    • RAM Firmware: ${DEPLOY_DIR_IMAGE}/lpddr4*.bin
    • U-Boot SPL:
      ${DEPLOY_DIR_IMAGE}/u-boot-spl.bin
      Iki file is a link, so copy it with cp –-dereference or display and copy the original file with ls –-long
      or
      saka sumber U-Boot sing disusun dhewe
    • Signed container with U-Boot Proper and ATF from step „3.2.1 U-Boot Proper and ATF“
      Iki files uga kudu disalin menyang imx-mkimage/iMX9/.
  2. Build bootstream
    • $ nggawe -j8 SOC = iMX9 REV = A1 flash_singleboot
      kalebu autobuild.mak
    • CST: KONTAINER 0 offset: 0x400
    • CST: KONTAINER 0: Blok Teken: offset ana ing 0x490
    • Offsets = 0x400 0x490
    • Rampung.
    • Cathetan: Please copy image to offset: IVT_OFFSET + IMAGE_OFFSET append u-boot-atf-container.img at 379 KB, psize=1024
    • 1145 + 0 cathetan ing
    • 1145 + 0 cathetan metu
    • 1172480 bita (1.2 MB, 1.1 MiB) disalin, 0.00266906 s, 439 MB/s
    • PERHATIAN: The offsets for the container and signature block are required in the next step.
      Artefak imx-mkimage/iMX9/flash.bin banjur kudu disalin menyang folder CST unpacked ing langkah "3.1 Generating tombol".
  3. Transfer offset of container and signature block to Command Sequence File (CSF):
  4. Sign the bootstream
    • linux64/bin/cst -i csf_boot_image.txt -o signed-flash.bin

The steps for replacing the boot stream can be found in the BSP layer (https://github.com/tq-systems/meta-tq) under meta-tq/doc.

Verifikasi
To check if the signed boot stream is valid, use the ahab_status command in U-Boot:

  • => ahab_status
  • Lifecycle: 0x00000008, OEM Open
  • Ora Ana Acara Ditemokake!
  • If an event is found, the boot stream is invalid and would not be able to boot on a locked device.

Kanggo pemalsuan, bootstream sing ora ditandatangani bisa boot lan banjur ahab_status bisa diarani:

  • => ahab_status
  • Lifecycle: 0x00000008, OEM Open
  • 0x0287fad6
  • IPC = MU APD (0x2)
  • CMD = ELE_OEM_CNTN_AUTH_REQ (0x87)
  • IND = ELE_BAD_KEY_HASH_FAILURE_IND (0xFA)
  • STA = ELE_SUCCESS_IND (0xD6)
  • 0x0287fad6
  • IPC = MU APD (0x2)
  • CMD = ELE_OEM_CNTN_AUTH_REQ (0x87)
  • IND = ELE_BAD_KEY_HASH_FAILURE_IND (0xFA)
  • STA = ELE_SUCCESS_IND (0xD6)

 Ngunci piranti

PERHATIAN: This step is irreversible and should only be carried out if necessary. If the configuration is incorrect, this step will result in an unusable device.

The device can be locked in the U-Boot with the command ahab_close. This means that only valid boot streams verified by the Boot ROM will boot. The following status is displayed after rebooting:

  • => ahab_status
  • Lifecycle: 0x00000020, OEM Closed
  • Ora Ana Acara Ditemokake!

FIT-Gambar

PERHATIAN: Path information is relative to a new, empty folder, e.g.
fit_image_work, or the kernel sources, if self-compiled. Hereafter referred to as the working directory.

Generating a key pair
An asymmetric key pair is used to sign the FIT image. Such a pair can be generated with OpenSSL:

$ openssl genpkey -algorithm RSA -out dev.key -pkeyopt rsa_keygen_bits:2048
$ openssl req -batch -new -x509 -key dev.key -out dev.crt

Create image tree source

  • Create image tree source sign.its for the FIT image.
  • /dts-v1/;
  • / {
  • description = “Kernel fitImage for TQMa93xx”;
  • #address-cells = <1>;
  • images {
  • kernel-1 {
  • description = “Linux kernel”;
  • data = /incbin/(“Image”);
  • type = “kernel”;
  • arch = “arm64”;
  • os = “linux”;
  • compression = “gzip”;
  • load = <0x90000000>;
  • entry = <0x90000000>;
  • hash-1 {
  • algo = “sha256”;
  • };
  • };
  • fdt-1 {
  • description = “Flattened Device Tree blob”;
  • data = /incbin/(“<path/to/Devicetree.dtb>”);
  • type = “flat_dt”;
  • arch = “arm64”;
  • compression = “none”;
  • load = <0x97000000>;
  • hash-1 {
  • algo = “sha256”;
  • };
  • };
  • };
  • configurations {
  • default = “conf-1”;
  • conf-1 {
  • description = “Linux kernel, FDT blob”;
  • kernel = “kernel-1”;
  • fdt = “fdt-1”;
  • hash-1 {
  • algo = “sha256”;
  • };
  • signature-1 {
  • algo = “sha256,rsa2048”;
  • key-name-hint = “dev”;
  • padding = “pkcs-1.5”;
  • sign-images = “kernel”, “fdt”;
  • };
  • };
  • };
  • };

 Creating a signed FIT image

Cathetan: The devicetree binary for U-Boot is required for this step. Ready-made devicetree binaries can be found in the Yocto workspace in the U-Boot build directory. The path to the build directory can be displayed with bitbake virtual/bootloader –e | grep ^B=.

  1. Nyalin sing dibutuhake files into the working directory:
    • Rename U-Boot devicetree imx93-tqma9352-mba91xxca.dtb, imx93-tqma9352-mba93xxca.dtb or imx93-tqma9352-mba93xxla.dtb, in pubkey.dtb:
      From U-Boot build directory in Yocto workspace (path: bitbake virtual/bootloader –e | grep ^B=)
      or
      saka sumber U-Boot sing disusun dhewe
    • Linux-Kernel:
      ${DEPLOY_DIR_IMAGE}/Image
      Iki file is a link, so copy it with cp –-dereference or display and copy the original file with ls –-long
      or
      from self-compiled Linux sources
    • Linux devicetree:
      Depending on the variant ${DEPLOY_DIR_IMAGE}/imx93-tqma93…
      Iki file is a link, so copy it with cp –-dereference or display and copy the original file with ls –-long
      or
      from self-compiled Linux sources
    • The keys generated in step 4.1
    • The ITS file digawe ing langkah 4.2
  2. Create FIT image with signature
    $ mkimage -f sign.its -K pubkey.dtb -k . -r image.itb
    The public key is written to the devicetree of the U-Boot. This key is used to verify the FIT image signed above.

PERHATIAN: To pack the U-Boot devicetree with the public key into the signed bootstream from chapter 3.2, the steps from chapter 3.2 must be repeated with a customized U-Boot Proper u-boot.bin. To do this, the devcietree with the public key pubkey.dtb must be specified via the EXT_DTB option when compiling the U-Boot:
make EXT_DTB=<Pfad/zu/pubkey.dtb>

Verifikasi
Ing U-Boot nganggo tombol umum, gambar gambar FIT sing ditandatangani.itb bisa diwiwiti kanthi bootm sawise dimuat saka medium sing cocog (TFTP, eMMC, SD).
Nalika booting gambar FIT, U-Boot ngasilake informasi Verifying Hash Integrity ... sha256,rsa2048:dev+ OK karo jeneng, algoritma lan dawa tombol sing digawe ing bab 4.1 ing console:

  • ## Loading kernel from FIT Image at 80400000 …
  • Verifying Hash Integrity … sha256,rsa2048:dev+ OK
  • ## Loading ramdisk from FIT Image at 80400000 …
  • Verifying Hash Integrity … sha256,rsa2048:dev+ OK
  • ## Loading fdt from FIT Image at 80400000 …
  • Verifying Hash Integrity … sha256,rsa2048:dev+ OK

Kanggo pemalsuan, pasangan kunci liyane bisa digawe kaya sing diterangake ing bagean 4.1 lan digunakake kanggo mlebu gambar FIT. Gambar FIT iki ora bisa boot tanpa ngganti tombol ing U-Boot Devicetree:
## Loading kernel from FIT Image at 80400000 …

Using ‘conf-1’ configuration
Verifying Hash Integrity … sha256,rsa2048:test- error!
Verification failed for ‘<NULL>’ hash node in ‘conf-1’ config node
Failed to verify required signature ‘key-dev’
Bad Data Hash
ERROR: can’t get kernel image!

Extend Chain of Trust: root partition
Rantai kepercayaan sing wis ditetepake sadurunge verifikasi asal saka kernel U-Boot lan Linux. Kanthi mekanisme kasebut ing ndhuwur, mung pemilik kunci pribadi sing digawe bisa mlebu piranti lunak lan boot ing piranti kasebut. Link luwih bisa ditambahake menyang rantai. Bagean ing ngisor iki nerangake carane partisi ROOT bisa direksa saka manipulasi nggunakake dm-verity. Kanggo implementasine nyata, uga ditampilake carane chain lengkap bisa digawe karo TQ-BSP. Pandhuan langkah-langkah kanggo proteksi dm-verity diilangi amarga kerumitan syarat.

 Sketch: Verity Devicemapper

  1. Generate Verity hashes:
    veritysetup ngetung nilai hash lan nyimpen ing mburi partisi ROOT. Pemisahan ROOT bisa dadi nyata file utawa piranti pamblokiran file (contone /dev/sdaX).
    • veritysetup \
    • –data-block-size=1024 \
    • –hash-block-size=4096 \
    • –hash-offset=<Offset> \
    • format \
    • <Root-Partition.img> \
    • <Root-Partition.img>
    • veritysetup ngasilake informasi ing ngisor iki (kanthi nilai sing beda-beda):
    • Informasi header VERITY kanggo data.img
    • UUID: e06ff4cb-6b56-4ad4-bd97-0104505a70a5
    • Hash type: 1
    • Data blocks: 204800
    • Data block size: 1024
    • Hash block size: 4096
    • Hash algorithm: sha256
    • Salt: 17328c48990b76fbb3e05d0ebfd236043674cf0d14c278bc875b42693621cc21
    • Root hash: a0e1a449d452f74d041706b955794c0041e3d8ad051068df6589e08485323698
    • Hash root minangka nilai sensitif sing kudu direksa. Yen hash iki dikompromi, contone, yen bisa diganti dening wong sing ora sah, mula perlindungan integritas partisi root kanthi dm-verity ora ana gunane.
  2. Integrate the root hash into the chain of trust
    • The root hash generated above is stored in the signed FIT image, which protects it against manipulation. For this purpose, an initramfs is added to the FIT image in which the root hash is stored in a file.
    • The images node of the ITS file from chapter 4.2 is extended by the following section, among others:
    • ramdisk-1 {
    • description = “dm-verity-image-initramfs”;
    • data = /incbin/(“<path/to/Initramfs.cpio.gz>”);
    • type = “ramdisk”;
    • arch = “arm64”;
    • os = “linux”;
    • compression = “none”;
    • load = <0x98000000>;
    • entry = <0x98000000>;
    • hash-1 {
    • algo = “sha256”;
    • };
    • };
  3. Check the integrity of the root partition
    • The initramfs contains a suitable script that generates a device mapper from the root partition and the root hash.
    • veritysetup \
    • –data-block-size=${DATA_BLOCK_SIZE} \
    • –hash-offset=${DATA_SIZE} \
    • create rootfs \
    • </dev/Root-Paritition> \
    • </dev/Root-Paritition> \
    • <Root Hash>

The device mapper is then mounted:

  • mount \
  • -o ro \
  • /dev/mapper/rootfs \
  • /rootfs

Oyod filesistem mung diwaca. Kanggo ngalih menyang ROOT nyata filesistem, nggunakake switch-root.

Automated creation with TQ-BSP
In principle, an image with a chain of trust from the boot loader to the root partition can be created automatically with the TQ-BSP.
For TQMa93xx the following options have to be added to local.conf :

  • # The DISTRO_FEATURE secure necessary config options for U-Boot and Kernel
  • DISTRO_FEATURES:append = ”aman”
  • # Name of the key used for signing the bootloader
  • IMX_HAB_KEY_NAME = “ahab”
  • # Activates the signing of the FIT image in the build process
  • UBOOT_SIGN_ENABLE = “1”
  • # This class contains the logic for creating a protected root partition
  • IMAGE_CLASSES += “dm-verity-img”
  • # Name of the initramfs image for dm-verity handling
  • INITRAMFS_IMAGE = “dm-verity-image-initramfs”
  • # Initramfs is stored as a separate artifact in the image
  • INITRAMFS_IMAGE_BUNDLE = “0”
  • # Store FIT image with initramfs in boot partition
  • IMAGE_BOOT_FILES:append = ” fitImage-${INITRAMFS_IMAGE}-${MACHINE}-
  • ${MACHINE};fitImage” # Image to be protected with dm-verity
  • # Alternative: tq-image-weston-debug
  • DM_VERITY_IMAGE = “tq-image-generic-debug”
  • # Type oft he above image
  • DM_VERITY_IMAGE_TYPE = “ext4”

PERHATIAN: The exact options may change in future versions of the BSP. The latest information can be found in the BSP layer documentation (https://github.com/tq-systems/meta-tq) under meta-tq/doc.

Gambar lengkap digawe nganggo bitbake tq-image-generic-debug lan banjur bisa ditulis menyang kertu SD, kanggo example.

Verifikasi
In Linux, mount -a can be used to check if the Verity Devicemapper is mounted as the root filesistem:

  • #munggah
  • /dev/mapper/rootfs on / type ext4 (ro,relatime)
  • Kajaba iku, kabeh ROOT file sistem mung diwaca ing kasus iki:
  • # touch test
  • touch: cannot touch ‘test’: Read-only file sistem

Kanggo falsification, ROOT file system can be modified offline and the device rebooted. The modification causes a different root hash and the boot process is aborted: device-mapper: verity: 179:98: data block 1 is corrupted

More information about the TQMa93xx can be found in the TQ Support Wiki: https://support.tq-group.com/en/arm/modules#nxp_imx_9_series

TQ-Systems GmbH
Mühlstraße 2 l Gut Delling l 82229 Seefeld Info@TQ-Group | TQ-Group

Pitakonan sing Sering Ditakoni

P: Apa bisa mbalikke proses nyetel Sekring sing ora bisa dibatalake sing kasebut ing How-to?
A: No, setting Fuses is irreversible. It is recommended to use a development pattern.

P: Ing endi aku bisa nemokake sumber sing dibutuhake kanggo Linux lan U-Boot?

A: Linux:
Repositori Linux

U-Boot: U-Boot
Repositori

Dokumen / Sumber Daya

TQ TQMa93 Boot Aman [pdf] Pandhuan pangguna
TQMa93xx, TQMa93 Boot Aman, Boot Aman, Boot

Referensi

Ninggalake komentar

Alamat email sampeyan ora bakal diterbitake. Kolom sing dibutuhake ditandhani *