]>
git.zerfleddert.de Git - proxmark3-svn/blob - client/flasher.c
cf2cdd954abac543f7f661bc693194677eb53201
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"
22 static serial_port sp
;
23 static char* serial_port_name
;
25 void cmd_debug(UsbCommand
* UC
) {
27 printf("UsbCommand length[len=%zd]\n",sizeof(UsbCommand
));
28 printf(" cmd[len=%zd]: %016"llx
"\n",sizeof(UC
->cmd
),UC
->cmd
);
29 printf(" arg0[len=%zd]: %016"llx
"\n",sizeof(UC
->arg
[0]),UC
->arg
[0]);
30 printf(" arg1[len=%zd]: %016"llx
"\n",sizeof(UC
->arg
[1]),UC
->arg
[1]);
31 printf(" arg2[len=%zd]: %016"llx
"\n",sizeof(UC
->arg
[2]),UC
->arg
[2]);
32 printf(" data[len=%zd]: ",sizeof(UC
->d
.asBytes
));
33 for (size_t i
=0; i
<16; i
++) {
34 printf("%02x",UC
->d
.asBytes
[i
]);
39 void SendCommand(UsbCommand
* txcmd
) {
42 if (!uart_send(sp
,(byte_t
*)txcmd
,sizeof(UsbCommand
))) {
43 printf("Sending bytes to proxmark failed\n");
48 void ReceiveCommand(UsbCommand
* rxcmd
) {
49 byte_t
* prxcmd
= (byte_t
*)rxcmd
;
53 rxlen
= sizeof(UsbCommand
) - (prx
-prxcmd
);
54 if (uart_receive(sp
,prx
,&rxlen
)) {
55 // printf("received [%zd] bytes\n",rxlen);
57 if ((prx
-prxcmd
) >= sizeof(UsbCommand
)) {
58 // printf("received: ");
66 void CloseProxmark() {
69 // Fix for linux, it seems that it is extremely slow to release the serial port file descriptor /dev/*
70 unlink(serial_port_name
);
73 int OpenProxmark(size_t i
) {
74 sp
= uart_open(serial_port_name
);
75 if (sp
== INVALID_SERIAL_PORT
) {
82 static void usage(char *argv0
)
84 fprintf(stderr
, "Usage: %s <port> [-b] image.elf [image.elf...]\n\n", argv0
);
85 fprintf(stderr
, "\t-b\tEnable flashing of bootloader area (DANGEROUS)\n\n");
86 fprintf(stderr
, "Example: %s path/to/osimage.elf path/to/fpgaimage.elf\n", argv0
);
91 int main(int argc
, char **argv
)
96 flash_file_t files
[MAX_FILES
];
98 memset(files
, 0, sizeof(files
));
105 for (int i
= 2; i
< argc
; i
++) {
106 if (argv
[i
][0] == '-') {
107 if (!strcmp(argv
[i
], "-b")) {
114 res
= flash_load(&files
[num_files
], argv
[i
], can_write_bl
);
116 fprintf(stderr
, "Error while loading %s\n", argv
[i
]);
119 fprintf(stderr
, "\n");
124 serial_port_name
= argv
[1];
125 fprintf(stderr
, "Waiting for Proxmark to appear on USB...");
126 while (!OpenProxmark(0)) {
127 fprintf(stderr
, ".");
129 fprintf(stderr
, " Found.\n");
131 res
= flash_start_flashing(can_write_bl
);
135 fprintf(stderr
, "\nFlashing...\n");
137 for (int i
= 0; i
< num_files
; i
++) {
138 res
= flash_write(&files
[i
]);
141 flash_free(&files
[i
]);
142 fprintf(stderr
, "\n");
145 fprintf(stderr
, "Resetting hardware...\n");
147 res
= flash_stop_flashing();
153 fprintf(stderr
, "All done.\n\n");
154 fprintf(stderr
, "Have a nice day!\n");