Secure boot on RK3588: a worked example
Note
TL;DR
A detailed walkthrough of the verified boot chain on the Axelera Voyager RK3588 BSP: Rockchip loader signing, SPL FIT verification, AVB for
boot.img, dm-verity for the root filesystem and signed Mender updates.The hardware root of trust below U-Boot is deliberately out of scope: read the Overview and What a production configuration would require sections before reusing this configuration in a product.
This guide documents the security architecture of the Axelera Voyager BSP on RK3588: the verified boot chain, root filesystem integrity, and signed over-the-air updates. It covers how each mechanism is built, how the pieces interact, and what would be required to turn it into a production configuration.
Read this first
This is a working example, not a shipping security feature.
We will not ship with secure boot enabled. Everything from U-Boot upwards is therefore implemented and functional, with development keys deliberately committed to the repository so that a clean kas build produces a bootable, self-consistent demonstration with no external inputs and no per-developer setup.
The hardware root of trust below U-Boot (loader signing and OTP fusing) is not implemented, not tested, and not planned. Without it the chain provides no security guarantee whatsoever, by design. See Overview for what that means concretely and What a production configuration would require for what closing the gap would involve.
Read the rest of this document as “here is how the mechanism works and how you would configure it”, not “here is how this device is secured”.
Overview
Five largely independent mechanisms are involved:
Mechanism |
Protects |
Enforcement point |
|---|---|---|
Rockchip loader secure boot |
|
BootROM, against a hash fused into OTP |
SPL FIT verification |
U-Boot proper, TF-A, OP-TEE |
SPL, against a key in its device tree |
AVB (Android Verified Boot) |
|
U-Boot, against a public key in U-Boot’s device tree |
dm-verity |
root filesystem, per 4 KiB block |
Kernel, against a root hash embedded in the initramfs |
Mender artifact signing |
OTA update payloads |
|
The first one is out of scope; everything else is implemented here.
Chain of trust
The verified boot chain: BootROM, idblock, U-Boot, boot.img and the dm-verity root filesystem.
Important
The chain is anchored at U-Boot, not at the BootROM.
0012-avb-Validate-vbmeta-key-against-U-Boots-dts.patch replaces the
eFuse-based key validation in validate_vbmeta_public_key() with a
comparison against a key in U-Boot’s device tree. That is sound
only if U-Boot itself cannot be replaced, which requires the OTP
to be fused.
That stage is out of scope for this BSP. Anyone with write access to the eMMC can replace the loader and U-Boot with ones carrying their own signatures. Every mechanism documented below is therefore a correctness and integrity mechanism (it detects accidental corruption, interrupted updates and unsigned artifacts) and not a defence against an attacker with physical or root access.
This is a deliberate scope decision, not an oversight. See OTP fusing.
Why AVB and not FIT
Rockchip’s official secure boot documentation presents FIT image signature
verification as the supported mechanism for Linux on RK3588, and describes
AVB as the preferred method for other SoCs but NOT for the RK3588.
This BSP does the opposite: it runs a Linux system through Rockchip’s Android
bootflow (boot.img built with mkbootimg, A/B slots,
vbmeta) and uses AVB to verify it.
This was a deliberate choice, and it was done to maintain the generated image
types and flashing methods used up to now: changing the image to FIT would
have required an entire architectural overhaul.
Two practical consequences follow, and both matter when reading vendor material:
Vendor documentation on this subject should be treated as a starting point, not as authoritative. The claim that AVB is not supported is demonstrably not true on this platform, thanks to our work and custom patches to allow just that. Where the Rockchip docs and the behaviour observed here disagree, the observed behaviour has been right so far.
This BSP is off the vendor-supported path. Rockchip support for AVB problems on the RK3588 SoC should not be assumed, and BSP bumps may break the patches in AVB: U-Boot modifications without warning. Budget for that at every kernel or U-Boot version bump.
Partition layout
The security work reshaped the GPT substantially. The layout below is the
final state after the introduction of security features, as produced by
meta-axelera/meta-voyager/wic/voyager-gptdisk.wks.in.
Dev |
Name |
Size |
Purpose |
|---|---|---|---|
N/A |
|
N/A |
|
p1 |
|
12M |
U-Boot proper |
p2 |
|
48M |
Slot A |
p3 |
|
48M |
Slot B |
p4 |
|
512K |
AVB bootloader control block. Required by Rockchip’s AVB code to exist; see 0010 - Slot routing for why it is not actually used for slot selection. |
p5 |
|
2M |
Required by the Rockchip bootflow; unused in practice |
p6 |
|
768K |
Signed AVB metadata for slot A |
p7 |
|
768K |
Signed AVB metadata for slot B |
p8 |
|
128K |
U-Boot environment (main) |
p9 |
|
128K |
U-Boot environment (redundant) |
p10 |
|
2048M |
Slot A dm-verity rootfs (ext4 + appended hash tree) |
p11 |
|
2048M |
Slot B dm-verity rootfs |
p12 |
|
128M |
Factory data, mounted at |
p13 |
|
rest |
Persistent data, mounted at |
The environment offset invariant
CONFIG_ENV_OFFSET in environment.cfg is an absolute byte offset that
U-Boot uses before any partition table is parsed. It must land exactly on
the start of env_a. This is a hand-maintained invariant with no build-time
check, and it is the single most common way to break this layout.
The arithmetic for the current layout, with --align 8192 (8 MiB) on
uboot:
uboot 8M -> 20M
boot_a 20M -> 68M (48M)
boot_b 68M -> 116M (48M)
misc 116M -> 116.5M (512K)
security 116.5M -> 118.5M (2M)
vbmeta_a 118.5M -> 119.25M (768K)
vbmeta_b 119.25M -> 120M (768K)
env_a 120M = 0x7800000 <-- CONFIG_ENV_OFFSET
env_b 120.125M = 0x7820000 <-- CONFIG_ENV_OFFSET_REDUND
This is why the series shrank boot_a/boot_b from 32M to 30M when
introducing misc, security and vbmeta_{a,b}: the four new
partitions total exactly 4 MiB, so 2 MiB came out of each boot slot to keep
the environment at 0x5400000. When the boot slots were later grown to 48M
for the verity initramfs, the offsets moved to 0x7800000.
Changing the layout
Partition numbers are hardcoded in seven places. If you renumber anything, work through all of them:
File |
Contains |
|---|---|
|
the layout itself |
|
|
|
|
|
rootfs A/B numbers, data partition number |
|
|
|
|
|
rootfs, boot and vbmeta device paths |
Additionally, avbtool add_hash_footer --partition_size in
linux-rockchip.inc must match the boot_a/boot_b --fixed-size
exactly (currently 50331648 = 48 MiB). A mismatch produces a boot.img
whose footer is written at the wrong offset, and AVB verification fails at
boot with a magic or hash error.
Key material
There are three distinct key roles. Two of them are RSA keypairs used at different boot stages by different tools, so it is best to not confuse them.
Role |
Algorithm |
Tool |
Where the public half lives |
|---|---|---|---|
Loader and U-Boot key |
RSA-2048 |
|
SPL device tree |
AVB root key |
RSA-2048 |
|
In U-Boot’s device tree as
|
Mender artifact key |
RSA (size configurable) |
|
Rootfs, |
Development keys in the tree
Two private keys are committed to the repository:
meta-axelera/recipes-kernel/linux/files/private_key.pem- AVBmeta-axelera/recipes-mender/mender-client/files/dev-private.key- Mender
This is intentional. Keeping them in-tree is what makes the example reproducible: a clean checkout builds, boots and accepts a signed OTA with no key ceremony and no per-developer configuration.
The obvious consequence is that any device built with defaults trusts anyone who has cloned the repository. Given that the chain is unanchored anyway (see Overview), these keys are not the weakest link, but they do mean the repository must be treated as containing no secrets.
Warning
Removing the files later is not sufficient. Both keys are in git history and would have to be treated as permanently compromised, with history rewritten or the repository re-created.
Where the keys come from
Each key is read from a location set in kas/include/base.yaml, under
local_conf_header. For the directories, the file names inside them are
fixed.
Variable |
Points to |
Default |
|---|---|---|
|
A directory containing |
Empty: the loader and U-Boot are not signed, and Rockchip’s prebuilt SPL is used. See Loader and U-Boot signing. |
|
A directory containing |
|
|
A private key file, under any name |
|
|
A public key file, under any name |
|
Paths are resolved inside kas-container, where ${TOPDIR}/.. is the
repository root. Keys that must not be committed belong in
${TOPDIR}/../env/keys/<name>: the env/ directory is ignored by git.
Generating the U-Boot/SPL key
Note that for U-Boot/SPL we do NOT include a development keypair
in the repository.
The reason for this is that these are designed to end up being burned
in the OTP area, which is irreversible.
Please create your own keypair and put it in the env/keys/uboot-spl
directory inside the root dir of our repo.
This env directory is included in .gitignore, and is a place
designed to contain the production keys in a way they won’t be accidentally
included in the repo commits, but still accessible from kas-container
during the build stage.
mkdir -p env/keys/uboot-spl && cd env/keys/uboot-spl
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out dev.key
openssl rsa -in dev.key -pubout -out dev.pubkey
openssl req -batch -new -x509 -key dev.key -out dev.crt
chmod 600 dev.key
mkimage signs with dev.key but takes the public key it embeds
in the SPL from dev.crt, so the three files must belong to the same
key. All three commands below must print the same hash:
openssl rsa -in dev.key -noout -modulus | sha256sum
openssl x509 -in dev.crt -noout -modulus | sha256sum
openssl rsa -pubin -in dev.pubkey -noout -modulus | sha256sum
Warning
Once a board’s OTP is fused with the hash of this key, the board only boots loaders signed with it, permanently. Keep the key, and the signed MASKROM loader built with it, backed up: the loader is the only way to reflash a fused board through MASKROM.
Generating the AVB root key
mkdir -p env/keys/avb
openssl genpkey -algorithm RSA \
-pkeyopt rsa_keygen_bits:2048 \
-outform PEM \
-out env/keys/avb/private_key.pem
Point AXE_AVB_SIGN_KEY_DIR at this key in kas/include/base.yaml
by uncommenting the correct line under avb-signing:
diff --git a/kas/include/base.yaml b/kas/include/base.yaml
index 29a9e24..d6e6f7f 100644
--- a/kas/include/base.yaml
+++ b/kas/include/base.yaml
@@ -180,8 +180,8 @@ local_conf_header:
# AXE_UBOOT_SIGN_KEY_DIR = "${TOPDIR}/../env/keys/uboot-spl"
avb-signing: |
- AXE_AVB_SIGN_KEY_DIR = "${TOPDIR}/../meta-axelera/recipes-kernel/linux/files"
- # AXE_AVB_SIGN_KEY_DIR = "${TOPDIR}/../env/keys/avb"
+ # AXE_AVB_SIGN_KEY_DIR = "${TOPDIR}/../meta-axelera/recipes-kernel/linux/files"
+ AXE_AVB_SIGN_KEY_DIR = "${TOPDIR}/../env/keys/avb"
engineering: |
DISTRO_FEATURES:append = "${@' voyager-dm-verity' if d.getVar('AXE_ENGINEERING_BUILD') != '1' else ''}"
The public part of the key will be automatically extracted by U-Boot’s recipe before embedding it in its device tree.
Generating the Mender artifact key
openssl genpkey -algorithm RSA \
-pkeyopt rsa_keygen_bits:3072 \
-out mender-private.key
openssl rsa -in mender-private.key -pubout -out mender-public.key
Both halves are wired in through kas:
diff --git a/kas/include/base.yaml b/kas/include/base.yaml
index b90ce52..c6e8dd5 100644
--- a/kas/include/base.yaml
+++ b/kas/include/base.yaml
@@ -167,5 +167,5 @@ local_conf_header:
TOOLCHAIN_TARGET_TASK:append = "${@'' if d.getVar('PN') == 'buildtools-tarball' else ' kernel-devsrc'}"
mender: |
- AXE_MENDER_ARTIFACT_SIGN_KEY = "/work/meta-axelera/recipes-mender/mender-client/files/dev-private.key"
- AXE_MENDER_ARTIFACT_PUBKEY = "/work/meta-axelera/recipes-mender/mender-client/files/dev-public.key"
+ AXE_MENDER_ARTIFACT_SIGN_KEY = "path/to/your/mender-private.key"
+ AXE_MENDER_ARTIFACT_PUBKEY = "path/to/your/mender-public.key"
Paths are resolved inside the kas container, so /work is the bind-mounted
repository root. A key held outside the repository must be mounted into the
container explicitly.
AXE_MENDER_ARTIFACT_SIGN_KEY is consumed by voyager-updateimg.bbclass
at artifact-build time and has no default; the class calls bbfatal if it
is empty, so an unsigned artifact cannot be produced by accident.
AXE_MENDER_ARTIFACT_PUBKEY defaults to the shipped development key in
mender-client_3.%.bbappend, which means a missing public key silently
yields a device that trusts the development key. Consider making that default
fatal for production builds.
Loader and U-Boot signing
The SPL verifies U-Boot proper before handing over to it, and every image below the kernel is signed with a single key, so that the same images keep working once the OTP is fused and the BootROM starts verifying the loader as well (see OTP fusing).
What is signed and what verifies it
Image |
Signed by |
Verified by |
|---|---|---|
|
|
SPL, against the public key embedded in its device tree |
|
|
BootROM, only once the OTP is fused |
MASKROM loader ( |
|
BootROM, only once the OTP is fused |
The FIT signature uses SHA-256 with RSA-2048 and PSS padding. mkimage
marks the key as required in the SPL device tree, so the SPL refuses
to boot a uboot.img that is not signed with that key, whether or not
the OTP is fused.
Enabling it
Signing is controlled by AXE_UBOOT_SIGN_KEY_DIR, which
by default is unset.
In Key material, we created the keypair in env/keys/uboot-spl/.
To enable this signing and checking, add the following in
kas/include/base.yaml, under the local_conf_header section:
uboot-signing: |
AXE_UBOOT_SIGN_KEY_DIR = "${TOPDIR}/../env/keys/uboot-spl"
When the variable is set, u-boot-rockchip.bbappend:
sets
RK_UBOOT_SPL, so the SPL is built from source; Rockchip’s prebuilt SPL does not contain our key and cannot verify U-Boot;adds
fit-signature.cfg, which enablesCONFIG_FIT_SIGNATUREandCONFIG_SPL_FIT_SIGNATURE, and enlarges the SPL heap withCONFIG_SPL_SYS_MALLOC_F_LEN=0x200000: the SPL uses the simple allocator, which never frees, and decompressing the images while checking signatures exhausts the default 512 KiB;copies the keys into
${B}/keys, wheremake.shexpects them;repacks the idblock with the SPL built from source and signs it. The base recipe’s
make.sh --idblockpacks Rockchip’s prebuilt SPL and does not sign it.
We also include a patch in u-boot-rockchip required for any of this
to work: without it, mkimage signs with the host OpenSSL’s default
PSS salt length, which newer OpenSSL versions set to the digest length,
while the SPL only accepts the maximum.
The build then fails its own signature check with
invalid pss padding (leftmost byte of db isn't 0x01).
The patch itself forces mkimage to sign with the maximum PSS salt length.
Checking a build
In log.do_compile of u-boot-rockchip, a signed build reports:
Signature check OK
Verifying Hash Integrity ... sha256,rsa2048:dev+
Image(signed, version=0): uboot.img (FIT with uboot, trust...) is ready
Image(signed): rk3588_spl_loader_v1.18.113.bin (with spl, ddr...) is ready
signing idblock ok
An unsigned build reports Image(no-signed) instead.
Checking a board
On the serial console, the SPL reports the OTP enable flag and the result of the signature check:
## Verified-boot: 0
sha256,rsa2048:dev+
Verified-boot: 0 means the OTP enable flag is not set.
dev+ means U-Boot was verified with the key. A uboot.img signed
with a different key is rejected, and the board does not boot:
padding_pss_verify: invalid pss padding (0xbc is missing)
Failed to verify required signature 'key-dev'
SPL: failed to boot from all boot devices
Limits
Until the OTP is fused, the BootROM runs any idblock. Someone able to
write the eMMC can replace the SPL with one that verifies nothing, so
this stage alone is not a root of trust: it protects the SPL to U-Boot
handover against a modified or wrongly signed uboot.img, and it
prepares the images for fusing. Until then, any board can still be
recovered through MASKROM with any loader.
AVB: build-side implementation
Tooling
avbtool comes from python3-avbtool-native. The kernel recipe
uses it to sign boot.img and vbmeta.img, and the U-Boot recipe
uses it to extract the public key to embed it in its device tree.
Both run it with nativepython3.
Image generation
All AVB work happens in do_deploy:append() in linux-rockchip.inc, in
three steps.
1. Build boot.img with the verity ramdisk embedded
${S}/scripts/mkbootimg \
--kernel ${B}/arch/${ARCH}/boot/Image.lz4 \
--ramdisk ${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE}-${MACHINE}.cpio.gz \
--second ${B}/resource.img \
--cmdline "root=PARTUUID=${RK_ROOTDEV_UUID}" \
-o ${DEPLOYDIR}/boot.img
The image is rebuilt by hand rather than reusing the kernel’s own
boot.img because mkbootimg must be given --ramdisk, and because
--cmdline now carries root=. The hardcoded PARTUUID values were
removed from the board device trees’ bootargs in a separate commit so
that this is the single source of truth.
2. Add the AVB hash footer
nativepython3 ${STAGING_BINDIR_NATIVE}/avbtool add_hash_footer \
--image ${DEPLOYDIR}/boot.img \
--partition_name boot \
--partition_size 50331648 \
--algorithm SHA256_RSA2048 \
--key ${AXE_AVB_SIGN_KEY_DIR}/private_key.pem
--partition_name boot (not boot_a) is significant; see
0011 - Descriptor name mismatch.
3. Generate the standalone vbmeta image
nativepython3 ${STAGING_BINDIR_NATIVE}/avbtool make_vbmeta_image \
--include_descriptors_from_image ${DEPLOYDIR}/boot.img \
--padding_size 4096 \
--algorithm SHA256_RSA2048 \
--key ${AXE_AVB_SIGN_KEY_DIR}/private_key.pem \
--output ${DEPLOYDIR}/vbmeta.img
vbmeta.img is the signed root of the AVB metadata: it carries the hash
descriptor extracted from boot.img plus a signature over the whole
structure. It is written to both vbmeta_a and vbmeta_b by the WKS.
An unsigned copy of boot.img is also deployed as unsigned_boot.img
for debugging and lab testing.
Note
This logic originally lived in do_install:append() and was moved to
do_deploy:append() when dm-verity was introduced, because the ramdisk
dependency created a loop through the image recipe.
AVB: U-Boot modifications
Five patches and one config fragment are applied to the Rockchip U-Boot fork.
All are marked Upstream-Status: Inappropriate [oe-specific].
These patches are what makes AVB verification work for a Linux payload rather
than an Android one; see Why AVB and not FIT. They are the most
fragile part of the BSP and the first thing to re-test after any U-Boot
version bump; three of the five touch common/android_bootloader.c.
# |
Patch |
Purpose |
|---|---|---|
0010 |
|
Make AVB read the active slot from the U-Boot environment |
0011 |
|
Strip the A/B suffix before descriptor lookup |
0012 |
|
Replace eFuse key validation with a key embedded in dts |
0013 |
|
64M -> 128M decompression window |
0014 |
|
Stop U-Boot suppressing the initramfs |
secureboot.cfg contains a single option:
CONFIG_ANDROID_AB=y
0010 - Slot routing
Two A/B mechanisms are in play and they disagree:
AVB reads the active slot from the
miscpartition’s bootloader control block, viark_avb_get_current_slot().Mender reads and writes the U-Boot environment variable
mender_boot_part.
Rather than teach Mender to write the misc partition, which
would make the matter extremely complex,
the patch redirects AVB to the environment:
int ab_get_slot_suffix(char *slot_suffix)
{
- /* TODO: get from pre-loader or misc partition */
- if (rk_avb_get_current_slot(slot_suffix)) {
- printf("rk_avb_get_current_slot() failed\n");
- return -1;
- }
+ /* Mender Integration: Override AVB slot selection */
+ ulong part_num = env_get_ulong("mender_boot_part", 10, MENDER_ROOTFS_PART_A_NUMBER);
The patch also allows AVB to write the Mender variables back on a failed boot, so that a boot-loop is broken by the same mechanism Mender uses.
Note the consequence: mender_boot_part holds a rootfs partition number
(10 or 11), and U-Boot derives the boot slot from it. The mapping between
rootfs slot and boot slot is therefore fixed by convention in three places:
this patch, the update module, and the WKS ordering; therefore it is not
expressible as configuration.
MENDER_ROOTFS_PART_A_NUMBER reaches U-Boot through
config_mender_defines.h, generated by meta-mender’s U-Boot integration.
Note
The misc partition still has to exist for the Rockchip AVB code to
initialise, but is no longer consulted for slot selection.
0011 - Descriptor name mismatch
avbtool add_hash_footer --partition_name boot writes a descriptor named
boot. U-Boot, however, passes the physical partition name (boot_a
or boot_b) into android_slot_verify() as the requested partition,
and libavb then fails to find a matching descriptor. The resulting NULL
dereference on the hdr array crashes the boot.
The patch strips the slot suffix before building the request list:
+ char boot_base_partname[PART_NAME_LEN] = {0};
+
+ strncpy(boot_base_partname, boot_partname, sizeof(boot_base_partname) - 1);
+
+ if (slot_suffix && strlen(slot_suffix) >= 2) {
+ /* drop a trailing "_a" / "_b" if present */
+ }
+
const char *requested_partitions[] = {
- boot_partname,
+ boot_base_partname,
The alternative, signing each slot with --partition_name boot_a and
boot_b and generating two vbmeta images, was not taken; it would imply
maintaining two distinct signed boot images per build, which would be identical
in all except the partition_name.
0012 - Embedded public key
In the vendor tree, validate_vbmeta_public_key() and
validate_public_key_for_partition() either validate the key against eFuse
(avb_atx_validate_vbmeta_public_key()) or trust any key, depending on
CONFIG_AVB_VBMETA_PUBLIC_KEY_VALIDATE. In the second case, AVB
verification is a no-op: any correctly formatted vbmeta, signed with any key,
is accepted.
The patch makes both functions compare the key in vbmeta with the
public-key property of the /avb node in U-Boot’s own device tree:
/ {
avb {
u-boot,dm-pre-reloc;
public-key = /incbin/("avb_root_pub.bin");
};
};
The node is defined in arch/arm/dts/axe-avb.dtsi, which the patch includes
from the board device trees: rk3588-antelao-axe-sbc.dts, and
rk3588-evb.dts, which itx-3588j uses. avb_root_pub.bin is generated at
build time from AXE_AVB_SIGN_KEY_DIR, so the key is not part of the U-Boot
source, and the dtsi itself is MIT-licensed.
This allows clients enforcing secureboot to not have to disclose their public
key under the GPL license.
The key must be read from U-Boot’s own device tree. With
CONFIG_USING_KERNEL_DTB, Rockchip’s U-Boot switches gd->fdt_blob to
the kernel’s device tree, which comes from the boot.img being verified: a
key read from there would let any boot.img carry its own trusted key. The
patch reads gd->ufdt_blob instead, which keeps pointing at U-Boot’s device
tree. A missing key, a missing device tree or a length mismatch all leave the
key untrusted; a missing key is reported as:
avb_check_root_pub: No AVB root public key in U-Boot's device tree
The patch also forces the device lock state to locked, since an unlocked
device skips verification entirely. As a consequence, the security
partition’s lock state is ignored, and there is no supported way to unlock a
unit for development.
The key is only as protected as U-Boot itself: it lives in the U-Boot device
tree inside uboot.img, which the SPL verifies only when loader signing is
enabled (see Loader and U-Boot signing), and the SPL is in turn verified
by the BootROM only once the OTP is fused.
0013 - Decompression window
Adding the ramdisk pushed the decompressed image past U-Boot’s default 64 MiB
bootm window:
Uncompressing LZ4 Kernel Image from 0x05480000 to 0x00400000 ...
Image too large(0x4000000 >= 0x4000000): increase CONFIG_SYS_BOOTM_LEN
Raised to 128 MiB.
0014 - Initramfs suppression
Rockchip’s android_bootloader_boot_flow() passes skip_initramfs on the
kernel command line unless it detects Android >= 10 with dynamic partitions.
Since dm-verity setup lives in the initramfs, skipping it means the rootfs
is never mapped:
- if (ab_is_support_dynamic_partition(dev_desc)) {
- mode_cmdline = "androidboot.force_normal_boot=1";
- } else {
- mode_cmdline = "skip_initramfs";
- }
+ /* For Linux dm-verity, do NOT skip_initramfs */
+ mode_cmdline = "androidboot.force_normal_boot=1";
dm-verity
dm-verity presents the rootfs as a read-only device-mapper target whose every
4 KiB block is checked against a Merkle tree at read time. The tree’s root
hash is fixed at build time and baked into the initramfs, which is itself
inside the AVB-verified boot.img.
Kernel configuration
meta-axelera/recipes-kernel/linux/files/security.cfg:
# Options to allow DM Verity
CONFIG_BLK_DEV_DM=y
CONFIG_DM_CRYPT=y
CONFIG_BLK_DEV_CRYPTOLOOP=y
CONFIG_DM_VERITY=y
Note
This configuration came from the Rockchip reference configuration.
Build configuration
diff --git a/meta-axelera/meta-voyager/conf/distro/voyager.conf b/meta-axelera/meta-voyager/conf/distro/voyager.conf
--- a/meta-axelera/meta-voyager/conf/distro/voyager.conf
+++ b/meta-axelera/meta-voyager/conf/distro/voyager.conf
@@ -39,5 +39,10 @@ DISTRO_FEATURES:remove = "vulkan"
+INITRAMFS_IMAGE = "dm-verity-image-initramfs"
+DM_VERITY_IMAGE = "voyager-image-weston"
+DM_VERITY_IMAGE_TYPE = "ext4"
+IMAGE_CLASSES += "dm-verity-img"
dm-verity-img.bbclass (from meta-security) hooks the image type named
by DM_VERITY_IMAGE_TYPE for the recipe named by DM_VERITY_IMAGE, runs
veritysetup format over the ext4 image, appends the hash tree, and
deposits <image>.ext4.verity in IMGDEPLOYDIR. The root hash is picked
up by dm-verity-image-initramfs, whose init script maps the volume.
Warning
DM_VERITY_IMAGE is set to voyager-image-weston specifically. Other
images that include voyager-image.inc will not get a .verity
artifact, but the WKS unconditionally references
${IMAGE_LINK_NAME}.${DM_VERITY_IMAGE_TYPE}.verity. Building a different
image against this WKS will fail at do_image_wic rather than produce
something insecure, but the failure is opaque.
Breaking the dependency loop
The natural dependency graph is circular:
voyager-image-weston:do_image_wic
needs boot.img
needs the verity initramfs
needs the root hash
needs voyager-image-weston's ext4 <-- same recipe
It is resolved by keeping the loop between tasks rather than recipes:
do_image_voyager_updateimg[depends]anddo_image_wic[depends]point at${PN}:do_image_ext4andvirtual/kernel:do_deploy, never atdo_image_complete.IMAGE_FSTYPESandIMAGE_TYPEDEPwere converted away from:appendso that the initramfs recipe can override them:# meta-voyager/recipes-core/images/dm-verity-image-initramfs.bbappend IMAGE_FSTYPES = "cpio.gz" IMAGE_CLASSES = "dm-verity-img" IMAGE_ROOTFS_SIZE = "8192"
Without the hard assignment the initramfs would inherit
wic,voyager-updateimgand friends from the distro and recurse.
Runtime consequences
A verity rootfs is immutable. Everything that used to write to / must be
relocated:
/etcis an overlayfs with its upper layer on/data(p13), assembled byoverlayfs-etc-preinit.sh./factory(p12) holds Mender’sdevice_type./dataholds Mender state and the update staging area./homealso lives in/dataas an overlay, so the user’s home directory can be used as normal.
Any packaging change that installs a file expected to be modified in place will now fail at runtime rather than at build time.
Signed OTA updates
Why the rootfs A/B module was replaced
Mender’s stock rootfs-image update module writes a filesystem image to
the inactive rootfs partition. Under this design that is not sufficient:
The rootfs image is now
ext4 + verity hash tree, and its root hash is baked into the initramfs insideboot.img. Updating the rootfs without updatingboot.imgproduces a hash mismatch and an unbootable slot.boot.imgandvbmeta.imgare no longer shipped inside the rootfs (they moved todo_deploy), so the old post-install script that copied them out of/bootno longer has anything to copy.
We therefore replaced mender-axelera-state-scripts with a custom
update module, mender-voyager-update-module, which ships all three
images together.
Artifact structure
voyager-updateimg.bbclass builds a zstd tarball containing:
<image>.ext4.verity rootfs + hash tree
boot.img signed, with AVB footer and verity initramfs
vbmeta.img signed AVB metadata
contents.json { "boot": ..., "root": ..., "vbmeta": ... }
wrapped in a Mender module-image artifact of type mender-update.
contents.json gives the on-device module the filenames without needing to
guess them from DISTRO_VERSION.
Artifact verification
Verification is configured through mender.conf:
"ArtifactVerifyKey": "/etc/mender/artifact-verify-key.pem"
installed from AXE_MENDER_ARTIFACT_PUBKEY by
mender-client_3.%.bbappend.
The mender.conf split
Mender reads two configuration files: /var/lib/mender/mender.conf
(persistent) and /etc/mender/mender.conf (transient). The BSP previously
installed its own /etc/mender/mender.conf and symlinked the other to it,
so both reads saw the same file. That was harmless until signature checking
was added, at which point:
ERRO[0000] both ArtifactVerifyKey and ArtifactVerifyKeys are set
The fix is to stop overriding the install and let the upstream
mender-client recipe do its own splitting of the mender.conf found in
SRC_URI. The update module compensates by merging both files when it
parses configuration.
Update flow
State |
Action |
|---|---|
|
Stream the tarball into |
|
Unpack, read |
|
Assert |
|
Clear |
|
Restore |
|
Remove the staging directory |
The module reports SupportsRollback: Yes and
NeedsArtifactReboot: Automatic.
Because U-Boot’s AVB slot selection is driven by mender_boot_part
(patch 0010), writing that variable is what switches both the rootfs and
the verified boot slot atomically.
Note
Slot A/B routing depends on fw_setenv writing an environment that
U-Boot can read. The mender_saveenv_canary check in the module exists
to catch a broken integration. Related: mkenvimage is invoked with
-r so the generated u-boot-env.img carries the redundant-environment
flag byte that CONFIG_ENV_OFFSET_REDUND makes U-Boot expect; without
it, every boot logs *** Warning - bad CRC, using default environment
and the Mender variables are silently lost.
What a production configuration would require
This section is not a procedure to follow. It exists so that the distance between the current example and a genuinely secured device is written down and can be estimated, should the requirement ever appear.
Software side
All of this is within the BSP and has been exercised in some form:
Generate AVB, Mender and loader keypairs in an HSM or an offline key store.
Point
AXE_AVB_SIGN_KEY_DIRandAXE_UBOOT_SIGN_KEY_DIRto the directories containing the new keys, and setAXE_MENDER_ARTIFACT_SIGN_KEY/AXE_MENDER_ARTIFACT_PUBKEY(see Where the keys come from).Purge the development keys, treating both as compromised and rewriting history.
Make
AXE_MENDER_ARTIFACT_PUBKEYfatal when unset, rather than defaulting to the development key.
Hardware side
Note that none of this has been attempted:
Sign the
idblock/loader and U-Boot withrk_sign_tool.Flash the signed firmware.
Fuse the OTP with the hash of the loader public key.
Confirm that a device flashed with an unsigned or differently-signed loader now refuses to boot.
OTP fusing
Warning
Fusing is irreversible. A unit fused with the wrong key hash, or fused before the corresponding signed loader is in place, is permanently bricked. Any attempt at this must start on sacrificial hardware.
This flow has not been run by the BSP team and is not documented here. Follow the official Rockchip secure boot documentation for RK3588, which is the authoritative source for it.
In rough outline, so that the shape of the work is visible:
a keypair is generated with rk_sign_tool, used to sign the
idblock/loader and U-Boot; the signed firmware is flashed; and the loader
writes the hash of the public key into OTP, after which the BootROM enforces
it. The exact tool invocations, key directory layout, whether secure boot
must be enabled as a separate fuse, and the RK3588-specific caveats are all
things to take from the vendor documentation rather than from this page.
Note
Vendor documentation on this platform has already proven inaccurate in at least one respect; see Why AVB and not FIT. Verify each step against observed hardware behaviour rather than assuming the document is correct, and expect the loader-signing flow to need the same kind of investigation the AVB work did.
Verification
Boot chain
Confirm AVB verified the boot image and that initramfs was not skipped:
cat /proc/cmdlineExpect to find the following:
androidboot.verifiedbootstate=green androidboot.veritymode=enforcing root=PARTUUID=...
And
skip_initramfsto be absent (see 0014 - Initramfs suppression above).Note
verifiedbootstateis the most useful single indicator. U-Boot sets it togreenonly when the vbmeta signature validated against the key in the device tree and every hash descriptor matched.orangemeans verification was skipped because the device reported itself unlocked; since patch 0012 - Embedded public key is meant to make this impossible, treat it as that patch having stopped working rather than as a configuration problem.redmeans verification ran and failed.veritymode=enforcingconfirms dm-verity will fail on a hash mismatch rather than merely logging it.
Root filesystem integrity
Check device-mapper came up at all:
dmesg | grep -i "device-mapper"Expect an
ioctl ... initialisedline. If this is missing, nothing below will work and the kernel configuration is the place to look for mistakes.Check
dm-verityis initialised:dmesg | grep -i "device-mapper: verity"Which should output something similar to this:
[ 6.136278] device-mapper: verity: sha256 using implementation "sha256-ce"And check that the rootfs is correctly mounted:
findmnt /The root mount should be a
/dev/mapperdevice and read-only, something like:TARGET SOURCE FSTYPE OPTIONS / /dev/mapper/rootfs ext4 ro,relatime,seclabel
The source must be a
/dev/mappernode.Note
A raw
/dev/mmcblk*source means the initramfs fell through to mounting the backing partition directly, so dm-verity is not in the path at all. The rootfs would still appear read-only in that case, so this check cannot be replaced by looking at the mount options alone.Confirm the mapped device is a verity target and not some other device-mapper type:
cat /sys/block/$(basename $(readlink -f /dev/mapper/rootfs))/dm/uuidExpect a
CRYPT-VERITY-prefix (orVERITY-).Negative test
It must not be possible to remount the rootfs as read-write, even with root access to the board:
mount -o remount,rw /Expect something similar to:
mount: /: cannot remount /dev/root read-write, is write-protected.
This is the strongest check in this section. It fails at the block device layer, not the mount layer: a dm-verity target implements no write path, so the mapped device carries the read-only flag and the kernel refuses the remount outright. A rootfs that is merely mounted
ro, with a writable device underneath, would remount successfully here.A write to a protected path must be refused:
echo test > /usr/bin/verity_write_probeExpect
Read-only file system. Anything else means the rootfs is writable and the integrity guarantee is void; remove the file if it was actually created.This check is weaker than the remount one but is closer to how a real-world problem tied to this would come up, e.g. a script or a daemon attempting to write something in
/. It is good to double check.
Update signing
Sign an artifact with a different key and confirm the client rejects it rather than installing it. A build without
AXE_MENDER_ARTIFACT_SIGN_KEYmust fail atdo_image_voyager_updateimg.
Known limitations
Deliberate, per the current scope
Limitation |
Consequence |
|---|---|
Loader signing and OTP not implemented |
No hardware root of trust. Everything above is an integrity mechanism only. |
Development private keys in git history |
The repository contains no secrets and must not be assumed to. |
Device lock state hardcoded |
No supported unlock path; dev units need a separate U-Boot. |
Note
This article is adapted from the Axelera Voyager BSP documentation: aisbc.axelera-doc — security.rst.