FreeCalypso > hg > fc-usbser-tools
comparison fteeprom/fteeprom-erase.c @ 21:af801ab43a33
fteeprom-erase: convert to new local libs
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 08 Sep 2023 23:47:50 +0000 |
parents | 11b8a30333b3 |
children | 2746b160afb7 |
comparison
equal
deleted
inserted
replaced
20:43b8e88dae02 | 21:af801ab43a33 |
---|---|
1 /* | |
2 * This program connects to an FTDI chip via libusb and commands that FTDI | |
3 * chip to erase its EEPROM in one fell swoop. This operation is known | |
4 * to work on FT2232C/D chips with 5V-powered EEPROMs, but is NOT appropriate | |
5 * for FT232R. This operation is also not recommended for external EEPROMs | |
6 * powered with 3.3V, as typically used with FT2232H. | |
7 * | |
8 * The present version has been converted to use our local libraries | |
9 * (libftmini and libuwrap) instead of libftdi - thus the external dependency | |
10 * is only libusb. | |
11 */ | |
12 | |
1 #include <sys/types.h> | 13 #include <sys/types.h> |
2 #include <stdio.h> | 14 #include <stdio.h> |
3 #include <stdlib.h> | 15 #include <stdlib.h> |
4 #include <unistd.h> | 16 #include <unistd.h> |
5 #include <ftdi.h> | 17 #include <usb.h> |
18 #include "../libuwrap/find_dev.h" | |
19 #include "../libuwrap/open_close.h" | |
20 #include "../libftmini/eeprom_func.h" | |
6 | 21 |
7 main(argc, argv) | 22 main(argc, argv) |
8 char **argv; | 23 char **argv; |
9 { | 24 { |
10 struct ftdi_context ftdi; | 25 struct usb_device *dev; |
26 usb_dev_handle *usbh; | |
11 | 27 |
12 if (argc != 2) { | 28 if (argc != 2) { |
13 fprintf(stderr, "usage: %s device-selector\n"); | 29 fprintf(stderr, "usage: %s device-selector\n"); |
14 exit(1); | 30 exit(1); |
15 } | 31 } |
16 ftdi_init(&ftdi); | 32 dev = find_usbdev_by_desc_string(argv[1]); |
17 if (ftdi_usb_open_string(&ftdi, argv[1]) < 0) { | 33 if (!dev) { |
18 fprintf(stderr, "FTDI USB open failed: %s\n", ftdi.error_str); | 34 fprintf(stderr, "error: specified USB device not found\n"); |
19 exit(1); | 35 exit(1); |
20 } | 36 } |
21 if (ftdi_erase_eeprom(&ftdi) < 0) { | 37 usbh = usbwrap_open_dev(dev, 1); |
22 fprintf(stderr, "EEPROM write error: %s\n", ftdi.error_str); | 38 ftmini_erase_eeprom(usbh); |
23 exit(1); | 39 usbwrap_close_dev(usbh); |
24 } | |
25 ftdi_usb_close(&ftdi); | |
26 exit(0); | 40 exit(0); |
27 } | 41 } |