The default eeprom size is 128 bytes - if we have a larger one, we need
a way to specify the fact.
Using ftdi_read_eeprom() / ftdi_eeprom_decode() to get the actual eeprom type
is not an option as ftdi_eeprom_decode() would overwrite the values set
by ftdi_eeprom_initdefaults()
Signed-off-by: Anders Larsen <al@xxxxxxxxxxx>
---
ftdi_eeprom/main.c | 25 ++++++++++++++++++-------
1 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/ftdi_eeprom/main.c b/ftdi_eeprom/main.c
index ad7de93..5127eeb 100644
--- a/ftdi_eeprom/main.c
+++ b/ftdi_eeprom/main.c
@@ -16,7 +16,6 @@
/*
TODO:
- - Remove 128 bytes limit
- Merge Uwe's eeprom tool. Current features:
- Init eeprom defaults based upon eeprom type
- Read -> Already there
@@ -118,6 +117,7 @@ int main(int argc, char *argv[])
CFG_STR("manufacturer", "Acme Inc.", 0),
CFG_STR("product", "USB Serial Converter", 0),
CFG_STR("serial", "08-15", 0),
+ CFG_INT("eeprom_type", 0x00, 0),
CFG_STR("filename", "", 0),
CFG_BOOL("flash_raw", cfg_false, 0),
CFG_BOOL("high_current", cfg_false, 0),
@@ -143,6 +143,7 @@ int main(int argc, char *argv[])
*/
int _read = 0, _erase = 0, _flash = 0;
+ const int max_eeprom_size = 256;
int my_eeprom_size = 0;
unsigned char *eeprom_buf = NULL;
char *filename;
@@ -231,12 +232,11 @@ int main(int argc, char *argv[])
ftdi_eeprom_initdefaults (ftdi, cfg_getstr(cfg, "manufacturer"),
cfg_getstr(cfg, "product"),
cfg_getstr(cfg, "serial"));
-
+
printf("FTDI read eeprom: %d\n", ftdi_read_eeprom(ftdi));
eeprom_get_value(ftdi, CHIP_SIZE, &my_eeprom_size);
- // TODO: Do we know the eeprom size already?
printf("EEPROM size: %d\n", my_eeprom_size);
-
+
if (_read > 0)
{
ftdi_eeprom_decode(ftdi, 0 /* debug: 1 */);
@@ -278,7 +278,7 @@ int main(int argc, char *argv[])
eeprom_set_value(ftdi, USE_SERIAL, cfg_getbool(cfg, "use_serial"));
eeprom_set_value(ftdi, USE_USB_VERSION, cfg_getbool(cfg,
"change_usb_version"));
eeprom_set_value(ftdi, USB_VERSION, cfg_getint(cfg, "usb_version"));
-
+ eeprom_set_value(ftdi, CHIP_TYPE, cfg_getint(cfg, "eeprom_type"));
eeprom_set_value(ftdi, HIGH_CURRENT, cfg_getbool(cfg, "high_current"));
eeprom_set_value(ftdi, CBUS_FUNCTION_0, str_to_cbus(cfg_getstr(cfg,
"cbus0"), 13));
@@ -312,6 +312,7 @@ int main(int argc, char *argv[])
}
size_check = ftdi_eeprom_build(ftdi);
+ eeprom_get_value(ftdi, CHIP_SIZE, &my_eeprom_size);
if (size_check == -1)
{
@@ -332,10 +333,20 @@ int main(int argc, char *argv[])
{
if (filename != NULL && strlen(filename) > 0)
{
- eeprom_buf = malloc(my_eeprom_size);
+ eeprom_buf = malloc(max_eeprom_size);
FILE *fp = fopen(filename, "rb");
- fread(eeprom_buf, 1, my_eeprom_size, fp);
+ if (fp == NULL)
+ {
+ printf ("Can't open eeprom file %s.\n", filename);
+ exit (-1);
+ }
+ my_eeprom_size = fread(eeprom_buf, 1, max_eeprom_size, fp);
fclose(fp);
+ if (my_eeprom_size < 128)
+ {
+ printf ("Can't read eeprom file %s.\n", filename);
+ exit (-1);
+ }
ftdi_set_eeprom_buf(ftdi, eeprom_buf, my_eeprom_size);
}
--
1.7.0.4
--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx
|