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: UPG common functions header file 15 */ 16 17 #ifndef UPG_COMMON_PORTING_H 18 #define UPG_COMMON_PORTING_H 19 20 #include "memory_config.h" 21 #include "errcode.h" 22 #include "upg.h" 23 #include "upg_definitions_porting.h" 24 25 #ifdef __cplusplus 26 #if __cplusplus 27 extern "C" { 28 #endif 29 #endif 30 31 #define BOOT_PORTING_RESET_REG 0x40002110 32 #define BOOT_PORTING_RESET_VALUE 0x4 33 34 #ifndef SIZE_MAX 35 #define SIZE_MAX UINT32_MAX 36 #endif 37 38 #if MEMORY_MINI 39 #define UPG_FILE_PATH "/user/" 40 #define UPG_FILE_NAME "/user/update.fwpkg" 41 #define UPG_RES_INDEX_PATH "/user/res_index.bin" 42 #else 43 #define UPG_FILE_PATH "/update/" 44 #define UPG_FILE_NAME "/update/update.fwpkg" 45 #define UPG_RES_INDEX_PATH "/update/res_index.bin" 46 #endif 47 48 #define UPG_FLASH_SIZE (FLASH_MAX_END - FLASH_START) 49 #define FLASH_PAGE_SIZE 4096 50 #define UPG_FLASH_PAGE_SIZE FLASH_PAGE_SIZE /* Bytes per sector */ 51 #define FOTA_DATA_STATUS_AREA_LEN UPG_FLASH_PAGE_SIZE 52 #define FOTA_DATA_BUFFER_AREA_LEN UPG_FLASH_PAGE_SIZE 53 #define FOTA_DATA_FLAG_AREA_LEN UPG_FLASH_PAGE_SIZE 54 #define UPG_UPGRADE_FLAG_LENGTH (FOTA_DATA_STATUS_AREA_LEN + FOTA_DATA_BUFFER_AREA_LEN + FOTA_DATA_FLAG_AREA_LEN) 55 56 #define UPG_META_DATA_LENGTH 0x0 57 58 /* APP Region */ 59 #define APP_FLASH_REGION_START (0x104000) 60 #define APP_FLASH_REGION_LENGTH (0x203000) 61 62 #define PARAMS_PARTITION_IMAGE_ID 0x4B87A52D 63 #define PARAMS_PARTITION_START_ADDR 0x200000 64 #define PARAMS_PARTITION_LENGTH 0x780 65 66 #define EFUSE_REE_SSB_VERSION 0xF0 67 #define EFUSE_REE_RECOVERT_VERSION 0xF0 68 #define EFUSE_REE_APP_VERSION 0xF0 69 #define EFUSE_REE_BT_VERSION 0xF0 70 #define EFUSE_REE_DSP_MAIN_VERSION 0xF0 71 #define EFUSE_REE_DSP_OVERLAY_VERSION 0xF0 72 73 #define ROOT_PUBLIC_KEY_RSV 32 74 /* root public key area, size is 0x80 */ 75 typedef struct { 76 uint32_t image_id; 77 uint32_t structure_version; /* currently version is 0x00010000 */ 78 uint32_t structure_length; 79 uint32_t key_owner_id; 80 uint32_t key_id; 81 uint32_t key_alg; /* 0x2A13C812: ECC256; 0x2A13C823: SM2 */ 82 uint32_t ecc_curve_type; /* 0x2A13C812: RFC 5639, BrainpoolP256r1 */ 83 uint32_t key_length; 84 uint8_t reserved[ROOT_PUBLIC_KEY_RSV]; /* 32 bytes above */ 85 uint8_t root_key_area[PUBLIC_KEY_LEN]; 86 } root_public_key; 87 88 /** 89 * @ingroup iot_update 90 * @brief Upgrade the backup area of each image before start the upgrade. 91 * CNcomment:升级开始前对各个镜像的备区升级。CNend 92 * 93 * @retval #ERRCODE_SUCC Success. 94 * @retval #Other Failure. For details, see soc_errno.h. 95 */ 96 errcode_t upg_image_backups_update(void); 97 98 void upg_progress_callback_register(void); 99 100 errcode_t ws63_upg_init(void); 101 /* 102 * 擦除镜像对应的整个flash分区 103 * img_header 镜像信息header,用于获取对应flash分区信息 104 */ 105 errcode_t upg_erase_whole_image(const upg_image_header_t *img_header); 106 107 #ifdef __cplusplus 108 #if __cplusplus 109 } 110 #endif 111 #endif 112 113 #endif /* UPG_COMMON_PORTING_H */ 114