]>
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 | //----------------------------------------------------------------------------- | |
8fe1a992 | 6 | // Flasher frontend tool |
a553f267 | 7 | //----------------------------------------------------------------------------- |
8 | ||
6658905f | 9 | #include <stdio.h> |
83a9b236 | 10 | #include <stdlib.h> |
8fe1a992 | 11 | #include <string.h> |
4cd41f34 | 12 | #include "sleep.h" |
7fe9b0b7 | 13 | #include "proxusb.h" |
6e4d4ee6 | 14 | #include "flash.h" |
6658905f | 15 | |
8fe1a992 | 16 | static void usage(char *argv0) |
a5b1ba20 | 17 | { |
8fe1a992 | 18 | fprintf(stderr, "Usage: %s [-b] image.elf [image.elf...]\n\n", argv0); |
19 | fprintf(stderr, "\t-b\tEnable flashing of bootloader area (DANGEROUS)\n\n"); | |
20 | fprintf(stderr, "Example: %s path/to/osimage.elf path/to/fpgaimage.elf\n", argv0); | |
a5b1ba20 | 21 | } |
6658905f | 22 | |
8fe1a992 | 23 | #define MAX_FILES 4 |
24 | ||
7fe9b0b7 | 25 | int main(int argc, char **argv) |
26 | { | |
8fe1a992 | 27 | int can_write_bl = 0; |
28 | int num_files = 0; | |
29 | int res; | |
30 | flash_file_t files[MAX_FILES]; | |
31 | ||
32 | memset(files, 0, sizeof(files)); | |
33 | ||
34 | if (argc < 2) { | |
35 | usage(argv[0]); | |
36 | return -1; | |
37 | } | |
38 | ||
39 | for (int i = 1; i < argc; i++) { | |
40 | if (argv[i][0] == '-') { | |
41 | if (!strcmp(argv[i], "-b")) { | |
42 | can_write_bl = 1; | |
43 | } else { | |
44 | usage(argv[0]); | |
45 | return -1; | |
46 | } | |
47 | } else { | |
48 | res = flash_load(&files[num_files], argv[i], can_write_bl); | |
49 | if (res < 0) { | |
50 | fprintf(stderr, "Error while loading %s\n", argv[i]); | |
51 | return -1; | |
52 | } | |
53 | fprintf(stderr, "\n"); | |
54 | num_files++; | |
55 | } | |
56 | } | |
57 | ||
58 | usb_init(); | |
59 | ||
60 | fprintf(stderr, "Waiting for Proxmark to appear on USB..."); | |
61 | while (!OpenProxmark(0)) { | |
62 | sleep(1); | |
63 | fprintf(stderr, "."); | |
64 | } | |
65 | fprintf(stderr, " Found.\n"); | |
66 | ||
67 | res = flash_start_flashing(can_write_bl); | |
68 | if (res < 0) | |
69 | return -1; | |
70 | ||
71 | fprintf(stderr, "\nFlashing...\n"); | |
72 | ||
73 | for (int i = 0; i < num_files; i++) { | |
74 | res = flash_write(&files[i]); | |
75 | if (res < 0) | |
76 | return -1; | |
77 | flash_free(&files[i]); | |
78 | fprintf(stderr, "\n"); | |
79 | } | |
80 | ||
81 | fprintf(stderr, "Resetting hardware...\n"); | |
82 | ||
83 | res = flash_stop_flashing(); | |
84 | if (res < 0) | |
85 | return -1; | |
86 | ||
87 | CloseProxmark(); | |
88 | ||
89 | fprintf(stderr, "All done.\n\n"); | |
90 | fprintf(stderr, "Have a nice day!\n"); | |
91 | ||
92 | return 0; | |
6658905f | 93 | } |