Signed AHAB Image Generation for U-Boot and Kernel#
In this notebook, we’ll demonstrate a proof-of-concept on how to:
Generate signed AHAB U-Boot and kernel images
Replace the unsigned AHAB U-Boot in the
wicfileReplace the unsigned kernel image with a signed version
Boot up the system with authenticated images
1. Prerequisites#
SPSDK is needed with examples extension.
pip install spsdk[examples](Please refer to the installation documentation.)This demo was tested with an i.MX95 FRDM and
Linux 6.18.20-2.0.0
1.1 Images preparation#
to create the resulting binary containing AHAB containers, we need to prepare the binaries
in this section we reproduce the process which is done by the
imx-mkimagetool as a flash singleboot binaryObtain all the necessary binaries and put them into the
inputsdirectory
1.2 U-Boot#
In order to enable secure boot, U-Boot must be built with AHAB support. CONFIG_AHAB_BOOT=y
If you want to use nxpele over fastboot, also multiplexing of console output to fastboot must be enabled by setting CONFIG_CONSOLE_MUX=y.
As building a (signed) bootloader image for i.MX95 is already explained in the i.MX95 signed AHAB with U-BOOT example, we skip the details here.
1.3 Requirements#
lpddr4 firmware files
u-boot binary (u-boot SPL and u-boot) built with AHAB support
bl31.bin binary (ARM Trusted Firmware)
ELE firmware binary
Kernel image (
Image-imx95evk.bin)Device tree blob (
imx95-15x15-frdm.dtb)Bootable disk image
.wicfile for the i.MX95 EVK boardFour ECC keys and four ML-DSA keys (shared example keys are used from
_data/keys/ecc384and_data/keys/mldsa65)i.MX95 FRDM board itself
from spsdk.utils.jupyter_utils import YamlDiffWidget
# This env variable sets colored logger output to STDOUT
%env JUPYTER_SPSDK=1
%alias execute echo %l && %l
%alias_magic ! execute
env: JUPYTER_SPSDK=1
Created `%!` as an alias for `%execute`.
2 Building the AHAB Images#
We first build the bootloader image, then we build the Kernel image with DTB.
U_BOOT_FLASH_BOOT_CONFIG = "./inputs/configs/bootimg_signed_mx95_serial_downloader.yaml"
U_BOOT_FLASH_BOOT = "./outputs/imx95-ahab-uboot-signed.bin"
%! nxpimage -v bootable-image export --config $U_BOOT_FLASH_BOOT_CONFIG --output $U_BOOT_FLASH_BOOT
nxpimage -v bootable-image export --config ./inputs/configs/bootimg_signed_mx95_serial_downloader.yaml --output ./outputs/imx95-ahab-uboot-signed.bin
WARNING:spsdk.apps.utils.common_cli_options:The --output option is deprecated. Define 'output' in the configuration file. (882ms since start, common_cli_options.py:896)
INFO:spsdk.apps.nxpimage_apps.nxpimage_bimg:Created Bootable Image:
Name: Bootable Image for mimx9596, Revision: latest
Starts: 0x0
Ends: 0x2b3fff
Size: Size: 2.7 MiB; 2,834,432 B
Alignment: 1 B
Execution Start Address: Not defined
Pattern:zeros
Memory type: MemoryType.SERIAL_DOWNLOADER
Format: bin
INFO:spsdk.apps.nxpimage_apps.nxpimage_bimg:Created Bootable Image memory map:
+==0x0000_0000= Bootable Image for mimx9596, Revision: latest ==+
| Size: 2.7 MiB; 2,834,432 B |
| Memory type: MemoryType.SERIAL_DOWNLOADER |
| Pattern: zeros |
|+==0x0000_0000= primary_image_container_set ==================+|
|| Size: 860.0 kiB; 880,640 B ||
|+==0x000d_6fff================================================+|
|+==0x000d_7000= secondary_image_container_set ================+|
|| Size: 1.9 MiB; 1,953,792 B ||
|+==0x002b_3fff================================================+|
+==0x002b_3fff==================================================+
Success. (Bootable Image: outputs/imx95-ahab-uboot-signed.bin created)
The Kernel and Device tree blob AHAB image is also very simple, and signing works in a similar fashion.
KERNEL_CONTAINER_CONFIG = "./inputs/configs/mx95_signed_kernel_dtb.yaml"
KERNEL_CONTAINER = "./outputs/os_cntr_signed.bin"
YamlDiffWidget("./inputs/diffs/mx95_signed_kernel_dtb.diffc").html
%! nxpimage -v ahab export -c $KERNEL_CONTAINER_CONFIG
nxpimage -v ahab export -c ./inputs/configs/mx95_signed_kernel_dtb.yaml
INFO:spsdk.crypto.keys:Legacy ML-DSA private key detected. SPSDK loaded this expanded-secret format via spsdk_pqc compatibility mode.
INFO:spsdk.crypto.keys:Legacy ML-DSA private key detected. SPSDK loaded this expanded-secret format via spsdk_pqc compatibility mode.
INFO:spsdk.image.ahab.ahab_iae:Image (Linux Kernel Image) size 35678720 bytes adjusted to 35679232 bytes
INFO:spsdk.image.ahab.ahab_iae:Image (Device Tree Blob) size 96394 bytes adjusted to 97280 bytes
INFO:spsdk.image.ahab.ahab_image:AHAB Image Offset has been updated in serial downloader mode.
INFO:spsdk.image.ahab.ahab_image:AHAB Image Offset Updates:
INFO:spsdk.image.ahab.ahab_image:+-----------+-------+------------+------------+------------+-----------+---------+
INFO:spsdk.image.ahab.ahab_image:| Container | Image | Old Offset | New Offset | Image Size | Gap After | Action |
INFO:spsdk.image.ahab.ahab_image:+-----------+-------+------------+------------+------------+-----------+---------+
INFO:spsdk.image.ahab.ahab_image:| 0 | 0 | 0x0 | 0xC000 | 0x2206C00 | 0x0 | UPDATED |
INFO:spsdk.image.ahab.ahab_image:| 0 | 1 | 0x0 | 0x2212C00 | 0x17C00 | 0x0 | UPDATED |
INFO:spsdk.image.ahab.ahab_image:+-----------+-------+------------+------------+------------+-----------+---------+
INFO:spsdk.image.ahab.ahab_image:Summary: 2 updated, 0 preserved, 0 locked
INFO:spsdk.apps.nxpimage_apps.nxpimage_ahab:Created AHAB Image:
Name: AHAB Image
Starts: 0x0
Ends: 0x222a7ff
Size: Size: 34.2 MiB; 35,825,664 B
Alignment: 1 B
Execution Start Address: Not defined
Pattern:zeros
AHAB Image for mimx9596, Revision: latest
INFO:spsdk.apps.nxpimage_apps.nxpimage_ahab:Created AHAB Image memory map:
+==0x0000_0000= AHAB Image ============+
| Size: 34.2 MiB; 35,825,664 B |
| AHAB Image for mimx9596, Revision: |
| latest |
| Pattern: zeros |
|+==0x0000_0000= AHAB Containers =====+|
|| Size: 48.0 kiB; 49,152 B ||
|| AHAB Containers block ||
|| Pattern: zeros ||
||+==0x0000_0000= AHAB Container 0 ==+||
||| Size: 6.2 kiB; 6,400 B |||
||| AHAB Container for oem_SWver:0 |||
||+==0x0000_18ff=====================+||
|+==0x0000_bfff=======================+|
|+==0x0000_c000= Linux Kernel Image ==+|
|| Size: 34.0 MiB; 35,679,232 B ||
||AHAB data block for cortex-a55 core ||
|| and executable Image Type. ||
|+==0x0221_2bff=======================+|
|+==0x0221_2c00= Device Tree Blob ====+|
|| Size: 95.0 kiB; 97,280 B ||
||AHAB data block for cortex-a55 core ||
|| and data Image Type. ||
|+==0x0222_a7ff=======================+|
+==0x0222_a7ff=========================+
Success. (AHAB: outputs/os_cntr_signed.bin created.)
INFO:spsdk.image.ahab.ahab_container:Generated file containing SRK hash: outputs/ahab_oem0_srk0_hash.txt
INFO:spsdk.image.ahab.ahab_container:
Fuses info:
--== Grouped register name: SRKH ==--
OTP ID: 128, Value: 0xD1169A45
OTP ID: 129, Value: 0xFD8F4B6B
OTP ID: 130, Value: 0x83DE38B4
OTP ID: 131, Value: 0x6E888094
OTP ID: 132, Value: 0x2B81E39C
OTP ID: 133, Value: 0x58FA4354
OTP ID: 134, Value: 0x38AACE56
OTP ID: 135, Value: 0x86BB9065
OTP ID: 136, Value: 0x3A0AF22F
OTP ID: 137, Value: 0x37F1AD83
OTP ID: 138, Value: 0x65D67226
OTP ID: 139, Value: 0xEF499B47
OTP ID: 140, Value: 0x1EDD5BDE
OTP ID: 141, Value: 0xA0F3FC02
OTP ID: 142, Value: 0x9EF40AFD
OTP ID: 143, Value: 0xE80560D0
INFO:spsdk.image.ahab.ahab_container:Generated script for writing fuses for container 0: outputs/ahab_oem0_srk0_hash_nxpele.bcf
INFO:spsdk.image.ahab.ahab_container:Generated file containing SRK hash: outputs/ahab_oem0_srk1_hash.txt
INFO:spsdk.image.ahab.ahab_container:
Fuses info:
--== Grouped register name: PQC_SRKH ==--
OTP ID: 448, Value: 0xD7D93F6A
OTP ID: 449, Value: 0x1B88598F
OTP ID: 450, Value: 0xE66945BB
OTP ID: 451, Value: 0x62A150D1
OTP ID: 452, Value: 0x24D0DCD2
OTP ID: 453, Value: 0x0F7422B0
OTP ID: 454, Value: 0xF3997E69
OTP ID: 455, Value: 0xA1742B47
OTP ID: 456, Value: 0xC75BC618
OTP ID: 457, Value: 0x2A2EC4EA
OTP ID: 458, Value: 0x4AAA6221
OTP ID: 459, Value: 0x68E3904A
OTP ID: 460, Value: 0x3AF18FA8
OTP ID: 461, Value: 0x28BE2F2A
OTP ID: 462, Value: 0x7243E7AD
OTP ID: 463, Value: 0xE3E08DC8
INFO:spsdk.image.ahab.ahab_container:Generated script for writing fuses for container 0: outputs/ahab_oem0_srk1_hash_nxpele.bcf
Exporting AHAB fuses to the output directory.
outputs/ahab_oem0_srk0_hash.txt
outputs/ahab_oem0_srk0_hash_nxpele.bcf
outputs/ahab_oem0_srk1_hash.txt
outputs/ahab_oem0_srk1_hash_nxpele.bcf
3 Image Download#
First we will download the WIC image onto the board, which by default comes with an unsigned bootloader and Linux kernel (amongst other things like the root filesystem, software, etc.)
It is possible to replace U-Boot with a signed one in the .wic file, but the issue with that is that once we do that, the system won’t boot, because the signed bootloader will also expect a signed kernel image with a device tree blob.
For completeness the script below would replace the old U-Boot with the new signed one:
WIC = "./dist/imx-image-full-imx95evk.wic"
nxpimage bootable-image wic update-uboot -b $WIC -u $U_BOOT_FLASH_BOOT
To download the WIC image onto the board we can use the SPSDK utility nxpuuu. As the WIC image often has a size of several gigabytes, this process can take several minutes.
We set our i.MX95 board into serial download mode, then use the following command:
WIC = "./dist/imx-image-full-imx95evk.wic"
VERBOSITY = "-v"
%! nxpuuu write $VERBOSITY -f mimx9596 -b emmc_all $U_BOOT_FLASH_BOOT $WIC
nxpuuu write -v -f mimx9596 -b emmc_all ./outputs/imx95-ahab-uboot-signed.bin ./dist/imx-image-full-imx95evk.wic
WARNING:spsdk.image.bootable_image.bimg:Multiple possible memory types detected: "Serial downloader", "embedded MultiMediaCard", "eMMC Boot area", "SD card", "Recovery SPI".The "Serial downloader" memory type will be used. (1298ms since start, bimg.py:643)
Success
4 Bootloader replacement#
Now that we have uploaded the .wic image onto the board, we can proceed with replacing the bootloader with the signed one, as we did not modify the .wic image.
Since we just uploaded the .wic image onto the board, we should still be in serial download mode.
The following command writes the new bootloader onto the emmc:
%! nxpuuu write -f mimx9596 -b emmc $U_BOOT_FLASH_BOOT
nxpuuu write -f mimx9596 -b emmc ./outputs/imx95-ahab-uboot-signed.bin
Success
5 Kernel replacement#
Now that we uploaded the signed bootloader, namely U-Boot which now expects a signed kernel image named os_cntr_signed.bin in the FAT partition, we need to upload it.
import os
KERNEL_SIZE = hex(os.path.getsize(KERNEL_CONTAINER))
FASTBOOT_BUFFER_ADDRESS = hex(
0xA8000000
) # This is the address which shows when you `echo ${cntr_addr}`
MMCDEV = 0
MMCPART = 1
# We turn on the u-boot console multiplexing into terminal so that we are able to see the output
%! nxpuuu run "FB: ucmd setenv stdout serial,fastboot"
# We set the fastboot buffer to a known address we have access to, in this case 0xA8000000
%! nxpuuu run "FB: ucmd setenv fastboot_buffer $FASTBOOT_BUFFER_ADDRESS"
# Download the kernel
%! nxpuuu run "FB: download -f $KERNEL_CONTAINER"
# Write the kernel to the FAT partition, these parameters may vary if we use an SD card etc.
%! nxpuuu run "FB: ucmd fatwrite mmc $MMCDEV:$MMCPART $FASTBOOT_BUFFER_ADDRESS os_cntr_signed.bin $KERNEL_SIZE"
nxpuuu run "FB: ucmd setenv stdout serial,fastboot"
Response: Detect USB boot. Will enter fastboot mode!
(NULL udevice *): request 00000000fdee2980 was not queued to ep1in-bulk
Success
nxpuuu run "FB: ucmd setenv fastboot_buffer 0xa8000000"
Response: Detect USB boot. Will enter fastboot mode!
(NULL udevice *): request 00000000fdee2980 was not queued to ep1in-bulk
Success
nxpuuu run "FB: download -f ./outputs/os_cntr_signed.bin"
Response: Starting download of 35825664 bytes
(NULL udevice *): request 00000000fdee2980 was not queued to ep1in-bulk
..........................................................................
..........................................................................
..........................................................................
...................................................
downloading of 35825664 bytes finished
(NULL udevice *): request 00000000fdee2980 was not queued to ep1in-bulk
Success
nxpuuu run "FB: ucmd fatwrite mmc 0:1 0xa8000000 os_cntr_signed.bin 0x222a800"
Response: 35825664 bytes written in 184 ms (185.7 MiB/s)
Detect USB boot. Will enter fastboot mode!
(NULL udevice *): request 00000000fdee2980 was not queued to ep1in-bulk
Success
We can now delete the old unsigned kernel. Note that this step is optional, but the signed bootloader should not be loading an unsigned kernel by default.
%! nxpuuu -v run "FB: ucmd fatrm mmc 0:1 Image"
nxpuuu -v run "FB: ucmd fatrm mmc 0:1 Image"
Response: Detect USB boot. Will enter fastboot mode!
(NULL udevice *): request 00000000fdee2980 was not queued to ep1in-bulk
Success
We can list the fat partition and see the various device tree blobs, other binaries, and most importantly our os_cntr_signed.bin file.
%! nxpuuu -v run "FB: ucmd fatls mmc 0:1"
nxpuuu -v run "FB: ucmd fatls mmc 0:1"
Response: 66417 imx95-15x15-ab2.dtb
99267 imx95-15x15-evk-adv7535-ap1302.dtb
96570 imx95-15x15-evk.dtb
77273 imx95-15x15-frdm-8mic-reve.dtb
98239 imx95-15x15-frdm-ap1302.dtb
79216 imx95-15x15-frdm-aud-hat.dtb
76318 imx95-15x15-frdm-boe-wxga-lvds-panel.dtb
97763 imx95-15x15-frdm-dual-os08a20-isp.dtb
96530 imx95-15x15-frdm-neutron.dtb
97151 imx95-15x15-frdm-os08a20-combo-isp.dtb
97083 imx95-15x15-frdm-os08a20-isp.dtb
96478 imx95-15x15-frdm-root.dtb
75076 imx95-15x15-frdm-rpmsg.dtb
97518 imx95-15x15-frdm-waveshare-7inch-c-panel.dtb
96394 imx95-15x15-frdm.dtb
101879 imx95-19x19-evk-adv7535-ap1302.dtb
100041 imx95-19x19-evk-adv7535.dtb
2931 imx95-19x19-evk-adv7535.dtbo
101111 imx95-19x19-evk-ap1302.dtb
4300 imx95-19x19-evk-ap1302.dtbo
100327 imx95-19x19-evk-cs42888.dtb
3429 imx95-19x19-evk-cs42888.dtbo
101850 imx95-19x19-evk-dsi-serdes-jdi-wuxga-panel.dtb
4848 imx95-19x19-evk-dsi-serdes-jdi-wuxga-panel.dtbo
100994 imx95-19x19-evk-dsi-serdes.dtb
3933 imx95-19x19-evk-dsi-serdes.dtbo
101179 imx95-19x19-evk-dual-os08a20-isp-it6263-lvds0.dtb
99980 imx95-19x19-evk-it6263-lvds-dual.dtb
2779 imx95-19x19-evk-it6263-lvds-dual.dtbo
100166 imx95-19x19-evk-it6263-lvds-two-disp.dtb
99810 imx95-19x19-evk-it6263-lvds0.dtb
2454 imx95-19x19-evk-it6263-lvds0.dtbo
99810 imx95-19x19-evk-it6263-lvds1.dtb
2454 imx95-19x19-evk-it6263-lvds1.dtbo
100262 imx95-19x19-evk-jdi-wuxga-lvds-panel.dtb
2728 imx95-19x19-evk-jdi-wuxga-lvds-panel.dtbo
99266 imx95-19x19-evk-jtag.dtb
230 imx95-19x19-evk-jtag.dtbo
77468 imx95-19x19-evk-lpspi-slave.dtb
101803 imx95-19x19-evk-lt9611uxc-ap1302.dtb
99965 imx95-19x19-evk-lt9611uxc.dtb
2840 imx95-19x19-evk-lt9611uxc.dtbo
74440 imx95-19x19-evk-netc-rpmsg.dtb
99398 imx95-19x19-evk-neutron.dtb
100019 imx95-19x19-evk-os08a20-combo.dtb
3274 imx95-19x19-evk-os08a20-combo.dtbo
100631 imx95-19x19-evk-os08a20-dual.dtb
100499 imx95-19x19-evk-os08a20-isp-it6263-lvds0.dtb
101535 imx95-19x19-evk-os08a20-isp-lvds-two-disp.dtb
99951 imx95-19x19-evk-os08a20.dtb
2761 imx95-19x19-evk-os08a20.dtbo
105112 imx95-19x19-evk-ox03c10-all.dtb
102284 imx95-19x19-evk-ox03c10-combo.dtb
6156 imx95-19x19-evk-ox03c10-combo.dtbo
102760 imx95-19x19-evk-ox03c10-isp-it6263-lvds0.dtb
102212 imx95-19x19-evk-ox03c10.dtb
5583 imx95-19x19-evk-ox03c10.dtbo
100015 imx95-19x19-evk-ox05b1s-combo.dtb
3238 imx95-19x19-evk-ox05b1s-combo.dtbo
100495 imx95-19x19-evk-ox05b1s-isp-it6263-lvds0.dtb
101527 imx95-19x19-evk-ox05b1s-isp-lvds-two-disp.dtb
99947 imx95-19x19-evk-ox05b1s.dtb
2725 imx95-19x19-evk-ox05b1s.dtbo
99286 imx95-19x19-evk-pcie1-ep.dtb
592 imx95-19x19-evk-pcie1-ep.dtbo
99932 imx95-19x19-evk-rm692c9.dtb
2680 imx95-19x19-evk-rm692c9.dtbo
99346 imx95-19x19-evk-root.dtb
100570 imx95-19x19-evk-rpmsg.dtb
78606 imx95-19x19-evk-sof.dtb
103333 imx95-19x19-evk-ti-serdes-combo.dtb
7812 imx95-19x19-evk-ti-serdes-combo.dtbo
103265 imx95-19x19-evk-ti-serdes.dtb
7295 imx95-19x19-evk-ti-serdes.dtbo
78223 imx95-19x19-evk-tja1104-rgmii.dtb
78133 imx95-19x19-evk-tja1104-rmii.dtb
99262 imx95-19x19-evk.dtb
97464 imx95-19x19-frdm-pro-aqr113c.dtb
79416 imx95-19x19-frdm-pro-aud-hat.dtb
98084 imx95-19x19-frdm-pro-dual-os08a20-isp.dtb
5039 imx95-19x19-frdm-pro-inmate.dtb
96851 imx95-19x19-frdm-pro-neutron.dtb
97472 imx95-19x19-frdm-pro-os08a20-combo-isp.dtb
97404 imx95-19x19-frdm-pro-os08a20-isp.dtb
96799 imx95-19x19-frdm-pro-root.dtb
97839 imx95-19x19-frdm-pro-waveshare-7inch-c-panel.dtb
96715 imx95-19x19-frdm-pro.dtb
5039 imx95-jailhouse-inmate.dtb
mcore-demos/
623016 tee.bin
1212432 xen
35825664 os_cntr_signed.bin
91 file(s), 1 dir(s)
Detect USB boot. Will enter fastboot mode!
(NULL udevice *): request 00000000fdee2980 was not queued to ep1in-bulk
Success
6 Boot of authenticated container#
Now that everything is done, we can change the boot mode to EMMC and see that the authenticated container is booting.
To check if the authenticated container is being booted, we deleted the original unsigned kernel Image.
During the boot we should see the following message in the console:
Running BSP bootcmd ...
switch to partitions #0, OK
mmc0(part 0) is current device
Failed to load 'boot.scr'
35807506 bytes read in 132 ms (258.7 MiB/s)
Booting from mmc ...
Authenticate OS container at 0x98000000
mu receive msg wait 1s
mu receive msg wait 2s
## Flattened Device Tree blob at 83000000
Booting using the fdt blob at 0x83000000
Working FDT set to 83000000
Using Device Tree in place at 0000000083000000, end 000000008300dfbc
Working FDT set to 83000000
Starting kernel ...
[ 0.000000] Booting Linux on physical CPU 0x0000000000 [0x412fd050]
U-Boot should authenticate and start the kernel automatically, but if it does not, or if you did not download the .wic with the root filesystem onto the board, you can run the command run bootcmd in the U-Boot console, which should read the os_cntr_signed.bin from the FAT partition, authenticate it, and start executing it.