nRF9160: HTTP application update

The HTTP application update sample demonstrates how to do a basic FOTA (firmware over-the-air) update. It uses the Download client library to download a file from a remote server and write it to flash.

Overview

The sample connects to an HTTP server to download a signed firmware image. The image is generated when building the sample, but you must upload it to a server and configure where it can be downloaded. See Specifying the image file for more information.

By default, the image is saved to MCUboot bootloader secondary slot. The downloaded image must be signed for use by MCUboot with imgtool.

Requirements

  • The following development board:
    • nRF9160 DK board (PCA10090)
  • A signed firmware image that is available for download from an HTTP server. This image is automatically generated when building the application.
  • The sample is configured to compile and run as a non-secure application on nRF91’s Cortex-M33. Therefore, it automatically includes the nRF9160: Secure Partition Manager that prepares the required peripherals to be available for the application.

Building and running

This sample can be found under samples/nrf9160/http_application_update in the nRF Connect SDK folder structure.

See Building and programming a sample application for information about how to build and program the application.

The sample is built as a non-secure firmware image for the nrf9160_pca10090ns board. Because of this, it automatically includes the nRF9160: Secure Partition Manager. The sample also uses MCUboot, which is automatically built and merged into the final HEX file when building the sample.

Specifying the image file

Before building the sample, you must specify where the image file will be located. If you do not want to host it yourself, you can upload it to nRF Cloud for testing purposes. See Hosting your image on nRF Cloud for instructions.

To specify the location in SEGGER Embedded Studio:

  1. Select Project > Configure nRF Connect SDK Project.
  2. Navigate to HTTP application update sample and specify the Download host name (CONFIG_DOWNLOAD_HOST) and The file to download (CONFIG_DOWNLOAD_FILE).
  3. Click Configure to save the configuration.

Hosting your image on nRF Cloud

  1. Go to firmware.nrfcloud.com and sign in. If you already have an nRF Cloud account, you can use the same credentials. Otherwise, create an account and sign in.

  2. In the menu on the left-hand side, select Firmware.

  3. Click Generate new to create a URL for the firmware image.

    Generate URL for firmware image in nRF Cloud

    Generate URL for firmware image in nRF Cloud

  4. Click the Copy URL button to copy the address.

When specifying the image file, use the s3.amazonaws.com part of the URL for the download host name. Make sure to not include the https. Specify the rest of the URL as file name.

Testing

After programming the sample to the board, test it by performing the following steps:

  1. Configure the application version to be 2. To do so, either change CONFIG_APPLICATION_VERSION to 2 in the prj.conf file, or select Project > Configure nRF Connect SDK Project > HTTP application update sample in SEGGER Embedded Studio and change the value for Application version. Then rebuild the application.

  2. Upload the file update.bin to the server you have chosen. To upload the file on nRF Cloud, click Upload for the firmware URL that you generated earlier. Then select the file update.bin and upload it.

  3. Reset your nRF9160 DK to start the application.

  4. Open a terminal emulator and observe that an output similar to this is printed:

    SPM: prepare to jump to Non-Secure image
    ***** Booting Zephyr OS v1.13.99 *****
    
  5. Observe that LED1 is lit. This indicates that version 1 of the application is running.

  6. Press Button 1 on the nRF9160 DK to start the download process and wait until “Download complete” is printed in the terminal.

  7. Press the RESET button on the board. MCUboot will now detect the downloaded image and write it to flash. This can take up to a minute and nothing is printed in the terminal while this is processing.

  8. Observe that LED1 and LED2 is lit. This indicates that version 2 or higher of the application is running.

Dependencies

This sample uses the following libraries:

From nRF Connect SDK
From nrfxlib
From Zephyr
From MCUboot