public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCHv2] net: uclass: Save ethernet MAC address when generated
@ 2021-11-20 15:53 Tom Rini
  2021-11-22 10:53 ` Wolfgang Denk
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Rini @ 2021-11-20 15:53 UTC (permalink / raw)
  To: u-boot; +Cc: Michal Simek, Ramon Fried

From: Michal Simek <michal.simek@xilinx.com>

When MAC address is randomly generated it should be also saved to
variables. This step is there when MAC address is passed via pdata but not
when it is randomly generated.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
[trini: Update Kconfig, handle legacy networking case as well]
Signed-off-by: Tom Rini <trini@konsulko.com>
---
Changes in v2:
- Update Kconfig help text to reflect this change.
- Update the legacy path to match.
---
 net/Kconfig      | 6 +++---
 net/eth-uclass.c | 2 ++
 net/eth_legacy.c | 2 ++
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/net/Kconfig b/net/Kconfig
index 7a2d14501881..20a36156a01f 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -28,9 +28,9 @@ 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.
+	  even when the ethaddr variable for that interface is unset by
+	  generating a new MAC address in the locally administered address
+	  space and setting the appropriate environment variable.
 
 config NETCONSOLE
 	bool "NetConsole support"
diff --git a/net/eth-uclass.c b/net/eth-uclass.c
index 0da0e85be031..58c308f33276 100644
--- a/net/eth-uclass.c
+++ b/net/eth-uclass.c
@@ -583,6 +583,8 @@ static int eth_post_probe(struct udevice *dev)
 		net_random_ethaddr(pdata->enetaddr);
 		printf("\nWarning: %s (eth%d) using random MAC address - %pM\n",
 		       dev->name, dev_seq(dev), pdata->enetaddr);
+		eth_env_set_enetaddr_by_index("eth", dev_seq(dev),
+					      pdata->enetaddr);
 #else
 		printf("\nError: %s address not set.\n",
 		       dev->name);
diff --git a/net/eth_legacy.c b/net/eth_legacy.c
index f383ccce0b92..e7f53b958b2e 100644
--- a/net/eth_legacy.c
+++ b/net/eth_legacy.c
@@ -164,6 +164,8 @@ int eth_write_hwaddr(struct eth_device *dev, const char *base_name,
 		net_random_ethaddr(dev->enetaddr);
 		printf("\nWarning: %s (eth%d) using random MAC address - %pM\n",
 		       dev->name, eth_number, dev->enetaddr);
+		eth_env_set_enetaddr_by_index("eth", dev_seq(dev),
+					      pdata->enetaddr);
 #else
 		printf("\nError: %s address not set.\n",
 		       dev->name);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-11-22 10:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-20 15:53 [PATCHv2] net: uclass: Save ethernet MAC address when generated Tom Rini
2021-11-22 10:53 ` Wolfgang Denk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox