2006-07-12 14:48:05 +00:00
|
|
|
/*
|
fsl: obsolete NXID v0 EEPROMs, automatically upgrade them to NXID v1
The NXID EEPROM format comes in two versions, v0 and v1. The only
difference is in the number of MAC addresses that can be stored. NXID v0
supports eight addresses, and NXID v1 supports 23.
Rather than allow a board to choose which version to support, NXID v0 is
now considered deprecated. The EEPROM code is updated to support only
NXID v1, but it can still read EEPROMs formatted with v0. In these cases,
the EEPROM data is loaded and the CRC is verified, but the data is stored
into a v1 data structure. If the EEPROM data is written back, it is
written in v1 format. This allows existing v0-formatted EEPROMs to
continue providing MAC addresses, but any changes to the data will force
an upgrade to the v1 format, while retaining all data.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2011-02-09 02:00:09 +00:00
|
|
|
* Copyright 2006, 2008-2009, 2011 Freescale Semiconductor
|
2006-07-12 14:48:05 +00:00
|
|
|
* York Sun (yorksun@freescale.com)
|
|
|
|
* Haiying Wang (haiying.wang@freescale.com)
|
2008-06-19 22:56:11 +00:00
|
|
|
* Timur Tabi (timur@freescale.com)
|
2006-07-12 14:48:05 +00:00
|
|
|
*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
|
|
|
#include <i2c.h>
|
|
|
|
#include <linux/ctype.h>
|
|
|
|
|
2010-09-30 20:36:50 +00:00
|
|
|
#ifdef CONFIG_SYS_I2C_EEPROM_CCID
|
2008-06-19 22:56:11 +00:00
|
|
|
#include "../common/eeprom.h"
|
2010-09-30 20:36:50 +00:00
|
|
|
#define MAX_NUM_PORTS 8
|
|
|
|
#endif
|
2008-06-19 22:56:11 +00:00
|
|
|
|
2010-09-30 20:36:50 +00:00
|
|
|
#ifdef CONFIG_SYS_I2C_EEPROM_NXID
|
|
|
|
#define MAX_NUM_PORTS 23
|
|
|
|
#define NXID_VERSION 1
|
|
|
|
#endif
|
2009-06-04 20:12:40 +00:00
|
|
|
|
2008-06-19 22:56:11 +00:00
|
|
|
/**
|
|
|
|
* static eeprom: EEPROM layout for CCID or NXID formats
|
|
|
|
*
|
|
|
|
* See application note AN3638 for details.
|
|
|
|
*/
|
|
|
|
static struct __attribute__ ((__packed__)) eeprom {
|
2008-10-16 13:01:15 +00:00
|
|
|
#ifdef CONFIG_SYS_I2C_EEPROM_CCID
|
2008-06-19 22:56:11 +00:00
|
|
|
u8 id[4]; /* 0x00 - 0x03 EEPROM Tag 'CCID' */
|
|
|
|
u8 major; /* 0x04 Board revision, major */
|
|
|
|
u8 minor; /* 0x05 Board revision, minor */
|
|
|
|
u8 sn[10]; /* 0x06 - 0x0F Serial Number*/
|
|
|
|
u8 errata[2]; /* 0x10 - 0x11 Errata Level */
|
|
|
|
u8 date[6]; /* 0x12 - 0x17 Build Date */
|
|
|
|
u8 res_0[40]; /* 0x18 - 0x3f Reserved */
|
|
|
|
u8 mac_count; /* 0x40 Number of MAC addresses */
|
|
|
|
u8 mac_flag; /* 0x41 MAC table flags */
|
2009-06-04 20:12:40 +00:00
|
|
|
u8 mac[MAX_NUM_PORTS][6]; /* 0x42 - 0x71 MAC addresses */
|
2008-06-19 22:56:11 +00:00
|
|
|
u32 crc; /* 0x72 CRC32 checksum */
|
|
|
|
#endif
|
2008-10-16 13:01:15 +00:00
|
|
|
#ifdef CONFIG_SYS_I2C_EEPROM_NXID
|
2008-06-19 22:56:11 +00:00
|
|
|
u8 id[4]; /* 0x00 - 0x03 EEPROM Tag 'NXID' */
|
|
|
|
u8 sn[12]; /* 0x04 - 0x0F Serial Number */
|
|
|
|
u8 errata[5]; /* 0x10 - 0x14 Errata Level */
|
|
|
|
u8 date[6]; /* 0x15 - 0x1a Build Date */
|
|
|
|
u8 res_0; /* 0x1b Reserved */
|
|
|
|
u32 version; /* 0x1c - 0x1f NXID Version */
|
|
|
|
u8 tempcal[8]; /* 0x20 - 0x27 Temperature Calibration Factors */
|
|
|
|
u8 tempcalsys[2]; /* 0x28 - 0x29 System Temperature Calibration Factors */
|
|
|
|
u8 tempcalflags; /* 0x2a Temperature Calibration Flags */
|
|
|
|
u8 res_1[21]; /* 0x2b - 0x3f Reserved */
|
|
|
|
u8 mac_count; /* 0x40 Number of MAC addresses */
|
|
|
|
u8 mac_flag; /* 0x41 MAC table flags */
|
2010-09-30 20:36:50 +00:00
|
|
|
u8 mac[MAX_NUM_PORTS][6]; /* 0x42 - x MAC addresses */
|
|
|
|
u32 crc; /* x+1 CRC32 checksum */
|
2008-06-19 22:56:11 +00:00
|
|
|
#endif
|
|
|
|
} e;
|
|
|
|
|
|
|
|
/* Set to 1 if we've read EEPROM into memory */
|
|
|
|
static int has_been_read = 0;
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
#ifdef CONFIG_SYS_I2C_EEPROM_NXID
|
2008-06-19 22:56:11 +00:00
|
|
|
/* Is this a valid NXID EEPROM? */
|
2009-07-03 17:45:44 +00:00
|
|
|
#define is_valid ((e.id[0] == 'N') || (e.id[1] == 'X') || \
|
|
|
|
(e.id[2] == 'I') || (e.id[3] == 'D'))
|
2008-06-19 22:56:11 +00:00
|
|
|
#endif
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
#ifdef CONFIG_SYS_I2C_EEPROM_CCID
|
2008-06-19 22:56:11 +00:00
|
|
|
/* Is this a valid CCID EEPROM? */
|
2009-07-03 17:45:44 +00:00
|
|
|
#define is_valid ((e.id[0] == 'C') || (e.id[1] == 'C') || \
|
|
|
|
(e.id[2] == 'I') || (e.id[3] == 'D'))
|
2008-06-19 22:56:11 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* show_eeprom - display the contents of the EEPROM
|
|
|
|
*/
|
|
|
|
static void show_eeprom(void)
|
2006-07-12 14:48:05 +00:00
|
|
|
{
|
|
|
|
int i;
|
2008-06-19 22:56:11 +00:00
|
|
|
unsigned int crc;
|
|
|
|
|
|
|
|
/* EEPROM tag ID, either CCID or NXID */
|
2008-10-16 13:01:15 +00:00
|
|
|
#ifdef CONFIG_SYS_I2C_EEPROM_NXID
|
2008-06-19 22:56:11 +00:00
|
|
|
printf("ID: %c%c%c%c v%u\n", e.id[0], e.id[1], e.id[2], e.id[3],
|
|
|
|
be32_to_cpu(e.version));
|
|
|
|
#else
|
|
|
|
printf("ID: %c%c%c%c\n", e.id[0], e.id[1], e.id[2], e.id[3]);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Serial number */
|
|
|
|
printf("SN: %s\n", e.sn);
|
|
|
|
|
|
|
|
/* Errata level. */
|
2008-10-16 13:01:15 +00:00
|
|
|
#ifdef CONFIG_SYS_I2C_EEPROM_NXID
|
2008-06-19 22:56:11 +00:00
|
|
|
printf("Errata: %s\n", e.errata);
|
|
|
|
#else
|
|
|
|
printf("Errata: %c%c\n",
|
|
|
|
e.errata[0] ? e.errata[0] : '.',
|
|
|
|
e.errata[1] ? e.errata[1] : '.');
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Build date, BCD date values, as YYMMDDhhmmss */
|
|
|
|
printf("Build date: 20%02x/%02x/%02x %02x:%02x:%02x %s\n",
|
|
|
|
e.date[0], e.date[1], e.date[2],
|
|
|
|
e.date[3] & 0x7F, e.date[4], e.date[5],
|
|
|
|
e.date[3] & 0x80 ? "PM" : "");
|
|
|
|
|
|
|
|
/* Show MAC addresses */
|
2009-06-04 20:12:40 +00:00
|
|
|
for (i = 0; i < min(e.mac_count, MAX_NUM_PORTS); i++) {
|
|
|
|
|
2008-06-19 22:56:11 +00:00
|
|
|
u8 *p = e.mac[i];
|
2008-01-16 22:12:12 +00:00
|
|
|
|
2008-06-19 22:56:11 +00:00
|
|
|
printf("Eth%u: %02x:%02x:%02x:%02x:%02x:%02x\n", i,
|
|
|
|
p[0], p[1], p[2], p[3], p[4], p[5]);
|
2008-01-16 22:12:12 +00:00
|
|
|
}
|
2006-07-12 14:48:05 +00:00
|
|
|
|
2008-06-19 22:56:11 +00:00
|
|
|
crc = crc32(0, (void *)&e, sizeof(e) - 4);
|
|
|
|
|
|
|
|
if (crc == be32_to_cpu(e.crc))
|
|
|
|
printf("CRC: %08x\n", be32_to_cpu(e.crc));
|
|
|
|
else
|
|
|
|
printf("CRC: %08x (should be %08x)\n",
|
|
|
|
be32_to_cpu(e.crc), crc);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("EEPROM dump: (0x%x bytes)\n", sizeof(e));
|
|
|
|
for (i = 0; i < sizeof(e); i++) {
|
|
|
|
if ((i % 16) == 0)
|
|
|
|
printf("%02X: ", i);
|
|
|
|
printf("%02X ", ((u8 *)&e)[i]);
|
|
|
|
if (((i % 16) == 15) || (i == sizeof(e) - 1))
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
#endif
|
2006-07-12 14:48:05 +00:00
|
|
|
}
|
|
|
|
|
2008-06-19 22:56:11 +00:00
|
|
|
/**
|
|
|
|
* read_eeprom - read the EEPROM into memory
|
|
|
|
*/
|
|
|
|
static int read_eeprom(void)
|
2006-07-12 14:48:05 +00:00
|
|
|
{
|
2008-06-19 22:56:11 +00:00
|
|
|
int ret;
|
2008-10-16 13:01:15 +00:00
|
|
|
#ifdef CONFIG_SYS_EEPROM_BUS_NUM
|
2008-06-19 22:56:11 +00:00
|
|
|
unsigned int bus;
|
|
|
|
#endif
|
2006-07-12 14:48:05 +00:00
|
|
|
|
2008-06-19 22:56:11 +00:00
|
|
|
if (has_been_read)
|
|
|
|
return 0;
|
2006-07-12 14:48:05 +00:00
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
#ifdef CONFIG_SYS_EEPROM_BUS_NUM
|
2008-06-19 22:56:11 +00:00
|
|
|
bus = i2c_get_bus_num();
|
2008-10-16 13:01:15 +00:00
|
|
|
i2c_set_bus_num(CONFIG_SYS_EEPROM_BUS_NUM);
|
2008-06-19 22:56:11 +00:00
|
|
|
#endif
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
ret = i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
|
2008-06-19 22:56:11 +00:00
|
|
|
(void *)&e, sizeof(e));
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
#ifdef CONFIG_SYS_EEPROM_BUS_NUM
|
2008-06-19 22:56:11 +00:00
|
|
|
i2c_set_bus_num(bus);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
show_eeprom();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
has_been_read = (ret == 0) ? 1 : 0;
|
|
|
|
|
|
|
|
return ret;
|
2006-07-12 14:48:05 +00:00
|
|
|
}
|
|
|
|
|
fsl: simplify the "mac id" command, improve boot-time informational message
The "mac id" command took a 4-character parameter as the identifier string.
However, for any given board, only one kind of identifier is acceptable, so it
makes no sense to ask the user to type it in. Instead, if the user enters
"mac id", the identifier (and also the version, if it's NXID) will
automatically be set to the correct value.
Improve the message that is displayed when EEPROM is read during boot. It now
displays "EEPROM:" and then either an error message or the EEPROM identifier
if successful.
If the identifier in EEPROM is valid, then always reject a bad CRC, even if the
CRC field has not been initialized.
Don't force the MAC address count to MAX_NUM_PORTS or less. Forcing the value
to be changed resulting in an in-memory copy that does not match what's in
hardware, even though the user did not request that change.
Finally, always update the CRC value in the in-memory copy after any field
is changed, so that the CRC is always correct.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2009-08-28 21:56:45 +00:00
|
|
|
/**
|
|
|
|
* update_crc - update the CRC
|
|
|
|
*
|
|
|
|
* This function should be called after each update to the EEPROM structure,
|
|
|
|
* to make sure the CRC is always correct.
|
|
|
|
*/
|
|
|
|
static void update_crc(void)
|
|
|
|
{
|
|
|
|
u32 crc;
|
|
|
|
|
|
|
|
crc = crc32(0, (void *)&e, sizeof(e) - 4);
|
|
|
|
e.crc = cpu_to_be32(crc);
|
|
|
|
}
|
|
|
|
|
2008-06-19 22:56:11 +00:00
|
|
|
/**
|
|
|
|
* prog_eeprom - write the EEPROM from memory
|
|
|
|
*/
|
|
|
|
static int prog_eeprom(void)
|
2006-07-12 14:48:05 +00:00
|
|
|
{
|
2010-08-02 18:03:23 +00:00
|
|
|
int ret = 0;
|
2009-09-01 22:17:24 +00:00
|
|
|
int i;
|
2008-06-19 22:56:11 +00:00
|
|
|
void *p;
|
2008-10-16 13:01:15 +00:00
|
|
|
#ifdef CONFIG_SYS_EEPROM_BUS_NUM
|
2008-06-19 22:56:11 +00:00
|
|
|
unsigned int bus;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Set the reserved values to 0xFF */
|
2008-10-16 13:01:15 +00:00
|
|
|
#ifdef CONFIG_SYS_I2C_EEPROM_NXID
|
2008-06-19 22:56:11 +00:00
|
|
|
e.res_0 = 0xFF;
|
|
|
|
memset(e.res_1, 0xFF, sizeof(e.res_1));
|
|
|
|
#else
|
|
|
|
memset(e.res_0, 0xFF, sizeof(e.res_0));
|
|
|
|
#endif
|
fsl: simplify the "mac id" command, improve boot-time informational message
The "mac id" command took a 4-character parameter as the identifier string.
However, for any given board, only one kind of identifier is acceptable, so it
makes no sense to ask the user to type it in. Instead, if the user enters
"mac id", the identifier (and also the version, if it's NXID) will
automatically be set to the correct value.
Improve the message that is displayed when EEPROM is read during boot. It now
displays "EEPROM:" and then either an error message or the EEPROM identifier
if successful.
If the identifier in EEPROM is valid, then always reject a bad CRC, even if the
CRC field has not been initialized.
Don't force the MAC address count to MAX_NUM_PORTS or less. Forcing the value
to be changed resulting in an in-memory copy that does not match what's in
hardware, even though the user did not request that change.
Finally, always update the CRC value in the in-memory copy after any field
is changed, so that the CRC is always correct.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2009-08-28 21:56:45 +00:00
|
|
|
update_crc();
|
2008-06-19 22:56:11 +00:00
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
#ifdef CONFIG_SYS_EEPROM_BUS_NUM
|
2008-06-19 22:56:11 +00:00
|
|
|
bus = i2c_get_bus_num();
|
2008-10-16 13:01:15 +00:00
|
|
|
i2c_set_bus_num(CONFIG_SYS_EEPROM_BUS_NUM);
|
2008-06-19 22:56:11 +00:00
|
|
|
#endif
|
|
|
|
|
2010-08-02 18:03:23 +00:00
|
|
|
/*
|
|
|
|
* The AT24C02 datasheet says that data can only be written in page
|
|
|
|
* mode, which means 8 bytes at a time, and it takes up to 5ms to
|
|
|
|
* complete a given write.
|
|
|
|
*/
|
fsl: simplify the "mac id" command, improve boot-time informational message
The "mac id" command took a 4-character parameter as the identifier string.
However, for any given board, only one kind of identifier is acceptable, so it
makes no sense to ask the user to type it in. Instead, if the user enters
"mac id", the identifier (and also the version, if it's NXID) will
automatically be set to the correct value.
Improve the message that is displayed when EEPROM is read during boot. It now
displays "EEPROM:" and then either an error message or the EEPROM identifier
if successful.
If the identifier in EEPROM is valid, then always reject a bad CRC, even if the
CRC field has not been initialized.
Don't force the MAC address count to MAX_NUM_PORTS or less. Forcing the value
to be changed resulting in an in-memory copy that does not match what's in
hardware, even though the user did not request that change.
Finally, always update the CRC value in the in-memory copy after any field
is changed, so that the CRC is always correct.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2009-08-28 21:56:45 +00:00
|
|
|
for (i = 0, p = &e; i < sizeof(e); i += 8, p += 8) {
|
2008-10-16 13:01:15 +00:00
|
|
|
ret = i2c_write(CONFIG_SYS_I2C_EEPROM_ADDR, i, CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
|
fsl: simplify the "mac id" command, improve boot-time informational message
The "mac id" command took a 4-character parameter as the identifier string.
However, for any given board, only one kind of identifier is acceptable, so it
makes no sense to ask the user to type it in. Instead, if the user enters
"mac id", the identifier (and also the version, if it's NXID) will
automatically be set to the correct value.
Improve the message that is displayed when EEPROM is read during boot. It now
displays "EEPROM:" and then either an error message or the EEPROM identifier
if successful.
If the identifier in EEPROM is valid, then always reject a bad CRC, even if the
CRC field has not been initialized.
Don't force the MAC address count to MAX_NUM_PORTS or less. Forcing the value
to be changed resulting in an in-memory copy that does not match what's in
hardware, even though the user did not request that change.
Finally, always update the CRC value in the in-memory copy after any field
is changed, so that the CRC is always correct.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2009-08-28 21:56:45 +00:00
|
|
|
p, min((sizeof(e) - i), 8));
|
2006-07-12 14:48:05 +00:00
|
|
|
if (ret)
|
|
|
|
break;
|
2008-06-19 22:56:11 +00:00
|
|
|
udelay(5000); /* 5ms write cycle timing */
|
2006-07-12 14:48:05 +00:00
|
|
|
}
|
2008-06-19 22:56:11 +00:00
|
|
|
|
2010-08-02 18:03:23 +00:00
|
|
|
if (!ret) {
|
|
|
|
/* Verify the write by reading back the EEPROM and comparing */
|
|
|
|
struct eeprom e2;
|
|
|
|
|
|
|
|
ret = i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0,
|
|
|
|
CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (void *)&e2, sizeof(e2));
|
|
|
|
if (!ret && memcmp(&e, &e2, sizeof(e)))
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
#ifdef CONFIG_SYS_EEPROM_BUS_NUM
|
2008-06-19 22:56:11 +00:00
|
|
|
i2c_set_bus_num(bus);
|
|
|
|
#endif
|
|
|
|
|
2006-07-12 14:48:05 +00:00
|
|
|
if (ret) {
|
|
|
|
printf("Programming failed.\n");
|
2010-08-02 18:03:23 +00:00
|
|
|
has_been_read = 0;
|
2006-07-12 14:48:05 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2008-06-19 22:56:11 +00:00
|
|
|
|
|
|
|
printf("Programming passed.\n");
|
2006-07-12 14:48:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-19 22:56:11 +00:00
|
|
|
/**
|
|
|
|
* h2i - converts hex character into a number
|
|
|
|
*
|
|
|
|
* This function takes a hexadecimal character (e.g. '7' or 'C') and returns
|
|
|
|
* the integer equivalent.
|
|
|
|
*/
|
|
|
|
static inline u8 h2i(char p)
|
|
|
|
{
|
|
|
|
if ((p >= '0') && (p <= '9'))
|
|
|
|
return p - '0';
|
|
|
|
|
|
|
|
if ((p >= 'A') && (p <= 'F'))
|
|
|
|
return (p - 'A') + 10;
|
|
|
|
|
|
|
|
if ((p >= 'a') && (p <= 'f'))
|
|
|
|
return (p - 'a') + 10;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set_date - stores the build date into the EEPROM
|
|
|
|
*
|
|
|
|
* This function takes a pointer to a string in the format "YYMMDDhhmmss"
|
|
|
|
* (2-digit year, 2-digit month, etc), converts it to a 6-byte BCD string,
|
|
|
|
* and stores it in the build date field of the EEPROM local copy.
|
|
|
|
*/
|
|
|
|
static void set_date(const char *string)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (strlen(string) != 12) {
|
|
|
|
printf("Usage: mac date YYMMDDhhmmss\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
e.date[i] = h2i(string[2 * i]) << 4 | h2i(string[2 * i + 1]);
|
fsl: simplify the "mac id" command, improve boot-time informational message
The "mac id" command took a 4-character parameter as the identifier string.
However, for any given board, only one kind of identifier is acceptable, so it
makes no sense to ask the user to type it in. Instead, if the user enters
"mac id", the identifier (and also the version, if it's NXID) will
automatically be set to the correct value.
Improve the message that is displayed when EEPROM is read during boot. It now
displays "EEPROM:" and then either an error message or the EEPROM identifier
if successful.
If the identifier in EEPROM is valid, then always reject a bad CRC, even if the
CRC field has not been initialized.
Don't force the MAC address count to MAX_NUM_PORTS or less. Forcing the value
to be changed resulting in an in-memory copy that does not match what's in
hardware, even though the user did not request that change.
Finally, always update the CRC value in the in-memory copy after any field
is changed, so that the CRC is always correct.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2009-08-28 21:56:45 +00:00
|
|
|
|
|
|
|
update_crc();
|
2008-06-19 22:56:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set_mac_address - stores a MAC address into the EEPROM
|
|
|
|
*
|
|
|
|
* This function takes a pointer to MAC address string
|
|
|
|
* (i.e."XX:XX:XX:XX:XX:XX", where "XX" is a two-digit hex number) and
|
|
|
|
* stores it in one of the MAC address fields of the EEPROM local copy.
|
|
|
|
*/
|
|
|
|
static void set_mac_address(unsigned int index, const char *string)
|
|
|
|
{
|
|
|
|
char *p = (char *) string;
|
|
|
|
unsigned int i;
|
|
|
|
|
2010-09-30 20:36:50 +00:00
|
|
|
if ((index >= MAX_NUM_PORTS) || !string) {
|
2008-06-19 22:56:11 +00:00
|
|
|
printf("Usage: mac <n> XX:XX:XX:XX:XX:XX\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; *p && (i < 6); i++) {
|
|
|
|
e.mac[index][i] = simple_strtoul(p, &p, 16);
|
|
|
|
if (*p == ':')
|
|
|
|
p++;
|
|
|
|
}
|
fsl: simplify the "mac id" command, improve boot-time informational message
The "mac id" command took a 4-character parameter as the identifier string.
However, for any given board, only one kind of identifier is acceptable, so it
makes no sense to ask the user to type it in. Instead, if the user enters
"mac id", the identifier (and also the version, if it's NXID) will
automatically be set to the correct value.
Improve the message that is displayed when EEPROM is read during boot. It now
displays "EEPROM:" and then either an error message or the EEPROM identifier
if successful.
If the identifier in EEPROM is valid, then always reject a bad CRC, even if the
CRC field has not been initialized.
Don't force the MAC address count to MAX_NUM_PORTS or less. Forcing the value
to be changed resulting in an in-memory copy that does not match what's in
hardware, even though the user did not request that change.
Finally, always update the CRC value in the in-memory copy after any field
is changed, so that the CRC is always correct.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2009-08-28 21:56:45 +00:00
|
|
|
|
|
|
|
update_crc();
|
2008-06-19 22:56:11 +00:00
|
|
|
}
|
|
|
|
|
2010-06-28 20:00:46 +00:00
|
|
|
int do_mac(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
2006-07-12 14:48:05 +00:00
|
|
|
{
|
2008-06-19 22:56:11 +00:00
|
|
|
char cmd;
|
2006-07-12 14:48:05 +00:00
|
|
|
|
2008-06-19 22:56:11 +00:00
|
|
|
if (argc == 1) {
|
|
|
|
show_eeprom();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd = argv[1][0];
|
|
|
|
|
|
|
|
if (cmd == 'r') {
|
|
|
|
read_eeprom();
|
|
|
|
return 0;
|
|
|
|
}
|
2006-07-12 14:48:05 +00:00
|
|
|
|
fsl: simplify the "mac id" command, improve boot-time informational message
The "mac id" command took a 4-character parameter as the identifier string.
However, for any given board, only one kind of identifier is acceptable, so it
makes no sense to ask the user to type it in. Instead, if the user enters
"mac id", the identifier (and also the version, if it's NXID) will
automatically be set to the correct value.
Improve the message that is displayed when EEPROM is read during boot. It now
displays "EEPROM:" and then either an error message or the EEPROM identifier
if successful.
If the identifier in EEPROM is valid, then always reject a bad CRC, even if the
CRC field has not been initialized.
Don't force the MAC address count to MAX_NUM_PORTS or less. Forcing the value
to be changed resulting in an in-memory copy that does not match what's in
hardware, even though the user did not request that change.
Finally, always update the CRC value in the in-memory copy after any field
is changed, so that the CRC is always correct.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2009-08-28 21:56:45 +00:00
|
|
|
if (cmd == 'i') {
|
|
|
|
#ifdef CONFIG_SYS_I2C_EEPROM_NXID
|
|
|
|
memcpy(e.id, "NXID", sizeof(e.id));
|
2010-09-30 20:36:50 +00:00
|
|
|
e.version = NXID_VERSION;
|
fsl: simplify the "mac id" command, improve boot-time informational message
The "mac id" command took a 4-character parameter as the identifier string.
However, for any given board, only one kind of identifier is acceptable, so it
makes no sense to ask the user to type it in. Instead, if the user enters
"mac id", the identifier (and also the version, if it's NXID) will
automatically be set to the correct value.
Improve the message that is displayed when EEPROM is read during boot. It now
displays "EEPROM:" and then either an error message or the EEPROM identifier
if successful.
If the identifier in EEPROM is valid, then always reject a bad CRC, even if the
CRC field has not been initialized.
Don't force the MAC address count to MAX_NUM_PORTS or less. Forcing the value
to be changed resulting in an in-memory copy that does not match what's in
hardware, even though the user did not request that change.
Finally, always update the CRC value in the in-memory copy after any field
is changed, so that the CRC is always correct.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2009-08-28 21:56:45 +00:00
|
|
|
#else
|
|
|
|
memcpy(e.id, "CCID", sizeof(e.id));
|
|
|
|
#endif
|
2011-02-09 19:40:51 +00:00
|
|
|
update_crc();
|
2008-06-19 22:56:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_valid) {
|
|
|
|
printf("Please read the EEPROM ('r') and/or set the ID ('i') first.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc == 2) {
|
2006-07-12 14:48:05 +00:00
|
|
|
switch (cmd) {
|
2006-08-22 17:25:27 +00:00
|
|
|
case 's': /* save */
|
2008-06-19 22:56:11 +00:00
|
|
|
prog_eeprom();
|
2006-08-22 17:25:27 +00:00
|
|
|
break;
|
|
|
|
default:
|
2010-07-16 23:06:04 +00:00
|
|
|
return cmd_usage(cmdtp);
|
2006-07-12 14:48:05 +00:00
|
|
|
}
|
2008-06-19 22:56:11 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We know we have at least one parameter */
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case 'n': /* serial number */
|
|
|
|
memset(e.sn, 0, sizeof(e.sn));
|
|
|
|
strncpy((char *)e.sn, argv[2], sizeof(e.sn) - 1);
|
fsl: simplify the "mac id" command, improve boot-time informational message
The "mac id" command took a 4-character parameter as the identifier string.
However, for any given board, only one kind of identifier is acceptable, so it
makes no sense to ask the user to type it in. Instead, if the user enters
"mac id", the identifier (and also the version, if it's NXID) will
automatically be set to the correct value.
Improve the message that is displayed when EEPROM is read during boot. It now
displays "EEPROM:" and then either an error message or the EEPROM identifier
if successful.
If the identifier in EEPROM is valid, then always reject a bad CRC, even if the
CRC field has not been initialized.
Don't force the MAC address count to MAX_NUM_PORTS or less. Forcing the value
to be changed resulting in an in-memory copy that does not match what's in
hardware, even though the user did not request that change.
Finally, always update the CRC value in the in-memory copy after any field
is changed, so that the CRC is always correct.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2009-08-28 21:56:45 +00:00
|
|
|
update_crc();
|
2008-06-19 22:56:11 +00:00
|
|
|
break;
|
|
|
|
case 'e': /* errata */
|
2008-10-16 13:01:15 +00:00
|
|
|
#ifdef CONFIG_SYS_I2C_EEPROM_NXID
|
2008-06-19 22:56:11 +00:00
|
|
|
memset(e.errata, 0, 5);
|
|
|
|
strncpy((char *)e.errata, argv[2], 4);
|
|
|
|
#else
|
|
|
|
e.errata[0] = argv[2][0];
|
|
|
|
e.errata[1] = argv[2][1];
|
|
|
|
#endif
|
fsl: simplify the "mac id" command, improve boot-time informational message
The "mac id" command took a 4-character parameter as the identifier string.
However, for any given board, only one kind of identifier is acceptable, so it
makes no sense to ask the user to type it in. Instead, if the user enters
"mac id", the identifier (and also the version, if it's NXID) will
automatically be set to the correct value.
Improve the message that is displayed when EEPROM is read during boot. It now
displays "EEPROM:" and then either an error message or the EEPROM identifier
if successful.
If the identifier in EEPROM is valid, then always reject a bad CRC, even if the
CRC field has not been initialized.
Don't force the MAC address count to MAX_NUM_PORTS or less. Forcing the value
to be changed resulting in an in-memory copy that does not match what's in
hardware, even though the user did not request that change.
Finally, always update the CRC value in the in-memory copy after any field
is changed, so that the CRC is always correct.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2009-08-28 21:56:45 +00:00
|
|
|
update_crc();
|
2008-06-19 22:56:11 +00:00
|
|
|
break;
|
|
|
|
case 'd': /* date BCD format YYMMDDhhmmss */
|
|
|
|
set_date(argv[2]);
|
|
|
|
break;
|
|
|
|
case 'p': /* MAC table size */
|
|
|
|
e.mac_count = simple_strtoul(argv[2], NULL, 16);
|
fsl: simplify the "mac id" command, improve boot-time informational message
The "mac id" command took a 4-character parameter as the identifier string.
However, for any given board, only one kind of identifier is acceptable, so it
makes no sense to ask the user to type it in. Instead, if the user enters
"mac id", the identifier (and also the version, if it's NXID) will
automatically be set to the correct value.
Improve the message that is displayed when EEPROM is read during boot. It now
displays "EEPROM:" and then either an error message or the EEPROM identifier
if successful.
If the identifier in EEPROM is valid, then always reject a bad CRC, even if the
CRC field has not been initialized.
Don't force the MAC address count to MAX_NUM_PORTS or less. Forcing the value
to be changed resulting in an in-memory copy that does not match what's in
hardware, even though the user did not request that change.
Finally, always update the CRC value in the in-memory copy after any field
is changed, so that the CRC is always correct.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2009-08-28 21:56:45 +00:00
|
|
|
update_crc();
|
2008-06-19 22:56:11 +00:00
|
|
|
break;
|
2010-09-30 20:36:50 +00:00
|
|
|
case '0' ... '9': /* "mac 0" through "mac 22" */
|
|
|
|
set_mac_address(simple_strtoul(argv[1], NULL, 10), argv[2]);
|
2008-06-19 22:56:11 +00:00
|
|
|
break;
|
|
|
|
case 'h': /* help */
|
|
|
|
default:
|
2010-07-16 23:06:04 +00:00
|
|
|
return cmd_usage(cmdtp);
|
2006-07-12 14:48:05 +00:00
|
|
|
}
|
2008-06-19 22:56:11 +00:00
|
|
|
|
2006-07-12 14:48:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-19 22:56:11 +00:00
|
|
|
/**
|
|
|
|
* mac_read_from_eeprom - read the MAC addresses from EEPROM
|
|
|
|
*
|
|
|
|
* This function reads the MAC addresses from EEPROM and sets the
|
|
|
|
* appropriate environment variables for each one read.
|
|
|
|
*
|
|
|
|
* The environment variables are only set if they haven't been set already.
|
|
|
|
* This ensures that any user-saved variables are never overwritten.
|
|
|
|
*
|
|
|
|
* This function must be called after relocation.
|
fsl: obsolete NXID v0 EEPROMs, automatically upgrade them to NXID v1
The NXID EEPROM format comes in two versions, v0 and v1. The only
difference is in the number of MAC addresses that can be stored. NXID v0
supports eight addresses, and NXID v1 supports 23.
Rather than allow a board to choose which version to support, NXID v0 is
now considered deprecated. The EEPROM code is updated to support only
NXID v1, but it can still read EEPROMs formatted with v0. In these cases,
the EEPROM data is loaded and the CRC is verified, but the data is stored
into a v1 data structure. If the EEPROM data is written back, it is
written in v1 format. This allows existing v0-formatted EEPROMs to
continue providing MAC addresses, but any changes to the data will force
an upgrade to the v1 format, while retaining all data.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2011-02-09 02:00:09 +00:00
|
|
|
*
|
|
|
|
* For NXID v1 EEPROMs, we support loading and up-converting the older NXID v0
|
|
|
|
* format. In a v0 EEPROM, there are only eight MAC addresses and the CRC is
|
|
|
|
* located at a different offset.
|
2008-06-19 22:56:11 +00:00
|
|
|
*/
|
2006-07-12 14:48:05 +00:00
|
|
|
int mac_read_from_eeprom(void)
|
|
|
|
{
|
2008-06-19 22:56:11 +00:00
|
|
|
unsigned int i;
|
fsl: obsolete NXID v0 EEPROMs, automatically upgrade them to NXID v1
The NXID EEPROM format comes in two versions, v0 and v1. The only
difference is in the number of MAC addresses that can be stored. NXID v0
supports eight addresses, and NXID v1 supports 23.
Rather than allow a board to choose which version to support, NXID v0 is
now considered deprecated. The EEPROM code is updated to support only
NXID v1, but it can still read EEPROMs formatted with v0. In these cases,
the EEPROM data is loaded and the CRC is verified, but the data is stored
into a v1 data structure. If the EEPROM data is written back, it is
written in v1 format. This allows existing v0-formatted EEPROMs to
continue providing MAC addresses, but any changes to the data will force
an upgrade to the v1 format, while retaining all data.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2011-02-09 02:00:09 +00:00
|
|
|
u32 crc, crc_offset = offsetof(struct eeprom, crc);
|
|
|
|
u32 *crcp; /* Pointer to the CRC in the data read from the EEPROM */
|
fsl: simplify the "mac id" command, improve boot-time informational message
The "mac id" command took a 4-character parameter as the identifier string.
However, for any given board, only one kind of identifier is acceptable, so it
makes no sense to ask the user to type it in. Instead, if the user enters
"mac id", the identifier (and also the version, if it's NXID) will
automatically be set to the correct value.
Improve the message that is displayed when EEPROM is read during boot. It now
displays "EEPROM:" and then either an error message or the EEPROM identifier
if successful.
If the identifier in EEPROM is valid, then always reject a bad CRC, even if the
CRC field has not been initialized.
Don't force the MAC address count to MAX_NUM_PORTS or less. Forcing the value
to be changed resulting in an in-memory copy that does not match what's in
hardware, even though the user did not request that change.
Finally, always update the CRC value in the in-memory copy after any field
is changed, so that the CRC is always correct.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2009-08-28 21:56:45 +00:00
|
|
|
|
|
|
|
puts("EEPROM: ");
|
2008-06-19 22:56:11 +00:00
|
|
|
|
|
|
|
if (read_eeprom()) {
|
2006-07-12 14:48:05 +00:00
|
|
|
printf("Read failed.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-06-19 22:56:11 +00:00
|
|
|
if (!is_valid) {
|
fsl: simplify the "mac id" command, improve boot-time informational message
The "mac id" command took a 4-character parameter as the identifier string.
However, for any given board, only one kind of identifier is acceptable, so it
makes no sense to ask the user to type it in. Instead, if the user enters
"mac id", the identifier (and also the version, if it's NXID) will
automatically be set to the correct value.
Improve the message that is displayed when EEPROM is read during boot. It now
displays "EEPROM:" and then either an error message or the EEPROM identifier
if successful.
If the identifier in EEPROM is valid, then always reject a bad CRC, even if the
CRC field has not been initialized.
Don't force the MAC address count to MAX_NUM_PORTS or less. Forcing the value
to be changed resulting in an in-memory copy that does not match what's in
hardware, even though the user did not request that change.
Finally, always update the CRC value in the in-memory copy after any field
is changed, so that the CRC is always correct.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2009-08-28 21:56:45 +00:00
|
|
|
printf("Invalid ID (%02x %02x %02x %02x)\n",
|
|
|
|
e.id[0], e.id[1], e.id[2], e.id[3]);
|
2006-07-12 14:48:05 +00:00
|
|
|
return -1;
|
2008-06-19 22:56:11 +00:00
|
|
|
}
|
|
|
|
|
fsl: obsolete NXID v0 EEPROMs, automatically upgrade them to NXID v1
The NXID EEPROM format comes in two versions, v0 and v1. The only
difference is in the number of MAC addresses that can be stored. NXID v0
supports eight addresses, and NXID v1 supports 23.
Rather than allow a board to choose which version to support, NXID v0 is
now considered deprecated. The EEPROM code is updated to support only
NXID v1, but it can still read EEPROMs formatted with v0. In these cases,
the EEPROM data is loaded and the CRC is verified, but the data is stored
into a v1 data structure. If the EEPROM data is written back, it is
written in v1 format. This allows existing v0-formatted EEPROMs to
continue providing MAC addresses, but any changes to the data will force
an upgrade to the v1 format, while retaining all data.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2011-02-09 02:00:09 +00:00
|
|
|
#ifdef CONFIG_SYS_I2C_EEPROM_NXID
|
|
|
|
/*
|
|
|
|
* If we've read an NXID v0 EEPROM, then we need to set the CRC offset
|
|
|
|
* to where it is in v0.
|
|
|
|
*/
|
|
|
|
if (e.version == 0)
|
|
|
|
crc_offset = 0x72;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
crc = crc32(0, (void *)&e, crc_offset);
|
|
|
|
crcp = (void *)&e + crc_offset;
|
|
|
|
if (crc != be32_to_cpu(*crcp)) {
|
fsl: simplify the "mac id" command, improve boot-time informational message
The "mac id" command took a 4-character parameter as the identifier string.
However, for any given board, only one kind of identifier is acceptable, so it
makes no sense to ask the user to type it in. Instead, if the user enters
"mac id", the identifier (and also the version, if it's NXID) will
automatically be set to the correct value.
Improve the message that is displayed when EEPROM is read during boot. It now
displays "EEPROM:" and then either an error message or the EEPROM identifier
if successful.
If the identifier in EEPROM is valid, then always reject a bad CRC, even if the
CRC field has not been initialized.
Don't force the MAC address count to MAX_NUM_PORTS or less. Forcing the value
to be changed resulting in an in-memory copy that does not match what's in
hardware, even though the user did not request that change.
Finally, always update the CRC value in the in-memory copy after any field
is changed, so that the CRC is always correct.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2009-08-28 21:56:45 +00:00
|
|
|
printf("CRC mismatch (%08x != %08x)\n", crc, be32_to_cpu(e.crc));
|
|
|
|
return -1;
|
2009-06-04 20:12:40 +00:00
|
|
|
}
|
|
|
|
|
fsl: obsolete NXID v0 EEPROMs, automatically upgrade them to NXID v1
The NXID EEPROM format comes in two versions, v0 and v1. The only
difference is in the number of MAC addresses that can be stored. NXID v0
supports eight addresses, and NXID v1 supports 23.
Rather than allow a board to choose which version to support, NXID v0 is
now considered deprecated. The EEPROM code is updated to support only
NXID v1, but it can still read EEPROMs formatted with v0. In these cases,
the EEPROM data is loaded and the CRC is verified, but the data is stored
into a v1 data structure. If the EEPROM data is written back, it is
written in v1 format. This allows existing v0-formatted EEPROMs to
continue providing MAC addresses, but any changes to the data will force
an upgrade to the v1 format, while retaining all data.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2011-02-09 02:00:09 +00:00
|
|
|
#ifdef CONFIG_SYS_I2C_EEPROM_NXID
|
|
|
|
/*
|
|
|
|
* MAC address #9 in v1 occupies the same position as the CRC in v0.
|
|
|
|
* Erase it so that it's not mistaken for a MAC address. We'll
|
|
|
|
* update the CRC later.
|
|
|
|
*/
|
|
|
|
if (e.version == 0)
|
|
|
|
memset(e.mac[8], 0xff, 6);
|
|
|
|
#endif
|
|
|
|
|
fsl: simplify the "mac id" command, improve boot-time informational message
The "mac id" command took a 4-character parameter as the identifier string.
However, for any given board, only one kind of identifier is acceptable, so it
makes no sense to ask the user to type it in. Instead, if the user enters
"mac id", the identifier (and also the version, if it's NXID) will
automatically be set to the correct value.
Improve the message that is displayed when EEPROM is read during boot. It now
displays "EEPROM:" and then either an error message or the EEPROM identifier
if successful.
If the identifier in EEPROM is valid, then always reject a bad CRC, even if the
CRC field has not been initialized.
Don't force the MAC address count to MAX_NUM_PORTS or less. Forcing the value
to be changed resulting in an in-memory copy that does not match what's in
hardware, even though the user did not request that change.
Finally, always update the CRC value in the in-memory copy after any field
is changed, so that the CRC is always correct.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2009-08-28 21:56:45 +00:00
|
|
|
for (i = 0; i < min(e.mac_count, MAX_NUM_PORTS); i++) {
|
2008-06-19 22:56:11 +00:00
|
|
|
if (memcmp(&e.mac[i], "\0\0\0\0\0\0", 6) &&
|
|
|
|
memcmp(&e.mac[i], "\xFF\xFF\xFF\xFF\xFF\xFF", 6)) {
|
|
|
|
char ethaddr[18];
|
|
|
|
char enetvar[9];
|
|
|
|
|
|
|
|
sprintf(ethaddr, "%02X:%02X:%02X:%02X:%02X:%02X",
|
|
|
|
e.mac[i][0],
|
|
|
|
e.mac[i][1],
|
|
|
|
e.mac[i][2],
|
|
|
|
e.mac[i][3],
|
|
|
|
e.mac[i][4],
|
|
|
|
e.mac[i][5]);
|
|
|
|
sprintf(enetvar, i ? "eth%daddr" : "ethaddr", i);
|
|
|
|
/* Only initialize environment variables that are blank
|
|
|
|
* (i.e. have not yet been set)
|
|
|
|
*/
|
|
|
|
if (!getenv(enetvar))
|
|
|
|
setenv(enetvar, ethaddr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
fsl: simplify the "mac id" command, improve boot-time informational message
The "mac id" command took a 4-character parameter as the identifier string.
However, for any given board, only one kind of identifier is acceptable, so it
makes no sense to ask the user to type it in. Instead, if the user enters
"mac id", the identifier (and also the version, if it's NXID) will
automatically be set to the correct value.
Improve the message that is displayed when EEPROM is read during boot. It now
displays "EEPROM:" and then either an error message or the EEPROM identifier
if successful.
If the identifier in EEPROM is valid, then always reject a bad CRC, even if the
CRC field has not been initialized.
Don't force the MAC address count to MAX_NUM_PORTS or less. Forcing the value
to be changed resulting in an in-memory copy that does not match what's in
hardware, even though the user did not request that change.
Finally, always update the CRC value in the in-memory copy after any field
is changed, so that the CRC is always correct.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2009-08-28 21:56:45 +00:00
|
|
|
#ifdef CONFIG_SYS_I2C_EEPROM_NXID
|
|
|
|
printf("%c%c%c%c v%u\n", e.id[0], e.id[1], e.id[2], e.id[3],
|
|
|
|
be32_to_cpu(e.version));
|
|
|
|
#else
|
|
|
|
printf("%c%c%c%c\n", e.id[0], e.id[1], e.id[2], e.id[3]);
|
|
|
|
#endif
|
|
|
|
|
fsl: obsolete NXID v0 EEPROMs, automatically upgrade them to NXID v1
The NXID EEPROM format comes in two versions, v0 and v1. The only
difference is in the number of MAC addresses that can be stored. NXID v0
supports eight addresses, and NXID v1 supports 23.
Rather than allow a board to choose which version to support, NXID v0 is
now considered deprecated. The EEPROM code is updated to support only
NXID v1, but it can still read EEPROMs formatted with v0. In these cases,
the EEPROM data is loaded and the CRC is verified, but the data is stored
into a v1 data structure. If the EEPROM data is written back, it is
written in v1 format. This allows existing v0-formatted EEPROMs to
continue providing MAC addresses, but any changes to the data will force
an upgrade to the v1 format, while retaining all data.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2011-02-09 02:00:09 +00:00
|
|
|
#ifdef CONFIG_SYS_I2C_EEPROM_NXID
|
|
|
|
/*
|
|
|
|
* Now we need to upconvert the data into v1 format. We do this last so
|
|
|
|
* that at boot time, U-Boot will still say "NXID v0".
|
|
|
|
*/
|
|
|
|
if (e.version == 0) {
|
|
|
|
e.version = NXID_VERSION;
|
|
|
|
update_crc();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-07-12 14:48:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2008-06-19 22:56:11 +00:00
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
#ifdef CONFIG_SYS_I2C_EEPROM_CCID
|
2008-06-19 22:56:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* get_cpu_board_revision - get the CPU board revision on 85xx boards
|
|
|
|
*
|
|
|
|
* Read the EEPROM to determine the board revision.
|
|
|
|
*
|
|
|
|
* This function is called before relocation, so we need to read a private
|
|
|
|
* copy of the EEPROM into a local variable on the stack.
|
|
|
|
*
|
2008-10-16 13:01:15 +00:00
|
|
|
* Also, we assume that CONFIG_SYS_EEPROM_BUS_NUM == CONFIG_SYS_SPD_BUS_NUM. The global
|
|
|
|
* variable i2c_bus_num must be compile-time initialized to CONFIG_SYS_SPD_BUS_NUM,
|
2008-06-19 22:56:11 +00:00
|
|
|
* so that the SPD code will work. This means that all pre-relocation I2C
|
2008-10-16 13:01:15 +00:00
|
|
|
* operations can only occur on the CONFIG_SYS_SPD_BUS_NUM bus. So if
|
|
|
|
* CONFIG_SYS_EEPROM_BUS_NUM != CONFIG_SYS_SPD_BUS_NUM, then we can't read the EEPROM when
|
2008-06-19 22:56:11 +00:00
|
|
|
* this function is called. Oh well.
|
|
|
|
*/
|
|
|
|
unsigned int get_cpu_board_revision(void)
|
|
|
|
{
|
|
|
|
struct board_eeprom {
|
|
|
|
u32 id; /* 0x00 - 0x03 EEPROM Tag 'CCID' */
|
|
|
|
u8 major; /* 0x04 Board revision, major */
|
|
|
|
u8 minor; /* 0x05 Board revision, minor */
|
|
|
|
} be;
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
|
2008-06-19 22:56:11 +00:00
|
|
|
(void *)&be, sizeof(be));
|
|
|
|
|
|
|
|
if (be.id != (('C' << 24) | ('C' << 16) | ('I' << 8) | 'D'))
|
|
|
|
return MPC85XX_CPU_BOARD_REV(0, 0);
|
|
|
|
|
|
|
|
if ((be.major == 0xff) && (be.minor == 0xff))
|
|
|
|
return MPC85XX_CPU_BOARD_REV(0, 0);
|
|
|
|
|
2008-10-08 11:41:30 +00:00
|
|
|
return MPC85XX_CPU_BOARD_REV(be.major, be.minor);
|
2008-06-19 22:56:11 +00:00
|
|
|
}
|
|
|
|
#endif
|