From patchwork Mon Dec 14 12:41:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olliver Schinagl X-Patchwork-Id: 556440 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 B8D711402C4 for ; Tue, 15 Dec 2015 00:08:54 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D7EE94BA91; Mon, 14 Dec 2015 14:08:43 +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 2cI24W-2LDD9; Mon, 14 Dec 2015 14:08:43 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id F108D4BA4D; Mon, 14 Dec 2015 14:08:27 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7BC414BA09 for ; Mon, 14 Dec 2015 13:50:11 +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 FXIg3pDCBS4k for ; Mon, 14 Dec 2015 13:50:11 +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 45E964B9EE for ; Mon, 14 Dec 2015 13:50:07 +0100 (CET) Received: from um-mba-140.cloud.ultimaker.com (unknown [185.66.93.49]) by 7of9.schinagl.nl (Postfix) with ESMTPA id 65F47450A9; Mon, 14 Dec 2015 13:41:19 +0100 (CET) From: Olliver Schinagl To: Hans de Goede , Ian Campbell , Joe Hershberger Date: Mon, 14 Dec 2015 13:41:09 +0100 Message-Id: <1450096872-16733-3-git-send-email-o.schinagl@ultimaker.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1450096872-16733-1-git-send-email-o.schinagl@ultimaker.com> References: <1450096872-16733-1-git-send-email-o.schinagl@ultimaker.com> X-Mailman-Approved-At: Mon, 14 Dec 2015 14:08:19 +0100 Cc: u-boot@lists.denx.de, Olliver Schinagl Subject: [U-Boot] [PATCH v2 2/5] sunxi: net: Allow the sunxi 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 set the MAC address 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 is in the eeprom is ignored if there is already a MAC address in the environment or (if enabled) the CRC8 check fails. Signed-off-by: Olliver Schinagl --- board/sunxi/Kconfig | 4 ++++ board/sunxi/board.c | 36 ++++++++++++++++++++++++++++++++++++ net/Kconfig | 1 + 3 files changed, 41 insertions(+) diff --git a/board/sunxi/Kconfig b/board/sunxi/Kconfig index 2dd9d3b..a2da3a6 100644 --- a/board/sunxi/Kconfig +++ b/board/sunxi/Kconfig @@ -339,18 +339,21 @@ config I2C0_ENABLE config I2C1_ENABLE bool "Enable I2C/TWI controller 1" + default y if (NET_ETHADDR_EEPROM_I2C_BUS = 1) default n ---help--- See I2C0_ENABLE help text. config I2C2_ENABLE bool "Enable I2C/TWI controller 2" + default y if NET_ETHADDR_EEPROM_I2C_BUS = 2 default n ---help--- See I2C0_ENABLE help text. 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 ---help--- @@ -359,6 +362,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 ---help--- diff --git a/board/sunxi/board.c b/board/sunxi/board.c index 6ac398c..28310a2 100644 --- a/board/sunxi/board.c +++ b/board/sunxi/board.c @@ -12,6 +12,7 @@ */ #include +#include #include #include #include @@ -23,6 +24,7 @@ #include #include #include +#include #include #include @@ -510,6 +512,37 @@ void get_board_serial(struct tag_serialnr *serialnr) } #endif +#if defined(CONFIG_NET_ETHADDR_EEPROM) && defined(CONFIG_NET_ETHADDR_EEPROM_I2C) +static int read_mac_from_eeprom(uint8_t *mac_addr) +{ + uint8_t eeprom[7]; + int old_i2c_bus; + + old_i2c_bus = i2c_get_bus_num(); + i2c_set_bus_num(CONFIG_NET_ETHADDR_EEPROM_I2C_BUS); + if (i2c_read(CONFIG_NET_ETHADDR_EEPROM_I2C_ADDR, + CONFIG_NET_ETHADDR_EEPROM_OFFSET, + CONFIG_NET_ETHADDR_EEPROM_I2C_ADDRLEN, + eeprom, 7)) { + i2c_set_bus_num(old_i2c_bus); + puts("Could not read the EEPROM; EEPROM missing?\n"); + return -1; + } + i2c_set_bus_num(old_i2c_bus); +#ifdef CONFIG_NET_ETHADDR_EEPROM_CRC8 + if (crc8(eeprom, 6) != eeprom[6]) { + puts("CRC error on MAC address from EEPROM.\n"); + return -1; + } +#endif + memcpy(mac_addr, eeprom, 6); + + return 0; +} +#else +static int read_mac_from_eeprom(uint8_t *mac_addr) { return -1; } +#endif + #if !defined(CONFIG_SPL_BUILD) #include @@ -553,6 +586,9 @@ int misc_init_r(void) } #endif + if ((!getenv("ethaddr")) && (!read_mac_from_eeprom(mac_addr))) + eth_setenv_enetaddr("ethaddr", mac_addr); + ret = sunxi_get_sid(sid); if (ret == 0 && sid[0] != 0 && sid[3] != 0) { if (!getenv("ethaddr")) { diff --git a/net/Kconfig b/net/Kconfig index aced51e..0f4cc5a 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -8,6 +8,7 @@ menuconfig NET if NET config NET_ETHADDR_EEPROM + depends on ARCH_SUNXI bool "Get ethaddr from eeprom" help Selecting this will try to get the Ethernet address from an onboard