]>
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"
15 #include "util_posix.h"
24 static serial_port sp
;
25 static char* serial_port_name
;
27 void cmd_debug(UsbCommand
* UC
) {
29 printf("UsbCommand length[len=%zd]\n",sizeof(UsbCommand
));
30 printf(" cmd[len=%zd]: %016" PRIx64
"\n",sizeof(UC
->cmd
),UC
->cmd
);
31 printf(" arg0[len=%zd]: %016" PRIx64
"\n",sizeof(UC
->arg
[0]),UC
->arg
[0]);
32 printf(" arg1[len=%zd]: %016" PRIx64
"\n",sizeof(UC
->arg
[1]),UC
->arg
[1]);
33 printf(" arg2[len=%zd]: %016" PRIx64
"\n",sizeof(UC
->arg
[2]),UC
->arg
[2]);
34 printf(" data[len=%zd]: ",sizeof(UC
->d
.asBytes
));
35 for (size_t i
=0; i
<16; i
++) {
36 printf("%02x",UC
->d
.asBytes
[i
]);
41 void SendCommand(UsbCommand
* txcmd
) {
44 if (!uart_send(sp
,(byte_t
*)txcmd
,sizeof(UsbCommand
))) {
45 printf("Sending bytes to proxmark failed\n");
50 void ReceiveCommand(UsbCommand
* rxcmd
) {
51 byte_t
* prxcmd
= (byte_t
*)rxcmd
;
55 rxlen
= sizeof(UsbCommand
) - (prx
-prxcmd
);
56 if (uart_receive(sp
,prx
,&rxlen
)) {
58 if ((prx
-prxcmd
) >= sizeof(UsbCommand
)) {
65 void CloseProxmark() {
68 // Fix for linux, it seems that it is extremely slow to release the serial port file descriptor /dev/*
69 unlink(serial_port_name
);
72 int OpenProxmark(size_t i
) {
73 sp
= uart_open(serial_port_name
);
74 if (sp
== INVALID_SERIAL_PORT
|| sp
== CLAIMED_SERIAL_PORT
) {
81 static void usage(char *argv0
)
83 fprintf(stderr
, "Usage: %s <port> [-b] image.elf [image.elf...]\n\n", argv0
);
84 fprintf(stderr
, "\t-b\tEnable flashing of bootloader area (DANGEROUS)\n\n");
85 //Is the example below really true? /Martin
86 fprintf(stderr
, "Example:\n\n\t %s path/to/osimage.elf path/to/fpgaimage.elf\n", argv0
);
87 fprintf(stderr
, "\nExample (Linux):\n\n\t %s /dev/ttyACM0 armsrc/obj/fullimage.elf\n", argv0
);
88 fprintf(stderr
, "\nNote (Linux): if the flasher gets stuck in 'Waiting for Proxmark to reappear on <DEVICE>',\n");
89 fprintf(stderr
, " you need to blacklist proxmark for modem-manager - see wiki for more details:\n");
90 fprintf(stderr
, " http://code.google.com/p/proxmark3/wiki/Linux\n\n");
95 int main(int argc
, char **argv
)
100 flash_file_t files
[MAX_FILES
];
102 memset(files
, 0, sizeof(files
));
109 for (int i
= 2; i
< argc
; i
++) {
110 if (argv
[i
][0] == '-') {
111 if (!strcmp(argv
[i
], "-b")) {
118 res
= flash_load(&files
[num_files
], argv
[i
], can_write_bl
);
120 fprintf(stderr
, "Error while loading %s\n", argv
[i
]);
123 fprintf(stderr
, "\n");
128 serial_port_name
= argv
[1];
130 fprintf(stderr
,"Waiting for Proxmark to appear on %s",serial_port_name
);
133 fprintf(stderr
, ".");
134 } while (!OpenProxmark(0));
135 fprintf(stderr
," Found.\n");
137 res
= flash_start_flashing(can_write_bl
,serial_port_name
);
141 fprintf(stderr
, "\nFlashing...\n");
143 for (int i
= 0; i
< num_files
; i
++) {
144 res
= flash_write(&files
[i
]);
147 flash_free(&files
[i
]);
148 fprintf(stderr
, "\n");
151 fprintf(stderr
, "Resetting hardware...\n");
153 res
= flash_stop_flashing();
159 fprintf(stderr
, "All done.\n\n");
160 fprintf(stderr
, "Have a nice day!\n");