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
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
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
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;
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)) {