885 lines
		
	
	
		
			26 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			885 lines
		
	
	
		
			26 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /****************************************************************************
 | |
| 
 | |
| Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
 | |
| 
 | |
| This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
 | |
| be copied by any method or incorporated into another program without
 | |
| the express written consent of Aerospace C.Power. This Information or any portion
 | |
| thereof remains the property of Aerospace C.Power. The Information contained herein
 | |
| is believed to be accurate and Aerospace C.Power assumes no responsibility or
 | |
| liability for its use in any way and conveys no license or title under
 | |
| any patent or copyright and makes no representation or warranty that this
 | |
| Information is free from patent or copyright infringement.
 | |
| 
 | |
| ****************************************************************************/
 | |
| 
 | |
| #ifndef IOT_UPGRADE_API_H
 | |
| #define IOT_UPGRADE_API_H
 | |
| 
 | |
| #include "iot_pkt_api.h"
 | |
| #include "iot_queue_api.h"
 | |
| #include "iot_mem_pool_api.h"
 | |
| #include "iot_config_api.h"
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| extern "C" {
 | |
| #endif
 | |
| 
 | |
| /** \defgroup UPGARDE_APIs UPGARDE APIs
 | |
|  *  @brief UPGRADE APIs
 | |
|  *
 | |
|  *
 | |
|  */
 | |
| 
 | |
| /** @addtogroup UPGARDE_APIs
 | |
|  * @{
 | |
|  *
 | |
|  */
 | |
| 
 | |
| /* define error code from STA. */
 | |
| /* OK to upgrade */
 | |
| #define IOT_PLC_UPGRADE_OK                  (0)
 | |
| /* receive request in invalid state */
 | |
| #define IOT_PLC_UPGRADE_STATE_ERR           (1)
 | |
| /* same version. don't upgrade */
 | |
| #define IOT_PLC_UPGRADE_ERR_SAME_VERSION    (2)
 | |
| /* flash operation error */
 | |
| #define IOT_PLC_UPGRADE_FLASH_ERROR         (3)
 | |
| /* don't upgrade in trail run state*/
 | |
| #define IOT_PLC_UPGRADE_TRAIL_RUN_REJ       (4)
 | |
| /* upgrade err because no memory */
 | |
| #define IOT_PLC_UPGRADE_ERR_NO_MEM          (5)
 | |
| /* block size error */
 | |
| #define IOT_PLC_UPGRADE_ERR_BLOCK_SIZE      (6)
 | |
| /* unknown error */
 | |
| #define IOT_PLC_UPGRADE_ERR_UNKNOWN         (7)
 | |
| 
 | |
| #define IOT_FILE_HDR_LEN                    (0x60)
 | |
| 
 | |
| /* file type of the upgrading image */
 | |
| /* CCo upgrading file */
 | |
| #define IOT_FILE_TYPE_CCO                   (0)
 | |
| /* STA upgrading file */
 | |
| #define IOT_FILE_TYPE_STA                   (1)
 | |
| /* External device upgrading file */
 | |
| #define IOT_FILE_TYPE_EXT_DEV               (2)
 | |
| /* invalid upgrading file type */
 | |
| #define IOT_FILE_TYPE_INVALID               (0xFFFF)
 | |
| 
 | |
| #define IOT_PLC_UPGRADE_ST_INVALID          (0)
 | |
| #define IOT_PLC_UPGRADE_ST_IDLE             (1)
 | |
| #define IOT_PLC_UPGRADE_ST_RECVING          (2)
 | |
| #define IOT_PLC_UPGRADE_ST_RECV_DONE        (3)
 | |
| #define IOT_PLC_UPGRADE_ST_EXECUTING        (4)
 | |
| #define IOT_PLC_UPGRADE_ST_TRAIL_RUN        (5)
 | |
| #define IOT_PLC_UPGRADE_ST_TRAIL_FAIL       (6)
 | |
| 
 | |
| /* device switch part result */
 | |
| /* none switch part */
 | |
| #define IOT_PLC_UPGRADE_SWITCH_NONE         (0)
 | |
| /* upgrade switch part successful */
 | |
| #define IOT_PLC_UPGRADE_SWITCH_SUCC         (1)
 | |
| /* upgrade switch part fail */
 | |
| #define IOT_PLC_UPGRADE_SWITCH_FAIL         (2)
 | |
| /* other switch part (not upgrade switch part) successful */
 | |
| #define IOT_PLC_UPGRADE_OTHER_SWITCH_SUCC   (3)
 | |
| /* other switch part (not upgrade switch part) fail */
 | |
| #define IOT_PLC_UPGRADE_OTHER_SWITCH_FAIL   (4)
 | |
| 
 | |
| /* 8 blocks in a upgrade window */
 | |
| #define IOT_SG_CCO_UPGRADE_BM_SIZE          (1)
 | |
| 
 | |
| /* max supported upgrading FW size is 300*8*400 bytes. */
 | |
| #define IOT_SG_CCO_UPGRADE_BM_SIZE_MAX      (300)
 | |
| 
 | |
| #if (IOT_SMART_GRID_ENABLE && PLC_SUPPORT_STA_ROLE)
 | |
| #define IOT_SG_UPGRADE_BLOCK_CNT            (4)
 | |
| #else
 | |
| #define IOT_SG_UPGRADE_BLOCK_CNT            (0)
 | |
| #endif
 | |
| 
 | |
| /* the latest state before the restart */
 | |
| #define UPGRADE_BP_STATE_IDLE               (0)
 | |
| #define UPGRADE_BP_STATE_RECVING            (1)
 | |
| #define UPGRADE_BP_STATE_RECV_DONE          (2)
 | |
| 
 | |
| /* get upgrade method */
 | |
| #define UPGRADE_GET_METHOD_SG               (0)
 | |
| #define UPGRADE_GET_METHOD_CLI              (1)
 | |
| 
 | |
| typedef enum {
 | |
|     UPGRADE_DATA_TYPE_FW,
 | |
|     UPGRADE_DATA_TYPE_PIB,
 | |
|     UPGRADE_DATA_TYPE_PKG,
 | |
|     UPGRADE_DATA_TYPE_CUS,
 | |
|     UPGRADE_DATA_TYPE_INVALID = 0xFF,
 | |
| } iot_upgrade_data_type;
 | |
| 
 | |
| typedef enum {
 | |
|     PART_0,
 | |
|     PART_1,
 | |
|     PART_INVALID = 0xFF,
 | |
| } iot_upgrade_part_t;
 | |
| 
 | |
| /* callback for crc check */
 | |
| typedef void (*file_part_crc_check)(uint8_t result);
 | |
| 
 | |
| /**
 | |
|  * @brief falsh_read_end - callback for read a data block to flash
 | |
|  * @param data             iot_pkt_t data
 | |
|  * @param result:          ERR_OK: success. others: fail
 | |
|  */
 | |
| typedef void(*falsh_read_end)(iot_pkt_t *data, uint32_t result);
 | |
| 
 | |
| /**
 | |
|  * @brief flash_write_end - callback for write a data block to flash
 | |
|  * @param block_index       flash data block index
 | |
|  * @param result:           ERR_OK: success. others: fail
 | |
|  */
 | |
| typedef void(*flash_write_end)(uint32_t block_index, uint32_t result);
 | |
| 
 | |
| typedef struct _iot_start_src {
 | |
|     /** upgrade ID, remains the same in single progress */
 | |
|     uint32_t id;
 | |
|     /** upgrade data block size, unit is byte,
 | |
|     valid value: 100 200 300 400 */
 | |
|     uint32_t block_size;
 | |
|     /** firmware size, uint is byte, max size : 444K */
 | |
|     uint32_t fw_size;
 | |
|     /** pib size, uint is byte, now : 32K */
 | |
|     uint32_t pib_size;
 | |
|     /** custom size, uint is byte */
 | |
|     uint32_t cus_size;
 | |
|     /** firmware crc-32 */
 | |
|     uint32_t fw_crc;
 | |
|     /** only for CLI upgrading. */
 | |
|     uint32_t fw_version;
 | |
|     /** pib crc-32 */
 | |
|     uint32_t pib_crc;
 | |
|     /** cus crc-32 */
 | |
|     uint32_t cus_crc;
 | |
|     /** crc check buffer */
 | |
|     iot_pkt_t *crc_check_buf;
 | |
|     /** crc check callback */
 | |
|     file_part_crc_check crc_check_cb;
 | |
|     /** callback of reading a data block to flash */
 | |
|     falsh_read_end read_block_cb;
 | |
|     /** callback of writting a data block to flash */
 | |
|     flash_write_end write_block_cb;
 | |
| } iot_start_src_t;
 | |
| 
 | |
| typedef struct _iot_start_rst {
 | |
|     /** upgrade ID, remains the same in single progress */
 | |
|     uint32_t id;
 | |
|     /** start to upgrade result code */
 | |
|     uint32_t flags;
 | |
| } iot_start_rst_t;
 | |
| 
 | |
| typedef struct _iot_trans_cmd {
 | |
|     /** upgrade ID, remains the same in single progress */
 | |
|     uint32_t id;
 | |
|     /** block data use crc or not */
 | |
|     uint32_t crc_flag;
 | |
|     /** data block number */
 | |
|     uint32_t block_num;
 | |
|     /** type of data,PIB or FW,see iot_upgrade_data_type */
 | |
|     uint8_t data_type;
 | |
|     /** iot packet data -- fw block data */
 | |
|     iot_pkt_t *data;
 | |
| } iot_trans_cmd_t;
 | |
| 
 | |
| typedef struct _iot_upg_sts_src {
 | |
|     /** upgrade ID, remains the same in single progress */
 | |
|     uint32_t id;
 | |
|     /** upgrade data block size, unit is byte */
 | |
|     uint32_t block_size;
 | |
|     /** type of data,PIB or FW,see iot_upgrade_data_type */
 | |
|     uint32_t file_type;
 | |
|     /** bitmap start position, unit is byte */
 | |
|     uint32_t bmp_start;
 | |
|     /** bitmap length, unit is byte */
 | |
|     uint32_t bmp_len;
 | |
| } iot_upg_sts_src_t;
 | |
| 
 | |
| typedef struct _iot_upg_sts_rst {
 | |
|     /** upgrade ID, remains the same in single progress */
 | |
|     uint32_t id;
 | |
|     /** upgrade data block size */
 | |
|     uint32_t block_size;
 | |
|     /** upgrade current state */
 | |
|     uint32_t state;
 | |
|     /** sign bitmap first zero position */
 | |
|     uint32_t pos_zero;
 | |
|     /** bitmap size: > 444K/100 */
 | |
|     uint8_t *bitmap;
 | |
| } iot_upg_sts_rst_t;
 | |
| 
 | |
| typedef struct _iot_pkg_upg_sts_src {
 | |
|     /** upgrade ID, remains the same in single progress */
 | |
|     uint32_t id;
 | |
|     /** upgrade data block size, unit is byte */
 | |
|     uint32_t block_size;
 | |
|     /** start block index in bitmap */
 | |
|     uint32_t block_index;
 | |
|     /** block count to query */
 | |
|     uint32_t block_cnt;
 | |
| } iot_pkg_upg_sts_src_t;
 | |
| 
 | |
| typedef struct _iot_pkg_upg_sts_rst {
 | |
|     /** upgrade ID, remains the same in single progress */
 | |
|     uint32_t id;
 | |
|     /** upgrade current state */
 | |
|     uint32_t state;
 | |
|     /** start block index in bitmap */
 | |
|     uint32_t block_index;
 | |
|     /** block count queried */
 | |
|     uint32_t block_cnt;
 | |
|     /** size of the bitmap buffer in byte */
 | |
|     uint32_t bmp_size;
 | |
|     /** bitmap size: > 444K/100 */
 | |
|     uint8_t *bitmap;
 | |
| } iot_pkg_upg_sts_rst_t;
 | |
| 
 | |
| typedef struct _iot_sta_info_src {
 | |
|     /** query list id */
 | |
|     uint8_t list;
 | |
| } iot_sta_info_src_t;
 | |
| 
 | |
| typedef struct _iot_sta_info_rst {
 | |
|     /** query list id */
 | |
|     uint8_t list;
 | |
|     /** upgrade ID, remains the same in single progress */
 | |
|     uint32_t id;
 | |
|     uint32_t info;
 | |
| } iot_sta_info_rst_t;
 | |
| 
 | |
| typedef struct _iot_upg_block_info_src {
 | |
|     /** upgrade ID, remains the same in single progress */
 | |
|     uint32_t id;
 | |
|     /** start block index in bitmap */
 | |
|     uint32_t block_index;
 | |
|     /** type of data,PIB or FW,see iot_upgrade_data_type */
 | |
|     uint32_t file_type;
 | |
| }iot_upg_block_info_src;
 | |
| 
 | |
| typedef struct _iot_upg_block_info_rst {
 | |
|     /** upgrade ID, remains the same in single progress */
 | |
|     uint32_t id;
 | |
|     /** is unwritten block */
 | |
|     bool_t   blank;
 | |
|     /** type of data,PIB or FW,see iot_upgrade_data_type */
 | |
|     uint32_t file_type;
 | |
|     uint32_t next_blank_block_index;
 | |
| }iot_upg_block_info_rst;
 | |
| 
 | |
| typedef struct _iot_upg_ext_file_info_rst {
 | |
|     /* start offset */
 | |
|     uint32_t offset;
 | |
|     /* external upgrade file size */
 | |
|     uint32_t file_size;
 | |
|     /* external upgrade file crc */
 | |
|     uint32_t file_crc;
 | |
| }iot_upg_ext_file_info_rst;
 | |
| 
 | |
| typedef struct _iot_upg_bp_resume_info {
 | |
|     /* upgrade state, see UPGRADE_BP_STATE_XXX */
 | |
|     uint8_t state;
 | |
|     /* upgrade type, see UPGRADE_GET_METHOD_XXX */
 | |
|     uint8_t upgrade_type;
 | |
|     /* external device upgrade flag */
 | |
|     uint8_t ext_upgrade_flag;
 | |
|     /* upgrade pib part flag */
 | |
|     uint8_t upgrade_pib_flag;
 | |
|     /* upgrade fw part flag */
 | |
|     uint8_t upgrade_fw_flag;
 | |
|     /* upgrade cus part flag */
 | |
|     uint8_t upgrade_cus_flag;
 | |
|     /* file crc */
 | |
|     uint32_t file_crc;
 | |
|     /* file len */
 | |
|     uint32_t file_len;
 | |
|     /* fw part checksum */
 | |
|     uint32_t fw_checksum;
 | |
|     /* pib part checksum */
 | |
|     uint32_t pib_checksum;
 | |
|     /* cus part checksum */
 | |
|     uint32_t cus_checksum;
 | |
| }iot_upg_bp_resume_info_t;
 | |
| 
 | |
| #define UPGRADE_VALUE_CHECK(src, dest, str) \
 | |
|     if ( src != dest ) { \
 | |
|         iot_printf(" %s(%d): %s\n", __FUNCTION__, __LINE__, str); \
 | |
|         return (1); \
 | |
|     }
 | |
| /**
 | |
|  * @brief - get a random value as the length.
 | |
|  *          only when file length from flash is 0.
 | |
|  * @return: file length
 | |
|  */
 | |
| uint32_t iot_upgrade_get_backup_len();
 | |
| 
 | |
| /**
 | |
|  * @brief - get a random value as the crc.
 | |
|  *          only when CRC from flash is 0.
 | |
|  * @return: file crc
 | |
|  */
 | |
| uint32_t iot_upgrade_get_backup_crc();
 | |
| 
 | |
| /**
 | |
|  * @brief: get boot partition id. This mehtod shall be called before calling
 | |
|  *         commit method.
 | |
|  * @param boot_part: 0 for part 0. 1 for part 1.
 | |
|  * @retval: 0 for success case. other for failed case.
 | |
|  */
 | |
| uint32_t iot_upgrade_get_part(uint32_t *boot_part);
 | |
| 
 | |
| /**
 | |
|  * @brief: get the partition id other than the boot partition.
 | |
|  * @retval: id of the boot partition id. User shall make sure
 | |
|  *          this value is valid.
 | |
|  */
 | |
| uint32_t iot_upgrade_get_another_part(uint32_t part);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_get_fw_crc() - get upgrade firmware crc value
 | |
|  * @param part: firmware partition number
 | |
|  *
 | |
|  * @return              0 - failed case
 | |
|  * @return              other value for CRC
 | |
|  */
 | |
| uint32_t iot_upgrade_get_fw_crc(uint32_t part);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_get_upgrade_status() - get upgrade status
 | |
|  *
 | |
|  * @return              0xff - failed case
 | |
|  * @return              other value for upgrade status
 | |
|  */
 | |
| uint32_t iot_upgrade_get_upgrade_status();
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_get_fw_size() - get upgrade firmware size
 | |
|  * @param part: firmware partition number
 | |
|  *
 | |
|  * @return              0 - failed
 | |
|  * @return          other - the crc value
 | |
|  */
 | |
| uint32_t iot_upgrade_get_fw_size(uint32_t part);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_get_fw_sts() - get upgrade firmware status
 | |
|  * @param part: firmware partition number
 | |
|  * @param crc: firmware status
 | |
|  *
 | |
|  * @return              0 - succeed
 | |
|  * @return              1 - fail
 | |
|  */
 | |
| uint32_t iot_upgrade_get_fw_sts(uint32_t part, char *sts);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_get_trail_run_dur() - get upgrade running period time
 | |
|  * @param part:     firmware partition number
 | |
|  * @return:         trail run duration
 | |
|  */
 | |
| uint32_t iot_upgrade_get_trail_run_dur(uint32_t part);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_get_fw_blksize() - get upgrade firmware block size
 | |
|  * @param part:     firmware partition number
 | |
|  * @return:         firmware block size
 | |
|  */
 | |
| uint32_t iot_upgrade_get_fw_blksize(uint32_t part);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_save_fw_crc() - save upgrade firmware crc value
 | |
|  * @param part: firmware partition number
 | |
|  * @param crc: firmware crc value to be saved
 | |
|  */
 | |
| void iot_upgrade_save_fw_crc(uint32_t part, uint32_t crc);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_save_upgrade_status() - save upgrade status
 | |
|  * @param status: upgrade status
 | |
|  */
 | |
| void iot_upgrade_save_upgrade_status(uint32_t status);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_save_fw_size() - save upgrade firmware size
 | |
|  * @param part: firmware partition number
 | |
|  * @param crc: firmware size to be saved
 | |
|  */
 | |
| void iot_upgrade_save_fw_len(uint32_t part, uint32_t len);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_save_fw_sts() - save upgrade firmware status
 | |
|  * @param part: firmware partition number
 | |
|  * @param crc: firmware status to be saved
 | |
|  */
 | |
| void iot_upgrade_save_fw_sts(uint32_t part, uint32_t state);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_save_fw_period() - save upgrade running period time
 | |
|  * @param part:     firmware partition number
 | |
|  * @param tr_dur:   train run duration
 | |
|  */
 | |
| void iot_upgrade_save_trail_run_dur(uint32_t part, uint32_t tr_dur);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_save_fw_blksize() - save upgrade firmware block size
 | |
|  * @param part:     firmware partition number
 | |
|  * @param tr_dur:   train run duration
 | |
|  */
 | |
| void iot_upgrade_save_fw_blksize(uint32_t part, uint32_t blksize);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_reset() - reset the chip
 | |
|  * @return              0 - succeed
 | |
|  * @return              1 - fail
 | |
|  */
 | |
| uint32_t iot_upgrade_reset();
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_start() - Prepare the environment of upgrade and active
 | |
|  *                              transfer-status
 | |
|  * @param rst: pointer to the output of upgrade start structure
 | |
|  * @param src: pointer to the input of upgrade start structure
 | |
|  *
 | |
|  * @return              0 - succeed
 | |
|  * @return              1 - fail
 | |
|  */
 | |
| uint32_t iot_upgrade_start(iot_start_rst_t *rst, iot_start_src_t *src);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_read_fw_data() - Read fw data from flash
 | |
|  * @param data: data buffer
 | |
|  * @param size: data buffer size
 | |
|  * @param offset: part offset from which to read
 | |
|  * @param part: file part to read
 | |
|  * @retval:             0 - succeed
 | |
|  * @retval:             1 - fail
 | |
|  */
 | |
| uint32_t iot_upgrade_read_fw_data(void *data, uint32_t size,
 | |
|     uint32_t offset, uint32_t part);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_trans() - Handle a transfer command frame.
 | |
|  *        It always free trans->pkt.
 | |
|  * @param trans: pointer to the input of upgrade transfer command infos
 | |
|  * @return: ERR_OK for successful case.
 | |
|  * @return: other value for failed case. see ERR_XXX.
 | |
|  */
 | |
| uint32_t iot_upgrade_trans(iot_trans_cmd_t *trans);
 | |
| 
 | |
| /*
 | |
|  * @brief: iot_upgrade_read - read specific block from flash
 | |
|  * @param trans: pointer to iot_trans_cmd_t specific the block to read
 | |
|  * @return: ERR_OK for successful case.
 | |
|  * @return: other value for failed case. see ERR_XXX.
 | |
|  */
 | |
| uint32_t iot_upgrade_read(iot_trans_cmd_t *trans);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_query_written_block_num() - Query written block num
 | |
|  *
 | |
|  * @retval:             written block num
 | |
|  */
 | |
| uint32_t iot_upgrade_query_written_block_num();
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_query_next_block() - Query next blank block
 | |
|  * @param rst: result info
 | |
|  * @param src: current index and file type info
 | |
|  *
 | |
|  * @retval:             0 - succeed
 | |
|  * @retval:             1 - fail
 | |
|  */
 | |
| uint32_t iot_upgrade_query_next_block(iot_upg_block_info_rst *rst,
 | |
|     iot_upg_block_info_src *src);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_is_completed() - Check if no block is blank
 | |
|  *
 | |
|  * @retval:             0 - uncompleted
 | |
|  * @retval:             1 - completed
 | |
|  */
 | |
| uint32_t iot_upgrade_is_completed();
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_query_block_info() - Query specified block in
 | |
|  * @param rst: result info
 | |
|  * @param src: index and file type info
 | |
|  *
 | |
|  * @retval:             0 - succeed
 | |
|  * @retval:             1 - fail
 | |
|  */
 | |
| uint32_t iot_upgrade_query_block_info(iot_upg_block_info_rst *rst,
 | |
|     iot_upg_block_info_src *src);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_query_state() - Query upgrade state
 | |
|  * @param rst : pointer to the output of upgrade query structure
 | |
|  * @param src : pointer to the input of upgrade query structure
 | |
|  *
 | |
|  * @return              0 - succeed
 | |
|  * @return              1 - fail
 | |
|  */
 | |
| uint32_t iot_upgrade_query_state(iot_upg_sts_rst_t *rst,
 | |
|                                  iot_upg_sts_src_t *src);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_query_station_info() - Query station infomations
 | |
|  * @param rst: pointer to the output of station info structure
 | |
|  * @param src: pointer to the input of station info structure
 | |
|  *
 | |
|  * @return              0 - succeed
 | |
|  * @return              1 - fail
 | |
|  */
 | |
| uint32_t iot_upgrade_query_station_info(iot_sta_info_rst_t * rst,
 | |
|                                         iot_sta_info_src_t *src);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_commit() - Handle a commit command when upgrade frame
 | |
|  *                               transfer finished
 | |
|  * @param upgrade_id:   current upgrade id
 | |
|  *
 | |
|  * @return              0 = succeed
 | |
|  * @return              1 = fail
 | |
|  */
 | |
| uint32_t iot_upgrade_commit(uint32_t upgrade_id);
 | |
| 
 | |
| /**
 | |
|  * @brief: read data of PIB/FW from flash
 | |
|  * @param buf:          the buffer to store request data
 | |
|  * @param read_size:    number of byte to read. shall aligh to 4 byte
 | |
|  * @param offset:       offset of the PIB/FW to be read
 | |
|  * @param read_part:    see UPGRADE_DATA_TYPE_XXX. not support
 | |
|  *                      UPGRADE_DATA_TYPE_PKG.
 | |
|  * @param cache_flag:   1 - cache mode, 0 - normal mode.
 | |
|  * @retval:             ERR_OK for successfully case.
 | |
|  *                      See ERR_XXX for failed case.
 | |
|  */
 | |
| uint32_t iot_pkg_upgrade_read(uint8_t *buf, uint32_t read_size, uint32_t offset,
 | |
|     uint32_t read_part, uint8_t cache_flag);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_cancel_commit() - Handle a cancel commit command
 | |
|  * @param upgrade_id:   current upgrade id
 | |
|  *
 | |
|  * @return              0 = succeed
 | |
|  * @return              1 = fail
 | |
|  */
 | |
| uint32_t iot_upgrade_cancel_commit(uint32_t upgrade_id);
 | |
| 
 | |
| /**
 | |
|  * @ @brief: get length of pib read only size
 | |
|  * @return: length of pib ro
 | |
|  */
 | |
| uint32_t iot_upgrade_get_pib_ro_size();
 | |
| 
 | |
| /**
 | |
|  * @ @brief: get length of pib
 | |
|  * @return: length of pib
 | |
|  */
 | |
| uint32_t iot_upgrade_get_pib_len();
 | |
| 
 | |
| /**
 | |
|  * @ @brief: get length of fw
 | |
|  * @return: length of fw
 | |
|  */
 | |
| uint32_t iot_upgrade_get_fw_len();
 | |
| 
 | |
| /**
 | |
|  * @ @brief: get length of cus
 | |
|  * @return: length of cus
 | |
|  */
 | |
| uint32_t iot_upgrade_get_cus_len();
 | |
| 
 | |
| /**
 | |
|  * @brief: set a bit in received bitmap
 | |
|  * @param index: index of the block
 | |
|  * @return: ERR_OK if successed. ERR_FAILED if failed.
 | |
|  */
 | |
| uint32_t iot_pkg_upgrade_set_bit(uint32_t index);
 | |
| 
 | |
| /**
 | |
|  * @brief: check if specific bit is set in received bitmap
 | |
|  * @param index: index of the block
 | |
|  * @return: 1 if the bit was set. 0 for other case.
 | |
|  */
 | |
| uint32_t iot_pkg_upgrade_is_set_bit(uint32_t index);
 | |
| 
 | |
| /**
 | |
|  * @brief: check if all blocks were transferred
 | |
|  * @param block_cnt:    total count of blocks to check
 | |
|  * @return: 1 if all blocks were transferred. 0 for other case.
 | |
|  */
 | |
| uint32_t iot_pkt_upgrade_trans_all_done(uint32_t block_cnt);
 | |
| 
 | |
| /**
 | |
|  * @brief  get header length.
 | |
|  * @param file_hdr: file header data.
 | |
|  * @return header length.
 | |
|  */
 | |
| uint32_t iot_get_file_header_len(uint8_t *file_hdr);
 | |
| 
 | |
| /**
 | |
|  * @brief  get fw length.
 | |
|  * @param file_hdr: file header data.
 | |
|  * @return fw length.
 | |
|  */
 | |
| uint32_t iot_get_file_fw_len(uint8_t *file_hdr);
 | |
| 
 | |
| /**
 | |
|  * @brief  get pib length.
 | |
|  * @param file_hdr: file header data.
 | |
|  * @return pib length.
 | |
|  */
 | |
| uint32_t iot_get_file_pib_len(uint8_t *file_hdr);
 | |
| 
 | |
| /**
 | |
|  * @brief  get cus length.
 | |
|  * @param file_hdr: file header data.
 | |
|  * @return cus length.
 | |
|  */
 | |
| uint32_t iot_get_file_cus_len(uint8_t *file_hdr);
 | |
| 
 | |
| /**
 | |
|  * @brief  get fw start position.
 | |
|  * @param file_hdr: file header data.
 | |
|  * @return fw start address.
 | |
|  */
 | |
| uint32_t iot_get_file_fw_start(uint8_t *file_hdr);
 | |
| 
 | |
| /**
 | |
|  * @brief  get pib start position.
 | |
|  * @param file_hdr: file header data.
 | |
|  * @return pib start address.
 | |
|  */
 | |
| uint32_t iot_get_file_pib_start(uint8_t *file_hdr);
 | |
| 
 | |
| /**
 | |
|  * @brief  get cus start position.
 | |
|  * @param file_hdr: file header data.
 | |
|  * @return cus start address.
 | |
|  */
 | |
| uint32_t iot_get_file_cus_start(uint8_t *file_hdr);
 | |
| 
 | |
| /**
 | |
|  * @brief:  get file type
 | |
|  * @param file_hdr: file header data
 | |
|  * @retval: the file type. see IOT_FILE_TYPE_XXX
 | |
|  */
 | |
| uint32_t iot_get_file_type_value(uint8_t *file_hdr);
 | |
| 
 | |
| /**
 | |
|  * @brief:  get file type and check if local file applicable to local device
 | |
|  * @param file_hdr: file header data
 | |
|  * @retval: the file type. see IOT_FILE_TYPE_XXX
 | |
|  */
 | |
| uint32_t iot_get_file_type(uint8_t *file_hdr);
 | |
| 
 | |
| /**
 | |
|  * @brief:  get file length
 | |
|  * @param file_hdr: file header data
 | |
|  * @retval: length of the file. Or return 0 if file hdr is invalid.
 | |
|  */
 | |
| uint32_t iot_get_file_len(uint8_t *file_hdr);
 | |
| 
 | |
| /**
 | |
|  * @brief:  get file CRC
 | |
|  * @param file_hdr: file header data
 | |
|  * @retval: CRC of the file. Or return 0 if file hdr is invalid.
 | |
|  */
 | |
| uint32_t iot_get_file_crc(uint8_t *file_hdr);
 | |
| 
 | |
| /*
 | |
|  * @brief: check if crc of the file is correct
 | |
|  * @param file_hdr: pointer to file header
 | |
|  * @param len:      length of the file
 | |
|  * @retval:     1 if the crc is valid, 0 invalid.
 | |
|  */
 | |
| uint32_t iot_check_file_crc(uint8_t *file_hdr, uint32_t len);
 | |
| 
 | |
| /**
 | |
|  * @brief:  get file version
 | |
|  * @param file_hdr: file header data
 | |
|  * @retval: version of the file.
 | |
|  */
 | |
| uint32_t iot_get_file_version(uint8_t *file_hdr);
 | |
| 
 | |
| /**
 | |
|  * @brief:  get image type
 | |
|  * @param file_hdr: file header data
 | |
|  * @retval: image type of the file.
 | |
|  */
 | |
| uint8_t iot_get_image_type(uint8_t *file_hdr);
 | |
| 
 | |
| 
 | |
| /**
 | |
|  * @brief:  get vendor id
 | |
|  * @param file_hdr: file header data
 | |
|  * @retval: vendor id of the file.
 | |
|  */
 | |
| uint16_t iot_get_vendor_id(uint8_t *file_hdr);
 | |
| 
 | |
| /**
 | |
|  * @brief: iot_upgrade_is_busy() - check upgrade status is busy
 | |
|  * @retval: 0 for idle status, other for busy status
 | |
|  */
 | |
| uint32_t iot_upgrade_is_busy();
 | |
| 
 | |
| /**
 | |
|  * @brief:  start upgrading with upgrade package file
 | |
|  * @param rst:          pointer to the output of upgrade start structure
 | |
|  * @param upgrade_id:   upgrade id
 | |
|  * @param block_size:   block size
 | |
|  * @param file_size:    size of the upgrade package file.
 | |
|  * @param file_crc:     file crc
 | |
|  * @param block_num:    block number of upgrade file.
 | |
|  * @param ext_upgrade_flag: external devie upgrade flag.
 | |
|  * @param file_hdr:     pointer to buffer of file header
 | |
|  * @retval: 0 for succeed case. Other for failed case.
 | |
|  */
 | |
| uint32_t iot_pkg_upgrade_start(iot_start_rst_t *rst, uint32_t upgrade_id,
 | |
|     uint32_t block_size, uint32_t file_size, uint32_t file_crc,
 | |
|     uint32_t block_num, uint8_t ext_upgrade_flag, uint8_t *file_hdr);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_switch_part(): swicth boot partition to another
 | |
|  * @retval: 0 for succeed case. Other for failed case.
 | |
|  */
 | |
| uint32_t iot_upgrade_switch_part();
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_get_switch_part_info() - get the last switch result
 | |
|  * @retval: switch part result, see - IOT_PLC_UPGRADE_SWITCH_XXX.
 | |
|  */
 | |
| uint8_t iot_upgrade_get_switch_part_info();
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_set_first_boot() - set first boot flag after upgrade
 | |
|  * @param is_first_boot: is first boot
 | |
|  */
 | |
| void iot_upgrade_set_first_boot(bool_t first_boot);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_is_first_boot() - query if first boot after upgrade
 | |
|  * @return              true - first boot
 | |
|  * @return              false - not first boot
 | |
|  */
 | |
| bool_t iot_upgrade_is_first_boot();
 | |
| 
 | |
| /**
 | |
|  * @brief: transfer data to flash. It always consume trans->pkt.
 | |
|  * @param trans:    the trans file obj with data to be transfered.
 | |
|  * @retval:         ERR_OK for successfully case. other value for failed case.
 | |
|  *                  See ERR_XXX for failed case.
 | |
|  */
 | |
| uint32_t iot_pkg_upgrade_trans(iot_trans_cmd_t *trans);
 | |
| 
 | |
| /**
 | |
|  * @brief: query upgrade state for upgrading by package
 | |
|  * @param rst: pointer to the output of upgrade start structure
 | |
|  * @param src: pointer to the input of upgrade start structure
 | |
|  * @retval: ERR_OK for succeed case. see ERR_XXX for failed case.
 | |
|  */
 | |
| uint32_t iot_pkg_upgrade_query_state(iot_pkg_upg_sts_rst_t *rst,
 | |
|     iot_pkg_upg_sts_src_t *src);
 | |
| 
 | |
| /**
 | |
|  * @brief: get pad value
 | |
|  * @return: the pad value in upgrading file
 | |
|  */
 | |
| uint8_t iot_pkg_get_pad_value();
 | |
| 
 | |
| /**
 | |
|  * @brief: query station information
 | |
|  * @param rst: pointer to the output of station info structure
 | |
|  * @param src: pointer to the input of station info structure
 | |
|  * @retval:    ERR_OK for succeed case. see ERR_XXX for failed case.
 | |
|  */
 | |
| uint32_t iot_pkg_upgrade_query_station_info(iot_sta_info_rst_t * rst,
 | |
|     iot_sta_info_src_t *src);
 | |
| /**
 | |
|  * @brief: commit a sg upgrade from package
 | |
|  * @param upgrade_id:   upgrade id
 | |
|  * @retval:     ERR_OK for succeed case. see ERR_XXX for failed case.
 | |
|  */
 | |
| uint32_t iot_pkg_upgrade_commit(uint32_t upgrade_id);
 | |
| 
 | |
| /**
 | |
|  * @brief: cancel a sg upgrade from package
 | |
|  * @param upgrade_id:       upgrade id
 | |
|  * @param cancel_commit:   cancel commit
 | |
|  * @retval:     ERR_OK for succeed case. see ERR_XXX for failed case.
 | |
|  */
 | |
| uint32_t iot_pkg_upgrade_cancel_commit(uint32_t upgrade_id,
 | |
|     uint32_t cancel_commit);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_pkg_upgrade_reset() - reset the chip for upgrading through package
 | |
|  * @return              0 - succeed
 | |
|  * @return              1 - fail
 | |
|  */
 | |
| uint32_t iot_pkg_upgrade_reset();
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_fw_hdr_img_crc_check() - check img crc
 | |
|  * @retval:   0 - succeed
 | |
|  * @retval:   1 - fail
 | |
|  */
 | |
| uint8_t iot_upgrade_fw_hdr_img_crc_check();
 | |
| 
 | |
| /**
 | |
|  * @brief iot_running_fw_get_size() - get the compressed firmware size executed.
 | |
|  * @return fw size.
 | |
|  */
 | |
| uint32_t iot_running_fw_get_size(void);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_running_fw_read() - get the firmware data currently executed.
 | |
|  * @param offset - offset position, ranging from 0 ~ fw size.
 | |
|  * @param buffer - buffer to store FW data.
 | |
|  * @param length - length to read data.
 | |
|  * @return number of bytes read successfully.
 | |
|  */
 | |
| uint32_t iot_running_fw_read(uint32_t offset,uint8_t *buffer,
 | |
|     uint32_t length);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_pkg_upgrade_file_crc_update() - calculate the file crc value.
 | |
|  * @param init_vect - the init vector.
 | |
|  * @param pbyData - data to be calculated.
 | |
|  * @param stLength - length the data.
 | |
|  * @param index - block count of data.
 | |
|  * @return calculate value.
 | |
|  */
 | |
| uint32_t iot_pkg_upgrade_file_crc_update(uint32_t init_vect, uint8_t *buffer,
 | |
|     uint32_t length, uint32_t index);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_get_ext_file_info() - get external upgrade file info.
 | |
|  * @param ext_rst - pointer to the output of file info structure.
 | |
|  * @return ERR_OK - get scusseed, other - get fail.
 | |
|  */
 | |
| uint32_t iot_upgrade_get_ext_file_info(iot_upg_ext_file_info_rst *ext_rst);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_upgrade_get_bp_resume_info() - get breakpoint resume info.
 | |
|  * @param method - see UPGRADE_GET_METHOD_XXX.
 | |
|  * @param resume_info - pointer to the output of resume info structure.
 | |
|  * @return ERR_OK - get scusseed, other - get fail.
 | |
|  */
 | |
| uint32_t iot_upgrade_get_bp_resume_info(uint8_t method,
 | |
|     iot_upg_bp_resume_info_t *resume_info);
 | |
| /**
 | |
|   * @}
 | |
|   */
 | |
| 
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| }
 | |
| #endif
 | |
| 
 | |
| #endif
 |