R&Y: Added DAY RTA Tapp Card and Additional BKK BEM Stored Value Card AIDs to `aid_de...
[RRG-proxmark3.git] / tools / deprecated-hid-flasher / flasher / flasher.c
blobf9d5f49b78de6f1a60fffeb7ffd611f0d6a64f00
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 // Flasher frontend tool
7 //-----------------------------------------------------------------------------
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include "proxusb.h"
13 #include "flash.h"
14 #include "sleep.h"
16 static void usage(char *argv0) {
17 fprintf(stderr, "Usage: %s [-b] image.elf [image.elf...]\n\n", argv0);
18 fprintf(stderr, "\t-b\tEnable flashing of bootloader area (DANGEROUS)\n\n");
19 fprintf(stderr, "Example: %s path/to/osimage.elf path/to/fpgaimage.elf\n", argv0);
22 #define MAX_FILES 4
24 int main(int argc, char **argv) {
25 int can_write_bl = 0;
26 int num_files = 0;
27 int res;
28 flash_file_t files[MAX_FILES];
30 memset(files, 0, sizeof(files));
32 if (argc < 2) {
33 usage(argv[0]);
34 return -1;
37 for (int i = 1; i < argc; i++) {
38 if (argv[i][0] == '-') {
39 if (!strcmp(argv[i], "-b")) {
40 can_write_bl = 1;
41 } else {
42 usage(argv[0]);
43 return -1;
45 } else {
46 res = flash_load(&files[num_files], argv[i], can_write_bl);
47 if (res < 0) {
48 fprintf(stderr, "Error while loading %s\n", argv[i]);
49 return -1;
51 fprintf(stderr, "\n");
52 num_files++;
56 usb_init();
58 fprintf(stderr, "Waiting for Proxmark3 to appear on USB...");
59 while (!OpenProxmark(1)) {
60 msleep(1000);
61 fprintf(stderr, ".");
62 fflush(stdout);
64 fprintf(stderr, " Found.\n");
66 res = flash_start_flashing(can_write_bl);
67 if (res < 0)
68 return -1;
70 fprintf(stderr, "\nFlashing...\n");
72 for (int i = 0; i < num_files; i++) {
73 res = flash_write(&files[i]);
74 if (res < 0)
75 return -1;
76 flash_free(&files[i]);
77 fprintf(stderr, "\n");
80 fprintf(stderr, "Resetting hardware...\n");
82 res = flash_stop_flashing();
83 if (res < 0)
84 return -1;
86 CloseProxmark();
88 fprintf(stderr, "All done.\n\n");
89 fprintf(stderr, "Have a nice day!\n");
91 return 0;