The branch, eeprom-new has been updated
via 200bd3ed2e1d2389217be44c0adc728909a2a100 (commit)
from b95e46548cdf96ef21b3de2a1b3d55ceeca12075 (commit)
- Log -----------------------------------------------------------------
commit 200bd3ed2e1d2389217be44c0adc728909a2a100
Author: Thomas Jarosch <thomas.jarosch@xxxxxxxxxxxxx>
Date: Sat Jan 15 18:51:38 2011 +0100
Fix raw eeprom buffer handling
-----------------------------------------------------------------------
Summary of changes:
ftdi_eeprom/main.c | 21 +++++++++++++++------
src/ftdi.c | 4 ++++
2 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/ftdi_eeprom/main.c b/ftdi_eeprom/main.c
index 03b24b3..25a3a5a 100644
--- a/ftdi_eeprom/main.c
+++ b/ftdi_eeprom/main.c
@@ -16,7 +16,6 @@
/*
TODO:
- - Use new eeprom get/set functions
- Remove 128 bytes limit
- Merge Uwe's eeprom tool. Current features:
- Init eeprom defaults based upon eeprom type
@@ -143,7 +142,10 @@ int main(int argc, char *argv[])
normal variables
*/
int _read = 0, _erase = 0, _flash = 0;
- unsigned char eeprom_buf[128]; // TODO: Kill this and
look for other hardcoded places of 128 bytes
+
+ const int my_eeprom_size = 128; /* TODO: Kill this. Check
with Uwe how we can determine the eeprom size properly
+ because it's
initialized with -1. Maybe assume 128 bytes per default? */
+ unsigned char eeprom_buf[my_eeprom_size];
char *filename;
int size_check;
int i, argc_filename;
@@ -306,8 +308,10 @@ int main(int argc, char *argv[])
if (filename != NULL && strlen(filename) > 0)
{
+ ftdi_get_eeprom_buf(ftdi, eeprom_buf, my_eeprom_size);
+
FILE *fp = fopen (filename, "wb");
- fwrite (eeprom_buf, 1, 128, fp);
+ fwrite (eeprom_buf, 1, my_eeprom_size, fp);
fclose (fp);
}
else
@@ -335,7 +339,7 @@ int main(int argc, char *argv[])
}
else
{
- printf ("Used eeprom space: %d bytes\n", 128-size_check);
+ printf ("Used eeprom space: %d bytes\n", my_eeprom_size-size_check);
}
if (_flash > 0)
@@ -345,8 +349,11 @@ int main(int argc, char *argv[])
if (filename != NULL && strlen(filename) > 0)
{
FILE *fp = fopen(filename, "rb");
- fread(eeprom_buf, 1, 128, fp);
+ fread(eeprom_buf, 1, my_eeprom_size, fp);
fclose(fp);
+
+ /* TODO: Dirty hack. Create an API for this. How about
ftdi_set_eeprom_buf()? */
+ memcpy(ftdi->eeprom->buf, eeprom_buf, my_eeprom_size);
}
}
printf ("FTDI write eeprom: %d\n", ftdi_write_eeprom(ftdi));
@@ -364,7 +371,9 @@ int main(int argc, char *argv[])
else
printf ("Writing to file: %s\n", filename);
- fwrite(eeprom_buf, 128, 1, fp);
+ ftdi_get_eeprom_buf(ftdi, eeprom_buf, my_eeprom_size);
+
+ fwrite(eeprom_buf, my_eeprom_size, 1, fp);
fclose(fp);
}
diff --git a/src/ftdi.c b/src/ftdi.c
index 4cc55e4..6de60be 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -3252,12 +3252,16 @@ int ftdi_set_eeprom_value(struct ftdi_context *ftdi,
enum ftdi_eeprom_value valu
\retval 0: All fine
\retval -1: struct ftdi_contxt or ftdi_eeprom missing
+ \retval -2: Not enough room to store eeprom
*/
int ftdi_get_eeprom_buf(struct ftdi_context *ftdi, unsigned char * buf, int
size)
{
if (!ftdi || !(ftdi->eeprom))
ftdi_error_return(-1, "No appropriate structure");
+ if (!buf || size < ftdi->eeprom->size)
+ ftdi_error_return(-1, "Not enough room to store eeprom");
+
// Only copy up to FTDI_MAX_EEPROM_SIZE bytes
if (size > FTDI_MAX_EEPROM_SIZE)
size = FTDI_MAX_EEPROM_SIZE;
hooks/post-receive
--
port libftdi to libusb-1.0
--
libftdi-git - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi-git+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx
|