Files
luban-lite-t3e-pro/application/baremetal/bootloader/include/aicupg.h

148 lines
4.1 KiB
C
Raw Normal View History

2023-08-30 16:21:18 +08:00
/*
2024-09-03 11:16:08 +08:00
* Copyright (c) 2023-2024, ArtInChip Technology Co., Ltd
2023-08-30 16:21:18 +08:00
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef __AICUPG_H__
#define __AICUPG_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <aic_core.h>
#define UPG_PROTO_CMD_GET_HWINFO 0x00
#define UPG_PROTO_CMD_GET_TRACEINFO 0x01
#define UPG_PROTO_CMD_WRITE 0x02
#define UPG_PROTO_CMD_READ 0x03
#define UPG_PROTO_CMD_EXEC 0x04
#define UPG_PROTO_CMD_RUN_SHELL_STR 0x05
#define UPG_PROTO_CMD_GET_MEM_BUF 0x08
#define UPG_PROTO_CMD_FREE_MEM_BUF 0x09
#define UPG_PROTO_CMD_SET_UPG_CFG 0x0A
#define UPG_PROTO_CMD_SET_UPG_END 0x0B
2024-06-04 19:00:30 +08:00
#define UPG_PROTO_CMD_GET_LOG_SIZE 0x0C
#define UPG_PROTO_CMD_GET_LOG_DATA 0x0D
2023-08-30 16:21:18 +08:00
#define UPG_PROTO_CMD_SET_FWC_META 0x10
#define UPG_PROTO_CMD_GET_BLOCK_SIZE 0x11
#define UPG_PROTO_CMD_SEND_FWC_DATA 0x12
#define UPG_PROTO_CMD_GET_FWC_CRC 0x13
#define UPG_PROTO_CMD_GET_FWC_BURN_RESULT 0x14
#define UPG_PROTO_CMD_GET_FWC_RUN_RESULT 0x15
#define UPG_PROTO_CMD_GET_STORAGE_MEDIA 0x16
#define UPG_PROTO_CMD_GET_PARTITION_TABLE 0x17
#define UPG_PROTO_CMD_READ_FWC_DATA 0x18
2023-11-09 20:19:51 +08:00
#define UPG_PROTO_CMD_SET_UART_ARGS 0x19
2023-08-30 16:21:18 +08:00
#define UPG_PROTO_CMD_INVALID 0xFF
#define UPG_PROTO_TYPE 0x01
#define UPG_PROTO_VERSION 0x01
/* "UPGC" */
#define UPG_CMD_HEADER_MAGIC (0x43475055)
/* "UPGR" */
#define UPG_CMD_RESP_MAGIC (0x52475055)
2024-06-04 19:00:30 +08:00
#define DATA_WRITE_ONCE_MAX_SIZE (1024 * 1024)
#define DATA_WRITE_ONCE_MID_SIZE (64 * 1024)
#define DATA_WRITE_ONCE_MIN_SIZE (20 * 1024)
2023-08-30 16:21:18 +08:00
struct cmd_header {
u32 magic; /* "UPGC" */
u8 protocol;
u8 version;
u8 command;
u8 reserved;
u32 data_length; /* Command r/w data length */
u32 checksum; /* Checksum for this header */
};
struct resp_header {
u32 magic; /* "UPGR" */
u8 protocol;
u8 version;
u8 command; /* Response for specific commmand */
u8 status;
u32 data_length; /* Response data length */
u32 checksum; /* Checksum for this header */
};
struct image_header_upgrade {
char magic[8];
char platform[64];
char product[64];
char version[64];
char media_type[64];
u32 media_dev_id;
char media_id[64];
u32 meta_offset;
u32 meta_size;
u32 file_offset;
u32 file_size;
};
struct image_header_pack {
struct image_header_upgrade hdr;
char pad[2048 - sizeof(struct image_header_upgrade)];
};
2023-11-30 19:48:02 +08:00
enum upg_mode {
UPG_MODE_FULL_DISK_UPGRADE = 0x00,
UPG_MODE_PARTITION_UPGRADE,
UPG_MODE_BURN_USER_ID,
UPG_MODE_DUMP_PARTITION,
UPG_MODE_BURN_IMG_FORCE,
2024-09-03 11:16:08 +08:00
/*
* UPG_MODE_BURN_FROZEN:
* Set by Host Tool for case:
* Host Tool already burn image/userid successfuly, and don't want burn
* the same image again before next reboot, Host Tool will set this
* flag to upg_cfg.mode.
*
* Host Tool will check this flag from device, if the flag in device is
* UPG_MODE_BURN_FROZEN, it will skip the device.
*/
2023-11-30 19:48:02 +08:00
UPG_MODE_BURN_FROZEN,
UPG_MODE_INVALID,
};
2023-08-30 16:21:18 +08:00
struct upg_cfg {
2024-09-03 11:16:08 +08:00
u8 mode; /* The value is "enum upg_mode" */
2023-08-30 16:21:18 +08:00
u8 reserved[31];
};
2023-11-30 19:48:02 +08:00
#define INIT_MODE(mode) (1 << (mode))
struct upg_init {
2024-09-03 11:16:08 +08:00
/* Store the "enum upg_mode" value by bit index */
u8 mode_bits;
2023-11-30 19:48:02 +08:00
};
s32 aicupg_initialize(struct upg_init *param);
2023-08-30 16:21:18 +08:00
s32 aicupg_set_upg_cfg(struct upg_cfg *cfg);
s32 aicupg_get_upg_mode(void);
s32 aicupg_data_packet_write(u8 *data, s32 len);
s32 aicupg_data_packet_read(u8 *data, s32 len);
2024-09-03 11:16:08 +08:00
void aicupg_show_upg_cfg_mode(int mode);
void aicupg_show_init_cfg_mode(int mode_bits);
2023-08-30 16:21:18 +08:00
/*fat upgrade function*/
s32 aicupg_fat_write(char *image_name, char *protection,
2024-09-03 11:16:08 +08:00
struct image_header_upgrade *header);
2023-08-30 16:21:18 +08:00
2024-04-03 16:40:57 +08:00
int aicupg_fat_direct_write(char *dst_type, u32 intf_id, char *fpath,
u32 dst_offset, u32 boot_flag, char *attr);
2024-09-03 11:16:08 +08:00
typedef void (*progress_cb)(u32 percent);
void aicupg_fat_set_process_cb(progress_cb cb);
2024-10-30 16:50:31 +08:00
void *aicupg_malloc_align(u32 size, size_t align);
void aicupg_free_align(void *ptr);
2023-08-30 16:21:18 +08:00
#ifdef __cplusplus
}
#endif
#endif /* __AICUPG_H__ */