From patchwork Tue Jan 11 09:28:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1578346 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=LouWmtBm; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JY53L3wWrz9sCD for ; Tue, 11 Jan 2022 20:28:28 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A705581982; Tue, 11 Jan 2022 10:28:22 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.b="LouWmtBm"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EB7A4805F9; Tue, 11 Jan 2022 10:28:20 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id F13D581982 for ; Tue, 11 Jan 2022 10:28:17 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ed1-x531.google.com with SMTP id b13so11261137edn.0 for ; Tue, 11 Jan 2022 01:28:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20210112.gappssmtp.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ExIzmCcr2Am8+weXCQuV+CTyni0BPmhz2OhjCeM9IbA=; b=LouWmtBm5WVSjvXoDQ5IvZJmsoN8Pd3n9WixoeBrd8g2smzjXXo9DhqL5g2Q5qaKFK CtAVbs+FOSJuZ2zcdqU++hH9IPUXmLf1MhCuBBcfhAdTav7lYu1G3VsgWA8z9Ezd2bPc qeAoy3xxHEbYS7FGv5vliS9MgBQP20a9M7TBbtK91q1rWJws4jjCLD/MKYqsEmwyHiTV xq4qfH1fP9X0T8kaVc7evnqRoOumoOFprITq9ih3sn44S3lFBqMBrJskwj41VZqKYW0o EtONjurun/P6HYe0stzNa7qx7Ak8LHC68Wox8gety6NBL5lrADWpSQ8UTFXhsh8jXvJ+ 6qgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=ExIzmCcr2Am8+weXCQuV+CTyni0BPmhz2OhjCeM9IbA=; b=lSN4iuxOpZAH/+94hXrPnrsV5OamcIRY9HGk6erkNjaUUR89wwLgEppy44RDCMWPRX 9IlA6ZNVmVt2/G25frenwU8Zpn7Y/CCEyVFuGyqZ064OWLAEwqKcoQkp1Py5pdW+2vUQ pYzCcOtVucnqHFOUoH9UcHTaGpC9BjeIo9I1hPewfmlntNdNXTASh9B2hI7fe8Tube5l li+jzVPKJ6ZLOHEteT4IPF0/dG+gm8b9nhLDkPFfDziJwTIHqBipC4HEVqTvIw2zM5oZ dTrMIfwjlkuifsn9DpBfO50tw8Db6DMeL/hfKTRe9uQ9UW/5wu9FnpiotP3HSO2/eQKX dPmg== X-Gm-Message-State: AOAM530g2IWcNowwHENaQt2ZDZzgrmaCRazqqNqmtFuaUL25yCfO1xI2 J4PUD9GDBQ18QzmUQ9PibNucqMTkTn54Au5b X-Google-Smtp-Source: ABdhPJyArqbaj3aZMpaVw1Kzc+NgkLULYigTFFJxBpum0BiB8ocOe1Vtfet8UyQeDMt7vw43cZ/ebw== X-Received: by 2002:a17:906:ac7:: with SMTP id z7mr2880458ejf.617.1641893297344; Tue, 11 Jan 2022 01:28:17 -0800 (PST) Received: from localhost ([2a02:768:2307:40d6::f9e]) by smtp.gmail.com with ESMTPSA id ga10sm3424474ejc.12.2022.01.11.01.28.16 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Jan 2022 01:28:16 -0800 (PST) From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Wolfgang Denk , Ramon Fried , Joe Hershberger , Simon Glass Subject: [PATCH v4] net: uclass: Save generated ethernet MAC addresses to the environment Date: Tue, 11 Jan 2022 10:28:09 +0100 Message-Id: <1a2518e3cc19c14a41875ef64c5acc1f16edc813.1641893287.git.michal.simek@xilinx.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean 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 Signed-off-by: Michal Simek Reviewed-by: Ramon Fried [trini: Update Kconfig, handle legacy networking case as well] Signed-off-by: Tom Rini Acked-by: Ramon Fried --- 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);