]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/flasher.c
Merge pull request #909 from pwpiwi/fix_button_break
[proxmark3-svn] / client / flasher.c
index 2bb87df9a96ea1ab5ab63a56a9e387a545f72272..a008f7bc9d85c82cb3dac55a723e6dbac83e2a04 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 #include <inttypes.h>
+#include <pthread.h>
 #include "proxmark3.h"
 #include "util.h"
 #include "util_posix.h"
 #include "flash.h"
-#include "uart.h"
+#include "comms.h"
 #include "usb_cmd.h"
 
-#ifdef _WIN32
-# define unlink(x)
-#else
-# include <unistd.h>
-#endif
 
 void cmd_debug(UsbCommand* UC) {
   //  Debug
@@ -37,29 +33,6 @@ void cmd_debug(UsbCommand* UC) {
   printf("...\n");
 }
 
-void SendCommand(UsbCommand* txcmd) {
-//  printf("send: ");
-//  cmd_debug(txcmd);
-  if (!uart_send(sp,(uint8_t*)txcmd,sizeof(UsbCommand))) {
-    printf("Sending bytes to proxmark failed\n");
-    exit(1);
-  }
-}
-
-void ReceiveCommand(UsbCommand* rxcmd) {
-  uint8_t* prxcmd = (uint8_t*)rxcmd;
-  uint8_t* prx = prxcmd;
-  size_t rxlen;
-  while (true) {
-    if (uart_receive(sp, prx, sizeof(UsbCommand) - (prx-prxcmd), &rxlen)) {
-      prx += rxlen;
-      if ((prx-prxcmd) >= sizeof(UsbCommand)) {
-        return;
-      }
-    }
-  }
-}
-
 static void usage(char *argv0)
 {
        fprintf(stderr, "Usage:   %s <port> [-b] image.elf [image.elf...]\n\n", argv0);
@@ -77,7 +50,7 @@ static void usage(char *argv0)
 
 int main(int argc, char **argv)
 {
-       int can_write_bl = 0;
+       int can_write_bl = false;
        int num_files = 0;
        int res;
        flash_file_t files[MAX_FILES];
@@ -92,7 +65,7 @@ int main(int argc, char **argv)
        for (int i = 2; i < argc; i++) {
                if (argv[i][0] == '-') {
                        if (!strcmp(argv[i], "-b")) {
-                               can_write_bl = 1;
+                               can_write_bl = true;
                        } else {
                                usage(argv[0]);
                                return -1;
@@ -110,12 +83,12 @@ int main(int argc, char **argv)
 
        char* serial_port_name = argv[1];
 
-       fprintf(stderr,"Waiting for Proxmark to appear on %s", serial_port_name);
-       do {
-               msleep(1000);
-               fprintf(stderr, ".");
-       } while (!OpenProxmark(0, serial_port_name));
-       fprintf(stderr," Found.\n");
+       if (!OpenProxmark(serial_port_name, true, 120, true)) {   // wait for 2 minutes
+               fprintf(stderr, "Could not find Proxmark on %s.\n\n", serial_port_name);
+               return -1;
+       } else {
+               fprintf(stderr," Found.\n");
+       }
 
        res = flash_start_flashing(can_write_bl, serial_port_name);
        if (res < 0)
@@ -137,7 +110,8 @@ int main(int argc, char **argv)
        if (res < 0)
                return -1;
 
-       CloseProxmark(serial_port_name);
+       // Stop the command thread.
+       CloseProxmark();
 
        fprintf(stderr, "All done.\n\n");
        fprintf(stderr, "Have a nice day!\n");
Impressum, Datenschutz