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: struct definitions for UPG 15 */ 16 17 #ifndef UPG_DEFINITIONS_H 18 #define UPG_DEFINITIONS_H 19 20 #include <stdint.h> 21 #include "partition_resource_id.h" 22 #include "upg.h" 23 #ifdef __cplusplus 24 #if __cplusplus 25 extern "C" { 26 #endif 27 #endif 28 29 30 #define UPG_IMAGE_ID_NV 0xCB9E063C 31 #define UPG_IMAGE_ID_RES_INDEX 0xCB9E0826 32 #define UPG_IMAGE_ID_RES_DATA 0xCB9E0832 33 #define UPG_IMAGE_ID_KEY_AREA 0xCB8D154E 34 #define UPG_IMAGE_ID_FOTA_INFO_AREA 0xCB8D154E 35 #define UPG_IMAGE_HRADER_MAGIC 0x464F5451 36 37 #define UPG_FIRMWARE_MAX_NUM 20 38 #define UPG_FLAG_RETYR_TIMES 3 39 40 #define VERIFY_BUFF_LEN 0x1000 41 42 #define ENCRYPTION_FLAG_ENABLED 0x3C7896E1 /* 加密打开 */ 43 #define DECOMPRESS_FLAG_ZIP 0x3C7896E1 /* 压缩镜像 */ 44 #define DECOMPRESS_FLAG_DIFF 0x44494646 /* 差分镜像 */ 45 46 #define UPG_HEAD_MAGIC 0x55AA55AA 47 #define UPG_END_MAGIC 0xAA55AA55 48 49 typedef struct upg_image_partition_ids_map { 50 uint32_t image_id; 51 partition_ids_t item_id; 52 } upg_image_partition_ids_map_t; 53 54 typedef enum upg_image_status { 55 UPG_IMAGE_STATUS_NOT_STARTED, /* 镜像未开始处理 */ 56 UPG_IMAGE_STATUS_STARTED, /* 镜像已开始处理 */ 57 UPG_IMAGE_STATUS_RETRY, /* 镜像处理失败,需要重试 */ 58 UPG_IMAGE_STATUS_FINISHED, /* 镜像已处理完成(镜像更新成功或更新失败但重试已达到3次) */ 59 UPG_IMAGE_STATUS_INVALID, 60 } upg_image_status_t; 61 62 typedef enum upg_image_status_switch { 63 UPG_IMAGE_STATUS_SWITCH_TO_STARTED, /* 切换到开始处理状态(当前处理的flag置为0x0F) */ 64 UPG_IMAGE_STATUS_SWITCH_TO_RETRY, /* 切换到重试状态(当前处理的flag置为0x00) */ 65 UPG_IMAGE_STATUS_SWITCH_TO_FINISHED, /* 切换到处理完成状态(所有3个flag都置为0x00) */ 66 UPG_IMAGE_STATUS_SWITCH_INVALID, 67 } upg_image_status_switch_t; 68 69 typedef enum upg_resource_operation { 70 UPG_RESOURCE_ADD_FILE, 71 UPG_RESOURCE_AMEND_FILE, 72 UPG_RESOURCE_DELETE_FILE, 73 UPG_RESOURCE_REMOVE_DIR 74 } upg_resource_operation_t; 75 76 typedef struct fota_upgrade_flag_area { 77 uint32_t head_magic; 78 uint32_t head_before_offset; 79 uint32_t package_length; 80 uint32_t firmware_num; 81 uint8_t firmware_flag[UPG_FIRMWARE_MAX_NUM][UPG_FLAG_RETYR_TIMES]; 82 uint8_t nv_flag[UPG_FLAG_RETYR_TIMES]; 83 uint8_t ver_change_flag; /* 版本是否变化标记,0x0:无变化 0xFF:有变化 */ 84 uint32_t update_result; 85 uint32_t nv_data_offset; 86 uint32_t nv_data_len; 87 uint32_t nv_hash_offset; 88 uint32_t nv_hash_len; 89 uint32_t complete_flag; 90 uint32_t head_end_magic; 91 } fota_upgrade_flag_area_t; 92 93 typedef struct upg_package_info { 94 uint32_t total_new_fw_size; 95 uint32_t finished_fw_size; 96 } upg_package_info_t; 97 98 typedef struct upg_image_collections { 99 uint32_t *img_ids; 100 uint32_t img_ids_cnt; 101 } upg_image_collections_t; 102 103 typedef struct upg_resource_index { 104 char file_path[128]; 105 uint32_t offset; 106 uint32_t file_len; 107 uint32_t operation_type; 108 } upg_resource_node_t; 109 110 typedef struct upg_resource_head { 111 uint32_t file_num; 112 upg_resource_node_t file_node[0]; 113 } upg_resource_index_t; 114 115 typedef struct upg_storage_ctx { 116 bool inited; 117 uint8_t rsv[3]; /* reserved 3 Bytes */ 118 upg_status_t upg_status; 119 upg_result_t temporary_result; 120 upg_func_t func_list; 121 uint32_t packge_len; 122 #if (UPG_CFG_PROCESS_NOTIFY_SUPPORT == YES) 123 uapi_upg_progress_cb progress_cb; 124 #endif 125 upg_package_info_t package_info; 126 } upg_storage_ctx_t; 127 128 #ifdef __cplusplus 129 #if __cplusplus 130 } 131 #endif 132 #endif 133 #endif /* UPG_DEFINITIONS_H */ 134