| #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]); |
| printf("%s getflag\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; |
| } |
| } |
| if (argc > 1 && (strcmp("getflag", argv[1])==0)) |
| { |
| nvro_flag = flags_get_nvroflag(); |
| switch (nvro_flag) |
| { |
| case NVRO_INIT: |
| printf("nvro_flag init:%08x\n", nvro_flag); |
| break; |
| case NVRO_BACKED_UP: |
| printf("nvro_flag backed up:%08x\n", nvro_flag); |
| break; |
| case NVRO_RESTORING: |
| printf("nvro_flag restoring:%08x\n", nvro_flag); |
| break; |
| default: |
| printf("nvro_flag invalid:%08x\n", nvro_flag); |
| break; |
| } |
| return 0; |
| } |
| |
| return -1; |
| } |
| |