Breeze協(xié)議提供基于藍(lán)牙鏈路連接阿里云的安全通道和服務(wù),Breeze OTA是在其基礎(chǔ)上實(shí)現(xiàn)的BLE固件升級(jí)功能。用戶移植需要對(duì)接的接口和數(shù)據(jù)結(jié)構(gòu)有:上層應(yīng)用接口,底層驅(qū)動(dòng)對(duì)接接口和bootloader對(duì)接數(shù)據(jù)結(jié)構(gòu)。

上層應(yīng)用對(duì)接API

ota_breeze_service_init

int ota_breeze_service_init(ota_breeze_service_manage_t* ota_manage);

參數(shù)

名稱 類型 描述
ota_manage ota_breeze_service_manage_t* 初始化ota信息,包括版本號(hào),消息接收回調(diào)函數(shù)等

類型介紹

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 to version verify*/
    ota_breeze_get_data_t get_dat_cb;/* breeze to ota send message callback function*/
}ota_breeze_service_manage_t;

返回值

成功:0;失敗:-1

詳細(xì)內(nèi)容查看ota_breeze_export.h

底層驅(qū)動(dòng)對(duì)接API

  • hal_flash_erase_sector_size
    uint32_t hal_flash_erase_sector_size(void);

    參數(shù)

    無(wú)

    返回值

    返回芯片flash最小擦寫(xiě)單元大小

  • hal_flash_erase
    int32_t hal_flash_erase(hal_partition_t pno, uint32_t off_set, uint32_t size);

    參數(shù)

    名稱 類型 描述
    pno hal_partition_t flash 分區(qū)ID
    off_set uint32_t 相對(duì)分區(qū)起始地址偏移量
    size uint32_t 擦寫(xiě)大小

    返回值

    成功:0;失敗:-1

  • hal_flash_read
    int32_t hal_flash_read(hal_partition_t pno, uint32_t* poff, void* buf, uint32_t buf_size);

    參數(shù)

    名稱 類型 描述
    pno hal_partition_t flash 分區(qū)ID
    poff uint32_t* 相對(duì)分區(qū)起始地址偏移量
    buf void* 讀取的數(shù)據(jù)數(shù)組
    buf_size uint32_t 讀取的數(shù)據(jù)長(zhǎng)度

    返回值

    成功:0;失敗:-1

  • hal_flash_write
    int32_t hal_flash_write(hal_partition_t pno, uint32_t* poff, const void* buf, uint32_t buf_size);

    參數(shù)

    名稱 類型 描述
    pno hal_partition_t flash 分區(qū)ID
    poff uint32_t* 相對(duì)分區(qū)起始地址偏移量
    buf const void* 寫(xiě)入數(shù)據(jù)數(shù)組
    buf_size uint32_t 寫(xiě)入數(shù)據(jù)長(zhǎng)度

    返回值

    成功:0;失敗:-1

  • hal_flash_get_info
    hal_logic_partition_t *hal_flash_get_info(hal_partition_t pno);

    參數(shù)

    名稱 類型 描述
    pno hal_partition_t flash 分區(qū)ID

    返回值

    成功:flash分區(qū)信息:分區(qū)起始地址,長(zhǎng)度等;失敗:NULL

    詳細(xì)內(nèi)容查看flash.h

Bootloader對(duì)接數(shù)據(jù)結(jié)構(gòu)

升級(jí)完成后,系統(tǒng)會(huì)將固件信息等保存flash參數(shù)區(qū),AliOS Things 保存在參數(shù)分區(qū)1;Bootloader 需要讀取保存的參數(shù),完成固件的copy和替代,實(shí)現(xiàn)升級(jí)。

typedef struct
{
    unsigned int settings_crc32;   /*settings crc32 value*/
    unsigned int ota_flag;         /*flag ota status*/
    unsigned int src_addr;         /*image storage address*/
    unsigned int dest_addr;        /*image run address*/
    unsigned int image_size;       /*image size*/
    unsigned int image_crc32;      /*image crc32*/
    unsigned int image_has_copy_len;   /*remember the copy len for bootloader off line*/
    unsigned char reserved_buf1[RESERVED_SIZE1]; /*reserved*/
    /*backup image include store addr, recovery bank addr, 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;           /*remember the copy len for off line*/
    unsigned char reserved_buf2[RESERVED_SIZE2]; /*reserved*/
    /*down_loader image parameters bootloader don't need to care*/
    unsigned int break_point_offset;                   /*breakpoint save when ota processing.*/
    unsigned char version_store_buf[VERSION_BUF_SIZE]; /*version save*/
    unsigned short image_info_crc16;                   /*image info crc value*/
    unsigned char bin_type;                            /*Image type*/
    unsigned char reserved_buf3[RESERVED_SIZE3];
} ota_settings_t;