]> cvs.zerfleddert.de Git - hmcfgusb/blobdiff - flash-ota.c
hmland: don't impersonate HM-CFG-LAN by default.
[hmcfgusb] / flash-ota.c
index 31e2ab5eced06184ef446b7b266679c3253525be..754cc29a8a3bb1f16d12ea6069f058a16640e517 100644 (file)
@@ -228,7 +228,7 @@ int send_hm_message(struct ota_dev *dev, struct recv_data *rdata, uint8_t *msg)
                                        }
                                }
                                errno = 0;
-                               pfd = hmcfgusb_poll(dev->hmcfgusb, 1);
+                               pfd = hmcfgusb_poll(dev->hmcfgusb, 1000);
                                if ((pfd < 0) && errno) {
                                        if (errno != ETIMEDOUT) {
                                                perror("\n\nhmcfgusb_poll");
@@ -263,7 +263,7 @@ int send_hm_message(struct ota_dev *dev, struct recv_data *rdata, uint8_t *msg)
                                        int pfd;
                                        do {
                                                errno = 0;
-                                               pfd = culfw_poll(dev->culfw, 1);
+                                               pfd = culfw_poll(dev->culfw, 200);
                                                if ((pfd < 0) && errno) {
                                                        if (errno != ETIMEDOUT) {
                                                                perror("\n\nculfw_poll");
@@ -305,7 +305,7 @@ static int switch_speed(struct ota_dev *dev, struct recv_data *rdata, uint8_t sp
 
                        while (1) {
                                errno = 0;
-                               pfd = hmcfgusb_poll(dev->hmcfgusb, 1);
+                               pfd = hmcfgusb_poll(dev->hmcfgusb, 1000);
                                if ((pfd < 0) && errno) {
                                        if (errno != ETIMEDOUT) {
                                                perror("\n\nhmcfgusb_poll");
@@ -420,7 +420,7 @@ int main(int argc, char **argv)
                        culfw_send(dev.culfw, "V\r\n", 3);
 
                        errno = 0;
-                       pfd = culfw_poll(dev.culfw, 1);
+                       pfd = culfw_poll(dev.culfw, 1000);
                        if ((pfd < 0) && errno) {
                                if (errno != ETIMEDOUT) {
                                        perror("\n\nhmcfgusb_poll");
@@ -435,11 +435,9 @@ int main(int argc, char **argv)
                        (rdata.version >> 8) & 0xff,
                        rdata.version & 0xff);
 
-               if (rdata.version < 0x0139) {
-                       fprintf(stderr, "\nThis version does _not_ support firmware upgrade mode!\n");
+               if (rdata.version < 0x013a) {
+                       fprintf(stderr, "\nThis version does _not_ support firmware upgrade mode, you need at least 1.58!\n");
                        exit(EXIT_FAILURE);
-               } else if (rdata.version < 0x0140) {
-                       printf("\n*** This version probably not supports firmware upgrade mode! ***\n\n");
                }
        } else {
                hmcfgusb_set_debug(debug);
@@ -455,11 +453,12 @@ int main(int argc, char **argv)
 
                if (!dev.hmcfgusb->bootloader) {
                        printf("HM-CFG-USB not in bootloader mode, entering bootloader.\n");
-                       hmcfgusb_enter_bootloader(dev.hmcfgusb);
                        printf("Waiting for device to reappear...\n");
 
                        do {
                                if (dev.hmcfgusb) {
+                                       if (!dev.hmcfgusb->bootloader)
+                                               hmcfgusb_enter_bootloader(dev.hmcfgusb);
                                        hmcfgusb_close(dev.hmcfgusb);
                                }
                                sleep(1);
@@ -468,10 +467,11 @@ int main(int argc, char **argv)
 
                if (dev.hmcfgusb->bootloader) {
                        printf("HM-CFG-USB in bootloader mode, rebooting\n");
-                       hmcfgusb_leave_bootloader(dev.hmcfgusb);
 
                        do {
                                if (dev.hmcfgusb) {
+                                       if (dev.hmcfgusb->bootloader)
+                                               hmcfgusb_leave_bootloader(dev.hmcfgusb);
                                        hmcfgusb_close(dev.hmcfgusb);
                                }
                                sleep(1);
@@ -486,7 +486,7 @@ int main(int argc, char **argv)
 
                while (1) {
                        errno = 0;
-                       pfd = hmcfgusb_poll(dev.hmcfgusb, 1);
+                       pfd = hmcfgusb_poll(dev.hmcfgusb, 1000);
                        if ((pfd < 0) && errno) {
                                if (errno != ETIMEDOUT) {
                                        perror("\n\nhmcfgusb_poll");
@@ -516,11 +516,11 @@ int main(int argc, char **argv)
                errno = 0;
                switch (dev.type) {
                        case DEVICE_TYPE_CULFW:
-                               pfd = culfw_poll(dev.culfw, 1);
+                               pfd = culfw_poll(dev.culfw, 1000);
                                break;
                        case DEVICE_TYPE_HMCFGUSB:
                        default:
-                               pfd = hmcfgusb_poll(dev.hmcfgusb, 1);
+                               pfd = hmcfgusb_poll(dev.hmcfgusb, 1000);
                                break;
                }
 
@@ -713,11 +713,11 @@ int main(int argc, char **argv)
                errno = 0;
                switch(dev.type) {
                        case DEVICE_TYPE_CULFW:
-                               pfd = culfw_poll(dev.culfw, 1);
+                               pfd = culfw_poll(dev.culfw, 1000);
                                break;
                        case DEVICE_TYPE_HMCFGUSB:
                        default:
-                               pfd = hmcfgusb_poll(dev.hmcfgusb, 1);
+                               pfd = hmcfgusb_poll(dev.hmcfgusb, 1000);
                                break;
                }
                if ((pfd < 0) && errno) {
@@ -738,6 +738,7 @@ int main(int argc, char **argv)
        switch(dev.type) {
                case DEVICE_TYPE_HMCFGUSB:
                        hmcfgusb_close(dev.hmcfgusb);
+                       hmcfgusb_exit();
                        break;
                case DEVICE_TYPE_CULFW:
                        culfw_close(dev.culfw);
Impressum, Datenschutz