--
Uwe Bonnes bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Institut fuer Kernphysik Schlossgartenstrasse 9 64289 Darmstadt
--------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------
>From 812cac945ae7c81752092151b3b47d609e6eaa9d Mon Sep 17 00:00:00 2001
From: Uwe Bonnes <bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 2 Jul 2011 13:34:00 +0200
Subject: Try to inihibit programming EEPROM with data for a different device
---
src/ftdi.c | 14 +++++++++++++-
src/ftdi.h | 4 ++++
2 files changed, 17 insertions(+), 1 deletions(-)
diff --git a/src/ftdi.c b/src/ftdi.c
index 4dc47bd..0833285 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -63,6 +63,8 @@ static void ftdi_usb_close_internal (struct ftdi_context
*ftdi)
{
libusb_close (ftdi->usb_dev);
ftdi->usb_dev = NULL;
+ if(ftdi->eeprom)
+ ftdi->eeprom->initialized_for_connected_device = 0;
}
}
@@ -2175,7 +2177,7 @@ int ftdi_set_error_char(struct ftdi_context *ftdi,
}
/**
- Init eeprom with default values.
+ Init eeprom with default values for the connected device
\param ftdi pointer to ftdi_context
\param manufacturer String to use as Manufacturer
\param product String to use as Product description
@@ -2184,6 +2186,7 @@ int ftdi_set_error_char(struct ftdi_context *ftdi,
\retval 0: all fine
\retval -1: No struct ftdi_context
\retval -2: No struct ftdi_eeprom
+ \retval -3: No connected device or device not yet opened
*/
int ftdi_eeprom_initdefaults(struct ftdi_context *ftdi, char * manufacturer,
char * product, char * serial)
@@ -2196,6 +2199,9 @@ int ftdi_eeprom_initdefaults(struct ftdi_context *ftdi,
char * manufacturer,
if (ftdi->eeprom == NULL)
ftdi_error_return(-2,"No struct ftdi_eeprom");
+ if (ftdi->usb_dev == NULL)
+ ftdi_error_return(-3, "No connected device or device not yet opened");
+
eeprom = ftdi->eeprom;
memset(eeprom, 0, sizeof(struct ftdi_eeprom));
@@ -2267,6 +2273,7 @@ int ftdi_eeprom_initdefaults(struct ftdi_context *ftdi,
char * manufacturer,
}
eeprom->size = -1;
}
+ eeprom->initialized_for_connected_device = 1;
return 0;
}
/*FTD2XX doesn't check for values not fitting in the ACBUS Signal oprtions*/
@@ -3676,6 +3683,7 @@ int ftdi_write_eeprom_location(struct ftdi_context *ftdi,
int eeprom_addr,
\retval 0: all fine
\retval -1: read failed
\retval -2: USB device unavailable
+ \retval -3: EEPROM not initialized for the connected device;
*/
int ftdi_write_eeprom(struct ftdi_context *ftdi)
{
@@ -3685,6 +3693,10 @@ int ftdi_write_eeprom(struct ftdi_context *ftdi)
if (ftdi == NULL || ftdi->usb_dev == NULL)
ftdi_error_return(-2, "USB device unavailable");
+
+ if(ftdi->eeprom->initialized_for_connected_device == 0)
+ ftdi_error_return(-3, "EEPROM not initialized for the connected
device");
+
eeprom = ftdi->eeprom->buf;
/* These commands were traced while running MProg */
diff --git a/src/ftdi.h b/src/ftdi.h
index c0a3d3d..cf6b312 100644
--- a/src/ftdi.h
+++ b/src/ftdi.h
@@ -200,6 +200,10 @@ struct ftdi_eeprom
int vendor_id;
/** product id */
int product_id;
+
+ /** Was the eeprom structure initialized for the actual
+ connected device? **/
+ int initialized_for_connected_device;
/** self powered */
int self_powered;
--
1.7.3.4
--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx
|