l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 1 | /*******************************************************
|
| 2 | *
|
| 3 | * @brief:
|
| 4 | * @details: add fota upgrade api
|
| 5 | * @author: l.yang
|
| 6 | * @date: 2023.8.3
|
| 7 | * @version: V1.0
|
| 8 | * @copyright:Copyright (c) MobileTek
|
| 9 | *
|
| 10 | *********************************************/
|
| 11 |
|
| 12 | #include <stdio.h>
|
| 13 | #include <stdlib.h>
|
| 14 | #include <string.h>
|
| 15 | #include <sys/types.h>
|
| 16 | #include <errno.h>
|
| 17 | #include <sys/stat.h>
|
| 18 | #include <fcntl.h>
|
| 19 | #include <sys/ioctl.h>
|
| 20 | #include <dirent.h>
|
| 21 | #include <getopt.h>
|
| 22 | #include <unistd.h>
|
| 23 |
|
| 24 | #ifdef __cplusplus
|
| 25 | extern "C" {
|
| 26 | #endif
|
| 27 |
|
| 28 | #include "include/lynq-qser-fota.h"
|
| 29 | #include "liblog/lynq_deflog.h"
|
l.yang | c39faa2 | 2024-06-14 11:00:04 +0800 | [diff] [blame] | 30 | #include "include/lynq-qser-autosuspend.h"
|
l.yang | 7224e6c | 2024-06-14 13:04:28 +0800 | [diff] [blame] | 31 | #include "pub_debug_info.h"
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 32 |
|
l.yang | f8e8cf2 | 2024-01-25 15:10:22 +0800 | [diff] [blame] | 33 | #define FOTA_REBOOT_FLAG "/mnt/userdata/.fota_reboot_flag"
|
| 34 | #define FOTA_FLAG_FILE "/mnt/userdata/.back_up_flag"
|
l.yang | daba4bb | 2023-08-30 10:47:55 +0800 | [diff] [blame] | 35 | #define USER_LOG_TAG "LYNQ_FOTA"
|
| 36 | #define FOTA_ADDR_FILE "/mnt/userdata/.addr_value"
|
| 37 | #define FOTA_FILE_NAME "upgrade.package"
|
l.yang | f8e8cf2 | 2024-01-25 15:10:22 +0800 | [diff] [blame] | 38 | #define FOTA_UPGRADE_PROCESS "/mnt/userdata/.fota_upgrade_process"
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 39 | #define SYSTEM_A "34650"
|
| 40 | #define SYSTEM_B "39019"
|
| 41 |
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 42 |
|
| 43 | #define BOOTABLE "45227"
|
| 44 | #define UNBOOTABLE "47806"
|
| 45 |
|
l.yang | c39faa2 | 2024-06-14 11:00:04 +0800 | [diff] [blame] | 46 | #define FOTA_WAKELOCK_NAME "FOTA_WAKELOCK"
|
| 47 |
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 48 |
|
l.yang | 6e54791 | 2023-08-14 16:56:48 +0800 | [diff] [blame] | 49 | #define LYNQ_UPGRADE_STATUS_VERIFING (0)
|
| 50 | #define LYNQ_UPGRADE_STATUS_VERIFY_SUCCESS (1)
|
| 51 | #define LYNQ_UPGRADE_STATUS_VERIFY_FAIL (2)
|
| 52 | #define LYNQ_UPGRADE_STATUS_UPDATING (3)
|
| 53 | #define LYNQ_UPGRADE_STATUS_UPDATE_SUCCESS (4)
|
| 54 | #define LYNQ_UPGRADE_STATUS_UPDATE_FAIL (5)
|
| 55 |
|
l.yang | f8e8cf2 | 2024-01-25 15:10:22 +0800 | [diff] [blame] | 56 | #define LYNQ_SYNNCHRONIZING 8
|
| 57 | #define LYNQ_SYNC_SUCCESS 9
|
l.yang | 04a9e9c | 2024-06-04 16:51:05 +0800 | [diff] [blame] | 58 | #define LYNQ_SYNC_FAILED 10
|
l.yang | f8e8cf2 | 2024-01-25 15:10:22 +0800 | [diff] [blame] | 59 |
|
| 60 | #define ZXIC_SYNCHRONIZING 1
|
| 61 | #define ZXIC_SYNC_SUCCESS 0
|
l.yang | 04a9e9c | 2024-06-04 16:51:05 +0800 | [diff] [blame] | 62 | #define ZXIC_SYNC_FAILED -1
|
l.yang | f8e8cf2 | 2024-01-25 15:10:22 +0800 | [diff] [blame] | 63 |
|
| 64 | #define NO_REBOOT 0
|
| 65 |
|
| 66 |
|
| 67 | int total_size = 0;
|
| 68 | int upgrade_size = 0;
|
l.yang | 6e54791 | 2023-08-14 16:56:48 +0800 | [diff] [blame] | 69 |
|
l.yang | 7224e6c | 2024-06-14 13:04:28 +0800 | [diff] [blame] | 70 |
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 71 | typedef struct
|
| 72 | {
|
| 73 | int system;
|
| 74 | int status;
|
| 75 | int try_cnt;
|
| 76 | } z_system_info_t;
|
| 77 |
|
| 78 | typedef struct
|
| 79 | {
|
| 80 | int upgrade_status;
|
| 81 | int total_size;
|
| 82 | int upgraded_size;
|
| 83 | } z_upgrade_status_info_t;
|
| 84 |
|
| 85 | typedef struct
|
| 86 | {
|
| 87 | int boot_to;
|
| 88 | int fota_status;
|
| 89 | z_system_info_t system_1;
|
| 90 | z_system_info_t system_2;
|
| 91 | } z_upgrade_system_info_t;
|
| 92 |
|
| 93 | typedef struct
|
| 94 | {
|
| 95 | z_upgrade_status_info_t *status;
|
| 96 | void(* status_cb)(z_upgrade_status_info_t *status);
|
| 97 | } z_upgrade_flush_status_t;
|
| 98 |
|
| 99 | extern int zxic_dual_verify();
|
| 100 | extern int zxic_dual_upgrade(z_upgrade_flush_status_t *flush_status);
|
| 101 | extern int zxic_dual_get_upgrade_status(z_upgrade_status_info_t *upgrade_info);
|
| 102 | extern int zxic_dual_get_current_system();
|
| 103 | extern int zxic_dual_get_boot_to_system();
|
| 104 | extern int zxic_dual_set_boot_to_system(int system, int reboot_flag);
|
| 105 | extern int zxic_dual_get_system_status(z_upgrade_system_info_t *system_info);
|
| 106 | extern int zxic_dual_set_system_status(int system, int status);
|
| 107 | extern int zxic_dual_get_fota_status_for_nv();
|
| 108 | extern int zxic_dual_set_fota_status_for_nv(int status);
|
| 109 | extern int zxic_dual_sync_system(void);
|
| 110 | extern int zxic_dual_get_upgrade_type(void);
|
| 111 | extern void zxic_dual_get_sync_status(int *sync_status);
|
| 112 | extern int zxic_dual_set_sync_status(int sync_status);
|
| 113 | extern int zxic_dual_config_package_path(char *upgrade_package_path, int length);
|
| 114 |
|
| 115 | int lynq_fota_verify();
|
| 116 | int lynq_fota_upgrade();
|
| 117 | int lynq_get_current_system();
|
| 118 | int lynq_get_boot_to_system();
|
| 119 | int lynq_set_boot_to_system(char *option_para);
|
| 120 | int lynq_set_system_a_status(char *option_para);
|
| 121 | int lynq_set_system_b_status(char *option_para);
|
| 122 | int lynq_sync_system();
|
| 123 | int lynq_get_upgrade_type();
|
| 124 | int lynq_get_sync_status();
|
| 125 | int lynq_set_sync_status(char *option_para);
|
l.yang | 526ef68 | 2024-07-15 17:46:51 +0800 | [diff] [blame] | 126 | int calculate_md5_sum( char *md5_sum,int md5_size);
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 127 |
|
| 128 | /*****************************************
|
| 129 | * @brief:rock_update_main
|
| 130 | * @param count [IN]:NA
|
| 131 | * @param sum [OUT]:NA
|
| 132 | * @return :success 0, failed -1
|
| 133 | * @todo:NA
|
| 134 | * @see:NA
|
| 135 | * @warning:NA
|
| 136 | ******************************************/
|
| 137 | int rock_update_main(int reboot_flag)
|
| 138 | {
|
| 139 |
|
| 140 | int ret = 0;
|
| 141 | int current_slot = 0;
|
l.yang | daba4bb | 2023-08-30 10:47:55 +0800 | [diff] [blame] | 142 | int fota_sync_flag = 0;
|
l.yang | f8e8cf2 | 2024-01-25 15:10:22 +0800 | [diff] [blame] | 143 | int reboot_flg = NO_REBOOT;
|
l.yang | 7224e6c | 2024-06-14 13:04:28 +0800 | [diff] [blame] | 144 | time_t startTime;
|
| 145 | time_t endTime;
|
| 146 | struct tm *localTime;
|
| 147 | double elapsed = 0;
|
l.yang | 526ef68 | 2024-07-15 17:46:51 +0800 | [diff] [blame] | 148 | char md5_sum[48] = {0};
|
l.yang | 7224e6c | 2024-06-14 13:04:28 +0800 | [diff] [blame] | 149 |
|
l.yang | daba4bb | 2023-08-30 10:47:55 +0800 | [diff] [blame] | 150 | FILE *fp = NULL;
|
| 151 | fp = fopen(FOTA_FLAG_FILE,"w+");
|
| 152 | if(fp == NULL)
|
| 153 | {
|
| 154 | LYINFLOG("Creat fota flag file failed");
|
| 155 | return -1;
|
| 156 | }
|
| 157 | fwrite(&fota_sync_flag,sizeof(int),1,fp);
|
| 158 | fclose(fp);
|
l.yang | c814c3a | 2023-09-12 17:42:58 +0800 | [diff] [blame] | 159 |
|
| 160 | /* T106BUG-189 fix */
|
| 161 | system("sync");
|
l.yang | f8e8cf2 | 2024-01-25 15:10:22 +0800 | [diff] [blame] | 162 |
|
| 163 | fp =fopen(FOTA_REBOOT_FLAG,"w+");
|
| 164 | if(fp == NULL)
|
| 165 | {
|
l.yang | ce9a485 | 2024-03-26 10:07:25 +0800 | [diff] [blame] | 166 | LYERRLOG("Creat get upgrade status flag failed");
|
l.yang | f8e8cf2 | 2024-01-25 15:10:22 +0800 | [diff] [blame] | 167 | return -1;
|
| 168 | }
|
| 169 |
|
| 170 | fwrite(&reboot_flg,sizeof(int),1,fp);
|
| 171 | fclose(fp);
|
| 172 | system("sync");
|
l.yang | ce9a485 | 2024-03-26 10:07:25 +0800 | [diff] [blame] | 173 |
|
| 174 | //fix T106BUG-585 start
|
| 175 | total_size = 0;
|
| 176 | upgrade_size = 0;
|
| 177 |
|
| 178 | fp = fopen(FOTA_UPGRADE_PROCESS,"w+");
|
| 179 | if(fp == NULL)
|
| 180 | {
|
| 181 | LYERRLOG("Error opening file");
|
| 182 | return -1;
|
| 183 | }
|
| 184 |
|
| 185 | fprintf(fp, "%d,%d\n", total_size, upgrade_size);
|
| 186 | fclose(fp);
|
| 187 | //fix T106BUG-585 end
|
| 188 |
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 189 | ret = lynq_fota_verify();
|
| 190 | if(ret != 0)
|
| 191 | {
|
| 192 | LYINFLOG("Verify package failed exit upgrade");
|
| 193 | return -1;
|
| 194 | }
|
l.yang | 7224e6c | 2024-06-14 13:04:28 +0800 | [diff] [blame] | 195 |
|
l.yang | 526ef68 | 2024-07-15 17:46:51 +0800 | [diff] [blame] | 196 | ret = calculate_md5_sum(md5_sum,sizeof(md5_sum));
|
| 197 | if(ret != 0)
|
| 198 | {
|
| 199 | LYINFLOG("Calculate md5 sum failed");
|
| 200 | }
|
| 201 |
|
l.yang | 7224e6c | 2024-06-14 13:04:28 +0800 | [diff] [blame] | 202 | startTime = time(NULL);
|
| 203 | if(startTime == (time_t)-1)
|
| 204 | {
|
| 205 | LYERRLOG("Failed to get the current time.\n");
|
| 206 | }
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 207 |
|
| 208 | LYINFLOG("-----Begin to upgrade ----");
|
| 209 | ret = lynq_fota_upgrade();
|
l.yang | 7224e6c | 2024-06-14 13:04:28 +0800 | [diff] [blame] | 210 |
|
| 211 | endTime = time(NULL);
|
| 212 | if(endTime == (time_t)-1)
|
| 213 | {
|
| 214 | LYERRLOG("Failed to get the current time.\n");
|
| 215 | }
|
| 216 | elapsed = difftime(endTime, startTime);
|
| 217 | localTime = localtime(&endTime);
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 218 | if(ret != 0)
|
| 219 | {
|
l.yang | 7224e6c | 2024-06-14 13:04:28 +0800 | [diff] [blame] | 220 | LYERRLOG("Upgrade failed");
|
l.yang | 526ef68 | 2024-07-15 17:46:51 +0800 | [diff] [blame] | 221 | ret = sc_debug_info_record(MODULE_ID_CAP_FOTA,"failed,spendtime: %.2lf seconds,finished time %s,md5:%s", elapsed,asctime(localTime),md5_sum);
|
l.yang | 7224e6c | 2024-06-14 13:04:28 +0800 | [diff] [blame] | 222 | if(ret <= 0)
|
| 223 | {
|
| 224 | LYERRLOG("lynq_record_debug_info failed");
|
| 225 | }
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 226 | return -1;
|
| 227 | }
|
l.yang | 7224e6c | 2024-06-14 13:04:28 +0800 | [diff] [blame] | 228 | else
|
| 229 | {
|
| 230 | LYINFLOG("Upgrade success");
|
l.yang | 526ef68 | 2024-07-15 17:46:51 +0800 | [diff] [blame] | 231 | ret = sc_debug_info_record(MODULE_ID_CAP_FOTA,"success,spendtime: %.2lf seconds,finished time %s,md5:%s", elapsed,asctime(localTime),md5_sum);
|
l.yang | 7224e6c | 2024-06-14 13:04:28 +0800 | [diff] [blame] | 232 | if(ret <= 0)
|
| 233 | {
|
| 234 | LYERRLOG("lynq_record_debug_info failed");
|
| 235 | }
|
| 236 | }
|
| 237 |
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 238 |
|
| 239 | ret = lynq_get_upgrade_status();
|
l.yang | 6e54791 | 2023-08-14 16:56:48 +0800 | [diff] [blame] | 240 | if(ret != LYNQ_UPGRADE_STATUS_UPDATE_SUCCESS)
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 241 | {
|
| 242 | LYINFLOG("Upgrade failed ");
|
| 243 | return -1;
|
| 244 | }
|
| 245 |
|
| 246 | current_slot = lynq_get_current_system();
|
| 247 | if(current_slot < 0)
|
| 248 | {
|
| 249 | LYINFLOG("Get current system failed");
|
| 250 | return -1;
|
| 251 | }
|
| 252 |
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 253 | if(current_slot == atoi(SYSTEM_A))
|
| 254 | {
|
| 255 | LYINFLOG("current system is system a");
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 256 | ret = lynq_set_boot_to_system((char *)SYSTEM_B);
|
| 257 | if(ret != 0)
|
| 258 | {
|
| 259 | LYINFLOG("set system B boot failed ");
|
| 260 | return -1;
|
| 261 | }
|
l.yang | 185656c | 2023-09-28 14:26:41 +0800 | [diff] [blame] | 262 |
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 263 | }
|
| 264 | else if( current_slot == atoi(SYSTEM_B))
|
| 265 | {
|
| 266 | LYINFLOG("current system is system a");
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 267 | ret = lynq_set_boot_to_system((char *)SYSTEM_A);
|
| 268 | if(ret != 0)
|
| 269 | {
|
| 270 | LYINFLOG("set system B boot failed ");
|
| 271 | return -1;
|
| 272 | }
|
| 273 |
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 274 | }
|
l.yang | daba4bb | 2023-08-30 10:47:55 +0800 | [diff] [blame] | 275 |
|
| 276 | fp = fopen(FOTA_FLAG_FILE,"w+");
|
| 277 | if(fp == NULL)
|
| 278 | {
|
| 279 | LYINFLOG("Creat fota flag file failed");
|
| 280 | return -1;
|
| 281 | }
|
| 282 |
|
| 283 | fota_sync_flag = 1;
|
| 284 | fwrite(&fota_sync_flag,sizeof(int),1,fp);
|
| 285 | fclose(fp);
|
l.yang | c814c3a | 2023-09-12 17:42:58 +0800 | [diff] [blame] | 286 |
|
| 287 | /* T106BUG-189 fix */
|
| 288 | system("sync");
|
| 289 |
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 290 | if(reboot_flag == 1)
|
| 291 | {
|
| 292 | LYINFLOG("Enter reboot device");
|
| 293 | system("reboot");
|
| 294 | }
|
| 295 |
|
| 296 | return 0;
|
| 297 | }
|
| 298 |
|
| 299 | /*****************************************
|
| 300 | * @brief:upgrade callback function
|
| 301 | * @param count [IN]:z_upgrade_status_info_t *p_status
|
| 302 | * @param sum [OUT]:NA
|
| 303 | * @return :NA
|
| 304 | * @todo:
|
| 305 | * @see:NA
|
| 306 | * @warning:NA
|
| 307 | ******************************************/
|
| 308 | void lynq_g_flush_upgrade_status(z_upgrade_status_info_t *p_status)
|
| 309 | {
|
| 310 |
|
| 311 | LYINFLOG("Current status:%d ", p_status->upgrade_status);
|
| 312 |
|
| 313 | LYINFLOG("Total size:%d ", p_status->total_size);
|
| 314 |
|
| 315 | LYINFLOG("Updated size:%d ", p_status->upgraded_size);
|
l.yang | f8e8cf2 | 2024-01-25 15:10:22 +0800 | [diff] [blame] | 316 |
|
| 317 | total_size = p_status->total_size;
|
| 318 | upgrade_size = p_status->upgraded_size;
|
| 319 |
|
| 320 | FILE *fp = NULL;
|
l.yang | ce9a485 | 2024-03-26 10:07:25 +0800 | [diff] [blame] | 321 |
|
| 322 |
|
l.yang | f8e8cf2 | 2024-01-25 15:10:22 +0800 | [diff] [blame] | 323 | fp = fopen(FOTA_UPGRADE_PROCESS,"w");
|
| 324 | if (fp == NULL)
|
| 325 | {
|
| 326 | LYERRLOG("Error opening file");
|
| 327 | return;
|
| 328 | }
|
| 329 |
|
| 330 | fprintf(fp, "%d,%d\n", total_size, upgrade_size);
|
| 331 | fclose(fp);
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 332 | }
|
| 333 |
|
| 334 | /*****************************************
|
| 335 | * @brief:lynq_fota_set_addr_value
|
| 336 | * @param count [IN]:char *path
|
| 337 | * @param sum [OUT]:
|
| 338 | * @return :success 0, failed -1
|
| 339 | * @todo:NA
|
| 340 | * @see:NA
|
| 341 | * @warning:NA
|
| 342 | ******************************************/
|
| 343 | int lynq_fota_set_addr_value(char *value,int size)
|
| 344 | {
|
| 345 | int ret =0;
|
l.yang | daba4bb | 2023-08-30 10:47:55 +0800 | [diff] [blame] | 346 | FILE *fp = NULL;
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 347 | LYLOGSET(LOG_INFO);
|
| 348 | LYLOGEINIT(USER_LOG_TAG);
|
| 349 |
|
| 350 | if (NULL == value || size <= 0)
|
| 351 | {
|
| 352 | LYINFLOG("Bad package path!!!");
|
| 353 | return -1;
|
| 354 | }
|
| 355 | ret = zxic_dual_config_package_path(value, strlen(value));
|
| 356 | if(ret == -1)
|
| 357 | {
|
| 358 | LYINFLOG("Configure upgrade package path fail");
|
| 359 | return -1;
|
| 360 | }
|
| 361 |
|
l.yang | daba4bb | 2023-08-30 10:47:55 +0800 | [diff] [blame] | 362 | fp = fopen(FOTA_ADDR_FILE,"w+");
|
| 363 | if(fp == NULL)
|
| 364 | {
|
| 365 | LYINFLOG("Open addr file failed");
|
| 366 | return -1;
|
| 367 | }
|
| 368 |
|
| 369 | fprintf(fp,"%s",value);
|
| 370 | fclose(fp);
|
| 371 |
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 372 | LYINFLOG("Configure upgrade package path success");
|
| 373 | return 0;
|
| 374 | }
|
| 375 |
|
l.yang | daba4bb | 2023-08-30 10:47:55 +0800 | [diff] [blame] | 376 | /*****************************************
|
| 377 | * @brief:lynq_fota_get_addr_value
|
| 378 | * @param count [IN]:char *tmp_value
|
| 379 | * @param sum [OUT]:
|
| 380 | * @return :success 0, failed -1
|
| 381 | * @todo:NA
|
| 382 | * @see:NA
|
| 383 | * @warning:NA
|
| 384 | ******************************************/
|
| 385 | int lynq_fota_get_addr_value(char *tmp_value)
|
| 386 | {
|
| 387 | FILE *fp = NULL;
|
| 388 | char tmp_addr[128] = {0};
|
| 389 |
|
| 390 |
|
| 391 | fp = fopen(FOTA_ADDR_FILE,"r");
|
| 392 | if(fp == NULL)
|
| 393 | {
|
| 394 | LYINFLOG("Open fota addr faile failed!!!");
|
| 395 | return -1;
|
| 396 | }
|
| 397 | while(fgets(tmp_addr,sizeof(tmp_addr),fp) != NULL)
|
| 398 | {
|
| 399 | if( strstr(tmp_addr,FOTA_FILE_NAME) != NULL)
|
| 400 | {
|
| 401 | strncpy(tmp_value,tmp_addr,sizeof(tmp_addr) - 1);
|
| 402 | break;
|
| 403 | }
|
| 404 | else
|
| 405 | {
|
| 406 | LYINFLOG("Get addr failed\n");
|
| 407 | fclose(fp);
|
| 408 | return -1;
|
| 409 | }
|
| 410 | }
|
| 411 |
|
| 412 | fclose(fp);
|
| 413 | return 0;
|
| 414 |
|
| 415 |
|
| 416 | }
|
| 417 |
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 418 |
|
| 419 | /*****************************************
|
| 420 | * @brief:lynq_fota_verify
|
| 421 | * @param count [IN]:NA
|
| 422 | * @param sum [OUT]:NA
|
| 423 | * @return :success 0, failed -1
|
| 424 | * @todo:NA
|
| 425 | * @see:NA
|
| 426 | * @warning:NA
|
| 427 | ******************************************/
|
| 428 | int lynq_fota_verify()
|
| 429 | {
|
| 430 | int ret = 0;
|
| 431 |
|
| 432 | LYINFLOG("-----Begin to verify upgrade package----");
|
| 433 | ret = zxic_dual_verify();
|
| 434 | if(ret != 0)
|
| 435 | {
|
| 436 | LYINFLOG("Verify upgrade package failed");
|
| 437 | return -1;
|
| 438 | }
|
| 439 |
|
| 440 | return 0;
|
| 441 |
|
| 442 | }
|
| 443 |
|
| 444 | /*****************************************
|
| 445 | * @brief:upgrade function
|
| 446 | * @param count [IN]:NA
|
| 447 | * @param sum [OUT]:NA
|
| 448 | * @return :success 0, failed -1
|
| 449 | * @todo:NA
|
| 450 | * @see:NA
|
| 451 | * @warning:NA
|
| 452 | ******************************************/
|
| 453 | int lynq_fota_upgrade()
|
| 454 | {
|
| 455 | int ret = 0;
|
| 456 | z_upgrade_flush_status_t flush_status;
|
| 457 | z_upgrade_status_info_t status;
|
| 458 | memset(&status, 0, sizeof(z_upgrade_status_info_t));
|
| 459 | flush_status.status = &status;
|
| 460 | flush_status.status_cb = &lynq_g_flush_upgrade_status;
|
| 461 |
|
| 462 |
|
| 463 | LYINFLOG("Enter lynq_fota_upgrade !!!!");
|
| 464 | ret = zxic_dual_upgrade(&flush_status);
|
| 465 | if(ret != 0)
|
| 466 | {
|
| 467 | LYINFLOG("Fota upgrade failed!!!");
|
| 468 | return -1;
|
| 469 | }
|
| 470 | return 0;
|
| 471 | }
|
| 472 |
|
| 473 | /*****************************************
|
| 474 | * @brief:lynq_fota_nrestart no reboot
|
| 475 | * @param count [IN]:NA
|
| 476 | * @param sum [OUT]:NA
|
| 477 | * @return :success 0, failed -1
|
| 478 | * @todo:NA
|
| 479 | * @see:NA
|
| 480 | * @warning:NA
|
| 481 | ******************************************/
|
| 482 | int lynq_fota_nrestart(void)
|
| 483 | {
|
| 484 | int ret = 0;
|
l.yang | c39faa2 | 2024-06-14 11:00:04 +0800 | [diff] [blame] | 485 | int tmp = 0;
|
| 486 | int lock_fd = 0;
|
| 487 | lock_fd = qser_wakelock_create(FOTA_WAKELOCK_NAME, strlen(FOTA_WAKELOCK_NAME));
|
| 488 | if(lock_fd < 0)
|
| 489 | {
|
| 490 | LYERRLOG("Create fota wakelock failed %d",lock_fd);
|
| 491 | }
|
| 492 |
|
| 493 | qser_wakelock_lock(lock_fd);
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 494 | ret = rock_update_main(0);
|
| 495 | if(ret != 0)
|
| 496 | {
|
l.yang | c39faa2 | 2024-06-14 11:00:04 +0800 | [diff] [blame] | 497 | LYINFLOG("Upgrade failed !!!!");
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 498 | }
|
| 499 | else
|
| 500 | {
|
| 501 | LYINFLOG("upgrade success!!!");
|
| 502 | }
|
l.yang | c39faa2 | 2024-06-14 11:00:04 +0800 | [diff] [blame] | 503 |
|
| 504 | qser_wakelock_unlock(lock_fd);
|
| 505 | tmp = qser_wakelock_destroy(lock_fd);
|
| 506 | if(tmp < 0)
|
| 507 | {
|
| 508 | LYERRLOG("Destroy fota wakelock failed");
|
| 509 | }
|
| 510 |
|
| 511 | return ret;
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 512 | }
|
| 513 |
|
| 514 | /*****************************************
|
| 515 | * @brief:lynq_rock_main,upgrade done reboot
|
| 516 | * @param count [IN]:int first_run
|
| 517 | * @param sum [OUT]:NA
|
| 518 | * @return :success 0, failed -1
|
| 519 | * @todo:NA
|
| 520 | * @see:NA
|
| 521 | * @warning:NA
|
| 522 | ******************************************/
|
| 523 | int lynq_rock_main(int first_run)
|
| 524 | {
|
| 525 | if(first_run <= 0)
|
| 526 | {
|
| 527 | LYINFLOG("Bad input value !!!");
|
| 528 | return -1;
|
| 529 | }
|
| 530 |
|
| 531 | int ret = 0;
|
l.yang | c39faa2 | 2024-06-14 11:00:04 +0800 | [diff] [blame] | 532 | int lock_fd = 0;
|
| 533 | int tmp = 0;
|
| 534 | lock_fd = qser_wakelock_create(FOTA_WAKELOCK_NAME, strlen(FOTA_WAKELOCK_NAME));
|
| 535 | if(lock_fd < 0)
|
| 536 | {
|
| 537 | LYERRLOG("Create fota wakelock failed %d",lock_fd);
|
| 538 | }
|
| 539 |
|
| 540 | qser_wakelock_lock(lock_fd);
|
| 541 |
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 542 | ret = rock_update_main(1);
|
| 543 | LYINFLOG("rock_update_main ret = %d\n", ret);
|
| 544 | if(ret != 0)
|
| 545 | {
|
| 546 | LYINFLOG("fota update fail!\n");
|
l.yang | 2bd0b5d | 2024-06-20 10:47:10 +0800 | [diff] [blame] | 547 | qser_wakelock_unlock(lock_fd);
|
| 548 | tmp = qser_wakelock_destroy(lock_fd);
|
| 549 | if(tmp < 0)
|
| 550 | {
|
| 551 | LYERRLOG("Destroy fota wakelock failed");
|
| 552 | }
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 553 | }
|
l.yang | c39faa2 | 2024-06-14 11:00:04 +0800 | [diff] [blame] | 554 |
|
l.yang | 2bd0b5d | 2024-06-20 10:47:10 +0800 | [diff] [blame] | 555 |
|
l.yang | c39faa2 | 2024-06-14 11:00:04 +0800 | [diff] [blame] | 556 | return ret;
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 557 |
|
| 558 | }
|
| 559 |
|
| 560 | /*****************************************
|
| 561 | * @brief:lynq_get_current_system
|
| 562 | * @param count [IN]:NA
|
| 563 | * @param sum [OUT]:NA
|
| 564 | * @return :success: curretn slot , failed:-1
|
| 565 | * @todo:NA
|
| 566 | * @see:NA
|
| 567 | * @warning:NA
|
| 568 | ******************************************/
|
| 569 | int lynq_get_current_system()
|
| 570 | {
|
| 571 | int ret = 0;
|
| 572 |
|
| 573 | ret = zxic_dual_get_current_system();
|
| 574 | if(ret < 0)
|
| 575 | {
|
| 576 | LYINFLOG("lynq get current system faile");
|
| 577 | return -1;
|
| 578 | }
|
| 579 | if(ret == 34650)
|
| 580 | {
|
| 581 | LYINFLOG("Get current system is system A");
|
| 582 | }
|
| 583 | else if(ret == 39019)
|
| 584 | {
|
| 585 | LYINFLOG("Get current system is system B");
|
| 586 | }
|
| 587 |
|
| 588 | return ret;
|
| 589 |
|
| 590 | }
|
| 591 |
|
| 592 | /*****************************************
|
| 593 | * @brief:lynq_get_boot_to_system
|
| 594 | * @param count [IN]:NA
|
| 595 | * @param sum [OUT]:NA
|
| 596 | * @return :success: 0, failed:-1
|
| 597 | * @todo:NA
|
| 598 | * @see:NA
|
| 599 | * @warning:NA
|
| 600 | ******************************************/
|
| 601 | int lynq_get_boot_to_system()
|
| 602 | {
|
| 603 | int boot_to = 0;
|
| 604 | boot_to = zxic_dual_get_boot_to_system();
|
| 605 | if(boot_to < 0)
|
| 606 | {
|
| 607 | LYINFLOG("lynq get boot to system failed");
|
| 608 | return -1;
|
| 609 | }
|
| 610 | else
|
| 611 | {
|
| 612 | LYINFLOG("Boot to system:0x%08X[%d]",boot_to);
|
| 613 | }
|
| 614 |
|
| 615 | return 0;
|
| 616 |
|
| 617 | }
|
| 618 |
|
| 619 | /*****************************************
|
| 620 | * @brief:lynq_set_boot_to_system
|
| 621 | * @param count [IN]:char *option_para
|
| 622 | * @param sum [OUT]:NA
|
| 623 | * @return :success: 0, failed:-1
|
| 624 | * @todo:NA
|
| 625 | * @see:NA
|
| 626 | * @warning:NA
|
| 627 | ******************************************/
|
| 628 | int lynq_set_boot_to_system(char *option_para)
|
| 629 | {
|
| 630 | int ret = 0;
|
| 631 | if(option_para == NULL)
|
| 632 | {
|
| 633 | LYINFLOG("Input invalid value! null option parameters! ");
|
| 634 | return -1;
|
| 635 | }
|
| 636 |
|
| 637 | ret = zxic_dual_set_boot_to_system(atoi(option_para), 0);
|
| 638 | if(ret < 0)
|
| 639 | {
|
| 640 | LYINFLOG("Set boot to [%s] error ", option_para);
|
| 641 | return -1;
|
| 642 | }
|
| 643 |
|
| 644 | return 0;
|
| 645 | }
|
| 646 |
|
| 647 | /*****************************************
|
| 648 | * @brief:lynq_get_upgrade_status
|
| 649 | * @param count [IN]:NA
|
| 650 | * @param sum [OUT]:NA
|
| 651 | * @return :success: 0, failed:-1
|
| 652 | * @todo:NA
|
| 653 | * @see:NA
|
| 654 | * @warning:NA
|
| 655 | ******************************************/
|
| 656 | int lynq_get_upgrade_status(void)
|
| 657 | {
|
| 658 | z_upgrade_status_info_t status;
|
| 659 | int ret = 0;
|
l.yang | f8e8cf2 | 2024-01-25 15:10:22 +0800 | [diff] [blame] | 660 | int reboot_flag = -1;
|
| 661 | FILE *fp = NULL;
|
| 662 | fp = fopen(FOTA_REBOOT_FLAG,"r");
|
| 663 | if(fp == NULL)
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 664 | {
|
l.yang | f8e8cf2 | 2024-01-25 15:10:22 +0800 | [diff] [blame] | 665 | LYERRLOG("Open reboot flag file failed");
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 666 | return -1;
|
| 667 | }
|
l.yang | f8e8cf2 | 2024-01-25 15:10:22 +0800 | [diff] [blame] | 668 |
|
| 669 | fread(&reboot_flag,sizeof(int),1,fp);
|
| 670 | fclose(fp);
|
| 671 |
|
| 672 | //get upgrade status before no reboot
|
| 673 | if(reboot_flag == NO_REBOOT)
|
| 674 | {
|
| 675 |
|
| 676 | ret = zxic_dual_get_upgrade_status(&status);
|
| 677 | if(ret < 0)
|
| 678 | {
|
| 679 | LYERRLOG("Get upgrade status fail! ");
|
| 680 | return -1;
|
| 681 | }
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 682 |
|
l.yang | f8e8cf2 | 2024-01-25 15:10:22 +0800 | [diff] [blame] | 683 | LYINFLOG("Current upgrade info: ");
|
| 684 | LYINFLOG("Current upgrade status:%d ", status.upgrade_status);
|
| 685 | LYINFLOG("Current upgrade total size:%d ", status.total_size);
|
| 686 | LYINFLOG("Current upgrade updated size:%d ", status.upgraded_size);
|
| 687 |
|
| 688 | return status.upgrade_status;
|
| 689 | }
|
| 690 | else
|
| 691 | {
|
| 692 | //get sync status
|
| 693 | int fota_sync_tatus = 0;
|
| 694 | fota_sync_tatus = lynq_get_sync_status();
|
| 695 | if(fota_sync_tatus == ZXIC_SYNCHRONIZING)
|
| 696 | {
|
| 697 | LYINFLOG("Now fota upgrade sync status is synchronizing");
|
| 698 | return LYNQ_SYNNCHRONIZING;
|
| 699 | }
|
| 700 | else if(fota_sync_tatus == ZXIC_SYNC_SUCCESS)
|
| 701 | {
|
| 702 | LYINFLOG("Now fota upgrade sync status sync success ");
|
| 703 | return LYNQ_SYNC_SUCCESS;
|
| 704 | }
|
l.yang | 04a9e9c | 2024-06-04 16:51:05 +0800 | [diff] [blame] | 705 | else if(fota_sync_tatus == ZXIC_SYNC_FAILED)
|
l.yang | f8e8cf2 | 2024-01-25 15:10:22 +0800 | [diff] [blame] | 706 | {
|
| 707 | LYERRLOG("Now fota upgrade sync status sync failed ");
|
| 708 | return LYNQ_SYNC_FAILED;
|
| 709 | }
|
| 710 |
|
| 711 |
|
| 712 | }
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 713 |
|
| 714 | }
|
| 715 |
|
| 716 | /*****************************************
|
| 717 | * @brief:lynq_get_upgrade_status
|
| 718 | * @param count [IN]:NA
|
| 719 | * @param sum [OUT]:NA
|
| 720 | * @return :success: 0, failed:-1
|
| 721 | * @todo:NA
|
| 722 | * @see:NA
|
| 723 | * @warning:NA
|
| 724 | ******************************************/
|
| 725 | int lynq_get_system_info()
|
| 726 | {
|
| 727 | int ret = 0;
|
| 728 | z_upgrade_system_info_t system_info;
|
| 729 |
|
| 730 | ret = zxic_dual_get_system_status(&system_info);
|
| 731 | if(ret < 0)
|
| 732 | {
|
| 733 | LYINFLOG("Get upgrade status fail! ");
|
| 734 | return -1;
|
| 735 | }
|
| 736 | else
|
| 737 | {
|
| 738 | LYINFLOG("System info: ");
|
| 739 | LYINFLOG("Boot to:0x%08X[%d] ", system_info.boot_to, system_info.boot_to);
|
| 740 | LYINFLOG("Fota status:%d ", system_info.fota_status);
|
| 741 | LYINFLOG("System1 system:0x%08X [%d] ", system_info.system_1.system, system_info.system_1.system);
|
| 742 | LYINFLOG("System1 status:%d ", system_info.system_1.status);
|
| 743 | LYINFLOG("System1 try_cnt:%d ", system_info.system_1.try_cnt);
|
| 744 | LYINFLOG("System2 system:0x%08X [%d] ", system_info.system_2.system, system_info.system_2.system);
|
| 745 | LYINFLOG("System2 status:%d ", system_info.system_2.status);
|
| 746 | LYINFLOG("System2 try_cnt:%d ", system_info.system_2.try_cnt);
|
| 747 | }
|
| 748 |
|
| 749 | return 0;
|
| 750 |
|
| 751 | }
|
| 752 |
|
| 753 | /*****************************************
|
| 754 | * @brief:lynq_set_system_a_status
|
| 755 | * @param count [IN]:char *option_para
|
| 756 | * @param sum [OUT]:NA
|
| 757 | * @return :success: 0, failed:-1
|
| 758 | * @todo:NA
|
| 759 | * @see:NA
|
| 760 | * @warning:NA
|
| 761 | ******************************************/
|
| 762 | int lynq_set_system_a_status(char *option_para)
|
| 763 | {
|
| 764 | int ret = -1;
|
| 765 | if (NULL == option_para)
|
| 766 | {
|
| 767 | LYINFLOG("Invalid option_para value ");
|
| 768 | return -1;
|
| 769 | }
|
| 770 |
|
| 771 | //34650 A slot status : bootable:45527 unbootalbe:47806 success:23579
|
| 772 | ret = zxic_dual_set_system_status(34650, atoi(option_para));
|
| 773 | if(ret < 0)
|
| 774 | {
|
| 775 | LYINFLOG("Set system 1 status to [%s] error ", option_para);
|
| 776 | return -1;
|
| 777 | }
|
| 778 |
|
| 779 | return 0;
|
| 780 |
|
| 781 | }
|
| 782 |
|
| 783 | /*****************************************
|
| 784 | * @brief:lynq_set_system_b_status
|
| 785 | * @param count [IN]:char *option_para
|
| 786 | * @param sum [OUT]:NA
|
| 787 | * @return :success: 0, failed:-1
|
| 788 | * @todo:NA
|
| 789 | * @see:NA
|
| 790 | * @warning:NA
|
| 791 | *****************************************/
|
| 792 | int lynq_set_system_b_status(char * option_para)
|
| 793 | {
|
| 794 | int ret = -1;
|
| 795 | if (NULL == option_para)
|
| 796 | {
|
| 797 | LYINFLOG("Invalid option_para value ");
|
| 798 | return -1;
|
| 799 | }
|
| 800 |
|
| 801 | //39019 B slot status: bootable:45227 unbootalbe:47806 success:23579
|
| 802 | ret = zxic_dual_set_system_status(39019, atoi(option_para));
|
| 803 | if(ret < 0)
|
| 804 | {
|
| 805 | LYINFLOG("Set system 2 status to [%s] error ", option_para);
|
| 806 | }
|
| 807 |
|
| 808 | return 0;
|
| 809 | }
|
| 810 |
|
| 811 | /*****************************************
|
| 812 | * @brief:lynq_get_fota_status_for_nv
|
| 813 | * @param count [IN]:NA
|
| 814 | * @param sum [OUT]:NA
|
| 815 | * @return :success: 0, failed:-1
|
| 816 | * @todo:NA
|
| 817 | * @see:NA
|
| 818 | * @warning:NA
|
| 819 | *****************************************/
|
| 820 | int lynq_get_fota_status_for_nv()
|
| 821 | {
|
| 822 | int status = 0;
|
| 823 | status = zxic_dual_get_fota_status_for_nv();
|
| 824 | if(status != 0)
|
| 825 | {
|
| 826 | LYINFLOG("Fota status:%d ", status);
|
| 827 | return -1;
|
| 828 | }
|
| 829 | return 0;
|
| 830 | }
|
| 831 |
|
| 832 | /*****************************************
|
| 833 | * @brief:lynq_set_fota_status_for_nv
|
| 834 | * @param count [IN]:char *option_para
|
| 835 | * @param sum [OUT]:NA
|
| 836 | * @return :success: 0, failed:-1
|
| 837 | * @todo:NA
|
| 838 | * @see:NA
|
| 839 | * @warning:NA
|
| 840 | *****************************************/
|
| 841 | int lynq_set_fota_status_for_nv(char * option_para)
|
| 842 | {
|
| 843 | int ret = 0;
|
| 844 |
|
| 845 | if (NULL == option_para)
|
| 846 | {
|
| 847 | LYINFLOG("Invalid value! null option parameters! ");
|
| 848 | return -1;
|
| 849 | }
|
| 850 |
|
| 851 | ret = zxic_dual_set_fota_status_for_nv(atoi(option_para));
|
| 852 | if(ret < 0)
|
| 853 | {
|
| 854 | LYINFLOG("Set fota_status to [%s] error ", option_para);
|
| 855 | }
|
| 856 |
|
| 857 | return ret;
|
| 858 | }
|
| 859 |
|
| 860 | /*****************************************
|
| 861 | * @brief:lynq_sync_system
|
| 862 | * @param count [IN]:char *option_para
|
| 863 | * @param sum [OUT]:NA
|
| 864 | * @return :success: 0, failed:-1
|
| 865 | * @todo:NA
|
| 866 | * @see:NA
|
| 867 | * @warning:NA
|
| 868 | *****************************************/
|
| 869 | int lynq_sync_system()
|
| 870 | {
|
| 871 | int ret = -1;
|
| 872 |
|
| 873 | ret = zxic_dual_sync_system();
|
| 874 | if( ret != 0)
|
| 875 | {
|
| 876 | LYINFLOG("lynq sync system failed !!!!");
|
| 877 | return -1;
|
| 878 | }
|
| 879 |
|
| 880 | return 0;
|
| 881 | }
|
| 882 |
|
| 883 | /*****************************************
|
| 884 | * @brief:lynq_get_upgrade_type
|
| 885 | * @param count [IN]:NA
|
| 886 | * @param sum [OUT]:NA
|
| 887 | * @return :success: 0, failed:-1
|
| 888 | * @todo:NA
|
| 889 | * @see:NA
|
| 890 | * @warning:NA
|
| 891 | *****************************************/
|
| 892 | int lynq_get_upgrade_type()
|
| 893 | {
|
| 894 | int upgrade_type = -1;
|
| 895 |
|
| 896 | upgrade_type = zxic_dual_get_upgrade_type();
|
| 897 | if(upgrade_type < 0)
|
| 898 | {
|
| 899 | LYINFLOG("Get upgrade type failed \n");
|
| 900 | return -1;
|
| 901 | }
|
| 902 | else
|
| 903 | {
|
| 904 | LYINFLOG("upgrade type is %d", upgrade_type);
|
| 905 | }
|
| 906 | return 0;
|
| 907 | }
|
| 908 |
|
| 909 | /*****************************************
|
| 910 | * @brief:lynq_get_sync_status
|
| 911 | * @param count [IN]:char *option_para
|
| 912 | * @param sum [OUT]:NA
|
| 913 | * @return :success: 0, failed:-1
|
| 914 | * @todo:NA
|
| 915 | * @see:NA
|
| 916 | * @warning:NA
|
| 917 | *****************************************/
|
| 918 | int lynq_get_sync_status()
|
| 919 | {
|
| 920 | int sync_status = -2;
|
| 921 | zxic_dual_get_sync_status(&sync_status);
|
| 922 | LYINFLOG("Current sync status is %d", sync_status);
|
l.yang | f8e8cf2 | 2024-01-25 15:10:22 +0800 | [diff] [blame] | 923 | return sync_status;
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 924 | }
|
| 925 |
|
| 926 | /*****************************************
|
| 927 | * @brief:lynq_set_sync_status
|
| 928 | * @param count [IN]:char *option_para
|
| 929 | * @param sum [OUT]:NA
|
| 930 | * @return :success: 0, failed:-1
|
| 931 | * @todo:NA
|
| 932 | * @see:NA
|
| 933 | * @warning:NA
|
| 934 | *****************************************/
|
| 935 | int lynq_set_sync_status(char * option_para)
|
| 936 | {
|
| 937 | int ret = 0;
|
| 938 |
|
| 939 | if (NULL == option_para)
|
| 940 | {
|
| 941 | LYINFLOG("Command input invalid value! null option parameters! ");
|
| 942 | return -1;
|
| 943 | }
|
| 944 |
|
| 945 | ret = zxic_dual_set_sync_status(atoi(option_para));
|
| 946 | if (0 != ret)
|
| 947 | {
|
| 948 | LYINFLOG("set sync status fail");
|
| 949 | return -1;
|
| 950 | }
|
| 951 |
|
| 952 | return 0;
|
| 953 | }
|
| 954 |
|
l.yang | f8e8cf2 | 2024-01-25 15:10:22 +0800 | [diff] [blame] | 955 | /*****************************************
|
| 956 | * @brief:lynq_read_process
|
| 957 | * @param count [IN]:NS
|
| 958 | * @param sum [OUT]:NA
|
| 959 | * @return :fota upgrade process 0-10
|
| 960 | * @todo:NA
|
| 961 | * @see:NA
|
| 962 | * @warning:NA
|
| 963 | *****************************************/
|
| 964 | int lynq_read_process(void)
|
| 965 | {
|
| 966 | LYINFLOG("Enter lynq_read_process");
|
| 967 |
|
| 968 | float fota_process = 0;
|
| 969 | int ration = 0;
|
| 970 | int read_count = 0;
|
| 971 | FILE *fp = NULL;
|
| 972 |
|
| 973 | while(1)
|
| 974 | {
|
| 975 |
|
| 976 | fp = fopen(FOTA_UPGRADE_PROCESS, "r");
|
| 977 | if(fp == NULL)
|
| 978 | {
|
| 979 | LYERRLOG("lynq_read_process open file failed");
|
| 980 | usleep(10000);
|
| 981 | read_count++;
|
| 982 | if(read_count > 5)
|
| 983 | {
|
| 984 | break;
|
| 985 | }
|
| 986 | }
|
| 987 | else
|
| 988 | {
|
| 989 | break;
|
| 990 | }
|
| 991 | }
|
| 992 |
|
| 993 | if(fp != NULL)
|
| 994 | {
|
| 995 |
|
| 996 | char line[256] = {0};
|
| 997 | if (fgets(line, sizeof(line), fp) != NULL)
|
| 998 | {
|
| 999 | sscanf(line, "%d,%d", &total_size, &upgrade_size);
|
| 1000 | }
|
| 1001 | fclose(fp);
|
| 1002 | }
|
| 1003 |
|
| 1004 |
|
| 1005 | if(total_size != 0 && upgrade_size <= total_size)
|
| 1006 | {
|
| 1007 | LYINFLOG("Caculate fota process ration ");
|
| 1008 | fota_process = (float) upgrade_size / total_size;
|
| 1009 | }
|
| 1010 |
|
| 1011 | ration = (int)(fota_process * 10);
|
| 1012 | LYINFLOG("Fota process ration is %d",ration);
|
| 1013 | return ration;
|
| 1014 | }
|
| 1015 |
|
l.yang | 526ef68 | 2024-07-15 17:46:51 +0800 | [diff] [blame] | 1016 | int calculate_md5_sum( char *md5_sum,int md5_size)
|
| 1017 | {
|
| 1018 | FILE *fp = NULL;
|
| 1019 | char package_path[256] = {0};
|
| 1020 | char command[64] = {0};
|
| 1021 | char *space_pos = NULL;
|
| 1022 | int length = 0;
|
| 1023 | char command_result[64] = {0};
|
| 1024 |
|
| 1025 | fp = fopen(FOTA_ADDR_FILE, "rb");
|
| 1026 | if(fp == NULL)
|
| 1027 | {
|
| 1028 | LYERRLOG("Open file failed", FOTA_ADDR_FILE);
|
| 1029 | return -1;
|
| 1030 | }
|
| 1031 | if(fgets(package_path, sizeof(package_path), fp) == NULL)
|
| 1032 | {
|
| 1033 | LYERRLOG("Read file %s failed", package_path);
|
| 1034 | }
|
| 1035 | fclose(fp);
|
| 1036 |
|
| 1037 | snprintf(command, sizeof(command), "md5sum %s",package_path);
|
| 1038 |
|
| 1039 | fp = popen(command, "r");
|
| 1040 | if (fp == NULL)
|
| 1041 | {
|
| 1042 | LYERRLOG("Failed to run command\n");
|
| 1043 | return -1;
|
| 1044 | }
|
| 1045 | if (fgets(command_result, sizeof(command_result), fp) != NULL)
|
| 1046 | {
|
| 1047 |
|
| 1048 | space_pos = strchr(command_result, ' ');
|
| 1049 | if (space_pos != NULL)
|
| 1050 | {
|
| 1051 | length = space_pos - command_result;
|
| 1052 | if(length >= md5_size)
|
| 1053 | {
|
| 1054 | pclose(fp);
|
| 1055 | return -1;
|
| 1056 | }
|
| 1057 | strncpy(md5_sum, command_result, length);
|
| 1058 | md5_sum[length] = '\0';
|
| 1059 | }
|
| 1060 | }
|
| 1061 |
|
| 1062 | pclose(fp);
|
| 1063 |
|
| 1064 | return 0;
|
| 1065 |
|
| 1066 | }
|
| 1067 |
|
you.chen | 21c62b7 | 2023-09-08 09:41:11 +0800 | [diff] [blame] | 1068 | DEFINE_LYNQ_LIB_LOG(LYNQ_FOTA)
|
l.yang | 7d7b51c | 2023-08-04 17:02:48 +0800 | [diff] [blame] | 1069 |
|
| 1070 | #ifdef __cplusplus
|
| 1071 | }
|
| 1072 | #endif
|