blob: 0ade3d330ee9e129ffb2eacf902ebb40ed6eec4b [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/**
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
39void* realloc_debug(void *ptr, size_t size, const char*func, long line);
40
41void* malloc_debug(size_t bytes, const char* func, long line);
42void* free_debug(void*p, const char* func, long line);
43char* 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
61
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
96typedef enum {
97 HASH_TYPE_SHA_512 = 0,
98 HASH_TYPE_SHA_256
99} Hash_type_s;
100
101
102/**
103* @brief ϵͳ·ÖÇøÐÅϢͷ
104* @param magic ħÊõ×Ö
105* @param plat ƽ̨: 0 - V3T, 1 - 8501
106* @param plat_partition_num ƽ̨·ÖÇøÊý
107* @param oem_partition_num oem·ÖÇøÊý
108*/
109typedef struct {
110 char magic[SYSTEM_UPGRADE_PARTITION_INFO_HEAD_MAGIC_LEN];
111 int plat;
112 int plat_partition_num;
113 int oem_partition_num;
114} system_partition_info_head_t;
115
116
117/**
118* @brief ƽ̨ϵͳ·ÖÇøÐÅÏ¢
119* @param name ·ÖÇøÃû
120* @param system_type ËùÊôϵͳÀàÐÍ - 0 ƽ̨ÀàÐÍ, 1 oem
121* @param partition_type ·ÖÇøÀàÐÍ
122*/
123typedef struct {
124 char name[PARTITION_NAME_LEN];
125 int system_type;
126 int partition_type;
127} platform_partition_info_t;
128
129
130/**
131* @brief oem·ÖÇøÐÅÏ¢
132* @param name ·ÖÇøÃû
133* @param system_type ËùÊôϵͳÀàÐÍ - 0 ƽ̨ÀàÐÍ, 1 oem
134* @param partition_type ·ÖÇøÀàÐÍ
135*/
136typedef struct {
137 char name[PARTITION_NAME_LEN];
138 int system_type;
139 int partition_type;
140} oem_partition_info_t;
141
142
143/**
144* @brief ϵͳ¿ÉÉý¼¶·ÖÇøÐÅÏ¢
145* @param platform_partition_info ƽ̨¿ÉÉý¼¶·ÖÇøÐÅÏ¢
146* @param oem_partition_info oem¿ÉÉý¼¶·ÖÇøÐÅÏ¢
147*/
148typedef struct {
149 system_partition_info_head_t system_partition_info_head;
150 platform_partition_info_t *platform_partition_info;
151 oem_partition_info_t *oem_partition_info;
152} system_upgrade_partition_info_t;
153
154
155/*******************************************************************************
156 * Global variable declarations *
157 ******************************************************************************/
158
159
160/*******************************************************************************
161 * Global function declarations *
162 ******************************************************************************/
163int upi_delete_folder(const char* folderpath);
164int upi_create_folder(const char* folderpath);
165int upi_check_file_existence(const char* filepath);
166char * get_log_root_path();
167char * get_temp_path();
168
169int hash_copy(char *dst, char *src, int type);
170int hash_compare(char *str1, char *str2, int type);
171void show_hash_hex(int type, const char* title, char *hash);
172
173
174void upi_set_upgrade_status(int status);
175void upi_set_upgrade_total_size(int total_size);
176void upi_set_upgrade_updated_size(int updated_size);
177void upi_set_sync_status(int sync_status);
178
179int upi_get_upgrade_status();
180int upi_get_upgrade_total_size();
181int upi_get_upgrade_updated_size();
182int upi_get_sync_status();
183
184int upi_get_current_system();
185int upi_get_target_upgrade_system();
186int upi_get_target_sync_system(int *target_system_index, int *target_system);
187
188ssize_t upi_readn(int fd, void *vptr, size_t n);
189
190int upi_init_system_partition_info(system_upgrade_partition_info_t *system_partition_info);
191void upi_deinit_system_partition_info(system_upgrade_partition_info_t *system_partition_info);
192
193
194/*******************************************************************************
195 * Inline function implementations *
196 ******************************************************************************/
197
198
199
200
201#endif // _UPI_PUBLIC_H
202