]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/flash.c
fix WaitForResponse (without timeout)
[proxmark3-svn] / client / flash.c
index e43ebd1b6932e07ecf5dcb29fa821c066d92f77d..f3d2f420934a87c0282571502ebbcc63a536e430 100644 (file)
@@ -40,7 +40,7 @@ static const uint8_t elf_ident[] = {
 
 // Turn PHDRs into flasher segments, checking for PHDR sanity and merging adjacent
 // unaligned segments if needed
-static int build_segs_from_phdrs(flash_file_t *ctx, FILE *fd, Elf32_Phdr *phdrs, int num_phdrs)
+static int build_segs_from_phdrs(flash_file_t *ctx, FILE *fd, Elf32_Phdr *phdrs, uint16_t num_phdrs)
 {
        Elf32_Phdr *phdr = phdrs;
        flash_seg_t *seg;
@@ -185,13 +185,13 @@ static int check_segs(flash_file_t *ctx, int can_write_bl) {
        return 0;
 }
 
+
 // Load an ELF file and prepare it for flashing
-int flash_load(flash_file_t *ctx, const char *name, bool can_write_bl)
-{
+int flash_load(flash_file_t *ctx, const char *name, bool can_write_bl) {
        FILE *fd = NULL;
        Elf32_Ehdr ehdr;
        Elf32_Phdr *phdrs = NULL;
-       int num_phdrs;
+       uint16_t num_phdrs;
        int res;
 
        fd = fopen(name, "rb");
@@ -267,10 +267,10 @@ fail:
        return -1;
 }
 
+
 // Get the state of the proxmark, backwards compatible
-static int get_proxmark_state(uint32_t *state)
-{
-       UsbCommand c;
+static int get_proxmark_state(uint32_t *state) {
+       UsbCommand c = {0};
        c.cmd = CMD_DEVICE_INFO;
        SendCommand(&c);
        UsbCommand resp;
@@ -300,9 +300,9 @@ static int get_proxmark_state(uint32_t *state)
        return 0;
 }
 
+
 // Enter the bootloader to be able to start flashing
-static int enter_bootloader(char *serial_port_name)
-{
+static int enter_bootloader(char *serial_port_name) {
        uint32_t state;
 
        if (get_proxmark_state(&state) < 0)
@@ -314,7 +314,7 @@ static int enter_bootloader(char *serial_port_name)
        }
 
        if (state & DEVICE_INFO_FLAG_CURRENT_MODE_OS) {
-               fprintf(stderr,"Entering bootloader...\n");
+               fprintf(stderr, "Entering bootloader...\n");
                UsbCommand c;
                memset(&c, 0, sizeof (c));
 
@@ -336,7 +336,9 @@ static int enter_bootloader(char *serial_port_name)
                msleep(100);
                CloseProxmark();
 
-               bool opened = OpenProxmark(serial_port_name, true, 120, true);   // wait for 2 minutes
+               msleep(1000); // wait for OS to detect device disconnect.
+
+               bool opened = OpenProxmark(serial_port_name, true, 120);   // wait for 2 minutes
                if (opened) {
                        fprintf(stderr," Found.\n");
                        return 0;
@@ -350,6 +352,7 @@ static int enter_bootloader(char *serial_port_name)
        return -1;
 }
 
+
 static int wait_for_ack(void)
 {
        UsbCommand ack;
@@ -361,11 +364,11 @@ static int wait_for_ack(void)
        return 0;
 }
 
+
 // Go into flashing mode
 int flash_start_flashing(int enable_bl_writes,char *serial_port_name)
 {
        uint32_t state;
-
        if (enter_bootloader(serial_port_name) < 0)
                return -1;
 
Impressum, Datenschutz