wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 3 | * Murray Jensen, CSIRO-MIT, <Murray.Jensen@csiro.au> |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <mpc8260.h> |
| 10 | |
| 11 | /* imports from fetch.c */ |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 12 | extern int fetch_and_parse (char *, ulong, int (*)(uchar *, uchar *)); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 13 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 14 | /* imports from input.c */ |
| 15 | extern int hymod_get_serno (const char *); |
| 16 | |
| 17 | /* this is relative to the root of the server's tftp directory */ |
| 18 | static char *def_bddb_cfgdir = "/hymod/bddb"; |
| 19 | |
| 20 | static int |
| 21 | hymod_eeprom_load (int which, hymod_eeprom_t *ep) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 22 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 23 | unsigned dev_addr = CONFIG_SYS_I2C_EEPROM_ADDR | \ |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 24 | (which ? HYMOD_EEOFF_MEZZ : HYMOD_EEOFF_MAIN); |
| 25 | unsigned offset = 0; |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 26 | uchar data[HYMOD_EEPROM_MAXLEN], *dp, *edp; |
| 27 | hymod_eehdr_t hdr; |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 28 | ulong len, crc; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 29 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 30 | memset (ep, 0, sizeof *ep); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 31 | |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 32 | eeprom_read (dev_addr, offset, (uchar *)&hdr, sizeof (hdr)); |
| 33 | offset += sizeof (hdr); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 34 | |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 35 | if (hdr.id != HYMOD_EEPROM_ID || hdr.ver > HYMOD_EEPROM_VER || |
| 36 | (len = hdr.len) > HYMOD_EEPROM_MAXLEN) |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 37 | return (0); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 38 | |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 39 | eeprom_read (dev_addr, offset, data, len); |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 40 | offset += len; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 41 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 42 | eeprom_read (dev_addr, offset, (uchar *)&crc, sizeof (ulong)); |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 43 | offset += sizeof (ulong); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 44 | |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 45 | if (crc32 (crc32 (0, (uchar *)&hdr, sizeof hdr), data, len) != crc) |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 46 | return (0); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 47 | |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 48 | ep->ver = hdr.ver; |
| 49 | dp = data; edp = dp + len; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 50 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 51 | for (;;) { |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 52 | ulong rtyp; |
| 53 | uchar rlen, *rdat; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 54 | |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 55 | rtyp = *dp++; |
| 56 | if ((rtyp & 0x80) == 0) |
| 57 | rlen = *dp++; |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 58 | else { |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 59 | 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 | } |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 73 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 74 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 75 | if (rtyp == 0) |
| 76 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 77 | |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 78 | rdat = dp; |
| 79 | dp += rlen; |
| 80 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 81 | if (dp > edp) /* error? */ |
| 82 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 83 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 84 | switch (rtyp) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 85 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 86 | case HYMOD_EEREC_SERNO: /* serial number */ |
| 87 | if (rlen == sizeof (ulong)) |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 88 | ep->serno = \ |
| 89 | ((ulong)rdat[0] << 24) | \ |
| 90 | ((ulong)rdat[1] << 16) | \ |
| 91 | ((ulong)rdat[2] << 8) | \ |
| 92 | (ulong)rdat[3]; |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 93 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 94 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 95 | case HYMOD_EEREC_DATE: /* date */ |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 96 | 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 | } |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 102 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 103 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 104 | case HYMOD_EEREC_BATCH: /* batch */ |
| 105 | if (rlen <= HYMOD_MAX_BATCH) |
| 106 | memcpy (ep->batch, rdat, ep->batchlen = rlen); |
| 107 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 108 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 109 | case HYMOD_EEREC_TYPE: /* board type */ |
| 110 | if (rlen == 1) |
| 111 | ep->bdtype = *rdat; |
| 112 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 113 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 114 | case HYMOD_EEREC_REV: /* board revision */ |
| 115 | if (rlen == 1) |
| 116 | ep->bdrev = *rdat; |
| 117 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 118 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 119 | case HYMOD_EEREC_SDRAM: /* sdram size(s) */ |
| 120 | if (rlen > 0 && rlen <= HYMOD_MAX_SDRAM) { |
| 121 | int i; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 122 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 123 | for (i = 0; i < rlen; i++) |
| 124 | ep->sdramsz[i] = rdat[i]; |
| 125 | ep->nsdram = rlen; |
| 126 | } |
| 127 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 128 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 129 | case HYMOD_EEREC_FLASH: /* flash size(s) */ |
| 130 | if (rlen > 0 && rlen <= HYMOD_MAX_FLASH) { |
| 131 | int i; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 132 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 133 | for (i = 0; i < rlen; i++) |
| 134 | ep->flashsz[i] = rdat[i]; |
| 135 | ep->nflash = rlen; |
| 136 | } |
| 137 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 138 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 139 | case HYMOD_EEREC_ZBT: /* zbt ram size(s) */ |
| 140 | if (rlen > 0 && rlen <= HYMOD_MAX_ZBT) { |
| 141 | int i; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 142 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 143 | for (i = 0; i < rlen; i++) |
| 144 | ep->zbtsz[i] = rdat[i]; |
| 145 | ep->nzbt = rlen; |
| 146 | } |
| 147 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 148 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 149 | case HYMOD_EEREC_XLXTYP: /* xilinx fpga type(s) */ |
| 150 | if (rlen > 0 && rlen <= HYMOD_MAX_XLX) { |
| 151 | int i; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 152 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 153 | for (i = 0; i < rlen; i++) |
| 154 | ep->xlx[i].type = rdat[i]; |
| 155 | ep->nxlx = rlen; |
| 156 | } |
| 157 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 158 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 159 | case HYMOD_EEREC_XLXSPD: /* xilinx fpga speed(s) */ |
| 160 | if (rlen > 0 && rlen <= HYMOD_MAX_XLX) { |
| 161 | int i; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 162 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 163 | for (i = 0; i < rlen; i++) |
| 164 | ep->xlx[i].speed = rdat[i]; |
| 165 | } |
| 166 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 167 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 168 | case HYMOD_EEREC_XLXTMP: /* xilinx fpga temperature(s) */ |
| 169 | if (rlen > 0 && rlen <= HYMOD_MAX_XLX) { |
| 170 | int i; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 171 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 172 | for (i = 0; i < rlen; i++) |
| 173 | ep->xlx[i].temp = rdat[i]; |
| 174 | } |
| 175 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 176 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 177 | case HYMOD_EEREC_XLXGRD: /* xilinx fpga grade(s) */ |
| 178 | if (rlen > 0 && rlen <= HYMOD_MAX_XLX) { |
| 179 | int i; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 180 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 181 | for (i = 0; i < rlen; i++) |
| 182 | ep->xlx[i].grade = rdat[i]; |
| 183 | } |
| 184 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 185 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 186 | case HYMOD_EEREC_CPUTYP: /* CPU type */ |
| 187 | if (rlen == 1) |
| 188 | ep->mpc.type = *rdat; |
| 189 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 190 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 191 | case HYMOD_EEREC_CPUSPD: /* CPU speed */ |
| 192 | if (rlen == 1) |
| 193 | ep->mpc.cpuspd = *rdat; |
| 194 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 195 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 196 | case HYMOD_EEREC_CPMSPD: /* CPM speed */ |
| 197 | if (rlen == 1) |
| 198 | ep->mpc.cpmspd = *rdat; |
| 199 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 200 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 201 | case HYMOD_EEREC_BUSSPD: /* bus speed */ |
| 202 | if (rlen == 1) |
| 203 | ep->mpc.busspd = *rdat; |
| 204 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 205 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 206 | case HYMOD_EEREC_HSTYPE: /* hs-serial chip type */ |
| 207 | if (rlen == 1) |
| 208 | ep->hss.type = *rdat; |
| 209 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 210 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 211 | case HYMOD_EEREC_HSCHIN: /* num hs-serial input chans */ |
| 212 | if (rlen == 1) |
| 213 | ep->hss.nchin = *rdat; |
| 214 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 215 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 216 | case HYMOD_EEREC_HSCHOUT: /* num hs-serial output chans */ |
| 217 | if (rlen == 1) |
| 218 | ep->hss.nchout = *rdat; |
| 219 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 220 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 221 | default: /* ignore */ |
| 222 | break; |
| 223 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 224 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 225 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 226 | return (1); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | /* maps an ascii "name=value" into a binary eeprom data record */ |
| 230 | typedef |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 231 | 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 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 239 | eerec_map_t; |
| 240 | |
| 241 | static uchar * |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 242 | uint_handler (eerec_map_t *rp, uchar *val, uchar *dp, uchar *edp) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 243 | { |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 244 | char *eval; |
| 245 | ulong lval; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 246 | |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 247 | lval = simple_strtol ((char *)val, &eval, 10); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 248 | |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 249 | if ((uchar *)eval == val || *eval != '\0') { |
| 250 | printf ("%s rec (%s) is not a valid uint\n", rp->name, val); |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 251 | return (NULL); |
| 252 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 253 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 254 | if (dp + 2 + rp->length > edp) { |
| 255 | printf ("can't fit %s rec into eeprom\n", rp->name); |
| 256 | return (NULL); |
| 257 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 258 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 259 | *dp++ = rp->type; |
| 260 | *dp++ = rp->length; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 261 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 262 | switch (rp->length) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 263 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 264 | case 1: |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 265 | if (lval >= 256) { |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 266 | printf ("%s rec value (%lu) out of range (0-255)\n", |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 267 | rp->name, lval); |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 268 | return (NULL); |
| 269 | } |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 270 | *dp++ = lval; |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 271 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 272 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 273 | case 2: |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 274 | if (lval >= 65536) { |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 275 | printf ("%s rec value (%lu) out of range (0-65535)\n", |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 276 | rp->name, lval); |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 277 | return (NULL); |
| 278 | } |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 279 | *dp++ = lval >> 8; |
| 280 | *dp++ = lval; |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 281 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 282 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 283 | case 4: |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 284 | *dp++ = lval >> 24; |
| 285 | *dp++ = lval >> 16; |
| 286 | *dp++ = lval >> 8; |
| 287 | *dp++ = lval; |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 288 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 289 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 290 | default: |
| 291 | printf ("huh? rp->length not 1, 2 or 4! (%d)\n", rp->length); |
| 292 | return (NULL); |
| 293 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 294 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 295 | return (dp); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | static uchar * |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 299 | date_handler (eerec_map_t *rp, uchar *val, uchar *dp, uchar *edp) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 300 | { |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 301 | hymod_date_t date; |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 302 | char *p = (char *)val; |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 303 | char *ep; |
| 304 | ulong lval; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 305 | |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 306 | lval = simple_strtol (p, &ep, 10); |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 307 | if (ep == p || *ep++ != '-') { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 308 | bad_date: |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 309 | printf ("%s rec (%s) is not a valid date\n", rp->name, val); |
| 310 | return (NULL); |
| 311 | } |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 312 | if (lval >= 65536) |
| 313 | goto bad_date; |
| 314 | date.year = lval; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 315 | |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 316 | lval = simple_strtol (p = ep, &ep, 10); |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 317 | if (ep == p || *ep++ != '-' || lval == 0 || lval > 12) |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 318 | goto bad_date; |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 319 | date.month = lval; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 320 | |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 321 | lval = simple_strtol (p = ep, &ep, 10); |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 322 | if (ep == p || *ep != '\0' || lval == 0 || lval > 31) |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 323 | goto bad_date; |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 324 | date.day = lval; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 325 | |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 326 | if (dp + 2 + rp->length > edp) { |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 327 | printf ("can't fit %s rec into eeprom\n", rp->name); |
| 328 | return (NULL); |
| 329 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 330 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 331 | *dp++ = rp->type; |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 332 | *dp++ = rp->length; |
| 333 | *dp++ = date.year >> 8; |
| 334 | *dp++ = date.year; |
| 335 | *dp++ = date.month; |
| 336 | *dp++ = date.day; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 337 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 338 | return (dp); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | static uchar * |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 342 | string_handler (eerec_map_t *rp, uchar *val, uchar *dp, uchar *edp) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 343 | { |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 344 | uint len; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 345 | |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 346 | if ((len = strlen ((char *)val)) > rp->maxlen) { |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 347 | printf ("%s rec (%s) string is too long (%d>%d)\n", |
| 348 | rp->name, val, len, rp->maxlen); |
| 349 | return (NULL); |
| 350 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 351 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 352 | if (dp + 2 + len > edp) { |
| 353 | printf ("can't fit %s rec into eeprom\n", rp->name); |
| 354 | return (NULL); |
| 355 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 356 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 357 | *dp++ = rp->type; |
| 358 | *dp++ = len; |
| 359 | memcpy (dp, val, len); |
| 360 | dp += len; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 361 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 362 | return (dp); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | static uchar * |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 366 | bytes_handler (eerec_map_t *rp, uchar *val, uchar *dp, uchar *edp) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 367 | { |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 368 | uchar bytes[HYMOD_MAX_BYTES], nbytes, *p; |
| 369 | char *ep; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 370 | |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 371 | for (nbytes = 0, p = val; *p != '\0'; p = (uchar *)ep) { |
| 372 | ulong lval; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 373 | |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 374 | lval = simple_strtol ((char *)p, &ep, 10); |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 375 | if ((uchar *)ep == p || (*ep != '\0' && *ep != ',') || \ |
| 376 | lval >= 256) { |
| 377 | printf ("%s rec (%s) byte array has invalid uint\n", |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 378 | rp->name, val); |
| 379 | return (NULL); |
| 380 | } |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 381 | if (nbytes >= HYMOD_MAX_BYTES) { |
| 382 | printf ("%s rec (%s) byte array too long\n", |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 383 | rp->name, val); |
| 384 | return (NULL); |
| 385 | } |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 386 | bytes[nbytes++] = lval; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 387 | |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 388 | if (*ep != '\0') |
| 389 | ep++; |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 390 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 391 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 392 | if (dp + 2 + nbytes > edp) { |
| 393 | printf ("can't fit %s rec into eeprom\n", rp->name); |
| 394 | return (NULL); |
| 395 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 396 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 397 | *dp++ = rp->type; |
| 398 | *dp++ = nbytes; |
| 399 | memcpy (dp, bytes, nbytes); |
| 400 | dp += nbytes; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 401 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 402 | return (dp); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | static eerec_map_t eerec_map[] = { |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 406 | /* 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 }, |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 426 | }; |
| 427 | |
| 428 | static int neerecs = sizeof eerec_map / sizeof eerec_map[0]; |
| 429 | |
| 430 | static uchar data[HYMOD_EEPROM_SIZE], *sdp, *dp, *edp; |
| 431 | |
| 432 | static int |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 433 | eerec_callback (uchar *name, uchar *val) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 434 | { |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 435 | eerec_map_t *rp; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 436 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 437 | for (rp = eerec_map; rp < &eerec_map[neerecs]; rp++) |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 438 | if (strcmp ((char *)name, rp->name) == 0) |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 439 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 440 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 441 | if (rp >= &eerec_map[neerecs]) |
| 442 | return (0); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 443 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 444 | if ((dp = (*rp->handler) (rp, val, dp, edp)) == NULL) |
| 445 | return (0); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 446 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 447 | return (1); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 448 | } |
| 449 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 450 | static int |
| 451 | hymod_eeprom_fetch(int which, char *filename, ulong addr) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 452 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 453 | unsigned dev_addr = CONFIG_SYS_I2C_EEPROM_ADDR | \ |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 454 | (which ? HYMOD_EEOFF_MEZZ : HYMOD_EEOFF_MAIN); |
| 455 | hymod_eehdr_t *hp = (hymod_eehdr_t *)&data[0]; |
| 456 | ulong crc; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 457 | |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 458 | memset (hp, 0, sizeof *hp); |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 459 | hp->id = HYMOD_EEPROM_ID; |
| 460 | hp->ver = HYMOD_EEPROM_VER; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 461 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 462 | dp = sdp = (uchar *)(hp + 1); |
| 463 | edp = dp + HYMOD_EEPROM_MAXLEN; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 464 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 465 | if (fetch_and_parse (filename, addr, eerec_callback) == 0) |
| 466 | return (0); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 467 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 468 | hp->len = dp - sdp; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 469 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 470 | crc = crc32 (0, data, dp - data); |
| 471 | memcpy (dp, &crc, sizeof (ulong)); |
| 472 | dp += sizeof (ulong); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 473 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 474 | eeprom_write (dev_addr, 0, data, dp - data); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 475 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 476 | return (1); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | static char *type_vals[] = { |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 480 | "NONE", "IO", "CLP", "DSP", "INPUT", "ALT-INPUT", "DISPLAY" |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 481 | }; |
| 482 | |
| 483 | static char *xlxtyp_vals[] = { |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 484 | "NONE", "XCV300E", "XCV400E", "XCV600E" |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 485 | }; |
| 486 | |
| 487 | static char *xlxspd_vals[] = { |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 488 | "NONE", "6", "7", "8" |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 489 | }; |
| 490 | |
| 491 | static char *xlxtmp_vals[] = { |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 492 | "NONE", "COM", "IND" |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 493 | }; |
| 494 | |
| 495 | static char *xlxgrd_vals[] = { |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 496 | "NONE", "NORMAL", "ENGSAMP" |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 497 | }; |
| 498 | |
| 499 | static char *cputyp_vals[] = { |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 500 | "NONE", "MPC8260" |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 501 | }; |
| 502 | |
| 503 | static char *clk_vals[] = { |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 504 | "NONE", "33", "66", "100", "133", "166", "200" |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 505 | }; |
| 506 | |
| 507 | static char *hstype_vals[] = { |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 508 | "NONE", "AMCC-S2064A" |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 509 | }; |
| 510 | |
| 511 | static void |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 512 | print_mem (char *l, char *s, uchar n, uchar a[]) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 513 | { |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 514 | 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; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 520 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 521 | for (i = 0; i < n; i++) |
| 522 | t += 1 << (a[i] - 20); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 523 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 524 | printf ("%s%luMB %s (%d banks:", s, t, l, n); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 525 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 526 | for (i = 0; i < n; i++) |
| 527 | printf ("%dMB%s", |
| 528 | 1 << (a[i] - 20), |
| 529 | (i == n - 1) ? ")" : ","); |
| 530 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 531 | } |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 532 | else |
| 533 | printf ("%sNO %s", s, l); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | void |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 537 | hymod_eeprom_print (hymod_eeprom_t *ep) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 538 | { |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 539 | int i; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 540 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 541 | printf (" Hymod %s board, rev %03d\n", |
| 542 | type_vals[ep->bdtype], ep->bdrev); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 543 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 544 | 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"); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 549 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 550 | switch (ep->bdtype) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 551 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 552 | 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]); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 558 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 559 | print_mem ("SDRAM", ", ", ep->nsdram, ep->sdramsz); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 560 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 561 | print_mem ("FLASH", ", ", ep->nflash, ep->flashsz); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 562 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 563 | puts ("\n"); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 564 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 565 | print_mem ("ZBT", " ", ep->nzbt, ep->zbtsz); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 566 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 567 | if (ep->nxlx > 0) { |
| 568 | hymod_xlx_t *xp; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 569 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 570 | 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 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 590 | } |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 591 | 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; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 615 | } |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 616 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 617 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 618 | int |
| 619 | hymod_eeprom_read (int which, hymod_eeprom_t *ep) |
| 620 | { |
| 621 | char *label = which ? "mezzanine" : "main"; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 622 | unsigned dev_addr = CONFIG_SYS_I2C_EEPROM_ADDR | \ |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 623 | (which ? HYMOD_EEOFF_MEZZ : HYMOD_EEOFF_MAIN); |
| 624 | char filename[50], prompt[50], *dir; |
| 625 | int serno, count = 0, rc; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 626 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 627 | rc = eeprom_probe (dev_addr, 0); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 628 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 629 | if (rc > 0) { |
| 630 | printf ("*** probe for eeprom failed with code %d\n", rc); |
| 631 | return (0); |
| 632 | } |
| 633 | |
| 634 | if (rc < 0) |
| 635 | return (rc); |
| 636 | |
| 637 | sprintf (prompt, "Enter %s board serial number: ", label); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 638 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 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-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 669 | rc = hymod_eeprom_fetch (which, filename, CONFIG_SYS_LOAD_ADDR); |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 670 | |
| 671 | if (rc == 0) { |
| 672 | puts ("*** fetch failed - ignoring eeprom contents\n"); |
| 673 | return (0); |
| 674 | } |
| 675 | |
| 676 | count++; |
| 677 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 678 | } |