# HG changeset patch # User Mychaela Falconia # Date 1694212814 0 # Node ID 43b8e88dae02ff868940acd7d5db074c0f1006b8 # Parent d420375243c9b1269b5b47bfe05a30ad9a767911 fteeprom-prog: convert to new local libs diff -r d420375243c9 -r 43b8e88dae02 fteeprom/Makefile --- a/fteeprom/Makefile Thu Sep 07 23:24:04 2023 +0000 +++ b/fteeprom/Makefile Fri Sep 08 22:40:14 2023 +0000 @@ -25,8 +25,8 @@ fteeprom-erase: fteeprom-erase.c ${CC} ${CFLAGS} -o $@ $@.c -lftdi -fteeprom-prog: fteeprom-prog.c - ${CC} ${CFLAGS} -o $@ $@.c -lftdi +fteeprom-prog: fteeprom-prog.o ${LIBS} + ${CC} ${CFLAGS} -o $@ $@.o ${LIBS} -lusb fteeprom-read: fteeprom-read.o ${LIBS} ${CC} ${CFLAGS} -o $@ $@.o ${LIBS} -lusb diff -r d420375243c9 -r 43b8e88dae02 fteeprom/fteeprom-prog.c --- a/fteeprom/fteeprom-prog.c Thu Sep 07 23:24:04 2023 +0000 +++ b/fteeprom/fteeprom-prog.c Fri Sep 08 22:40:14 2023 +0000 @@ -1,3 +1,12 @@ +/* + * This program connects to an FTDI chip via libusb and programs its EEPROM + * with a raw hex image read from stdin or from a backup file. + * + * The present version has been converted to use our local libraries + * (libftmini and libuwrap) instead of libftdi - thus the external dependency + * is only libusb. + */ + #include #include #include @@ -5,7 +14,10 @@ #include #include #include -#include +#include +#include "../libuwrap/find_dev.h" +#include "../libuwrap/open_close.h" +#include "../libftmini/eeprom_func.h" unsigned eeprom_size; u_short eeprom[256]; @@ -71,8 +83,8 @@ main(argc, argv) char **argv; { - struct ftdi_context ftdi; - u_short modem_status; + struct usb_device *dev; + usb_dev_handle *usbh; unsigned n; if (argc < 2 || argc > 3) { @@ -84,34 +96,15 @@ read_eeprom_from_file(argv[2]); else read_eeprom_from_stdin(); - ftdi_init(&ftdi); - if (ftdi_usb_open_string(&ftdi, argv[1]) < 0) { - fprintf(stderr, "FTDI USB open failed: %s\n", ftdi.error_str); - exit(1); - } - /* magic sequence apparently required for FT232R */ - if (ftdi_usb_reset(&ftdi) < 0) { - fprintf(stderr, "ftdi_usb_reset() failed: %s\n", - ftdi.error_str); - exit(1); - } - if (ftdi_poll_modem_status(&ftdi, &modem_status) < 0) { - fprintf(stderr, "ftdi_poll_modem_status() failed: %s\n", - ftdi.error_str); + dev = find_usbdev_by_desc_string(argv[1]); + if (!dev) { + fprintf(stderr, "error: specified USB device not found\n"); exit(1); } - if (ftdi_set_latency_timer(&ftdi, 0x77) < 0) { - fprintf(stderr, "ftdi_set_latency_timer() failed: %s\n", - ftdi.error_str); - exit(1); - } - for (n = 0; n < eeprom_size; n++) { - if (ftdi_write_eeprom_location(&ftdi, n, eeprom[n]) < 0) { - fprintf(stderr, "EEPROM write error: %s\n", - ftdi.error_str); - exit(1); - } - } - ftdi_usb_close(&ftdi); + usbh = usbwrap_open_dev(dev, 1); + /* FIXME: reimplement FT232R magic sequence */ + for (n = 0; n < eeprom_size; n++) + ftmini_write_eeprom_loc(usbh, n, eeprom[n]); + usbwrap_close_dev(usbh); exit(0); }