FOTA AT commands

This page describes AT commands related to Firmware Over-The-Air (FOTA) updates.

FOTA request #XFOTA

The #XFOTA command sends various types of FOTA requests, based on specific operation codes.

Set command

The set command performs FOTA-related operations.

Syntax

AT#XFOTA=<op>[,<file_url>[,<sec_tag>[,<pdn_id>]]]

The parameters and their defined values are the following:

<op>
  • 0 - Stop FOTA (during download only). Can be used as a way to pause and resume the download, by issuing the same FOTA start command to resume.

  • 1 - Start FOTA for application update.

  • 2 - Start FOTA for modem delta update.

  • 5 - Start FOTA for MCUboot second-stage bootloader update.

  • 7 - Read modem DFU area size and firmware image offset (for modem delta update).

  • 9 - Erase modem DFU area (for modem delta update).

<file_url>

String. The full HTTP or HTTPS path of the target image to download. Must be provided to the start operations. For the MCUboot bootloader update, the target image must be the signed image for the inactive s0/s1 slot. You can use the AT#XBOOTINFO=1 command to query which slot is active.

<sec_tag>

Integer. Indicates to the modem the credential of the security tag used for establishing a secure connection for downloading the image. It is associated with the certificate or PSK. Must be provided to the start operations when using HTTPS.

<pdn_id>

Integer. The Packet Data Network (PDN) ID that can be used instead of the default PDN for downloading. Can be provided to the start operations.

Note

For historical reasons, this is the PDN ID and not the cid of the +CGDCONT command, which most other commands use. You can get the PDN ID of a cid with the AT%XGETPDNID=<cid> command.

Note

Raw sockets must not use the PDN connection at the same time. See Socket AT commands for more information.

After the #XFOTA: 4,0 notification indicating that the FOTA update is downloaded, it must be activated by resetting either the whole device with the AT#XRESET command, or in case of modem update only the modem with the AT#XMODEMRESET command.

Note

During a delta update to the modem, the modem DFU area is automatically erased as needed as part of the update process. Erasing this area manually is optional.

However, this leads to the command starting the update taking longer to complete, and also leaves the connection to the FOTA server idle while the area is being erased, which can provoke issues.

Note

The firmware image is stored in external flash memory during a full modem update. The external flash is erased automatically after a new firmware activation.

Activating the new modem firmware is done identically to a modem delta update, by resetting either the whole device or only the modem.

Important

For the MCUboot bootloader update, NSIB (B0) uses monotonic counter values to prevent rollback. When performing an MCUboot FOTA, the host must ensure that the new MCUboot image has a strictly higher monotonic counter value than the currently running MCUboot to avoid update failure.

Updates for MCUboot images are limited to 40 slots.

Response syntax

AT#XFOTA=7
#XFOTA: <size>,<offset>

The parameters and their defined values are the following:

<size>

Integer. The size of the modem DFU area in bytes.

<offset>

Integer. The offset of the firmware image in the modem DFU area. It is 0 if no image is in the modem DFU area, and 2621440 (NRF_MODEM_DELTA_DFU_OFFSET_DIRTY) if the modem DFU area needs to be erased before a new firmware update can be received.

Example

application firmware download and update
AT#XFOTA=1,"http://remote.host/fota/sm_app_update.bin"
OK
#XFOTA: 1,0,0
...
#XFOTA: 4,0
AT#XRESET
OK
Ready
#XFOTA: 5,0

read modem DFU info
AT#XFOTA=7
#XFOTA: 294912,0
OK

modem firmware download and update
AT#XFOTA=2,"http://remote.host/fota/mfw_nrf9151_update_from_2.0.2_to_2.0.3.bin"
OK
#XFOTA: 1,0,0
...
#XFOTA: 4,0
AT#XMODEMRESET
#XFOTA: 5,0
#XMODEMRESET: 0
OK

read modem DFU info
AT#XFOTA=7
#XFOTA: 294912,2621440
OK

erase modem DFU area for next modem delta update (optional)
AT#XFOTA=9
OK

MCUboot bootloader update
AT#XBOOTINFO=1
#XBOOTINFO: 0
OK
AT#XFOTA=5,"https://remote.host/fota/signed_by_mcuboot_and_b0_s1_image.bin",42
OK
#XFOTA: 1,0,0
...
#XFOTA: 4,0
AT#XRESET
OK
Ready
#XFOTA: 5,0

Unsolicited notification

#XFOTA: <fota_stage>,<fota_status>[,<fota_info>]

The parameters and their defined values are the following:

<fota_stage>
  • 0 - Init.

  • 1 - Download.

  • 2 - Download, erase pending (modem delta update only).

  • 3 - Download, erase complete (modem delta update only).

  • 4 - Downloaded, to be activated.

  • 5 - Complete.

<fota_status>
  • 0 - OK.

  • 1 - Error.

  • 2 - Cancelled.

<fota_info>

Integer. Its value can have different meanings based on the values returned by <fota_stage> and <fota_status>.

See the following table:

<fota_stage>

<fota_status>

<fota_info>

1 (namely Download)

0 (namely OK)

Percentage of the download

1 (namely Download)

1 (namely ERROR)

Error code, see download error codes

1 (namely Download)

2 (namely CANCELLED)

0 - Downloading is cancelled before completion

4 (namely Activate)

1 (namely ERROR)

71303173 - Low voltage, retry on reboot

5 (namely Complete)

1 (namely ERROR)

Error code, see activation error codes

Download error codes

The download error codes are common to all FOTA types and correspond to the fota_download_error_cause enumeration of the FOTA download library:

  • 1 - Connecting to the server failed (for example, because of wrong TLS credentials).

  • 2 - Download failed.

  • 3 - Update image rejected.

  • 4 - Update image type mismatch.

  • 5 - Internal error on the device.

  • 6 - Error in the DFU library.

  • 7 - Protocol not supported.

  • 8 - Invalid URL or configuration.

Activation error codes

The activation error codes depend on the FOTA type.

Application update
  • A negative error code - Confirming the new image after the first boot failed.

  • A positive error code - The swap type reported by MCUboot was not the one expected for a new image that is pending confirmation. For example, 5 (BOOT_SWAP_TYPE_FAIL) means that the swap failed because the new image is not valid, and 255 (BOOT_SWAP_TYPE_PANIC) means that MCUboot failed to read the swap state from flash.

Modem delta update

The error codes are the NRF_MODEM_DFU_RESULT_* results reported by the modem:

  • 71303169 (NRF_MODEM_DFU_RESULT_INTERNAL_ERROR) - The modem encountered a fatal internal error during firmware update.

  • 71303170 (NRF_MODEM_DFU_RESULT_HARDWARE_ERROR) - The modem encountered a fatal hardware error during firmware update.

  • 71303171 (NRF_MODEM_DFU_RESULT_AUTH_ERROR) - Modem firmware update failed due to an authentication error.

  • 71303172 (NRF_MODEM_DFU_RESULT_UUID_ERROR) - Modem firmware update failed due to UUID mismatch.

  • 71303173 (NRF_MODEM_DFU_RESULT_VOLTAGE_LOW) - Modem firmware update not executed due to low voltage. The modem will retry the update on reboot.

MCUboot bootloader update
  • A negative error code - Reading the active MCUboot version after the update failed.

  • 1 - The MCUboot version did not change. This is also reported when you update the same version to slot s0 while slot s1 is active, even though the update has succeeded. Verify the result with the AT#XBOOTINFO command.

Read command

The read command is not supported.

Test command

The test command tests the existence of the command and provides information about the type of its subparameters.

Syntax

AT#XFOTA=?

Response syntax

#XFOTA: <list of op value>,<file_url>,<sec_tag>,<pdn_id>

Examples

AT#XFOTA=?

#XFOTA: (0,1,2,3,5,7,9),<file_url>,<sec_tag>,<pdn_id>

OK