xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame^] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <string.h> |
| 4 | #include "libcpnv.h" |
| 5 | #include "flags_api.h" |
| 6 | |
| 7 | int main(int argc, char *argv[]) |
| 8 | { |
| 9 | unsigned int nvro_flag; |
| 10 | int ret; |
| 11 | |
| 12 | if (argc == 1) |
| 13 | { |
| 14 | printf("%s backup\n", argv[0]); |
| 15 | printf("%s restore\n", argv[0]); |
| 16 | printf("%s check\n", argv[0]); |
| 17 | return -1; |
| 18 | } |
| 19 | if (argc > 1 && (strcmp("backup", argv[1])==0)) |
| 20 | { |
| 21 | if (cpnv_NvroBackup() == CPNV_OK) |
| 22 | { |
| 23 | printf("cpnv_NvroBackup success\n"); |
| 24 | return 0; |
| 25 | } |
| 26 | else |
| 27 | { |
| 28 | printf("cpnv_NvroBackup fail\n"); |
| 29 | return -1; |
| 30 | } |
| 31 | } |
| 32 | if (argc > 1 && (strcmp("restore", argv[1])==0)) |
| 33 | { |
| 34 | ret = flags_set_nvroflag(NVRO_RESTORING); |
| 35 | if (ret != 0) |
| 36 | { |
| 37 | printf("[error]nvro_tool set NVRO_RESTORING\n"); |
| 38 | return -1; |
| 39 | } |
| 40 | else |
| 41 | { |
| 42 | printf("nvro_tool set NVRO_RESTORING success\n"); |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | } |
| 47 | if (argc > 1 && (strcmp("check", argv[1])==0)) |
| 48 | { |
| 49 | nvro_flag = flags_get_nvroflag(); |
| 50 | if (nvro_flag != NVRO_RESTORING) |
| 51 | { |
| 52 | printf("nvro_tool restore check and do nothing:%08x\n", nvro_flag); |
| 53 | return 0; |
| 54 | } |
| 55 | if (cpnv_NvroRestore() == CPNV_OK) |
| 56 | { |
| 57 | printf("cpnv_NvroRestore success\n"); |
| 58 | return 0; |
| 59 | } |
| 60 | else |
| 61 | { |
| 62 | printf("cpnv_NvroRestore fail\n"); |
| 63 | return -1; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | return -1; |
| 68 | } |
| 69 | |