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