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