-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.cpp
56 lines (45 loc) · 1.21 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <string>
#include "usbprogrammer.h"
#include "devicemanager.h"
#include "flash.h"
using namespace std;
void usage(char* prog)
{
cout << "Usage: " << prog << " <action> <filename>" << endl;
cout << "Action can be:" << endl;
cout << " dump - dump firmware from device" << endl;
cout << " flash - flash new firmware to device" << endl;
}
int main(int argc, char **argv) {
DeviceManager manager;
Flash flash;
if(argc != 3) {
usage(argv[0]);
return 0;
}
string action = argv[1];
if(action != "dump" && action != "flash") {
cout << "Invalid action!" << endl;
usage(argv[0]);
return 0;
}
if(!UsbProgrammer::getProgrammer()->IsInitialized()) {
cout << "Cannot connect to programmer!" << endl;
return 1;
}
if(!manager.IsSupported()) {
cout << "Device is NOT supported!" << endl;
return 1;
}
if(action == "dump") {
if(!flash.dump(argv[2])) {
cout << "Dumping failed!" << endl;
return 1;
}
} else if(action == "flash"){
cout << "Action currently not supported!" << endl;
}
manager.XapResetAndGo();
return 0;
}