]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
net: Implement random ethaddr fallback in eth.c
authorJoe Hershberger <joe.hershberger@ni.com>
Mon, 4 May 2015 19:55:13 +0000 (14:55 -0500)
committerLothar Waßmann <LW@KARO-electronics.de>
Tue, 8 Sep 2015 20:43:15 +0000 (22:43 +0200)
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 <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
README
doc/README.enetaddr
net/Kconfig
net/eth.c

diff --git a/README b/README
index c56001cdecbbe88925d779806de37f174c0b135d..42cd55953bc1e96c3cc6cf515686ae2295590ee3 100644 (file)
--- a/README
+++ b/README
@@ -5747,7 +5747,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
index 0fafd2cdcd5f575796c69fc3fe97c085d4a666b4..82c9cd5fe56f68b55c5eb50de332092468eccb08 100644 (file)
@@ -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
index 22b9eaac53a2880a45b1d06f548e8a59c88256f1..a2bd4fe580b0063914ee37ebedad55a74663f4d1 100644 (file)
@@ -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
index 04a544c872a07c8e17ee003262a9d50f7bf3f8b1..6c49db583b60d92615ba3ad42f349068c7374c3a 100644 (file)
--- a/net/eth.c
+++ b/net/eth.c
@@ -538,9 +538,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;
@@ -666,9 +672,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)) {