From 865d5b4c443741f2bed531fdca0b5864ed629552 Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Sun, 16 Feb 2014 09:38:22 +0100 Subject: [PATCH 1/1] check hmcfgusb firmware before trying to switch speed --- flash-ota.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/flash-ota.c b/flash-ota.c index f8431a6..fd6cd6e 100644 --- a/flash-ota.c +++ b/flash-ota.c @@ -53,6 +53,7 @@ struct recv_data { enum message_type message_type; uint16_t status; int speed; + uint16_t hmcfgusb_version; }; static int parse_hmcfgusb(uint8_t *buf, int buf_len, void *data) @@ -82,6 +83,9 @@ static int parse_hmcfgusb(uint8_t *buf, int buf_len, void *data) case 'G': rdata->speed = buf[1]; break; + case 'H': + rdata->hmcfgusb_version = (buf[11] << 8) | buf[12]; + break; default: break; } @@ -229,6 +233,30 @@ int main(int argc, char **argv) printf("\nHM-CFG-USB opened\n\n"); + memset(out, 0, sizeof(out)); + out[0] = 'K'; + hmcfgusb_send(dev, out, sizeof(out), 1); + + while (1) { + errno = 0; + pfd = hmcfgusb_poll(dev, 1); + if ((pfd < 0) && errno) { + if (errno != ETIMEDOUT) { + perror("\n\nhmcfgusb_poll"); + exit(EXIT_FAILURE); + } + } + if (rdata.hmcfgusb_version) + break; + } + + if (rdata.hmcfgusb_version < 0x3c7) { + fprintf(stderr, "HM-CFG-USB firmware too low: %u < 967\n", rdata.hmcfgusb_version); + exit(EXIT_FAILURE); + } + + printf("HM-CFG-USB firmware version: %u\n", rdata.hmcfgusb_version); + if (!switch_speed(dev, &rdata, 10)) { fprintf(stderr, "Can't switch speed!\n"); exit(EXIT_FAILURE); -- 2.39.5