1 /* 2 * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 2 7 * of the License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 */ 18 #ifndef __PLAT_FIRMWARE_H__ 19 #define __PLAT_FIRMWARE_H__ 20 21 /* **************************************************************************** 22 1 头文件包含 23 **************************************************************************** */ 24 #if (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION) 25 #include "stdlib.h" 26 #include "hi_types.h" 27 #include "oal_net.h" 28 #include "exception_rst.h" 29 #elif (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION) 30 #include "oal_net.h" 31 #include "exception_rst.h" 32 #endif 33 34 #ifdef __cplusplus 35 #if __cplusplus 36 extern "C" { 37 #endif 38 #endif 39 40 /* **************************************************************************** 41 2 宏定义 42 **************************************************************************** */ 43 #define READ_MEG_TIMEOUT 200 /* 200ms */ 44 #define READ_MEG_JUMP_TIMEOUT 100000 /* 100s */ 45 46 #define FILE_CMD_WAIT_TIME_MIN 5000 /* 5000us */ 47 #define FILE_CMD_WAIT_TIME_MAX 5100 /* 5100us */ 48 49 #define VERSION_LEN 64 50 #define READ_CFG_BUF_LEN 2048 51 52 #define DOWNLOAD_CMD_LEN 32 53 #define DOWNLOAD_CMD_PARA_LEN 150 54 55 #define CMD_SUB_PARA_CNT_MAX 15 /* 命令参数里子参数最大数目 */ 56 57 #define HOST_DEV_TIMEOUT 3 58 #define INT32_STR_LEN 32 59 60 #define SHUTDOWN_TX_CMD_LEN 64 61 62 #define CMD_JUMP_EXEC_RESULT_SUCC 0 63 #define CMD_JUMP_EXEC_RESULT_FAIL 1 64 65 #define MFG_FIRMWARE_BIN 1 66 #define FIRMWARE_BIN 0 67 68 /* 以下是发往device命令的关键字 */ 69 #define VER_CMD_KEYWORD "VERSION" 70 #define JUMP_CMD_KEYWORD "JUMP" 71 #define CONFIG_CMD_KEYWORD "CONFIG" 72 #define FILES_CMD_KEYWORD "FILES" 73 #define RMEM_CMD_KEYWORD "READM" 74 #define WMEM_CMD_KEYWORD "WRITEM" 75 #define QUIT_CMD_KEYWORD "QUIT" 76 77 /* 以下是device对命令执行成功返回的关键字,host收到一下关键字则命令执行成功 */ 78 #define MSG_FROM_DEV_WRITEM_OK "WRITEM OK" 79 #define MSG_FROM_DEV_READM_OK "" 80 #define MSG_FROM_DEV_FILES_OK "FILES OK" 81 #define MSG_FROM_DEV_READY_OK "READY" 82 #define MSG_FROM_DEV_JUMP_OK "JUMP OK" 83 #define MSG_FROM_DEV_CONFIG_OK "CONFIG OK" 84 #define MSG_FROM_DEV_SET_OK "SET OK" 85 #define MSG_FROM_DEV_QUIT_OK "" 86 87 /* 以下是cfg文件配置命令的参数头,一条合法的cfg命令格式为:参数头+命令关键字(QUIT命令除外) */ 88 #define FILE_TYPE_CMD_KEY "ADDR_FILE_" 89 #define NUM_TYPE_CMD_KEY "PARA_" 90 #define CFG_TYPE_CMD_KEY "CFG_" 91 92 #define WIFI_CFG_MAC "MAC" 93 #define WIFI_CFG_COUNTRY_CODE "COUNTRY_CODE" 94 #define WIFI_CFG_DBB_PARAMS "DBB_PARAMS" 95 #define WIFI_CFG_CH_TXPWR "CH_TXPWR_OFFSET" 96 #define WIFI_CFG_FREQ_COMP "FREQ_COMP" 97 #define WIFI_CFG_RSSI_OFFSET "RSSI_OFFSET" 98 99 #define COMPART_KEYWORD ' ' 100 #define CMD_LINE_SIGN ';' 101 #define CFG_INFO_RESERVE_LEN 2 102 103 #if (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION) 104 #define OS_MEM_KFREE(p) free(p) 105 #define OS_KMALLOC_GFP(size) memalign(32, SKB_DATA_ALIGN(size)) 106 #define OS_VMALLOC_GFP(size) malloc(size) 107 #define OS_MEM_VFREE(p) free(p) 108 #elif (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION) 109 #define OS_KMALLOC_GFP(size) oal_memalloc(size) 110 #endif 111 #define hiusb_align_32(len) (ALIGN((len), 32)) 112 113 /* **************************************************************************** 114 3 枚举定义 115 **************************************************************************** */ 116 enum FIRMWARE_CFG_CMD_ENUM { 117 ERROR_TYPE_CMD = 0, /* 错误的命令 */ 118 FILE_TYPE_CMD, /* 下载文件的命令 */ 119 NUM_TYPE_CMD, /* 下载配置参数的命令 */ 120 CFG_TYPE_CMD, /* 产测配置命令 */ 121 QUIT_TYPE_CMD, /* 退出命令 */ 122 SHUTDOWN_WIFI_TYPE_CMD, /* SHUTDOWN WCPU命令 */ 123 }; 124 125 enum FIRMWARE_CFG_FILE_ENUM { 126 WIFI_CFG = 0, 127 RAM_REG_TEST_CFG, 128 CFG_FILE_TOTAL 129 }; 130 131 enum DEV_SOFT_VER_TYPE { 132 SOFT_VER_CO1 = 0, 133 SOFT_VER_CO2, 134 SOFT_VER_BUTT 135 }; 136 137 /* **************************************************************************** 138 3 STRUCT DEFINE 139 **************************************************************************** */ 140 /* **************************************************************************** 141 4 全局变量定义 142 **************************************************************************** */ 143 /* **************************************************************************** 144 5 消息头定义 145 **************************************************************************** */ 146 /* **************************************************************************** 147 6 消息定义 148 **************************************************************************** */ 149 /* **************************************************************************** 150 7 STRUCT定义 151 **************************************************************************** */ 152 typedef struct cmd_type_st { 153 hi_s32 cmd_type; 154 hi_u8 cmd_name[DOWNLOAD_CMD_LEN]; 155 hi_u8 cmd_para[DOWNLOAD_CMD_PARA_LEN]; 156 } cmd_type_struct; 157 158 typedef struct cfg_cmd_st { 159 hi_u8 cmd_name[DOWNLOAD_CMD_LEN]; 160 hi_u8 cmd_para[DOWNLOAD_CMD_PARA_LEN]; 161 hi_u16 val_len; 162 hi_u32 val_offset; 163 } cfg_cmd_struct; 164 165 typedef struct firmware_globals_st { 166 hi_s32 al_count[CFG_FILE_TOTAL]; /* 存储每个cfg文件解析后有效的命令个数 */ 167 cmd_type_struct *apst_cmd[CFG_FILE_TOTAL]; /* 存储每个cfg文件的有效命令 */ 168 hi_u8 auc_CfgVersion[VERSION_LEN]; /* 存储cfg文件中配置的版本号信息 */ 169 hi_u8 auc_DevVersion[VERSION_LEN]; /* 存储加载时device侧上报的版本号信息 */ 170 } firmware_globals_struct; 171 172 typedef struct _firmware_mem { 173 /* 保存firmware file内容的buffer,先将文件读到这个buffer中,然后从这个向device buffer发送 */ 174 hi_u8 *puc_data_buf; 175 /* pucDataBuf的长度 */ 176 hi_u32 ul_data_buf_len; 177 178 #define CMD_BUFF_LEN 256 179 hi_u8 *puc_recv_cmd_buff; 180 hi_u8 *puc_send_cmd_buff; 181 } firmware_mem_stru; 182 183 typedef struct _efuse_info_st_ { 184 hi_u32 chip_id : 8; 185 hi_u32 chip_ver : 2; 186 hi_u32 soft_ver : 2; 187 hi_u32 host_ver : 2; 188 hi_u32 resv_b2 : 2; 189 hi_u32 chip_ver_butt : 16; 190 191 hi_u32 mac_h : 16; 192 hi_u32 mac_h_butt : 16; 193 194 hi_u32 mac_m : 16; 195 hi_u32 mac_m_butt : 16; 196 197 hi_u32 mac_l : 16; 198 hi_u32 mac_l_butt : 16; 199 } efuse_info_stru; 200 201 typedef struct _firmware_file_st_ { 202 hi_u8 *addr; 203 hi_u32 len; 204 } firmware_file_stru; 205 206 #define DECLARE_FIRMWARE_FILE(filename) static firmware_file_stru firmware_file_##filename = { \ 207 .addr = (hi_u8 *)firmware_array_##filename, \ 208 .len = sizeof(firmware_array_##filename), \ 209 } 210 211 /* **************************************************************************** 212 8 UNION定义 213 **************************************************************************** */ 214 /* **************************************************************************** 215 9 OTHERS定义 216 **************************************************************************** */ 217 /* **************************************************************************** 218 10 函数声明 219 **************************************************************************** */ 220 hi_s32 firmware_download(hi_u32 ul_index); 221 hi_s32 device_mem_dump(wifi_dump_mem_info_stru *mem_dump_info); 222 hi_u32 plat_firmware_init(void); 223 hi_s32 plat_firmware_clear(void); 224 hi_s32 firmware_read_efuse_info(hi_void); 225 efuse_info_stru *get_efuse_info_handler(hi_void); 226 hi_u32 get_device_soft_version(hi_void); 227 hi_s32 firmware_write_cfg(hi_u8 *key, hi_u8 *new_val, hi_u8 len); 228 hi_bool cfg_get_mac(hi_u8 *mac_addr, hi_u8 size); 229 hi_u32 firmware_sync_cfg_paras_to_wal_customize(hi_void); 230 hi_bool parse_mac_addr(const hi_u8 *str, hi_u8 str_len, hi_u8 *mac, hi_u8 size); 231 232 #ifdef __cplusplus 233 #if __cplusplus 234 } 235 #endif 236 #endif 237 238 #endif /* end of plat_firmware.h */ 239