The Breeze protocol provides a secure channel and services for connecting to Alibaba Cloud over a Bluetooth link. Breeze Over-the-Air (OTA) is a Bluetooth Low Energy (BLE) firmware upgrade feature built on this protocol. To port the SDK, you need to implement the following APIs and data structures: upper-layer application APIs, underlying driver APIs, and bootloader data structures.
Upper-layer application API
ota_breeze_service_init
int ota_breeze_service_init(ota_breeze_service_manage_t* ota_manage);Parameters
| Name | Type | Description |
| ota_manage | ota_breeze_service_manage_t* | Initializes OTA information, including the version number and the message receiving callback function. |
Type definitions
typedef struct _ota_ble_service_dat{
unsigned char is_ota_enable; /*0: Disable OTA. 1: Enable OTA.*/
ota_breeze_version_t verison;/*OS version. Used for version verification.*/
ota_breeze_get_data_t get_dat_cb;/* Callback function for Breeze to send messages to OTA.*/
}ota_breeze_service_manage_t;Return value
0 indicates success. -1 indicates failure.
For more information, see ota_breeze_export.h.
Underlying driver APIs
- hal_flash_erase_sector_size
uint32_t hal_flash_erase_sector_size(void);Parameters
None
Return value
Returns the minimum erasable unit size of the chip's flash memory.
- hal_flash_erase
int32_t hal_flash_erase(hal_partition_t pno, uint32_t off_set, uint32_t size);Parameters
Name Type Description pno hal_partition_t Flash partition ID. off_set uint32_t Offset relative to the start address of the partition. size uint32_t Size to erase. Return value
0 indicates success. -1 indicates failure.
- hal_flash_read
int32_t hal_flash_read(hal_partition_t pno, uint32_t* poff, void* buf, uint32_t buf_size);Parameters
Name Type Description pno hal_partition_t Flash partition ID. poff uint32_t* Offset relative to the start address of the partition. buf void* Data array to store the read data. buf_size uint32_t Length of the data to read. Return value
0 indicates success. -1 indicates failure.
- hal_flash_write
int32_t hal_flash_write(hal_partition_t pno, uint32_t* poff, const void* buf, uint32_t buf_size);Parameters
Name Type Description pno hal_partition_t Flash partition ID. poff uint32_t* Offset relative to the start address of the partition. buf const void* Writes a data array buf_size uint32_t Length of the data to write. Return value
0 indicates success. -1 indicates failure.
- hal_flash_get_info
hal_logic_partition_t *hal_flash_get_info(hal_partition_t pno);Parameters
Name Type Description pno hal_partition_t Flash partition ID. Return value
On success, this function returns the flash partition information, such as the start address and length. On failure, it returns NULL.
For more information, see flash.h.
Bootloader data structure
After the upgrade is complete, the system saves firmware details to the flash parameter area. AliOS Things saves this information to parameter partition 1. The bootloader must read these saved parameters to copy and replace the firmware, which completes the upgrade.
typedef struct
{
unsigned int settings_crc32; /*CRC32 value for settings.*/
unsigned int ota_flag; /*Flag for OTA status.*/
unsigned int src_addr; /*Image storage address.*/
unsigned int dest_addr; /*Image execution address.*/
unsigned int image_size; /*Image size.*/
unsigned int image_crc32; /*Image CRC32.*/
unsigned int image_has_copy_len; /*Records the copied length for the offline bootloader.*/
unsigned char reserved_buf1[RESERVED_SIZE1]; /*Reserved.*/
/*Backup image, including storage address, recovery bank address, image size, and image CRC32.*/
unsigned int backup_store_addr;
unsigned int backup_dest_addr;
unsigned int backup_image_size;
unsigned int backup_image_crc32;
unsigned int backup_has_copy_len; /*Records the copied length for offline operations.*/
unsigned char reserved_buf2[RESERVED_SIZE2]; /*Reserved.*/
/*Downloader image parameters. The bootloader does not need to handle these.*/
unsigned int break_point_offset; /*Saves the breakpoint during OTA processing.*/
unsigned char version_store_buf[VERSION_BUF_SIZE]; /*Saves the version.*/
unsigned short image_info_crc16; /*CRC16 value for image information.*/
unsigned char bin_type; /*Image type.*/
unsigned char reserved_buf3[RESERVED_SIZE3]; /*Reserved.*/
} ota_settings_t;