Getting Started With Zephyr: OTA Updates with Spotflow
In the previous two posts about Spotflow, Rakhshan Sayed walked through connecting a board to Spotflow (https://www.embeddedrelated.com/showarticle/1810.php) and using Spotflow’s coredump analysis feature to debug a crash after it has occurred in the field (https://www.embeddedrelated.com/showarticle/1813.php). In this post, I will walk you through the mechanics of Spotflow’s over-the-air (OTA) firmware update feature on Zephyr. While the previous posts target an NXP FRDM-MCXN947 (https://www.nxp.com/design/design-center/development-boards-and-designs/FRDM-MCXN947) and use Windows as their development environment, this post targets a Nordic Semiconductor nRF7002-DK (https://www.nordicsemi.com/Products/Development-hardware/nRF7002-DK) and uses Fedora Linux as its development environment.
Environment and Device Setup
Spotflow makes the environment and device setup incredibly straightforward. First, as with any embedded software application that is based on The Zephyr Project, we need to create our Python virtual environment and activate it, as shown below (assuming that our working directory is ~/spotflow/ota):
mab@fedora:~/spotflow/ota$ python3 -m venv .venv
mab@fedora:~/spotflow/ota$ source .venv/bin/activate
(.venv) mab@fedora:~/spotflow/ota$
Then, after logging into Spotflow’s website, we can click on the Quickstart button in the left sidebar and click on “Zephyr” when prompted for the device stack, as shown in the image below:

Spotflow then prompts us for our board, where we can select the nrf7002 DK, as shown in the image below:

After clicking on “Next Step”, Spotflow provides a neat script and gives us a simple command that we can execute on our development machine to allow the script to set up our West environment and install all necessary dependencies. As shown in the image below, we can simply click the button to copy the command and then paste it into our terminal for execution:

After we execute the command in our terminal, the script prompts us for a few inputs to configure our environment. First, it asks us to enter our workspace directory, with the default being spotflow-ws under our home directory:
(.venv) mab@fedora:~/spotflow/ota$ source <(curl --proto '=https' --tlsv1.2 -sSf https://downloads.spotflow.io/spotflowup.sh) --zephyr --board nrf7002dk
[?] Enter workspace folder path [/home/mab/spotflow-ws] ./
[!] Folder '/home/mab/spotflow/ota/./' already exists and is not empty.
[?] Continue anyway? This may cause issues. [y/N] y
Since the directory already exists, the script asks for confirmation, which we can approve. Afterward, the script fetches and installs the necessary Spotflow and Zephyr dependencies (Note: After the script completes, the console window exits, and we have to open a new one and restart our Python environment).
We can click on “Next Step” in step 2 (“Create West Workspace”) of the Spotflow workflow, and we are given a set of Kconfig options we can paste into prj.conf of the logs sample that Spotflow provides, as shown in the image below (Note: I’ve hidden the ingest key below because it is used to authenticate devices against my Spotflow instance):

As an initial test, we can navigate to the logs Spotflow sample, as shown below, and paste the snippet we copied from Spotflow’s web interface, with our WiFi password and ingest key filled in:

We can click on “Next Step” in the Spotflow web interface and follow the subsequent instructions to build and flash the logs sample:

After building and flashing the firmware to the nRF7002 development kit, we can open a UART and see the following output from the board, indicating successful communication with the backend:
[00:00:12.352,081] <dbg> spotflow_net: mqtt_evt_handler: MQTT client connected!
[00:00:12.352,081] <inf> spotflow_net: spotflow_mqtt_establish_mqtt: MQTT connected!
[00:00:12.352,813] <inf> spotflow_net: spotflow_session_metadata_encode: Generated device run ID: 1983561134530618745
[00:00:12.764,709] <dbg> spotflow_net: mqtt_evt_handler: SUBACK packet id: 12175
[00:00:12.764,709] <dbg> spotflow_net: mqtt_evt_handler: Subscription to desired configuration topic acknowledged
[00:00:13.555,938] <inf> MAIN: main: Hello from Zephyr to Spotflow: 5
[00:00:15.556,030] <inf> MAIN: main: Hello from Zephyr to Spotflow: 6
[00:00:17.556,121] <inf> MAIN: main: Hello from Zephyr to Spotflow: 7
[00:00:19.556,213] <inf> MAIN: main: Hello from Zephyr to Spotflow: 8
[00:00:21.556,304] <inf> MAIN: main: Hello from Zephyr to Spotflow: 9
[00:00:23.556,396] <inf> MAIN: main: Hello from Zephyr to Spotflow: 10
[00:00:25.556,488] <inf> MAIN: main: Hello from Zephyr to Spotflow: 11
[00:00:27.556,579] <inf> MAIN: main: Hello from Zephyr to Spotflow: 12
[00:00:29.556,671] <inf> MAIN: main: Hello from Zephyr to Spotflow: 13
[00:00:31.556,762] <inf> MAIN: main: Hello from Zephyr to Spotflow: 14
[00:00:33.556,854] <inf> MAIN: main: Hello from Zephyr to Spotflow: 15
[00:00:35.556,945] <inf> MAIN: main: Hello from Zephyr to Spotflow: 16
[00:00:37.557,037] <inf> MAIN: main: Hello from Zephyr to Spotflow: 17
[00:00:39.557,128] <inf> MAIN: main: Hello from Zephyr to Spotflow: 18
[00:00:41.557,220] <inf> MAIN: main: Hello from Zephyr to Spotflow: 19
Additionally, we can navigate to the Spotflow web interface, click on our device (“nrf7002dk-001”), click on the “Events Explorer” tab, and notice the messages that were sent from our device to the Spotflow backend (these messages match the output from the UART console), as shown in the images below:


OTA Updates With Spotflow
Spotflow also provides an ota sample we can use to test the OTA feature. However, we need to apply the following modifications to get the sample to compile successfully and function as expected.
First, of course, we need to include the WiFi credentials and our Spotflow ingest key in the sample. We can do that in prj.conf, as we did in the logs sample, but the more appropriate way to do it is to create credentials.conf and add the necessary Kconfig settings, as shown below:
(.venv) mab@fedora:~/spotflow/ota/spotflow/zephyr/samples/ota$ cat credentials.conf
# Copy this file to credentials.conf and fill in the values
CONFIG_NET_WIFI_SSID="mab"
CONFIG_NET_WIFI_PASSWORD="xxxxxx"
CONFIG_SPOTFLOW_DEVICE_ID="nrf7002dk-001"
CONFIG_SPOTFLOW_INGEST_KEY="sf_xxxxxxxx"
Second, if we attempt to build the sample, we will get the following Kconfig error:
(.venv) mab@fedora:~/spotflow/ota/spotflow/zephyr/samples/ota$ west build --pristine --board nrf7002dk/nrf5340/cpuapp/ns
.
.
.
warning: MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG_ALLOW_NON_CSPRNG (defined at modules/mbedtls/Kconfig.mbedtls:606, modules/mbedtls/Kconfig.mbedtls:606) was assigned the value 'y' but got the value 'n'. Check these unsatisfied dependencies: ((MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG && MBEDTLS_BUILTIN && MBEDTLS_CFG_FILE = "config-mbedtls.h" && MBEDTLS) || (MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG && MBEDTLS_BUILTIN && MBEDTLS_CFG_FILE = "config-mbedtls.h" && MBEDTLS && 0)) (=n). See http://docs.zephyrproject.org/latest/kconfig.html#CONFIG_MBEDTLS_PSA_CRYPTO
_EXTERNAL_RNG_ALLOW_NON_CSPRNG and/or look up MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG_ALLOW_NON_CSPRNG in the menuconfig/guiconfig interface. The Application Development Primer, Setting Configuration Values, and Kconfig - Tips and Best Practices sections of the manual might be helpful too.
By comparing the ota sample against the logs sample and getting some help from Claude, we need to add Kconfig.sysbuild and populate it with the following:
config WIFI_NRF70
default y if BOARD_NRF7002DK || BOARD_THINGY53
source "${ZEPHYR_BASE}/share/sysbuild/Kconfig"
If we again attempt to rebuild the firmware, we get the following error:
/home/mab/zephyr-sdk-0.17.4/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: zephyr/zephyr_pre0.elf section `text' will not fit in region `FLASH'
/home/mab/zephyr-sdk-0.17.4/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: region `FLASH' overflowed by 249244 bytes
Since we’ve enabled the WiFi stack and OTA support, the image size has ballooned to the point where it no longer fits in the internal Flash memory. Unfortunately, there are no Kconfig options we can set to reduce the image size. Instead, we can change the update strategy with a few Kconfig tweaks. Nominally, the candidate update image is downloaded to a region in the internal Flash of the nRF5340 (the SoC on the nRF7002 DK). However, we can make the following changes to the ota sample to move the downloaded image to external Flash:
- Add the following to
Kconfig.sysbuild(after theconfig WIFI_NRF70section we added previously):
config PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY
default y if BOARD_NRF7002DK
- Create
sysbuild.cmakeand add the following content to it, which adds support for external Flash in MCUBoot:
if(SB_CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY)
set_config_bool(mcuboot CONFIG_SPI y)
set_config_bool(mcuboot CONFIG_SPI_NOR y)
set_config_bool(mcuboot CONFIG_SPI_NOR_SFDP_DEVICETREE y)
set_config_int(mcuboot CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE 4096)
set_config_bool(mcuboot CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK y)
set_config_bool(mcuboot CONFIG_BOOT_ERASE_PROGRESSIVELY y)
set_config_int(mcuboot CONFIG_BOOT_MAX_IMG_SECTORS 256)
sysbuild_cache_set(VAR mcuboot_EXTRA_DTC_OVERLAY_FILE APPEND
${CMAKE_CURRENT_LIST_DIR}/sysbuild/mcuboot_ext_flash.overlay)
endif()
- Create
mcuboot_ext_flash.overlayin thesysbuilddirectory and the following, which adds software support for the external Flash chip in MCUBoot:
/ {
chosen {
nordic,pm-ext-flash = &mx25r64;
};
};
&mx25r64 {
status = "okay";
};
- Create
nrf7002dk_nrf5340_cpuapp.confandnrf7002dk_nrf5340_cpuapp_ns.confin the boards directory and the following, which adds support for the SPI subsystem and support for SPI_NOR Flash chips (in addition to allowing the firmware to communicate with the Spotflow backend):
CONFIG_MBEDTLS_MPI_MAX_SIZE=512
CONFIG_SPI=y
CONFIG_SPI_NOR=y
CONFIG_SPI_NOR_SFDP_DEVICETREE=y
CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
- Create
nrf7002dk_nrf5340_cpuapp_ns.overlayandnrf7002dk_nrf5340_cpuapp.overlayand the following, which adds support for the external Flash chip in the application:
/ {
chosen {
nordic,pm-ext-flash = &mx25r64;
};
};
&mx25r64 {
status = "okay";
};
- We also need to increase the number of connections to account for the additional HTTPS requests for the firmware download itself, which can be accomplished by adding the following Kconfig in the sample
prj.conf:
CONFIG_NET_MAX_CONN=8
The image should now compile successfully. After flashing the firmware image to the board, we see the following in the UART console:
[00:00:00.225,036] <inf> ota_sample: main: Starting Spotflow OTA sample
[00:00:00.225,067] <dbg> spotflow_ota: spotflow_ota_log_loaded_attempt: Loaded OTA persistence: no saved attempt
[00:00:00.225,128] <dbg> spotflow_ota: spotflow_ota_log_loaded_probation: Loaded OTA persistence: no main firmware probation record
[00:00:00.225,372] <dbg> spotflow_ota: spotflow_ota_fw_main_reconcile_startup: No main firmware probation record to reconcile
[00:00:00.225,402] <dbg> spotflow_ota: spotflow_ota_init: OTA initialized (last received attempt 0)
[00:00:00.225,463] <inf> ota_sample: confirm_unconfirmed_main_firmware: Main firmware state: phase=NOT_RUNNING result=0
[00:00:00.225,677] <inf> wifi_supplicant: handler: wpa_supplicant initialized
[00:00:00.230,834] <inf> spotflow_metrics: register_metric_common: Registered metric 'boot_reset' (type=int, agg=0, max_ts=1, max_labels=1)
[00:00:00.230,987] <inf> spotflow_metrics: spotflow_metrics_system_init: System metrics initialized: 0 metrics registered, collection=10s, aggregation=60s
[00:00:00.231,018] <inf> spotflow_metrics: spotflow_metrics_heartbeat_init: Heartbeat initialized (interval=60 s)
[00:00:00.231,048] <inf> spotflow_net: wait_for_network: Waiting for network...
[00:00:01.225,524] <inf> spotflow_sample_net: spotflow_sample_net_init: Initializing Wi-Fi...
[00:00:01.225,616] <inf> spotflow_sample_wifi: connect_to_wifi: Connecting to SSID: mab
[00:00:03.134,399] <inf> ota_sample: main: Ready to receive OTA updates
[00:00:04.551,422] <inf> spotflow_sample_wifi: wifi_event_handler: Connected to mab
[00:00:04.656,890] <inf> spotflow_device_id: spotflow_get_device_id: Using Spotflow device ID: nrf7002dk-001
[00:00:06.739,288] <inf> spotflow_net: spotflow_mqtt_establish_mqtt: MQTT connected!
[00:00:06.740,905] <inf> spotflow_net: spotflow_session_metadata_encode: Generated device run ID: 4472634062868426918
Similarly, we can see the following in the Spotflow dashboard:

Before we can deploy firmware updates, we need to create a “cohort”, which is a collection of devices organized in a certain fashion. To do this, we can click on “OTA Updates” in the left sidebar of the web interface and click on “Create Cohort”, as shown below:

On the following screen, we can give the cohort a name (“OTA Test Fleet” in our example), select the checkbox next to “nrf7200dk-001” and click on “Create Cohort”, as shown in the image below:

Now, we’ll upload firmware to Spotflow, which will enable us to create a deployment and perform an OTA update of our cohort. Before we do that, we’ll make a small change to our existing firmware so we may confirm that the update was successful, as shown below:
int main(void)
{
- LOG_INF("Starting Spotflow OTA sample");
+ LOG_INF("Starting Spotflow OTA sample v1.0");
confirm_unconfirmed_main_firmware();
Rebuild the firmware and then navigate to the Spotflow web interface. From there, click on “Firmwares” in the left sidebar and click on the “+ Add New Firmare” button, as shown below:

In the right sidebar that opens, enter “OTA Test” for the “Firmware Name” field and click on “Create Firmware”, as shown below:

Then, click on “+ Add New Version”, give it a version name (“v1.0”), upload zephyr.signed.bin and click “Create Firmware Version”, as shown below:

Finally, we can go back to the “OTA Updates” section and click on “New Deployment” as shown below:

In the subsequent screen, select “OTA Test” in the “Firmware” dropdown and “v1.0” in the “Version” dropdown, and click “Continue to Review”, as shown below:

In the final window, click on “Start Deployment”:

If we go back to the UART console, we can see the following output, indicating that the download of the update has begun (Note: this will take some time):
[00:00:10.496,582] <inf> spotflow_net: spotflow_mqtt_establish_mqtt: MQTT connected!
[00:00:10.498,382] <inf> spotflow_net: spotflow_session_metadata_encode: Generated device run ID: 10274357885327839515
[00:00:10.911,651] <inf> spotflow_net: spotflow_config_set_sent_log_level: Updated sent log level to 3 (was 4)
[00:02:12.975,799] <inf> spotflow_ota: handle_decoded_c2d_message: OTA attempt 10 accepted (1 artifacts)
[00:02:12.977,813] <inf> spotflow_ota: initialize_worker_operation: OTA attempt 10: started artifact 'ota-test' v1.0 (index 0, main)
[00:02:12.980,346] <inf> spotflow_ota: spotflow_ota_fw_main_process_artifact: OTA attempt 10: started main firmware artifact 'ota-test' v1.0
[00:02:12.980,468] <inf> spotflow_ota: spotflow_ota_fw_main_process_artifact: Main firmware phase -> pending download
[00:02:12.980,499] <inf> ota_sample: spotflow_on_main_firmware_update_progressed: Main firmware progress: phase=PENDING_DOWNLOAD paused=0 result=0
[00:02:12.981,628] <inf> spotflow_ota: download_started_cb: Main firmware phase -> downloading
[00:02:12.981,658] <inf> ota_sample: spotflow_on_main_firmware_update_progressed: Main firmware progress: phase=DOWNLOADING paused=0 result=0
[00:02:12.981,689] <dbg> spotflow_ota: spotflow_ota_download_artifact: Starting artifact download (TLS: 1, port: 443)
[00:02:13.063,293] <inf> spotflow_ota: connect_socket: CA probe for sec tag 2: rc=-27 len=1391
Eventually, we should see the device reboot, and MCUboot swap the firmware to the one that was just downloaded (Note: This will also take some time):
*** Booting MCUboot v2.3.0-dev-d537e5b5d244 ***
*** Using nRF Connect SDK v3.2.4-4c3fc0d44534 ***
*** Using Zephyr OS v4.2.99-9673eec75908 ***
I: Starting bootloader
I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
I: Secondary image: magic=good, swap_type=0x2, copy_done=0x3, image_ok=0x3
I: Boot source: none
I: Image index: 0, Swap type: test
I: Starting swap using move algorithm.
Ultimately, we should see the new firmware boot in the UART console:
I: Bootloader chainload address offset: 0xc000
I: Image version: v0.0.0
[00:00:00.003,173] <inf> spi_nor: spi_nor_process_bfp: mx25r6435f@0: 8 MiBy flash
[00:00:00.007,263] <inf> fs_nvs: nvs_mount: 2 Sectors of 4096 bytes
[00:00:00.007,263] <inf> fs_nvs: nvs_mount: alloc wra: 0, fa0
[00:00:00.007,293] <inf> fs_nvs: nvs_mount: data wra: 0, 94
[00:00:00.007,629] <inf> spotflow_net: spotflow_config_persistence_try_load: Persisted Spotflow configuration loaded
[00:00:00.007,629] <inf> spotflow_net: spotflow_config_init_sent_log_level: Initialized sent log level to 3
[00:00:00.007,659] <inf> spotflow_logging: init: Spotflow logging backend initialized.
*** Booting nRF Connect SDK v3.2.4-4c3fc0d44534 ***
*** Using Zephyr OS v4.2.99-9673eec75908 ***
[00:00:00.223,876] <inf> mcuboot_util: boot_swap_type_multi: Image index: 0, Swap type: revert
[00:00:00.224,273] <inf> ota_sample: main: Starting Spotflow OTA sample v1.0
If we go back to the web interface, we can see that it reports that the update was successful and that our device is on the version we just uploaded:

Thus, we have successfully learned how to add OTA support to the nRF7002 DK using Spotflow and test out the feature.
- Comments
- Write a Comment Select to add a comment
To post reply to a comment, click on the 'reply' button attached to each comment. To post a new comment (not a reply to a comment) check out the 'Write a Comment' tab at the top of the comments.
Please login (on the right) if you already have an account on this platform.
Otherwise, please use this form to register (free) an join one of the largest online community for Electrical/Embedded/DSP/FPGA/ML engineers:








