]>
Commit | Line | Data |
---|---|---|
1 | //----------------------------------------------------------------------------- | |
2 | // This code is licensed to you under the terms of the GNU GPL, version 2 or, | |
3 | // at your option, any later version. See the LICENSE.txt file for the text of | |
4 | // the license. | |
5 | //----------------------------------------------------------------------------- | |
6 | // Flashing binary | |
7 | //----------------------------------------------------------------------------- | |
8 | ||
9 | #include <stdio.h> | |
10 | #include <stdlib.h> | |
11 | #include "sleep.h" | |
12 | #include "proxusb.h" | |
13 | #include "flash.h" | |
14 | ||
15 | unsigned int current_command = CMD_UNKNOWN; | |
16 | ||
17 | extern struct partition partitions[]; | |
18 | ||
19 | static void usage(char **argv) | |
20 | { | |
21 | fprintf(stderr, "Usage: %s areas image [image [image]]\n", argv[0]); | |
22 | fprintf(stderr, " areas is a comma-separated list of areas to flash, with no spaces\n"); | |
23 | fprintf(stderr, " Known areas are:"); | |
24 | ||
25 | for (int i = 0; partitions[i].name != NULL; ++i) { | |
26 | fprintf(stderr, " %s", partitions[i].name); | |
27 | } | |
28 | ||
29 | fprintf(stderr, "\n"); | |
30 | fprintf(stderr, " image is the path to the corresponding image\n\n"); | |
31 | fprintf(stderr, "Example: %s os,fpga path/to/osimage.elf path/to/fpgaimage.elf\n", argv[0]); | |
32 | } | |
33 | ||
34 | int main(int argc, char **argv) | |
35 | { | |
36 | if (argc < 2) { | |
37 | usage(argv); | |
38 | exit(-1); | |
39 | } | |
40 | ||
41 | /* Count area arguments */ | |
42 | int areas = 0, offset=-1, length=0; | |
43 | while (find_next_area(argv[1], &offset, &length)) areas++; | |
44 | ||
45 | if (areas != argc - 2) { | |
46 | usage(argv); | |
47 | exit(-1); | |
48 | } | |
49 | ||
50 | usb_init(); | |
51 | ||
52 | fprintf(stderr,"Waiting for Proxmark to appear on USB... "); | |
53 | while (!OpenProxmark(0)) { sleep(1); } | |
54 | fprintf(stderr,"Found.\n"); | |
55 | ||
56 | do_flash(argv); | |
57 | ||
58 | UsbCommand c = {CMD_HARDWARE_RESET}; | |
59 | SendCommand(&c); | |
60 | ||
61 | CloseProxmark(); | |
62 | ||
63 | fprintf(stderr,"Have a nice day!\n"); | |
64 | ||
65 | return 0; | |
66 | } |