]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/flasher.c
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"
18 static serial_port sp
;
19 static char* serial_port_name
;
21 void cmd_debug(UsbCommand
* UC
) {
23 printf("UsbCommand length[len=%zd]\n",sizeof(UsbCommand
));
24 printf(" cmd[len=%zd]: %016"llx
"\n",sizeof(UC
->cmd
),UC
->cmd
);
25 printf(" arg0[len=%zd]: %016"llx
"\n",sizeof(UC
->arg
[0]),UC
->arg
[0]);
26 printf(" arg1[len=%zd]: %016"llx
"\n",sizeof(UC
->arg
[1]),UC
->arg
[1]);
27 printf(" arg2[len=%zd]: %016"llx
"\n",sizeof(UC
->arg
[2]),UC
->arg
[2]);
28 printf(" data[len=%zd]: ",sizeof(UC
->d
.asBytes
));
29 for (size_t i
=0; i
<16; i
++) {
30 printf("%02x",UC
->d
.asBytes
[i
]);
35 void SendCommand(UsbCommand
* txcmd
) {
38 if (!uart_send(sp
,(byte_t
*)txcmd
,sizeof(UsbCommand
))) {
39 printf("Sending bytes to proxmark failed\n");
44 void ReceiveCommand(UsbCommand
* rxcmd
) {
45 byte_t
* prxcmd
= (byte_t
*)rxcmd
;
49 rxlen
= sizeof(UsbCommand
) - (prx
-prxcmd
);
50 if (uart_receive(sp
,prx
,&rxlen
)) {
51 // printf("received [%zd] bytes\n",rxlen);
53 if ((prx
-prxcmd
) >= sizeof(UsbCommand
)) {
54 // printf("received: ");
62 void CloseProxmark() {
67 int OpenProxmark(size_t i
) {
68 sp
= uart_open(serial_port_name
);
69 if (sp
== INVALID_SERIAL_PORT
) {
77 static void usage(char *argv0
)
79 fprintf(stderr
, "Usage: %s <port> [-b] image.elf [image.elf...]\n\n", argv0
);
80 fprintf(stderr
, "\t-b\tEnable flashing of bootloader area (DANGEROUS)\n\n");
81 fprintf(stderr
, "Example: %s path/to/osimage.elf path/to/fpgaimage.elf\n", argv0
);
86 int main(int argc
, char **argv
)
91 flash_file_t files
[MAX_FILES
];
93 memset(files
, 0, sizeof(files
));
100 for (int i
= 2; i
< argc
; i
++) {
101 if (argv
[i
][0] == '-') {
102 if (!strcmp(argv
[i
], "-b")) {
109 res
= flash_load(&files
[num_files
], argv
[i
], can_write_bl
);
111 fprintf(stderr
, "Error while loading %s\n", argv
[i
]);
114 fprintf(stderr
, "\n");
119 serial_port_name
= argv
[1];
120 fprintf(stderr
, "Waiting for Proxmark to appear on USB...");
121 while (!OpenProxmark(0)) {
122 fprintf(stderr
, ".");
124 fprintf(stderr
, " Found.\n");
126 res
= flash_start_flashing(can_write_bl
);
130 fprintf(stderr
, "\nFlashing...\n");
132 for (int i
= 0; i
< num_files
; i
++) {
133 res
= flash_write(&files
[i
]);
136 flash_free(&files
[i
]);
137 fprintf(stderr
, "\n");
140 fprintf(stderr
, "Resetting hardware...\n");
142 res
= flash_stop_flashing();
148 fprintf(stderr
, "All done.\n\n");
149 fprintf(stderr
, "Have a nice day!\n");