]> git.zerfleddert.de Git - proxmark3-svn/blame - client/flasher.c
lf hid improvements - encoding and long tag simulation
[proxmark3-svn] / client / flasher.c
CommitLineData
a553f267 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
4// the license.
5//-----------------------------------------------------------------------------
8fe1a992 6// Flasher frontend tool
a553f267 7//-----------------------------------------------------------------------------
8
6658905f 9#include <stdio.h>
83a9b236 10#include <stdlib.h>
8fe1a992 11#include <string.h>
43534cba 12#include <inttypes.h>
ad939de5 13#include <pthread.h>
125a98a1 14#include "proxmark3.h"
acf0582d 15#include "util.h"
ec9c7112 16#include "util_posix.h"
6e4d4ee6 17#include "flash.h"
ad939de5 18#include "comms.h"
28fdb04f 19#include "usb_cmd.h"
20
13dbdd6b 21
28fdb04f 22void cmd_debug(UsbCommand* UC) {
23 // Debug
24 printf("UsbCommand length[len=%zd]\n",sizeof(UsbCommand));
43534cba 25 printf(" cmd[len=%zd]: %016" PRIx64 "\n",sizeof(UC->cmd),UC->cmd);
26 printf(" arg0[len=%zd]: %016" PRIx64 "\n",sizeof(UC->arg[0]),UC->arg[0]);
27 printf(" arg1[len=%zd]: %016" PRIx64 "\n",sizeof(UC->arg[1]),UC->arg[1]);
28 printf(" arg2[len=%zd]: %016" PRIx64 "\n",sizeof(UC->arg[2]),UC->arg[2]);
28fdb04f 29 printf(" data[len=%zd]: ",sizeof(UC->d.asBytes));
30 for (size_t i=0; i<16; i++) {
31 printf("%02x",UC->d.asBytes[i]);
32 }
33 printf("...\n");
34}
35
8fe1a992 36static void usage(char *argv0)
a5b1ba20 37{
28fdb04f 38 fprintf(stderr, "Usage: %s <port> [-b] image.elf [image.elf...]\n\n", argv0);
8fe1a992 39 fprintf(stderr, "\t-b\tEnable flashing of bootloader area (DANGEROUS)\n\n");
f5ecd97b 40 fprintf(stderr, "\nExample:\n\n\t %s "SERIAL_PORT_H" armsrc/obj/fullimage.elf\n", argv0);
41#ifdef __linux__
42 fprintf(stderr, "\nNote (Linux): if the flasher gets stuck at 'Waiting for Proxmark to reappear',\n");
43 fprintf(stderr, " you may need to blacklist proxmark for modem-manager. v1.4.14 and later\n");
44 fprintf(stderr, " include this configuration patch already. The change can be found at:\n");
45 fprintf(stderr, " https://cgit.freedesktop.org/ModemManager/ModemManager/commit/?id=6e7ff47\n\n");
46#endif
a5b1ba20 47}
6658905f 48
8fe1a992 49#define MAX_FILES 4
50
7fe9b0b7 51int main(int argc, char **argv)
52{
ad939de5 53 int can_write_bl = false;
8fe1a992 54 int num_files = 0;
55 int res;
56 flash_file_t files[MAX_FILES];
57
58 memset(files, 0, sizeof(files));
59
28fdb04f 60 if (argc < 3) {
8fe1a992 61 usage(argv[0]);
62 return -1;
63 }
64
28fdb04f 65 for (int i = 2; i < argc; i++) {
8fe1a992 66 if (argv[i][0] == '-') {
67 if (!strcmp(argv[i], "-b")) {
ad939de5 68 can_write_bl = true;
8fe1a992 69 } else {
70 usage(argv[0]);
71 return -1;
72 }
73 } else {
74 res = flash_load(&files[num_files], argv[i], can_write_bl);
75 if (res < 0) {
76 fprintf(stderr, "Error while loading %s\n", argv[i]);
77 return -1;
78 }
79 fprintf(stderr, "\n");
80 num_files++;
81 }
82 }
83
f5ecd97b 84 char* serial_port_name = argv[1];
85
ad939de5 86 if (!OpenProxmark(serial_port_name, true, 120, true)) { // wait for 2 minutes
87 fprintf(stderr, "Could not find Proxmark on %s.\n\n", serial_port_name);
88 return -1;
89 } else {
90 fprintf(stderr," Found.\n");
91 }
8fe1a992 92
f5ecd97b 93 res = flash_start_flashing(can_write_bl, serial_port_name);
8fe1a992 94 if (res < 0)
95 return -1;
96
97 fprintf(stderr, "\nFlashing...\n");
98
99 for (int i = 0; i < num_files; i++) {
100 res = flash_write(&files[i]);
101 if (res < 0)
102 return -1;
103 flash_free(&files[i]);
104 fprintf(stderr, "\n");
105 }
106
107 fprintf(stderr, "Resetting hardware...\n");
108
109 res = flash_stop_flashing();
110 if (res < 0)
111 return -1;
112
ad939de5 113 // Stop the command thread.
114 CloseProxmark();
8fe1a992 115
116 fprintf(stderr, "All done.\n\n");
117 fprintf(stderr, "Have a nice day!\n");
118
119 return 0;
6658905f 120}
Impressum, Datenschutz