Files
kunlun/driver/inc/upgrade.h
2024-09-28 14:24:04 +08:00

132 lines
3.4 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 UPGRADE_DRIVER_H
#define UPGRADE_DRIVER_H
#include "iot_pkt_api.h"
#include "iot_queue.h"
#include "iot_mem_pool.h"
#include "iot_upgrade_api.h"
#ifdef __cplusplus
extern "C" {
#endif
/** \defgroup Driver_APIs UPGARDE APIs
* @brief UPGRADE APIs
*
*
*/
/** @addtogroup Driver_APIs
* @{
*
*/
#define UPGRADE_DEFAULT_BLOCK_SIZE (400)
/*
* upgrade file max size = 700k bytes
* recover block size = 1200 bytes
* bitmap size = 700 * 1024 / 1200 / 8
*/
#define UPGRADE_RECOVER_BITMAPT_SIZE (75)
typedef struct node_t {
iot_pkt_t *data; /* firmware data block */
uint32_t block_num; /* data block number */
struct node_t *next; /* next node */
} node_t, *node_ptr;
typedef struct {
node_ptr head, tail;
} link_queue;
typedef enum {
UPGRADE_TYPE_INVALID = 0x0,
UPGRADE_TYPE_CLI,
UPGRADE_TYPE_SG,
} iot_upgrade_type_t;
typedef enum {
STATUS_IDLE = 0x0,
STATUS_INIT,
STATUS_TRANS,
STATUS_FINISH,
STATUS_COMMIT,
} iot_upgrade_sts_t;
typedef enum {
QUERY_STA_ID_NUM = 0x0,
QUERY_STA_ID_VER,
QUERY_STA_ID_BOOTLOADER,
QUERY_STA_ID_CRC,
QUERY_STA_ID_LEN,
QUERY_STA_ID_DEV_TYPE,
QUERY_STA_ID_RESERVED
} iot_query_sta_info;
#pragma pack(push)
#pragma pack (1)
/* for recover upgrade when sta power off and on */
typedef struct _iot_upgrade_recover_info {
uint8_t type; /* upgrade type */
uint32_t id; /* upgrade id, for sg */
uint32_t size; /* file size, for sg */
uint32_t version; /* file version, for cli */
uint32_t header_crc; /* file header crc, for sg */
uint32_t file_crc; /* file crc, for sg and cli */
/* bitmap for storing block, for sg and cli */
uint8_t bitmap[UPGRADE_RECOVER_BITMAPT_SIZE];
} iot_upgrade_recover_info_t;
#pragma pack(pop)
#define UPGRADE_VALUE_CHECK(src, dest, str) \
if ( src != dest ) { \
iot_printf(" %s(%d): %s\n", __FUNCTION__, __LINE__, str); \
return (1); \
}
/**
* @brief iot_upgrade_init(): init uprade module
* @retval: ERR_OK for successful case. ERR_FAIL for failed case.
*/
uint32_t iot_upgrade_init();
/**
* @brief: check mode of the file
* @param file_hdr: file header data
* @retval: get mode of the file.
*/
uint8_t iot_get_file_mode(uint8_t *file_hdr);
/**
* @brief: get enc mode of the upgrade file
* @param file_hdr: file header data
* @retval: enc mode of the file. see IOT_FILE_MODE_XXX.
* IOT_FILE_MODE_UNKNOWN if file format is unknown.
*/
uint8_t iot_pkt_upgrade_get_enc_mode(uint8_t *file_hdr);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* UPGRADE_DRIVER_H */