Merge "[Feature][T106] Optimize partition damage recovery logic"
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-fota-backup/files/lynq-fota-backup.cpp b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-fota-backup/files/lynq-fota-backup.cpp
index 23bb8e4..5fff5eb 100755
--- a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-fota-backup/files/lynq-fota-backup.cpp
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-fota-backup/files/lynq-fota-backup.cpp
@@ -32,6 +32,7 @@
 #define FOTA_SYNC_FLAG    1

 #define FOTA_CURRENT_SYS  "/mnt/userdata/.fota_current_sys"

 

+#define USER_LOG_TAG "LYNQ_FOTA_BACKUP"

 

 extern int lynq_sync_system();

 extern int lynq_fota_get_addr_value(char *tmp_value);

@@ -49,7 +50,7 @@
     fp = fopen(FOTA_REBOOT_FLAG,"w+");

     if(fp == NULL)

     {

-        printf("Open reboot flag file failed\n");

+        LYERRLOG("Open reboot flag file failed\n");

         return;

     }

     

@@ -70,33 +71,34 @@
     //not fota 

     if(access(FOTA_FLAG_FILE, F_OK) == -1)

     {

-        printf("Fota flag file no exist\n");

+        LYINFLOG("Fota flag file no exist\n");

 

         //file no exist,get current sys write to file

         if(access(FOTA_CURRENT_SYS,F_OK) == -1)

         {

-            printf("Record current sys file no exist\n");

+            LYINFLOG("Record current sys file no exist\n");

             

             fp = fopen(FOTA_CURRENT_SYS,"w");

             if(fp == NULL)

              {

-                printf("creat  record current file failed\n");

+                LYERRLOG("creat  record current file failed\n");

                 return -1;

             }

             current_sys = lynq_get_current_system();

             if(current_sys < 0)

             {

-                printf("Get current system failed %d\n",current_sys);

+                LYERRLOG("Get current system failed %d\n",current_sys);

                 fclose(fp);

                 return -1;

             }

             else

             {

                 

-                printf("Get current system success  %d\n",current_sys);

+                LYINFLOG("Get current system success  %d\n",current_sys);

                 fprintf(fp, "%d", current_sys);

-                system("sync");

                 fclose(fp);

+                system("sync");

+                

                 return 0;

             }

         }

@@ -105,16 +107,16 @@
             current_sys = lynq_get_current_system();

             if(current_sys < 0)

             {

-                printf("Get current system failed %d\n",current_sys);

+                LYERRLOG("Get current system failed %d\n",current_sys);

                 return -1;

             }

 

-            printf("Get current system success  %d\n",current_sys);

+            LYINFLOG("Get current system success  %d\n",current_sys);

             

             fp = fopen(FOTA_CURRENT_SYS,"r");

             if(fp == NULL)

             {

-                printf("read file failed \n");

+                LYERRLOG("read file failed \n");

                 return -1;

             }

         

@@ -124,37 +126,39 @@
             }

             else

             {

-                printf("tmp_sys is NULL");

+                LYERRLOG("tmp_sys is NULL");

                 fclose(fp);

                 return -1;

             }

             

             if( record_sys == current_sys)

             {

-                printf("System not need sync \n");

+                LYINFLOG("System not need sync \n");

                 fclose(fp);

                 return 0;

             }

             else 

             {

-                fp = fopen(FOTA_CURRENT_SYS,"w");

-                if(fp == NULL)

-                {

-                    printf("creat file failed  \n");

-                    return -1;

-                }

-                

-                printf("System need sync \n");

-                fprintf(fp,"%d",current_sys);

-                system("sync");

-                fclose(fp);

+                LYINFLOG("System need sync \n");

                 ret = lynq_sync_system();

                 if(ret < 0 )

                 {

-                    printf("A/B sync system failed \n");

+                    LYERRLOG("A/B sync system failed \n");

                     return -1;

                 }

-                printf("A/B sync system success \n");

+                LYINFLOG("A/B sync system success,record current sys \n");

+                fp = fopen(FOTA_CURRENT_SYS,"w");

+                if(fp == NULL)

+                {

+                    LYERRLOG("creat file failed  \n");

+                    return -1;

+                }

+                

+                fprintf(fp,"%d",current_sys);

+                fclose(fp);

+                system("sync");

+                

+                

                 return 0;

             }

         }

@@ -166,20 +170,20 @@
         fp = fopen(FOTA_CURRENT_SYS,"w");

         if(fp == NULL)

         {

-            printf("Creat file failed \n");

+            LYERRLOG("Creat file failed \n");

             return -1;

         }

-        printf("fota flag file exist,record current sys \n");

+        LYINFLOG("fota flag file exist,record current sys \n");

         current_sys = lynq_get_current_system();

         if(current_sys < 0)

         {

-            printf("Get current system failed %d\n",current_sys);

+            LYERRLOG("Get current system failed %d\n",current_sys);

             return -1;

         }

         

         fprintf(fp,"%d",current_sys);

-        system("sync");

         fclose(fp);

+        system("sync");

         return 0;

     }

            

@@ -198,7 +202,7 @@
     fp = fopen(FOTA_FLAG_FILE,"r");

     if(fp == NULL)

     {

-        printf("No need fota sync\n");

+        LYERRLOG("No need fota sync\n");

         return -1;

 

     }

@@ -213,7 +217,7 @@
         ret = lynq_sync_system();

         if(ret != 0)

         {

-            printf("sync faild\n");

+            LYERRLOG("sync faild\n");

         }

        system("rm -rf /mnt/userdata/.back_up_flag");

         

@@ -223,20 +227,20 @@
         ret = lynq_fota_get_addr_value(tmp_addr);

         if(ret != 0)

         {

-            printf("Get addr failed\n");

+            LYERRLOG("Get addr failed\n");

             return -1;

         }

-        printf("tmp_addr is %s\n",tmp_addr);

+        LYINFLOG("tmp_addr is %s\n",tmp_addr);

         ret = lynq_fota_set_addr_value(tmp_addr,10);

         if(ret != 0)

         {

-            printf("Set addr failed\n");

+            LYERRLOG("Set addr failed\n");

             return -1;

         }

         ret = lynq_fota_nrestart();

         if(ret != 0)

         {

-            printf("Upgrade failed\n");

+            LYERRLOG("Upgrade failed\n");

             return -1;

         }

         

@@ -245,6 +249,7 @@
     return 0;

 

 }

+DEFINE_LYNQ_LIB_LOG(LYNQ_FOTA_BACKUP)

 

 #ifdef __cplusplus

 }