All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] fsl: board EEPROM has the CRC in the wrong location
@ 2012-07-12 21:46 Timur Tabi
  2012-07-12 22:03 ` sun york-R58495
  0 siblings, 1 reply; 32+ messages in thread
From: Timur Tabi @ 2012-07-12 21:46 UTC (permalink / raw)
  To: u-boot

The NXID v1 EEPROM format has the CRC at offset 0xFC, but for some reason it
was placed at address 0xCC instead.  To retain compatibility with existing
boards, we check the CRC in the old location if necessary.

Signed-off-by: Timur Tabi <timur@freescale.com>
---
 board/freescale/common/sys_eeprom.c |   28 ++++++++++++++++++++++++++--
 1 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/board/freescale/common/sys_eeprom.c b/board/freescale/common/sys_eeprom.c
index d2ed036..2541dd2 100644
--- a/board/freescale/common/sys_eeprom.c
+++ b/board/freescale/common/sys_eeprom.c
@@ -34,8 +34,16 @@
 #endif
 
 #ifdef CONFIG_SYS_I2C_EEPROM_NXID
-#define MAX_NUM_PORTS	23
+#define MAX_NUM_PORTS	31
 #define NXID_VERSION	1
+
+/*
+ * Older versions of this code incorrectly placed the CRC at offset 0xCC,
+ * when it should have been at 0xFC.  To maintain compatibility with boards
+ * that have the CRC at 0xCC, we check for the CRC at 0xCC if it's not in
+ * 0xFC.
+ */
+#define BROKEN_CRC_OFFSET	0xCC
 #endif
 
 /**
@@ -71,7 +79,7 @@ static struct __attribute__ ((__packed__)) eeprom {
 	u8 mac_count;     /* 0x40        Number of MAC addresses */
 	u8 mac_flag;      /* 0x41        MAC table flags */
 	u8 mac[MAX_NUM_PORTS][6];     /* 0x42 - x MAC addresses */
-	u32 crc;          /* x+1         CRC32 checksum */
+	u32 crc;          /* 0xFC        CRC32 checksum */
 #endif
 } e;
 
@@ -457,6 +465,22 @@ int mac_read_from_eeprom(void)
 
 	crc = crc32(0, (void *)&e, crc_offset);
 	crcp = (void *)&e + crc_offset;
+#ifdef BROKEN_CRC_OFFSET
+	/*
+	 * If the CRC is wrong, then check the old location.  If it contains a
+	 * valid CRC, then assume that this is an older EEPROM.  We update the
+	 * real CRC so that the EEPROM looks valid.
+	 */
+	if ((e.version == NXID_VERSION) && (crc != be32_to_cpup(crcp))) {
+		u32 crc2 = crc32(0, (void *)&e, BROKEN_CRC_OFFSET);
+		void *crcp2 = (void *)&e + BROKEN_CRC_OFFSET;
+
+		if (crc2 == be32_to_cpup(crcp2)) {
+			debug("Broken NXID v1 CRC found and corrected\n");
+			update_crc();
+		}
+	}
+#endif
 	if (crc != be32_to_cpu(*crcp)) {
 		printf("CRC mismatch (%08x != %08x)\n", crc, be32_to_cpu(e.crc));
 		return -1;
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2012-07-16 22:32 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-12 21:46 [U-Boot] [PATCH] fsl: board EEPROM has the CRC in the wrong location Timur Tabi
2012-07-12 22:03 ` sun york-R58495
2012-07-12 22:37   ` Scott Wood
2012-07-12 22:44     ` Timur Tabi
2012-07-12 22:46     ` sun york-R58495
2012-07-12 22:49       ` Scott Wood
2012-07-12 22:52         ` Timur Tabi
2012-07-13  4:32           ` Wolfgang Denk
2012-07-13 12:11             ` Tabi Timur-B04825
2012-07-13 21:26               ` Wolfgang Denk
2012-07-13  4:30   ` Wolfgang Denk
2012-07-13  4:38     ` sun york-R58495
2012-07-13 12:12       ` Tabi Timur-B04825
2012-07-13 21:22         ` York Sun
2012-07-13 12:10     ` Tabi Timur-B04825
2012-07-13 21:25       ` Wolfgang Denk
2012-07-13 21:29         ` Timur Tabi
2012-07-13 21:32           ` Wolfgang Denk
2012-07-13 21:39             ` Timur Tabi
2012-07-13 21:45         ` Scott Wood
2012-07-13 21:53           ` Timur Tabi
2012-07-13 22:19             ` Scott Wood
2012-07-13 22:22               ` Timur Tabi
2012-07-13 22:41                 ` Scott Wood
2012-07-13 22:46                   ` Timur Tabi
2012-07-13 22:54                     ` Scott Wood
2012-07-13 23:01             ` Wolfgang Denk
2012-07-13 23:12               ` Scott Wood
     [not found]                 ` <C5EFF1F960B6FC4C873CF9BD5FE250210791DCC8@039-SN2MPN1-013.039d.mgd.msft.net>
2012-07-15 12:52                   ` Tabi Timur-B04825
2012-07-16 19:57                 ` Wolfgang Denk
2012-07-16 22:32                   ` Scott Wood
2012-07-13 22:59           ` Wolfgang Denk

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.