The problem: a field device anyone can pick up
An energy-monitoring device in the field is physically exposed: whoever holds it can read out the flash, replace the bootloader or flash a tampered image. Passwords and SSH hardening alone do not protect against manipulation of the software itself - they secure access, not the integrity of the code that runs.
The starting point is a concrete, already-shipped system: an NXP i.MX6-family SoC (Cortex-A7, with CAAM), 256 MB RAM, the bootloader in a 1 MiB SPI-NOR, the rootfs as UBIFS on 256 MiB raw NAND (UBI), an 8 GB eMMC for data. The vendor BSP is based on the mainline kernel, not NXP linux-imx; the build uses Yocto Kirkstone, U-Boot 2024.01 and kernel 6.1. A fleet of these devices is deployed - so security must be retrofittable without opening every unit.
Regulation makes this urgent: the EU Cyber Resilience Act (CRA) demands security by design and demonstrable vulnerability handling for products with digital elements; ISO/IEC 27400 and NIST 8259 provide guardrails for IoT security. An unbroken chain of trust from power-on to the root filesystem is one of the most effective controls against persistent tampering.
Three terms are often confused: secure boot ensures that only signed, trusted components are loaded until the operating system starts. Verified boot goes further and checks authenticity and integrity of every boot stage - the full chain of trust. Measured boot records and assesses the boot process, detecting deviations without necessarily preventing them. This article describes verified boot - as a case study along a real, anonymized implementation.
- Only signed software boots - from power-on to userspace, no gap in the chain.
- Data at rest is encrypted; the key never sits in plaintext on the device.
- The device stays updatable in the field: signed updates, A/B partitions, rollback.
- Existing devices are migratable - without USB access, which is locked in production.
- The development workflow stays workable: a development image close to the production image.
- The writable surface is minimal - an almost fully writable rootfs is not hardening.
The solution space: the chain and its alternatives
On i.MX6 the boot ROM authenticates the first loaded code (the SPL) using NXP High Assurance Boot (HABv4). HAB is RSA-based and anchored in ROM; once the corresponding eFuses are programmed it cannot be altered. The SPL verifies the signed U-Boot, and U-Boot verifies the signed fitImage (kernel plus device tree). Each stage authenticates the next before handing over control.
A signed bootloader alone, however, leaves the rootfs as an open flank: anyone who can write the flash can swap the rootfs without touching the HAB chain. So the chain must reach the rootfs. There are two kernel mechanisms for this: dm-verity lays a sha256 hash tree over a block device and verifies every block on read (read-only, a single signed root hash as the trust anchor); IMA/EVM instead measures and appraises per file and also works on writable filesystems. dm-verity was chosen - a simpler anchor, read-only by design. Important: without encryption, IMA/EVM is vulnerable to offline attacks (the extended attributes can be wiped offline); dm-verity is not.
The design decisions are thus fixed early: a read-only SquashFS rootfs in an A/B layout, a signed root hash checked by an initramfs compiled into the kernel (making it part of the HAB chain itself), encrypted data on the eMMC and signed RPM updates. The rest of this article works through that chain step by step - with the commands, configuration symbols and failure signatures from the real bring-up.
- Boot ROM → SPL (HABv4, RSA signature)
- SPL → U-Boot (HABv4)
- U-Boot → fitImage: kernel + device tree (HABv4)
- Kernel initramfs → dm-verity root hash (ECDSA signature)
- dm-verity → every rootfs block read (sha256 hash tree)
HABv4 PKI: generating the Super Root Keys
HAB authenticates images through a public key infrastructure: a set of Super Root Keys (SRKs) forms the root. Their combined hash is burnt into the SoC OTP fuses; at runtime HAB checks that the SRK table shipped with the image matches that fuse value. NXP ships the Code Signing Tool (CST), which generates keys, signs CSF data and computes the SRK table. The public NXP documents AN4581 (i.MX Secure Boot on HABv4 Supported Devices) and AN12263 (HABv4 RVT Guidelines) plus the HABv4 API manual in the CST package describe the procedure in full.
The PKI tree is generated with the CST script hab4_pki_tree.sh. Proven parameters: a new CA, RSA-4096, four SRKs with the CA flag set, a long validity period (HAB itself does not check certificate duration). Two text files drive the process: serial (an 8-digit serial number for the certificates) and key_pass.txt (a password, repeated twice, protecting all private keys in PKCS#8 format). The names of the generated certificates reflect the chosen options - pick different values and you must adjust the filenames in the following steps.
Key hygiene is non-negotiable: private keys never belong in a repository. Development keys may live in the build container; production keys are kept offline and strictly separated. The commands below show the pattern with placeholders.
# In the CST keys/ directory: drive the interactive PKI generator
echo 12345678 > serial
echo '<your-password>' > key_pass.txt
echo '<your-password>' >> key_pass.txt
./hab4_pki_tree.sh
# Do you want to use an existing CA key (y/n)?: n
# Do you want to use Elliptic Curve Cryptography (y/n)?: n
# Enter key length in bits for PKI tree: 4096
# Enter PKI tree duration (years): 10
# How many Super Root Keys should be generated? 4
# Do you want the SRK certificates to have the CA flag set? (y/n)?: y
# Private keys -> keys/, X.509 certificates -> crts/The SRK table and fuse values
From the four SRK certificates, srktool produces two artifacts: the SRK table (shipped inside the image) and the fuse table (programmed into the chip). -h 4 selects four hash entries, -d sha256 the algorithm, -f 1 the fuse format. The order of the certificates determines the slot indices - it must match the Source index values used later in the CSF files.
The byte order of the fuse words must be exactly right. A mistake here renders the part unbootable once the security configuration is closed - and fuses are one-time programmable, not correctable. The values are chip-specific; the fuse table from your own srktool run is the only valid source.
# In the CST crts/ directory: SRK table + fuse values from the four SRK certs
srktool -h 4 -t SRK_1_2_3_4_table.bin -e SRK_1_2_3_4_fuse.bin \
-d sha256 -f 1 \
-c SRK1_sha256_4096_65537_v3_ca_crt.pem,SRK2_sha256_4096_65537_v3_ca_crt.pem,\
SRK3_sha256_4096_65537_v3_ca_crt.pem,SRK4_sha256_4096_65537_v3_ca_crt.pemEnabling HAB and reading the build logs
HAB is enabled in the U-Boot configuration (CONFIG_IMX_HAB=y), cleanly as a patch in a dedicated layer. The build with secure-boot support produces four relevant files: SPL, SPL.log, u-boot-ivt.img and u-boot-ivt.img.log. They live in the build folder of the U-Boot recipe.
The image is already 4 KB aligned and the Image Vector Table (IVT) is appended - hence the name u-boot-ivt.img. The HAB blocks data (address, offset, length of the signed region) is in the .log files. These values are taken from the build, not guessed - they are the basis of the [Authenticate Data] blocks in the CSF.
# U-Boot defconfig (patch in your own layer)
CONFIG_IMX_HAB=y
# Build artifacts to collect (from the U-Boot recipe build dir):
# SPL - the secondary program loader
# SPL.log - HAB blocks for the SPL
# u-boot-ivt.img - 4KB-aligned U-Boot with appended IVT
# u-boot-ivt.img.log - HAB blocks for U-BootThe Command Sequence File (CSF)
The Command Sequence File describes what HAB should verify: install the SRK table ([Install SRK]), authenticate the CSF key ([Install CSFK] + [Authenticate CSF]), install the image key ([Install Key]) and finally authenticate the image data ([Authenticate Data]). The Blocks line names the RAM load address, the offset of the signed region inside the image, its length and the image file - straight from the build logs.
The engine here is CAAM. On SoCs without CAAM (such as i.MX6ULL) the engine must be set to SW - this is not just availability but the chip erratum ERR010449 (see AN4581 and the i.MX6ULL errata). The signed CSF binary is produced with cst -i csf.txt -o csf.bin and appended to the image; SPL and U-Boot are then merged into one flashable image. The public U-Boot HABv4 guides (doc/imx/habv4) show the procedure for non-SPL and SPL targets.
[Header]
Version = 4.1
Hash Algorithm = sha256
Engine = CAAM # SW on SoCs without CAAM (e.g. i.MX6ULL, ERR010449)
Engine Configuration = 0
Certificate Format = X509
Signature Format = CMS
[Install SRK]
File = "../crts/SRK_1_2_3_4_table.bin"
Source index = 0 # which SRK slot signs this image
[Install CSFK]
File = "../crts/CSF1_1_sha256_4096_65537_v3_usr_crt.pem"
[Authenticate CSF]
[Install Key]
Verification index = 0
Target index = 2
File = "../crts/IMG1_1_sha256_4096_65537_v3_usr_crt.pem"
[Authenticate Data]
Verification index = 2
# Address Offset Length Data file
Blocks = <load_address> <offset> <length> "u-boot-ivt.img"Layout pitfall 1: padding and the CSF offset
HAB does not forgive layout mistakes. In one real build: actual file size 0xac020, intended size from the image header 0xae060 (712736 bytes plus a 64-byte header = 712800 = 0xae060). The difference 0x2040 is the required CSF_PAD_SIZE - the upstream default is 0x2000, patchable in arch/arm/include/asm/mach-imx/hab.h. The intended size comes from file u-boot-ivt.img; padding is done with objcopy.
Second pitfall: the SPL computes the CSF offset as image size minus CONFIG_CSF_SIZE (arch/arm/mach-imx/spl.c). For the SPL to find the U-Boot image IVT, CONFIG_CSF_SIZE must equal CSF_PAD_SIZE plus the IVT size (0x20) - 0x2060 in the example. This value was only found by debugging; it is in no datasheet.
Third: appending the CSF invalidates the legacy CRC. CONFIG_SPL_LEGACY_IMAGE_CRC_CHECK is therefore disabled - for production, refreshing the CRC after signing is the cleaner path. If you simply drop the check, document that deliberately.
# Intended size from the image header (example values, version string genericized)
file u-boot-ivt.img
# u-boot-ivt.img: u-boot legacy uImage, U-Boot 2024.01, Firmware/ARM,
# (Not compressed), 712736 bytes, Load Address: 0x87800000,
# Entry Point: 0x87800000, Header CRC: 0x........, Data CRC: 0x........
# intended size = 712736 + 64 = 712800 = 0xae060
# Pad the signed image to its intended size
objcopy -I binary -O binary --gap-fill 0x00 --pad-to 0xae060 \
u-boot-ivt.img_signed u-boot-ivt.img_signed_pad
# Related config symbols (keep in sync):
# CSF_PAD_SIZE 0x2040 (arch/arm/include/asm/mach-imx/hab.h)
# CONFIG_CSF_SIZE 0x2060 (= CSF_PAD_SIZE + IVT 0x20)
# CONFIG_SPL_LEGACY_IMAGE_CRC_CHECK offLayout pitfall 2: merging SPL and U-Boot
SPL and U-Boot are merged into one image via objcopy: the SPL sections are stripped, padded to a fixed address and the padded U-Boot image is then concatenated. The SPL expects U-Boot at CONFIG_SYS_SPI_U_BOOT_OFFS - padding and that offset must stay in sync, otherwise the SPL crashes and U-Boot does not start.
And: the SPL is burnt into NOR flash at a 0x400 offset. That offset must be accounted for in CONFIG_SYS_SPI_U_BOOT_OFFS - the 0x400 adds to the padding. The section list below is the one from the real build; depending on the U-Boot version further sections may be needed.
# Merge stripped SPL + padded U-Boot into one flashable image
# (pad address is build-specific; example: 0x10800)
objcopy -j .text -j .secure_text -j .secure_data -j .rodata -j .hash \
-j .data -j .got -j .got.plt -j __u_boot_list -j .rel.dyn \
-j .binman_sym_table -j .text_rest -j .dtb.init.rodata \
-j .efi_runtime -j .efi_runtime_rel \
-I binary -O binary --pad-to=0x10800 SPL_signed u-boot-with-spl.imx
cat u-boot-ivt.img_signed_pad >> u-boot-with-spl.imx
# Keep CONFIG_SYS_SPI_U_BOOT_OFFS in sync with the pad address (+ 0x400 NOR offset)Yocto integration: signing in the build
Signing manually after every build is error-prone. The clean approach is a bbclass in a dedicated layer (e.g. meta-hab) that references CST certificates and keys through variables (CST_CSF_CERT, CST_IMG_CERT, CST_CSF_KEY, CST_IMG_KEY) and provides per-recipe CSF files in recipes-bsp (SPL/U-Boot) and recipes-kernel (fitImage). A normal bitbake run then produces signed images directly.
To swap key paths or certificates, override the variables in the layer configuration. After a key change, rebuild the affected recipes with cleansstate - otherwise old signatures linger in the sstate cache. The same pattern later carries signed RPM updates: the rootfs image is produced as a signed package and verified by the updater.
# meta-hab/classes/hab.bbclass - key/cert references (override in layer conf)
CST_CSF_CERT ?= "${CST_CRT_ROOT}/crts/CSF1_1_sha256_4096_65537_v3_usr_crt.pem"
CST_IMG_CERT ?= "${CST_CRT_ROOT}/crts/IMG1_1_sha256_4096_65537_v3_usr_crt.pem"
CST_CSF_KEY ?= "${CST_CRT_ROOT}/keys/CSF1_1_sha256_4096_65537_v3_usr_key.pem"
CST_IMG_KEY ?= "${CST_CRT_ROOT}/keys/IMG1_1_sha256_4096_65537_v3_usr_key.pem"
# Rebuild signed artifacts after a key change
bitbake u-boot -c cleansstate && bitbake u-boot
bitbake linux -c cleansstate && bitbake linux
bitbake dm-verity-image-initramfs -c cleansstate
bitbake production-imageBurning fuses, hab_status, closing the device
The SRK hash words are programmed from the fuse table into the OTP fuses (i.MX6, using U-Boot fuse numbering: bank 3, words 0-7). This is a one-time operation - once burnt, it cannot be undone. The values are chip-specific; the lines below show only the pattern.
The device then boots in the open state: HAB verifies signatures and logs events but does not yet block. The SPL log shows the authentication ("Authenticate image from DDR location ..."), the U-Boot command hab_status the state. Only when "No HAB Events Found!" appears (configuration 0xf0, state 0x66) is the signature chain demonstrably correct. A single HAB event means: do not close, investigate.
Only now is the device closed: the SEC_CONFIG[1] fuse (i.MX6: bank 0, word 6, value 0x2 - documented in AN4581) enforces signature verification. From this moment the chip only boots correctly signed images; if anything in the chain is wrong, the device is unbootable - a total loss in the field. Hence: test in the open state first, then close. In manufacturing this is an extra step (OTP burning); developer boards stay open so custom images boot.
# SRK hash fuses - YOUR values from SRK_1_2_3_4_fuse.bin (one-time!)
fuse prog 3 0 <srk_word_0>
fuse prog 3 1 <srk_word_1>
# ... words 2..7 ...
# SPL boot log in the open state (HAB verifies, does not block):
# hab fuse not enabled
# Authenticate image from DDR location 0x877fffc0...
# Verify in U-Boot
hab_status
# Secure boot disabled
# HAB Configuration: 0xf0, HAB State: 0x66
# No HAB Events Found!
# Close the device (one-time, irreversible)
fuse prog 0 6 0x2Key rolling and SRK revoke
Being able to rotate keys is part of a robust security concept. HAB allows four SRK slots: an image is signed with slot 0, an update with slot 1. To do this, switch the CSF/IMG certificates and keys in the bbclass to the new files and set the Source index from 0 to 1 in the CSF files. The SRK hash in the fuses stays the same - it covers all four keys.
Compromised keys must be revocable. For this, extend the CSF with an [Unlock] section (Engine = OCOTP, Features = SRK Revoke) and set the SRK_REVOKE fuse (i.MX6: bank 5, word 7; a bit mask per slot: 0x1 for SRK0, 0x2 for SRK1, 0x4 for SRK2). Important: only SRK0-2 are revocable; the fourth slot (SRK3) is the non-revocable reserve - keep it unused.
The safe sequence for field devices: install an update signed with the new key, reboot, validate - and only then revoke the old key. This keeps the device bootable even if the update fails. The order is decisive: revoke first and update later risks an unbootable device.
# In the CSF, after [Authenticate CSF]:
[Unlock]
Engine = OCOTP
Features = SRK Revoke
# Roll to the second SRK slot: set in every CSF (recipes-bsp + recipes-kernel)
Source index = 1
# After the update is validated, revoke the OLD slot-0 key (one-time).
# Mask per slot: SRK0=0x1 SRK1=0x2 SRK2=0x4 (SRK3 not revocable)
fuse prog 5 7 0x1Rootfs verification: the filesystem question
HAB covers SPL, U-Boot, kernel and device tree - the rootfs is the next link. The first hurdle is the existing filesystem: UBIFS on UBI is not a block device and therefore not directly dm-verity-capable. The kernel can expose a UBI volume as a block device (CONFIG_MTD_UBI_BLOCK) and put a SquashFS on top - read-only by design and space-saving.
But: U-Boot reads the fitImage from the rootfs. U-Boot can read SquashFS from block devices (e.g. MMC) but not from a UBI volume - the ubiblock-equivalent path is not mainline (as of 2024.01); the relevant work is a 2023 RFC ("mtd: ubi: Enable accessing RO filesystems in UBI vols"). Three options were evaluated; the decision went to (b): the fitImage is separated from the rootfs into its own raw UBI partitions, the rootfs stays read-only SquashFS. U-Boot then no longer needs to read the rootfs filesystem.
The consequences of (b) are manageable but real: changed U-Boot environment arguments, two new NAND partitions (for A/B), an adapted dnf post-install script and moving the fitImage out of the rootfs. In return U-Boot stays independent of the rootfs type - an advantage that keeps later filesystem changes open.
- (a) Patch a UBI block driver into U-Boot: not mainline, must be maintained with every U-Boot update; no patch fits 2024.01 out of the box. Pro: a single partition for rootfs and kernel.
- (b) Separate the fitImage into its own raw UBI partitions: U-Boot stays independent of the rootfs type. Con: an additional partition in the update mechanism. Chosen.
- (c) Move the rootfs to eMMC/ext4 (read-only): a single partition, but questions about eMMC size and future availability; U-Boot must be able to read eMMC.
Partition layout and first flashing
The NAND layout gets four partitions: root-a/root-b (96 MiB SquashFS each, ~67 MB content) and os-a/os-b (20 MiB raw UBI each for the fitImage, ~13.5 MB). A data/overlay area is created on the eMMC: the sys-overlay partition in NAND was too small, so it moves to the eMMC - as a 3 GiB ext4 partition, with space reserved for future rootfs and U-Boot A/B.
First flashing runs via TFTP from U-Boot. Prerequisites: a U-Boot with verified-boot support, a signed fitImage and a production-image.squashfs.verity. Once signed, the rootfs must not change - otherwise verification fails at boot.
# Create the A/B partition table (in U-Boot)
ubi part rootfs
ubi list
ubi remove <old-partitions>
ubi create root-a 0x6000000 # 96 MiB SquashFS
ubi create root-b 0x6000000
ubi create os-a 0x1400000 # 20 MiB raw UBI (fitImage)
ubi create os-b 0x1400000
# Flash initial rootfs and os (in U-Boot, via TFTP)
tftp 0x80000000 production-image.squashfs.verity
ubi write 0x80000000 root-a 0x${filesize}
tftp 0x82000000 fitImage-signed
ubi write 0x82000000 os-a 0x${filesize}
run vendor_bootcmd # starts the systemdm-verity and the signed root hash
dm-verity lays a sha256 hash tree over a block device and verifies every block on read; the target is read-only. veritysetup format computes the hash tree and root hash. The root hash is signed (here ECDSA P-256) and appended to the rootfs - at a defined offset after the filesystem.
An initramfs compiled into the kernel (and thus HAB-verified itself) carries the public key integrated at build time. It checks a mark at the expected offset, verifies the signature, obtains the root hash, sets up dm-verity, mounts the verified rootfs and hands over to userspace via switch_root. Alternatively the kernel can verify the root hash signature itself against the builtin trusted keyring with DM_VERITY_VERIFY_ROOTHASH_SIG.
The Yocto integration (meta-hab) turns this into a production-image.squashfs.verity and a signed RPM. After a key change, linux, the dm-verity initramfs and the image must be rebuilt with cleansstate. A development key pair may live in the build - production keys never. The kernel documentation (admin-guide/device-mapper/verity) describes the hash tree and parameters in detail.
# Sign the dm-verity root hash (ECDSA P-256; genericized filenames)
openssl ecparam -name prime256v1 -genkey -noout -out verity_priv.pem
openssl ec -in verity_priv.pem -pubout -out verity_public.pem
# Hash tree + root hash (veritysetup, default --hash sha256)
veritysetup format rootfs.squashfs rootfs.hash
# Root hash: <64 hex chars> <- this value is signed and appended
# Rebuild the signed chain after a key change (Yocto)
bitbake -c cleansstate production-image linux dm-verity-image-initramfs
bitbake production-imageWritable paths: overlays, symlinks, data classes
A read-only rootfs needs some writable paths. Two methods: overlayfs (the image ships defaults, modifications shadow them only when actually changed - restore by deleting the upper layer) and symlinks into a dedicated writable area. Each directory gets its own overlay - that gives control over which part of the system can be reset.
A data classification helps: parameters (changeable anytime, reset on factory reset and system update), provisioning (initial setup that must survive a factory reset - keys, cloud endpoints, network configuration) and lifetime (never reset, e.g. working hours). Classified correctly, a factory reset is pure overlay deletion.
The maintainability rule: every recipe that extends write access requires a shared base-files include; for shared system resources only complete after the image is assembled, use a ROOTFS_POSTPROCESS_COMMAND. Changes only for class-target. Typical candidates: /home, /var/cache, /var/lib (the RPM database), configuration in /etc (SSH keys, network, passwd/shadow) and application data.
Honest lesson: initially almost the whole rootfs was made writable to merge quickly - that is not best practice. The list was then deliberately minimized; the migration costs (factory reset, lost configuration, no more system binaries in the overlay, ldconfig can no longer update the cache - then LD_LIBRARY_PATH or an image update). The attack surface should stay minimal.
# Standalone component: move config into the writable area, symlink back
# (genericized; every such recipe requires the shared base-files include)
require recipes-software/application/base-files.inc
DEPENDS:append:class-target = " base-files"
do_install:append:class-target() {
install -d ${D}${writableRoot}${sysconfdir}
mv ${D}${sysconfdir}/mydaemon ${D}${writableRoot}${sysconfdir}/mydaemon
ln -s ${writableRoot}${sysconfdir}/mydaemon ${D}${sysconfdir}/mydaemon
}
FILES:${PN}:append:class-target = " ${sysconfdir}/mydaemon ${writableRoot}${sysconfdir}/mydaemon"
# Shared resource: a ROOTFS_POSTPROCESS_COMMAND (defined in base-files.inc)
base_files_provision_readonly_etc() {
mv ${IMAGE_ROOTFS}${sysconfdir}/passwd ${IMAGE_ROOTFS}${writableRoot}${sysconfdir}
ln -s ${writableRoot}${sysconfdir}/passwd ${IMAGE_ROOTFS}${sysconfdir}/passwd
}
ROOTFS_POSTPROCESS_COMMAND:append = " base_files_provision_readonly_etc;"Encrypted storage: dm-crypt with CAAM keyblobs
Verification protects against tampering, not against read-out. For data at rest, a dm-crypt container is created on the eMMC: an encrypted file unlocked at boot and mounted via a loop device; writable folders are redirected there via overlay. The key must never sit in plaintext - otherwise the whole encryption is pointless.
On i.MX6, CAAM wraps the key with the hardware OTPMK (One-Time-Programmable Master Key) into a keyblob; only the chip itself can unwrap it. This is where the BSP choice determines effort: NXP describes the hidden-key features in AN12714 (i.MX Encrypted Storage Using CAAM Secure Keys) but requires linux-imx. A mainline-based vendor BSP does not ship those drivers. The solution was a deliberate tradeoff: the public caam-keyblob driver plus a userspace blob-handling example - good enough for the security requirement, far less effort than a kernel switch. As a long-term alternative, OP-TEE with PKCS#11 was evaluated (a TPM-like secure enclave; NXP now routes secure keys through OP-TEE/PKCS#11) - more effort, deferred in this phase.
Known residual risk: some i.MX6 chips show a temperature-dependent CAAM RNG hardware error (documented in the NXP community and OP-TEE issue #1408); running mainline means NXP fixes do not arrive automatically. NXP AN12838 (CAAM Secure Key for OpenSSL) also targets vendor BSP kernels; mainline support is limited. Such residual risks belong in the documentation, not hidden.
# CAAM RNG hardware-error signature (temperature-dependent, some i.MX6 chips):
caam_jr 2141000.jr: 2000005b: CCB: desc idx 0: RNG: Hardware error
# The caam-keyblob driver relies on the CAAM RNG, which fails to instantiate
# on affected chips (temperature-dependent). On mainline, NXP fixes for this
# are not integrated automatically.Updates: signed RPMs, A/B, interruption safety
The secure system must remain updatable - otherwise it is not maintainable in the field. Updates ship as signed RPM packages through DNF; the public key lives in the read-only rootfs. The system image (U-Boot, kernel, rootfs) is produced as a signed package; applications are installed and updated separately on the writable area.
A/B means: a new image always lands in the inactive system partition, and the latest configuration becomes active for the updated partition too. The flow is interrupt-safe - with a state log and a retry counter. For kernel panics a watchdog must be enabled from within U-Boot; rollback exists at system and at application level.
A distinction is made between recoverable and non-recoverable failures: power-loss/reboot is recoverable as long as the last successful step is known and a retry counter runs along. Kernel panic/system stall while booting into the new image, failed data migration or an incompatible application package are non-recoverable - here a watchdog reset or a rollback is mandatory. The steps in detail:
- Receive the update job from the backend.
- Flash the new system image into the inactive partition.
- Reboot into the new image.
- Disable the default application start.
- Create backups for rollback.
- Migrate /var/lib/rpm and system configuration.
- Install the new applications (fetched with the update job).
- Start applications in migration mode, then in normal operation.
- Report update-job completion to the backend.
The RPM database trap
/var/lib must be an overlay (the RPM database lives there). After a system-image update, however, the old overlay database shadows the updated system database - and the old database knows the separately installed applications that were added during the device lifetime. It must be made viable again.
A spike showed: rebuilding the database (option 1) or a partial rebuild (option 2) are not feasible. The workable path: delete the overlay RPM database, make the SquashFS database visible again, clean the overlay of binaries and repopulate the database with the needed packages (rpm --justdb). This belongs to every system update that also updates the applications.
# Repopulate the RPM database without reinstalling files or running scripts
rpm --justdb --noscripts --notriggers bash.rpm
rpm -Uvh --justdb bash*rpm
# --justdb update only the database, not the filesystem
# --noscripts do not execute package scriptlets
# --notriggers do not execute trigger scriptletsBootloader update and migrating the fleet
For the bootloader there are three documented paths: from running Linux (SCP to the device, identify the NOR MTD, erase, dd at a 0x400 offset, readback via cmp), via TFTP from U-Boot (sf probe/erase/write) and via UUU/fastboot in serial download mode. The latter is disabled on closed devices - an attack path, since a signed bootloader can be extracted from an update image. Fastboot therefore does not belong in the shipped bootloader.
Existing devices can be migrated, but the procedure is delicate: on production-locked devices USB access is disabled, so the bootloader update must happen from running Linux - a mistake here destroys the device. The path: update the bootloader, repartition from the U-Boot console (A/B), write rootfs and fitImage via TFTP, set up the eMMC, env save, boot. On first start the system creates the encrypted storage and overlays itself; afterwards the signed RPM is installed.
Hardening is staged: the production image carries the final measures prepared but not yet enabled (enabled via a file or the bootloader at provisioning); the development image is close to the production image but without security enabled and with developer utilities. And stay honest: wherever measures are not yet merged or tested, document it - a security concept is only as good as its demonstrable state.
# Bootloader update from running Linux (closed device: USB is off)
mtdinfo -a
# mtd1: Name spi1.0, Type nor, Eraseblock 4096 bytes, 1 MiB total <- the NOR
flash_eraseall /dev/mtd1
dd if=/media/card/flash.bin of=/dev/mtd1 bs=1024 seek=1 # 0x400 offset
# Readback + compare MUST show no difference
dd if=/dev/mtd1 of=/media/card/readback.bin bs=1024 skip=1 count=$(stat -c%s /media/card/flash.bin)
cmp /media/card/flash.bin /media/card/readback.bin -n $(stat -c%s /media/card/flash.bin)
# Sanity: the IVT magic at offset 0x400
dd if=/dev/mtd1 of=/media/card/beginning.bin bs=1 count=1040
hexdump /media/card/beginning.bin
# 0000400 00d1 4020 8000 0090 0000 0000 0000 0000Pitfall checklist
From workshops and practice along the chain of trust, the same candidates keep appearing - check them early and save yourself expensive board bring-ups:
- SPL size: does the signed SPL still fit the available SRAM/boot region?
- Separate boot partition: U-Boot cannot read SquashFS from UBI - separate the fitImage.
- CSF padding: keep CSF_PAD_SIZE, CONFIG_CSF_SIZE and the SPI offset in sync.
- CRC: the legacy CRC is invalid after signing - disable the check or refresh the CRC.
- Key handling: strictly separate development and production keys, never check them in.
- Key rolling: plan SRK slots and the revoke mechanism from the start (SRK3 is not revocable).
- BSP support: mainline BSPs often lack NXP HAB/CAAM features - decide tradeoffs deliberately.
- Manufacturing and rollout: burning fuses is one-way; test open first, then close; plan a migration path for existing devices.
Public literature covers the procedure: NXP AN4581 (i.MX Secure Boot on HABv4 Supported Devices), AN12263 (HABv4 RVT Guidelines and Recommendations), AN12056 (Encrypted Boot on HABv4 and CAAM Enabled Devices), AN12714 (i.MX Encrypted Storage Using CAAM Secure Keys), AN12838 (Strengthening Public Key Cryptography using CAAM Secure Key), the U-Boot HABv4 guides (doc/imx/habv4), the kernel dm-verity and IMA/EVM documentation, and the veritysetup and rpm man pages. On SquashFS support in U-Boot: arXiv 2206.12751. For a deeper dive: the Quarkslab analysis of HAB vulnerabilities shows why a correctly implemented chain is more than just a fuse bit.
The companion article "USB Boot with HAB Signature Verification" continues exactly this chain: a recovery boot from a USB stick that inherits verification instead of bypassing it. The related case study in the work section places the effort in its real engagement context.
