blob: ffb0df197683a4437ca923de2b3613f62e085c96 [file] [log] [blame]
wdenkaffae2b2002-08-17 09:36:01 +00001/*
2 * (C) Copyright 2001
wdenk6dd652f2003-06-19 23:40:20 +00003 * Murray Jensen, CSIRO-MIT, <Murray.Jensen@csiro.au>
wdenkaffae2b2002-08-17 09:36:01 +00004 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenkaffae2b2002-08-17 09:36:01 +00006 */
7
8#include <common.h>
9#include <mpc8260.h>
10
11/* imports from fetch.c */
wdenk6dd652f2003-06-19 23:40:20 +000012extern int fetch_and_parse (char *, ulong, int (*)(uchar *, uchar *));
wdenkaffae2b2002-08-17 09:36:01 +000013
wdenk6dd652f2003-06-19 23:40:20 +000014/* imports from input.c */
15extern int hymod_get_serno (const char *);
16
17/* this is relative to the root of the server's tftp directory */
18static char *def_bddb_cfgdir = "/hymod/bddb";
19
20static int
21hymod_eeprom_load (int which, hymod_eeprom_t *ep)
wdenkaffae2b2002-08-17 09:36:01 +000022{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020023 unsigned dev_addr = CONFIG_SYS_I2C_EEPROM_ADDR | \
wdenk6dd652f2003-06-19 23:40:20 +000024 (which ? HYMOD_EEOFF_MEZZ : HYMOD_EEOFF_MAIN);
25 unsigned offset = 0;
wdenk592c5ca2003-06-21 00:17:24 +000026 uchar data[HYMOD_EEPROM_MAXLEN], *dp, *edp;
27 hymod_eehdr_t hdr;
wdenk6dd652f2003-06-19 23:40:20 +000028 ulong len, crc;
wdenkaffae2b2002-08-17 09:36:01 +000029
wdenk6dd652f2003-06-19 23:40:20 +000030 memset (ep, 0, sizeof *ep);
wdenkaffae2b2002-08-17 09:36:01 +000031
wdenk592c5ca2003-06-21 00:17:24 +000032 eeprom_read (dev_addr, offset, (uchar *)&hdr, sizeof (hdr));
33 offset += sizeof (hdr);
wdenkaffae2b2002-08-17 09:36:01 +000034
wdenk592c5ca2003-06-21 00:17:24 +000035 if (hdr.id != HYMOD_EEPROM_ID || hdr.ver > HYMOD_EEPROM_VER ||
36 (len = hdr.len) > HYMOD_EEPROM_MAXLEN)
wdenk6dd652f2003-06-19 23:40:20 +000037 return (0);
wdenkaffae2b2002-08-17 09:36:01 +000038
wdenk592c5ca2003-06-21 00:17:24 +000039 eeprom_read (dev_addr, offset, data, len);
wdenk6dd652f2003-06-19 23:40:20 +000040 offset += len;
wdenkaffae2b2002-08-17 09:36:01 +000041
wdenk6dd652f2003-06-19 23:40:20 +000042 eeprom_read (dev_addr, offset, (uchar *)&crc, sizeof (ulong));
wdenk592c5ca2003-06-21 00:17:24 +000043 offset += sizeof (ulong);
wdenkaffae2b2002-08-17 09:36:01 +000044
Wolfgang Denk77ddac92005-10-13 16:45:02 +020045 if (crc32 (crc32 (0, (uchar *)&hdr, sizeof hdr), data, len) != crc)
wdenk6dd652f2003-06-19 23:40:20 +000046 return (0);
wdenkaffae2b2002-08-17 09:36:01 +000047
wdenk592c5ca2003-06-21 00:17:24 +000048 ep->ver = hdr.ver;
49 dp = data; edp = dp + len;
wdenkaffae2b2002-08-17 09:36:01 +000050
wdenk6dd652f2003-06-19 23:40:20 +000051 for (;;) {
wdenk6dd652f2003-06-19 23:40:20 +000052 ulong rtyp;
53 uchar rlen, *rdat;
wdenkaffae2b2002-08-17 09:36:01 +000054
wdenk592c5ca2003-06-21 00:17:24 +000055 rtyp = *dp++;
56 if ((rtyp & 0x80) == 0)
57 rlen = *dp++;
wdenk6dd652f2003-06-19 23:40:20 +000058 else {
wdenk592c5ca2003-06-21 00:17:24 +000059 uchar islarge = rtyp & 0x40;
60
61 rtyp = ((rtyp & 0x3f) << 8) | *dp++;
62 if (islarge) {
63 rtyp = (rtyp << 8) | *dp++;
64 rtyp = (rtyp << 8) | *dp++;
65 }
66
67 rlen = *dp++;
68 rlen = (rlen << 8) | *dp++;
69 if (islarge) {
70 rlen = (rlen << 8) | *dp++;
71 rlen = (rlen << 8) | *dp++;
72 }
wdenk6dd652f2003-06-19 23:40:20 +000073 }
74
75 if (rtyp == 0)
76 break;
77
wdenk592c5ca2003-06-21 00:17:24 +000078 rdat = dp;
79 dp += rlen;
80
wdenk6dd652f2003-06-19 23:40:20 +000081 if (dp > edp) /* error? */
82 break;
83
84 switch (rtyp) {
85
86 case HYMOD_EEREC_SERNO: /* serial number */
87 if (rlen == sizeof (ulong))
wdenk592c5ca2003-06-21 00:17:24 +000088 ep->serno = \
89 ((ulong)rdat[0] << 24) | \
90 ((ulong)rdat[1] << 16) | \
91 ((ulong)rdat[2] << 8) | \
92 (ulong)rdat[3];
wdenk6dd652f2003-06-19 23:40:20 +000093 break;
94
95 case HYMOD_EEREC_DATE: /* date */
wdenk592c5ca2003-06-21 00:17:24 +000096 if (rlen == sizeof (hymod_date_t)) {
97 ep->date.year = ((ushort)rdat[0] << 8) | \
98 (ushort)rdat[1];
99 ep->date.month = rdat[2];
100 ep->date.day = rdat[3];
101 }
wdenk6dd652f2003-06-19 23:40:20 +0000102 break;
103
104 case HYMOD_EEREC_BATCH: /* batch */
105 if (rlen <= HYMOD_MAX_BATCH)
106 memcpy (ep->batch, rdat, ep->batchlen = rlen);
107 break;
108
109 case HYMOD_EEREC_TYPE: /* board type */
110 if (rlen == 1)
111 ep->bdtype = *rdat;
112 break;
113
114 case HYMOD_EEREC_REV: /* board revision */
115 if (rlen == 1)
116 ep->bdrev = *rdat;
117 break;
118
119 case HYMOD_EEREC_SDRAM: /* sdram size(s) */
120 if (rlen > 0 && rlen <= HYMOD_MAX_SDRAM) {
121 int i;
122
123 for (i = 0; i < rlen; i++)
124 ep->sdramsz[i] = rdat[i];
125 ep->nsdram = rlen;
126 }
127 break;
128
129 case HYMOD_EEREC_FLASH: /* flash size(s) */
130 if (rlen > 0 && rlen <= HYMOD_MAX_FLASH) {
131 int i;
132
133 for (i = 0; i < rlen; i++)
134 ep->flashsz[i] = rdat[i];
135 ep->nflash = rlen;
136 }
137 break;
138
139 case HYMOD_EEREC_ZBT: /* zbt ram size(s) */
140 if (rlen > 0 && rlen <= HYMOD_MAX_ZBT) {
141 int i;
142
143 for (i = 0; i < rlen; i++)
144 ep->zbtsz[i] = rdat[i];
145 ep->nzbt = rlen;
146 }
147 break;
148
149 case HYMOD_EEREC_XLXTYP: /* xilinx fpga type(s) */
150 if (rlen > 0 && rlen <= HYMOD_MAX_XLX) {
151 int i;
152
153 for (i = 0; i < rlen; i++)
154 ep->xlx[i].type = rdat[i];
155 ep->nxlx = rlen;
156 }
157 break;
158
159 case HYMOD_EEREC_XLXSPD: /* xilinx fpga speed(s) */
160 if (rlen > 0 && rlen <= HYMOD_MAX_XLX) {
161 int i;
162
163 for (i = 0; i < rlen; i++)
164 ep->xlx[i].speed = rdat[i];
165 }
166 break;
167
168 case HYMOD_EEREC_XLXTMP: /* xilinx fpga temperature(s) */
169 if (rlen > 0 && rlen <= HYMOD_MAX_XLX) {
170 int i;
171
172 for (i = 0; i < rlen; i++)
173 ep->xlx[i].temp = rdat[i];
174 }
175 break;
176
177 case HYMOD_EEREC_XLXGRD: /* xilinx fpga grade(s) */
178 if (rlen > 0 && rlen <= HYMOD_MAX_XLX) {
179 int i;
180
181 for (i = 0; i < rlen; i++)
182 ep->xlx[i].grade = rdat[i];
183 }
184 break;
185
186 case HYMOD_EEREC_CPUTYP: /* CPU type */
187 if (rlen == 1)
188 ep->mpc.type = *rdat;
189 break;
190
191 case HYMOD_EEREC_CPUSPD: /* CPU speed */
192 if (rlen == 1)
193 ep->mpc.cpuspd = *rdat;
194 break;
195
196 case HYMOD_EEREC_CPMSPD: /* CPM speed */
197 if (rlen == 1)
198 ep->mpc.cpmspd = *rdat;
199 break;
200
201 case HYMOD_EEREC_BUSSPD: /* bus speed */
202 if (rlen == 1)
203 ep->mpc.busspd = *rdat;
204 break;
205
206 case HYMOD_EEREC_HSTYPE: /* hs-serial chip type */
207 if (rlen == 1)
208 ep->hss.type = *rdat;
209 break;
210
211 case HYMOD_EEREC_HSCHIN: /* num hs-serial input chans */
212 if (rlen == 1)
213 ep->hss.nchin = *rdat;
214 break;
215
216 case HYMOD_EEREC_HSCHOUT: /* num hs-serial output chans */
217 if (rlen == 1)
218 ep->hss.nchout = *rdat;
219 break;
220
221 default: /* ignore */
222 break;
223 }
wdenkaffae2b2002-08-17 09:36:01 +0000224 }
225
wdenk6dd652f2003-06-19 23:40:20 +0000226 return (1);
wdenkaffae2b2002-08-17 09:36:01 +0000227}
228
229/* maps an ascii "name=value" into a binary eeprom data record */
230typedef
wdenk6dd652f2003-06-19 23:40:20 +0000231 struct _eerec_map {
232 char *name;
233 uint type;
234 uchar *(*handler) \
235 (struct _eerec_map *, uchar *, uchar *, uchar *);
236 uint length;
237 uint maxlen;
238 }
wdenkaffae2b2002-08-17 09:36:01 +0000239eerec_map_t;
240
241static uchar *
wdenk6dd652f2003-06-19 23:40:20 +0000242uint_handler (eerec_map_t *rp, uchar *val, uchar *dp, uchar *edp)
wdenkaffae2b2002-08-17 09:36:01 +0000243{
wdenk592c5ca2003-06-21 00:17:24 +0000244 char *eval;
245 ulong lval;
wdenkaffae2b2002-08-17 09:36:01 +0000246
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200247 lval = simple_strtol ((char *)val, &eval, 10);
wdenkaffae2b2002-08-17 09:36:01 +0000248
wdenk592c5ca2003-06-21 00:17:24 +0000249 if ((uchar *)eval == val || *eval != '\0') {
250 printf ("%s rec (%s) is not a valid uint\n", rp->name, val);
wdenk6dd652f2003-06-19 23:40:20 +0000251 return (NULL);
wdenkaffae2b2002-08-17 09:36:01 +0000252 }
wdenkaffae2b2002-08-17 09:36:01 +0000253
wdenk6dd652f2003-06-19 23:40:20 +0000254 if (dp + 2 + rp->length > edp) {
255 printf ("can't fit %s rec into eeprom\n", rp->name);
256 return (NULL);
wdenkaffae2b2002-08-17 09:36:01 +0000257 }
wdenkaffae2b2002-08-17 09:36:01 +0000258
wdenk6dd652f2003-06-19 23:40:20 +0000259 *dp++ = rp->type;
260 *dp++ = rp->length;
wdenkaffae2b2002-08-17 09:36:01 +0000261
wdenk6dd652f2003-06-19 23:40:20 +0000262 switch (rp->length) {
wdenkaffae2b2002-08-17 09:36:01 +0000263
wdenk6dd652f2003-06-19 23:40:20 +0000264 case 1:
wdenk592c5ca2003-06-21 00:17:24 +0000265 if (lval >= 256) {
wdenk6dd652f2003-06-19 23:40:20 +0000266 printf ("%s rec value (%lu) out of range (0-255)\n",
wdenk592c5ca2003-06-21 00:17:24 +0000267 rp->name, lval);
wdenk6dd652f2003-06-19 23:40:20 +0000268 return (NULL);
269 }
wdenk592c5ca2003-06-21 00:17:24 +0000270 *dp++ = lval;
wdenk6dd652f2003-06-19 23:40:20 +0000271 break;
272
273 case 2:
wdenk592c5ca2003-06-21 00:17:24 +0000274 if (lval >= 65536) {
wdenk6dd652f2003-06-19 23:40:20 +0000275 printf ("%s rec value (%lu) out of range (0-65535)\n",
wdenk592c5ca2003-06-21 00:17:24 +0000276 rp->name, lval);
wdenk6dd652f2003-06-19 23:40:20 +0000277 return (NULL);
278 }
wdenk592c5ca2003-06-21 00:17:24 +0000279 *dp++ = lval >> 8;
280 *dp++ = lval;
wdenk6dd652f2003-06-19 23:40:20 +0000281 break;
282
283 case 4:
wdenk592c5ca2003-06-21 00:17:24 +0000284 *dp++ = lval >> 24;
285 *dp++ = lval >> 16;
286 *dp++ = lval >> 8;
287 *dp++ = lval;
wdenk6dd652f2003-06-19 23:40:20 +0000288 break;
289
290 default:
291 printf ("huh? rp->length not 1, 2 or 4! (%d)\n", rp->length);
292 return (NULL);
293 }
294
295 return (dp);
wdenkaffae2b2002-08-17 09:36:01 +0000296}
297
298static uchar *
wdenk6dd652f2003-06-19 23:40:20 +0000299date_handler (eerec_map_t *rp, uchar *val, uchar *dp, uchar *edp)
wdenkaffae2b2002-08-17 09:36:01 +0000300{
wdenk6dd652f2003-06-19 23:40:20 +0000301 hymod_date_t date;
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200302 char *p = (char *)val;
wdenk592c5ca2003-06-21 00:17:24 +0000303 char *ep;
304 ulong lval;
wdenkaffae2b2002-08-17 09:36:01 +0000305
wdenk592c5ca2003-06-21 00:17:24 +0000306 lval = simple_strtol (p, &ep, 10);
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200307 if (ep == p || *ep++ != '-') {
wdenkaffae2b2002-08-17 09:36:01 +0000308bad_date:
wdenk6dd652f2003-06-19 23:40:20 +0000309 printf ("%s rec (%s) is not a valid date\n", rp->name, val);
310 return (NULL);
311 }
wdenk592c5ca2003-06-21 00:17:24 +0000312 if (lval >= 65536)
wdenk6dd652f2003-06-19 23:40:20 +0000313 goto bad_date;
wdenk592c5ca2003-06-21 00:17:24 +0000314 date.year = lval;
wdenkaffae2b2002-08-17 09:36:01 +0000315
wdenk592c5ca2003-06-21 00:17:24 +0000316 lval = simple_strtol (p = ep, &ep, 10);
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200317 if (ep == p || *ep++ != '-' || lval == 0 || lval > 12)
wdenk6dd652f2003-06-19 23:40:20 +0000318 goto bad_date;
wdenk592c5ca2003-06-21 00:17:24 +0000319 date.month = lval;
wdenkaffae2b2002-08-17 09:36:01 +0000320
wdenk592c5ca2003-06-21 00:17:24 +0000321 lval = simple_strtol (p = ep, &ep, 10);
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200322 if (ep == p || *ep != '\0' || lval == 0 || lval > 31)
wdenk592c5ca2003-06-21 00:17:24 +0000323 goto bad_date;
324 date.day = lval;
325
326 if (dp + 2 + rp->length > edp) {
wdenk6dd652f2003-06-19 23:40:20 +0000327 printf ("can't fit %s rec into eeprom\n", rp->name);
328 return (NULL);
329 }
wdenkaffae2b2002-08-17 09:36:01 +0000330
wdenk6dd652f2003-06-19 23:40:20 +0000331 *dp++ = rp->type;
wdenk592c5ca2003-06-21 00:17:24 +0000332 *dp++ = rp->length;
333 *dp++ = date.year >> 8;
334 *dp++ = date.year;
335 *dp++ = date.month;
336 *dp++ = date.day;
wdenkaffae2b2002-08-17 09:36:01 +0000337
wdenk6dd652f2003-06-19 23:40:20 +0000338 return (dp);
wdenkaffae2b2002-08-17 09:36:01 +0000339}
340
341static uchar *
wdenk6dd652f2003-06-19 23:40:20 +0000342string_handler (eerec_map_t *rp, uchar *val, uchar *dp, uchar *edp)
wdenkaffae2b2002-08-17 09:36:01 +0000343{
wdenk6dd652f2003-06-19 23:40:20 +0000344 uint len;
wdenkaffae2b2002-08-17 09:36:01 +0000345
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200346 if ((len = strlen ((char *)val)) > rp->maxlen) {
wdenk6dd652f2003-06-19 23:40:20 +0000347 printf ("%s rec (%s) string is too long (%d>%d)\n",
348 rp->name, val, len, rp->maxlen);
349 return (NULL);
350 }
wdenkaffae2b2002-08-17 09:36:01 +0000351
wdenk6dd652f2003-06-19 23:40:20 +0000352 if (dp + 2 + len > edp) {
353 printf ("can't fit %s rec into eeprom\n", rp->name);
354 return (NULL);
355 }
wdenkaffae2b2002-08-17 09:36:01 +0000356
wdenk6dd652f2003-06-19 23:40:20 +0000357 *dp++ = rp->type;
358 *dp++ = len;
359 memcpy (dp, val, len);
360 dp += len;
wdenkaffae2b2002-08-17 09:36:01 +0000361
wdenk6dd652f2003-06-19 23:40:20 +0000362 return (dp);
wdenkaffae2b2002-08-17 09:36:01 +0000363}
364
365static uchar *
wdenk6dd652f2003-06-19 23:40:20 +0000366bytes_handler (eerec_map_t *rp, uchar *val, uchar *dp, uchar *edp)
wdenkaffae2b2002-08-17 09:36:01 +0000367{
wdenk592c5ca2003-06-21 00:17:24 +0000368 uchar bytes[HYMOD_MAX_BYTES], nbytes, *p;
369 char *ep;
wdenkaffae2b2002-08-17 09:36:01 +0000370
wdenk592c5ca2003-06-21 00:17:24 +0000371 for (nbytes = 0, p = val; *p != '\0'; p = (uchar *)ep) {
372 ulong lval;
wdenkaffae2b2002-08-17 09:36:01 +0000373
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200374 lval = simple_strtol ((char *)p, &ep, 10);
wdenk592c5ca2003-06-21 00:17:24 +0000375 if ((uchar *)ep == p || (*ep != '\0' && *ep != ',') || \
376 lval >= 256) {
377 printf ("%s rec (%s) byte array has invalid uint\n",
378 rp->name, val);
379 return (NULL);
380 }
wdenk6dd652f2003-06-19 23:40:20 +0000381 if (nbytes >= HYMOD_MAX_BYTES) {
382 printf ("%s rec (%s) byte array too long\n",
383 rp->name, val);
384 return (NULL);
385 }
wdenk592c5ca2003-06-21 00:17:24 +0000386 bytes[nbytes++] = lval;
wdenk6dd652f2003-06-19 23:40:20 +0000387
wdenk592c5ca2003-06-21 00:17:24 +0000388 if (*ep != '\0')
389 ep++;
wdenkaffae2b2002-08-17 09:36:01 +0000390 }
391
wdenk6dd652f2003-06-19 23:40:20 +0000392 if (dp + 2 + nbytes > edp) {
393 printf ("can't fit %s rec into eeprom\n", rp->name);
394 return (NULL);
wdenkaffae2b2002-08-17 09:36:01 +0000395 }
396
wdenk6dd652f2003-06-19 23:40:20 +0000397 *dp++ = rp->type;
398 *dp++ = nbytes;
399 memcpy (dp, bytes, nbytes);
400 dp += nbytes;
wdenkaffae2b2002-08-17 09:36:01 +0000401
wdenk6dd652f2003-06-19 23:40:20 +0000402 return (dp);
wdenkaffae2b2002-08-17 09:36:01 +0000403}
404
405static eerec_map_t eerec_map[] = {
wdenk6dd652f2003-06-19 23:40:20 +0000406 /* name type handler len max */
407 { "serno", HYMOD_EEREC_SERNO, uint_handler, 4, 0 },
408 { "date", HYMOD_EEREC_DATE, date_handler, 4, 0 },
409 { "batch", HYMOD_EEREC_BATCH, string_handler, 0, HYMOD_MAX_BATCH },
410 { "type", HYMOD_EEREC_TYPE, uint_handler, 1, 0 },
411 { "rev", HYMOD_EEREC_REV, uint_handler, 1, 0 },
412 { "sdram", HYMOD_EEREC_SDRAM, bytes_handler, 0, HYMOD_MAX_SDRAM },
413 { "flash", HYMOD_EEREC_FLASH, bytes_handler, 0, HYMOD_MAX_FLASH },
414 { "zbt", HYMOD_EEREC_ZBT, bytes_handler, 0, HYMOD_MAX_ZBT },
415 { "xlxtyp", HYMOD_EEREC_XLXTYP, bytes_handler, 0, HYMOD_MAX_XLX },
416 { "xlxspd", HYMOD_EEREC_XLXSPD, bytes_handler, 0, HYMOD_MAX_XLX },
417 { "xlxtmp", HYMOD_EEREC_XLXTMP, bytes_handler, 0, HYMOD_MAX_XLX },
418 { "xlxgrd", HYMOD_EEREC_XLXGRD, bytes_handler, 0, HYMOD_MAX_XLX },
419 { "cputyp", HYMOD_EEREC_CPUTYP, uint_handler, 1, 0 },
420 { "cpuspd", HYMOD_EEREC_CPUSPD, uint_handler, 1, 0 },
421 { "cpmspd", HYMOD_EEREC_CPMSPD, uint_handler, 1, 0 },
422 { "busspd", HYMOD_EEREC_BUSSPD, uint_handler, 1, 0 },
423 { "hstype", HYMOD_EEREC_HSTYPE, uint_handler, 1, 0 },
424 { "hschin", HYMOD_EEREC_HSCHIN, uint_handler, 1, 0 },
425 { "hschout", HYMOD_EEREC_HSCHOUT, uint_handler, 1, 0 },
wdenkaffae2b2002-08-17 09:36:01 +0000426};
427
428static int neerecs = sizeof eerec_map / sizeof eerec_map[0];
429
430static uchar data[HYMOD_EEPROM_SIZE], *sdp, *dp, *edp;
431
432static int
wdenk6dd652f2003-06-19 23:40:20 +0000433eerec_callback (uchar *name, uchar *val)
wdenkaffae2b2002-08-17 09:36:01 +0000434{
wdenk6dd652f2003-06-19 23:40:20 +0000435 eerec_map_t *rp;
wdenkaffae2b2002-08-17 09:36:01 +0000436
wdenk6dd652f2003-06-19 23:40:20 +0000437 for (rp = eerec_map; rp < &eerec_map[neerecs]; rp++)
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200438 if (strcmp ((char *)name, rp->name) == 0)
wdenk6dd652f2003-06-19 23:40:20 +0000439 break;
wdenkaffae2b2002-08-17 09:36:01 +0000440
wdenk6dd652f2003-06-19 23:40:20 +0000441 if (rp >= &eerec_map[neerecs])
442 return (0);
wdenkaffae2b2002-08-17 09:36:01 +0000443
wdenk6dd652f2003-06-19 23:40:20 +0000444 if ((dp = (*rp->handler) (rp, val, dp, edp)) == NULL)
445 return (0);
wdenkaffae2b2002-08-17 09:36:01 +0000446
wdenk6dd652f2003-06-19 23:40:20 +0000447 return (1);
wdenkaffae2b2002-08-17 09:36:01 +0000448}
449
wdenk6dd652f2003-06-19 23:40:20 +0000450static int
451hymod_eeprom_fetch(int which, char *filename, ulong addr)
wdenkaffae2b2002-08-17 09:36:01 +0000452{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200453 unsigned dev_addr = CONFIG_SYS_I2C_EEPROM_ADDR | \
wdenk6dd652f2003-06-19 23:40:20 +0000454 (which ? HYMOD_EEOFF_MEZZ : HYMOD_EEOFF_MAIN);
455 hymod_eehdr_t *hp = (hymod_eehdr_t *)&data[0];
456 ulong crc;
wdenkaffae2b2002-08-17 09:36:01 +0000457
wdenk592c5ca2003-06-21 00:17:24 +0000458 memset (hp, 0, sizeof *hp);
wdenk6dd652f2003-06-19 23:40:20 +0000459 hp->id = HYMOD_EEPROM_ID;
460 hp->ver = HYMOD_EEPROM_VER;
wdenkaffae2b2002-08-17 09:36:01 +0000461
wdenk6dd652f2003-06-19 23:40:20 +0000462 dp = sdp = (uchar *)(hp + 1);
463 edp = dp + HYMOD_EEPROM_MAXLEN;
wdenkaffae2b2002-08-17 09:36:01 +0000464
wdenk6dd652f2003-06-19 23:40:20 +0000465 if (fetch_and_parse (filename, addr, eerec_callback) == 0)
466 return (0);
wdenkaffae2b2002-08-17 09:36:01 +0000467
wdenk6dd652f2003-06-19 23:40:20 +0000468 hp->len = dp - sdp;
wdenkaffae2b2002-08-17 09:36:01 +0000469
wdenk6dd652f2003-06-19 23:40:20 +0000470 crc = crc32 (0, data, dp - data);
471 memcpy (dp, &crc, sizeof (ulong));
472 dp += sizeof (ulong);
wdenkaffae2b2002-08-17 09:36:01 +0000473
wdenk6dd652f2003-06-19 23:40:20 +0000474 eeprom_write (dev_addr, 0, data, dp - data);
wdenkaffae2b2002-08-17 09:36:01 +0000475
wdenk6dd652f2003-06-19 23:40:20 +0000476 return (1);
wdenkaffae2b2002-08-17 09:36:01 +0000477}
478
479static char *type_vals[] = {
wdenk6dd652f2003-06-19 23:40:20 +0000480 "NONE", "IO", "CLP", "DSP", "INPUT", "ALT-INPUT", "DISPLAY"
wdenkaffae2b2002-08-17 09:36:01 +0000481};
482
483static char *xlxtyp_vals[] = {
wdenk6dd652f2003-06-19 23:40:20 +0000484 "NONE", "XCV300E", "XCV400E", "XCV600E"
wdenkaffae2b2002-08-17 09:36:01 +0000485};
486
487static char *xlxspd_vals[] = {
wdenk6dd652f2003-06-19 23:40:20 +0000488 "NONE", "6", "7", "8"
wdenkaffae2b2002-08-17 09:36:01 +0000489};
490
491static char *xlxtmp_vals[] = {
wdenk6dd652f2003-06-19 23:40:20 +0000492 "NONE", "COM", "IND"
wdenkaffae2b2002-08-17 09:36:01 +0000493};
494
495static char *xlxgrd_vals[] = {
wdenk6dd652f2003-06-19 23:40:20 +0000496 "NONE", "NORMAL", "ENGSAMP"
wdenkaffae2b2002-08-17 09:36:01 +0000497};
498
499static char *cputyp_vals[] = {
wdenk6dd652f2003-06-19 23:40:20 +0000500 "NONE", "MPC8260"
wdenkaffae2b2002-08-17 09:36:01 +0000501};
502
503static char *clk_vals[] = {
wdenk6dd652f2003-06-19 23:40:20 +0000504 "NONE", "33", "66", "100", "133", "166", "200"
wdenkaffae2b2002-08-17 09:36:01 +0000505};
506
507static char *hstype_vals[] = {
wdenk6dd652f2003-06-19 23:40:20 +0000508 "NONE", "AMCC-S2064A"
wdenkaffae2b2002-08-17 09:36:01 +0000509};
510
511static void
wdenk6dd652f2003-06-19 23:40:20 +0000512print_mem (char *l, char *s, uchar n, uchar a[])
wdenkaffae2b2002-08-17 09:36:01 +0000513{
wdenk6dd652f2003-06-19 23:40:20 +0000514 if (n > 0) {
515 if (n == 1)
516 printf ("%s%dMB %s", s, 1 << (a[0] - 20), l);
517 else {
518 ulong t = 0;
519 int i;
wdenkaffae2b2002-08-17 09:36:01 +0000520
wdenk6dd652f2003-06-19 23:40:20 +0000521 for (i = 0; i < n; i++)
522 t += 1 << (a[i] - 20);
wdenkaffae2b2002-08-17 09:36:01 +0000523
wdenk6dd652f2003-06-19 23:40:20 +0000524 printf ("%s%luMB %s (%d banks:", s, t, l, n);
wdenkaffae2b2002-08-17 09:36:01 +0000525
wdenk6dd652f2003-06-19 23:40:20 +0000526 for (i = 0; i < n; i++)
527 printf ("%dMB%s",
528 1 << (a[i] - 20),
529 (i == n - 1) ? ")" : ",");
530 }
wdenkaffae2b2002-08-17 09:36:01 +0000531 }
wdenk6dd652f2003-06-19 23:40:20 +0000532 else
533 printf ("%sNO %s", s, l);
wdenkaffae2b2002-08-17 09:36:01 +0000534}
535
536void
wdenk6dd652f2003-06-19 23:40:20 +0000537hymod_eeprom_print (hymod_eeprom_t *ep)
wdenkaffae2b2002-08-17 09:36:01 +0000538{
wdenk6dd652f2003-06-19 23:40:20 +0000539 int i;
wdenkaffae2b2002-08-17 09:36:01 +0000540
wdenk6dd652f2003-06-19 23:40:20 +0000541 printf (" Hymod %s board, rev %03d\n",
542 type_vals[ep->bdtype], ep->bdrev);
wdenkaffae2b2002-08-17 09:36:01 +0000543
wdenk6dd652f2003-06-19 23:40:20 +0000544 printf (" serial #: %010lu, date %04d-%02d-%02d",
545 ep->serno, ep->date.year, ep->date.month, ep->date.day);
546 if (ep->batchlen > 0)
547 printf (", batch \"%.*s\"", ep->batchlen, ep->batch);
548 puts ("\n");
wdenkaffae2b2002-08-17 09:36:01 +0000549
wdenk6dd652f2003-06-19 23:40:20 +0000550 switch (ep->bdtype) {
wdenkaffae2b2002-08-17 09:36:01 +0000551
wdenk6dd652f2003-06-19 23:40:20 +0000552 case HYMOD_BDTYPE_IO:
553 case HYMOD_BDTYPE_CLP:
554 case HYMOD_BDTYPE_DSP:
555 printf (" Motorola %s CPU, speeds: %s/%s/%s",
556 cputyp_vals[ep->mpc.type], clk_vals[ep->mpc.cpuspd],
557 clk_vals[ep->mpc.cpmspd], clk_vals[ep->mpc.busspd]);
wdenkaffae2b2002-08-17 09:36:01 +0000558
wdenk6dd652f2003-06-19 23:40:20 +0000559 print_mem ("SDRAM", ", ", ep->nsdram, ep->sdramsz);
wdenkaffae2b2002-08-17 09:36:01 +0000560
wdenk6dd652f2003-06-19 23:40:20 +0000561 print_mem ("FLASH", ", ", ep->nflash, ep->flashsz);
wdenkaffae2b2002-08-17 09:36:01 +0000562
wdenk6dd652f2003-06-19 23:40:20 +0000563 puts ("\n");
wdenkaffae2b2002-08-17 09:36:01 +0000564
wdenk6dd652f2003-06-19 23:40:20 +0000565 print_mem ("ZBT", " ", ep->nzbt, ep->zbtsz);
wdenkaffae2b2002-08-17 09:36:01 +0000566
wdenk6dd652f2003-06-19 23:40:20 +0000567 if (ep->nxlx > 0) {
568 hymod_xlx_t *xp;
wdenkaffae2b2002-08-17 09:36:01 +0000569
wdenk6dd652f2003-06-19 23:40:20 +0000570 if (ep->nxlx == 1) {
571 xp = &ep->xlx[0];
572 printf (", Xilinx %s FPGA (%s/%s/%s)",
573 xlxtyp_vals[xp->type],
574 xlxspd_vals[xp->speed],
575 xlxtmp_vals[xp->temp],
576 xlxgrd_vals[xp->grade]);
577 }
578 else {
579 printf (", %d Xilinx FPGAs (", ep->nxlx);
580 for (i = 0; i < ep->nxlx; i++) {
581 xp = &ep->xlx[i];
582 printf ("%s[%s/%s/%s]%s",
583 xlxtyp_vals[xp->type],
584 xlxspd_vals[xp->speed],
585 xlxtmp_vals[xp->temp],
586 xlxgrd_vals[xp->grade],
587 (i == ep->nxlx - 1) ? ")" : ", ");
588 }
589 }
wdenkaffae2b2002-08-17 09:36:01 +0000590 }
wdenk6dd652f2003-06-19 23:40:20 +0000591 else
592 puts(", NO FPGAs");
593
594 puts ("\n");
595
596 if (ep->hss.type > 0)
597 printf (" High Speed Serial: "
598 "%s, %d input%s, %d output%s\n",
599 hstype_vals[ep->hss.type],
600 ep->hss.nchin,
601 (ep->hss.nchin == 1 ? "" : "s"),
602 ep->hss.nchout,
603 (ep->hss.nchout == 1 ? "" : "s"));
604 break;
605
606 case HYMOD_BDTYPE_INPUT:
607 case HYMOD_BDTYPE_ALTINPUT:
608 case HYMOD_BDTYPE_DISPLAY:
609 break;
610
611 default:
612 /* crap! */
613 printf (" UNKNOWN BOARD TYPE: %d\n", ep->bdtype);
614 break;
wdenkaffae2b2002-08-17 09:36:01 +0000615 }
wdenk6dd652f2003-06-19 23:40:20 +0000616}
wdenkaffae2b2002-08-17 09:36:01 +0000617
wdenk6dd652f2003-06-19 23:40:20 +0000618int
619hymod_eeprom_read (int which, hymod_eeprom_t *ep)
620{
621 char *label = which ? "mezzanine" : "main";
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200622 unsigned dev_addr = CONFIG_SYS_I2C_EEPROM_ADDR | \
wdenk6dd652f2003-06-19 23:40:20 +0000623 (which ? HYMOD_EEOFF_MEZZ : HYMOD_EEOFF_MAIN);
624 char filename[50], prompt[50], *dir;
625 int serno, count = 0, rc;
wdenkaffae2b2002-08-17 09:36:01 +0000626
wdenk6dd652f2003-06-19 23:40:20 +0000627 rc = eeprom_probe (dev_addr, 0);
wdenkaffae2b2002-08-17 09:36:01 +0000628
wdenk6dd652f2003-06-19 23:40:20 +0000629 if (rc > 0) {
630 printf ("*** probe for eeprom failed with code %d\n", rc);
631 return (0);
632 }
wdenkaffae2b2002-08-17 09:36:01 +0000633
wdenk6dd652f2003-06-19 23:40:20 +0000634 if (rc < 0)
635 return (rc);
636
637 sprintf (prompt, "Enter %s board serial number: ", label);
638
639 if ((dir = getenv ("bddb_cfgdir")) == NULL)
640 dir = def_bddb_cfgdir;
641
642 for (;;) {
643 int rc;
644
645 if (hymod_eeprom_load (which, ep))
646 return (1);
647
648 printf ("*** %s board EEPROM contents are %sinvalid\n",
649 label, count == 0 ? "" : "STILL ");
650
651 puts ("*** will fetch from server (Ctrl-C to abort)\n");
652
653 serno = hymod_get_serno (prompt);
654
655 if (serno < 0) {
656 if (serno == -1)
657 puts ("\n*** interrupted!");
658 else
659 puts ("\n*** timeout!");
660 puts (" - ignoring eeprom contents\n");
661 return (0);
662 }
663
664 sprintf (filename, "%s/%010d.cfg", dir, serno);
665
666 printf ("*** fetching %s board EEPROM contents from server\n",
667 label);
668
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200669 rc = hymod_eeprom_fetch (which, filename, CONFIG_SYS_LOAD_ADDR);
wdenk6dd652f2003-06-19 23:40:20 +0000670
671 if (rc == 0) {
672 puts ("*** fetch failed - ignoring eeprom contents\n");
673 return (0);
674 }
675
676 count++;
677 }
wdenkaffae2b2002-08-17 09:36:01 +0000678}