]> git.zerfleddert.de Git - proxmark3-svn/blame_incremental - client/flasher.c
Fixed ISSUE 15 in iso14443a.c - Gerhard
[proxmark3-svn] / client / flasher.c
... / ...
CommitLineData
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//-----------------------------------------------------------------------------
8
9#include <stdio.h>
10#include <stdlib.h>
11#include <string.h>
12#include "sleep.h"
13#include "proxusb.h"
14#include "flash.h"
15
16static void usage(char *argv0)
17{
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);
21}
22
23#define MAX_FILES 4
24
25int main(int argc, char **argv)
26{
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;
93}
Impressum, Datenschutz