Over-The-Air Device Firmware Upgrade (Alpha)#
The Wi-SUN Over-The-Air Device Firmware Upgrade (OTA DFU) service is implemented to facilitate the updating of Wi-SUN device firmware. This component requires the Gecko Bootloader API to execute firmware writing, verification, and bootload operations.
To obtain a new Gecko Bootloader File (GBL) from a remote host Over-The-Air, a Trivial File Transfer Protocol (TFTP) client is employed, leveraging the Wi-SUN network. The entire firmware upgrade session is manageable over CoAP, with the service offering remote host connection settings, firmware file selection, notification, and status request capabilities. Configuration of the connection to the TFTP remote host can be accomplished within the component configuration file. To use this component, a bootloader must be flashed onto the device. The component relies on functions that reside within the bootloader. To choose the appropriate bootloader, consider factors such as flash location (internal or external) and size. To save on download time, we recommend applying compression on both the bootloader and device projects.
The following diagram shows the component architecture: 

The example below shows how OTA DFU can be performed in any project.
#include <stdio.h>
#include "cmsis_os2.h"
#include "sl_wisun_ota_dfu.h"
static void start_ota_dfu(void) {
sl_status_t api_status = SL_STATUS_FAIL;
uint32_t fw_update_status = 0;
// Set remote host that stores the firmware image.
// TFTP protocol is used to download the firmware.
// 69 is the default TFTP Port
api_status = sl_wisun_ota_dfu_set_host_addr("2001:db8::1", 69);
if (api_status != SL_STATUS_OK) {
// Error handling
return;
}
// Set GBL file path
// The path is relative to the preconfigured TFTP shared directory
api_status = sl_wisun_ota_dfu_set_gbl_path("my_new_firmware.gbl");
if (api_status != SL_STATUS_OK) {
// Error handling
return;
}
// Start firmware update
api_status = sl_wisun_ota_dfu_start_fw_update();
if (api_status != SL_STATUS_OK) {
// Error handling
return;
}
// Waiting for the firmware download to finish.
while(1) {
fw_update_status = sl_wisun_ota_dfu_get_fw_update_status();
if (fw_update_status & (1 << SL_WISUN_OTA_DFU_STATUS_FW_DOWNLOADED)) {
printf("Firmware downloaded. Preparing to bootload\n");
break;
} else if (fw_update_status & (1 << SL_WISUN_OTA_DFU_STATUS_FW_DOWNLOAD_ERROR)) {
printf("Firmware download failed\n");
break;
}
osDelay(1);
}
}
The CoAP remote settings can be configured as follows:
coap-client -m get -N -B 3 -t text coap://[$WISUN_NODE_IPV6_ADDR]:5683/ota/dfu -e "help"
Commands:
[P: POST (set), G: GET (get)]
[G] help
[G] (empty payload) status
[P] start
[P] stop
[P] install
[G|P] host_address <ipv6> <port>
[G|P] gbl <path>
[G|P] uri <path>
[G|P] notify_host_address <ipv6> <port>
[G|P] notify_uri <path>
[G|P] notify_chunk_cnt <count>