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 <ti...@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


_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to