]>
Commit | Line | Data |
---|---|---|
a553f267 | 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 | ||
6658905f | 9 | #include <stdio.h> |
83a9b236 | 10 | #include <stdlib.h> |
4cd41f34 | 11 | #include "sleep.h" |
7fe9b0b7 | 12 | #include "proxusb.h" |
6e4d4ee6 | 13 | #include "flash.h" |
6658905f | 14 | |
9b255608 | 15 | unsigned int current_command = CMD_UNKNOWN; |
16 | ||
6e4d4ee6 | 17 | extern struct partition partitions[]; |
a5b1ba20 | 18 | |
19 | static void usage(char **argv) | |
20 | { | |
7fe9b0b7 | 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:"); | |
6e4d4ee6 | 24 | |
7fe9b0b7 | 25 | for (int i = 0; partitions[i].name != NULL; ++i) { |
26 | fprintf(stderr, " %s", partitions[i].name); | |
27 | } | |
6e4d4ee6 | 28 | |
7fe9b0b7 | 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]); | |
a5b1ba20 | 32 | } |
6658905f | 33 | |
7fe9b0b7 | 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); | |
a5b1ba20 | 57 | |
7fe9b0b7 | 58 | UsbCommand c = {CMD_HARDWARE_RESET}; |
59 | SendCommand(&c); | |
6658905f | 60 | |
7fe9b0b7 | 61 | CloseProxmark(); |
6658905f | 62 | |
7fe9b0b7 | 63 | fprintf(stderr,"Have a nice day!\n"); |
6658905f | 64 | |
7fe9b0b7 | 65 | return 0; |
6658905f | 66 | } |