blob: 3e1e3321695de7279c3d53eb8fa7a51ab48cc75e [file] [log] [blame]
Haiying Wang34c68782006-07-12 10:48:05 -04001/*
Haiying Wange5607542009-06-04 16:12:40 -04002 * Copyright 2006, 2008-2009 Freescale Semiconductor
Haiying Wang34c68782006-07-12 10:48:05 -04003 * York Sun (yorksun@freescale.com)
4 * Haiying Wang (haiying.wang@freescale.com)
Timur Tabibdea8372008-06-19 17:56:11 -05005 * Timur Tabi (timur@freescale.com)
Haiying Wang34c68782006-07-12 10:48:05 -04006 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
24 */
25
26#include <common.h>
27#include <command.h>
28#include <i2c.h>
29#include <linux/ctype.h>
30
Timur Tabibdea8372008-06-19 17:56:11 -050031#include "../common/eeprom.h"
Haiying Wang34c68782006-07-12 10:48:05 -040032
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020033#if !defined(CONFIG_SYS_I2C_EEPROM_CCID) && !defined(CONFIG_SYS_I2C_EEPROM_NXID)
34#error "Please define either CONFIG_SYS_I2C_EEPROM_CCID or CONFIG_SYS_I2C_EEPROM_NXID"
Timur Tabibdea8372008-06-19 17:56:11 -050035#endif
Haiying Wang34c68782006-07-12 10:48:05 -040036
Haiying Wange5607542009-06-04 16:12:40 -040037#define MAX_NUM_PORTS 8 /* This value must be 8 as defined in doc */
38
Timur Tabibdea8372008-06-19 17:56:11 -050039/**
40 * static eeprom: EEPROM layout for CCID or NXID formats
41 *
42 * See application note AN3638 for details.
43 */
44static struct __attribute__ ((__packed__)) eeprom {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020045#ifdef CONFIG_SYS_I2C_EEPROM_CCID
Timur Tabibdea8372008-06-19 17:56:11 -050046 u8 id[4]; /* 0x00 - 0x03 EEPROM Tag 'CCID' */
47 u8 major; /* 0x04 Board revision, major */
48 u8 minor; /* 0x05 Board revision, minor */
49 u8 sn[10]; /* 0x06 - 0x0F Serial Number*/
50 u8 errata[2]; /* 0x10 - 0x11 Errata Level */
51 u8 date[6]; /* 0x12 - 0x17 Build Date */
52 u8 res_0[40]; /* 0x18 - 0x3f Reserved */
53 u8 mac_count; /* 0x40 Number of MAC addresses */
54 u8 mac_flag; /* 0x41 MAC table flags */
Haiying Wange5607542009-06-04 16:12:40 -040055 u8 mac[MAX_NUM_PORTS][6]; /* 0x42 - 0x71 MAC addresses */
Timur Tabibdea8372008-06-19 17:56:11 -050056 u32 crc; /* 0x72 CRC32 checksum */
57#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020058#ifdef CONFIG_SYS_I2C_EEPROM_NXID
Timur Tabibdea8372008-06-19 17:56:11 -050059 u8 id[4]; /* 0x00 - 0x03 EEPROM Tag 'NXID' */
60 u8 sn[12]; /* 0x04 - 0x0F Serial Number */
61 u8 errata[5]; /* 0x10 - 0x14 Errata Level */
62 u8 date[6]; /* 0x15 - 0x1a Build Date */
63 u8 res_0; /* 0x1b Reserved */
64 u32 version; /* 0x1c - 0x1f NXID Version */
65 u8 tempcal[8]; /* 0x20 - 0x27 Temperature Calibration Factors */
66 u8 tempcalsys[2]; /* 0x28 - 0x29 System Temperature Calibration Factors */
67 u8 tempcalflags; /* 0x2a Temperature Calibration Flags */
68 u8 res_1[21]; /* 0x2b - 0x3f Reserved */
69 u8 mac_count; /* 0x40 Number of MAC addresses */
70 u8 mac_flag; /* 0x41 MAC table flags */
Haiying Wange5607542009-06-04 16:12:40 -040071 u8 mac[MAX_NUM_PORTS][6]; /* 0x42 - 0x71 MAC addresses */
Timur Tabibdea8372008-06-19 17:56:11 -050072 u32 crc; /* 0x72 CRC32 checksum */
73#endif
74} e;
75
76/* Set to 1 if we've read EEPROM into memory */
77static int has_been_read = 0;
78
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020079#ifdef CONFIG_SYS_I2C_EEPROM_NXID
Timur Tabibdea8372008-06-19 17:56:11 -050080/* Is this a valid NXID EEPROM? */
Kumar Gala4dc62452009-07-03 12:45:44 -050081#define is_valid ((e.id[0] == 'N') || (e.id[1] == 'X') || \
82 (e.id[2] == 'I') || (e.id[3] == 'D'))
Timur Tabibdea8372008-06-19 17:56:11 -050083#endif
84
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020085#ifdef CONFIG_SYS_I2C_EEPROM_CCID
Timur Tabibdea8372008-06-19 17:56:11 -050086/* Is this a valid CCID EEPROM? */
Kumar Gala4dc62452009-07-03 12:45:44 -050087#define is_valid ((e.id[0] == 'C') || (e.id[1] == 'C') || \
88 (e.id[2] == 'I') || (e.id[3] == 'D'))
Timur Tabibdea8372008-06-19 17:56:11 -050089#endif
90
91/**
92 * show_eeprom - display the contents of the EEPROM
93 */
94static void show_eeprom(void)
Haiying Wang34c68782006-07-12 10:48:05 -040095{
96 int i;
Timur Tabibdea8372008-06-19 17:56:11 -050097 unsigned int crc;
Haiying Wang34c68782006-07-12 10:48:05 -040098
Timur Tabibdea8372008-06-19 17:56:11 -050099 /* EEPROM tag ID, either CCID or NXID */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200100#ifdef CONFIG_SYS_I2C_EEPROM_NXID
Timur Tabibdea8372008-06-19 17:56:11 -0500101 printf("ID: %c%c%c%c v%u\n", e.id[0], e.id[1], e.id[2], e.id[3],
102 be32_to_cpu(e.version));
103#else
104 printf("ID: %c%c%c%c\n", e.id[0], e.id[1], e.id[2], e.id[3]);
105#endif
Haiying Wang34cf9592008-01-16 17:12:12 -0500106
Timur Tabibdea8372008-06-19 17:56:11 -0500107 /* Serial number */
108 printf("SN: %s\n", e.sn);
Haiying Wang34cf9592008-01-16 17:12:12 -0500109
Timur Tabibdea8372008-06-19 17:56:11 -0500110 /* Errata level. */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200111#ifdef CONFIG_SYS_I2C_EEPROM_NXID
Timur Tabibdea8372008-06-19 17:56:11 -0500112 printf("Errata: %s\n", e.errata);
113#else
114 printf("Errata: %c%c\n",
115 e.errata[0] ? e.errata[0] : '.',
116 e.errata[1] ? e.errata[1] : '.');
117#endif
Haiying Wang34cf9592008-01-16 17:12:12 -0500118
Timur Tabibdea8372008-06-19 17:56:11 -0500119 /* Build date, BCD date values, as YYMMDDhhmmss */
120 printf("Build date: 20%02x/%02x/%02x %02x:%02x:%02x %s\n",
121 e.date[0], e.date[1], e.date[2],
122 e.date[3] & 0x7F, e.date[4], e.date[5],
123 e.date[3] & 0x80 ? "PM" : "");
Haiying Wang34cf9592008-01-16 17:12:12 -0500124
Timur Tabibdea8372008-06-19 17:56:11 -0500125 /* Show MAC addresses */
Haiying Wange5607542009-06-04 16:12:40 -0400126 for (i = 0; i < min(e.mac_count, MAX_NUM_PORTS); i++) {
127
Timur Tabibdea8372008-06-19 17:56:11 -0500128 u8 *p = e.mac[i];
Haiying Wang34cf9592008-01-16 17:12:12 -0500129
Timur Tabibdea8372008-06-19 17:56:11 -0500130 printf("Eth%u: %02x:%02x:%02x:%02x:%02x:%02x\n", i,
131 p[0], p[1], p[2], p[3], p[4], p[5]);
132 }
Haiying Wang34cf9592008-01-16 17:12:12 -0500133
Timur Tabibdea8372008-06-19 17:56:11 -0500134 crc = crc32(0, (void *)&e, sizeof(e) - 4);
Haiying Wang34c68782006-07-12 10:48:05 -0400135
Timur Tabibdea8372008-06-19 17:56:11 -0500136 if (crc == be32_to_cpu(e.crc))
137 printf("CRC: %08x\n", be32_to_cpu(e.crc));
138 else
139 printf("CRC: %08x (should be %08x)\n",
140 be32_to_cpu(e.crc), crc);
Haiying Wang34c68782006-07-12 10:48:05 -0400141
Timur Tabibdea8372008-06-19 17:56:11 -0500142#ifdef DEBUG
143 printf("EEPROM dump: (0x%x bytes)\n", sizeof(e));
144 for (i = 0; i < sizeof(e); i++) {
145 if ((i % 16) == 0)
146 printf("%02X: ", i);
147 printf("%02X ", ((u8 *)&e)[i]);
148 if (((i % 16) == 15) || (i == sizeof(e) - 1))
149 printf("\n");
150 }
151#endif
Haiying Wang34c68782006-07-12 10:48:05 -0400152}
153
Timur Tabibdea8372008-06-19 17:56:11 -0500154/**
155 * read_eeprom - read the EEPROM into memory
156 */
157static int read_eeprom(void)
Haiying Wang34c68782006-07-12 10:48:05 -0400158{
Timur Tabibdea8372008-06-19 17:56:11 -0500159 int ret;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200160#ifdef CONFIG_SYS_EEPROM_BUS_NUM
Timur Tabibdea8372008-06-19 17:56:11 -0500161 unsigned int bus;
162#endif
Haiying Wang34c68782006-07-12 10:48:05 -0400163
Timur Tabibdea8372008-06-19 17:56:11 -0500164 if (has_been_read)
165 return 0;
Haiying Wang34c68782006-07-12 10:48:05 -0400166
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200167#ifdef CONFIG_SYS_EEPROM_BUS_NUM
Timur Tabibdea8372008-06-19 17:56:11 -0500168 bus = i2c_get_bus_num();
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200169 i2c_set_bus_num(CONFIG_SYS_EEPROM_BUS_NUM);
Timur Tabibdea8372008-06-19 17:56:11 -0500170#endif
171
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200172 ret = i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
Timur Tabibdea8372008-06-19 17:56:11 -0500173 (void *)&e, sizeof(e));
174
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200175#ifdef CONFIG_SYS_EEPROM_BUS_NUM
Timur Tabibdea8372008-06-19 17:56:11 -0500176 i2c_set_bus_num(bus);
177#endif
178
179#ifdef DEBUG
180 show_eeprom();
181#endif
182
183 has_been_read = (ret == 0) ? 1 : 0;
184
185 return ret;
Haiying Wang34c68782006-07-12 10:48:05 -0400186}
187
Timur Tabibdea8372008-06-19 17:56:11 -0500188/**
189 * prog_eeprom - write the EEPROM from memory
190 */
191static int prog_eeprom(void)
Haiying Wang34c68782006-07-12 10:48:05 -0400192{
193 int ret, i, length;
Timur Tabibdea8372008-06-19 17:56:11 -0500194 unsigned int crc;
195 void *p;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200196#ifdef CONFIG_SYS_EEPROM_BUS_NUM
Timur Tabibdea8372008-06-19 17:56:11 -0500197 unsigned int bus;
198#endif
Haiying Wang34c68782006-07-12 10:48:05 -0400199
Timur Tabibdea8372008-06-19 17:56:11 -0500200 /* Set the reserved values to 0xFF */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200201#ifdef CONFIG_SYS_I2C_EEPROM_NXID
Timur Tabibdea8372008-06-19 17:56:11 -0500202 e.res_0 = 0xFF;
203 memset(e.res_1, 0xFF, sizeof(e.res_1));
204#else
205 memset(e.res_0, 0xFF, sizeof(e.res_0));
206#endif
Haiying Wang34cf9592008-01-16 17:12:12 -0500207
Timur Tabibdea8372008-06-19 17:56:11 -0500208 length = sizeof(e);
209 crc = crc32(0, (void *)&e, length - 4);
210 e.crc = cpu_to_be32(crc);
211
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200212#ifdef CONFIG_SYS_EEPROM_BUS_NUM
Timur Tabibdea8372008-06-19 17:56:11 -0500213 bus = i2c_get_bus_num();
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200214 i2c_set_bus_num(CONFIG_SYS_EEPROM_BUS_NUM);
Timur Tabibdea8372008-06-19 17:56:11 -0500215#endif
216
217 for (i = 0, p = &e; i < length; i += 8, p += 8) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200218 ret = i2c_write(CONFIG_SYS_I2C_EEPROM_ADDR, i, CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
Timur Tabibdea8372008-06-19 17:56:11 -0500219 p, min((length - i), 8));
Haiying Wang34c68782006-07-12 10:48:05 -0400220 if (ret)
221 break;
Timur Tabibdea8372008-06-19 17:56:11 -0500222 udelay(5000); /* 5ms write cycle timing */
Haiying Wang34c68782006-07-12 10:48:05 -0400223 }
Timur Tabibdea8372008-06-19 17:56:11 -0500224
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200225#ifdef CONFIG_SYS_EEPROM_BUS_NUM
Timur Tabibdea8372008-06-19 17:56:11 -0500226 i2c_set_bus_num(bus);
227#endif
228
Haiying Wang34c68782006-07-12 10:48:05 -0400229 if (ret) {
230 printf("Programming failed.\n");
231 return -1;
Haiying Wang34c68782006-07-12 10:48:05 -0400232 }
Timur Tabibdea8372008-06-19 17:56:11 -0500233
234 printf("Programming passed.\n");
Haiying Wang34c68782006-07-12 10:48:05 -0400235 return 0;
236}
237
Timur Tabibdea8372008-06-19 17:56:11 -0500238/**
239 * h2i - converts hex character into a number
240 *
241 * This function takes a hexadecimal character (e.g. '7' or 'C') and returns
242 * the integer equivalent.
243 */
244static inline u8 h2i(char p)
245{
246 if ((p >= '0') && (p <= '9'))
247 return p - '0';
248
249 if ((p >= 'A') && (p <= 'F'))
250 return (p - 'A') + 10;
251
252 if ((p >= 'a') && (p <= 'f'))
253 return (p - 'a') + 10;
254
255 return 0;
256}
257
258/**
259 * set_date - stores the build date into the EEPROM
260 *
261 * This function takes a pointer to a string in the format "YYMMDDhhmmss"
262 * (2-digit year, 2-digit month, etc), converts it to a 6-byte BCD string,
263 * and stores it in the build date field of the EEPROM local copy.
264 */
265static void set_date(const char *string)
266{
267 unsigned int i;
268
269 if (strlen(string) != 12) {
270 printf("Usage: mac date YYMMDDhhmmss\n");
271 return;
272 }
273
274 for (i = 0; i < 6; i++)
275 e.date[i] = h2i(string[2 * i]) << 4 | h2i(string[2 * i + 1]);
276}
277
278/**
279 * set_mac_address - stores a MAC address into the EEPROM
280 *
281 * This function takes a pointer to MAC address string
282 * (i.e."XX:XX:XX:XX:XX:XX", where "XX" is a two-digit hex number) and
283 * stores it in one of the MAC address fields of the EEPROM local copy.
284 */
285static void set_mac_address(unsigned int index, const char *string)
286{
287 char *p = (char *) string;
288 unsigned int i;
289
290 if (!string) {
291 printf("Usage: mac <n> XX:XX:XX:XX:XX:XX\n");
292 return;
293 }
294
295 for (i = 0; *p && (i < 6); i++) {
296 e.mac[index][i] = simple_strtoul(p, &p, 16);
297 if (*p == ':')
298 p++;
299 }
300}
301
302int do_mac(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
Haiying Wang34c68782006-07-12 10:48:05 -0400303{
304 int i;
Timur Tabibdea8372008-06-19 17:56:11 -0500305 char cmd;
Haiying Wang34c68782006-07-12 10:48:05 -0400306
Timur Tabibdea8372008-06-19 17:56:11 -0500307 if (argc == 1) {
308 show_eeprom();
309 return 0;
310 }
311
312 cmd = argv[1][0];
313
314 if (cmd == 'r') {
315 read_eeprom();
316 return 0;
317 }
Haiying Wang34c68782006-07-12 10:48:05 -0400318
Timur Tabibdea8372008-06-19 17:56:11 -0500319 if ((cmd == 'i') && (argc > 2)) {
320 for (i = 0; i < 4; i++)
321 e.id[i] = argv[2][i];
322 return 0;
323 }
324
325 if (!is_valid) {
326 printf("Please read the EEPROM ('r') and/or set the ID ('i') first.\n");
327 return 0;
328 }
329
330 if (argc == 2) {
Haiying Wang34c68782006-07-12 10:48:05 -0400331 switch (cmd) {
Jon Loeliger4fbb09c2006-08-22 12:25:27 -0500332 case 's': /* save */
Timur Tabibdea8372008-06-19 17:56:11 -0500333 prog_eeprom();
Jon Loeliger4fbb09c2006-08-22 12:25:27 -0500334 break;
Jon Loeliger4fbb09c2006-08-22 12:25:27 -0500335 default:
Peter Tyserddb3af92009-01-27 18:03:10 -0600336 cmd_usage(cmdtp);
Jon Loeliger4fbb09c2006-08-22 12:25:27 -0500337 break;
Haiying Wang34c68782006-07-12 10:48:05 -0400338 }
Timur Tabibdea8372008-06-19 17:56:11 -0500339
340 return 0;
341 }
342
343 /* We know we have at least one parameter */
344
345 switch (cmd) {
346 case 'n': /* serial number */
347 memset(e.sn, 0, sizeof(e.sn));
348 strncpy((char *)e.sn, argv[2], sizeof(e.sn) - 1);
349 break;
350 case 'e': /* errata */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200351#ifdef CONFIG_SYS_I2C_EEPROM_NXID
Timur Tabibdea8372008-06-19 17:56:11 -0500352 memset(e.errata, 0, 5);
353 strncpy((char *)e.errata, argv[2], 4);
354#else
355 e.errata[0] = argv[2][0];
356 e.errata[1] = argv[2][1];
357#endif
358 break;
359 case 'd': /* date BCD format YYMMDDhhmmss */
360 set_date(argv[2]);
361 break;
362 case 'p': /* MAC table size */
363 e.mac_count = simple_strtoul(argv[2], NULL, 16);
364 break;
365 case '0' ... '7': /* "mac 0" through "mac 7" */
366 set_mac_address(cmd - '0', argv[2]);
367 break;
368 case 'h': /* help */
369 default:
Peter Tyserddb3af92009-01-27 18:03:10 -0600370 cmd_usage(cmdtp);
Timur Tabibdea8372008-06-19 17:56:11 -0500371 break;
Haiying Wang34c68782006-07-12 10:48:05 -0400372 }
Timur Tabibdea8372008-06-19 17:56:11 -0500373
Haiying Wang34c68782006-07-12 10:48:05 -0400374 return 0;
375}
376
Timur Tabibdea8372008-06-19 17:56:11 -0500377/**
378 * mac_read_from_eeprom - read the MAC addresses from EEPROM
379 *
380 * This function reads the MAC addresses from EEPROM and sets the
381 * appropriate environment variables for each one read.
382 *
383 * The environment variables are only set if they haven't been set already.
384 * This ensures that any user-saved variables are never overwritten.
385 *
386 * This function must be called after relocation.
387 */
Haiying Wang34c68782006-07-12 10:48:05 -0400388int mac_read_from_eeprom(void)
389{
Timur Tabibdea8372008-06-19 17:56:11 -0500390 unsigned int i;
Haiying Wang34c68782006-07-12 10:48:05 -0400391
Timur Tabibdea8372008-06-19 17:56:11 -0500392 if (read_eeprom()) {
Haiying Wang34c68782006-07-12 10:48:05 -0400393 printf("Read failed.\n");
394 return -1;
395 }
396
Timur Tabibdea8372008-06-19 17:56:11 -0500397 if (!is_valid) {
398 printf("Invalid ID (%02x %02x %02x %02x)\n", e.id[0], e.id[1], e.id[2], e.id[3]);
Haiying Wang34c68782006-07-12 10:48:05 -0400399 return -1;
Timur Tabibdea8372008-06-19 17:56:11 -0500400 }
401
402 if (be32_to_cpu(e.crc) != 0xFFFFFFFF) {
403 u32 crc = crc32(0, (void *)&e, sizeof(e) - 4);
404
405 if (crc != be32_to_cpu(e.crc)) {
406 printf("CRC mismatch (%08x != %08x).\n", crc,
407 be32_to_cpu(e.crc));
408 return -1;
Haiying Wang34c68782006-07-12 10:48:05 -0400409 }
410 }
Timur Tabibdea8372008-06-19 17:56:11 -0500411
Haiying Wange5607542009-06-04 16:12:40 -0400412 /* Check the number of MAC addresses which is limited to
413 * MAX_NUM_PORTS.
414 */
415 if (e.mac_count > MAX_NUM_PORTS) {
416 printf("Warning: The number of MAC addresses is greater"
417 " than %u, force it to %u.\n", MAX_NUM_PORTS,
418 MAX_NUM_PORTS);
419 e.mac_count = MAX_NUM_PORTS;
420 }
421
422 for (i = 0; i < e.mac_count; i++) {
Timur Tabibdea8372008-06-19 17:56:11 -0500423 if (memcmp(&e.mac[i], "\0\0\0\0\0\0", 6) &&
424 memcmp(&e.mac[i], "\xFF\xFF\xFF\xFF\xFF\xFF", 6)) {
425 char ethaddr[18];
426 char enetvar[9];
427
428 sprintf(ethaddr, "%02X:%02X:%02X:%02X:%02X:%02X",
429 e.mac[i][0],
430 e.mac[i][1],
431 e.mac[i][2],
432 e.mac[i][3],
433 e.mac[i][4],
434 e.mac[i][5]);
435 sprintf(enetvar, i ? "eth%daddr" : "ethaddr", i);
436 /* Only initialize environment variables that are blank
437 * (i.e. have not yet been set)
438 */
439 if (!getenv(enetvar))
440 setenv(enetvar, ethaddr);
441 }
442 }
443
Haiying Wang34c68782006-07-12 10:48:05 -0400444 return 0;
445}
Timur Tabibdea8372008-06-19 17:56:11 -0500446
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200447#ifdef CONFIG_SYS_I2C_EEPROM_CCID
Timur Tabibdea8372008-06-19 17:56:11 -0500448
449/**
450 * get_cpu_board_revision - get the CPU board revision on 85xx boards
451 *
452 * Read the EEPROM to determine the board revision.
453 *
454 * This function is called before relocation, so we need to read a private
455 * copy of the EEPROM into a local variable on the stack.
456 *
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200457 * Also, we assume that CONFIG_SYS_EEPROM_BUS_NUM == CONFIG_SYS_SPD_BUS_NUM. The global
458 * variable i2c_bus_num must be compile-time initialized to CONFIG_SYS_SPD_BUS_NUM,
Timur Tabibdea8372008-06-19 17:56:11 -0500459 * so that the SPD code will work. This means that all pre-relocation I2C
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200460 * operations can only occur on the CONFIG_SYS_SPD_BUS_NUM bus. So if
461 * CONFIG_SYS_EEPROM_BUS_NUM != CONFIG_SYS_SPD_BUS_NUM, then we can't read the EEPROM when
Timur Tabibdea8372008-06-19 17:56:11 -0500462 * this function is called. Oh well.
463 */
464unsigned int get_cpu_board_revision(void)
465{
466 struct board_eeprom {
467 u32 id; /* 0x00 - 0x03 EEPROM Tag 'CCID' */
468 u8 major; /* 0x04 Board revision, major */
469 u8 minor; /* 0x05 Board revision, minor */
470 } be;
471
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200472 i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
Timur Tabibdea8372008-06-19 17:56:11 -0500473 (void *)&be, sizeof(be));
474
475 if (be.id != (('C' << 24) | ('C' << 16) | ('I' << 8) | 'D'))
476 return MPC85XX_CPU_BOARD_REV(0, 0);
477
478 if ((be.major == 0xff) && (be.minor == 0xff))
479 return MPC85XX_CPU_BOARD_REV(0, 0);
480
Rafal Czubak5c50d142008-10-08 13:41:30 +0200481 return MPC85XX_CPU_BOARD_REV(be.major, be.minor);
Timur Tabibdea8372008-06-19 17:56:11 -0500482}
Timur Tabibdea8372008-06-19 17:56:11 -0500483#endif