]> git.zerfleddert.de Git - hmcfgusb/blobdiff - flash-ota.c
flash-ota: fix typo
[hmcfgusb] / flash-ota.c
index 634e19b2b0db0c09af00ffb81d39114d6ad9d94c..b9b96cc05a3959c25e49647e1b7238c4fe08e61a 100644 (file)
 #include "culfw.h"
 #include "util.h"
 
-#define MAX_RETRIES    5
+#define MAX_RETRIES            5
+#define NORMAL_MAX_PAYLOAD     37
+#define LOWER_MAX_PAYLOAD      17
 
 extern char *optarg;
 
 uint32_t hmid = 0;
 uint32_t my_hmid = 0;
 
+/* Maximum payloadlen supported by IO */
+uint32_t max_payloadlen = NORMAL_MAX_PAYLOAD;
+
 enum device_type {
        DEVICE_TYPE_HMCFGUSB,
        DEVICE_TYPE_CULFW,
@@ -337,6 +342,7 @@ void flash_ota_syntax(char *prog)
        fprintf(stderr, "\nPossible options:\n");
        fprintf(stderr, "\t-c device\tenable CUL-mode with CUL at path \"device\"\n");
        fprintf(stderr, "\t-b bps\t\tuse CUL with speed \"bps\" (default: %u)\n", DEFAULT_CUL_BPS);
+       fprintf(stderr, "\t-l\t\tlower payloadlen (required for devices with little RAM, e.g. CUL v2 and CUL v4)\n");
        fprintf(stderr, "\t-h\t\tthis help\n");
 }
 
@@ -366,7 +372,7 @@ int main(int argc, char **argv)
 
        printf("HomeMatic OTA flasher version " VERSION "\n\n");
 
-       while((opt = getopt(argc, argv, "b:c:f:hs:")) != -1) {
+       while((opt = getopt(argc, argv, "b:c:f:hls:")) != -1) {
                switch (opt) {
                        case 'b':
                                bps = atoi(optarg);
@@ -377,6 +383,10 @@ int main(int argc, char **argv)
                        case 'f':
                                fw_file = optarg;
                                break;
+                       case 'l':
+                               printf("Reducing payload-len from %d to %d\n", max_payloadlen, LOWER_MAX_PAYLOAD);
+                               max_payloadlen = LOWER_MAX_PAYLOAD;
+                               break;
                        case 's':
                                serial = optarg;
                                break;
@@ -412,7 +422,7 @@ int main(int argc, char **argv)
                }
                dev.type = DEVICE_TYPE_CULFW;
 
-               printf("Requesting firmware-version\n");
+               printf("Requesting firmware version\n");
                culfw_send(dev.culfw, "\r\n", 2);
                culfw_flush(dev.culfw);
 
@@ -435,11 +445,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 +463,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 +477,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);
@@ -645,11 +655,11 @@ int main(int argc, char **argv)
                first = 1;
                cnt = 0;
                do {
-                       int payloadlen = 35;
+                       int payloadlen = max_payloadlen - 2;
                        int ack = 0;
 
                        if (first) {
-                               payloadlen = 37;
+                               payloadlen = max_payloadlen;
                                first = 0;
                        }
 
@@ -738,6 +748,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