FreeCalypso > hg > fc-usbser-tools
comparison duart28/eeprom_rd.c @ 29:a7393d00996a
fc-duart28-conf: implement check-eeprom
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 09 Sep 2023 19:13:35 +0000 |
parents | |
children | 8de3891460db |
comparison
equal
deleted
inserted
replaced
28:c4b4ebaa2117 | 29:a7393d00996a |
---|---|
1 /* | |
2 * This module implements the steps of reading and validating the starting | |
3 * EEPROM content. | |
4 */ | |
5 | |
6 #include <sys/types.h> | |
7 #include <stdio.h> | |
8 #include <stdlib.h> | |
9 #include <string.h> | |
10 #include <strings.h> | |
11 #include <usb.h> | |
12 #include "../libftmini/eeprom_func.h" | |
13 | |
14 u_short eeprom[64]; | |
15 | |
16 void | |
17 read_eeprom(usbh) | |
18 usb_dev_handle *usbh; | |
19 { | |
20 unsigned n; | |
21 | |
22 for (n = 0; n < 64; n++) | |
23 eeprom[n] = ftmini_read_eeprom_loc(usbh, n); | |
24 } | |
25 | |
26 static void | |
27 verify_nonblank() | |
28 { | |
29 unsigned n; | |
30 | |
31 for (n = 0; n < 64; n++) { | |
32 if (eeprom[n] != 0xFFFF) | |
33 return; | |
34 } | |
35 fprintf(stderr, "error: EEPROM is blank (erased?)\n"); | |
36 exit(1); | |
37 } | |
38 | |
39 static void | |
40 verify_eeprom_chksum() | |
41 { | |
42 u_short chksum = 0xAAAA; | |
43 unsigned n; | |
44 | |
45 for (n = 0; n < 64; n++) { | |
46 chksum ^= eeprom[n]; | |
47 chksum = (chksum << 1) | (chksum >> 15); | |
48 } | |
49 if (chksum == 0) | |
50 return; | |
51 fprintf(stderr, "error: EEPROM checksum is wrong\n"); | |
52 exit(1); | |
53 } | |
54 | |
55 static int | |
56 check_req_match() | |
57 { | |
58 if (eeprom[0] != 0x0808) | |
59 return 0; | |
60 if (eeprom[1] != 0x0403) | |
61 return 0; | |
62 if (eeprom[2] != 0x6010 && eeprom[2] != 0x7152) | |
63 return 0; | |
64 if (eeprom[3] != 0x0500) | |
65 return 0; | |
66 if (eeprom[4] != 0x3280) | |
67 return 0; | |
68 if (eeprom[5] != 0x0000 && eeprom[5] != 0x0008) | |
69 return 0; | |
70 if (eeprom[6] != 0x0200) | |
71 return 0; | |
72 if (eeprom[7] != 0x1896) | |
73 return 0; | |
74 if (eeprom[8] != 0x12AE) | |
75 return 0; | |
76 if (eeprom[10] != 0x0046) | |
77 return 0; | |
78 if (eeprom[11] != 0x0318) | |
79 return 0; | |
80 if (eeprom[12] != 'F') | |
81 return 0; | |
82 if (eeprom[13] != 'r') | |
83 return 0; | |
84 if (eeprom[14] != 'e') | |
85 return 0; | |
86 if (eeprom[15] != 'e') | |
87 return 0; | |
88 if (eeprom[16] != 'C') | |
89 return 0; | |
90 if (eeprom[17] != 'a') | |
91 return 0; | |
92 if (eeprom[18] != 'l') | |
93 return 0; | |
94 if (eeprom[19] != 'y') | |
95 return 0; | |
96 if (eeprom[20] != 'p') | |
97 return 0; | |
98 if (eeprom[21] != 's') | |
99 return 0; | |
100 if (eeprom[22] != 'o') | |
101 return 0; | |
102 if (eeprom[23] != 0x0312) | |
103 return 0; | |
104 if (eeprom[24] != 'D') | |
105 return 0; | |
106 if (eeprom[25] != 'U') | |
107 return 0; | |
108 if (eeprom[26] != 'A') | |
109 return 0; | |
110 if (eeprom[27] != 'R') | |
111 return 0; | |
112 if (eeprom[28] != 'T') | |
113 return 0; | |
114 if (eeprom[29] != '2') | |
115 return 0; | |
116 if (eeprom[30] != '8') | |
117 return 0; | |
118 if (eeprom[31] != 'C' && eeprom[31] != 'S') | |
119 return 0; | |
120 return 1; | |
121 } | |
122 | |
123 analyze_eeprom() | |
124 { | |
125 verify_nonblank(); | |
126 verify_eeprom_chksum(); | |
127 if (!check_req_match()) { | |
128 fprintf(stderr, | |
129 "error: EEPROM content does not match FC DUART28\n"); | |
130 exit(1); | |
131 } | |
132 if (eeprom[2] == 0x7152 && eeprom[31] == 'C') { | |
133 printf("EEPROM is programmed for DUART28C\n"); | |
134 return 'C'; | |
135 } | |
136 if (eeprom[2] == 0x6010 && eeprom[31] == 'S') { | |
137 printf("EEPROM is programmed for DUART28S\n"); | |
138 return 'C'; | |
139 } | |
140 printf("EEPROM is inconsistent between C and S configs!\n"); | |
141 return '?'; | |
142 } |