/* hfupdate.h * * Copyright (C) 2017 ShangHai High-flying Electronics Technology Co.,Ltd. * * This file is part of HSF. * */ #ifndef _HF_UPDATE_H_ #define _HF_UPDATE_H_ #ifdef __cplusplus extern "C" { #endif #define HF_CONFIG_OTA_FLAG_REDAY (0x0A0A55A0) #define HF_CONFIG_OTA_FLAG_OK (0x0505AA50) #define HF_BOOT_CONFIG_MAGIC_CODE (0x48464254) #define HF_CONFIG_OTA_FLAG_FAIL (0x5A5A5A00) #define HF_BOOT_RUN_MODE_NORMAL (0) #define HF_BOOT_RUN_MODE_AUTO_UPGRADE (0xA5010202) #define HF_BOOT_RUN_MODE_DEBUG (0xA5010203) typedef enum HFUPDATE_TYPE { HFUPDATE_SW=0, HFUPDATE_CONFIG=1, HFUPDATE_WIFIFW, HFUPDATE_WEB, }HFUPDATE_TYPE_E; typedef enum http_download_type{ HTTP_DOWNLOAD_TYPE_TMP = 1, //下载到buff HTTP_DOWNLOAD_TYPE_FLASH = 2, //下载到FLASH HTTP_DOWNLOAD_LOCATION_UPGRADE = 4, //upgrade分区 HTTP_DOWNLOAD_LOCATION_FLASH_UPGRADE = HTTP_DOWNLOAD_TYPE_FLASH|HTTP_DOWNLOAD_LOCATION_UPGRADE, //FLASH中upgrade分区 HTTP_DOWNLOAD_LOCATION_WEB = 8, //web分区 HTTP_DOWNLOAD_LOCATION_FLASH_WEB = HTTP_DOWNLOAD_TYPE_FLASH|HTTP_DOWNLOAD_LOCATION_WEB, //FLASH中web分区 }http_download_type_t; int HSF_IAPI hfupdate_auto_upgrade(uint32_t flags); int HSF_IAPI http_download_enable_range(char enable); int HSF_IAPI hfupdate_auto_upgrade_start(void); int HSF_IAPI check_webpage_file_ok(char *addr, char *version); /** * @brief start OTA to update application. * * @param[in] type: update type, now only support 'HFUPDATE_SW' & 'HFUPDATE_WEB' * @return[out] HF_SUCCESS-successfully, other value is failed * @see None. * @note this function will need time to erase flash. */ int HSF_API hfupdate_start(HFUPDATE_TYPE_E type); /** * @brief write update file. * * @param[in] type: update type, now only support 'HFUPDATE_SW' & 'HFUPDATE_WEB' * offset: offset address, start from 0 * data: a pointer to data * len: the len of data * @return[out] the length of write success * @see None. * @note this function will need some time to erase flash. */ int HSF_API hfupdate_write_file(HFUPDATE_TYPE_E type, uint32_t offset, uint8_t *data, int len); /** * @brief complete update. * * @param[in] type: update type, now only support 'HFUPDATE_SW' & 'HFUPDATE_WEB' * file_total_len: the len of file * @return[out] HF_SUCCESS-successfully, other value is failed * @see None. * @note return -1 means file type error, return -2 means file crc error. */ int HSF_API hfupdate_complete(HFUPDATE_TYPE_E type, uint32_t file_total_len); /** * @brief download OTA file use http. * * @param[in] purl: http url * @return[out] HF_SUCCESS-successfully, other value is failed * @see None. * @note None. */ int HSF_API hfupdate_fw_as_http(const char *purl); /** * @brief get bootloader version. * * @param[in] version: the buffer to store bootloader version * @return[out] the crc32 of bootloader, 0 is failed * @see None. * @note None. */ unsigned int HSF_API hfupdate_read_boot_ver(char *version); /** * @brief check whether or not in updating * * @param[in] None * @return[out] 0-not in updating, 1-in updating * @see None. * @note None. */ int HSF_API hfupdate_auto_upgrade_is_running(void); /** * @desc: * @params: start_range is 0,file_len is NULL when DISABLE_HTTP_DOWNLOAD_RANGE * @param[in] purl: http url * @param[in] p_data: a buffer or a FLASH address to store update file * @param[in] len: the len of p_data FLASH * @param[in] type: the HTTP Download data to LOCATION * @param[in] start_range: Download from Start position * @return[out] < 0 error numb , > 0 down file length */ int HSF_API http_download_file(const char *purl, char *p_data, uint32_t len, http_download_type_t type, int start_range, int *file_len); #ifdef __cplusplus } #endif #endif