From 8c305104a0da9da7f3703b648bea194314a94a5e Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Fri, 21 Nov 2014 17:14:39 +0100 Subject: mkii: Check for supported image types --- src/mkii.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/mkii.c') diff --git a/src/mkii.c b/src/mkii.c index 0214c7a..47b0c66 100644 --- a/src/mkii.c +++ b/src/mkii.c @@ -86,6 +86,9 @@ int mkii_init(struct usb_device_info * dev) { struct mkii_message * msg; enum device device; int ret; + char * newptr; + char * ptr; + enum image_type type; printf("Initializing Mk II protocol...\n"); @@ -117,6 +120,34 @@ int mkii_init(struct usb_device_info * dev) { dev->hwrev = mkii_get_hwrev(dev); + memcpy(msg->data, "/update/supported_images", sizeof("/update/supported_images")-1); + ret = mkii_send_receive(dev->udev, MKII_GET_IMAGES, msg, sizeof("/update/supported_images")-1, msg, sizeof(buf)); + if ( ret < 2 || msg->data[0] != 0 ) { + ERROR("Cannot get supported image types"); + return -1; + } + + msg->data[ret] = 0; + ptr = msg->data + 1; + + printf("Supported images by current device configuration:"); + + while ( ptr && *ptr ) { + newptr = strchr(ptr, ','); + if ( newptr ) { + *newptr = 0; + ++newptr; + } + type = image_type_from_string(ptr); + if ( type != IMAGE_UNKNOWN ) { + dev->data |= (1 << type); + printf(" %s", ptr); + } + ptr = newptr; + } + + printf("\n"); + return 0; } @@ -155,6 +186,11 @@ int mkii_flash_image(struct usb_device_info * dev, struct image * image) { ERROR("Not implemented yet"); return -1; + if ( ! ( dev->data & (1 << image->type) ) ) { + ERROR("Flashing image %s is not supported in current device configuration", image_type_to_string(image->type)); + return -1; + } + msg = (struct mkii_message *)buf; msg1 = (struct mkii_message *)buf1; ptr = msg->data; -- cgit v1.2.3