When creating firmware for IoT devices, engineers know that they will have to update it over time. This post shows how to run Zephyr OTA updates on nRF devices without risking a bricked board. How the board handles an incoming update is critical. Erasing and writing to internal flash takes some time and can temporarily stall the CPU bus. It can introduce severe problems if not handled properly.
There are many ways that firmware updates can be performed on a microcontroller, e.g., via UART, USB. Sometimes a system update must be performed wirelessly, e.g., when a device is deployed in a location that is difficult to access. We can perform wireless updates via Bluetooth Low Energy or Wi-Fi.
Zephyr is already a common choice for commercial hardware: according to Linux Foundation Research, 62% of surveyed organizations in Europe use it in their products. We walk through a complete mcumgr firmware update over BLE and show how MCUboot firmware rollback keeps the device running when a new image fails. Then we cover the settings that make secure OTA firmware updates possible. The last part describes OTA updates over OpenThread from one of our projects.
What is OTA?
This is a method to deliver an update wirelessly. It is often called FOTA, which means Firmware Over The Air. The update can be uploaded by your PC to the device.
If you want to update the device from the cloud, you can use a server to host an update and implement signaling of update availability. When performed and valid, an update replaces old firmware with a new one.
How does OTA work?
Much of the OTA updates consist of transferring the new software from the server to the client, e.g., a microcontroller or microprocessor. But before it is sent to a remote device, written software must be compiled. Then the executable file must be converted into a portable binary image. Because network protocols have strict payload limits (MTU), the binary cannot be transmitted as a single block. Instead, it must be packetized.
What happens when an update fails
For every secure DFU (device firmware update), it is strongly recommended to define a boot partition for the boot manager and two additional partitions for the old application image and the new one. This MCUboot dual-slot configuration is critical as a fail-safe. If an update is interrupted or corrupted, the microcontroller can safely revert to the old, working firmware.
Ways to perform Zephyr OTA updates
With Zephyr RTOS, you do not have to build everything from scratch. For standard setups, Zephyr provides off-the-shelf components, MCUboot (the bootloader) and mcumgr (the management and transfer subsystem), that work out of the box over BLE, Wi-Fi, or IPv6 networks like OpenThread. The Zephyr over-the-air update documentation gives an overview of these options.
However, if your network has strict bandwidth, RAM, or fleet-scheduling constraints, you do not have to abandon Zephyr completely. Instead, you can write a custom OTA transport in your application to control packet pacing and scheduling, while still relying on MCUboot for signature verification, dual-slot swapping, and safe rollback.
What to configure for Zephyr OTA updates in nRF Connect SDK
This blog was written using the nRF Connect SDK version 3.4.1. In different versions, some of the commands may not work. Nordic describes the same nRF Connect SDK OTA update flow in its guide to FOTA updates on nRF52 Series devices.
MCUboot bootloader
In Zephyr, to perform an update, it is highly recommended to enable MCUboot. It is a secure bootloader, which enables easy software upgrades. MCUboot is not dependent on any specific operating system. In this post, we will discuss the MCUboot swap mode update method, described in detail in the MCUboot design documentation. You can simply include MCUboot in your build process by typing the following command in sysbuild.conf:
SB_CONFIG_BOOTLOADER_MCUBOOT=y
Enabling the bootloader does not add any DFU functionality by default. A user must enable it on their own.
Enabling the MCUboot bootloader also simplifies memory management. You do not have to define partitions manually. The Zephyr build system automatically generates a default flash layout that includes the following partitions:
boot partition: for the bootloader
primary partition: for the currently running app
secondary partition: for the uploaded image
If you must save data into nvs, you can also add the following instruction to be able to save data on nvs partition.
CONFIG_NVS=y
You can also define partitions manually in the device tree.
Enable FOTA in project configuration
In Zephyr, a developer must set up Bluetooth LE and enable FOTA over it in the project configuration file. You can simply do it by typing the following line in prj.conf.
CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DEVICE_NAME="device_name"
# enable necessary configuration with mcumgr in project configuration
CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU=y
MCUboot image signing for the firmware update file
Firmware signing is a critical security layer that guarantees your device only boots authentic code. By default, nRF Connect SDK signs MCUboot images with a publicly known development key. This means anyone within BLE range could write and run malicious firmware on an unhardened device if you ship with defaults.
For production, every build must be signed with your own private key, while the corresponding public key is embedded in MCUboot or provisioned into hardware key storage so the bootloader verifies the signature before swapping the image into the primary slot.
In Zephyr, we can use imgtool to prepare a signing key. Nordic lists the supported key types for MCUboot image signing in its signature keys documentation. Then, in the sysbuild configuration file, enable this key to be used in every build by adding the following line to sysbuild.conf.
SB_CONFIG_BOOT_SIGNATURE_KEY_FILE="path/to/your/generated/key.pem"
#this has to be adjusted to your generated key type.
SB_CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256=y
Software you need to perform the update
To install an update, a developer must have installed necessary software like AuTerm, which is an app with a graphical interface, or smpmgr and mcumgr via the terminal. Each one of these programs allows you to perform DFU wirelessly or by wire.
How a mcumgr firmware update works with MCUboot
Assuming partitions were defined correctly, the active app runs from the primary partition.
Initiating the update requires a wireless link between the host and the device. Enable BLE in the firmware and start advertising. This makes the device discoverable. After the client (e.g., your PC) connects and discovers the target’s SMP service, the two negotiate the BLE MTU (maximum transmission unit). Then the mcumgr client uses this negotiated MTU to fragment the firmware payload into packets for transmission.
A mcumgr firmware update starts with the mcumgr image upload over BLE from the PC to the device:
mcumgr --conntype ble --connstring peer_name='device_name' image upload path/to/update_file.signed.bin
The incoming payload is written into the secondary partition. A dual-bank architecture doesn’t prevent update failures, but it does prevent those failures from bricking the device. If a transfer drops mid-flight or is otherwise interrupted, the currently running application in the primary partition remains completely functional.
Once the upload finishes successfully, verify the image state. At this stage, the new firmware should appear in the secondary slot:
mcumgr --conntype ble --connstring peer_name='device_name' image list
The next step is to mark the new image flag as pending. Grab a hash of the image. It is displayed on the images list. When a hash is obtained, just call:
mcumgr --conntype ble --connstring peer_name='device_name' image test
Now, trigger a remote reboot to execute the swap via the command below.
mcumgr --conntype ble --connstring peer_name='device_name' reset
Once the bootloader verifies the update’s hash and cryptographic signature, it swaps images and runs from the new one, updating its flag to active. The old image still has a confirmed flag. If you accidentally reset the device again without confirming the new image, images will swap again, and the device will boot from the old image. The new one will still be saved in the device memory, but on a secondary partition.
Calling the instruction below confirms the image. It can also be done in the code by calling boot_write_img_confirmed().
mcumgr --conntype ble --connstring peer_name='device_name' image confirm
From that moment, a reboot will not swap images.
If the update succeeds, the old image will not be immediately erased from the secondary partition. The next update will do it. If you really want to delete an old image after the correct update, you can delete it, e.g., using the mcumgr command. It deletes the second slot image.
mcumgr --conntype ble --connstring peer_name='device_name' image erase
What if validation of the internal hash fails? Swap does not occur after a reset. The new image will not be applied and will be immediately erased from the secondary slot.
How to build secure OTA firmware updates
While the Zephyr ecosystem abstracts away many complex low-level mechanics, there are critical behaviors we must explicitly manage to get secure OTA firmware updates.
Secure the connection
The default connection in nRF Connect SDK is not secure. Everyone who discovers the device can upload an app image. In Zephyr, there are a few Kconfig options that help with connection security. Adding the following commands in prj.conf gives you a much safer connection than the default one.
# these two are necessary to save and load bond between update host an the device
CONFIG_SETTINGS=y
CONFIG_BT_SETTINGS=y
CONFIG_BT_SMP=y
# safe connection only
CONFIG_BT_SMP_SC_ONLY=y
# mcumgr configuration, which forces device authentication
CONFIG_MCUMGR_TRANSPORT_BT_PERM_RW_AUTHEN=y
The above command forces a secure connection between, e.g., a PC and the device. The connection will require authentication between devices, so you will need an authorization key. There are several ways a BLE authentication key can be obtained.
The microcontroller can generate a passkey whenever someone tries to pair with the device. Then it can be sent or displayed (e.g., in Serial Terminal).
Also, you can declare a fixed passkey, but then you must add the following instruction to prj.conf. A fixed passkey is more vulnerable to attacks such as brute force.
The solution depends on your needs. Of course, all of this must be declared also in the Zephyr program.
CONFIG_BT_FIXED_PASSKEY=y
For this part, I recommend using smpmgr. It works very similarly to mcumgr, but it works almost out of the box when uploading or listing the images and resetting the device when using a secure connection.
Before you use smpmgr, you must only pair the update host (e.g., PC) with the device. Then the device must be trusted. You can do it via bluetoothctl on Linux. There you can obtain a MAC address, which is necessary to use smpmgr. Remember to close bluetoothctl after finishing operations.
The commands below should help you with sending an update.
1) Upload:
smpmgr --ble image upload /path_to/zephyr.signed.bin
2) List:
smpmgr --ble image state-read
3) Mark for test:
smpmgr --ble image state-write
4) Reset:
smpmgr --ble os reset
Also, in the code, a method must be called to load BLE settings if you don’t want to pair with the device after every reset, and some callbacks must be wired properly.
Watchdog
During a lengthy flash swap, the main application is not running. Instead, MCUboot handles the swap and must be properly configured to feed the hardware watchdog, ensuring the device doesn’t reset mid-update. Proper setup of a watchdog may not be enough. It can interrupt the swap process, so even after reset, images are not swapped. To avoid that problem, add the following Kconfig flag to sysbuild/mcuboot.conf.
CONFIG_BOOT_WATCHDOG_FEED=y
Save critical process data and device states to NVS
Critical data must be saved to the Non-Volatile Storage (NVS) partition so it survives the update process. You can do it when the Zephyr reset hook occurs.
Check if the device is still handling a critical process
The firmware should not blindly accept a remote reset request. Instead, it should intercept the request and delay the reboot until any critical CPU processes, hardware I/O, or NVS writes have safely completed. Only then should the device reset.
If you are using mcumgr or smpmgr, you can configure a Zephyr hook to set the desired behavior of the device when reset occurs.
You must set these two options in the prj.conf file:
CONFIG_MCUMGR_MGMT_NOTIFICATION_HOOKS=y
CONFIG_MCUMGR_GRP_OS_RESET_HOOK=y
Also remember to include the necessary header in your project file.
#include
Then you can configure your callback in code and, e.g., safely take care of all your important data. If the device is still busy, the reset callback should return an error, e.g., MGMT_ERR_EBUSY.
Version downgrade protection
In Zephyr, you can easily enable version downgrade prevention.
It prevents installing an older firmware version, which can have vulnerabilities.
You must create a mcuboot.conf file inside the sysbuild folder. If you do not have this directory, create it in the main project folder. Inside the file, type:
CONFIG_MCUBOOT_DOWNGRADE_PREVENTION=y
It requires changing the version in the VERSION file or in prj.conf:
CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION="1.0.0"
Now you must rebuild the project and flash the board. From that moment, there will be no possibility to swap app images when the newly uploaded image has an older version.
You can upload and mark an image with faulty versioning for testing, but it will be rejected.
Auto image confirmation and MCUboot firmware rollback
Earlier, we confirmed the test image manually via mcumgr. Your firmware can also confirm itself. If you have the following flag in the .conf file, you don’t have to add anything else
CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU=y
Run it after critical subsystems, such as BLE, storage, and sensors. Initialize and pass basic self-checks. Confirming writes the image_ok flag directly to flash and does not require a reboot. If the new firmware crashes or reboots before reaching this point, it remains unconfirmed, and MCUboot firmware rollback restores the previous working image on the next boot.
#include
/* Call only after critical initialization and self-checks succeed */
if (!boot_is_img_confirmed()) {
int err = boot_write_img_confirmed();
if (err) {
LOG_ERR("Failed to confirm image (%d)", err);
} else {
LOG_INF("Boot image confirmed");
}
}
What happens after an update
After updating the devices as developers or product owners, we must have a report of the update status. They should report immediately if the update succeeded or failed and why, because you can quickly start searching for bugs.
Updating many BLE devices at the same time
When your devices have only BLE, you can perform the update via gateways.
Gateway is usually a small Linux computer that hosts radios for local protocols.
It can be connected to Ethernet and send OTA updates to nearby devices. Also, it can be connected to the cloud and send data from sensors.
Using a gateway provides centralized security, because devices trust the gateway.
What if your project requires a custom OTA protocol?
If your project has strict bandwidth, RAM, or fleet-scheduling constraints, or does not use an OS with built-in update subsystems like mcumgr, you can implement your own lightweight transport protocol. Your application receives the firmware blocks over the chosen network, erases flash sectors as needed, writes the data into the secondary partition, and marks the image as pending so MCUboot handles cryptographic verification and the slot swap on reboot.
OTA updates over OpenThread in a WizzDev project
We have deployed many devices whose updates come from wireless connections.
For example, in one of the projects, nRF devices (routers, sensors) talk to a local hub over OpenThread. Once installed, they receive OTA updates over OpenThread, the same radio network they use every day. Usable throughput is only about 2–10 kB/s per device. That number shapes the whole design.
How the hub schedules updates across the mesh
For example, in one of the projects, nRF devices talk to a gateway over OpenThread. Once installed, they have to be updated over that same radio network. Usable throughput across the entire network is only about only a few kB/s, which shapes the whole design.
The gateway is the update server. When an update is available, the gateway sends a small “new firmware available” message. The device then requests the image in blocks, one at a time, and writes each block straight to flash. This stop-and-wait approach uses little RAM and lets the device set the pace on a lossy mesh.
One device at a time can be updated. A single transfer already uses a large share of the mesh, so parallel updates would only cause collisions. The gateway scheduler has three states:
Boot delay. It waits a few seconds after start so devices can reconnect.
Idle. It picks the next online device that needs an update.
In progress. It watches the device’s block requests. After the next few seconds of silence, the update counts as done, which leaves time for the device to reboot.
Devices that were offline are queued again when they come back, so the fleet converges on its own.
How we kept each update safe
The image goes into the inactive, secondary slot. The device checks the size and CRC32, then asks the bootloader for a test swap and reboots. The bootloader verifies the signature and swaps the slots. The new firmware must confirm itself after a settling period, or the bootloader rolls back to the old image.
Images are signed and encrypted. Also, we have implemented a mechanism to prevent installing older firmware versions.
Conclusions
Deploying an IoT device is only the beginning of its lifecycle. Maintenance can also be a challenge. Zephyr OTA updates let developers patch vulnerabilities, optimize performance, and deploy new features without requiring physical access to boards mounted all over the world. Regulation adds pressure too, as described in our guide to the Cyber Resilience Act for IoT devices.
Zephyr can handle the highest-risk aspects of the update process for you. The dual-bank architecture protects your devices against mid-transfer power losses, dropped wireless connections, and corrupted images.
Setting up the partition layout and the signing keys takes time. It pays off over the whole product lifecycle. An OTA pipeline is a basic requirement for modern, secure embedded systems. By relying on Zephyr’s ecosystem, developers can focus on application value instead of bootloader mechanics.
Key takeaways
MCUboot keeps the running application in the primary slot and writes the update to the secondary slot, so an interrupted transfer does not brick the device.
A new image is first marked for test and becomes permanent only after it has been confirmed.
Production builds must be signed with your own key, because nRF Connect SDK signs images with a publicly known development key by default.
The default BLE connection is not secure, so the device should require authenticated pairing before anyone can upload an image.
In a WizzDev OpenThread project, a hub updates one device at a time in 512-byte blocks at about 2–10 kB/s.







