No subject


Fri Jun 27 10:01:13 CEST 2014


> > Well, it may be unset (00:00:...) or it may be invalid (b2:a3:...).
> 
> The address being not set at all, and it being set to
> 00:00:00:00:00:00, are two totally different cases, In the former,
> it's, well, not set, and in the latter it is set to an invalid
 > value.

Unfortunately, that's not how the code works now. it uses 00:00: as a
marker that address is not set. (And I don't think completely redoing
the code for sake of error message is sane.)

--- a/net/eth.c
+++ b/net/eth.c
@@ -10,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)
 {
@@ -152,6 +153,11 @@ static void eth_current_changed(void)
 		setenv("ethact", NULL);
 }
 
+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)
 {
@@ -160,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);
@@ -177,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;
@@ -303,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++;

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html


More information about the U-Boot mailing list