net: uclass: Save ethernet MAC address when generated
PATCH v2 1/1 net: uclass: Save ethernet MAC address when generated
From: Michal Simek <[email protected]>
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.
---
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(-)
net/Kconfig +3 -3
@@ -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"
net/eth-uclass.c +2 -0
@@ -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);
net/eth_legacy.c +2 -0
@@ -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);
Signature · 1 line
2.25.1
Dear Tom,
Quoted 4 lines · In message <[email protected]> you wrote:
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.
"saved to variables" ? Which variables? In C code? In the environment?
This is not clear here.
net/Kconfig config NET_RANDOM_ETHADDR · line 33
Quoted 7 lines
net/Kconfig +3
-3Selecting 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.
Same here: "ethaddr variable" - I guess this refers to the environment variable? Then we should write that.
Hmmm: "when the ethaddr variable ... is unset by generating ... and setting the appropriate environment variable." this is misleading, as the "ethaddr variable" is not unset by setting the env var.
Suggestion:
Selecting this will allow the Ethernet interface to function even when the ethaddr variable for that interface is unset. In this case, a random MAC address in the locally administered address space is generated. It will be saved to the appropriate environment variable, too.
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: [email protected] A conservative is a man with two perfectly good legs who has never learned to walk. - Franklin D. Roosevelt