1 /***************************************************************************
4 begin : Mon Apr 7 12:05:22 CEST 2003
5 copyright : (C) 2003-2014 by Intra2net AG and the libftdi developers
6 email : opensource@intra2net.com
7 SPDX-License-Identifier: GPL-2.0-only
8 ***************************************************************************/
10 /***************************************************************************
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License version 2 as *
14 * published by the Free Software Foundation. *
16 ***************************************************************************/
20 - Merge Uwe's eeprom tool. Current features:
21 - Init eeprom defaults based upon eeprom type
22 - Read -> Already there
23 - Write -> Already there
24 - Erase -> Already there
26 - Ability to find device by PID/VID, product name or serial
29 - Out-of-the-box compatibility with FTDI's eeprom tool configuration files
45 #include <ftdi_eeprom_version.h>
47 static int parse_cbus(cfg_t *cfg, cfg_opt_t *opt, const char *value, void *result)
49 static const char* options[] =
51 "TXDEN", "PWREN", "RXLED", "TXLED", "TXRXLED", "SLEEP", "CLK48",
52 "CLK24", "CLK12", "CLK6", "IOMODE", "BB_WR", "BB_RD"
56 for (i=0; i<sizeof(options)/sizeof(*options); i++)
58 if (!(strcmp(options[i], value)))
65 cfg_error(cfg, "Invalid %s option '%s'", cfg_opt_name(opt), value);
69 static int parse_group0_drive(cfg_t *cfg, cfg_opt_t *opt, const char *value, void *result)
71 static const char* options[] =
73 "4MA", "8MA", "12MA", "16MA"
77 for (i=0; i<sizeof(options)/sizeof(*options); i++)
79 if (!(strcasecmp(options[i], value)))
86 cfg_error(cfg, "Invalid %s option '%s'", cfg_opt_name(opt), value);
90 static int parse_cbush(cfg_t *cfg, cfg_opt_t *opt, const char *value, void *result)
92 static const char* options[] =
94 "TRISTATE", "TXLED", "RXLED", "TXRXLED", "PWREN", "SLEEP",
95 "DRIVE_0", "DRIVE1", "IOMODE", "TXDEN", "CLK30", "CLK15", "CLK7_5"
99 for (i=0; i<sizeof(options)/sizeof(*options); i++)
101 if (!(strcmp(options[i], value)))
108 cfg_error(cfg, "Invalid %s option '%s'", cfg_opt_name(opt), value);
112 static int parse_cbusx(cfg_t *cfg, cfg_opt_t *opt, const char *value, void *result)
114 static const char* options[] =
116 "TRISTATE", "TXLED", "RXLED", "TXRXLED", "PWREN", "SLEEP",
117 "DRIVE_0", "DRIVE1", "IOMODE", "TXDEN", "CLK24", "CLK12",
118 "CLK6", "BAT_DETECT", "BAT_DETECT_NEG", "I2C_TXE", "I2C_RXF", "VBUS_SENSE",
119 "BB_WR", "BB_RD", "TIME_STAMP", "AWAKE"
123 for (i=0; i<sizeof(options)/sizeof(*options); i++)
125 if (!(strcmp(options[i], value)))
132 cfg_error(cfg, "Invalid %s option '%s'", cfg_opt_name(opt), value);
136 static int parse_chtype(cfg_t *cfg, cfg_opt_t *opt, const char *value, void *result)
144 { "UART", CHANNEL_IS_UART },
145 { "FIFO", CHANNEL_IS_FIFO },
146 { "OPTO", CHANNEL_IS_OPTO },
147 { "CPU", CHANNEL_IS_CPU },
148 { "FT1284", CHANNEL_IS_FT1284}
152 for (i=0; i<sizeof(options)/sizeof(*options); i++)
154 if (!(strcmp(options[i].key, value)))
156 *(int *)result = options[i].opt;
161 cfg_error(cfg, "Invalid %s option '%s'", cfg_opt_name(opt), value);
166 * @brief Set eeprom value
168 * \param ftdi pointer to ftdi_context
169 * \param value_name Enum of the value to set
170 * \param value Value to set
172 * Function will abort the program on error
174 static void eeprom_set_value(struct ftdi_context *ftdi, enum ftdi_eeprom_value value_name, int value)
176 if (ftdi_set_eeprom_value(ftdi, value_name, value) < 0)
178 printf("Unable to set eeprom value %d: %s. Aborting\n", value_name, ftdi_get_error_string(ftdi));
184 * @brief Get eeprom value
186 * \param ftdi pointer to ftdi_context
187 * \param value_name Enum of the value to get
188 * \param value Value to get
190 * Function will abort the program on error
192 static void eeprom_get_value(struct ftdi_context *ftdi, enum ftdi_eeprom_value value_name, int *value)
194 if (ftdi_get_eeprom_value(ftdi, value_name, value) < 0)
196 printf("Unable to get eeprom value %d: %s. Aborting\n", value_name, ftdi_get_error_string(ftdi));
201 static void usage(const char *program)
203 fprintf(stderr, "Syntax: %s [...options...] <config-file>\n", program);
204 fprintf(stderr, "Valid Options:\n");
205 fprintf(stderr, "--device <description> Specify device to open by description string. One of:\n");
206 fprintf(stderr, " d:<devicenode>\n");
207 fprintf(stderr, " i:<vendor>:<product>\n");
208 fprintf(stderr, " i:<vendor>:<product>:<index>\n");
209 fprintf(stderr, " s:<vendor>:<product>:<serial>\n");
210 fprintf(stderr, "--read-eeprom Read eeprom and write to -filename- from config-file\n");
211 fprintf(stderr, "--build-eeprom Build eeprom image\n");
212 fprintf(stderr, "--erase-eeprom Erase eeprom\n");
213 fprintf(stderr, "--flash-eeprom Flash eeprom\n");
214 fprintf(stderr, "--verbose Print more information\n");
217 int main(int argc, char *argv[])
220 configuration options
224 CFG_INT("vendor_id", 0, 0),
225 CFG_INT("product_id", 0, 0),
226 CFG_BOOL("self_powered", cfg_true, 0),
227 CFG_BOOL("remote_wakeup", cfg_true, 0),
228 CFG_BOOL("in_is_isochronous", cfg_false, 0),
229 CFG_BOOL("out_is_isochronous", cfg_false, 0),
230 CFG_BOOL("suspend_pull_downs", cfg_false, 0),
231 CFG_BOOL("use_serial", cfg_false, 0),
232 CFG_BOOL("change_usb_version", cfg_false, 0),
233 CFG_INT("usb_version", 0, 0),
234 CFG_INT("default_pid", 0x6001, 0),
235 CFG_INT("max_power", 0, 0),
236 CFG_STR("manufacturer", "Acme Inc.", 0),
237 CFG_STR("product", "USB Serial Converter", 0),
238 CFG_STR("serial", "08-15", 0),
239 CFG_INT("eeprom_type", 0x00, 0),
240 CFG_STR("filename", "", 0),
241 CFG_BOOL("flash_raw", cfg_false, 0),
242 CFG_BOOL("high_current", cfg_false, 0),
243 CFG_INT_CB("cbus0", -1, 0, parse_cbus),
244 CFG_INT_CB("cbus1", -1, 0, parse_cbus),
245 CFG_INT_CB("cbus2", -1, 0, parse_cbus),
246 CFG_INT_CB("cbus3", -1, 0, parse_cbus),
247 CFG_INT_CB("cbus4", -1, 0, parse_cbus),
248 CFG_INT_CB("cbush0", -1, 0, parse_cbush),
249 CFG_INT_CB("cbush1", -1, 0, parse_cbush),
250 CFG_INT_CB("cbush2", -1, 0, parse_cbush),
251 CFG_INT_CB("cbush3", -1, 0, parse_cbush),
252 CFG_INT_CB("cbush4", -1, 0, parse_cbush),
253 CFG_INT_CB("cbush5", -1, 0, parse_cbush),
254 CFG_INT_CB("cbush6", -1, 0, parse_cbush),
255 CFG_INT_CB("cbush7", -1, 0, parse_cbush),
256 CFG_INT_CB("cbush8", -1, 0, parse_cbush),
257 CFG_INT_CB("cbush9", -1, 0, parse_cbush),
258 CFG_INT_CB("cbusx0", -1, 0, parse_cbusx),
259 CFG_INT_CB("cbusx1", -1, 0, parse_cbusx),
260 CFG_INT_CB("cbusx2", -1, 0, parse_cbusx),
261 CFG_INT_CB("cbusx3", -1, 0, parse_cbusx),
262 CFG_INT_CB("group0_drive", -1, 0, parse_group0_drive),
263 CFG_BOOL("invert_txd", cfg_false, 0),
264 CFG_BOOL("invert_rxd", cfg_false, 0),
265 CFG_BOOL("invert_rts", cfg_false, 0),
266 CFG_BOOL("invert_cts", cfg_false, 0),
267 CFG_BOOL("invert_dtr", cfg_false, 0),
268 CFG_BOOL("invert_dsr", cfg_false, 0),
269 CFG_BOOL("invert_dcd", cfg_false, 0),
270 CFG_BOOL("invert_ri", cfg_false, 0),
271 CFG_INT_CB("cha_type", -1, 0, parse_chtype),
272 CFG_INT_CB("chb_type", -1, 0, parse_chtype),
273 CFG_BOOL("cha_vcp", cfg_true, 0),
274 CFG_BOOL("chb_vcp", cfg_true, 0),
275 CFG_BOOL("chc_vcp", cfg_true, 0),
276 CFG_BOOL("chd_vcp", cfg_true, 0),
277 CFG_BOOL("cha_rs485", cfg_false, 0),
278 CFG_BOOL("chb_rs485", cfg_false, 0),
279 CFG_BOOL("chc_rs485", cfg_false, 0),
280 CFG_BOOL("chd_rs485", cfg_false, 0),
281 CFG_FUNC("include", &cfg_include),
282 CFG_INT("user_data_addr", 0x18, 0),
283 CFG_STR("user_data_file", "", 0),
297 const char *cfg_filename = NULL;
298 const char *device_description = NULL;
299 const char *user_data_file = NULL;
300 char *user_data_buffer = NULL;
302 const int max_eeprom_size = 256;
303 int my_eeprom_size = 0;
304 unsigned char *eeprom_buf = NULL;
312 struct ftdi_context *ftdi = NULL;
314 printf("\nFTDI eeprom generator v%s\n", EEPROM_VERSION_STRING);
315 printf ("(c) Intra2net AG and the libftdi developers <opensource@intra2net.com>\n");
317 for (i = 1; i < argc; i++) {
320 cfg_filename = argv[i];
322 else if (!strcmp(argv[i], "--device"))
329 device_description = argv[++i];
331 else if (!strcmp(argv[i], "--read-eeprom"))
333 command = COMMAND_READ;
335 else if (!strcmp(argv[i], "--erase-eeprom"))
337 command = COMMAND_ERASE;
339 else if (!strcmp(argv[i], "--flash-eeprom"))
341 command = COMMAND_FLASH;
343 else if (!strcmp(argv[i], "--build-eeprom"))
345 command = COMMAND_BUILD;
347 else if (!strcmp(argv[i], "--verbose"))
364 if ((fp = fopen(cfg_filename, "r")) == NULL)
366 printf ("Can't open configuration file\n");
371 cfg = cfg_init(opts, 0);
372 cfg_parse(cfg, cfg_filename);
373 filename = cfg_getstr(cfg, "filename");
375 if (cfg_getbool(cfg, "self_powered") && cfg_getint(cfg, "max_power") > 0)
376 printf("Hint: Self powered devices should have a max_power setting of 0.\n");
378 if ((ftdi = ftdi_new()) == 0)
380 fprintf(stderr, "Failed to allocate ftdi structure :%s \n",
381 ftdi_get_error_string(ftdi));
385 if (device_description != NULL)
387 i = ftdi_usb_open_string(ftdi, device_description);
391 printf("Unable to find FTDI device with description: %s\n",
393 printf("Error code: %d (%s)\n", i, ftdi_get_error_string(ftdi));
397 else if (command > 0)
399 int vendor_id = cfg_getint(cfg, "vendor_id");
400 int product_id = cfg_getint(cfg, "product_id");
402 i = ftdi_usb_open(ftdi, vendor_id, product_id);
406 int default_pid = cfg_getint(cfg, "default_pid");
407 printf("Unable to find FTDI devices under given vendor/product id: 0x%X/0x%X\n", vendor_id, product_id);
408 printf("Error code: %d (%s)\n", i, ftdi_get_error_string(ftdi));
409 printf("Retrying with default FTDI pid=%#04x.\n", default_pid);
411 i = ftdi_usb_open(ftdi, 0x0403, default_pid);
414 printf("Error: %s\n", ftdi->error_str);
419 ftdi_eeprom_initdefaults (ftdi, cfg_getstr(cfg, "manufacturer"),
420 cfg_getstr(cfg, "product"),
421 cfg_getstr(cfg, "serial"));
423 printf("FTDI read eeprom: %d\n", ftdi_read_eeprom(ftdi));
424 eeprom_get_value(ftdi, CHIP_SIZE, &my_eeprom_size);
425 printf("EEPROM size: %d\n", my_eeprom_size);
427 if (command == COMMAND_READ)
429 ftdi_eeprom_decode(ftdi, verbose);
431 eeprom_buf = malloc(my_eeprom_size);
432 ftdi_get_eeprom_buf(ftdi, eeprom_buf, my_eeprom_size);
434 if (eeprom_buf == NULL)
436 fprintf(stderr, "Malloc failed, aborting\n");
439 if (filename != NULL && strlen(filename) > 0)
441 FILE *fp = fopen (filename, "wb");
445 fwrite(eeprom_buf, 1, my_eeprom_size, fp);
449 fprintf(stderr, "Could not open output file %s: %s\n", filename, strerror(errno));
453 printf("Warning: Not writing eeprom, you must supply a valid filename\n");
459 eeprom_set_value(ftdi, VENDOR_ID, cfg_getint(cfg, "vendor_id"));
460 eeprom_set_value(ftdi, PRODUCT_ID, cfg_getint(cfg, "product_id"));
462 eeprom_set_value(ftdi, SELF_POWERED, cfg_getbool(cfg, "self_powered"));
463 eeprom_set_value(ftdi, REMOTE_WAKEUP, cfg_getbool(cfg, "remote_wakeup"));
464 eeprom_set_value(ftdi, MAX_POWER, cfg_getint(cfg, "max_power"));
466 eeprom_set_value(ftdi, IN_IS_ISOCHRONOUS, cfg_getbool(cfg, "in_is_isochronous"));
467 eeprom_set_value(ftdi, OUT_IS_ISOCHRONOUS, cfg_getbool(cfg, "out_is_isochronous"));
468 eeprom_set_value(ftdi, SUSPEND_PULL_DOWNS, cfg_getbool(cfg, "suspend_pull_downs"));
470 eeprom_set_value(ftdi, USE_SERIAL, cfg_getbool(cfg, "use_serial"));
471 eeprom_set_value(ftdi, USE_USB_VERSION, cfg_getbool(cfg, "change_usb_version"));
472 eeprom_set_value(ftdi, USB_VERSION, cfg_getint(cfg, "usb_version"));
473 eeprom_set_value(ftdi, CHIP_TYPE, cfg_getint(cfg, "eeprom_type"));
475 eeprom_set_value(ftdi, HIGH_CURRENT, cfg_getbool(cfg, "high_current"));
477 if (ftdi->type == TYPE_R)
479 if (cfg_getint(cfg, "cbus0") != -1)
480 eeprom_set_value(ftdi, CBUS_FUNCTION_0, cfg_getint(cfg, "cbus0"));
481 if (cfg_getint(cfg, "cbus1") != -1)
482 eeprom_set_value(ftdi, CBUS_FUNCTION_1, cfg_getint(cfg, "cbus1"));
483 if (cfg_getint(cfg, "cbus2") != -1)
484 eeprom_set_value(ftdi, CBUS_FUNCTION_2, cfg_getint(cfg, "cbus2"));
485 if (cfg_getint(cfg, "cbus3") != -1)
486 eeprom_set_value(ftdi, CBUS_FUNCTION_3, cfg_getint(cfg, "cbus3"));
487 if (cfg_getint(cfg, "cbus4") != -1)
488 eeprom_set_value(ftdi, CBUS_FUNCTION_4, cfg_getint(cfg, "cbus4"));
490 else if (ftdi->type == TYPE_232H)
492 if (cfg_getint(cfg, "cbush0") != -1)
493 eeprom_set_value(ftdi, CBUS_FUNCTION_0, cfg_getint(cfg, "cbush0"));
494 if (cfg_getint(cfg, "cbush1") != -1)
495 eeprom_set_value(ftdi, CBUS_FUNCTION_1, cfg_getint(cfg, "cbush1"));
496 if (cfg_getint(cfg, "cbush2") != -1)
497 eeprom_set_value(ftdi, CBUS_FUNCTION_2, cfg_getint(cfg, "cbush2"));
498 if (cfg_getint(cfg, "cbush3") != -1)
499 eeprom_set_value(ftdi, CBUS_FUNCTION_3, cfg_getint(cfg, "cbush3"));
500 if (cfg_getint(cfg, "cbush4") != -1)
501 eeprom_set_value(ftdi, CBUS_FUNCTION_4, cfg_getint(cfg, "cbush4"));
502 if (cfg_getint(cfg, "cbush5") != -1)
503 eeprom_set_value(ftdi, CBUS_FUNCTION_5, cfg_getint(cfg, "cbush5"));
504 if (cfg_getint(cfg, "cbush6") != -1)
505 eeprom_set_value(ftdi, CBUS_FUNCTION_6, cfg_getint(cfg, "cbush6"));
506 if (cfg_getint(cfg, "cbush7") != -1)
507 eeprom_set_value(ftdi, CBUS_FUNCTION_7, cfg_getint(cfg, "cbush7"));
508 if (cfg_getint(cfg, "cbush8") != -1)
509 eeprom_set_value(ftdi, CBUS_FUNCTION_8, cfg_getint(cfg, "cbush8"));
510 if (cfg_getint(cfg, "cbush9") != -1)
511 eeprom_set_value(ftdi, CBUS_FUNCTION_9, cfg_getint(cfg, "cbush9"));
512 if (cfg_getint(cfg, "group0_drive") != -1)
513 eeprom_set_value(ftdi, GROUP0_DRIVE, cfg_getint(cfg, "group0_drive"));
515 else if (ftdi->type == TYPE_230X)
517 if (cfg_getint(cfg, "cbusx0") != -1)
518 eeprom_set_value(ftdi, CBUS_FUNCTION_0, cfg_getint(cfg, "cbusx0"));
519 if (cfg_getint(cfg, "cbusx1") != -1)
520 eeprom_set_value(ftdi, CBUS_FUNCTION_1, cfg_getint(cfg, "cbusx1"));
521 if (cfg_getint(cfg, "cbusx2") != -1)
522 eeprom_set_value(ftdi, CBUS_FUNCTION_2, cfg_getint(cfg, "cbusx2"));
523 if (cfg_getint(cfg, "cbusx3") != -1)
524 eeprom_set_value(ftdi, CBUS_FUNCTION_3, cfg_getint(cfg, "cbusx3"));
528 if (cfg_getbool(cfg, "invert_rxd")) invert |= INVERT_RXD;
529 if (cfg_getbool(cfg, "invert_txd")) invert |= INVERT_TXD;
530 if (cfg_getbool(cfg, "invert_rts")) invert |= INVERT_RTS;
531 if (cfg_getbool(cfg, "invert_cts")) invert |= INVERT_CTS;
532 if (cfg_getbool(cfg, "invert_dtr")) invert |= INVERT_DTR;
533 if (cfg_getbool(cfg, "invert_dsr")) invert |= INVERT_DSR;
534 if (cfg_getbool(cfg, "invert_dcd")) invert |= INVERT_DCD;
535 if (cfg_getbool(cfg, "invert_ri")) invert |= INVERT_RI;
536 eeprom_set_value(ftdi, INVERT, invert);
538 if (cfg_getint(cfg, "cha_type") != -1)
539 eeprom_set_value(ftdi, CHANNEL_A_TYPE, cfg_getint(cfg, "cha_type"));
540 if (cfg_getint(cfg, "chb_type") != -1)
541 eeprom_set_value(ftdi, CHANNEL_B_TYPE, cfg_getint(cfg, "chb_type"));
543 eeprom_set_value(ftdi, CHANNEL_A_DRIVER,
544 cfg_getbool(cfg, "cha_vcp") ? DRIVER_VCP : 0);
545 eeprom_set_value(ftdi, CHANNEL_B_DRIVER,
546 cfg_getbool(cfg, "chb_vcp") ? DRIVER_VCP : 0);
547 eeprom_set_value(ftdi, CHANNEL_C_DRIVER,
548 cfg_getbool(cfg, "chc_vcp") ? DRIVER_VCP : 0);
549 eeprom_set_value(ftdi, CHANNEL_D_DRIVER,
550 cfg_getbool(cfg, "chd_vcp") ? DRIVER_VCP : 0);
552 eeprom_set_value(ftdi, CHANNEL_A_RS485, cfg_getbool(cfg, "cha_rs485"));
553 eeprom_set_value(ftdi, CHANNEL_B_RS485, cfg_getbool(cfg, "chb_rs485"));
554 eeprom_set_value(ftdi, CHANNEL_C_RS485, cfg_getbool(cfg, "chc_rs485"));
555 eeprom_set_value(ftdi, CHANNEL_D_RS485, cfg_getbool(cfg, "chd_rs485"));
557 /* Arbitrary user data */
558 eeprom_set_value(ftdi, USER_DATA_ADDR, cfg_getint(cfg, "user_data_addr"));
559 user_data_file = cfg_getstr(cfg, "user_data_file");
560 if (user_data_file && strlen(user_data_file) > 0)
565 printf("User data file: %s\n", user_data_file);
566 /* Allocate a buffer for the user data */
567 user_data_buffer = (char *)malloc(max_eeprom_size);
568 if (user_data_buffer == NULL)
570 fprintf(stderr, "Malloc failed, aborting\n");
574 if (stat(user_data_file, &st))
576 printf ("Can't stat user data file %s.\n", user_data_file);
579 if (st.st_size > max_eeprom_size)
580 printf("Warning: %s is too big, only reading %d bytes\n",
581 user_data_file, max_eeprom_size);
582 /* Read the user data file, no more than max_eeprom_size bytes */
583 FILE *fp = fopen(user_data_file, "rb");
586 printf ("Can't open user data file %s.\n", user_data_file);
589 data_size = fread(user_data_buffer, 1, max_eeprom_size, fp);
593 printf ("Can't read user data file %s.\n", user_data_file);
596 printf("User data size: %d\n", data_size);
598 ftdi_set_eeprom_user_data(ftdi, user_data_buffer, data_size);
602 if (command == COMMAND_ERASE)
604 printf("FTDI erase eeprom: %d\n", ftdi_erase_eeprom(ftdi));
607 size_check = ftdi_eeprom_build(ftdi);
608 eeprom_get_value(ftdi, CHIP_SIZE, &my_eeprom_size);
610 if (size_check == -1)
612 printf ("Sorry, the eeprom can only contain %d bytes.\n", my_eeprom_size);
615 else if (size_check < 0)
617 printf ("ftdi_eeprom_build(): error: %d\n", size_check);
622 printf ("Used eeprom space: %d bytes\n", my_eeprom_size-size_check);
625 if (command == COMMAND_FLASH)
627 if (cfg_getbool(cfg, "flash_raw"))
629 if (filename != NULL && strlen(filename) > 0)
631 eeprom_buf = malloc(max_eeprom_size);
632 FILE *fp = fopen(filename, "rb");
635 printf ("Can't open eeprom file %s.\n", filename);
638 my_eeprom_size = fread(eeprom_buf, 1, max_eeprom_size, fp);
640 if (my_eeprom_size < 128)
642 printf ("Can't read eeprom file %s.\n", filename);
646 printf("Flashing raw eeprom from file %s (%d bytes)\n",
647 filename, my_eeprom_size);
649 ftdi_set_eeprom_buf(ftdi, eeprom_buf, my_eeprom_size);
652 printf ("ERROR: flash_raw mode enabled, but no eeprom filename "
653 "given in config file.\n");
657 printf ("FTDI write eeprom: %d\n", ftdi_write_eeprom(ftdi));
658 libusb_reset_device(ftdi->usb_dev);
662 if (filename != NULL && strlen(filename) > 0 && !cfg_getbool(cfg, "flash_raw"))
664 fp = fopen(filename, "w");
667 printf ("Can't write eeprom file.\n");
671 printf ("Writing to file: %s\n", filename);
673 if (eeprom_buf == NULL)
674 eeprom_buf = malloc(my_eeprom_size);
675 ftdi_get_eeprom_buf(ftdi, eeprom_buf, my_eeprom_size);
677 fwrite(eeprom_buf, my_eeprom_size, 1, fp);
684 if (user_data_buffer)
685 free(user_data_buffer);
688 printf("FTDI close: %d\n", ftdi_usb_close(ftdi));