annotate duart28/eeprom_rd.c @ 93:a1df83d04cc9

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