]> git.zerfleddert.de Git - proxmark3-svn/blame_incremental - client/flasher.c
Merge branch 'master' into fix_iclass_sim
[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 <inttypes.h>
13#include <pthread.h>
14#include "proxmark3.h"
15#include "util.h"
16#include "util_posix.h"
17#include "flash.h"
18#include "comms.h"
19#include "usb_cmd.h"
20
21
22void cmd_debug(UsbCommand* UC) {
23 // Debug
24 printf("UsbCommand length[len=%zd]\n",sizeof(UsbCommand));
25 printf(" cmd[len=%zd]: %016" PRIx64 "\n",sizeof(UC->cmd),UC->cmd);
26 printf(" arg0[len=%zd]: %016" PRIx64 "\n",sizeof(UC->arg[0]),UC->arg[0]);
27 printf(" arg1[len=%zd]: %016" PRIx64 "\n",sizeof(UC->arg[1]),UC->arg[1]);
28 printf(" arg2[len=%zd]: %016" PRIx64 "\n",sizeof(UC->arg[2]),UC->arg[2]);
29 printf(" data[len=%zd]: ",sizeof(UC->d.asBytes));
30 for (size_t i=0; i<16; i++) {
31 printf("%02x",UC->d.asBytes[i]);
32 }
33 printf("...\n");
34}
35
36static void usage(char *argv0)
37{
38 fprintf(stderr, "Usage: %s <port> [-b] image.elf [image.elf...]\n\n", argv0);
39 fprintf(stderr, "\t-b\tEnable flashing of bootloader area (DANGEROUS)\n\n");
40 fprintf(stderr, "\nExample:\n\n\t %s "SERIAL_PORT_H" armsrc/obj/fullimage.elf\n", argv0);
41#ifdef __linux__
42 fprintf(stderr, "\nNote (Linux): if the flasher gets stuck at 'Waiting for Proxmark to reappear',\n");
43 fprintf(stderr, " you may need to blacklist proxmark for modem-manager. v1.4.14 and later\n");
44 fprintf(stderr, " include this configuration patch already. The change can be found at:\n");
45 fprintf(stderr, " https://cgit.freedesktop.org/ModemManager/ModemManager/commit/?id=6e7ff47\n\n");
46#endif
47}
48
49#define MAX_FILES 4
50
51int main(int argc, char **argv)
52{
53 int can_write_bl = false;
54 int num_files = 0;
55 int res;
56 flash_file_t files[MAX_FILES];
57
58 memset(files, 0, sizeof(files));
59
60 if (argc < 3) {
61 usage(argv[0]);
62 return -1;
63 }
64
65 for (int i = 2; i < argc; i++) {
66 if (argv[i][0] == '-') {
67 if (!strcmp(argv[i], "-b")) {
68 can_write_bl = true;
69 } else {
70 usage(argv[0]);
71 return -1;
72 }
73 } else {
74 res = flash_load(&files[num_files], argv[i], can_write_bl);
75 if (res < 0) {
76 fprintf(stderr, "Error while loading %s\n", argv[i]);
77 return -1;
78 }
79 fprintf(stderr, "\n");
80 num_files++;
81 }
82 }
83
84 char* serial_port_name = argv[1];
85
86 if (!OpenProxmark(serial_port_name, true, 120, true)) { // wait for 2 minutes
87 fprintf(stderr, "Could not find Proxmark on %s.\n\n", serial_port_name);
88 return -1;
89 } else {
90 fprintf(stderr," Found.\n");
91 }
92
93 res = flash_start_flashing(can_write_bl, serial_port_name);
94 if (res < 0)
95 return -1;
96
97 fprintf(stderr, "\nFlashing...\n");
98
99 for (int i = 0; i < num_files; i++) {
100 res = flash_write(&files[i]);
101 if (res < 0)
102 return -1;
103 flash_free(&files[i]);
104 fprintf(stderr, "\n");
105 }
106
107 fprintf(stderr, "Resetting hardware...\n");
108
109 res = flash_stop_flashing();
110 if (res < 0)
111 return -1;
112
113 // Stop the command thread.
114 CloseProxmark();
115
116 fprintf(stderr, "All done.\n\n");
117 fprintf(stderr, "Have a nice day!\n");
118
119 return 0;
120}
Impressum, Datenschutz