lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /** |
| 2 | * @file upi_public.h |
| 3 | * @brief ¹«¹²½Ó¿Ú¼°ÐÅÏ¢ |
| 4 | * |
| 5 | * Copyright (C) 2017 Sanechips Technology Co., Ltd. |
| 6 | * @author |
| 7 | * |
| 8 | */ |
| 9 | |
| 10 | #ifndef _UPI_PUBLIC_H |
| 11 | #define _UPI_PUBLIC_H |
| 12 | |
| 13 | /******************************************************************************* |
| 14 | * Include header files * |
| 15 | ******************************************************************************/ |
| 16 | #include <stdio.h> |
| 17 | #include <stdlib.h> |
| 18 | #include <unistd.h> |
| 19 | #include <string.h> |
| 20 | #include <errno.h> |
| 21 | #include <sys/types.h> |
| 22 | #include <sys/stat.h> |
| 23 | |
| 24 | |
| 25 | |
| 26 | /******************************************************************************* |
| 27 | * Macro definitions * |
| 28 | ******************************************************************************/ |
| 29 | //ÄÚ´æ¼ì²â¿ª¹Ø |
| 30 | //#define FOTA_MEM_DEBUG |
| 31 | |
| 32 | |
| 33 | #ifndef FOTA_MEM_DEBUG |
| 34 | #define upi_free(ptr) if(NULL != ptr) {free(ptr); ptr = NULL;} |
| 35 | #define upi_malloc(size) malloc(size) |
| 36 | #define upi_strdup(str) strdup(str) |
| 37 | #define upi_realloc(ptr, size) realloc(ptr, size) |
| 38 | #else |
| 39 | void* realloc_debug(void *ptr, size_t size, const char*func, long line); |
| 40 | |
| 41 | void* malloc_debug(size_t bytes, const char* func, long line); |
| 42 | void* free_debug(void*p, const char* func, long line); |
| 43 | char* strdup_debug(const char* str, const char* func, long line); |
| 44 | |
| 45 | #define upi_free(ptr) if(NULL != ptr){free_debug(ptr, __FUNCTION__, __LINE__); ptr=NULL;} |
| 46 | #define upi_malloc(size) malloc_debug(size, __FUNCTION__, __LINE__) |
| 47 | #define upi_strdup(str) strdup_debug(str, __FUNCTION__, __LINE__) |
| 48 | #define upi_realloc(ptr, size) realloc_debug(ptr, size, __FUNCTION__, __LINE__) |
| 49 | |
| 50 | |
| 51 | #endif |
| 52 | |
| 53 | #define MAX_PATH_LEN (256) |
| 54 | #define SHA512_LEN (64) |
| 55 | #define HASH_MAX_LEN (64) |
| 56 | |
| 57 | #define PARTITION_NAME_LEN (32) |
| 58 | #define EXTRA_NAME_LEN (32) |
| 59 | |
| 60 | |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame] | 61 | |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 62 | #define FOTA_AB_UPGRADE_STATUS "fota_ab_upgrade_status" |
| 63 | |
| 64 | #define FOTA_AB_UPGRADE_TOTAL_SIZE "fota_ab_upgrade_total_size" |
| 65 | |
| 66 | #define FOTA_AB_UPGRADE_UPDATED_SZIE "fota_ab_upgrade_updated_size" |
| 67 | |
| 68 | #define FOTA_AB_AA_SYNC_STATUS "fota_ab_aa_sync_status" |
| 69 | |
| 70 | |
| 71 | #define PARTITION_NAME_FOTA_FLAG "flags" |
| 72 | #define PARTITION_NAME_ROOTFS_1 "rootfs" |
| 73 | #define PARTITION_NAME_ROOTFS_2 "rootfs2" |
| 74 | #define SYSTEM_INDEX_1 (1) |
| 75 | #define SYSTEM_INDEX_2 (2) |
| 76 | #define SYSTEM_INDEX_UNKNOWN (-1) |
| 77 | |
| 78 | |
| 79 | |
| 80 | #define FILE_PATH_PROC_MTD "/proc/mtd" |
| 81 | #define FILE_PATH_PROC_CMDLINE "/proc/cmdline" |
| 82 | |
| 83 | |
| 84 | #define SYSTEM_UPGRADE_PARTITION_INFO_HEAD_MAGIC ("SUPI") |
| 85 | #define SYSTEM_UPGRADE_PARTITION_INFO_HEAD_MAGIC_LEN (4) |
| 86 | |
| 87 | #define SYSTEM_PARTITION_FILE ("/etc_ro/systemPartitionInfo.conf") |
| 88 | |
| 89 | #define PLATFORM_PARTITION_NUM_MAX (7) |
| 90 | #define OEM_PARTITION_NUM_MAX (7) |
| 91 | |
| 92 | /******************************************************************************* |
| 93 | * Type definitions * |
| 94 | ******************************************************************************/ |
| 95 | |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame] | 96 | typedef enum |
| 97 | { |
| 98 | HASH_TYPE_SHA_512 = 0, |
| 99 | HASH_TYPE_SHA_256 |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 100 | } Hash_type_s; |
| 101 | |
| 102 | |
| 103 | /** |
| 104 | * @brief ϵͳ·ÖÇøÐÅϢͷ |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame] | 105 | * @param magic ħÊõ×Ö |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 106 | * @param plat ƽ̨: 0 - V3T, 1 - 8501 |
| 107 | * @param plat_partition_num ƽ̨·ÖÇøÊý |
| 108 | * @param oem_partition_num oem·ÖÇøÊý |
| 109 | */ |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame] | 110 | typedef struct |
| 111 | { |
| 112 | char magic[SYSTEM_UPGRADE_PARTITION_INFO_HEAD_MAGIC_LEN]; |
| 113 | int plat; |
| 114 | int plat_partition_num; |
| 115 | int oem_partition_num; |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 116 | } system_partition_info_head_t; |
| 117 | |
| 118 | |
| 119 | /** |
| 120 | * @brief ƽ̨ϵͳ·ÖÇøÐÅÏ¢ |
| 121 | * @param name ·ÖÇøÃû |
| 122 | * @param system_type ËùÊôϵͳÀàÐÍ - 0 ƽ̨ÀàÐÍ, 1 oem |
| 123 | * @param partition_type ·ÖÇøÀàÐÍ |
| 124 | */ |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame] | 125 | typedef struct |
| 126 | { |
| 127 | char name[PARTITION_NAME_LEN]; |
| 128 | int system_type; |
| 129 | int partition_type; |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 130 | } platform_partition_info_t; |
| 131 | |
| 132 | |
| 133 | /** |
| 134 | * @brief oem·ÖÇøÐÅÏ¢ |
| 135 | * @param name ·ÖÇøÃû |
| 136 | * @param system_type ËùÊôϵͳÀàÐÍ - 0 ƽ̨ÀàÐÍ, 1 oem |
| 137 | * @param partition_type ·ÖÇøÀàÐÍ |
| 138 | */ |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame] | 139 | typedef struct |
| 140 | { |
| 141 | char name[PARTITION_NAME_LEN]; |
| 142 | int system_type; |
| 143 | int partition_type; |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 144 | } oem_partition_info_t; |
| 145 | |
| 146 | |
| 147 | /** |
| 148 | * @brief ϵͳ¿ÉÉý¼¶·ÖÇøÐÅÏ¢ |
| 149 | * @param platform_partition_info ƽ̨¿ÉÉý¼¶·ÖÇøÐÅÏ¢ |
| 150 | * @param oem_partition_info oem¿ÉÉý¼¶·ÖÇøÐÅÏ¢ |
| 151 | */ |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame] | 152 | typedef struct |
| 153 | { |
| 154 | system_partition_info_head_t system_partition_info_head; |
| 155 | platform_partition_info_t *platform_partition_info; |
| 156 | oem_partition_info_t *oem_partition_info; |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 157 | } system_upgrade_partition_info_t; |
| 158 | |
| 159 | |
| 160 | /******************************************************************************* |
| 161 | * Global variable declarations * |
| 162 | ******************************************************************************/ |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame] | 163 | extern char FOTA_PACKAGE_FILE[128]; |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 164 | |
| 165 | |
| 166 | /******************************************************************************* |
| 167 | * Global function declarations * |
| 168 | ******************************************************************************/ |
| 169 | int upi_delete_folder(const char* folderpath); |
| 170 | int upi_create_folder(const char* folderpath); |
| 171 | int upi_check_file_existence(const char* filepath); |
| 172 | char * get_log_root_path(); |
| 173 | char * get_temp_path(); |
| 174 | |
| 175 | int hash_copy(char *dst, char *src, int type); |
| 176 | int hash_compare(char *str1, char *str2, int type); |
| 177 | void show_hash_hex(int type, const char* title, char *hash); |
| 178 | |
| 179 | |
| 180 | void upi_set_upgrade_status(int status); |
| 181 | void upi_set_upgrade_total_size(int total_size); |
| 182 | void upi_set_upgrade_updated_size(int updated_size); |
| 183 | void upi_set_sync_status(int sync_status); |
| 184 | |
| 185 | int upi_get_upgrade_status(); |
| 186 | int upi_get_upgrade_total_size(); |
| 187 | int upi_get_upgrade_updated_size(); |
| 188 | int upi_get_sync_status(); |
| 189 | |
| 190 | int upi_get_current_system(); |
| 191 | int upi_get_target_upgrade_system(); |
| 192 | int upi_get_target_sync_system(int *target_system_index, int *target_system); |
| 193 | |
| 194 | ssize_t upi_readn(int fd, void *vptr, size_t n); |
| 195 | |
| 196 | int upi_init_system_partition_info(system_upgrade_partition_info_t *system_partition_info); |
| 197 | void upi_deinit_system_partition_info(system_upgrade_partition_info_t *system_partition_info); |
| 198 | |
| 199 | |
| 200 | /******************************************************************************* |
| 201 | * Inline function implementations * |
| 202 | ******************************************************************************/ |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | #endif // _UPI_PUBLIC_H |
| 208 | |