From patchwork Thu Jul 12 21:46:34 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timur Tabi X-Patchwork-Id: 170753 X-Patchwork-Delegate: afleming@freescale.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 6611D2C02F0 for ; Fri, 13 Jul 2012 07:46:51 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0D2F1280ED; Thu, 12 Jul 2012 23:46:50 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id AJgbo-7zXgGC; Thu, 12 Jul 2012 23:46:49 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A6C22280E5; Thu, 12 Jul 2012 23:46:48 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C7C96280E5 for ; Thu, 12 Jul 2012 23:46:46 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lN9POg8BUHNJ for ; Thu, 12 Jul 2012 23:46:44 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from tx2outboundpool.messaging.microsoft.com (tx2ehsobe001.messaging.microsoft.com [65.55.88.11]) by theia.denx.de (Postfix) with ESMTPS id 3CEF2280D5 for ; Thu, 12 Jul 2012 23:46:42 +0200 (CEST) Received: from mail130-tx2-R.bigfish.com (10.9.14.244) by TX2EHSOBE014.bigfish.com (10.9.40.34) with Microsoft SMTP Server id 14.1.225.23; Thu, 12 Jul 2012 21:46:38 +0000 Received: from mail130-tx2 (localhost [127.0.0.1]) by mail130-tx2-R.bigfish.com (Postfix) with ESMTP id 325C640234 for ; Thu, 12 Jul 2012 21:46:41 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 0 X-BigFish: VS0(zzzz1202hzz8275bhz2dh2a8h668h839hd24he5bhf0ah107ah) Received: from mail130-tx2 (localhost.localdomain [127.0.0.1]) by mail130-tx2 (MessageSwitch) id 1342129599287056_14484; Thu, 12 Jul 2012 21:46:39 +0000 (UTC) Received: from TX2EHSMHS014.bigfish.com (unknown [10.9.14.250]) by mail130-tx2.bigfish.com (Postfix) with ESMTP id 438C2460046 for ; Thu, 12 Jul 2012 21:46:39 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by TX2EHSMHS014.bigfish.com (10.9.99.114) with Microsoft SMTP Server (TLS) id 14.1.225.23; Thu, 12 Jul 2012 21:46:36 +0000 Received: from tx30smr01.am.freescale.net (10.81.153.31) by 039-SN1MMR1-002.039d.mgd.msft.net (10.84.1.15) with Microsoft SMTP Server (TLS) id 14.2.298.5; Thu, 12 Jul 2012 16:46:37 -0500 Received: from efes.am.freescale.net (efes.am.freescale.net [10.82.123.3]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id q6CLkZcC026223; Thu, 12 Jul 2012 14:46:35 -0700 From: Timur Tabi To: Andy Fleming , York Sun , , Date: Thu, 12 Jul 2012 16:46:34 -0500 Message-ID: <1342129594-7861-1-git-send-email-timur@freescale.com> X-Mailer: git-send-email 1.7.3.4 MIME-Version: 1.0 X-OriginatorOrg: freescale.com Subject: [U-Boot] [PATCH] fsl: board EEPROM has the CRC in the wrong location X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de 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 --- 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;