]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - net/eth.c
serial/serial_arc: set registers address during compilation
[people/ms/u-boot.git] / net / eth.c
index 321d5b18fd842d3d5df52549b2647ab8fb9ef816..eac4f7b3d0ed602c852d0f47dd9580670f8292da 100644 (file)
--- a/net/eth.c
+++ b/net/eth.c
@@ -2,23 +2,7 @@
  * (C) Copyright 2001-2010
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
@@ -26,6 +10,7 @@
 #include <net.h>
 #include <miiphy.h>
 #include <phy.h>
+#include <asm/errno.h>
 
 void eth_parse_enetaddr(const char *addr, uchar *enetaddr)
 {
@@ -79,28 +64,6 @@ static int eth_mac_skip(int index)
        return ((skip_state = getenv(enetvar)) != NULL);
 }
 
-#ifdef CONFIG_RANDOM_MACADDR
-void eth_random_enetaddr(uchar *enetaddr)
-{
-       uint32_t rval;
-
-       srand(get_timer(0));
-
-       rval = rand();
-       enetaddr[0] = rval & 0xff;
-       enetaddr[1] = (rval >> 8) & 0xff;
-       enetaddr[2] = (rval >> 16) & 0xff;
-
-       rval = rand();
-       enetaddr[3] = rval & 0xff;
-       enetaddr[4] = (rval >> 8) & 0xff;
-       enetaddr[5] = (rval >> 16) & 0xff;
-
-       /* make sure it's local and unicast */
-       enetaddr[0] = (enetaddr[0] | 0x02) & ~0x01;
-}
-#endif
-
 /*
  * CPU and board-specific Ethernet initializations.  Aliased function
  * signals caller to move on
@@ -190,6 +153,11 @@ static void eth_current_changed(void)
                setenv("ethact", NULL);
 }
 
+static int eth_address_set(unsigned char *addr)
+{
+       return memcmp(addr, "\0\0\0\0\0\0", 6);
+}
+
 int eth_write_hwaddr(struct eth_device *dev, const char *base_name,
                   int eth_number)
 {
@@ -198,8 +166,8 @@ int eth_write_hwaddr(struct eth_device *dev, const char *base_name,
 
        eth_getenv_enetaddr_by_index(base_name, eth_number, env_enetaddr);
 
-       if (memcmp(env_enetaddr, "\0\0\0\0\0\0", 6)) {
-               if (memcmp(dev->enetaddr, "\0\0\0\0\0\0", 6) &&
+       if (eth_address_set(env_enetaddr)) {
+               if (eth_address_set(dev->enetaddr) &&
                                memcmp(dev->enetaddr, env_enetaddr, 6)) {
                        printf("\nWarning: %s MAC addresses don't match:\n",
                                dev->name);
@@ -215,14 +183,22 @@ int eth_write_hwaddr(struct eth_device *dev, const char *base_name,
                                             dev->enetaddr);
                printf("\nWarning: %s using MAC address from net device\n",
                        dev->name);
+       } else if (!(eth_address_set(dev->enetaddr))) {
+               printf("\nError: %s address not set.\n",
+                      dev->name);
+               return -EINVAL;
        }
 
-       if (dev->write_hwaddr &&
-                       !eth_mac_skip(eth_number)) {
-               if (!is_valid_ether_addr(dev->enetaddr))
-                       return -1;
+       if (dev->write_hwaddr && !eth_mac_skip(eth_number)) {
+               if (!is_valid_ether_addr(dev->enetaddr)) {
+                       printf("\nError: %s address %pM illegal value\n",
+                                dev->name, dev->enetaddr);
+                       return -EINVAL;
+               }
 
                ret = dev->write_hwaddr(dev);
+               if (ret)
+                       printf("\nWarning: %s failed to set MAC address\n", dev->name);
        }
 
        return ret;
@@ -295,7 +271,7 @@ int eth_initialize(bd_t *bis)
        eth_current = NULL;
 
        bootstage_mark(BOOTSTAGE_ID_NET_ETH_START);
-#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
+#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) || defined(CONFIG_PHYLIB)
        miiphy_init();
 #endif
 
@@ -341,8 +317,7 @@ int eth_initialize(bd_t *bis)
                                puts("\nWarning: eth device name has a space!"
                                        "\n");
 
-                       if (eth_write_hwaddr(dev, "eth", dev->index))
-                               puts("\nWarning: failed to set MAC address\n");
+                       eth_write_hwaddr(dev, "eth", dev->index);
 
                        dev = dev->next;
                        num_devices++;