[Feature][ZXW-204][ZXW-205] add query fota upgrade process api and backup Status
Only Configure: No
Affected branch: master
Affected module: Fota
Is it affected on both ZXIC and MTK:only zxic
Self-test: Yes
Doc Update:Yes
Change-Id: I2546527d92a356a85d60d1cd763b9b462c458e3c
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-fota/lynq-qser-fota.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-qser-fota/lynq-qser-fota.cpp
index 53ee3c8..5dab391 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-qser-fota/lynq-qser-fota.cpp
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-fota/lynq-qser-fota.cpp
@@ -28,12 +28,13 @@
#include "include/lynq-qser-fota.h"
#include "liblog/lynq_deflog.h"
-#define FOTA_FLAG_FILE "/mnt/userdata/.back_up_flag"
+#define FOTA_REBOOT_FLAG "/mnt/userdata/.fota_reboot_flag"
+#define FOTA_FLAG_FILE "/mnt/userdata/.back_up_flag"
#define USER_LOG_TAG "LYNQ_FOTA"
#define FOTA_ADDR_FILE "/mnt/userdata/.addr_value"
#define FOTA_FILE_NAME "upgrade.package"
-
+#define FOTA_UPGRADE_PROCESS "/mnt/userdata/.fota_upgrade_process"
#define SYSTEM_A "34650"
#define SYSTEM_B "39019"
@@ -49,6 +50,18 @@
#define LYNQ_UPGRADE_STATUS_UPDATE_SUCCESS (4)
#define LYNQ_UPGRADE_STATUS_UPDATE_FAIL (5)
+#define LYNQ_SYNNCHRONIZING 8
+#define LYNQ_SYNC_SUCCESS 9
+#define LYNQ_SYNC_FAILED -1
+
+#define ZXIC_SYNCHRONIZING 1
+#define ZXIC_SYNC_SUCCESS 0
+
+#define NO_REBOOT 0
+
+
+int total_size = 0;
+int upgrade_size = 0;
typedef struct
{
@@ -122,6 +135,7 @@
int ret = 0;
int current_slot = 0;
int fota_sync_flag = 0;
+ int reboot_flg = NO_REBOOT;
FILE *fp = NULL;
fp = fopen(FOTA_FLAG_FILE,"w+");
if(fp == NULL)
@@ -134,6 +148,17 @@
/* T106BUG-189 fix */
system("sync");
+
+ fp =fopen(FOTA_REBOOT_FLAG,"w+");
+ if(fp == NULL)
+ {
+ LYERRLOG("Creaf get upgrade status flag failed");
+ return -1;
+ }
+
+ fwrite(&reboot_flg,sizeof(int),1,fp);
+ fclose(fp);
+ system("sync");
ret = lynq_fota_verify();
if(ret != 0)
@@ -233,7 +258,20 @@
LYINFLOG("Total size:%d ", p_status->total_size);
LYINFLOG("Updated size:%d ", p_status->upgraded_size);
- return ;
+
+ total_size = p_status->total_size;
+ upgrade_size = p_status->upgraded_size;
+
+ FILE *fp = NULL;
+ fp = fopen(FOTA_UPGRADE_PROCESS,"w");
+ if (fp == NULL)
+ {
+ LYERRLOG("Error opening file");
+ return;
+ }
+
+ fprintf(fp, "%d,%d\n", total_size, upgrade_size);
+ fclose(fp);
}
/*****************************************
@@ -528,21 +566,59 @@
{
z_upgrade_status_info_t status;
int ret = 0;
-
-
- ret = zxic_dual_get_upgrade_status(&status);
- if(ret < 0)
+ int reboot_flag = -1;
+ FILE *fp = NULL;
+ fp = fopen(FOTA_REBOOT_FLAG,"r");
+ if(fp == NULL)
{
- LYINFLOG("Get upgrade status fail! ");
+ LYERRLOG("Open reboot flag file failed");
return -1;
}
+
+ fread(&reboot_flag,sizeof(int),1,fp);
+ fclose(fp);
+
+ //get upgrade status before no reboot
+ if(reboot_flag == NO_REBOOT)
+ {
+
+ ret = zxic_dual_get_upgrade_status(&status);
+ if(ret < 0)
+ {
+ LYERRLOG("Get upgrade status fail! ");
+ return -1;
+ }
- LYINFLOG("Current upgrade info: ");
- LYINFLOG("Current upgrade status:%d ", status.upgrade_status);
- LYINFLOG("Current upgrade total size:%d ", status.total_size);
- LYINFLOG("Current upgrade updated size:%d ", status.upgraded_size);
-
- return status.upgrade_status;
+ LYINFLOG("Current upgrade info: ");
+ LYINFLOG("Current upgrade status:%d ", status.upgrade_status);
+ LYINFLOG("Current upgrade total size:%d ", status.total_size);
+ LYINFLOG("Current upgrade updated size:%d ", status.upgraded_size);
+
+ return status.upgrade_status;
+ }
+ else
+ {
+ //get sync status
+ int fota_sync_tatus = 0;
+ fota_sync_tatus = lynq_get_sync_status();
+ if(fota_sync_tatus == ZXIC_SYNCHRONIZING)
+ {
+ LYINFLOG("Now fota upgrade sync status is synchronizing");
+ return LYNQ_SYNNCHRONIZING;
+ }
+ else if(fota_sync_tatus == ZXIC_SYNC_SUCCESS)
+ {
+ LYINFLOG("Now fota upgrade sync status sync success ");
+ return LYNQ_SYNC_SUCCESS;
+ }
+ else if(fota_sync_tatus == LYNQ_SYNC_FAILED)
+ {
+ LYERRLOG("Now fota upgrade sync status sync failed ");
+ return LYNQ_SYNC_FAILED;
+ }
+
+
+ }
}
@@ -753,7 +829,7 @@
int sync_status = -2;
zxic_dual_get_sync_status(&sync_status);
LYINFLOG("Current sync status is %d", sync_status);
- return 0;
+ return sync_status;
}
/*****************************************
@@ -785,6 +861,67 @@
return 0;
}
+/*****************************************
+* @brief:lynq_read_process
+* @param count [IN]:NS
+* @param sum [OUT]:NA
+* @return :fota upgrade process 0-10
+* @todo:NA
+* @see:NA
+* @warning:NA
+*****************************************/
+int lynq_read_process(void)
+{
+ LYINFLOG("Enter lynq_read_process");
+
+ float fota_process = 0;
+ int ration = 0;
+ int read_count = 0;
+ FILE *fp = NULL;
+
+ while(1)
+ {
+
+ fp = fopen(FOTA_UPGRADE_PROCESS, "r");
+ if(fp == NULL)
+ {
+ LYERRLOG("lynq_read_process open file failed");
+ usleep(10000);
+ read_count++;
+ if(read_count > 5)
+ {
+ break;
+ }
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ if(fp != NULL)
+ {
+
+ char line[256] = {0};
+ if (fgets(line, sizeof(line), fp) != NULL)
+ {
+ sscanf(line, "%d,%d", &total_size, &upgrade_size);
+ }
+ fclose(fp);
+ }
+
+
+ if(total_size != 0 && upgrade_size <= total_size)
+ {
+ LYINFLOG("Caculate fota process ration ");
+ fota_process = (float) upgrade_size / total_size;
+ }
+
+ ration = (int)(fota_process * 10);
+ LYINFLOG("Fota process ration is %d",ration);
+ return ration;
+}
+
DEFINE_LYNQ_LIB_LOG(LYNQ_FOTA)
#ifdef __cplusplus