FreeCalypso > hg > fc-usbser-tools
annotate fteeprom/fteeprom-prog.c @ 48:9cfe3223fbf8
doc/FTDI-EEPROM-tools: document -d options
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 11 Sep 2023 03:58:41 +0000 |
parents | a94bd4002076 |
children | ca2250b4833d |
rev | line source |
---|---|
20
43b8e88dae02
fteeprom-prog: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
1 /* |
43b8e88dae02
fteeprom-prog: 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 programs its EEPROM |
43b8e88dae02
fteeprom-prog: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
3 * with a raw hex image read from stdin or from a backup file. |
43b8e88dae02
fteeprom-prog: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
4 * |
43b8e88dae02
fteeprom-prog: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
5 * The present version has been converted to use our local libraries |
43b8e88dae02
fteeprom-prog: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
6 * (libftmini and libuwrap) instead of libftdi - thus the external dependency |
43b8e88dae02
fteeprom-prog: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
7 * is only libusb. |
43b8e88dae02
fteeprom-prog: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
8 */ |
43b8e88dae02
fteeprom-prog: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
9 |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <sys/types.h> |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <ctype.h> |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <string.h> |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <strings.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> |
20
43b8e88dae02
fteeprom-prog: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
17 #include <usb.h> |
43b8e88dae02
fteeprom-prog: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
18 #include "../libuwrap/find_dev.h" |
43b8e88dae02
fteeprom-prog: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
19 #include "../libuwrap/open_close.h" |
43b8e88dae02
fteeprom-prog: 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 |
45
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
22 char *device_selector, *input_filename; |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
23 int detach_num, ft232r_mode; |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 unsigned eeprom_size; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 u_short eeprom[256]; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 |
45
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
27 process_cmdline(argc, argv) |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
28 char **argv; |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
29 { |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
30 int c; |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
31 extern int optind; |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
32 extern char *optarg; |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
33 |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
34 while ((c = getopt(argc, argv, "d:r")) != EOF) { |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
35 switch (c) { |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
36 case 'd': |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
37 detach_num = atoi(optarg); |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
38 switch (detach_num) { |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
39 case 0: |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
40 case 1: |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
41 case 2: |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
42 case 4: |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
43 break; |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
44 default: |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
45 fprintf(stderr, "error: invalid -d argument\n"); |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
46 exit(1); |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
47 } |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
48 continue; |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
49 case 'r': |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
50 ft232r_mode = 1; |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
51 detach_num = 1; |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
52 continue; |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
53 default: |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
54 /* error msg already printed */ |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
55 exit(1); |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
56 } |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
57 } |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
58 if (argc < optind + 1 || argc > optind + 2) { |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
59 fprintf(stderr, |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
60 "usage: %s [options] device-selector [eeprom-image]\n", |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
61 argv[0]); |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
62 exit(1); |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
63 } |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
64 device_selector = argv[optind]; |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
65 input_filename = argv[optind + 1]; |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
66 } |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
67 |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 read_eeprom_common(inf, filename_for_errs) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 FILE *inf; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 char *filename_for_errs; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 char linebuf[1024], *cp; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 int lineno, rc; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 unsigned ptr = 0, input_off; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 for (cp = linebuf; isspace(*cp); cp++) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 ; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 if (*cp == '\0' || *cp == '#') |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 continue; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 if (ptr >= 256) { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 fprintf(stderr, |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 "%s line %d: maximum EEPROM size exceeded\n", |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 filename_for_errs, lineno); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 exit(1); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 rc = sscanf(linebuf, "%x: %hx %hx %hx %hx %hx %hx %hx %hx", |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 &input_off, eeprom + ptr, eeprom + ptr + 1, |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 eeprom + ptr + 2, eeprom + ptr + 3, |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 eeprom + ptr + 4, eeprom + ptr + 5, |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 eeprom + ptr + 6, eeprom + ptr + 7); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 if (rc != 9 || input_off != ptr * 2) { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 fprintf(stderr, "%s line %d: invalid input\n", |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 filename_for_errs, lineno); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 exit(1); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 ptr += 8; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 if (ptr != 64 && ptr != 128 && ptr != 256) { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 fprintf(stderr, "%s: not an EEPROM image of recognized size\n", |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 filename_for_errs); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 exit(1); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 eeprom_size = ptr; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 read_eeprom_from_file(filename) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 char *filename; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 FILE *inf; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 inf = fopen(filename, "r"); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 if (!inf) { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 perror(filename); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 exit(1); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 read_eeprom_common(inf, filename); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 fclose(inf); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 read_eeprom_from_stdin() |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 read_eeprom_common(stdin, "stdin"); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 main(argc, argv) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 char **argv; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 { |
20
43b8e88dae02
fteeprom-prog: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
129 struct usb_device *dev; |
43b8e88dae02
fteeprom-prog: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
130 usb_dev_handle *usbh; |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 unsigned n; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 |
45
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
133 process_cmdline(argc, argv); |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
134 if (input_filename) |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
135 read_eeprom_from_file(input_filename); |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
136 else |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 read_eeprom_from_stdin(); |
45
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
138 dev = find_usbdev_by_desc_string(device_selector); |
20
43b8e88dae02
fteeprom-prog: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
139 if (!dev) { |
43b8e88dae02
fteeprom-prog: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
140 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
|
141 exit(1); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 } |
41
940cde8a99b6
fteeprom-prog: we don't need to claim the interface
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
143 usbh = usb_open(dev); |
940cde8a99b6
fteeprom-prog: we don't need to claim the interface
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
144 if (!usbh) { |
940cde8a99b6
fteeprom-prog: we don't need to claim the interface
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
145 fprintf(stderr, "error: usb_open() failed\n"); |
940cde8a99b6
fteeprom-prog: we don't need to claim the interface
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
146 exit(1); |
940cde8a99b6
fteeprom-prog: we don't need to claim the interface
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
147 } |
45
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
148 if (detach_num) |
a94bd4002076
fteeprom-prog: implement -d option for interface detach
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
149 usbwrap_claim_all_ifs(usbh, detach_num); |
23
7e6dcceb5ee8
fteeprom-prog: implement -r option for FT232R mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
20
diff
changeset
|
150 if (ft232r_mode) |
7e6dcceb5ee8
fteeprom-prog: implement -r option for FT232R mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
20
diff
changeset
|
151 ft232r_eeprom_magic(usbh); |
20
43b8e88dae02
fteeprom-prog: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
152 for (n = 0; n < eeprom_size; n++) |
43b8e88dae02
fteeprom-prog: convert to new local libs
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
153 ftmini_write_eeprom_loc(usbh, n, eeprom[n]); |
41
940cde8a99b6
fteeprom-prog: we don't need to claim the interface
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
154 usb_close(usbh); |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 exit(0); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 } |