[U-Boot-Users] [PATCH v2] FSL: Fix common EEPROM_data structure definition

Jon Loeliger jdl at freescale.com
Thu Jan 17 19:26:13 CET 2008


From: Haiying Wang <Haiying.Wang at freescale.com>

- Fix EEPROM_data structure definition according to System EEPROM Data Format.
- Read MAC addresses from EEPROM to ethXaddr before saving ethXaddr to
  bd->bi_ethaddr.

Signed-off-by: Haiying Wang <Haiying.Wang at freescale.com>
---

This patch was only tested on MPC8641HPCN board, but it is supposed to
work for all NXID boards. Please help to verify if possible.

 board/freescale/common/sys_eeprom.c |  112 ++++++++++++++++++++++-------------
 common/cmd_mac.c                    |    4 +-
 lib_ppc/board.c                     |    9 ++-
 3 files changed, 78 insertions(+), 47 deletions(-)

diff --git a/board/freescale/common/sys_eeprom.c b/board/freescale/common/sys_eeprom.c
index 7bc663b..606fb3e 100644
--- a/board/freescale/common/sys_eeprom.c
+++ b/board/freescale/common/sys_eeprom.c
@@ -29,16 +29,19 @@
 
 #ifdef CFG_ID_EEPROM
 typedef struct {
-	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 */
+	u8 id[4];		/* 0x0000 - 0x0003 EEPROM Tag */
+	u8 sn[12];		/* 0x0004 - 0x000F Serial Number */
+	u8 errata[5];		/* 0x0010 - 0x0014 Errata Level */
+	u8 date[6];		/* 0x0015 - 0x001a Build Date */
+	u8 res_0;		/* 0x001b 	   Reserved */
+	u8 version[4];		/* 0x001c - 0x001f Version */
+	u8 tempcal[8];		/* 0x0020 - 0x0027 Temperature Calibration Factors*/
+	u8 tempcalsys[2]; 	/* 0x0028 - 0x0029 System Temperature Calibration Factors*/
+	u8 res_1[22];		/* 0x0020 - 0x003f Reserved */
+	u8 mac_size;		/* 0x0040 	   Mac table size */
+	u8 mac_flag;		/* 0x0041 	   Mac table flags */
+	u8 mac[8][6];		/* 0x0042 - 0x0071 Mac addresses */
+	u32 crc;		/* 0x0072 	   crc32 checksum */
 } EEPROM_data;
 
 static EEPROM_data mac_data;
@@ -46,28 +49,57 @@ static EEPROM_data mac_data;
 int mac_show(void)
 {
 	int i;
+	u8 mac_size;
 	unsigned char ethaddr[8][18];
+	unsigned char enetvar[32];
+
+	/* Show EEPROM tagID,
+	 * always the four characters 'NXID'.
+	 */
+	printf("ID ");
+	for (i = 0; i < 4; i++)
+		printf("%c", mac_data.id[i]);
+	printf("\n");
+
+	/* Show Serial number,
+	 * 0 to 11 charaters of errata information.
+	 */
+	printf("SN ");
+	for (i = 0; i < 12; i++)
+		printf("%c", mac_data.sn[i]);
+	printf("\n");
 
-	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",
+	/* Show Errata Level,
+	 * 0 to 4 characters of errata information.
+	 */
+	printf("Errata ");
+	for (i = 0; i < 5; i++)
+		printf("%c", mac_data.errata[i]);
+	printf("\n");
+
+	/* Show Build Date,
+	 * BCD date values, as YYMMDDhhmmss.
+	 */
+	printf("Date 20%02x\/%02x\/%02x %02x:%02x:%02x\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]);
-	for (i = 0; i < 8; i++) {
+	       mac_data.date[5]);
+
+	/* Show MAC table size,
+	 * Value from 0 to 7 indicating how many MAC
+	 * addresses are stored in the system EEPROM.
+	 */
+	if((mac_data.mac_size > 0) && (mac_data.mac_size <= 8))
+		mac_size = mac_data.mac_size;
+	else
+		mac_size = 8; /* Set the max size */
+	printf("MACSIZE %x\n", mac_size);
+
+	/* Show Mac addresses */
+	for (i = 0; i < mac_size; i++) {
 		sprintf((char *)ethaddr[i],
 			"%02x:%02x:%02x:%02x:%02x:%02x",
 			mac_data.mac[i][0],
@@ -77,12 +109,12 @@ int mac_show(void)
 			mac_data.mac[i][4],
 			mac_data.mac[i][5]);
 		printf("MAC %d %s\n", i, ethaddr[i]);
-	}
 
-	setenv("ethaddr",  (char *)ethaddr[0]);
-	setenv("eth1addr", (char *)ethaddr[1]);
-	setenv("eth2addr", (char *)ethaddr[2]);
-	setenv("eth3addr", (char *)ethaddr[3]);
+		sprintf((char *)enetvar,
+			i ? "eth%daddr" : "ethaddr", i);
+		setenv((char *)enetvar, (char *)ethaddr[i]);
+
+	}
 
 	return 0;
 }
@@ -121,17 +153,14 @@ int mac_prog(void)
 	unsigned char dev = ID_EEPROM_ADDR, *ptr;
 	unsigned char *eeprom_data = (unsigned char *)(&mac_data);
 
-	for (i = 0; i < sizeof(mac_data.res_1); i++)
-		mac_data.res_1[i] = 0;
-	for (i = 0; i < sizeof(mac_data.res_2); i++)
-		mac_data.res_2[i] = 0;
+	mac_data.res_0 = 0;
+	memset((void *)mac_data.res_1, 0, sizeof(mac_data.res_1));
+
 	length = sizeof(EEPROM_data);
 	crc = crc32(crc, eeprom_data, length - 4);
 	mac_data.crc = crc;
 	for (i = 0, ptr = eeprom_data; i < length; i += 8, ptr += 8) {
-		ret =
-		    i2c_write(dev, i, 1, ptr,
-			      (length - i) < 8 ? (length - i) : 8);
+		ret = i2c_write(dev, i, 1, ptr, min((length - i),8));
 		udelay(5000);	/* 5ms write cycle timing */
 		if (ret)
 			break;
@@ -180,12 +209,13 @@ int do_mac(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 			}
 			break;
 		case 'd':	/* date */
-			for (i = 0; i < 7; i++) {
-				mac_data.date[i] = argv[2][i];
+			mac_val = simple_strtoull(argv[2], NULL, 16);
+			for (i = 0; i < 6; i++) {
+				mac_data.date[i] = (mac_val >> (40 - 8 * i));
 			}
 			break;
-		case 'p':	/* number of ports */
-			mac_data.tab_size =
+		case 'p':	/* mac table size */
+			mac_data.mac_size =
 			    (unsigned char)simple_strtoul(argv[2], NULL, 16);
 			break;
 		case '0':	/* mac 0 */
diff --git a/common/cmd_mac.c b/common/cmd_mac.c
index 0add432..faed8f7 100644
--- a/common/cmd_mac.c
+++ b/common/cmd_mac.c
@@ -33,7 +33,7 @@ U_BOOT_CMD(
 	"mac     - display and program the system ID and MAC addresses in EEPROM\n",
 	"[read|save|id|num|errata|date|ports|0|1|2|3|4|5|6|7]\n"
 	"read\n"
-	"    - show content of mac\n"
+	"    - show content of EEPROM\n"
 	"mac save\n"
 	"    - save to the EEPROM\n"
 	"mac id\n"
@@ -43,7 +43,7 @@ U_BOOT_CMD(
 	"mac errata\n"
 	"    - program errata data\n"
 	"mac date\n"
-	"    - program data date\n"
+	"    - program date\n"
 	"mac ports\n"
 	"    - program the number of ports\n"
 	"mac 0\n"
diff --git a/lib_ppc/board.c b/lib_ppc/board.c
index 9aa67f9..68b652a 100644
--- a/lib_ppc/board.c
+++ b/lib_ppc/board.c
@@ -832,6 +832,11 @@ void board_init_r (gd_t *id, ulong dest_addr)
 #if defined(CONFIG_SC3)
 	sc3_read_eeprom();
 #endif
+
+#ifdef CFG_ID_EEPROM
+	mac_read_from_eeprom();
+#endif
+
 	s = getenv ("ethaddr");
 #if defined (CONFIG_MBX) || \
     defined (CONFIG_RPXCLASSIC) || \
@@ -899,10 +904,6 @@ void board_init_r (gd_t *id, ulong dest_addr)
 	}
 #endif
 
-#ifdef CFG_ID_EEPROM
-	mac_read_from_eeprom();
-#endif
-
 #if defined(CONFIG_TQM8xxL) || defined(CONFIG_TQM8260) || \
     defined(CONFIG_TQM8272) || \
     defined(CONFIG_CCM) || defined(CONFIG_KUP4K) || \
-- 
1.5.3.rc3.13.g7ab3







More information about the U-Boot mailing list