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