[Feature][ZXW-130]merge P50U02 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: I4f29ec5bb7c59385f23738d2b7ca84e67c100f69
diff --git a/ap/app/nvro_tool/Makefile b/ap/app/nvro_tool/Makefile
new file mode 100755
index 0000000..3582a63
--- /dev/null
+++ b/ap/app/nvro_tool/Makefile
@@ -0,0 +1,36 @@
+#*******************************************************************************
+# include build/common makefile
+#*******************************************************************************
+include $(COMMON_MK)
+
+##############USER COMIZE BEGIN################
+EXEC    = nvro_tool
+OBJS    = main.o 
+
+CFLAGS += -I$(APP_DIR)/include
+CFLAGS += -I$(LIB_DIR)/libcpnv
+CFLAGS += -g -Werror=implicit-function-declaration
+
+LDLIBS = -lcpnv -L$(LIB_DIR)/libcpnv
+LDLIBS += -lnvram_sc -L$(LIB_DIR)/libnvram
+LDLIBS += -lflags -L$(LIB_DIR)/libflags
+LDLIBS += -lcrypto -L$(LIB_DIR)/libssl/install/lib
+
+##############USER COMIZE END##################
+
+#*******************************************************************************
+# targets
+#*******************************************************************************
+EXECS = $(EXEC)
+all: $(EXECS)
+
+$(EXEC): $(OBJS)
+	$(CC) $(LDFLAGS) -o $@ $^ -Wl,--start-group $(LDLIBS) $(LDLIBS_$@) -Wl,--end-group
+	@cp $@ $@.elf
+
+romfs:
+	$(ROMFSINST) $(EXEC) /bin/$(EXEC)
+
+clean:
+	-rm -f $(EXEC) *.elf *.gdb *.o
+
diff --git a/ap/app/nvro_tool/main.c b/ap/app/nvro_tool/main.c
new file mode 100755
index 0000000..681e236
--- /dev/null
+++ b/ap/app/nvro_tool/main.c
@@ -0,0 +1,69 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "libcpnv.h"
+#include "flags_api.h"
+
+int main(int argc, char *argv[])
+{
+    unsigned int nvro_flag;
+    int ret;
+
+    if (argc == 1)
+    {
+        printf("%s backup\n", argv[0]);
+        printf("%s restore\n", argv[0]);
+        printf("%s check\n", argv[0]);
+        return -1;
+    }
+    if (argc > 1 && (strcmp("backup", argv[1])==0))
+    {
+        if (cpnv_NvroBackup() == CPNV_OK)
+        {
+            printf("cpnv_NvroBackup success\n");
+            return 0;
+        }
+        else
+        {
+            printf("cpnv_NvroBackup fail\n");
+            return -1;
+        }
+    }
+    if (argc > 1 && (strcmp("restore", argv[1])==0))
+    {
+        ret = flags_set_nvroflag(NVRO_RESTORING);
+        if (ret != 0)
+        {
+            printf("[error]nvro_tool set NVRO_RESTORING\n");
+            return -1;
+        }
+        else
+        {
+            printf("nvro_tool set NVRO_RESTORING success\n");
+            return 0;
+        }
+
+    }
+    if (argc > 1 && (strcmp("check", argv[1])==0))
+    {
+        nvro_flag = flags_get_nvroflag();
+        if (nvro_flag != NVRO_RESTORING)
+        {
+            printf("nvro_tool restore check and do nothing:%08x\n", nvro_flag);
+            return 0;
+        }
+        if (cpnv_NvroRestore() == CPNV_OK)
+        {
+            printf("cpnv_NvroRestore success\n");
+            return 0;
+        }
+        else
+        {
+            printf("cpnv_NvroRestore fail\n");
+            return -1;
+        }
+    }
+
+    return -1;
+}
+