[Feature][ZXW-313] Save fota package md5 value,delete package size in the maintenance log
Only Configure:No
Affected branch:master
Affected module:fota
Is it affected on both ZXIC and MTK: ZXIC
Self-test: Yes
Doc Update: No
Change-Id: Ie8ba7345e142d93e52910ae58718a963925019a7
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 1589c5f..811e7e7 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
@@ -123,7 +123,7 @@
int lynq_get_upgrade_type();
int lynq_get_sync_status();
int lynq_set_sync_status(char *option_para);
-
+int calculate_md5_sum( char *md5_sum,int md5_size);
/*****************************************
* @brief:rock_update_main
@@ -145,6 +145,7 @@
time_t endTime;
struct tm *localTime;
double elapsed = 0;
+ char md5_sum[48] = {0};
FILE *fp = NULL;
fp = fopen(FOTA_FLAG_FILE,"w+");
@@ -192,6 +193,12 @@
return -1;
}
+ ret = calculate_md5_sum(md5_sum,sizeof(md5_sum));
+ if(ret != 0)
+ {
+ LYINFLOG("Calculate md5 sum failed");
+ }
+
startTime = time(NULL);
if(startTime == (time_t)-1)
{
@@ -211,7 +218,7 @@
if(ret != 0)
{
LYERRLOG("Upgrade failed");
- ret = sc_debug_info_record(MODULE_ID_CAP_FOTA,"failed,spendtime: %.2lf seconds,package size:%d,finished time %s", elapsed,total_size,asctime(localTime));
+ ret = sc_debug_info_record(MODULE_ID_CAP_FOTA,"failed,spendtime: %.2lf seconds,finished time %s,md5:%s", elapsed,asctime(localTime),md5_sum);
if(ret <= 0)
{
LYERRLOG("lynq_record_debug_info failed");
@@ -221,7 +228,7 @@
else
{
LYINFLOG("Upgrade success");
- ret = sc_debug_info_record(MODULE_ID_CAP_FOTA,"success,spendtime: %.2lf seconds,package size:%d,finished time %s", elapsed,total_size,asctime(localTime));
+ ret = sc_debug_info_record(MODULE_ID_CAP_FOTA,"success,spendtime: %.2lf seconds,finished time %s,md5:%s", elapsed,asctime(localTime),md5_sum);
if(ret <= 0)
{
LYERRLOG("lynq_record_debug_info failed");
@@ -1006,6 +1013,58 @@
return ration;
}
+int calculate_md5_sum( char *md5_sum,int md5_size)
+{
+ FILE *fp = NULL;
+ char package_path[256] = {0};
+ char command[64] = {0};
+ char *space_pos = NULL;
+ int length = 0;
+ char command_result[64] = {0};
+
+ fp = fopen(FOTA_ADDR_FILE, "rb");
+ if(fp == NULL)
+ {
+ LYERRLOG("Open file failed", FOTA_ADDR_FILE);
+ return -1;
+ }
+ if(fgets(package_path, sizeof(package_path), fp) == NULL)
+ {
+ LYERRLOG("Read file %s failed", package_path);
+ }
+ fclose(fp);
+
+ snprintf(command, sizeof(command), "md5sum %s",package_path);
+
+ fp = popen(command, "r");
+ if (fp == NULL)
+ {
+ LYERRLOG("Failed to run command\n");
+ return -1;
+ }
+ if (fgets(command_result, sizeof(command_result), fp) != NULL)
+ {
+
+ space_pos = strchr(command_result, ' ');
+ if (space_pos != NULL)
+ {
+ length = space_pos - command_result;
+ if(length >= md5_size)
+ {
+ pclose(fp);
+ return -1;
+ }
+ strncpy(md5_sum, command_result, length);
+ md5_sum[length] = '\0';
+ }
+ }
+
+ pclose(fp);
+
+ return 0;
+
+}
+
DEFINE_LYNQ_LIB_LOG(LYNQ_FOTA)
#ifdef __cplusplus