From: Michal Simek <michal.simek@xilinx.com>
To: u-boot@lists.denx.de, git@xilinx.com
Cc: Wolfgang Denk <wd@denx.de>, Ramon Fried <rfried.dev@gmail.com>,
Joe Hershberger <joe.hershberger@ni.com>,
Simon Glass <sjg@chromium.org>
Subject: [PATCH v4] net: uclass: Save generated ethernet MAC addresses to the environment
Date: Tue, 11 Jan 2022 10:28:09 +0100 [thread overview]
Message-ID: <1a2518e3cc19c14a41875ef64c5acc1f16edc813.1641893287.git.michal.simek@xilinx.com> (raw)
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>
---
Changes in v4:
- Legacy code was c&p from DM which didn't work. CI found it that's why
new version is required
Changes in v3:
- Update Kconfig help text with Wolfgang's suggestion
- Reword the commit message to hopefully be clearer
Changes in v2:
- Update Kconfig help text to reflect this change.
- Update the legacy path to match.
net/Kconfig | 9 +++++----
net/eth-uclass.c | 2 ++
net/eth_legacy.c | 2 ++
3 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/net/Kconfig b/net/Kconfig
index 7a2d14501881..cabe93c6bd29 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -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"
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..0b282d918bec 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", eth_number,
+ dev->enetaddr);
#else
printf("\nError: %s address not set.\n",
dev->name);
--
2.34.1
next reply other threads:[~2022-01-11 9:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-11 9:28 Michal Simek [this message]
2022-01-12 9:39 ` [PATCH v4] net: uclass: Save generated ethernet MAC addresses to the environment Michal Simek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1a2518e3cc19c14a41875ef64c5acc1f16edc813.1641893287.git.michal.simek@xilinx.com \
--to=michal.simek@xilinx.com \
--cc=git@xilinx.com \
--cc=joe.hershberger@ni.com \
--cc=rfried.dev@gmail.com \
--cc=sjg@chromium.org \
--cc=u-boot@lists.denx.de \
--cc=wd@denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.