From patchwork Tue Nov 8 15:54:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olliver Schinagl X-Patchwork-Id: 692374 X-Patchwork-Delegate: joe.hershberger@gmail.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 3tCw4N0H4lz9t2b for ; Wed, 9 Nov 2016 03:39:00 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=schinagl.nl header.i=@schinagl.nl header.b="GLV1OBH8"; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 30B5AB38AC; Tue, 8 Nov 2016 17:37:48 +0100 (CET) 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 d3IIR2ptZZRC; Tue, 8 Nov 2016 17:37:48 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8FEE8B38BA; Tue, 8 Nov 2016 17:37:08 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4B3EEA75D7 for ; Tue, 8 Nov 2016 17:02:19 +0100 (CET) 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 p3tPaU8SGO4X for ; Tue, 8 Nov 2016 17:02:19 +0100 (CET) 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 7of9.schinagl.nl (7of9.schinagl.nl [88.159.158.68]) by theia.denx.de (Postfix) with ESMTPS id 7698EB3835 for ; Tue, 8 Nov 2016 17:02:18 +0100 (CET) Received: from localhost.localdomain (static-98-101-100-159.thenetworkfactory.nl [159.100.101.98]) by 7of9.schinagl.nl (Postfix) with ESMTPA id 3BEF1574813; Tue, 8 Nov 2016 16:54:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=schinagl.nl; s=7of9; t=1478620495; bh=5Qz3f29BVkOBpw34UJ280uBR+oA5CIGV1z/iDSn15+Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=GLV1OBH8i5UhrQ2RsaiWTqMXcCF55myUZVmV9WwPgZYLJBmCCXu4cogpQ70Wvo7Ed c2zCPvNe8/JNUX1XDJXOdC76A2dc7C4tfsy8wILesh5U2xU9RvxTvw/0l/1WTPfy1y rPOVkmEyJBY5gwMMeeyjjry9cHzSTAzWwE8hnQKo= From: Olliver Schinagl To: Ian Campbell , Hans De Goede , Albert Aribaud , Iain Paton , FUKAUMI Naoki , Joe Hershberger , Olliver Schinagl , Simon Glass , Jeffy Chen , Michal Simek , =?UTF-8?q?Stefan=20Br=C3=BCns?= , Nathan Rossi , =?UTF-8?q?Andreas=20Bie=C3=9Fmann?= , Stefano Babic , Stefan Roese , Maxime Ripard Date: Tue, 8 Nov 2016 16:54:34 +0100 Message-Id: <20161108155437.1085-9-oliver@schinagl.nl> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161108155437.1085-1-oliver@schinagl.nl> References: <[PATCH v2 0/5] Retrieve MAC address from EEPROM> <20161108155437.1085-1-oliver@schinagl.nl> X-Mailman-Approved-At: Tue, 08 Nov 2016 17:36:37 +0100 Cc: dev@linux-sunxi.org, u-boot@lists.denx.de Subject: [U-Boot] [PATCH 08/11] net: sunxi: Allow sunxi boards to set the MAC from an EEPROM X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This patch uses the newly introduced Kconfig options to use the net_op read_rom_hwaddr to retrieve the MAC from an EEPROM. This will be especially useful for the Olimex OLinuXino series of sunxi boards as they all have an 2k i2c eeprom chip. The MAC address in the eeprom is ignored (if enabled) if the CRC8 check fails. This new functionality allows for querying multiple MAC addresses. The first (supported) device being probed gets the first address, the second the second etc. If a generated MAC address is desired, set it to all 0 (and if crc8 is configured also add that) for the adapter. Signed-off-by: Olliver Schinagl --- board/sunxi/Kconfig | 4 ++++ board/sunxi/board.c | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/board/sunxi/Kconfig b/board/sunxi/Kconfig index e1d4ab1..6b8ac99 100644 --- a/board/sunxi/Kconfig +++ b/board/sunxi/Kconfig @@ -414,6 +414,7 @@ config I2C0_ENABLE config I2C1_ENABLE bool "Enable I2C/TWI controller 1" + default y if (NET_ETHADDR_EEPROM_I2C_BUS = 1) default n select CMD_I2C ---help--- @@ -421,6 +422,7 @@ config I2C1_ENABLE config I2C2_ENABLE bool "Enable I2C/TWI controller 2" + default y if NET_ETHADDR_EEPROM_I2C_BUS = 2 default n select CMD_I2C ---help--- @@ -428,6 +430,7 @@ config I2C2_ENABLE if MACH_SUN6I || MACH_SUN7I config I2C3_ENABLE + default y if NET_ETHADDR_EEPROM_I2C_BUS = 3 bool "Enable I2C/TWI controller 3" default n select CMD_I2C @@ -447,6 +450,7 @@ endif if MACH_SUN7I config I2C4_ENABLE + default y if NET_ETHADDR_EEPROM_I2C_BUS = 4 bool "Enable I2C/TWI controller 4" default n select CMD_I2C diff --git a/board/sunxi/board.c b/board/sunxi/board.c index 71124f4..f1e64cd 100644 --- a/board/sunxi/board.c +++ b/board/sunxi/board.c @@ -12,6 +12,7 @@ */ #include +#include #include #include #include @@ -31,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -626,11 +628,46 @@ static void _sunxi_gen_sid_hwaddr(unsigned char *enetaddr, uint8_t cnt) memcpy(enetaddr, mac_addr, ARP_HLEN); } +static void _sunxi_read_rom_hwaddr(unsigned char *enetaddr, uint8_t cnt) +{ + uint8_t eeprom[ARP_HLEN + 1] = { 0x00 }; +#if defined(CONFIG_NET_ETHADDR_EEPROM) && defined(CONFIG_NET_ETHADDR_EEPROM_I2C) + int old_i2c_bus; + + old_i2c_bus = i2c_get_bus_num(); + if (old_i2c_bus != CONFIG_NET_ETHADDR_EEPROM_I2C_BUS) + i2c_set_bus_num(CONFIG_NET_ETHADDR_EEPROM_I2C_BUS); + /* Skip in blocks of 8 (ARP + CRC8 + pad), but read 7. */ + if (i2c_read(CONFIG_NET_ETHADDR_EEPROM_I2C_ADDR, + CONFIG_NET_ETHADDR_EEPROM_OFFSET + (cnt * (ARP_HLEN + 2)), + CONFIG_NET_ETHADDR_EEPROM_I2C_ADDRLEN, + eeprom, ARP_HLEN + 1)) { + i2c_set_bus_num(old_i2c_bus); + puts("Could not read the EEPROM; EEPROM missing?\n"); + return; + } + i2c_set_bus_num(old_i2c_bus); +#ifdef CONFIG_NET_ETHADDR_EEPROM_CRC8 + if (crc8(0, eeprom, ARP_HLEN) != eeprom[ARP_HLEN]) { + puts("CRC error on MAC address from EEPROM.\n"); + return; + } +#endif +#endif + + memcpy(enetaddr, eeprom, ARP_HLEN); +} + static int sunxi_read_rom_hwaddr(unsigned char *enetaddr) { static unsigned int cnt; - _sunxi_gen_sid_hwaddr(enetaddr, cnt); + _sunxi_read_rom_hwaddr(enetaddr, cnt); + + if (is_zero_ethaddr(enetaddr)) { + _sunxi_gen_sid_hwaddr(enetaddr, cnt); + puts("Serial# based "); + } /* First call, first stored MAC address, increase for next call */ cnt++;