Skip to content

Secure boot on Nordic nRF devices

Secure boot and signed firmware updates on Nordic nRF. Nordic's secure immutable bootloader (b0, also called NSIB) verifies MCUboot, and MCUboot verifies the Zephyr application. Every signing key stays in the HSM.

See it in practice: watch the 90-second walkthrough for this flow on laavat.io.

This supports the CRA's essential requirements on integrity and secure updates: the device boots only firmware you authorised and accepts only updates you signed.

The chain

Three stages, each verifying the next. The chain starts in b0, which locks its own flash region at every reset, so it cannot be changed without erasing the chip.

  • b0 / NSIB


    Stage 1 · locked flash

    Nordic's immutable first-stage bootloader. It cannot be updated, and it enforces the whole chain.

    Trusts: the hashes of one or more public keys in its provisioning area

    Verifies: MCUboot, the next stage

  • MCUboot


    Stage 2 · flash

    Second-stage bootloader. Updatable, and signed so b0 will accept it.

    Trusts: an ECDSA-P256 public key embedded in the MCUboot binary at build time

    Verifies: the Zephyr app, the next stage

  • Zephyr app


    Stage 3 · app slot

    The application. Updatable, signed via imgtool so MCUboot will accept it.

    Provides: the signature MCUboot verifies at each boot

The keys stay in the HSM

The two private keys behind this chain are created in the HSM and never leave it. The device holds only the matching public keys: one in b0's provisioning area and one built into the MCUboot binary. At boot, verification uses only those public keys: LAAVAT is not in the loop, and a device in the field never contacts the platform to boot.

On the nRF52 Series both keys are ECDSA on prime256v1 (P-256, secp256r1): b0 verifies ECDSA-P256 with the chip's crypto hardware, and imgtool supports it natively. See key custody for how the private keys are held.

Where b0's keys live

On the nRF52 Series, b0 does not store the public keys themselves. Its provisioning area holds a 16-byte fingerprint of each key: the first 16 bytes of the SHA-256 of the 64-byte public key (X‖Y). At boot, b0 checks that the key in MCUboot's validation block has one of these fingerprints, and then verifies the signature with that key. Other series keep their keys elsewhere:

Series What b0 trusts, and where b0 signature
nRF52 Key fingerprints, in the provisioning partition in internal flash ECDSA-P256
nRF53, nRF91 Key fingerprints, in the one-time programmable (OTP) region of the UICR ECDSA-P256
nRF54L The public keys themselves, in the Key Management Unit (KMU), which also enforces revocation. The KMU is provisioned in a separate step. Ed25519 by default

On the nRF52, nRF53 and nRF91, no separate manufacturing step is needed with the nRF Connect SDK: the build produces the provisioning data (provision.hex) from the public key you configure (see With the nRF Connect SDK build), and it is programmed together with the firmware. This page follows the nRF52 Series with ECDSA-P256.

On the nRF52, the provisioning data can hold more than one key. The build lists the signing key first, then the keys in SB_CONFIG_SECURE_BOOT_PUBLIC_KEY_FILES, in order. When b0 verifies an image with a key further down the list, it invalidates every key before it, so shipping firmware signed with the next key revokes the earlier ones. Each key is its own DigestSigning operation in the product. The keys are fixed once the device is provisioned.

The LAAVAT product

One product holds both signing operations. Each has its own ECDSA-P256 key in the HSM for one role in the chain, and both use the same approval rule.

  • nRF MCUboot signing


    operationType: DigestSigning

    You hash MCUboot locally and submit a 32-byte digest; the HSM signs it with ECDSA-P256 and returns a 64-byte signature, which goes into b0's validation-info block.

    Key: ECDSAP256, "Digest Signing key"

  • nRF Zephyr app signing


    operationType: SignMcuBoot

    You submit a .tgz with a small request.json plus the unsigned .bin; LAAVAT runs imgtool sign internally with the HSM key and returns a signed MCUboot-format image.

    Key: ECDSAP256, "MCUboot sign"

Operation type versus CLI argument

The operationType in the product definition is SignMcuBoot, but the imagesigning add command takes MCUBoot. Both are correct: they are two names for the same operation.

Example product definition

Group UUIDs are per-tenant; substitute your own.

{
  "name": "nRF52840 NSIB",
  "description": "nRF52840 with signing of MCUboot for b0/NSIB and the Zephyr app for MCUboot",
  "productType": "Production",
  "enabled": true,
  "caInfo": [],
  "rndKeys": [],
  "productOperations": [
    {
      "name": "nRF Zephyr app signing",
      "description": "Sign nRF Zephyr app",
      "operationType": "SignMcuBoot",
      "token": {
        "name": "MCUboot sign",
        "description": "Signing key for nRF MCUboot and Zephyr app",
        "keyType": "ECDSAP256"
      },
      "approvalRule": {
        "name": "Test rule",
        "description": "Rule used for testing",
        "allowedGroups": ["<allowed-group-uuid>"],
        "approvalGroups": ["<approval-group-uuid>"],
        "blanketGroups": []
      }
    },
    {
      "name": "nRF MCUboot signing",
      "description": "Digest signing with ECC key",
      "operationType": "DigestSigning",
      "token": {
        "name": "Digest Signing key",
        "description": "Digest signing key",
        "keyType": "ECDSAP256"
      },
      "approvalRule": {
        "name": "Rule for access",
        "description": "Rule used for testing",
        "allowedGroups": ["<allowed-group-uuid>"],
        "approvalGroups": ["<approval-group-uuid>"],
        "blanketGroups": []
      }
    }
  ]
}

Token handling

The examples use a signing-tool config file, test.ini, created with config-init and pointing to a token file. See secure token handling.

Hop A: signing MCUboot for b0

At boot, b0 reads the validation-info block, a fixed structure right after MCUboot in flash, to decide whether to start MCUboot. The signature in it covers MCUboot only, not the rest of the block. The signed message is the 32-byte SHA-256 of MCUboot, and because ECDSA-SHA256 hashes the message it signs, b0 checks the signature against the SHA-256 of that hash. Only the signature needs the private key, so LAAVAT creates it, and the rest of the block is built on your side, by the SDK build or by hand.

Both ways need the public key of the MCUboot signing operation: the SDK build puts its fingerprint into provision.hex, and a hand-built block carries the key itself. Fetch it once:

signing-tool -n test.ini product getpubkey -P <product-id> --operid <digest-oper-id> -O laavat_b0_pub.pem

With the nRF Connect SDK build

This is the usual way. The SDK builds b0 and MCUboot together, and its custom signing command is meant for keys held in an HSM. The build hashes MCUboot, writes the 32-byte SHA-256 to a file, calls your command with that file, and reads the signature from its standard output. It then builds the validation-info block, checks the signature against the public key you configured, and writes that key's hash into provision.hex.

Save the signing command as an executable script, for example laavat-b0-sign.sh:

#!/bin/sh
# Custom signing command for b0: the nRF Connect SDK calls it with a file holding
# the firmware's SHA-256 and reads the signature from stdout.
set -e
sig=$(mktemp)
trap 'rm -f "$sig"' EXIT
req=$(signing-tool -n /path/to/test.ini --json imagesigning add DigestSigning -P <product-id> --operid <digest-oper-id> -p "$(openssl dgst -sha256 -binary "$1" | base64 -w0)" -H SHA256 --encoding RAW -N nrf-b0-mcuboot -D "b0 signing" | jq -r .id)
signing-tool -n /path/to/test.ini imagesigning get -I "$req" --wait -O "$sig" > /dev/null
cat "$sig"

Then configure the build in the application's sysbuild.conf:

SB_CONFIG_SECURE_BOOT_APPCORE=y
SB_CONFIG_BOOTLOADER_MCUBOOT=y
SB_CONFIG_SECURE_BOOT_SIGNING_CUSTOM=y
SB_CONFIG_SECURE_BOOT_SIGNING_PUBLIC_KEY="/path/to/laavat_b0_pub.pem"
SB_CONFIG_SECURE_BOOT_SIGNING_COMMAND="/path/to/laavat-b0-sign.sh"
  • The script sends the SHA-256 of the file's contents, so the HSM signs SHA-256(fw_hash), the value b0 checks.
  • --encoding RAW returns the 64-byte r‖s. The build expects that form, although the SDK's help text for the signing command asks for DER.
  • Only the signature goes to standard output. signing-tool's other output is discarded, so the build log stays readable; its error messages still appear, and a failed request stops the build.
  • --wait returns when the request is signed. If the operation needs an approval, the build waits for it.
  • The build signs MCUboot twice, once for each b0 slot (s0 and s1), so each build sends two requests. With an approval rule, both need approving.

b0 and MCUboot need their own flash partitions. From nRF Connect SDK 3.4, Partition Manager is off by default and the partitions come from devicetree; Nordic's bootloader partitioning page lists the ones b0 needs. With that layout, b0 skips the first 0x200 bytes of MCUboot and the block's address is the slot start plus 0x200; the build handles both.

Without the nRF Connect SDK build

If MCUboot is built outside the SDK, or signed after the build, you build the validation-info block yourself. It is 176 bytes, appended to MCUboot:

u8[12]  magic       // three little-endian words: 0x281ee6de, 0x86518483, 0x00013402 (nRF52)
u32     fw_address  // where MCUboot starts in flash, plus the header skip if any
u8[32]  fw_hash     // SHA-256 over the MCUboot bytes b0 boots
u8[64]  pubkey      // P-256 uncompressed X‖Y
u8[64]  signature   // ECDSA-P256, r‖s, over SHA-256(fw_hash)

1. Hash the firmware. Hash MCUboot, then hash the result once more. LAAVAT signs a ready-made digest, so you send the hash that ECDSA-SHA256 would have computed: the SHA-256 of MCUboot's hash.

openssl dgst -sha256 -binary mcuboot.bin > fw_hash.bin
openssl dgst -sha256 -binary fw_hash.bin > digest.bin

2. Send only the digest. Submit the 32 bytes, base64-encoded, to the DigestSigning operation. The image itself never leaves your build environment; only its hash is sent.

signing-tool -n test.ini --json imagesigning add DigestSigning -P <product-id> --operid <digest-oper-id> -p "$(base64 -w0 digest.bin)" -H SHA256 --encoding RAW -N nrf-b0-mcuboot -D "b0 signing" | jq -r .id

The request is asynchronous: the command prints its ID. Download the signature with that ID. --wait waits until the request is ready, so there is no need to poll.

signing-tool -n test.ini imagesigning get -I <request-id> --wait -O b0_sig.bin

--encoding RAW returns the signature as the 64-byte r‖s that b0 expects. Without it, the signature comes back DER-encoded.

3. Assemble the block. Append the 176-byte block to MCUboot: magic, address, fw_hash, public key and signature. b0 looks for the block at the first 4-byte boundary after the image, so pad MCUboot with 0xFF to a multiple of 4 first.

printf '\xde\xe6\x1e\x28\x83\x84\x51\x86\x02\x34\x01\x00' > magic.bin
printf '\x00\x80\x00\x00' > address.bin
openssl ec -pubin -in laavat_b0_pub.pem -outform DER | tail -c 64 > pubkey.bin
head -c $(( -$(stat -c%s mcuboot.bin) & 3 )) /dev/zero | tr '\0' '\377' > pad.bin
cat mcuboot.bin pad.bin magic.bin address.bin fw_hash.bin pubkey.bin b0_sig.bin > mcuboot.b0-signed.bin
  • The magic is the SDK's FW_INFO_MAGIC_COMMON, SB_VALIDATION_INFO_MAGIC and a compatibility word (validation version 2, hardware id 52, crypto id 1), each written little-endian.
  • The address is where MCUboot starts on the nRF52840 DK, 0x8000. Without Partition Manager (the nRF Connect SDK 3.4 default), b0 skips the first CONFIG_ROM_START_OFFSET bytes (0x200) of MCUboot: hash from that offset, and write the address as 0x8200.
  • tail -c 64 keeps the X and Y coordinates of the public key and drops the DER header.

The image now boots on any device provisioned with the matching public key, with no further contact with LAAVAT.

Hop B: signing the application for MCUboot

MCUboot has its own signing tool, imgtool, producing a well-known format: a fixed header, the payload, and a trailing TLV block carrying the signature and metadata. This hop delegates the whole imgtool invocation to LAAVAT, so the private key never appears on the build host.

1. Package what imgtool needs

Build a .tgz containing the unsigned zephyr.bin and a request.json carrying the usual imgtool parameters:

{
  "images": [{
    "filename": "zephyr.bin",
    "output": "signed-zephyr.bin",
    "align": "4",
    "version": "1.6.44+1628771740",
    "header_size": "0x200",
    "slot_size": "0xea000",
    "pad_header": true,
    "pad": true,
    "confirm": true,
    "security_counter": "auto"
  }]
}

header_size, slot_size and align must match your partition layout. align is the flash write-block size, 4 on the nRF52840, as the nRF Connect SDK sets it.

2. Submit to the MCUboot operation

LAAVAT unpacks the archive, runs imgtool sign inside the HSM boundary with the key bound to this operation, and returns a .tgz containing the signed image.

signing-tool -n test.ini --json imagesigning add MCUBoot -P <product-id> --operid <app-oper-id> -F app-submit.tgz -N nrf-zephyr-app -D "Zephyr app signing" | jq -r .id
signing-tool -n test.ini imagesigning get -I <request-id> --wait --skipBase64 -O app-signed.tgz

3. Extract the signed image

Untar the response; the signed binary is signed-zephyr.bin, at the top of the archive. It is a standard MCUboot image: the bootloader on the device, imgtool verify and mcumgr treat it like any locally signed image.

For the request and response formats in detail, see MCUboot signing.

MCUboot's key

MCUboot must be built with the public key of the app signing operation (laavat_app_pub.pem). The nRF Connect SDK build expects to sign images itself with that same key file, which it cannot do with a public key only, so leave image signing for MCUboot to LAAVAT and configure the build for it in your project. If you update MCUboot itself in the field, its update image is signed by LAAVAT the same way.

Variant: with TF-M in the chain

On nRF devices with Arm TrustZone (the nRF5340, nRF91 and nRF54L Series), some builds split the application region into a Secure Processing Environment (TF-M, Trusted Firmware-M) and a Non-Secure Processing Environment (the Zephyr app). MCUboot then verifies two images at boot instead of one, and both need signing. The nRF52 Series has no TrustZone, so this variant does not apply to the nRF52840.

graph LR
    A["<b>b0 / NSIB</b><br/>stage 1 · locked flash"]
    B["<b>MCUboot</b><br/>stage 2 · flash"]
    C["<b>TF-M</b><br/>stage 3a · secure"]
    D["<b>Zephyr app</b><br/>stage 3b · non-secure"]
    A -->|verifies| B
    B -->|verifies| C
    B -->|verifies| D

b0 is unchanged and still verifies only MCUboot. The second image is MCUboot's concern alone.

Append one more entry to productOperations, the same shape as the Zephyr app operation with a different name and key:

{
  "name": "nRF TF-M signing",
  "description": "Sign nRF TF-M secure image",
  "operationType": "SignMcuBoot",
  "token": {
    "name": "TF-M sign",
    "description": "Signing key for nRF TF-M",
    "keyType": "ECDSAP256"
  },
  "approvalRule": {
    "name": "TF-M signing rule",
    "description": "Who may request and approve TF-M signing",
    "allowedGroups": ["<allowed-group-uuid>"],
    "approvalGroups": ["<approval-group-uuid>"],
    "blanketGroups": []
  }
}

The signing flow gains one more submit-and-download cycle, identical in shape to the application submission but pointed at the TF-M operation with the TF-M binary as input.

Verifying without hardware

Both hops can be checked on the build host, before any hardware exists. MCUboot has a verifier you can run there; b0 does not, so its checks are repeated.

Hop A: repeating b0's checks

b0 only runs on the chip. What it checks before starting MCUboot is public in the nRF Connect SDK source, so the checks can be repeated on the build host. With the SDK build, the build itself checks the signature before it writes the signed image. For a block you assembled, read the 176 bytes back off the signed image and run b0's three checks:

  1. Find the block. b0 looks within 4 bytes after the end of the firmware for the 12-byte magic. If it finds none, it does not boot.
  2. The public key matches the provisioned one. The key in the block must have one of the key fingerprints in the provisioning area. Use the key from product getpubkey as the reference, since that is the key the device is provisioned with.
  3. The signature verifies. Hash the firmware b0 boots, hash that hash, and verify the 64-byte signature against the result with the key from the block. This is the ECDSA-P256 verification b0 performs.

In signature mode b0 does not compare the block's fw_hash or address fields; a changed firmware byte fails check 3. If all three pass, b0 accepts the image.

Hop B: checking with imgtool

MCUboot ships its verifier as a Python CLI, running the same maths the on-device bootloader executes at boot. No simulation is needed, because the tool is the reference implementation.

signing-tool -n test.ini product getpubkey -P <product-id> --operid <app-oper-id> -O laavat_app_pub.pem
imgtool verify --key laavat_app_pub.pem signed-zephyr.bin
imgtool dumpinfo signed-zephyr.bin

If imgtool verify exits zero, MCUboot on a real device would accept the image. dumpinfo parses the header and TLV block, so you can confirm the version, signature algorithm, key hash and TLV list are what you asked for.

Where off-hardware verification stops

What checking without hardware does and does not show:

Claim Off-hardware What would close the gap
MCUboot signature is cryptographically correct for b0 Fully proven Nothing more needed
App signature is cryptographically correct for MCUboot Fully proven Nothing more needed
Struct magic, field layout and signed digest match b0 Checked against the nRF Connect SDK source Boot on an nRF52840 DK, or compare with bl_validation.c and bl_crypto.c in your sdk-nrf checkout
The custom signing command works inside an SDK build Checked in a full nRF Connect SDK 3.4.2 build for the nRF52840 DK: both MCUboot slots signed, the build's own check passed, provision.hex holds the key's hash Nothing more needed
b0 finds the block at its expected flash offset Partial Boot on an nRF52840 DK
The provisioning data puts the key hashes where b0 reads them The hash is in the build's provision.hex; not programmed on a device Program it on an nRF52840 DK and boot
Both signings survive concurrent submissions Not stressed A parallel-submission test, if throughput matters

References

Try this on your own board

A free LAAVAT evaluation runs on the hosted platform. Bring one real image or one device-certificate flow and take it from first login to a verified signature.

Start your evaluation Watch the 90-second walkthroughs