2010-02-21 00:47:22 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
|
|
|
// at your option, any later version. See the LICENSE.txt file for the text of
|
|
|
|
// the license.
|
|
|
|
//-----------------------------------------------------------------------------
|
2010-02-26 14:03:43 +00:00
|
|
|
// Flasher frontend tool
|
2010-02-21 00:47:22 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2009-04-09 06:43:20 +00:00
|
|
|
#include <stdio.h>
|
2010-02-06 09:33:17 +00:00
|
|
|
#include <stdlib.h>
|
2010-02-26 14:03:43 +00:00
|
|
|
#include <string.h>
|
2017-07-28 01:37:55 +02:00
|
|
|
#include <inttypes.h>
|
2018-09-06 21:43:20 +02:00
|
|
|
#include <pthread.h>
|
2017-07-30 09:17:48 +02:00
|
|
|
#include "util_posix.h"
|
2013-02-28 22:22:24 +00:00
|
|
|
#include "proxmark3.h"
|
2018-09-06 21:43:20 +02:00
|
|
|
#include "util.h"
|
2010-01-04 05:11:08 +00:00
|
|
|
#include "flash.h"
|
2018-09-06 21:43:20 +02:00
|
|
|
#include "comms.h"
|
2015-07-22 23:00:52 +02:00
|
|
|
#include "usb_cmd.h"
|
2013-02-28 15:11:52 +00:00
|
|
|
|
2017-10-17 20:58:17 +02:00
|
|
|
#define MAX_FILES 4
|
|
|
|
|
|
|
|
void cmd_debug(UsbCommand* c) {
|
2016-01-21 08:02:41 +01:00
|
|
|
// Debug
|
2017-09-26 17:04:25 +02:00
|
|
|
printf("UsbCommand length[len=%zd]\n", sizeof(UsbCommand));
|
2017-10-17 20:58:17 +02:00
|
|
|
printf(" cmd[len=%zd]: %016" PRIx64"\n", sizeof(c->cmd), c->cmd);
|
|
|
|
printf(" arg0[len=%zd]: %016" PRIx64"\n", sizeof(c->arg[0]), c->arg[0]);
|
|
|
|
printf(" arg1[len=%zd]: %016" PRIx64"\n", sizeof(c->arg[1]), c->arg[1]);
|
|
|
|
printf(" arg2[len=%zd]: %016" PRIx64"\n", sizeof(c->arg[2]), c->arg[2]);
|
|
|
|
printf(" data[len=%zd]: ", sizeof(c->d.asBytes));
|
2016-01-21 08:02:41 +01:00
|
|
|
|
|
|
|
for (size_t i=0; i<16; i++)
|
2017-10-17 20:58:17 +02:00
|
|
|
printf("%02x", c->d.asBytes[i]);
|
2016-01-21 08:02:41 +01:00
|
|
|
|
|
|
|
printf("...\n");
|
2013-02-28 15:11:52 +00:00
|
|
|
}
|
|
|
|
|
2017-09-26 17:04:25 +02:00
|
|
|
static void usage(char *argv0) {
|
2017-10-19 13:41:55 +02:00
|
|
|
fprintf(stdout, "Usage: %s <port> [-b] image.elf [image.elf...]\n\n", argv0);
|
|
|
|
fprintf(stdout, "\t-b\tEnable flashing of bootloader area (DANGEROUS)\n\n");
|
2018-06-17 12:55:32 +02:00
|
|
|
fprintf(stdout, "\nExample:\n\n\t %s "SERIAL_PORT_H" armsrc/obj/fullimage.elf\n", argv0);
|
2018-05-06 22:43:46 +02:00
|
|
|
#ifdef __linux__
|
2017-10-19 13:41:55 +02:00
|
|
|
fprintf(stdout, "\nNote (Linux): if the flasher gets stuck in 'Waiting for Proxmark to reappear on <DEVICE>',\n");
|
2017-10-29 19:25:34 +01:00
|
|
|
fprintf(stdout, " you need to blacklist proxmark for modem-manager - see wiki for more details:\n\n");
|
2017-10-19 13:41:55 +02:00
|
|
|
fprintf(stdout, " https://github.com/Proxmark/proxmark3/wiki/Gentoo Linux\n\n");
|
|
|
|
fprintf(stdout, " https://github.com/Proxmark/proxmark3/wiki/Ubuntu Linux\n\n");
|
2018-05-06 22:43:46 +02:00
|
|
|
fprintf(stdout, " https://github.com/Proxmark/proxmark3/wiki/OSX\n\n");
|
|
|
|
#endif
|
2009-09-01 14:35:13 +00:00
|
|
|
}
|
2009-04-09 06:43:20 +00:00
|
|
|
|
2017-10-17 20:58:17 +02:00
|
|
|
int main(int argc, char **argv) {
|
2010-02-26 14:03:43 +00:00
|
|
|
int can_write_bl = 0;
|
|
|
|
int num_files = 0;
|
|
|
|
int res;
|
|
|
|
flash_file_t files[MAX_FILES];
|
|
|
|
|
|
|
|
memset(files, 0, sizeof(files));
|
|
|
|
|
2013-02-28 15:11:52 +00:00
|
|
|
if (argc < 3) {
|
2010-02-26 14:03:43 +00:00
|
|
|
usage(argv[0]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-02-28 15:11:52 +00:00
|
|
|
for (int i = 2; i < argc; i++) {
|
2010-02-26 14:03:43 +00:00
|
|
|
if (argv[i][0] == '-') {
|
|
|
|
if (!strcmp(argv[i], "-b")) {
|
|
|
|
can_write_bl = 1;
|
|
|
|
} else {
|
|
|
|
usage(argv[0]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
res = flash_load(&files[num_files], argv[i], can_write_bl);
|
2018-09-06 21:43:20 +02:00
|
|
|
if (res < 0)
|
2010-02-26 14:03:43 +00:00
|
|
|
return -1;
|
2018-09-06 21:43:20 +02:00
|
|
|
|
2010-02-26 14:03:43 +00:00
|
|
|
fprintf(stderr, "\n");
|
|
|
|
num_files++;
|
|
|
|
}
|
|
|
|
}
|
2018-09-06 21:43:20 +02:00
|
|
|
|
|
|
|
char* serial_port_name = argv[1];
|
2010-02-26 14:03:43 +00:00
|
|
|
|
2018-09-06 21:43:20 +02:00
|
|
|
if (!OpenProxmark(serial_port_name, true, 60, true)) {
|
|
|
|
fprintf(stderr, "Could not find Proxmark on " _RED_(%s) ".\n\n", serial_port_name);
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, _GREEN_(Found) "\n");
|
|
|
|
}
|
2016-01-21 08:02:41 +01:00
|
|
|
|
|
|
|
res = flash_start_flashing(can_write_bl, serial_port_name);
|
2010-02-26 14:03:43 +00:00
|
|
|
if (res < 0)
|
|
|
|
return -1;
|
|
|
|
|
2018-09-06 21:43:20 +02:00
|
|
|
fprintf(stdout, "\n" _BLUE_(Flashing...)"\n");
|
2010-02-26 14:03:43 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < num_files; i++) {
|
|
|
|
res = flash_write(&files[i]);
|
|
|
|
if (res < 0)
|
|
|
|
return -1;
|
|
|
|
flash_free(&files[i]);
|
2017-10-19 13:41:55 +02:00
|
|
|
fprintf(stdout, "\n");
|
2010-02-26 14:03:43 +00:00
|
|
|
}
|
|
|
|
|
2018-09-06 21:43:20 +02:00
|
|
|
fprintf(stdout, _BLUE_(Resetting hardware...) "\n");
|
2010-02-26 14:03:43 +00:00
|
|
|
|
|
|
|
res = flash_stop_flashing();
|
|
|
|
if (res < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
CloseProxmark();
|
|
|
|
|
2018-09-06 21:43:20 +02:00
|
|
|
fprintf(stdout, _BLUE_(All done.) "\n\nHave a nice day!\n");
|
2010-02-26 14:03:43 +00:00
|
|
|
return 0;
|
2009-04-09 06:43:20 +00:00
|
|
|
}
|