]> git.zerfleddert.de Git - hmcfgusb/commitdiff
reboot before flashing and retry a bit more often
authorMichael Gernoth <michael@gernoth.net>
Sun, 16 Feb 2014 14:30:00 +0000 (15:30 +0100)
committerMichael Gernoth <michael@gernoth.net>
Sun, 16 Feb 2014 14:30:00 +0000 (15:30 +0100)
flash-hmcfgusb.c
flash-ota.c
version.h

index 244559d6e1d61dc1cf7bd499376f1db3a80ec06b..45d467f08451aa63d76df62fec8dc3136f9eaabb 100644 (file)
@@ -97,13 +97,11 @@ int main(int argc, char **argv)
                fprintf(stderr, "\nWaiting for device to reappear...\n");
 
                do {
                fprintf(stderr, "\nWaiting for device to reappear...\n");
 
                do {
-                       sleep(2);
-               } while ((dev = hmcfgusb_init(parse_hmcfgusb, &rdata)) == NULL);
-
-               if (!dev->bootloader) {
-                       fprintf(stderr, "Can't enter bootloader, giving up!\n");
-                       exit(EXIT_FAILURE);
-               }
+                       if (dev) {
+                               hmcfgusb_close(dev);
+                       }
+                       sleep(1);
+               } while (((dev = hmcfgusb_init(parse_hmcfgusb, &rdata)) == NULL) || (!dev->bootloader));
        }
 
        printf("\nHM-CFG-USB opened.\n\n");
        }
 
        printf("\nHM-CFG-USB opened.\n\n");
index cbda024a9b8269c6bb2617d068708db6c7b4933e..034ae785bcfcfc79e71c8455af1956f6dd1a0c6d 100644 (file)
@@ -41,6 +41,8 @@
 #include "version.h"
 #include "hmcfgusb.h"
 
 #include "version.h"
 #include "hmcfgusb.h"
 
+#define MAX_RETRIES    5
+
 uint32_t hmid = 0;
 uint32_t my_hmid = 0;
 
 uint32_t hmid = 0;
 uint32_t my_hmid = 0;
 
@@ -135,7 +137,13 @@ int send_hm_message(struct hmcfgusb_dev *dev, struct recv_data *rdata, uint8_t *
                            ((rdata->status & 0xff) == 0x02)) {
                                break;
                        } else {
                            ((rdata->status & 0xff) == 0x02)) {
                                break;
                        } else {
-                               fprintf(stderr, "\nInvalid status: %04x\n", rdata->status);
+                               if ((rdata->status & 0xff00) == 0x0400) {
+                                       fprintf(stderr, "\nOut of credits!\n");
+                               } else if ((rdata->status & 0xff) == 0x08) {
+                                       fprintf(stderr, "\nMissing ACK!\n");
+                               } else {
+                                       fprintf(stderr, "\nInvalid status: %04x\n", rdata->status);
+                               }
                                return 0;
                        }
                }
                                return 0;
                        }
                }
@@ -228,12 +236,34 @@ int main(int argc, char **argv)
                exit(EXIT_FAILURE);
        }
 
                exit(EXIT_FAILURE);
        }
 
+       printf("\nRebooting HM-CFG-USB to avoid running out of credits\n\n");
+
+       if (!dev->bootloader) {
+               printf("HM-CFG-USB not in bootloader mode, entering bootloader.\n");
+               hmcfgusb_enter_bootloader(dev);
+               printf("Waiting for device to reappear...\n");
+
+               do {
+                       if (dev) {
+                               hmcfgusb_close(dev);
+                       }
+                       sleep(1);
+               } while (((dev = hmcfgusb_init(parse_hmcfgusb, &rdata)) == NULL) || (!dev->bootloader));
+       }
+
        if (dev->bootloader) {
        if (dev->bootloader) {
-               fprintf(stderr, "\nHM-CFG-USB in bootloader mode, aborting!\n");
-               exit(EXIT_FAILURE);
+               printf("HM-CFG-USB in bootloader mode, rebooting\n");
+               hmcfgusb_leave_bootloader(dev);
+
+               do {
+                       if (dev) {
+                               hmcfgusb_close(dev);
+                       }
+                       sleep(1);
+               } while (((dev = hmcfgusb_init(parse_hmcfgusb, &rdata)) == NULL) || (dev->bootloader));
        }
 
        }
 
-       printf("\nHM-CFG-USB opened\n\n");
+       printf("\n\nHM-CFG-USB opened\n\n");
 
        memset(out, 0, sizeof(out));
        out[0] = 'K';
 
        memset(out, 0, sizeof(out));
        out[0] = 'K';
@@ -424,7 +454,7 @@ int main(int argc, char **argv)
                        } else {
                                pos = &(fw->fw[block][2]);
                                cnt++;
                        } else {
                                pos = &(fw->fw[block][2]);
                                cnt++;
-                               if (cnt == 3) {
+                               if (cnt == MAX_RETRIES) {
                                        fprintf(stderr, "\nToo many errors, giving up!\n");
                                        exit(EXIT_FAILURE);
                                } else {
                                        fprintf(stderr, "\nToo many errors, giving up!\n");
                                        exit(EXIT_FAILURE);
                                } else {
index aa8235f6622e441be81b9de210b02830d2cb07c1..c5a8e5701931996b8f04492a0466d1b52512b4c5 100644 (file)
--- a/version.h
+++ b/version.h
@@ -1 +1 @@
-#define VERSION        "0.093-git"
+#define VERSION        "0.094-git"
Impressum, Datenschutz