Annotation of embedtools/src/updimg.c, revision 1.1.2.4
1.1.2.1 misho 1: #include "global.h"
1.1.2.2 misho 2: #include "upd.h"
1.1.2.1 misho 3:
4:
5: sl_config cfg;
6: int Verbose, Mode;
7: extern char compiled[], compiledby[], compilehost[];
8:
9:
10: static void Usage()
11: {
12: printf( " Update Image tool for embedded systems on CompactFlash\n"
13: "=== %s === %s@%s ===\n\n"
14: " Syntax: updimg [-v] <modes> <image_name> [operate_dir]\n\n"
15: "\t-v\t\tVerbose ...\n\n"
16: "\t-a\t\tMake image active for next boot\n"
1.1.2.4 ! misho 17: "\t-i <tftp_dir>\tInstall new image\n"
1.1.2.1 misho 18: "\t-r\t\tRollback old backuped image\n"
1.1.2.3 misho 19: "\t-t <tftp_dir>\tExport for TFTP download\n"
1.1.2.1 misho 20: "\t-b\t\tBackup image\n"
21: "\t-d\t\tClean backuped image\n"
22: "\n", compiled, compiledby, compilehost);
23: }
24:
25: // -----------------------------------
26:
27: int main(int argc, char **argv)
28: {
1.1.2.3 misho 29: char ch, szImg[MAXPATHLEN], szTFTP[MAXPATHLEN];
1.1.2.1 misho 30: int mode;
31:
1.1.2.4 ! misho 32: while ((ch = getopt(argc, argv, "hvdbt:ai:r")) != -1)
1.1.2.1 misho 33: switch (ch) {
34: case 'a':
35: Mode |= 0x1;
36: break;
37: case 't':
38: Mode |= 0x8;
1.1.2.3 misho 39: strlcpy(szTFTP, optarg, MAXPATHLEN);
1.1.2.1 misho 40: break;
41: case 'r':
1.1.2.4 ! misho 42: if (Mode & 0x10) {
1.1.2.1 misho 43: printf("Error:: can`t set rollback mode because find set install ...\n");
44: return 1;
45: } else
1.1.2.4 ! misho 46: Mode |= 0x20;
1.1.2.1 misho 47: break;
48: case 'i':
1.1.2.4 ! misho 49: if (Mode & 0x20) {
1.1.2.1 misho 50: printf("Error:: can`t set install mode because find set rollback ...\n");
51: return 1;
52: } else
1.1.2.4 ! misho 53: Mode |= 0x10;
! 54: strlcpy(szTFTP, optarg, MAXPATHLEN);
1.1.2.1 misho 55: break;
56: case 'b':
1.1.2.4 ! misho 57: if (Mode & 0x4) {
1.1.2.1 misho 58: printf("Error:: can`t set backup mode because find set clean ...\n");
59: return 1;
60: } else
1.1.2.4 ! misho 61: Mode |= 0x2;
1.1.2.1 misho 62: break;
63: case 'd':
1.1.2.4 ! misho 64: if (Mode & 0x2) {
1.1.2.1 misho 65: printf("Error:: can`t set clean mode because find set backup ...\n");
66: return 1;
67: } else
1.1.2.4 ! misho 68: Mode |= 0x4;
1.1.2.1 misho 69: break;
70: case 'v':
71: Verbose++;
72: break;
73: case 'h':
74: default:
75: Usage();
76: return 1;
77: }
78: argc -= optind;
79: argv += optind;
80: if (!Mode) {
81: printf("Error:: Mode not specified !!!\n\n");
82: Usage();
83: return 1;
84: }
85: if (!argc) {
86: printf("Error:: Image filename not specified !!!\n\n");
87: Usage();
88: return 1;
89: } else
1.1.2.2 misho 90: basename_r(*argv, szImg);
1.1.2.1 misho 91: if (argc > 1) {
1.1.2.2 misho 92: chdir(argv[1]);
93: VERB(5) printf("Info(5):: Change to dir %s\n", argv[1]);
1.1.2.1 misho 94: }
95:
96: openlog("updimg", LOG_CONS, 0);
1.1.2.2 misho 97:
1.1.2.1 misho 98: for (mode = 0x20; mode; mode >>= 1)
99: switch (Mode & mode) {
100: case 0x1:
1.1.2.2 misho 101: Activate(szImg);
1.1.2.1 misho 102: break;
103: case 0x2:
1.1.2.4 ! misho 104: Backup(szImg, NULL);
1.1.2.1 misho 105: break;
106: case 0x4:
1.1.2.4 ! misho 107: Clean(szImg);
1.1.2.1 misho 108: break;
109: case 0x8:
1.1.2.3 misho 110: tFTP(szImg, szTFTP);
1.1.2.1 misho 111: break;
112: case 0x10:
1.1.2.4 ! misho 113: Install(szImg, szTFTP);
1.1.2.1 misho 114: break;
115: case 0x20:
1.1.2.4 ! misho 116: Rollback(szImg);
1.1.2.1 misho 117: break;
118: }
119:
120: closelog();
121: return 0;
122: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>