From 870259ecc121c5574fe119db0b3dad3416deca79 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 8 Jan 2016 19:14:12 +0100 Subject: check software version between firmware and CLI --- commandline/i2c-util.c | 32 ++++++++++++++++++++++++++++---- firmware/usbconfig.h | 4 +++- global_config.h | 2 ++ 3 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 global_config.h diff --git a/commandline/i2c-util.c b/commandline/i2c-util.c index 772aae7..426d7d8 100644 --- a/commandline/i2c-util.c +++ b/commandline/i2c-util.c @@ -23,6 +23,7 @@ obtained from http://libusb.sourceforge.net/. #include /* this is libusb, see http://libusb.sourceforge.net/ */ #include "i2c-util.h" +#include "../global_config.h" #define USBDEV_SHARED_VENDOR 0x16C0 /* VOTI */ #define USBDEV_SHARED_PRODUCT 0x05DC /* Obdev's free shared PID */ @@ -81,12 +82,14 @@ static int usbGetStringAscii(usb_dev_handle * dev, int index, int langid, char #define USB_ERROR_IO 3 static int usbOpenDevice(usb_dev_handle ** device, int vendor, char *vendorName, - int product, char *productName) + int product, char *productName, int upperversion, + int lowerversion) { struct usb_bus *bus; struct usb_device *dev; usb_dev_handle *handle = NULL; int errorCode = USB_ERROR_NOTFOUND; + int major, minor; static int didUsbInit = 0; if (!didUsbInit) { @@ -154,6 +157,25 @@ static int usbOpenDevice(usb_dev_handle ** device, int vendor, char *vendorName, if (handle != NULL) { errorCode = 0; *device = handle; + + minor = dev->descriptor.bcdDevice & 0xff; + major = dev->descriptor.bcdDevice >> 8; + + if (major != USBDEV_VERSION_MAJOR) { + fprintf(stderr, + "Error: Firmware and host software version are not compatible\n" + "Firmware: %2d.%02d\n Host: %2d.%02d\n" + "Please upgrade the firmware or downgrade the CLI\n", + major, minor, USBDEV_VERSION_MAJOR, USBDEV_VERSION_MINOR); + errorCode = -1; + } + else if (minor != USBDEV_VERSION_MINOR) { + fprintf(stderr, + "Note: Firmware and host software version may be incompatible\n" + "Firmware: %2d.%02d\n Host: %2d.%02d\n" + "Please upgrade the firmware or downgrade the CLI\n", + major, minor, USBDEV_VERSION_MAJOR, USBDEV_VERSION_MINOR); + } } return errorCode; } @@ -340,10 +362,12 @@ void i2c_init() usb_init(); if (usbOpenDevice (&handle, USBDEV_SHARED_VENDOR, "finalrewind.org", - USBDEV_SHARED_PRODUCT, "VUSB-I2C") != 0) { + USBDEV_SHARED_PRODUCT, "VUSB-I2C", 0, 1) != 0) { fprintf(stderr, - "Could not find USB device \"VUSB-I2C\" with vid=0x%x pid=0x%x\n", - USBDEV_SHARED_VENDOR, USBDEV_SHARED_PRODUCT); + "Could not find USB device \"VUSB-I2C\" with vid=0x%x pid=0x%x" + " version~%d.%02d\n", + USBDEV_SHARED_VENDOR, USBDEV_SHARED_PRODUCT, + USBDEV_VERSION_MAJOR, USBDEV_VERSION_MINOR); exit(1); } } diff --git a/firmware/usbconfig.h b/firmware/usbconfig.h index 585d16d..d9c9bf3 100644 --- a/firmware/usbconfig.h +++ b/firmware/usbconfig.h @@ -11,6 +11,8 @@ #ifndef __usbconfig_h_included__ #define __usbconfig_h_included__ +#include "../global_config.h" + /* General Description: This file contains parts of the USB driver which can be configured and can or @@ -138,7 +140,7 @@ the newest features and options. * you use obdev's free shared VID/PID pair. Be sure to read the rules in * USBID-License.txt! */ -#define USB_CFG_DEVICE_VERSION 0x00, 0x01 +#define USB_CFG_DEVICE_VERSION USBDEV_VERSION_MINOR, USBDEV_VERSION_MAJOR /* Version number of the device: Minor number first, then major number. */ #define USB_CFG_VENDOR_NAME 'f', 'i', 'n', 'a', 'l', 'r', 'e', 'w', 'i', 'n', 'd', '.', 'o', 'r', 'g' diff --git a/global_config.h b/global_config.h new file mode 100644 index 0000000..16c1918 --- /dev/null +++ b/global_config.h @@ -0,0 +1,2 @@ +#define USBDEV_VERSION_MAJOR 0 +#define USBDEV_VERSION_MINOR 1 -- cgit v1.2.3