FreeCalypso > hg > freecalypso-hwlab
annotate fteeprom/ftee-gen2232h.c @ 54:47dbfd66bd58
fteeprom-prog: added magic sequence from libftdi
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 09 May 2019 22:15:20 +0000 |
parents | 6a2886f9943e |
children |
rev | line source |
---|---|
40
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 #include <sys/types.h> |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 #include <ctype.h> |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 #include <string.h> |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 #include <strings.h> |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <stdio.h> |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdlib.h> |
44
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
7 #include <unistd.h> |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
8 |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
9 char *configfile, *serial; |
40
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 u_short vid = 0x0403, pid = 0x6010; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 char *manuf, *product; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 u_char byte00 = 0x08, byte01 = 0x08; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 u_char byte08 = 0x80, byte0A = 0x00; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 unsigned maxpower = 100; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 u_char group0, group1, group2, group3; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
44
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
18 u_short eeprom[128]; |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
19 u_char eeprom_chip = 0x46; |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
20 unsigned eeprom_size, eeprom_string_ptr; |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
21 |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
22 process_cmdline(argc, argv) |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
23 char **argv; |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
24 { |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
25 int c; |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
26 extern int optind; |
40
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 |
44
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
28 while ((c = getopt(argc, argv, "bB")) != EOF) { |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
29 switch (c) { |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
30 case 'b': |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
31 eeprom_chip = 0x56; |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
32 continue; |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
33 case 'B': |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
34 eeprom_chip = 0x66; |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
35 continue; |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
36 default: |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
37 /* error msg already printed */ |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
38 exit(1); |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
39 } |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
40 } |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
41 if (argc < optind + 1 || argc > optind + 2) { |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
42 fprintf(stderr, |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
43 "usage: %s [options] config-file [serial-num]\n", |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
44 argv[0]); |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
45 exit(1); |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
46 } |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
47 configfile = argv[optind]; |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
48 serial = argv[optind+1]; |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
49 } |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
50 |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
51 init_eeprom_size() |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
52 { |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
53 if (eeprom_chip == 0x46) { |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
54 eeprom_size = 64; |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
55 eeprom_string_ptr = 0x0D; |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
56 } else { |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
57 eeprom_size = 128; |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
58 eeprom_string_ptr = 0x4D; |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
59 } |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
60 } |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
61 |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
62 read_config_file() |
40
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 { |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 FILE *inf; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 char linebuf[1024]; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 int lineno; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 char *cp, *np; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 |
44
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
69 inf = fopen(configfile, "r"); |
40
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 if (!inf) { |
44
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
71 perror(configfile); |
40
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 exit(1); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 } |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 cp = index(linebuf, '\n'); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 if (!cp) { |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 fprintf(stderr, |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 "%s line %d: too long or unterminated\n", |
44
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
79 configfile, lineno); |
40
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 exit(1); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 } |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 *cp = '\0'; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 for (cp = linebuf; isspace(*cp); cp++) |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 ; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 if (*cp == '\0' || *cp == '#') |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 continue; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 for (np = cp; *cp && !isspace(*cp); cp++) |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 ; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 if (*cp) |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 *cp++ = '\0'; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 while (isspace(*cp)) |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 cp++; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 if (*cp == '\0' || *cp == '#') { |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 fprintf(stderr, |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 "%s line %d: \"%s\" setting without argument\n", |
44
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
96 configfile, lineno, np); |
40
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 exit(1); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 } |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 if (!strcmp(np, "vid")) |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 vid = strtoul(cp, 0, 16); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 else if (!strcmp(np, "pid")) |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 pid = strtoul(cp, 0, 16); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 else if (!strcmp(np, "manuf")) |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 manuf = strdup(cp); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 else if (!strcmp(np, "product")) |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 product = strdup(cp); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 else if (!strcmp(np, "byte00")) |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 byte00 = strtoul(cp, 0, 16); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 else if (!strcmp(np, "byte01")) |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 byte01 = strtoul(cp, 0, 16); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 else if (!strcmp(np, "byte08")) |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 byte08 = strtoul(cp, 0, 16); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 else if (!strcmp(np, "byte0A")) |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 byte0A = strtoul(cp, 0, 16); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 else if (!strcmp(np, "maxpower")) |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 maxpower = strtoul(cp, 0, 10); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 else if (!strcmp(np, "group0")) |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 group0 = strtoul(cp, 0, 16); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 else if (!strcmp(np, "group1")) |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 group1 = strtoul(cp, 0, 16); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 else if (!strcmp(np, "group2")) |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 group2 = strtoul(cp, 0, 16); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 else if (!strcmp(np, "group3")) |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 group3 = strtoul(cp, 0, 16); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 else { |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 fprintf(stderr, "%s line %d: unknown \"%s\" setting\n", |
44
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
127 configfile, lineno, np); |
40
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 exit(1); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 } |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 } |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 fclose(inf); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 if (!manuf) { |
44
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
133 fprintf(stderr, "error: manuf not set in %s\n", configfile); |
40
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 exit(1); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 } |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 if (!product) { |
44
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
137 fprintf(stderr, "error: product not set in %s\n", configfile); |
40
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 exit(1); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 } |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 } |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 write_string(str) |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 char *str; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 { |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 unsigned longlen, startptr; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 |
44
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
147 if (eeprom_size - 1 - eeprom_string_ptr < strlen(str) + 1) { |
40
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 fprintf(stderr, "error: strings are too long\n"); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 exit(1); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 } |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 longlen = strlen(str) * 2 + 2; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 startptr = eeprom_string_ptr; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 eeprom[eeprom_string_ptr++] = 0x0300 | longlen; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 while (*str) |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 eeprom[eeprom_string_ptr++] = *str++; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 return (longlen << 8) | 0x80 | (startptr << 1); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 } |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 |
44
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
159 fill_eeprom() |
40
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 { |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 u_char byte09; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 if (serial) |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 byte0A |= 0x08; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 else |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 byte0A &= 0xF7; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 byte09 = maxpower / 2; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 eeprom[0] = (byte01 << 8) | byte00; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 eeprom[1] = vid; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 eeprom[2] = pid; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 eeprom[3] = 0x0700; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 eeprom[4] = (byte09 << 8) | byte08; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 eeprom[5] = byte0A; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 eeprom[6] = (group3 << 12) | (group2 << 8) | (group1 << 4) | group0; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 eeprom[7] = write_string(manuf); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 eeprom[8] = write_string(product); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 if (serial) |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 eeprom[9] = write_string(serial); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 else |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 eeprom[9] = 0; |
44
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
181 eeprom[12] = eeprom_chip; |
40
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 } |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 do_checksum() |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 { |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 u_short chksum = 0xAAAA; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 unsigned n; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 |
44
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
189 for (n = 0; n < eeprom_size - 1; n++) { |
40
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 chksum ^= eeprom[n]; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 chksum = (chksum << 1) | (chksum >> 15); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 } |
44
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
193 eeprom[n] = chksum; |
40
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 } |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 emit_output() |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 { |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 unsigned n, col; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 |
44
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
200 for (n = 0; n < eeprom_size; n++) { |
40
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 col = n & 7; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 if (col == 0) |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 printf("%02X:", n * 2); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 printf(" %04X", eeprom[n]); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 if (col == 7) |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 putchar('\n'); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 } |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 } |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 main(argc, argv) |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 char **argv; |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 { |
44
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
213 process_cmdline(argc, argv); |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
214 read_config_file(); |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
215 init_eeprom_size(); |
6a2886f9943e
ftee-gen2232h: same change as in ftee-gen2232c
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
216 fill_eeprom(); |
40
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 do_checksum(); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
218 emit_output(); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
219 exit(0); |
d150d4704ff5
fteeprom: ftee-gen2232h program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
220 } |