• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  * Description: Provides efuse port template
15  *
16  * Create: 2023-03-04
17  */
18 #ifndef EFUSE_PORTING_H
19 #define EFUSE_PORTING_H
20 
21 #include <stdint.h>
22 
23 #ifdef __cplusplus
24 #if __cplusplus
25 extern "C" {
26 #endif /* __cplusplus */
27 #endif /* __cplusplus */
28 
29 /**
30  * @defgroup drivers_port_efuse Efuse
31  * @ingroup  drivers_port
32  * @{
33  */
34 
35 #define EFUSE_REGION_NUM               1
36 #define EFUSE_REGION_MAX_BITS          2048
37 #define EFUSE_REGION_MAX_BYTES         (EFUSE_REGION_MAX_BITS >> 3)  // MAX_BIT / 8
38 #define EFUSE_MAX_BITS                 (EFUSE_REGION_MAX_BITS * EFUSE_REGION_NUM)
39 #define EFUSE_MAX_BYTES                (EFUSE_MAX_BITS >> 3)  // MAX_BIT / 8
40 #define EFUSE_MAX_BIT_POS              8U
41 
42 #define EFUSE_PMU_CLKLDO_VSET_MASK       0x78
43 #define EFUSE_PMU_CLKLDO_OFFSET          3
44 #define EFUSE_TRIM_VERSION_DEFAULT_VALUE 1
45 #define EFUSE_CHAR_BIT_WIDE              8
46 #define EFUSE_CALC_CRC_MAX_LEN          32
47 #define EFUSE_DIE_ID_BASE_BYTE_ADDR      0
48 
49 #define EFUSE_TRIM_FLAG    50
50 #define EFUSE_IS_CHIP_TRIMED 0
51 // 7-0 -> Version of the trim
52 #define EFUSE_TRIM_VERSION 51
53 // 2-0 -> vset_bbldo[3:1]
54 // 6-3 -> vset_clkldo[3:0]
55 #define EFUSE_PMU_TRIM_VSET 25
56 
57 typedef enum {
58     HAL_EFUSE_REGION_0,
59     HAL_EFUSE_REGION_MAX,
60 } hal_efuse_region_t;
61 
62 #define EFUSE_IDX_NRW 0x0
63 #define EFUSE_IDX_RO  0x1
64 #define EFUSE_IDX_WO  0x2
65 #define EFUSE_IDX_RW  0x3
66 
67 #define EFUSE_FLASHBOOT_ROLLBACK_VERSION 656
68 #define EFUSE_APP_ROLLBACK_VERSION 624
69 #define MAC_ADDR_0_EFUSE_START_BIT 1584
70 #define MAC_ADDR_1_EFUSE_START_BIT 1632
71 #define MAC_ADDR_2_EFUSE_START_BIT 1680
72 #define MAC_ADDR_LAST_EFUSE_START_BIT 1728
73 #define EFUSE_MAC_NUM 4
74 #define EFUSE_SIZE_1_BYTS 1
75 #define HASH_ROOT_PUBLIC_KEY_LEN 32
76 #define EFUSE_SSI_MASK_START_BIT 193
77 #define EFUSE_FUNC_JTAG_MASK_START_BIT 194
78 #define EFUSE_DFT_JTAG_MASK_START_BIT 195
79 #define EFUSE_HASH_ROOT_PUBLIC_KEY_START_BIT 672
80 #define EFUSE_SEC_VERIFY_ENABLE_START_BIT 960
81 
82 #define CUSTOM_RESVED_EFUSE_BYTE_LEN 16
83 #define CUSTOM_RESVED_EFUSE_LEN_START_BYTE_ADDR 222
84 
85 #define CUSTOM_RESVED2_EFUSE_BYTE_LEN 16
86 #define CUSTOM_RESVED2_EFUSE_LEN_START_BYTE_ADDR 84
87 #define CUSTOM_RESVED3_EFUSE_LEN_START_BYTE_ADDR 100
88 
89 #define BURN_EFUSE_IDX_MAX           115
90 #define EFUSE_BIT_NUM 2048
91 #define EFUSE_READ_MAX_BYTE 32
92 #define BURN_EFUSE_BIN_ADDR 0xA30000
93 #define EFUSE_CFG_MAX_LEN       1320
94 #define EFUSE_CFG_MIN_LEN       48
95 #define CUSTOMER_RSVD_EFUSE_START_BIT  1776
96 #define CUSTOMER_RSVD_EFUSE_BIT_LEN    128
97 
98 typedef enum {
99     EFUSE_CHIP_ID = 0,
100     EFUSE_DIE_ID = 1,
101     EFUSE_MCU_VER_ID = 2,
102     EFUSE_FLASHBOOT_VER_ID = 3,
103     EFUSE_PARAMS_VER_ID = 4,
104     EFUSE_HASH_ROOT_PUBLIC_KEY_ID = 5,
105     EFUSE_MSID_ID = 6,
106     EFUSE_SEC_VERIFY_ENABLE = 7,
107     EFUSE_TYPE_ID = 8,
108     EFUSE_MAC_ADDR_01_ID = 9,
109     EFUSE_MAC_ADDR_02_ID = 10,
110     EFUSE_MAC_ADDR_03_ID = 11,
111     EFUSE_MAC_ADDR_LAST_ID = 12,
112     EFUSE_CUSTOM_RESVED_ID = 13,
113     EFUSE_CUSTOM_RESVED2_ID = 14,
114     EFUSE_GET_S_ID = 15,
115     EFUSE_GET_B_ID = 16,
116     EFUSE_GET_K_ID = 17,
117     EFUSE_IDX_MAX,
118 } efuse_idx;
119 
120 /**
121  * @if Eng
122  * @brief  Base address for the EFUSE boot done.
123  * @else
124  * @brief  EFUSE的上电完成地址
125  * @endif
126  */
127 extern uint32_t g_efuse_boot_done_addr;
128 
129 /**
130  * @if Eng
131  * @brief  Base address for the IP.
132  * @else
133  * @brief  IP的基地址
134  * @endif
135  */
136 extern uint32_t g_efuse_base_addr[1];
137 
138 /**
139  * @if Eng
140  * @brief  Base read address for the IP.
141  * @else
142  * @brief  IP的读基地址
143  * @endif
144  */
145 extern uint32_t g_efuse_region_read_address[1];
146 
147 /**
148  * @if Eng
149  * @brief  Base write address for the IP.
150  * @else
151  * @brief  IP的写基地址
152  * @endif
153  */
154 extern uint32_t g_efuse_region_write_address[1];
155 
156 /**
157  * @if Eng
158  * @brief  Register hal funcs objects into hal_efuse module.
159  * @else
160  * @brief  将hal funcs对象注册到hal_efuse模块中
161  * @endif
162  */
163 void efuse_port_register_hal_funcs(void);
164 
165 /**
166  * @if Eng
167  * @brief  Unregister hal funcs objects from hal_efuse module.
168  * @else
169  * @brief  从hal_efuse模块注销hal funcs对象
170  * @endif
171  */
172 void efuse_port_unregister_hal_funcs(void);
173 
174 /**
175  * @brief  Get the region of a otp byte address
176  * @param  byte_addr the addr of the byte to get register
177  * @retval region The region of otp
178  * @else
179  * @brief  获取otp字节地址的区域
180  * @param  byte_addr 要获取寄存器的字节的地址
181  * @retval 区域OTP的区域
182  */
183 hal_efuse_region_t hal_efuse_get_region(uint32_t byte_addr);
184 
185 /**
186  * @brief  Get the offset addr of a otp byte address
187  * @param  byte_addr the addr of the byte to get register
188  * @retval address
189  * @else
190  * @brief  获取otp字节地址的偏移地址
191  * @param  byte_addr 要获取寄存器的字节的地址
192  * @retval 偏移地址
193  */
194 uint16_t hal_efuse_get_byte_offset(uint32_t byte_addr);
195 
196 /**
197  * @brief  Get the value from efuse
198  * @param  efuse_idx the index of the byte to get in map
199  * @param  data the value of the byte to get
200  * @param  data_len the length of the byte to get
201  * @retval ERRCODE_SUCC   Success.
202  * @retval Other        Failure. For details, see @ref errcode_t
203  * @else
204  * @brief  从efuse中读取指定字节
205  * @param  efuse_idx 要获取字节在表中的序号
206  * @param  data 要获取的字节返回的值
207  * @param  data_len 要获取的字节的长度
208  * @retval ERRCODE_SUCC 成功
209  * @retval Other        失败,参考 @ref errcode_t
210  */
211 uint32_t efuse_read_item(efuse_idx efuse_id, uint8_t *data, uint16_t data_len);
212 
213 void set_efuse_period(void);
214 
215 uint32_t efuse_write_mac(uint8_t *data, uint16_t data_len);
216 uint32_t efuse_read_mac(uint8_t *data, uint16_t data_len, uint8_t *left_time);
217 uint32_t efuse_write_sle_mac(uint8_t *data, uint16_t data_len);
218 uint32_t efuse_read_sle_mac(uint8_t *data, uint16_t data_len);
219 uint32_t efuse_write_customer_rsvd_efuse(uint8_t *data, uint16_t data_len);
220 uint32_t efuse_write_customer_rsvd2_efuse(uint8_t *data, uint16_t data_len);
221 uint32_t efuse_read_customer_rsvd2_efuse(uint8_t *data, uint16_t data_len);
222 #ifdef _PRE_WLAN_FEATURE_MFG_TEST
223 uint32_t efuse_write_jtag_ssi(void);
224 uint32_t efuse_read_jtag_ssi(uint8_t *data, uint16_t data_len);
225 uint32_t efuse_write_hash_root_public_key(uint8_t *data, uint16_t data_len);
226 uint32_t efuse_read_hash_root_public_key(uint8_t *data, uint16_t data_len);
227 uint32_t efuse_write_sec_verify(void);
228 uint32_t efuse_read_sec_verify(uint8_t *data, uint16_t data_len);
229 #endif
230 #ifdef __cplusplus
231 #if __cplusplus
232 }
233 #endif /* __cplusplus */
234 #endif /* __cplusplus */
235 
236 #endif
237