From patchwork Mon May 4 19:55:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Hershberger X-Patchwork-Id: 467813 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 79AB9140758 for ; Tue, 5 May 2015 05:57:45 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B006C4B96C; Mon, 4 May 2015 21:57:40 +0200 (CEST) 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 lviRzK-fgydV; Mon, 4 May 2015 21:57:40 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A5DCA4B969; Mon, 4 May 2015 21:57:39 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2ACC94B9AF for ; Mon, 4 May 2015 21:57:36 +0200 (CEST) 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 CAjKaRXxSL_t for ; Mon, 4 May 2015 21:57:36 +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 ni.com (skprod2.natinst.com [130.164.80.23]) by theia.denx.de (Postfix) with ESMTPS id 1D9634B984 for ; Mon, 4 May 2015 21:57:30 +0200 (CEST) Received: from us-aus-mgwout1.amer.corp.natinst.com (nb-snip2-1338.natinst.com [130.164.19.135]) by us-aus-skprod2.natinst.com (8.15.0.59/8.15.0.59) with ESMTP id t44JvELB011013; Mon, 4 May 2015 14:57:14 -0500 Received: from linux-xvxi.natinst.com ([130.164.14.198]) by us-aus-mgwout1.amer.corp.natinst.com (Lotus Domino Release 8.5.3FP6) with ESMTP id 2015050414571448-767807 ; Mon, 4 May 2015 14:57:14 -0500 From: Joe Hershberger To: u-boot@lists.denx.de Date: Mon, 4 May 2015 14:55:13 -0500 Message-Id: <1430769315-27109-1-git-send-email-joe.hershberger@ni.com> X-Mailer: git-send-email 1.7.11.5 X-MIMETrack: Itemize by SMTP Server on US-AUS-MGWOut1/AUS/H/NIC(Release 8.5.3FP6|November 21, 2013) at 05/04/2015 02:57:14 PM, Serialize by Router on US-AUS-MGWOut1/AUS/H/NIC(Release 8.5.3FP6|November 21, 2013) at 05/04/2015 02:57:14 PM, Serialize complete at 05/04/2015 02:57:14 PM X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2015-05-04_04:, , signatures=0 Cc: Marek Vasut , Tom Rini , Joe Hershberger , Thierry Reding , York Sun Subject: [U-Boot] [PATCH 1/3] net: Implement random ethaddr fallback in eth.c 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" Implement the random ethaddr fallback in eth.c so it is in a common place and not reimplemented in each board or driver that wants this behavior. Signed-off-by: Joe Hershberger Reviewed-by: Simon Glass --- To function properly in the driver-model case, this patch requires that https://patchwork.ozlabs.org/patch/467418/ be applied. README | 3 ++- doc/README.enetaddr | 2 ++ net/Kconfig | 8 ++++++++ net/eth.c | 12 ++++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/README b/README index ee65fdb..9e90c4b 100644 --- a/README +++ b/README @@ -5629,7 +5629,8 @@ o If both the SROM and the environment contain a MAC address, and the warning is printed. o If neither SROM nor the environment contain a MAC address, an error - is raised. + is raised. If CONFIG_NET_RANDOM_ETHADDR is defined, then in this case + a random, locally-assigned MAC is used. If Ethernet drivers implement the 'write_hwaddr' function, valid MAC addresses will be programmed into hardware as part of the initialization process. This diff --git a/doc/README.enetaddr b/doc/README.enetaddr index 0fafd2c..82c9cd5 100644 --- a/doc/README.enetaddr +++ b/doc/README.enetaddr @@ -37,6 +37,8 @@ Correct flow of setting up the MAC address (summarized): environment variable will be used unchanged. If the environment variable is not set, it will be initialized from eth_device->enetaddr, and a warning will be printed. + If both are invalid and CONFIG_NET_RANDOM_ETHADDR is defined, a random, + locally-assigned MAC is written to eth_device->enetaddr. 4. Program the address into hardware if the following conditions are met: a) The relevant driver has a 'write_addr' function b) The user hasn't set an 'ethmacskip' environment variable diff --git a/net/Kconfig b/net/Kconfig index 22b9eaa..a2bd4fe 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -7,4 +7,12 @@ menuconfig NET if NET +config NET_RANDOM_ETHADDR + bool "Random ethaddr if unset" + help + Selecting this will allow the Ethernet interface to function + even when the ethaddr variable for that interface is unset. + A new MAC address will be generated on every boot and it will + not be added to the environment. + endif # if NET diff --git a/net/eth.c b/net/eth.c index 8e6acfe..c4e0878 100644 --- a/net/eth.c +++ b/net/eth.c @@ -529,9 +529,15 @@ static int eth_post_probe(struct udevice *dev) printf("\nWarning: %s using MAC address from ROM\n", dev->name); } else if (is_zero_ethaddr(pdata->enetaddr)) { +#ifdef CONFIG_NET_RANDOM_ETHADDR + net_random_ethaddr(pdata->enetaddr); + printf("\nWarning: %s (eth%d) using random MAC address - %pM\n", + dev->name, dev->seq, pdata->enetaddr); +#else printf("\nError: %s address not set.\n", dev->name); return -EINVAL; +#endif } return 0; @@ -657,9 +663,15 @@ int eth_write_hwaddr(struct eth_device *dev, const char *base_name, printf("\nWarning: %s using MAC address from net device\n", dev->name); } else if (is_zero_ethaddr(dev->enetaddr)) { +#ifdef CONFIG_NET_RANDOM_ETHADDR + net_random_ethaddr(dev->enetaddr); + printf("\nWarning: %s (eth%d) using random MAC address - %pM\n", + dev->name, eth_number, dev->enetaddr); +#else printf("\nError: %s address not set.\n", dev->name); return -EINVAL; +#endif } if (dev->write_hwaddr && !eth_mac_skip(eth_number)) {