]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
net: uclass: Save generated ethernet MAC addresses to the environment
authorMichal Simek <michal.simek@xilinx.com>
Tue, 11 Jan 2022 09:28:09 +0000 (10:28 +0100)
committerMichal Simek <michal.simek@xilinx.com>
Tue, 11 Jan 2022 09:33:42 +0000 (10:33 +0100)
When a MAC address is randomly generated we currently only update the
appropriate data structure.  For consistency and to re-align with
historic usage, it should be also saved to the appropriate environment
variable as well.

Cc: Wolfgang Denk <wd@denx.de>
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>
Acked-by: Ramon Fried <rfried.dev@gmail.com>
Link: https://lore.kernel.org/r/1a2518e3cc19c14a41875ef64c5acc1f16edc813.1641893287.git.michal.simek@xilinx.com
net/Kconfig
net/eth-uclass.c
net/eth_legacy.c

index 7a2d145018815c622dec7d37fba3753a3819dc46..cabe93c6bd296b2744ac46930870351c096fe600 100644 (file)
@@ -27,10 +27,11 @@ config BOOTP_SEND_HOSTNAME
 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.
+         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.
 
 config NETCONSOLE
        bool "NetConsole support"
index 0da0e85be0314baa19d6ff043a90adf7838cd7c9..58c308f33276696d1b9a227153c1761190c23388 100644 (file)
@@ -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);
index f383ccce0b92e528df54c8bb02ae966b61bce813..0b282d918bec382d2aae28f8b396249cf9c2553c 100644 (file)
@@ -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", eth_number,
+                                             dev->enetaddr);
 #else
                printf("\nError: %s address not set.\n",
                       dev->name);