upstream u-boot with additional patches for our devices/boards:
https://lists.denx.de/pipermail/u-boot/2017-March/282789.html (AXP crashes) ;
Gbit ethernet patch for some LIME2 revisions ;
with SPI flash support
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
255 lines
6.1 KiB
255 lines
6.1 KiB
19 years ago
|
/*
|
||
|
* Copyright 2006 Freescale Semiconductor
|
||
|
* York Sun (yorksun@freescale.com)
|
||
|
* Haiying Wang (haiying.wang@freescale.com)
|
||
|
*
|
||
|
* 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>
|
||
|
|
||
|
typedef struct {
|
||
18 years ago
|
unsigned char id[4]; /* 0x0000 - 0x0003 */
|
||
|
unsigned char sn[12]; /* 0x0004 - 0x000F */
|
||
|
unsigned char errata[5]; /* 0x0010 - 0x0014 */
|
||
|
unsigned char date[7]; /* 0x0015 - 0x001a */
|
||
|
unsigned char res_1[37]; /* 0x001b - 0x003f */
|
||
|
unsigned char tab_size; /* 0x0040 */
|
||
|
unsigned char tab_flag; /* 0x0041 */
|
||
|
unsigned char mac[8][6]; /* 0x0042 - 0x0071 */
|
||
|
unsigned char res_2[126]; /* 0x0072 - 0x00ef */
|
||
|
unsigned int crc; /* 0x00f0 - 0x00f3 crc32 checksum */
|
||
19 years ago
|
} EEPROM_data;
|
||
|
|
||
|
static EEPROM_data mac_data;
|
||
|
|
||
|
int mac_show(void)
|
||
|
{
|
||
|
int i;
|
||
|
unsigned char ethaddr[8][18];
|
||
|
|
||
18 years ago
|
printf("ID %c%c%c%c\n",
|
||
|
mac_data.id[0],
|
||
|
mac_data.id[1],
|
||
|
mac_data.id[2],
|
||
|
mac_data.id[3]);
|
||
|
printf("Errata %c%c%c%c%c\n",
|
||
|
mac_data.errata[0],
|
||
|
mac_data.errata[1],
|
||
|
mac_data.errata[2],
|
||
|
mac_data.errata[3],
|
||
|
mac_data.errata[4]);
|
||
|
printf("Date %c%c%c%c%c%c%c\n",
|
||
|
mac_data.date[0],
|
||
|
mac_data.date[1],
|
||
|
mac_data.date[2],
|
||
|
mac_data.date[3],
|
||
|
mac_data.date[4],
|
||
|
mac_data.date[5],
|
||
|
mac_data.date[6]);
|
||
19 years ago
|
for (i = 0; i < 8; i++) {
|
||
18 years ago
|
sprintf((char *)ethaddr[i],
|
||
18 years ago
|
"%02x:%02x:%02x:%02x:%02x:%02x",
|
||
|
mac_data.mac[i][0],
|
||
|
mac_data.mac[i][1],
|
||
|
mac_data.mac[i][2],
|
||
|
mac_data.mac[i][3],
|
||
|
mac_data.mac[i][4],
|
||
|
mac_data.mac[i][5]);
|
||
19 years ago
|
printf("MAC %d %s\n", i, ethaddr[i]);
|
||
|
}
|
||
|
|
||
18 years ago
|
setenv("ethaddr", (char *)ethaddr[0]);
|
||
|
setenv("eth1addr", (char *)ethaddr[1]);
|
||
|
setenv("eth2addr", (char *)ethaddr[2]);
|
||
|
setenv("eth3addr", (char *)ethaddr[3]);
|
||
19 years ago
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
int mac_read(void)
|
||
|
{
|
||
18 years ago
|
int ret, length;
|
||
19 years ago
|
unsigned int crc = 0;
|
||
|
unsigned char dev = ID_EEPROM_ADDR, *data;
|
||
|
|
||
|
length = sizeof(EEPROM_data);
|
||
|
ret = i2c_read(dev, 0, 1, (unsigned char *)(&mac_data), length);
|
||
|
if (ret) {
|
||
|
printf("Read failed.\n");
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
data = (unsigned char *)(&mac_data);
|
||
|
printf("Check CRC on reading ...");
|
||
18 years ago
|
crc = crc32(crc, data, length - 4);
|
||
19 years ago
|
if (crc != mac_data.crc) {
|
||
18 years ago
|
printf("CRC checksum is invalid, in EEPROM CRC is %x, calculated CRC is %x\n",
|
||
|
mac_data.crc, crc);
|
||
19 years ago
|
return -1;
|
||
18 years ago
|
} else {
|
||
19 years ago
|
printf("CRC OK\n");
|
||
|
mac_show();
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
int mac_prog(void)
|
||
|
{
|
||
|
int ret, i, length;
|
||
|
unsigned int crc = 0;
|
||
18 years ago
|
unsigned char dev = ID_EEPROM_ADDR, *ptr;
|
||
|
unsigned char *eeprom_data = (unsigned char *)(&mac_data);
|
||
19 years ago
|
|
||
|
for (i = 0; i < sizeof(mac_data.res_1); i++)
|
||
|
mac_data.res_1[i] = 0;
|
||
18 years ago
|
for (i = 0; i < sizeof(mac_data.res_2); i++)
|
||
19 years ago
|
mac_data.res_2[i] = 0;
|
||
|
length = sizeof(EEPROM_data);
|
||
18 years ago
|
crc = crc32(crc, eeprom_data, length - 4);
|
||
19 years ago
|
mac_data.crc = crc;
|
||
|
for (i = 0, ptr = eeprom_data; i < length; i += 8, ptr += 8) {
|
||
18 years ago
|
ret =
|
||
|
i2c_write(dev, i, 1, ptr,
|
||
|
(length - i) < 8 ? (length - i) : 8);
|
||
|
udelay(5000); /* 5ms write cycle timing */
|
||
19 years ago
|
if (ret)
|
||
|
break;
|
||
|
}
|
||
|
if (ret) {
|
||
|
printf("Programming failed.\n");
|
||
|
return -1;
|
||
18 years ago
|
} else {
|
||
|
printf("Programming %d bytes. Reading back ...\n", length);
|
||
19 years ago
|
mac_read();
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
18 years ago
|
int do_mac(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
|
||
19 years ago
|
{
|
||
|
int i;
|
||
|
char cmd = 's';
|
||
|
unsigned long long mac_val;
|
||
|
|
||
18 years ago
|
if (i2c_probe(ID_EEPROM_ADDR) != 0)
|
||
19 years ago
|
return -1;
|
||
|
|
||
18 years ago
|
if (argc > 1) {
|
||
19 years ago
|
cmd = argv[1][0];
|
||
|
switch (cmd) {
|
||
18 years ago
|
case 'r': /* display */
|
||
|
mac_read();
|
||
|
break;
|
||
|
case 's': /* save */
|
||
|
mac_prog();
|
||
|
break;
|
||
|
case 'i': /* id */
|
||
|
for (i = 0; i < 4; i++) {
|
||
|
mac_data.id[i] = argv[2][i];
|
||
|
}
|
||
|
break;
|
||
|
case 'n': /* serial number */
|
||
|
for (i = 0; i < 12; i++) {
|
||
|
mac_data.sn[i] = argv[2][i];
|
||
|
}
|
||
|
break;
|
||
|
case 'e': /* errata */
|
||
|
for (i = 0; i < 5; i++) {
|
||
|
mac_data.errata[i] = argv[2][i];
|
||
|
}
|
||
|
break;
|
||
|
case 'd': /* date */
|
||
|
for (i = 0; i < 7; i++) {
|
||
|
mac_data.date[i] = argv[2][i];
|
||
|
}
|
||
|
break;
|
||
|
case 'p': /* number of ports */
|
||
|
mac_data.tab_size =
|
||
|
(unsigned char)simple_strtoul(argv[2], NULL, 16);
|
||
|
break;
|
||
|
case '0': /* mac 0 */
|
||
|
case '1': /* mac 1 */
|
||
|
case '2': /* mac 2 */
|
||
|
case '3': /* mac 3 */
|
||
|
case '4': /* mac 4 */
|
||
|
case '5': /* mac 5 */
|
||
|
case '6': /* mac 6 */
|
||
|
case '7': /* mac 7 */
|
||
|
mac_val = simple_strtoull(argv[2], NULL, 16);
|
||
|
for (i = 0; i < 6; i++) {
|
||
|
mac_data.mac[cmd - '0'][i] =
|
||
|
*((unsigned char *)
|
||
|
(((unsigned int)(&mac_val)) + i + 2));
|
||
|
}
|
||
|
break;
|
||
|
case 'h': /* help */
|
||
|
default:
|
||
|
printf("Usage:\n%s\n", cmdtp->usage);
|
||
|
break;
|
||
19 years ago
|
}
|
||
18 years ago
|
} else {
|
||
19 years ago
|
mac_show();
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
int mac_read_from_eeprom(void)
|
||
|
{
|
||
18 years ago
|
int length, i;
|
||
|
unsigned char dev = ID_EEPROM_ADDR;
|
||
|
unsigned char *data;
|
||
|
unsigned char ethaddr[4][18];
|
||
|
unsigned char enetvar[32];
|
||
19 years ago
|
unsigned int crc = 0;
|
||
|
|
||
|
length = sizeof(EEPROM_data);
|
||
18 years ago
|
if (i2c_read(dev, 0, 1, (unsigned char *)(&mac_data), length)) {
|
||
19 years ago
|
printf("Read failed.\n");
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
data = (unsigned char *)(&mac_data);
|
||
18 years ago
|
crc = crc32(crc, data, length - 4);
|
||
19 years ago
|
if (crc != mac_data.crc) {
|
||
|
return -1;
|
||
18 years ago
|
} else {
|
||
|
for (i = 0; i < 4; i++) {
|
||
|
if (memcmp(&mac_data.mac[i], "\0\0\0\0\0\0", 6)) {
|
||
18 years ago
|
sprintf((char *)ethaddr[i],
|
||
18 years ago
|
"%02x:%02x:%02x:%02x:%02x:%02x",
|
||
|
mac_data.mac[i][0],
|
||
|
mac_data.mac[i][1],
|
||
|
mac_data.mac[i][2],
|
||
|
mac_data.mac[i][3],
|
||
|
mac_data.mac[i][4],
|
||
19 years ago
|
mac_data.mac[i][5]);
|
||
18 years ago
|
sprintf((char *)enetvar,
|
||
18 years ago
|
i ? "eth%daddr" : "ethaddr",
|
||
|
i);
|
||
18 years ago
|
setenv((char *)enetvar, (char *)ethaddr[i]);
|
||
19 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
return 0;
|
||
|
}
|