• 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: Function headers of different chips in the UPG module.
15  */
16 
17 #ifndef UPG_ADAPTION_H
18 #define UPG_ADAPTION_H
19 
20 #include <stdio.h>
21 #include <stdint.h>
22 #include <stdbool.h>
23 #include "partition.h"
24 #include "upg_definitions.h"
25 #include "upg.h"
26 #include "upg_common_porting.h"
27 #include "errcode.h"
28 
29 #ifdef __cplusplus
30 #if __cplusplus
31 extern "C" {
32 #endif
33 #endif
34 
35 /* Adaption function for UPG common */
36 /* 获取镜像ID和分区ID的map表
37  * map: 镜像ID和分区ID的映射表
38  * 返回map表中映射数量
39  */
40 uint32_t upg_get_ids_map(upg_image_partition_ids_map_t **map);
41 /* 获取当前程序支持的升级镜像 */
42 upg_image_collections_t *uapi_upg_get_image_id_collection(void);
43 /* 获取升级包路径 */
44 char *upg_get_pkg_file_path(void);
45 /* 获取资源索引路径 */
46 char *upg_get_res_file_index_path(void);
47 /* 获取升级包所在目录 */
48 char *upg_get_pkg_file_dir(void);
49 
50 /*
51  * 获取FOTA升级标记区的Flash起始地址,该地址为在flash上的相对地址,是相对flash基地址的偏移
52  * start_address 返回升级标记区的起始地址
53  */
54 errcode_t upg_get_upgrade_flag_flash_start_addr(uint32_t *start_address);
55 
56 /*
57  * 获取FOTA升级进度恢复标记区的Flash起始地址,该地址为在flash上的相对地址,是相对flash基地址的偏移
58  * start_address 返回标记区的起始地址
59  */
60 errcode_t upg_get_progress_status_start_addr(uint32_t *start_address, uint32_t *size);
61 
62  /*
63  * 如果升级包保存在flash上,FOTA分区为如下结构:
64  * ---------------------
65  *    升级包存储区
66  * --------------------
67  *    缓存区(4K)(可选)
68  * --------------------
69  *    写入状态区(4K)(可选)
70  * --------------------
71  *    升级标记区(4K)
72  * --------------------
73  *
74  * 如果升级包保存在EMMC上,FOTA分区为如下结构:
75  * --------------------
76  *    缓存区(4K)
77  * --------------------
78  *    写入状态区(4K)
79  * --------------------
80  *    升级标记区(4K)
81  * --------------------
82  */
83 /*
84  * 获取在Flash上预留的FOTA分区的地址和长度,该地址为在flash上的相对地址,是相对flash基地址的偏移
85  * start_address 返回FOTA分区的起始地址
86  * size          返回FOTA分区大小(包含升级标记区和缓存区、状态区)
87  */
88 errcode_t upg_get_fota_partiton_area_addr(uint32_t *start_address, uint32_t *size);
89 
90 /*
91  * 获取校验用的root_public_key
92  */
93 uint8_t *upg_get_root_public_key(void);
94 
95 /*
96  * 获取Flash基地址
97  */
98 uint32_t upg_get_flash_base_addr(void);
99 
100 /*
101  * 获取Flash大小
102  */
103 uint32_t upg_get_flash_size(void);
104 
105 /*
106  * 重启
107  */
108 void upg_reboot(void);
109 
110 /*
111  * 防止看门狗超时,踢狗
112  */
113 void upg_watchdog_kick(void);
114 
115 /*
116  * 检查FOTA升级包中的信息与板端是否匹配,检查数据包括msid_ext, hardware_id, user_defined等,根据需要选择检查内容
117  * pkg_header 升级包包头指针
118  * 检查成功,返回 ERRCODE_SUCC
119  */
120 errcode_t upg_check_fota_information(const upg_package_header_t *pkg_header);
121 
122 /*
123  * 获取otp/efuse中的回滚版本号
124  * image_id 镜像的ID
125  * anti_rollback_ver 防回滚版本号地址
126  */
127 errcode_t upg_get_board_rollback_version(uint32_t image_id, uint32_t *anti_rollback_ver);
128 
129 /*
130  * 设置otp/efuse中的回滚版本号
131  * image_id 镜像的ID
132  * anti_rollback_ver 防回滚版本号地址
133  */
134 errcode_t upg_set_board_rollback_version(uint32_t image_id, uint32_t *anti_rollback_ver);
135 
136 /*
137  * 获取板端防回滚版本号Mask值
138  * key_mask KEY区防回滚版本号Mask
139  * code_mask Code区防回滚版本号Mask
140  */
141 errcode_t upg_get_board_version_mask(uint32_t image_id, uint32_t *key_mask, uint32_t *code_mask);
142 
143 /*
144  * 获取板端镜像的版本号
145  * key_ver KEY区版本号
146  * code_ver Code区版本号
147  */
148 errcode_t upg_get_board_version(uint32_t image_id, uint32_t *key_ver, uint32_t *code_ver);
149 
150 /*
151  * flash读数据接口
152  * flash_offset 待读取数据的flash偏移地址
153  * size 期望读取的数据长度
154  * ram_data 出参,数据存放的内存地址
155  */
156 errcode_t upg_flash_read(const uint32_t flash_offset, const uint32_t size, uint8_t *ram_data);
157 
158 /*
159  * flash写数据接口
160  * flash_offset 待写入数据的flash偏移地址
161  * size 期望写入的数据长度
162  * ram_data 入参,待写入数据存放的内存地址
163  * do_erase 写前擦除标记,true:写前执行擦除;false:直接写入
164  */
165 errcode_t upg_flash_write(const uint32_t flash_offset, uint32_t size, const uint8_t *ram_data, bool do_erase);
166 
167 /*
168  * flash擦除数据接口
169  * flash_offset 待擦除数据的flash偏移地址
170  * size 期望擦除的数据长度
171  */
172 errcode_t upg_flash_erase(const uint32_t flash_offset, const uint32_t size);
173 
174 #ifdef __cplusplus
175 #if __cplusplus
176 }
177 #endif
178 #endif
179 
180 #endif /* UPG_ADAPTION_H */
181