1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
|
/*
* (C) Copyright 2001
* Murray Jensen, CSIRO Manufacturing Science and Technology,
* <Murray.Jensen@cmst.csiro.au>
*
* See file CREDITS for list of people who contributed to this
* project.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
#include <common.h>
#include <mpc8260.h>
/* imports from fetch.c */
extern int fetch_and_parse(bd_t *, char *, ulong, int (*)(uchar *, uchar *));
int
eeprom_load(unsigned offset, hymod_eeprom_t *ep)
{
uchar data[HYMOD_EEPROM_SIZE], *dp, *edp;
hymod_eehdr_t *hp;
ulong len, crc;
memset(ep, 0, sizeof *ep);
memset(data, 0, HYMOD_EEPROM_SIZE);
crc = 0;
hp = (hymod_eehdr_t *)data;
eeprom_read(CFG_DEF_EEPROM_ADDR, offset, (uchar *)hp, sizeof (*hp));
offset += sizeof (*hp);
if (hp->id != HYMOD_EEPROM_ID || hp->ver > HYMOD_EEPROM_VER ||
(len = hp->len) > HYMOD_EEPROM_MAXLEN)
return (0);
dp = (uchar *)(hp + 1); edp = dp + len;
eeprom_read(CFG_DEF_EEPROM_ADDR, offset, dp, len);
offset += len;
eeprom_read(CFG_DEF_EEPROM_ADDR, offset, (uchar *)&crc, sizeof (ulong));
if (crc32(0, data, edp - data) != crc)
return (0);
ep->ver = hp->ver;
for (;;) {
hymod_eerec_t *rp = (hymod_eerec_t *)dp;
ulong rtyp;
uchar rlen, *rdat;
uint rsiz;
if (rp->small.topbit == 0) {
rtyp = rp->small.type;
rlen = rp->small.len;
rdat = rp->small.data;
rsiz = offsetof(hymod_eerec_t, small.data) + rlen;
}
else if (rp->medium.nxtbit == 0) {
rtyp = rp->medium.type;
rlen = rp->medium.len;
rdat = rp->medium.data;
rsiz = offsetof(hymod_eerec_t, medium.data) + rlen;
}
else {
rtyp = rp->large.type;
rlen = rp->large.len;
rdat = rp->large.data;
rsiz = offsetof(hymod_eerec_t, large.data) + rlen;
}
if (rtyp == 0)
break;
dp += rsiz;
if (dp > edp) /* error? */
break;
switch (rtyp) {
case HYMOD_EEREC_SERNO: /* serial number */
if (rlen == sizeof (ulong))
memcpy(&ep->serno, rdat, sizeof (ulong));
break;
case HYMOD_EEREC_DATE: /* date */
if (rlen == sizeof (hymod_date_t))
memcpy(&ep->date, rdat, sizeof (hymod_date_t));
break;
case HYMOD_EEREC_BATCH: /* batch */
if (rlen <= HYMOD_MAX_BATCH)
memcpy(ep->batch, rdat, ep->batchlen = rlen);
break;
case HYMOD_EEREC_TYPE: /* board type */
if (rlen == 1)
ep->bdtype = *rdat;
break;
case HYMOD_EEREC_REV: /* board revision */
if (rlen == 1)
ep->bdrev = *rdat;
break;
case HYMOD_EEREC_SDRAM: /* sdram size(s) */
if (rlen > 0 && rlen <= HYMOD_MAX_SDRAM) {
int i;
for (i = 0; i < rlen; i++)
ep->sdramsz[i] = rdat[i];
ep->nsdram = rlen;
}
break;
case HYMOD_EEREC_FLASH: /* flash size(s) */
if (rlen > 0 && rlen <= HYMOD_MAX_FLASH) {
int i;
for (i = 0; i < rlen; i++)
ep->flashsz[i] = rdat[i];
ep->nflash = rlen;
}
break;
case HYMOD_EEREC_ZBT: /* zbt ram size(s) */
if (rlen > 0 && rlen <= HYMOD_MAX_ZBT) {
int i;
for (i = 0; i < rlen; i++)
ep->zbtsz[i] = rdat[i];
ep->nzbt = rlen;
}
break;
case HYMOD_EEREC_XLXTYP: /* xilinx fpga type(s) */
if (rlen > 0 && rlen <= HYMOD_MAX_XLX) {
int i;
for (i = 0; i < rlen; i++)
ep->xlx[i].type = rdat[i];
ep->nxlx = rlen;
}
break;
case HYMOD_EEREC_XLXSPD: /* xilinx fpga speed(s) */
if (rlen > 0 && rlen <= HYMOD_MAX_XLX) {
int i;
for (i = 0; i < rlen; i++)
ep->xlx[i].speed = rdat[i];
}
break;
case HYMOD_EEREC_XLXTMP: /* xilinx fpga temperature(s) */
if (rlen > 0 && rlen <= HYMOD_MAX_XLX) {
int i;
for (i = 0; i < rlen; i++)
ep->xlx[i].temp = rdat[i];
}
break;
case HYMOD_EEREC_XLXGRD: /* xilinx fpga grade(s) */
if (rlen > 0 && rlen <= HYMOD_MAX_XLX) {
int i;
for (i = 0; i < rlen; i++)
ep->xlx[i].grade = rdat[i];
}
break;
case HYMOD_EEREC_CPUTYP: /* CPU type */
if (rlen == 1)
ep->mpc.type = *rdat;
break;
case HYMOD_EEREC_CPUSPD: /* CPU speed */
if (rlen == 1)
ep->mpc.cpuspd = *rdat;
break;
case HYMOD_EEREC_CPMSPD: /* CPM speed */
if (rlen == 1)
ep->mpc.cpmspd = *rdat;
break;
case HYMOD_EEREC_BUSSPD: /* bus speed */
if (rlen == 1)
ep->mpc.busspd = *rdat;
break;
case HYMOD_EEREC_HSTYPE: /* high-speed serial chip type */
if (rlen == 1)
ep->hss.type = *rdat;
break;
case HYMOD_EEREC_HSCHIN: /* high-speed serial input channels */
if (rlen == 1)
ep->hss.nchin = *rdat;
break;
case HYMOD_EEREC_HSCHOUT: /* high-speed serial output channels */
if (rlen == 1)
ep->hss.nchout = *rdat;
break;
default: /* ignore */
break;
}
}
return (1);
}
/* maps an ascii "name=value" into a binary eeprom data record */
typedef
struct _eerec_map {
char *name;
uint type;
uchar *(*handler)(struct _eerec_map *, uchar *, uchar *, uchar *);
uint length;
uint maxlen;
}
eerec_map_t;
static uchar *
uint_handler(eerec_map_t *rp, uchar *value, uchar *dp, uchar *edp)
{
uchar *eval;
union {
uchar cval[4];
ushort sval[2];
ulong lval;
} rdata;
rdata.lval = simple_strtol(value, (char **)&eval, 10);
if (eval == value || *eval != '\0') {
printf("%s record (%s) is not a valid uint\n", rp->name, value);
return (NULL);
}
if (dp + 2 + rp->length > edp) {
printf("can't fit %s record into eeprom\n", rp->name);
return (NULL);
}
*dp++ = rp->type;
*dp++ = rp->length;
switch (rp->length) {
case 1:
if (rdata.lval >= 256) {
printf("%s record value (%lu) out of range (0-255)\n",
rp->name, rdata.lval);
return (NULL);
}
*dp++ = rdata.cval[3];
break;
case 2:
if (rdata.lval >= 65536) {
printf("%s record value (%lu) out of range (0-65535)\n",
rp->name, rdata.lval);
return (NULL);
}
memcpy(dp, &rdata.sval[1], 2);
dp += 2;
break;
case 4:
memcpy(dp, &rdata.lval, 4);
dp += 4;
break;
default:
printf("huh? rp->length not 1, 2 or 4! (%d)\n", rp->length);
return (NULL);
}
return (dp);
}
static uchar *
date_handler(eerec_map_t *rp, uchar *value, uchar *dp, uchar *edp)
{
hymod_date_t date;
uchar *p = value, *ep;
date.year = simple_strtol(p, (char **)&ep, 10);
if (ep == p || *ep++ != '-') {
bad_date:
printf("%s record (%s) is not a valid date\n", rp->name, value);
return (NULL);
}
date.month = simple_strtol(p = ep, (char **)&ep, 10);
if (ep == p || *ep++ != '-' || date.month == 0 || date.month > 12)
goto bad_date;
date.day = simple_strtol(p = ep, (char **)&ep, 10);
if (ep == p || *ep != '\0' || date.day == 0 || date.day > 31)
goto bad_date;
if (dp + 2 + sizeof (hymod_date_t) > edp) {
printf("can't fit %s record into eeprom\n", rp->name);
return (NULL);
}
*dp++ = rp->type;
*dp++ = sizeof (hymod_date_t);
memcpy(dp, &date, sizeof (hymod_date_t));
dp += sizeof (hymod_date_t);
return (dp);
}
static uchar *
string_handler(eerec_map_t *rp, uchar *value, uchar *dp, uchar *edp)
{
uint len;
if ((len = strlen(value)) > rp->maxlen) {
printf("%s record (%s) string is too long (%d>%d)\n",
rp->name, value, len, rp->maxlen);
return (NULL);
}
if (dp + 2 + len > edp) {
printf("can't fit %s record into eeprom\n", rp->name);
return (NULL);
}
*dp++ = rp->type;
*dp++ = len;
memcpy(dp, value, len);
dp += len;
return (dp);
}
static uchar *
bytes_handler(eerec_map_t *rp, uchar *value, uchar *dp, uchar *edp)
{
uchar bytes[HYMOD_MAX_BYTES], nbytes = 0;
uchar *p = value, *ep;
for (;;) {
if (nbytes >= HYMOD_MAX_BYTES) {
printf("%s record (%s) byte array too long\n", rp->name, value);
return (NULL);
}
bytes[nbytes++] = simple_strtol(p, (char **)&ep, 10);
if (ep == p || (*ep != '\0' && *ep != ',')) {
printf("%s record (%s) byte array has invalid uint\n",
rp->name, value);
return (NULL);
}
if (*ep++ == '\0')
break;
p = ep;
}
if (dp + 2 + nbytes > edp) {
printf("can't fit %s record into eeprom\n", rp->name);
return (NULL);
}
*dp++ = rp->type;
*dp++ = nbytes;
memcpy(dp, bytes, nbytes);
dp += nbytes;
return (dp);
}
static eerec_map_t eerec_map[] = {
/* name type handler len max */
{ "serno", HYMOD_EEREC_SERNO, uint_handler, 4, 0 },
{ "date", HYMOD_EEREC_DATE, date_handler, 4, 0 },
{ "batch", HYMOD_EEREC_BATCH, string_handler, 0, HYMOD_MAX_BATCH },
{ "type", HYMOD_EEREC_TYPE, uint_handler, 1, 0 },
{ "rev", HYMOD_EEREC_REV, uint_handler, 1, 0 },
{ "sdram", HYMOD_EEREC_SDRAM, bytes_handler, 0, HYMOD_MAX_SDRAM },
{ "flash", HYMOD_EEREC_FLASH, bytes_handler, 0, HYMOD_MAX_FLASH },
{ "zbt", HYMOD_EEREC_ZBT, bytes_handler, 0, HYMOD_MAX_ZBT },
{ "xlxtyp", HYMOD_EEREC_XLXTYP, bytes_handler, 0, HYMOD_MAX_XLX },
{ "xlxspd", HYMOD_EEREC_XLXSPD, bytes_handler, 0, HYMOD_MAX_XLX },
{ "xlxtmp", HYMOD_EEREC_XLXTMP, bytes_handler, 0, HYMOD_MAX_XLX },
{ "xlxgrd", HYMOD_EEREC_XLXGRD, bytes_handler, 0, HYMOD_MAX_XLX },
{ "cputyp", HYMOD_EEREC_CPUTYP, uint_handler, 1, 0 },
{ "cpuspd", HYMOD_EEREC_CPUSPD, uint_handler, 1, 0 },
{ "cpmspd", HYMOD_EEREC_CPMSPD, uint_handler, 1, 0 },
{ "busspd", HYMOD_EEREC_BUSSPD, uint_handler, 1, 0 },
{ "hstype", HYMOD_EEREC_HSTYPE, uint_handler, 1, 0 },
{ "hschin", HYMOD_EEREC_HSCHIN, uint_handler, 1, 0 },
{ "hschout", HYMOD_EEREC_HSCHOUT, uint_handler, 1, 0 },
};
static int neerecs = sizeof eerec_map / sizeof eerec_map[0];
static uchar data[HYMOD_EEPROM_SIZE], *sdp, *dp, *edp;
static int
eeprom_fetch_callback(uchar *name, uchar *value)
{
eerec_map_t *rp;
for (rp = eerec_map; rp < &eerec_map[neerecs]; rp++)
if (strcmp(name, rp->name) == 0)
break;
if (rp >= &eerec_map[neerecs])
return (0);
if ((dp = (*rp->handler)(rp, value, dp, edp)) == NULL)
return (0);
return (1);
}
int
eeprom_fetch(unsigned offset, bd_t *bd, char *filename, ulong addr)
{
hymod_eehdr_t *hp = (hymod_eehdr_t *)&data[0];
ulong crc;
hp->id = HYMOD_EEPROM_ID;
hp->ver = HYMOD_EEPROM_VER;
dp = sdp = (uchar *)(hp + 1);
edp = dp + HYMOD_EEPROM_MAXLEN;
if (fetch_and_parse(bd, filename, addr, eeprom_fetch_callback) == 0)
return (0);
hp->len = dp - sdp;
crc = crc32(0, data, dp - data);
memcpy(dp, &crc, sizeof (ulong));
dp += sizeof (ulong);
eeprom_write(CFG_DEF_EEPROM_ADDR, offset, data, dp - data);
return (1);
}
static char *type_vals[] = {
"NONE", "IO", "CLP", "DSP", "INPUT", "ALT-INPUT", "DISPLAY"
};
static char *xlxtyp_vals[] = {
"NONE", "XCV300E", "XCV400E", "XCV600E"
};
static char *xlxspd_vals[] = {
"NONE", "6", "7", "8"
};
static char *xlxtmp_vals[] = {
"NONE", "COM", "IND"
};
static char *xlxgrd_vals[] = {
"NONE", "NORMAL", "ENGSAMP"
};
static char *cputyp_vals[] = {
"NONE", "MPC8260"
};
static char *clk_vals[] = {
"NONE", "33", "66", "100", "133", "166", "200"
};
static char *hstype_vals[] = {
"NONE", "AMCC-S2064A"
};
static void
print_mem(char *l, char *s, uchar n, uchar a[])
{
if (n > 0) {
if (n == 1)
printf("%s%dMB %s", s, 1 << (a[0] - 20), l);
else {
ulong t = 0;
int i;
for (i = 0; i < n; i++)
t += 1 << (a[i] - 20);
printf("%s%luMB %s (%d banks:", s, t, l, n);
for (i = 0; i < n; i++)
printf("%dMB%s", 1 << (a[i] - 20), (i == n - 1) ? ")" : ",");
}
}
else
printf("%sNO %s", s, l);
}
void
eeprom_print(hymod_eeprom_t *ep)
{
int i;
printf(" Hymod %s board, rev %03d\n",
type_vals[ep->bdtype], ep->bdrev);
printf(" serial #: %010lu, date %04d-%02d-%02d",
ep->serno, ep->date.year, ep->date.month, ep->date.day);
if (ep->batchlen > 0)
printf(", batch \"%.*s\"", ep->batchlen, ep->batch);
puts("\n");
switch (ep->bdtype) {
case HYMOD_BDTYPE_IO:
case HYMOD_BDTYPE_CLP:
case HYMOD_BDTYPE_DSP:
printf(" Motorola %s CPU, speeds: %s/%s/%s",
cputyp_vals[ep->mpc.type], clk_vals[ep->mpc.cpuspd],
clk_vals[ep->mpc.cpmspd], clk_vals[ep->mpc.busspd]);
print_mem("SDRAM", ", ", ep->nsdram, ep->sdramsz);
print_mem("FLASH", ", ", ep->nflash, ep->flashsz);
puts("\n");
print_mem("ZBT", " ", ep->nzbt, ep->zbtsz);
if (ep->nxlx > 0) {
hymod_xlx_t *xp;
if (ep->nxlx == 1) {
xp = &ep->xlx[0];
printf(", Xilinx %s FPGA (%s/%s/%s)",
xlxtyp_vals[xp->type], xlxspd_vals[xp->speed],
xlxtmp_vals[xp->temp], xlxgrd_vals[xp->grade]);
}
else {
printf(", %d Xilinx FPGAs (", ep->nxlx);
for (i = 0; i < ep->nxlx; i++) {
xp = &ep->xlx[i];
printf("%s[%s/%s/%s]%s",
xlxtyp_vals[xp->type], xlxspd_vals[xp->speed],
xlxtmp_vals[xp->temp], xlxgrd_vals[xp->grade],
(i == ep->nxlx - 1) ? ")" : ", ");
}
}
}
else
puts(", NO FPGAs");
puts("\n");
if (ep->hss.type > 0)
printf(" High Speed Serial: %s, %d input%s, %d output%s\n",
hstype_vals[ep->hss.type],
ep->hss.nchin, (ep->hss.nchin == 1 ? "" : "s"),
ep->hss.nchout, (ep->hss.nchout == 1 ? "" : "s"));
break;
case HYMOD_BDTYPE_INPUT:
case HYMOD_BDTYPE_ALTINPUT:
case HYMOD_BDTYPE_DISPLAY:
break;
default:
/* crap! */
printf(" UNKNOWN BOARD TYPE: %d\n", ep->bdtype);
break;
}
}
|