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