summaryrefslogtreecommitdiff
path: root/board/hymod/eeprom.c
diff options
context:
space:
mode:
Diffstat (limited to 'board/hymod/eeprom.c')
-rw-r--r--board/hymod/eeprom.c1002
1 files changed, 543 insertions, 459 deletions
diff --git a/board/hymod/eeprom.c b/board/hymod/eeprom.c
index 9d50646..01e1453 100644
--- a/board/hymod/eeprom.c
+++ b/board/hymod/eeprom.c
@@ -1,7 +1,6 @@
/*
* (C) Copyright 2001
- * Murray Jensen, CSIRO Manufacturing Science and Technology,
- * <Murray.Jensen@cmst.csiro.au>
+ * Murray Jensen, CSIRO-MIT, <Murray.Jensen@csiro.au>
*
* See file CREDITS for list of people who contributed to this
* project.
@@ -26,396 +25,408 @@
#include <mpc8260.h>
/* imports from fetch.c */
-extern int fetch_and_parse(bd_t *, char *, ulong, int (*)(uchar *, uchar *));
+extern int fetch_and_parse (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;
+/* imports from input.c */
+extern int hymod_get_serno (const char *);
- for (;;) {
- hymod_eerec_t *rp = (hymod_eerec_t *)dp;
- ulong rtyp;
- uchar rlen, *rdat;
- uint rsiz;
+/* this is relative to the root of the server's tftp directory */
+static char *def_bddb_cfgdir = "/hymod/bddb";
- 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;
- }
+static int
+hymod_eeprom_load (int which, hymod_eeprom_t *ep)
+{
+ unsigned dev_addr = CFG_I2C_EEPROM_ADDR | \
+ (which ? HYMOD_EEOFF_MEZZ : HYMOD_EEOFF_MAIN);
+ unsigned offset = 0;
+ 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 (dev_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 (dev_addr, offset, dp, len);
+ offset += len;
+
+ eeprom_read (dev_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;
+ 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: /* hs-serial chip type */
+ if (rlen == 1)
+ ep->hss.type = *rdat;
+ break;
+
+ case HYMOD_EEREC_HSCHIN: /* num hs-serial input chans */
+ if (rlen == 1)
+ ep->hss.nchin = *rdat;
+ break;
+
+ case HYMOD_EEREC_HSCHOUT: /* num hs-serial output chans */
+ if (rlen == 1)
+ ep->hss.nchout = *rdat;
+ break;
+
+ default: /* ignore */
+ break;
+ }
}
- }
- return (1);
+ 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;
- }
+ 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)
+uint_handler (eerec_map_t *rp, uchar *val, 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);
+ uchar *eval;
+ union {
+ uchar cval[4];
+ ushort sval[2];
+ ulong lval;
+ } rdata;
+
+ rdata.lval = simple_strtol (val, (char **)&eval, 10);
+
+ if (eval == val || *eval != '\0') {
+ printf ("%s rec (%s) is not a valid uint\n",
+ rp->name, val);
+ 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);
+
+ if (dp + 2 + rp->length > edp) {
+ printf ("can't fit %s rec into eeprom\n", rp->name);
+ return (NULL);
}
- memcpy(dp, &rdata.sval[1], 2);
- dp += 2;
- break;
- case 4:
- memcpy(dp, &rdata.lval, 4);
- dp += 4;
- break;
+ *dp++ = rp->type;
+ *dp++ = rp->length;
+
+ switch (rp->length) {
- default:
- printf("huh? rp->length not 1, 2 or 4! (%d)\n", rp->length);
- return (NULL);
- }
+ case 1:
+ if (rdata.lval >= 256) {
+ printf ("%s rec 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 rec 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);
+ return (dp);
}
static uchar *
-date_handler(eerec_map_t *rp, uchar *value, uchar *dp, uchar *edp)
+date_handler (eerec_map_t *rp, uchar *val, uchar *dp, uchar *edp)
{
- hymod_date_t date;
- uchar *p = value, *ep;
+ hymod_date_t date;
+ uchar *p = val, *ep;
- date.year = simple_strtol(p, (char **)&ep, 10);
- if (ep == p || *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);
- }
+ printf ("%s rec (%s) is not a valid date\n", rp->name, val);
+ 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.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;
+ 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);
- }
+ if (dp + 2 + sizeof (hymod_date_t) > edp) {
+ printf ("can't fit %s rec 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);
+ *dp++ = rp->type;
+ *dp++ = sizeof (hymod_date_t);
+ memcpy (dp, &date, sizeof (hymod_date_t));
+ dp += sizeof (hymod_date_t);
- return (dp);
+ return (dp);
}
static uchar *
-string_handler(eerec_map_t *rp, uchar *value, uchar *dp, uchar *edp)
+string_handler (eerec_map_t *rp, uchar *val, uchar *dp, uchar *edp)
{
- uint len;
+ 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 ((len = strlen (val)) > rp->maxlen) {
+ printf ("%s rec (%s) string is too long (%d>%d)\n",
+ rp->name, val, len, rp->maxlen);
+ return (NULL);
+ }
- if (dp + 2 + len > edp) {
- printf("can't fit %s record into eeprom\n", rp->name);
- return (NULL);
- }
+ if (dp + 2 + len > edp) {
+ printf ("can't fit %s rec into eeprom\n", rp->name);
+ return (NULL);
+ }
- *dp++ = rp->type;
- *dp++ = len;
- memcpy(dp, value, len);
- dp += len;
+ *dp++ = rp->type;
+ *dp++ = len;
+ memcpy (dp, val, len);
+ dp += len;
- return (dp);
+ return (dp);
}
static uchar *
-bytes_handler(eerec_map_t *rp, uchar *value, uchar *dp, uchar *edp)
+bytes_handler (eerec_map_t *rp, uchar *val, uchar *dp, uchar *edp)
{
- uchar bytes[HYMOD_MAX_BYTES], nbytes = 0;
- uchar *p = value, *ep;
+ uchar bytes[HYMOD_MAX_BYTES], nbytes = 0;
+ uchar *p = val, *ep;
- for (;;) {
+ for (;;) {
- if (nbytes >= HYMOD_MAX_BYTES) {
- printf("%s record (%s) byte array too long\n", rp->name, value);
- return (NULL);
- }
+ if (nbytes >= HYMOD_MAX_BYTES) {
+ printf ("%s rec (%s) byte array too long\n",
+ rp->name, val);
+ return (NULL);
+ }
- bytes[nbytes++] = simple_strtol(p, (char **)&ep, 10);
+ 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 == p || (*ep != '\0' && *ep != ',')) {
+ printf ("%s rec (%s) byte array has invalid uint\n",
+ rp->name, val);
+ return (NULL);
+ }
- if (*ep++ == '\0')
- break;
+ if (*ep++ == '\0')
+ break;
- p = ep;
- }
+ p = ep;
+ }
- if (dp + 2 + nbytes > edp) {
- printf("can't fit %s record into eeprom\n", rp->name);
- return (NULL);
- }
+ if (dp + 2 + nbytes > edp) {
+ printf ("can't fit %s rec into eeprom\n", rp->name);
+ return (NULL);
+ }
- *dp++ = rp->type;
- *dp++ = nbytes;
- memcpy(dp, bytes, nbytes);
- dp += nbytes;
+ *dp++ = rp->type;
+ *dp++ = nbytes;
+ memcpy (dp, bytes, nbytes);
+ dp += nbytes;
- return (dp);
+ 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 },
+ /* 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];
@@ -423,175 +434,248 @@ 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_callback (uchar *name, uchar *val)
{
- eerec_map_t *rp;
+ eerec_map_t *rp;
- for (rp = eerec_map; rp < &eerec_map[neerecs]; rp++)
- if (strcmp(name, rp->name) == 0)
- break;
+ for (rp = eerec_map; rp < &eerec_map[neerecs]; rp++)
+ if (strcmp (name, rp->name) == 0)
+ break;
- if (rp >= &eerec_map[neerecs])
- return (0);
+ if (rp >= &eerec_map[neerecs])
+ return (0);
- if ((dp = (*rp->handler)(rp, value, dp, edp)) == NULL)
- return (0);
+ if ((dp = (*rp->handler) (rp, val, dp, edp)) == NULL)
+ return (0);
- return (1);
+ return (1);
}
-int
-eeprom_fetch(unsigned offset, bd_t *bd, char *filename, ulong addr)
+static int
+hymod_eeprom_fetch(int which, char *filename, ulong addr)
{
- hymod_eehdr_t *hp = (hymod_eehdr_t *)&data[0];
- ulong crc;
+ unsigned dev_addr = CFG_I2C_EEPROM_ADDR | \
+ (which ? HYMOD_EEOFF_MEZZ : HYMOD_EEOFF_MAIN);
+ hymod_eehdr_t *hp = (hymod_eehdr_t *)&data[0];
+ ulong crc;
- hp->id = HYMOD_EEPROM_ID;
- hp->ver = HYMOD_EEPROM_VER;
+ hp->id = HYMOD_EEPROM_ID;
+ hp->ver = HYMOD_EEPROM_VER;
- dp = sdp = (uchar *)(hp + 1);
- edp = dp + HYMOD_EEPROM_MAXLEN;
+ dp = sdp = (uchar *)(hp + 1);
+ edp = dp + HYMOD_EEPROM_MAXLEN;
- if (fetch_and_parse(bd, filename, addr, eeprom_fetch_callback) == 0)
- return (0);
+ if (fetch_and_parse (filename, addr, eerec_callback) == 0)
+ return (0);
- hp->len = dp - sdp;
+ hp->len = dp - sdp;
- crc = crc32(0, data, dp - data);
- memcpy(dp, &crc, sizeof (ulong));
- dp += sizeof (ulong);
+ crc = crc32 (0, data, dp - data);
+ memcpy (dp, &crc, sizeof (ulong));
+ dp += sizeof (ulong);
- eeprom_write(CFG_DEF_EEPROM_ADDR, offset, data, dp - data);
+ eeprom_write (dev_addr, 0, data, dp - data);
- return (1);
+ return (1);
}
static char *type_vals[] = {
- "NONE", "IO", "CLP", "DSP", "INPUT", "ALT-INPUT", "DISPLAY"
+ "NONE", "IO", "CLP", "DSP", "INPUT", "ALT-INPUT", "DISPLAY"
};
static char *xlxtyp_vals[] = {
- "NONE", "XCV300E", "XCV400E", "XCV600E"
+ "NONE", "XCV300E", "XCV400E", "XCV600E"
};
static char *xlxspd_vals[] = {
- "NONE", "6", "7", "8"
+ "NONE", "6", "7", "8"
};
static char *xlxtmp_vals[] = {
- "NONE", "COM", "IND"
+ "NONE", "COM", "IND"
};
static char *xlxgrd_vals[] = {
- "NONE", "NORMAL", "ENGSAMP"
+ "NONE", "NORMAL", "ENGSAMP"
};
static char *cputyp_vals[] = {
- "NONE", "MPC8260"
+ "NONE", "MPC8260"
};
static char *clk_vals[] = {
- "NONE", "33", "66", "100", "133", "166", "200"
+ "NONE", "33", "66", "100", "133", "166", "200"
};
static char *hstype_vals[] = {
- "NONE", "AMCC-S2064A"
+ "NONE", "AMCC-S2064A"
};
static void
-print_mem(char *l, char *s, uchar n, uchar a[])
+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) ? ")" : ",");
+ 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);
+ else
+ printf ("%sNO %s", s, l);
}
void
-eeprom_print(hymod_eeprom_t *ep)
+hymod_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) ? ")" : ", ");
+ 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;
+ }
+}
+
+int
+hymod_eeprom_read (int which, hymod_eeprom_t *ep)
+{
+ char *label = which ? "mezzanine" : "main";
+ unsigned dev_addr = CFG_I2C_EEPROM_ADDR | \
+ (which ? HYMOD_EEOFF_MEZZ : HYMOD_EEOFF_MAIN);
+ char filename[50], prompt[50], *dir;
+ int serno, count = 0, rc;
+
+ rc = eeprom_probe (dev_addr, 0);
+
+ if (rc > 0) {
+ printf ("*** probe for eeprom failed with code %d\n", rc);
+ return (0);
+ }
+
+ if (rc < 0)
+ return (rc);
+
+ sprintf (prompt, "Enter %s board serial number: ", label);
+
+ if ((dir = getenv ("bddb_cfgdir")) == NULL)
+ dir = def_bddb_cfgdir;
+
+ for (;;) {
+ int rc;
+
+ if (hymod_eeprom_load (which, ep))
+ return (1);
+
+ printf ("*** %s board EEPROM contents are %sinvalid\n",
+ label, count == 0 ? "" : "STILL ");
+
+ puts ("*** will fetch from server (Ctrl-C to abort)\n");
+
+ serno = hymod_get_serno (prompt);
+
+ if (serno < 0) {
+ if (serno == -1)
+ puts ("\n*** interrupted!");
+ else
+ puts ("\n*** timeout!");
+ puts (" - ignoring eeprom contents\n");
+ return (0);
+ }
+
+ sprintf (filename, "%s/%010d.cfg", dir, serno);
+
+ printf ("*** fetching %s board EEPROM contents from server\n",
+ label);
+
+ rc = hymod_eeprom_fetch (which, filename, CFG_LOAD_ADDR);
+
+ if (rc == 0) {
+ puts ("*** fetch failed - ignoring eeprom contents\n");
+ return (0);
+ }
+
+ count++;
}
- 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;
- }
}