[Feature][ZXW-136]merge P50U04 version

Only Configure: No
Affected branch: master
Affected module: unknow
Is it affected on both ZXIC and MTK: only ZXIC
Self-test: Yes
Doc Update: No

Change-Id: I7b6a8e22777591bc7a9ede91d6695d9415116f81
diff --git a/ap/lib/libcpnv/nvro.c b/ap/lib/libcpnv/nvro.c
index 0e5880c..d65b151 100755
--- a/ap/lib/libcpnv/nvro.c
+++ b/ap/lib/libcpnv/nvro.c
@@ -161,7 +161,10 @@
         return -1;
     buf = malloc(4096);
     if (buf == NULL)
+    {
+        close(fd);
         return -1;
+    }
     MD5_Init(&ctx);
     do
     {
@@ -173,6 +176,7 @@
 
     MD5_Final(hash_value, &ctx);
     free(buf);
+    close(fd);
     return 0;
 }
 
@@ -233,13 +237,17 @@
         printf("[error]cpnv erase nvrofs2\n");
         return CPNV_ERROR;
     }
-    
-    nvrofs2_umount();
+
     ret = nvrofs2_mount(1);
     if (ret != 0)
     {
-        printf("[error]cpnv nvrofs2_mount\n");
-        return CPNV_ERROR;
+        nvrofs2_umount();
+        ret = nvrofs2_mount(1);
+        if (ret != 0)
+        {
+            printf("[error]cpnv nvrofs2_mount\n");
+            return CPNV_ERROR;
+        }
     }
     ret = copyfile("/mnt/nvrofs/nvroall.bin", "/mnt/nvrofs2/nvroall.bin");
     if (ret != 0)
@@ -333,6 +341,7 @@
 
 out_err:
     nvrofs2_umount();
+    flags_set_nvroflag(NVRO_BACKED_UP);
 
     return CPNV_ERROR;
 }