From patchwork Mon Nov 22 13:45:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Rini X-Patchwork-Id: 1558084 X-Patchwork-Delegate: rfried.dev@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HyT7k5Dp4z9sS8 for ; Tue, 23 Nov 2021 00:46:10 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DF0EA80FAE; Mon, 22 Nov 2021 14:46:04 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=konsulko.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 3EC52831E9; Mon, 22 Nov 2021 14:46:02 +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.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) (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 A305F80EEE for ; Mon, 22 Nov 2021 14:45:58 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=konsulko.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=tom.rini@gmail.com Received: by mail-qt1-f180.google.com with SMTP id l8so16517388qtk.6 for ; Mon, 22 Nov 2021 05:45:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=oANUO1gtdvQR9nPBDK2SxbS2mrYzPk2Gdkw1VPorTYg=; b=ofbVVGj43T2cSQXLm2PZOwNLXF/sw/zO2elKPNWEqc0x2aPR/RLeFVsga+MpOKXjBI 7boxQ31n28FdQtN4mxSxJRWR3CxLSJubOzyJFBQEh5OJasLj6A6kneROtirRwxChl9K0 2u1dscIPHTIdmf7IKXiX5+1TidTmaY8KboBTDRUvE83yqoQx7h8JRROgrPIQZdxlcQNM /Eac95KKlP9lDmbx1TJvF4WFABbl9JVtDjp4pwx7odRFC8Qy3QZmTn8RkwBPdU/ULH3q imzk5MKakEyrdx3pgQToTrrCehuT29HTaulVnNYZ4WR9jYCYSY3QWizDkEyZKGLXSbkW M15Q== X-Gm-Message-State: AOAM530+HWAriT6Vn8voa+2r668DyPcqqoIW7r9aqkgkq4apa43Vt1dF kik7DYvW7M7fmgEinyaOYSOEeDH0cQ== X-Google-Smtp-Source: ABdhPJxAcgNrNmAGrpaQShMNijYcK492imLy6q/7eTfcJwPS9Katchp1EpPgYiaz1RJgS/l+5vuK+Q== X-Received: by 2002:a05:622a:454:: with SMTP id o20mr32233010qtx.217.1637588752442; Mon, 22 Nov 2021 05:45:52 -0800 (PST) Received: from bill-the-cat.lan (2603-6081-7b01-cbda-d1dd-c96e-a218-ce5d.res6.spectrum.com. [2603:6081:7b01:cbda:d1dd:c96e:a218:ce5d]) by smtp.gmail.com with ESMTPSA id v12sm4587888qtx.80.2021.11.22.05.45.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Nov 2021 05:45:51 -0800 (PST) From: Tom Rini To: u-boot@lists.denx.de Cc: Michal Simek , Wolfgang Denk , Ramon Fried Subject: [PATCHv3] net: uclass: Save generated ethernet MAC addresses to the environment Date: Mon, 22 Nov 2021 08:45:48 -0500 Message-Id: <20211122134548.3310678-1-trini@konsulko.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.37 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 From: Michal Simek 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 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..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);