]>
git.zerfleddert.de Git - proxmark3-svn/blob - client/flasher.c
40e40524e6dc8e317cce0a53ccda779b82b77445
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 //-----------------------------------------------------------------------------
15 #include "proxmark3.h"
17 #include "util_posix.h"
29 void cmd_debug(UsbCommand
* UC
) {
31 printf("UsbCommand length[len=%zd]\n",sizeof(UsbCommand
));
32 printf(" cmd[len=%zd]: %016" PRIx64
"\n",sizeof(UC
->cmd
),UC
->cmd
);
33 printf(" arg0[len=%zd]: %016" PRIx64
"\n",sizeof(UC
->arg
[0]),UC
->arg
[0]);
34 printf(" arg1[len=%zd]: %016" PRIx64
"\n",sizeof(UC
->arg
[1]),UC
->arg
[1]);
35 printf(" arg2[len=%zd]: %016" PRIx64
"\n",sizeof(UC
->arg
[2]),UC
->arg
[2]);
36 printf(" data[len=%zd]: ",sizeof(UC
->d
.asBytes
));
37 for (size_t i
=0; i
<16; i
++) {
38 printf("%02x",UC
->d
.asBytes
[i
]);
43 static void usage(char *argv0
)
45 fprintf(stderr
, "Usage: %s <port> [-b] image.elf [image.elf...]\n\n", argv0
);
46 fprintf(stderr
, "\t-b\tEnable flashing of bootloader area (DANGEROUS)\n\n");
47 //Is the example below really true? /Martin
48 fprintf(stderr
, "Example:\n\n\t %s path/to/osimage.elf path/to/fpgaimage.elf\n", argv0
);
49 fprintf(stderr
, "\nExample (Linux):\n\n\t %s /dev/ttyACM0 armsrc/obj/fullimage.elf\n", argv0
);
50 fprintf(stderr
, "\nNote (Linux): if the flasher gets stuck at 'Waiting for Proxmark to reappear',\n");
51 fprintf(stderr
, " you may need to blacklist proxmark for modem-manager. v1.4.14 and later\n");
52 fprintf(stderr
, " include this configuration patch already. The change can be found at:\n");
53 fprintf(stderr
, " https://cgit.freedesktop.org/ModemManager/ModemManager/commit/?id=6e7ff47\n\n");
58 int main(int argc
, char **argv
)
63 flash_file_t files
[MAX_FILES
];
65 pthread_t reader_thread
;
67 memset(&conn
, 0, sizeof(receiver_arg
));
68 memset(files
, 0, sizeof(files
));
75 for (int i
= 2; i
< argc
; i
++) {
76 if (argv
[i
][0] == '-') {
77 if (!strcmp(argv
[i
], "-b")) {
84 res
= flash_load(&files
[num_files
], argv
[i
], can_write_bl
);
86 fprintf(stderr
, "Error while loading %s\n", argv
[i
]);
89 fprintf(stderr
, "\n");
94 pthread_mutex_init(&conn
.recv_lock
, NULL
);
96 char* serial_port_name
= argv
[1];
98 fprintf(stderr
,"Waiting for Proxmark to appear on %s", serial_port_name
);
101 fprintf(stderr
, ".");
102 } while (!OpenProxmark(serial_port_name
));
103 fprintf(stderr
," Found.\n");
105 // Lets start up the communications thread
107 pthread_create(&reader_thread
, NULL
, &uart_receiver
, &conn
);
109 res
= flash_start_flashing(&conn
, can_write_bl
, serial_port_name
);
113 fprintf(stderr
, "\nFlashing...\n");
115 for (int i
= 0; i
< num_files
; i
++) {
116 res
= flash_write(&files
[i
]);
119 flash_free(&files
[i
]);
120 fprintf(stderr
, "\n");
123 fprintf(stderr
, "Resetting hardware...\n");
125 res
= flash_stop_flashing();
129 // Stop the command thread.
131 pthread_join(reader_thread
, NULL
);
132 CloseProxmark(&conn
, serial_port_name
);
133 pthread_mutex_destroy(&conn
.recv_lock
);
135 fprintf(stderr
, "All done.\n\n");
136 fprintf(stderr
, "Have a nice day!\n");