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