This commit is contained in:
lmx
2025-10-29 13:10:02 +08:00
commit 49a07fa419
2284 changed files with 642060 additions and 0 deletions

View File

@ -0,0 +1,71 @@
#ifndef _DUAL_BANK_API_H_
#define _DUAL_BANK_API_H_
/* @brief:Api for getting the buffer size for temporary storage
*/
u32 get_dual_bank_passive_update_max_buf(void);
/* @brief:Initializes the update task,and setting the crc value and file size of new fw;
* @param fw_crc:crc value of new fw file
* @param fw_size:total size of new fw file
* @param priv:reserved
* @param max_ptk_len: Supported maxium length of every programming,it decides the max size of programming every time
*/
u32 dual_bank_passive_update_init(u32 fw_crc, u32 fw_size, u16 max_pkt_len, void *priv);
/* @brief:exit the update task
* @param priv:reserved
*/
u32 dual_bank_passive_update_exit(void *priv);
/* @brief:Judge whether enough space for new fw file
* @note: it should be called after dual_bank_passive_update_init(...);
* @param fw_size:fw size of new fw file
*/
u32 dual_bank_update_allow_check(u32 fw_size);
/* @brief:copy the data to temporary buffer and notify task to write non-volatile storage
* @param data:the pointer to download data
* @param len:the length to download data
* @param write_complete_cb:callback for programming done,return 0 if no err occurred
*/
u32 dual_bank_update_write(void *data, u16 len, int (*write_complete_cb)(void *priv));
/* @brief: caculate all the data had flashed,and compare with the cre value intializeed when update init;
* @crc_init_hdl:if it equals NULL,use internal implementation(CRC16-CCITT Standard);otherwise,use user's customization;
* @crc_calc_hdl:if it equals NULL,use internal implementation(CRC16-CCITT Standard);otherwise,use user's customization;
* @verify_result_hdl:when the verification completed,this callback for result notification;
* if crc_res equals 1,crc verification passed,if 0,the verification failed.
*/
u32 dual_bank_update_verify(void (*crc_init_hdl)(void), u32(*crc_calc_hdl)(u32 init_crc, u8 *data, u32 len), int (*verify_result_hdl)(int crc_res));
/* @brief:After the new fw verification succeed,call this api to program the new boot info for new fw
* @param burn_boot_info_result_hdl:this callback for error notification
* if err equals 0,the operate to burn boot info succeed,other value means to fail.
*/
u32 dual_bank_update_burn_boot_info(int (*burn_boot_info_result_hdl)(int err));
enum {
CLEAR_APP_RUNNING_BANK = 0,
CLEAR_APP_UPDATE_BANK,
};
/* @brief:this api for erasing the boot info of specific bank,it should be called much carefully
* @param type:it decides which bank's boot info would be erased;
* clean the boot info of running bank and call system_reset,system will run the other bank if available;
*/
int flash_update_clr_boot_info(u8 type);
/* @brief:this api for user read flash data to calculate crc
* @param offset: the offset relative to update area
read_buf: user data buffer
read_len: read length
@returns: Actual read length
*/
u32 dual_bank_update_read_data(u32 offset, u8 *read_buf, u32 read_len);
#endif

View File

@ -0,0 +1,43 @@
#ifndef _UART_DEV_
#define _UART_DEV_
#include "typedef.h"
#define MSG_UART_UPDATE_READY 0x1
#define MSG_UART_UPDATE_START 0x2
#define MSG_UART_UPDATE_START_RSP 0X3
#define MSG_UART_UPDATE_READ_RSP 0x4
#define PROTOCAL_SIZE 528
#define SYNC_SIZE 6
#define SYNC_MARK0 0xAA
#define SYNC_MARK1 0x55
typedef union {
u8 raw_data[PROTOCAL_SIZE + SYNC_SIZE];
struct {
u8 mark0;
u8 mark1;
u16 length;
u8 data[PROTOCAL_SIZE + 2]; //最后CRC16
} data;
} protocal_frame_t;
struct file_info {
u8 cmd;
u32 addr;
u32 len;
} __attribute__((packed));
typedef struct __update_io {
u16 rx;
u16 tx;
u8 input_channel; //input channel选择根据方案选择未被使用的channel
u8 output_channel; //同input channel
} uart_update_cfg;
void uart_update_init(uart_update_cfg *cfg);
void sava_uart_update_param(void);
#endif

161
include_lib/update/update.h Normal file
View File

@ -0,0 +1,161 @@
#ifndef _UPDATE_H_
#define _UPDATE_H_
#include "typedef.h"
extern u32 UPDATA_BEG;
#define UPDATA_FLAG_ADDR ((void *)((u32)&UPDATA_BEG + 0x08))
#define BOOT_STATUS_ADDR ((void *)((u32)&UPDATA_BEG)) //预留8个bytes
#define UPDATA_MAGIC (0x5A00) //防止CRC == 0 的情况
typedef enum {
UPDATA_NON = UPDATA_MAGIC,
UPDATA_READY,
UPDATA_SUCC,
UPDATA_PARM_ERR,
UPDATA_DEV_ERR,
UPDATA_KEY_ERR,
} UPDATA_RESULT;
typedef enum {
USB_UPDATA = UPDATA_MAGIC, //0x5A00
SD0_UPDATA, //0x5A01
SD1_UPDATA,
PC_UPDATA,
UART_UPDATA,
BT_UPDATA,
BLE_APP_UPDATA,
SPP_APP_UPDATA,
DUAL_BANK_UPDATA,
BLE_TEST_UPDATA,
NORFLASH_UPDATA,
//NOTE:以上的定义不要调整,新升级方式在此添加,注意加在USER_NORFLASH_UFW_UPDATA之前;
USER_NORFLASH_UFW_UPDATA,
NON_DEV = 0xFFFF,
} UPDATA_TYPE;
// sd
enum {
SD_CONTROLLER_0 = 1,
SD_CONTROLLER_1,
};
enum {
SD0_IO_A = 1,
SD0_IO_B,
SD1_IO_A,
SD1_IO_B,
SD0_IO_C,
SD0_IO_D,
SD0_IO_E,
SD0_IO_F,
};
typedef struct _UPDATA_SD {
u8 control_type;
u8 control_io;
u8 online_check_way;
u8 max_data_baud;
u16 wDevTimeOutMax;
u8 per_online_status;
u8 hc_mode;
u8(*io_det_func)(void);
u8 power;
u8 control_io_clk;
u8 control_io_cmd;
u8 control_io_dat;
} UPDATA_SD;
// uart
typedef struct _UPDATA_UART {
u32 control_io_tx; //<IO口对接
u32 control_io_rx; //<IO口对接
u32 control_baud; //<波特率
u32 control_timeout; //<超时单位10ms
} UPDATA_UART; /*共12个bytes*/
#define UPDATE_PARAM_MAGIC 0x5441
#if (USE_SDFILE_NEW == 1)
typedef struct _UPDATA_PARM {
u16 parm_crc;
u16 parm_type; //UPDATA_TYPE:sdk pass parm to uboot
u16 parm_result; //UPDATA_TYPE:uboot return result to sdk
u16 magic; //0x5441
//8byte
union {
struct {
u8 file_path[32]; //updata file path
};
struct {
u8 file_patch[32]; //updata file path
};
};
u8 parm_priv[32]; //sd updata
//64byte
u32 ota_addr;
u16 ext_arg_len;
u16 ext_arg_crc;
//8 byte
} UPDATA_PARM;
enum EXT_ARG_TYPE {
EXT_LDO_TRIM_RES = 0,
EXT_JUMP_FLAG,
EXT_TYPE_MAX = 0xff,
};
struct ext_arg_t {
u8 type;
u8 len;
u8 *data;
};
//8+64+8+32 =112;
#else
typedef struct _UPDATA_PARM {
u16 parm_crc;
u16 parm_type; //UPDATA_TYPE:sdk pass parm to uboot
u16 parm_result; //UPDATA_TYPE:uboot return result to sdk
u8 file_patch[32]; //updata file patch
u8 parm_priv[32]; //sd updata
} UPDATA_PARM;
#endif
#define UPDATE_PRIV_PARAM_LEN 32
void update_mode_api_v2(UPDATA_TYPE type, void (*priv_param_fill_hdl)(UPDATA_PARM *p), void (*priv_update_jump_handle)(int type));
void update_param_priv_fill(UPDATA_PARM *p, void *priv, u16 priv_len);
u16 update_result_get(void);
bool device_is_first_start();
int update_result_deal();
void update_result_set(u16 result);
void update_clear_result();
bool update_success_boot_check(void);
typedef u8(*update_handler_t)(void);
typedef enum _UPDATE_STATE_T {
UPDATE_TASK_INIT,
UPDATE_CH_INIT,
UPDATE_CH_SUCESS_REPORT,
UPDATE_CH_EXIT,
} UPDATE_STATE_T;
struct update_target {
char *name;
update_handler_t driver_close;
};
//void update_param_private_fill_handle_register(void (*handle)(UPDATA_PARM *p));
#define REGISTER_UPDATE_TARGET(target) \
const struct update_target target sec(.update_target)
extern const struct update_target update_target_begin[];
extern const struct update_target update_target_end[];
#define list_for_each_update_target(p) \
for (p = update_target_begin; p < update_target_end; p++)
#endif

View File

@ -0,0 +1,35 @@
SECTIONS
{
.data : ALIGN(4)
{
update_data_start = .;
update_data_end = .;
} > ram0
.bss (NOLOAD) :ALIGN(4)
{
update_bss_start = .;
*(.update_bss)
update_bss_end = .;
} > ram0
.text : ALIGN(4)
{
update_code_start = .;
*(.bt_updata_ram_code)
*(.update_const)
*(.update_code)
update_code_end = .;
} > code0
UPDATE_CODE_TOTAL_SIZE = update_code_end - update_code_start;
}

View File

@ -0,0 +1,197 @@
#ifndef _UPDATE_LOADER_DOWNLOAD_H_
#define _UPDATE_LOADER_DOWNLOAD_H_
#include "typedef.h"
extern const int config_update_mode;
extern const int support_dual_bank_update_en;
#define UPDATE_MODULE_IS_SUPPORT(x) (config_update_mode & x)
#define UPDATE_SUPPORT_DEV_IS_NULL() (config_update_mode == UPDATE_DEV_NULL)
#define UPDATE_DUAL_BANK_IS_SUPPORT() (1 == support_dual_bank_update_en)
struct __tws_ota_para {
u32 fm_size;
u32 fm_crc;
u16 max_pkt_len;
};
typedef struct _ret_code {
int stu;
u8 err_code;
} update_ret_code_t;
typedef struct _update_op_api_tws {
//for tws ota start
int (*tws_ota_start)(void *priv);
int (*tws_ota_data_send)(u8 *buf, u16 len);
int (*tws_ota_err)(u8);
u16(*enter_verfiy_hdl)(void *priv);
u16(*exit_verify_hdl)(u8 *, u8 *);
u16(*update_boot_info_hdl)(void *priv);
int (*tws_ota_result_hdl)(u8);
int (*tws_ota_data_send_pend)(void);
//for user chip update
int (*tws_ota_user_chip_update_send)(u8 cmd, u8 *buf, u16 len);
} update_op_tws_api_t; //给tws同步升级用的接口
update_op_tws_api_t *get_tws_update_api(void);
void tws_sync_update_crc_handler_register(void (*crc_init_hdl)(void), u32(*crc_calc_hdl)(u32 init_crc, u8 *data, u32 len));
void update_start_exit_sniff(void);
void set_ota_status(u8 status);
typedef struct _update_op_api_t {
void (*ch_init)(void (*resume_hdl)(void *priv), int (*sleep_hdl)(void *priv));
u16(*f_open)(void);
u16(*f_read)(void *fp, u8 *buff, u16 len);
int (*f_seek)(void *fp, u8 type, u32 offset);
u16(*f_stop)(u8 err);
int (*notify_update_content_size)(void *priv, u32 size);
void (*ch_exit)(void *priv);
} update_op_api_t;
extern const update_op_api_t lmp_ch_update_op;
extern const update_op_api_t strg_ch_update_op;
extern const update_op_api_t rcsp_update_op;
#define UPDATE_SEAGNMENT_EN 1
enum {
UPDATE_LOADER_OK = 1,
UPDATE_LOADER_ERR,
};
enum {
PKT_FLAG_MIDDLE = 0,
PKT_FLAG_FIRST,
PKT_FLAG_LAST,
};
//update result code bitmap
#define UPDATE_RESULT_FLAG_BITMAP BIT(7)
//update result code;
enum {
UPDATE_RESULT_ERR_NONE = 0,
UPDATE_RESULT_FILE_SIZE_ERR = 0x1, //文件大小错误
UPDATE_RESULT_LOADER_SIZE_ERR = 0x2, //loader大小错误
UPDATE_RESULT_LOADER_VERIFY_ERR, //update loader校验失败
UPDATE_RESULT_REMOTE_FILE_HEAD_ERR, //读升级文件头错误
UPDATE_RESULT_LOCAL_FILE_HEAD_ERR = 0x5, //读flash文件头错误
UPDATE_RESULT_NOT_FIND_TARGET_FILE_ERR, //找不到目标文件(ota.bin找不到对应loader)
UPDATE_RESULT_FILE_OPERATION_ERR, //文件操作失败
UPDATE_RESULT_FLASH_DATA_VERIFY_ERR, //flash数据校验失败
UPDATE_RESULT_UBOOT_NOT_MATCH = 0x09, //UBOOT不匹配
UPDATE_RESULT_PRODUCT_INFO_NOT_MATCH = 0x0a, //芯片型号不匹配
UPDATE_RESULT_EX_DSP_UPDATE_ERR, //外部IC升级出错;
UPDATE_RESULT_CFG_UPDATE_ERR, //配置升级出错
UPDATE_RESULT_FLASH_ERASE_ERR = 0x0d, //flash 擦失败(可能是写保护)
UPDATE_RESULT_REMOTE_FILE_NOT_MATCH, //升级文件不匹配
UPDATE_RESULT_ANC_CFG_UPDATE_ERR, //ANC配置升级出错
UPDATE_RESULT_ANC_COEF_UPDATE_ERR = 0x10, //ANC配置升级出错
UPDATE_RESULT_OTA_TWS_NO_RSP, //对耳同步升级传输数据没有回复
UPDATE_RESULT_RESOURCE_LIMIT, //资源不足
UPDATE_RESULT_OTA_TWS_START_ERR, //对耳启动升级失败
UPDATE_RESULT_OTA_TWS_CRC_ERROR, //对耳校验失败
UPDATE_RESULT_OTA_APP_EXIT = 0x15, //升级过程APP强制退出
UPDATE_RESULT_TWS_NO_CONNECT, //对耳未连接
UPDATE_RESULT_READ_REMOTE_FILE_ERR, //读取不到远端数据
UPDATE_RESULT_UFW_FLASH_HEAD_CRC_ERR, //校验远端文件里的FLASH_HEAD失败
UPDATE_RESULT_UFW_CODE_HEAD_CRC_ERR, //校验远端文件里的APP_CODE_HEAD失败
UPDATE_RESULT_UFW_ALGIN_OF_OFFSET_MATCH_ERR, //升级文件中找不到和本地对齐和偏移方式一致的文件
UPDATE_RESULT_UFW_CANNOT_FIND_VM_AREA, //升级文件中找不到vm区域信息
UPDATE_RESULT_LOADER_HEAD_CRC_ERR, //校验LOADER_HEAD失败检查ota.bin前面数据是否为00
UPDATE_RESULT_LOADER_WRITE_ERR, //写loader失败
UPDATE_RESULT_DUALBANK_GET_UFW_APP_HEAD_ERR, //双备份获取远端APP_head失败
UPDATE_RESULT_DUALBANK_GET_LOCAL_APP_HEAD_ERR, //双备份获取本地APP_head失败
UPDATE_RESULT_DUALBANK_APP_HEAD_NOT_MATCH, //双备份本地和远端APP分解线不匹配
};
#include "system/task.h"
typedef struct _update_type_info_t {
int type;
u8 task_en;
void (*cb)(void *priv, int type, u8 cmd);
void *cb_priv;
update_op_api_t *p_op_api;
void (*common_state_cbk)(int type, u32 status, u32 code);
OS_SEM update_sem;
} update_type_info_t;
typedef struct _update_mode_info_t {
s32 type;
void (*state_cbk)(int type, u32 status, void *priv);
const update_op_api_t *p_op_api;
u8 task_en;
} update_mode_info_t;
typedef struct _succ_report_t {
u32 loader_saddr;
u32 priv_param;
u32(*update_param_write_hdl)(u32 priv, u8 *buf, u16 len);
} succ_report_t;
#define UPDATE_DEV_NULL 0
#define UPDATE_BT_LMP_EN BIT(0)
#define UPDATE_STORAGE_DEV_EN BIT(1)
#define UPDATE_UART_EN BIT(2)
#define UPDATE_APP_EN BIT(3) //包括APP升级还有其他升级方式如串口升级非测试盒方式
#define UPDATE_BLE_TEST_EN BIT(4)
typedef struct _user_chip_update_t {
u8 *file_name;
int (*update_init)(void *priv, update_op_api_t *file_ops);
int (*update_get_len)(void);
int (*update_loop)(void *priv);
} user_chip_update_t;
typedef struct _user_chip_info_t {
union {
struct {
u32 file_addr;
};
struct {
u32 addr;
};
};
u32 len;
u16 crc;
u32 dev_addr;
} user_chip_update_info_t;
typedef struct _update_size_t {
u8 type;
} update_type_t;
enum UPDATE_SIZE_TYPE {
UPDATE_LEN_TYPE_CONTENT = 0,
UPDATE_LEN_TYPE_LOADER,
UPDATE_LEN_TYPE_EX_IC,
};
void register_user_chip_update_handle(const user_chip_update_t *user_update_ins);
void rcsp_update_loader_download_init(int update_type, void (*result_cbk)(void *priv, u8 type, u8 cmd));
int app_active_update_task_init(update_mode_info_t *info);
int update_file_verify(u32 ufw_addr, u16(*ufw_read)(void *buf, u32 addr, u32 len));
//==========================================================//
// 获取升级进度信息 //
//注意: 只有双备份升级可以获取该信息 //
//==========================================================//
typedef struct _update_percent_info {
u32 total_len; //固件总升级大小
u32 finish_len; //当前完成升级大小
u32 percent; //当前进度百分比
} update_percent_info;
//注册升级进度更新回调函数:
void register_update_percent_info_callback_handle(void (*handle)(update_percent_info *info));
//查询当前升级进度信息:
void update_percent_info_query(update_percent_info *info);
#endif /*_UPDATE_LOADER_DOWNLOAD_H_*/