.. _SM_AT_FOTA: FOTA AT commands **************** .. contents:: :local: :depth: 1 This page describes AT commands related to Firmware Over-The-Air (FOTA) updates. .. only:: not nrf91m1 The commands are available when the :ref:`CONFIG_SM_FOTA ` Kconfig option is enabled. 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=[,[,[,]]] The parameters and their defined values are the following: * ``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. .. only:: not nrf91m1 * ``3`` - Start FOTA for full modem update. Can only be used when the :file:`full-fota.conf` configuration file and :file:`full-fota-nrf9151.overlay` devicetree overlay are used. * ``5`` - Start FOTA for MCUboot second-stage bootloader update. .. only:: not nrf91m1 Only available when the device uses the NSIB (B0) and MCUboot as a second-stage bootloader. Not supported on the Thingy:91 X. * ``7`` - Read modem DFU area size and firmware image offset (for modem delta update). * ``9`` - Erase modem DFU area (for modem delta update). 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. 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. 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=`` command. .. note:: Raw sockets must not use the PDN connection at the same time. See :ref:`SM_AT_SOCKET_RAW_SOCKET_LIMITATION` 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. .. only:: not nrf91m1 This means that updates for MCUboot images are limited to the number of slots defined in the ``SB_CONFIG_SECURE_BOOT_NUM_VER_COUNTER_SLOTS`` Kconfig option. In |SM|, it is set to ``40`` by default. .. only:: nrf91m1 Updates for MCUboot images are limited to 40 slots. Response syntax ~~~~~~~~~~~~~~~ :: AT#XFOTA=7 #XFOTA: , The parameters and their defined values are the following: Integer. The size of the modem DFU area in bytes. 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: ,[,] The parameters and their defined values are the following: .. sm_nrf_cloud_fota_urc_params_start * ``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. * ``0`` - OK. * ``1`` - Error. * ``2`` - Cancelled. Integer. Its value can have different meanings based on the values returned by ```` and ````. See the following table: +-------------------------+----------------------------+------------------------------------------------------------------------------+ |```` |```` | ```` | +=========================+============================+==============================================================================+ |``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. .. sm_nrf_cloud_fota_urc_params_end .. only:: not nrf91m1 Full modem update * A negative error code - Activating the update failed, for example when loading the modem firmware from the update storage. The update storage is erased and the device reboots. 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: ,,, Examples ~~~~~~~~ :: AT#XFOTA=? #XFOTA: (0,1,2,3,5,7,9),,, OK