b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 1 | #include <stdlib.h>
|
| 2 | #include <stdio.h>
|
| 3 | #include <string.h>
|
| 4 | #include <sys/stat.h>
|
| 5 | #include <sys/types.h>
|
| 6 | #include <unistd.h>
|
| 7 | #include <dlfcn.h>
|
| 8 | #include <stdint.h>
|
| 9 |
|
| 10 | #include <errno.h>
|
| 11 | #include <stdbool.h>
|
| 12 |
|
l.yang | 7b93b55 | 2025-05-28 05:00:14 -0700 | [diff] [blame] | 13 | #include "gsw_ota_ua_interface.h"
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 14 |
|
| 15 |
|
| 16 |
|
| 17 | #define LYNQ_OTA_INPROCESS 3
|
| 18 | #define LYNQ_OTA_SUCCESS 4
|
| 19 | #define LYNQ_OTA_FAILED 5
|
| 20 |
|
| 21 | #ifndef LOG_ERR_LEVEL |
| 22 | #define LOG_ERR_LEVEL 3 /* error conditions */ |
| 23 | #endif |
| 24 | #ifndef LOG_WARN_LEVEL |
| 25 | #define LOG_WARN_LEVEL 4 /* warning conditions */ |
| 26 | #endif |
| 27 | #ifndef LOG_INFO_LEVEL |
| 28 | #define LOG_INFO_LEVEL 6 /* informational */ |
| 29 | #endif |
| 30 | #ifndef LOG_DEBUG_LEVEL |
| 31 | #define LOG_DEBUG_LEVEL 7 /* debug-level messages */ |
| 32 | #endif |
| 33 | #ifndef LOG_VERBOSE_LEVEL |
| 34 | #define LOG_VERBOSE_LEVEL 8 |
| 35 | #endif
|
| 36 |
|
| 37 |
|
| 38 | #define LIB_PATH "/lib/libmbtk_lib.so"
|
| 39 |
|
l.yang | 6a42e4d | 2025-05-28 01:04:20 -0700 | [diff] [blame] | 40 | #define GSW_OTA "[HAL][GSW_OTA]"
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 41 |
|
| 42 | #define StatFunc(x,y) stat(x,y)
|
| 43 |
|
| 44 | #define LOGV(fmt, args ...) \ |
| 45 | do{ \ |
| 46 | char *file_ptr_1001 = __FILE__; \ |
| 47 | char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \ |
| 48 | char line_1001[10] = {0}; \ |
| 49 | sprintf(line_1001, "%d", __LINE__); \ |
| 50 | while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \ |
| 51 | if(*ptr_1001 == '/') \ |
| 52 | break; \ |
| 53 | ptr_1001--; \ |
| 54 | } \ |
l.yang | 6a42e4d | 2025-05-28 01:04:20 -0700 | [diff] [blame] | 55 | fun_ptr_log(LOG_VERBOSE_LEVEL, "%s#%s: "GSW_OTA"" fmt, ptr_1001 + 1, line_1001, ##args); \
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 56 | } while(0) |
| 57 | |
| 58 | #define LOGI(fmt, args...) \ |
| 59 | do{ \ |
| 60 | char *file_ptr_1001 = __FILE__; \ |
| 61 | char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \ |
| 62 | char line_1001[10] = {0}; \ |
| 63 | sprintf(line_1001, "%d", __LINE__); \ |
| 64 | while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \ |
| 65 | if(*ptr_1001 == '/') \ |
| 66 | break; \ |
| 67 | ptr_1001--; \ |
| 68 | } \ |
l.yang | 6a42e4d | 2025-05-28 01:04:20 -0700 | [diff] [blame] | 69 | fun_ptr_log(LOG_INFO_LEVEL, "%s#%s: "GSW_OTA"" fmt, ptr_1001 + 1, line_1001, ##args); \
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 70 | } while(0) |
| 71 | |
| 72 | #define LOGD(fmt, args...) \ |
| 73 | do{ \ |
| 74 | char *file_ptr_1001 = __FILE__; \ |
| 75 | char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \ |
| 76 | char line_1001[10] = {0}; \ |
| 77 | sprintf(line_1001, "%d", __LINE__); \ |
| 78 | while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \ |
| 79 | if(*ptr_1001 == '/') \ |
| 80 | break; \ |
| 81 | ptr_1001--; \ |
| 82 | } \ |
l.yang | 6a42e4d | 2025-05-28 01:04:20 -0700 | [diff] [blame] | 83 | fun_ptr_log(LOG_DEBUG_LEVEL, "%s#%s: "GSW_OTA"" fmt, ptr_1001 + 1, line_1001, ##args); \
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 84 | } while(0) |
| 85 | |
| 86 | #define LOGW(fmt, args...) \ |
| 87 | do{ \ |
| 88 | char *file_ptr_1001 = __FILE__; \ |
| 89 | char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \ |
| 90 | char line_1001[10] = {0}; \ |
| 91 | sprintf(line_1001, "%d", __LINE__); \ |
| 92 | while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \ |
| 93 | if(*ptr_1001 == '/') \ |
| 94 | break; \ |
| 95 | ptr_1001--; \ |
| 96 | } \ |
l.yang | 6a42e4d | 2025-05-28 01:04:20 -0700 | [diff] [blame] | 97 | fun_ptr_log(LOG_WARN_LEVEL, "%s#%s: "GSW_OTA"" fmt, ptr_1001 + 1, line_1001, ##args); \
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 98 | } while(0) |
| 99 | |
| 100 | #define LOGE(fmt, args...) \ |
| 101 | do{ \ |
| 102 | char *file_ptr_1001 = __FILE__; \
|
| 103 | char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \ |
| 104 | char line_1001[10] = {0}; \ |
| 105 | sprintf(line_1001, "%d", __LINE__); \ |
| 106 | while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \ |
| 107 | if(*ptr_1001 == '/') \ |
| 108 | break; \ |
| 109 | ptr_1001--; \ |
| 110 | } \ |
l.yang | 6a42e4d | 2025-05-28 01:04:20 -0700 | [diff] [blame] | 111 | fun_ptr_log(LOG_ERR_LEVEL, "%s#%s: "GSW_OTA"" fmt, ptr_1001 + 1, line_1001, ##args); \
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 112 | } while(0)
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 113 |
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 114 |
|
l.yang | 7b93b55 | 2025-05-28 05:00:14 -0700 | [diff] [blame] | 115 | typedef enum
|
| 116 | {
|
| 117 | GSW_UPDATE_SUCCEED = 0, //update succeed
|
| 118 | GSW_UPDATE_INPROGRESS, //update in progress
|
| 119 | GSW_UPDATE_BACKUP, //A/B partition sync in progress
|
| 120 | GSW_UPDATE_FAILED, //update failed
|
| 121 | GSW_UPDATE_WAITEDONE, //update in-active part finished,not switch update part.
|
| 122 | GSW_UPDATE_NEEDSYNC, //switch update part, need sync A/B part
|
| 123 | GSW_UPDATE_CANCEL //updata cancel success
|
| 124 | }gsw_update_state_t;
|
| 125 |
|
| 126 | typedef enum
|
| 127 | {
|
| 128 | GSW_UPDATE_NOERROR=0, //升级成功
|
| 129 | GSW_UPDATE_ARGUMENTERROR, //升级程序启动参数错误
|
| 130 | GSW_UPDATE_SDCARDNOEXIST, //未挂载外置FLASH等存储设备
|
| 131 | GSW_UPDATE_PACKAGENOEXIST, //升级包不存在
|
| 132 | GSW_UPDATE_UNZIPFAILED, //解压升级包出错
|
| 133 | GSW_UPDATE_PARTITIONFLUSHERROR,//写入分区出错
|
| 134 | GSW_UPDATE_XMLPARSEERROR, //解析 fotaconfig.xml 文件出错
|
| 135 | GSW_UPDATE_DIFFUBIUNATTACH, //差分升级 UBI 分区挂载异常
|
| 136 | GSW_UPDATE_NOSPACELEFT, //空间不足
|
| 137 | GSW_UPDATE_FILECHECKFAILED, //MD5 值校验失败
|
| 138 | GSW_UPDATE_BSPATCHFAILED, //bspatch 合成新文件夹失败
|
| 139 | GSW_UPDATE_NOFINDPARTITION, //待升级分区不存在
|
| 140 | GSW_UPDATE_UBIVOLUMEERROR, //差分升级,待升级 UBI 卷不存在
|
| 141 | GSW_UPDATE_NOFOTACONFIGFILE, //升级包中无 fotaconfig.xml 文件
|
| 142 | GSW_UPDATE_GETOLDSOFTWAREFAILED,//读取原始版本固件失败
|
| 143 | GSW_UPDATE_FILENOTEXIST, //文件不存在
|
| 144 | GSW_UPDATE_UPGRADECANCELED, //升级或分区同步被取消
|
| 145 | GSW_UPDATE_NONEEDCANCEL, //取消升级失败
|
| 146 | GSW_UPDATE_NOGOING //升级或分区同步正在进行,不可重复操作
|
| 147 | }gsw_update_exit_code_t;
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 148 |
|
| 149 |
|
l.yang | 7b93b55 | 2025-05-28 05:00:14 -0700 | [diff] [blame] | 150 | typedef struct
|
| 151 | {
|
| 152 | unsigned int percentage; //update progress0-100
|
| 153 | gsw_update_state_t update_state;
|
| 154 | gsw_update_exit_code_t exit_code;
|
| 155 | }gsw_update_info_s;
|
| 156 |
|
| 157 | typedef struct
|
| 158 | {
|
| 159 | gsw_update_state_t update_state;
|
| 160 | uint8_t is_damaged; //TURE: damaged FALSE:no damaged
|
| 161 | uint8_t damaged_partname[16];
|
| 162 | }gsw_system_status_s;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 163 |
|
| 164 | typedef int (*mbtk_fota_get_active_absys_type)(void);
|
| 165 | typedef int (*mbtk_fota_fw_write)(char* fname, int segment_size);
|
| 166 | typedef int (*mbtk_fota_fw_write_by_url)(char* url, int segment_size,
|
| 167 | int conn_timeout, int download_timeout);
|
| 168 |
|
| 169 | typedef int(*fota_callback)(int state, int percent);
|
| 170 | typedef int (*mbtk_fota_init)(fota_callback cb);
|
| 171 | typedef int (*mbtk_fota_status)(void);
|
| 172 |
|
| 173 | typedef void (*mbtk_log)(int level, const char *format,...);
|
| 174 |
|
| 175 | static int segment_size =0;
|
| 176 | static int Process_flag = 0;
|
| 177 | char addr_buf[256] = {0};
|
| 178 | static void *handle = NULL;
|
| 179 | static mbtk_log fun_ptr_log = NULL;
|
| 180 |
|
| 181 | static int s_ota_flag = -1;
|
| 182 |
|
| 183 | int fota_cb(int status, int percent)
|
| 184 | {
|
| 185 | Process_flag = percent;
|
| 186 | return 0;
|
| 187 | }
|
| 188 |
|
| 189 | static int funstat( char *filename)
|
| 190 | { |
| 191 | int ret = 0; |
| 192 | struct stat tmep_s; |
| 193 | |
| 194 | memset(&tmep_s, 0, sizeof(stat)); |
| 195 | ret = StatFunc(filename, &tmep_s); |
| 196 | |
| 197 | if (ret) |
| 198 | { |
| 199 | LOGE("stat %s failed! error_code: %s", filename ,strerror(errno)); |
| 200 | return -1; |
| 201 | } |
| 202 | |
| 203 | if (tmep_s.st_size > 0) |
| 204 | { |
| 205 | segment_size = tmep_s.st_size; |
| 206 | } |
| 207 | |
| 208 | return 0; |
| 209 | }
|
| 210 |
|
| 211 | int32_t init_handle()
|
| 212 | {
|
| 213 | if(handle == NULL)
|
| 214 | {
|
| 215 | handle = dlopen(LIB_PATH, RTLD_NOW );
|
| 216 | if(handle == NULL)
|
| 217 | {
|
l.yang | 7b93b55 | 2025-05-28 05:00:14 -0700 | [diff] [blame] | 218 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 219 | }
|
| 220 | if(fun_ptr_log == NULL)
|
| 221 | {
|
| 222 | fun_ptr_log = (mbtk_log)dlsym(handle, "mbtk_log");
|
| 223 | if(fun_ptr_log == NULL)
|
| 224 | {
|
l.yang | 7b93b55 | 2025-05-28 05:00:14 -0700 | [diff] [blame] | 225 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 226 | }
|
| 227 | }
|
| 228 |
|
| 229 | }
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 | return GSW_HAL_SUCCESS;
|
| 234 | }
|
| 235 |
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 236 | /**
|
| 237 | * @brief Start install modem software
|
| 238 | * @param [in] char* file_path
|
| 239 | * @param [out] NULL
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 240 | * @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 241 | */
|
| 242 | int32_t gsw_update_modem_start_autobackup(char* file_path)
|
| 243 | {
|
| 244 |
|
| 245 | if(file_path == NULL)
|
| 246 | {
|
| 247 | LOGE("invalid file_path \n");
|
l.yang | 7b93b55 | 2025-05-28 05:00:14 -0700 | [diff] [blame] | 248 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 249 | }
|
| 250 |
|
| 251 |
|
| 252 | mbtk_fota_fw_write func_ptr_update = NULL;
|
| 253 | mbtk_fota_init func_ptr_init= NULL;
|
| 254 | mbtk_fota_fw_write_by_url func_ptr_update_url = NULL;
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 | int ret = -1;
|
| 259 | ret = init_handle();
|
| 260 | if(ret < 0)
|
| 261 | {
|
| 262 | LOGE("init_handle fail");
|
l.yang | 7b93b55 | 2025-05-28 05:00:14 -0700 | [diff] [blame] | 263 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 264 | }
|
| 265 |
|
| 266 | func_ptr_update_url = (mbtk_fota_fw_write_by_url)dlsym(handle, "mbtk_fota_fw_write_by_url");
|
| 267 | if(func_ptr_update_url == NULL)
|
| 268 | {
|
| 269 | LOGE("Error: %s", dlerror());
|
l.yang | 7b93b55 | 2025-05-28 05:00:14 -0700 | [diff] [blame] | 270 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 271 | }
|
| 272 |
|
| 273 |
|
| 274 | // Get the function pointer
|
| 275 | func_ptr_update = (mbtk_fota_fw_write)dlsym(handle, "mbtk_fota_fw_write");
|
| 276 | if (func_ptr_update == NULL)
|
| 277 | {
|
| 278 | LOGE("Error: %s", dlerror());
|
l.yang | 7b93b55 | 2025-05-28 05:00:14 -0700 | [diff] [blame] | 279 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 280 | }
|
| 281 |
|
| 282 | func_ptr_init = (mbtk_fota_init)dlsym(handle, "mbtk_fota_init");
|
| 283 | if(func_ptr_init == NULL)
|
| 284 | {
|
| 285 | LOGE("Error: %s", dlerror());
|
l.yang | 7b93b55 | 2025-05-28 05:00:14 -0700 | [diff] [blame] | 286 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 287 | }
|
| 288 |
|
| 289 |
|
| 290 | if(s_ota_flag == -1)
|
| 291 | {
|
| 292 | ret = func_ptr_init(fota_cb);
|
| 293 | if(ret < 0)
|
| 294 | {
|
| 295 | LOGE("Error: mbtk_fota_init failed");
|
| 296 |
|
l.yang | 7b93b55 | 2025-05-28 05:00:14 -0700 | [diff] [blame] | 297 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 298 | }
|
| 299 | else
|
| 300 | {
|
| 301 | s_ota_flag = 0;
|
| 302 | }
|
| 303 | }
|
| 304 |
|
| 305 | if(strncmp(file_path, "http", 4) == 0)
|
| 306 | {
|
| 307 | segment_size = 62914560;
|
| 308 | ret = func_ptr_update_url(file_path, segment_size,10, 600);
|
| 309 | }
|
| 310 | else
|
| 311 | {
|
hj.shao | 6318d60 | 2025-06-09 20:33:13 -0700 | [diff] [blame] | 312 | if(strstr(file_path,"fota.delta") == NULL)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 313 | {
|
| 314 | LOGE("Bad file path ");
|
l.yang | 7b93b55 | 2025-05-28 05:00:14 -0700 | [diff] [blame] | 315 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 316 | }
|
| 317 | else
|
| 318 | {
|
| 319 | if(access(file_path,F_OK) !=0)
|
| 320 | {
|
| 321 | LOGE("update file no exist");
|
l.yang | 7b93b55 | 2025-05-28 05:00:14 -0700 | [diff] [blame] | 322 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 323 | }
|
| 324 | }
|
| 325 |
|
| 326 | ret = funstat(file_path);
|
| 327 | if (ret) |
| 328 | { |
| 329 | LOGE("get segment_size fail");
|
l.yang | 7b93b55 | 2025-05-28 05:00:14 -0700 | [diff] [blame] | 330 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 331 | }
|
| 332 | ret = func_ptr_update(file_path, segment_size);
|
| 333 | if(ret < 0)
|
| 334 | {
|
| 335 | LOGE("Error: mbtk_fota_fw_write failed\n");
|
l.yang | 7b93b55 | 2025-05-28 05:00:14 -0700 | [diff] [blame] | 336 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 337 | }
|
| 338 | }
|
| 339 | return GSW_HAL_SUCCESS;
|
| 340 |
|
| 341 | }
|
| 342 |
|
| 343 | /**
|
| 344 | * @brief check the modem update condition
|
| 345 | * @param [in] NULL
|
| 346 | * @param [out] NULL
|
| 347 | * @retval TRUE/FALSE
|
| 348 | */
|
| 349 | bool gsw_update_modem_check_condition(void)
|
| 350 | {
|
| 351 | char command[32] = {0};
|
| 352 | char buffer[64] = {0};
|
| 353 | const char *process_ota = "{otad}";
|
| 354 |
|
| 355 | snprintf(command,sizeof(command), "ps | grep %s | grep -v grep", process_ota);
|
| 356 | FILE *fp = popen(command, "r");
|
| 357 | if (fp == NULL)
|
| 358 | {
|
| 359 | return false;
|
| 360 | }
|
| 361 |
|
| 362 | if(fgets(buffer, sizeof(buffer), fp)!= NULL)
|
| 363 | {
|
| 364 | pclose(fp);
|
| 365 | return true;
|
| 366 | }
|
| 367 | pclose(fp);
|
| 368 | return false;
|
| 369 |
|
| 370 | }
|
| 371 |
|
| 372 | /**
|
| 373 | * @brief get update modem result
|
| 374 | * @param [in] NULL
|
| 375 | * @param [out] NULL
|
| 376 | * @retval E_GSW_OTA_RET
|
| 377 | */
|
l.yang | 7b93b55 | 2025-05-28 05:00:14 -0700 | [diff] [blame] | 378 | int32_t gsw_update_modem_result_query(void)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 379 | {
|
| 380 |
|
| 381 | mbtk_fota_status func_ptr_get_result = NULL;
|
| 382 | int ret = -1;
|
| 383 |
|
| 384 | ret = init_handle();
|
| 385 | if(ret < 0)
|
| 386 | {
|
| 387 | LOGE("init_handle fail");
|
l.yang | 7b93b55 | 2025-05-28 05:00:14 -0700 | [diff] [blame] | 388 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 389 | }
|
| 390 |
|
| 391 | // Get the function pointer
|
| 392 | func_ptr_get_result = (mbtk_fota_status)dlsym(handle, "mbtk_fota_status");
|
| 393 | if (func_ptr_get_result == NULL)
|
| 394 | {
|
| 395 | LOGE("Error: %s\n", dlerror());
|
l.yang | 7b93b55 | 2025-05-28 05:00:14 -0700 | [diff] [blame] | 396 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 397 | }
|
| 398 | ret = func_ptr_get_result();
|
| 399 | if(ret < 0 && ret !=-1)
|
| 400 | {
|
| 401 | LOGE("Error: mbtk_fota_status failed\n");
|
l.yang | 7b93b55 | 2025-05-28 05:00:14 -0700 | [diff] [blame] | 402 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 403 | }
|
| 404 |
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 405 |
|
| 406 | if(ret == LYNQ_OTA_INPROCESS)
|
| 407 | {
|
| 408 | return GSW_OTA_INPROCESS;
|
| 409 |
|
| 410 | }
|
| 411 | else if(ret == LYNQ_OTA_SUCCESS)
|
| 412 | {
|
| 413 | return GSW_OTA_SUCCESS;
|
| 414 | }
|
| 415 | else if(ret == -1)
|
| 416 | {
|
| 417 | return GSW_OTA_NO_TASK;
|
| 418 | }
|
| 419 |
|
| 420 | return GSW_OTA_FAILURE;
|
| 421 |
|
| 422 |
|
| 423 | }
|
| 424 |
|
| 425 | /**
|
| 426 | * @brief Start install modem software
|
| 427 | * @param [in] char* file_path
|
| 428 | * @param [out] NULL
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 429 | * @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 430 | */
|
| 431 | int32_t gsw_update_modem_start_nobackup(char* file_path)
|
| 432 | {
|
| 433 |
|
| 434 | return GSW_HAL_SUCCESS;
|
| 435 | }
|
| 436 |
|
| 437 |
|
| 438 | /**
|
| 439 | * @brief get current system
|
| 440 | * @param [in] NULL
|
| 441 | * @param [out] NULL
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 442 | * @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 443 | */
|
l.yang | 7b93b55 | 2025-05-28 05:00:14 -0700 | [diff] [blame] | 444 | int32_t gsw_update_modem_get_system(void)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 445 | {
|
| 446 | int ret = -1;
|
| 447 |
|
| 448 | mbtk_fota_get_active_absys_type func_ptr;
|
| 449 | ret = init_handle();
|
| 450 | if(ret < 0)
|
| 451 | {
|
| 452 | LOGE("init_handle fail");
|
l.yang | 7b93b55 | 2025-05-28 05:00:14 -0700 | [diff] [blame] | 453 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 454 | }
|
| 455 |
|
| 456 | // Get the function pointer
|
| 457 | func_ptr = (mbtk_fota_get_active_absys_type)dlsym(handle, "mbtk_fota_get_active_absys_type");
|
| 458 | if (func_ptr == NULL)
|
| 459 | {
|
| 460 | LOGE("Error: %s", dlerror());
|
l.yang | 7b93b55 | 2025-05-28 05:00:14 -0700 | [diff] [blame] | 461 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 462 | }
|
| 463 | ret = func_ptr();
|
| 464 | if(ret < 0)
|
| 465 | {
|
| 466 | LOGE("Error: mbtk_fota_get_active_absys_type failed");
|
l.yang | 7b93b55 | 2025-05-28 05:00:14 -0700 | [diff] [blame] | 467 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 468 |
|
| 469 | }
|
| 470 |
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 471 |
|
| 472 | return ret;
|
| 473 |
|
| 474 | }
|
| 475 |
|
| 476 | /**
|
| 477 | * @brief cancel update
|
| 478 | * @param [in] NULL
|
| 479 | * @param [out] NULL
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 480 | * @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 481 | */
|
| 482 | int32_t gsw_update_modem_cancel(void)
|
| 483 | {
|
| 484 |
|
| 485 | return GSW_HAL_SUCCESS;
|
| 486 | }
|
| 487 |
|
| 488 | /**
|
| 489 | * @brief get modem update info
|
| 490 | * @param [in] NULL
|
| 491 | * @param [out] gsw_update_info_s
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 492 | * @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 493 | */
|
| 494 | int32_t gsw_update_modem_get_info(gsw_update_info_s *update_info)
|
| 495 | {
|
| 496 | int ret = -1;
|
| 497 |
|
| 498 | mbtk_fota_status func_ptr_get_info = NULL;
|
| 499 |
|
| 500 | ret = init_handle();
|
| 501 | if(ret < 0)
|
| 502 | {
|
| 503 | LOGE("init_handle fail");
|
l.yang | 7b93b55 | 2025-05-28 05:00:14 -0700 | [diff] [blame] | 504 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 505 | }
|
| 506 |
|
| 507 | // Get the function pointer
|
| 508 | func_ptr_get_info = (mbtk_fota_status)dlsym(handle, "mbtk_fota_status");
|
| 509 | if (func_ptr_get_info == NULL)
|
| 510 | {
|
| 511 | LOGE("Error: %s\n", dlerror());
|
l.yang | 7b93b55 | 2025-05-28 05:00:14 -0700 | [diff] [blame] | 512 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 513 | }
|
| 514 | ret = func_ptr_get_info();
|
| 515 | if(ret < 0 && ret != -1)
|
| 516 | {
|
| 517 | LOGE("Error: mbtk_fota_status failed\n");
|
l.yang | 7b93b55 | 2025-05-28 05:00:14 -0700 | [diff] [blame] | 518 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 519 | }
|
| 520 |
|
| 521 | //升级成功之后,未重启,不可重复升级
|
| 522 | if(ret == LYNQ_OTA_INPROCESS)
|
| 523 | {
|
| 524 | update_info->exit_code = GSW_UPDATE_NOGOING;
|
| 525 | update_info->percentage = Process_flag;
|
| 526 | update_info->update_state = GSW_UPDATE_INPROGRESS;
|
| 527 | }
|
| 528 | if(ret == LYNQ_OTA_SUCCESS)
|
| 529 | {
|
| 530 | update_info->exit_code = GSW_UPDATE_NOERROR;
|
| 531 | update_info->percentage = Process_flag;
|
| 532 | update_info->update_state = GSW_UPDATE_WAITEDONE;
|
| 533 | }
|
| 534 |
|
| 535 |
|
| 536 | if(ret == LYNQ_OTA_FAILED || ret == -1)
|
| 537 | {
|
| 538 | update_info->exit_code = GSW_UPDATE_GETOLDSOFTWAREFAILED;
|
| 539 | update_info->percentage = Process_flag;
|
| 540 | update_info->update_state = GSW_UPDATE_FAILED;
|
| 541 | }
|
| 542 |
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 543 | return GSW_HAL_SUCCESS;
|
| 544 |
|
| 545 | }
|
| 546 |
|
| 547 |
|
| 548 | /**
|
| 549 | * @brief get modem system status
|
| 550 | * @param [in] NULL
|
| 551 | * @param [out] gsw_system_status_s
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 552 | * @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 553 | */
|
| 554 | int32_t gsw_update_modem_get_status(gsw_system_status_s *system_status)
|
| 555 | {
|
| 556 | return GSW_HAL_SUCCESS;
|
| 557 | }
|
| 558 |
|
| 559 | /**
|
| 560 | * @brief A/B system sync
|
| 561 | * @param [in] NULL
|
| 562 | * @param [out] NULL
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 563 | * @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 564 | */
|
| 565 | int32_t gsw_update_modem_sync(void)
|
| 566 | {
|
| 567 | return GSW_HAL_SUCCESS;
|
| 568 |
|
| 569 | }
|
| 570 |
|
| 571 | /**
|
| 572 | * @brief A/B system switch
|
| 573 | * @param [in] NULL
|
| 574 | * @param [out] NULL
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 575 | * @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 576 | */
|
| 577 | int32_t gsw_update_modem_switch(void)
|
| 578 | {
|
| 579 | return GSW_HAL_SUCCESS;
|
| 580 | }
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 581 |
|
| 582 | int32_t gsw_update_modem_process(void *bufdata)
|
| 583 | {
|
| 584 | return gsw_update_modem_start_autobackup(UPDATE_MODEM_PACKAGE);
|
| 585 | }
|
| 586 |
|
| 587 | int32_t gsw_get_ab_system(gsw_system_type *type)
|
| 588 | {
|
| 589 | int32_t ret = GSW_HAL_NORMAL_FAIL;
|
| 590 |
|
| 591 | ret = gsw_update_modem_get_system();
|
| 592 | if (GSW_HAL_NORMAL_FAIL != ret)
|
| 593 | {
|
| 594 | *type = (gsw_system_type)ret;
|
| 595 | }
|
| 596 |
|
| 597 | return ret;
|
| 598 | }
|