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