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