]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/flasher.c
2bb87df9a96ea1ab5ab63a56a9e387a545f72272
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
5 //-----------------------------------------------------------------------------
6 // Flasher frontend tool
7 //-----------------------------------------------------------------------------
13 #include "proxmark3.h"
15 #include "util_posix.h"
26 void cmd_debug(UsbCommand
* UC
) {
28 printf("UsbCommand length[len=%zd]\n",sizeof(UsbCommand
));
29 printf(" cmd[len=%zd]: %016" PRIx64
"\n",sizeof(UC
->cmd
),UC
->cmd
);
30 printf(" arg0[len=%zd]: %016" PRIx64
"\n",sizeof(UC
->arg
[0]),UC
->arg
[0]);
31 printf(" arg1[len=%zd]: %016" PRIx64
"\n",sizeof(UC
->arg
[1]),UC
->arg
[1]);
32 printf(" arg2[len=%zd]: %016" PRIx64
"\n",sizeof(UC
->arg
[2]),UC
->arg
[2]);
33 printf(" data[len=%zd]: ",sizeof(UC
->d
.asBytes
));
34 for (size_t i
=0; i
<16; i
++) {
35 printf("%02x",UC
->d
.asBytes
[i
]);
40 void SendCommand(UsbCommand
* txcmd
) {
43 if (!uart_send(sp
,(uint8_t*)txcmd
,sizeof(UsbCommand
))) {
44 printf("Sending bytes to proxmark failed\n");
49 void ReceiveCommand(UsbCommand
* rxcmd
) {
50 uint8_t* prxcmd
= (uint8_t*)rxcmd
;
51 uint8_t* prx
= prxcmd
;
54 if (uart_receive(sp
, prx
, sizeof(UsbCommand
) - (prx
-prxcmd
), &rxlen
)) {
56 if ((prx
-prxcmd
) >= sizeof(UsbCommand
)) {
63 static void usage(char *argv0
)
65 fprintf(stderr
, "Usage: %s <port> [-b] image.elf [image.elf...]\n\n", argv0
);
66 fprintf(stderr
, "\t-b\tEnable flashing of bootloader area (DANGEROUS)\n\n");
67 fprintf(stderr
, "\nExample:\n\n\t %s "SERIAL_PORT_H
" armsrc/obj/fullimage.elf\n", argv0
);
69 fprintf(stderr
, "\nNote (Linux): if the flasher gets stuck at 'Waiting for Proxmark to reappear',\n");
70 fprintf(stderr
, " you may need to blacklist proxmark for modem-manager. v1.4.14 and later\n");
71 fprintf(stderr
, " include this configuration patch already. The change can be found at:\n");
72 fprintf(stderr
, " https://cgit.freedesktop.org/ModemManager/ModemManager/commit/?id=6e7ff47\n\n");
78 int main(int argc
, char **argv
)
83 flash_file_t files
[MAX_FILES
];
85 memset(files
, 0, sizeof(files
));
92 for (int i
= 2; i
< argc
; i
++) {
93 if (argv
[i
][0] == '-') {
94 if (!strcmp(argv
[i
], "-b")) {
101 res
= flash_load(&files
[num_files
], argv
[i
], can_write_bl
);
103 fprintf(stderr
, "Error while loading %s\n", argv
[i
]);
106 fprintf(stderr
, "\n");
111 char* serial_port_name
= argv
[1];
113 fprintf(stderr
,"Waiting for Proxmark to appear on %s", serial_port_name
);
116 fprintf(stderr
, ".");
117 } while (!OpenProxmark(0, serial_port_name
));
118 fprintf(stderr
," Found.\n");
120 res
= flash_start_flashing(can_write_bl
, serial_port_name
);
124 fprintf(stderr
, "\nFlashing...\n");
126 for (int i
= 0; i
< num_files
; i
++) {
127 res
= flash_write(&files
[i
]);
130 flash_free(&files
[i
]);
131 fprintf(stderr
, "\n");
134 fprintf(stderr
, "Resetting hardware...\n");
136 res
= flash_stop_flashing();
140 CloseProxmark(serial_port_name
);
142 fprintf(stderr
, "All done.\n\n");
143 fprintf(stderr
, "Have a nice day!\n");