FreeCalypso > hg > fc-usbser-tools
annotate fteeprom/fteeprom-read.c @ 26:49239efbdcc8
rm fteeprom/test/fteeprom-prog-bad
When the magic command sequence for FT232R was added to libftdi-based
fteeprom-prog, a version without this magic sequence was preserved in
fteeprom-prog-bad. However, the new minilib version of fteeprom-prog
operates without this magic sequence by default (as appropriate for
FT2232D, FT2232H etc) and needs to be run with -r option to invoke
FT232R-specific mode with the necessary magic.
Anyone who needs fteeprom-prog-bad for study or experimentation
can find it in freecalypso-hwlab Hg repository where it was originally
developed.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 09 Sep 2023 16:06:56 +0000 |
parents | 1d76deae1e74 |
children | bb1d0956b0a8 |
rev | line source |
---|---|
16
1d76deae1e74
fteeprom-read: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
1 /* |
1d76deae1e74
fteeprom-read: 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 reads out its EEPROM. |
1d76deae1e74
fteeprom-read: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
3 * The present version has been converted to use our local libraries |
1d76deae1e74
fteeprom-read: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
4 * (libftmini and libuwrap) instead of libftdi - thus the external dependency |
1d76deae1e74
fteeprom-read: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
5 * is only libusb. |
1d76deae1e74
fteeprom-read: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
6 */ |
1d76deae1e74
fteeprom-read: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
7 |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <sys/types.h> |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <string.h> |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <strings.h> |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdio.h> |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <stdlib.h> |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <unistd.h> |
16
1d76deae1e74
fteeprom-read: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
14 #include <usb.h> |
1d76deae1e74
fteeprom-read: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
15 #include "../libuwrap/find_dev.h" |
1d76deae1e74
fteeprom-read: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
16 #include "../libuwrap/open_close.h" |
1d76deae1e74
fteeprom-read: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
17 #include "../libftmini/eeprom_func.h" |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 char *device_selector; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 unsigned eeprom_size = 64; |
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 process_cmdline(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 { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 int c; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 extern int optind; |
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 while ((c = getopt(argc, argv, "bB")) != EOF) { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 switch (c) { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 case 'b': |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 eeprom_size = 128; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 continue; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 case 'B': |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 eeprom_size = 256; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 continue; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 default: |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 /* error msg already printed */ |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 exit(1); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 if (argc != optind + 1) { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 fprintf(stderr, "usage: %s [options] device-selector\n", |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 argv[0]); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 exit(1); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 device_selector = argv[optind]; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 main(argc, argv) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 char **argv; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 { |
16
1d76deae1e74
fteeprom-read: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
52 struct usb_device *dev; |
1d76deae1e74
fteeprom-read: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
53 usb_dev_handle *usbh; |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 u_short word; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 unsigned n, col; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 process_cmdline(argc, argv); |
16
1d76deae1e74
fteeprom-read: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
58 dev = find_usbdev_by_desc_string(device_selector); |
1d76deae1e74
fteeprom-read: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
59 if (!dev) { |
1d76deae1e74
fteeprom-read: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
60 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
|
61 exit(1); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 } |
16
1d76deae1e74
fteeprom-read: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
63 usbh = usbwrap_open_dev(dev, 1); |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 for (n = 0; n < eeprom_size; n++) { |
16
1d76deae1e74
fteeprom-read: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
65 word = ftmini_read_eeprom_loc(usbh, n); |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 col = n & 7; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 if (col == 0) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 printf("%02X:", n * 2); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 printf(" %04X", word); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 if (col == 7) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 putchar('\n'); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 } |
16
1d76deae1e74
fteeprom-read: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
73 usbwrap_close_dev(usbh); |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 exit(0); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 } |