From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39747C432BE for ; Thu, 26 Aug 2021 23:50:36 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2957960E75 for ; Thu, 26 Aug 2021 23:50:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2957960E75 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4153583210; Fri, 27 Aug 2021 01:50:32 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="nuhBsEIr"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AA7128321D; Fri, 27 Aug 2021 01:50:28 +0200 (CEST) Received: from mail-oi1-x232.google.com (mail-oi1-x232.google.com [IPv6:2607:f8b0:4864:20::232]) (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 1837582ECD for ; Fri, 27 Aug 2021 01:50:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=mr.nuke.me@gmail.com Received: by mail-oi1-x232.google.com with SMTP id q39so7000554oiw.12 for ; Thu, 26 Aug 2021 16:50:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=sjwnRV2om1dRCzqr+J/xbSMimbBrSDfWSpKwtpiox84=; b=nuhBsEIrEvny7+xltYKSV7qgt/cyVE2N2JwgB2Bbc2xIHTyHPT6k6gtzdzc3wpGDqJ zvXQ7j5H29qz0xI4QzxYGVBpcY8K37EE/zNP+BGo2Okf+8llf6cddPnwmvlEjJzYYq0Y 54hXdVoCz0MDS0dzEBErqNMZMXVkgBdOJBNHrCRkbpf08SH8uFbOWQmN/DIS2eXEyPf/ C57I40VjkpXrnDixcghxCUTYmP+8IW/CUfATKb9YbqQAp7VzG8cD5nNnlJGxH93h98aw W4D0WrQgrUm3c8E/zlZ/8mhB3BZ7H/NQWaB/3ZdJbWsc1JJw4TTMda5GhOrkow4RwUnu pGTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=sjwnRV2om1dRCzqr+J/xbSMimbBrSDfWSpKwtpiox84=; b=rLMM1Z6NBhOk5eOosEja1BgcMAVTwVhY9kqJAqC9RL6v/AAOmP+iOi+kKPMQnLWCCR UVakxRW3ida2giCT2qnpF15sxERKpkppATuzEQv5h1m2eIr5o3l8APQuCvQK/bahGWCg RmztMc/LmrqNIjoaw8HRttOmYLG0MBEWYwgTxI4M3DubcYeg207AJnxocwtRnrw0TmeH XAhtTEUjBbsbsGsxWxFXt0pzpkNyszeUsei+cmCrXVCAkcdTHHnWIG4FzLep4vQnP/0P R1FaslQmxgkmdp14QUGdF226tP0wRzdrI5oqHAc3vh7mBbJuZc4xjcTv0oCiabiHv50p 0z6A== X-Gm-Message-State: AOAM530ifCWAL+eU5WxZqsLjArhmT5IiPO8AKj88VHqz00oz8pciVk2Y j1lb+aUtkKKTzyVyCvwqZ+7Pj9NEIy8= X-Google-Smtp-Source: ABdhPJywgW/i0KiP5fY///UUm1M8X+TMERlLraSraxo6xU4V2++jYH3DMl9rj+uKdmfLG3S4QA+kXg== X-Received: by 2002:a05:6808:10c8:: with SMTP id s8mr13084336ois.175.1630021820383; Thu, 26 Aug 2021 16:50:20 -0700 (PDT) Received: from nuclearis3.gtech (c-98-195-139-126.hsd1.tx.comcast.net. [98.195.139.126]) by smtp.gmail.com with ESMTPSA id w66sm943631otb.15.2021.08.26.16.50.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 26 Aug 2021 16:50:19 -0700 (PDT) Subject: Re: [PATCH 04/10] fdt_support: Implement fdt_ethernet_set_macaddr() To: Sean Anderson , u-boot@lists.denx.de Cc: patrick.delaunay@foss.st.com, marex@denx.de References: <20210826214209.254461-1-mr.nuke.me@gmail.com> <20210826214209.254461-5-mr.nuke.me@gmail.com> From: "Alex G." Message-ID: <0ab95129-d3bf-39f1-1281-b9c8b71def1f@gmail.com> Date: Thu, 26 Aug 2021 18:50:19 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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 Hi Sean, On 8/26/21 6:35 PM, Sean Anderson wrote: > > > On 8/26/21 5:42 PM, Alexandru Gagniuc wrote: >> Oftentimes we have MAC address information stored in a ROM or OTP. The >> way to add that to the FDT would be through the u-boot environment, >> and then fdt_fixup_ethernet(). This is not very useful in SPL. >> >> It would be more helpful to be able to "set interface x to MAC y". >> This is where fdt_ethernet_set_macaddr() comes in. It is similar in >> function to fdt_fixup_ethernet(), but only updates one interface, >> without using the u-boot env, and without string processing. > > Have you considered adopting the nvmem-cells property for ethernet > controllers (added in Linux commit 0e839df92cf3 ("net: ethernet: provide > nvmem_get_mac_address()"))? Obviously I haven't. It sounds like a great idea. Thank you for pointing me to it. Alex > --Sean > >> Signed-off-by: Alexandru Gagniuc >> --- >>   common/fdt_support.c  | 30 ++++++++++++++++++++++++++++++ >>   include/fdt_support.h | 17 +++++++++++++++++ >>   2 files changed, 47 insertions(+) >> >> diff --git a/common/fdt_support.c b/common/fdt_support.c >> index 4341d84bd5..c4cbd4060e 100644 >> --- a/common/fdt_support.c >> +++ b/common/fdt_support.c >> @@ -592,6 +592,36 @@ void fdt_fixup_ethernet(void *fdt) >>       } >>   } >> >> +int fdt_ethernet_set_macaddr(void *fdt, int ethnum, const uint8_t >> *mac_addr) >> +{ >> +    const char *path, *name; >> +    int prop, aliases_node; >> +    char eth_name[16] = "ethernet"; >> + >> +    aliases_node = fdt_path_offset(fdt, "/aliases"); >> +    if (aliases_node < 0) >> +        return aliases_node; >> + >> +    if (ethnum >= 0) >> +        sprintf(eth_name, "ethernet%d", ethnum); >> + >> +    fdt_for_each_property_offset(prop, fdt, aliases_node) { >> +        path = fdt_getprop_by_offset(fdt, prop, &name, NULL); >> +        if (!strcmp(name, eth_name)) >> +            break; >> + >> +        path = NULL; >> +    } >> + >> +    if (!path) >> +        return -FDT_ERR_NOTFOUND; >> + >> +    do_fixup_by_path(fdt, path, "mac-address", mac_addr, 6, 0); >> +    do_fixup_by_path(fdt, path, "local-mac-address", mac_addr, 6, 1); >> + >> +    return 0; >> +} >> + >>   int fdt_record_loadable(void *blob, u32 index, const char *name, >>               uintptr_t load_addr, u32 size, uintptr_t entry_point, >>               const char *type, const char *os, const char *arch) >> diff --git a/include/fdt_support.h b/include/fdt_support.h >> index f6f46bb8e9..3f0bcb5a00 100644 >> --- a/include/fdt_support.h >> +++ b/include/fdt_support.h >> @@ -119,6 +119,23 @@ static inline int fdt_fixup_memory_banks(void >> *blob, u64 start[], u64 size[], >>   #endif >> >>   void fdt_fixup_ethernet(void *fdt); >> + >> +/** >> + * Set the "mac-address" and "local-mac-address" of ethernet node >> + * The ethernet node is located from the "/aliases" section of the >> fdt. When >> + * 'ethnum' is positive, then the name is matched exactly, e.g >> "ethernet0". >> + * When ethnum is negative, the first ethernet alias is updated. >> + * Unlike fdt_fixup_ethernet(), this function only updates one >> ethernet node, >> + * and soes not use the "ethaddr" from the u-boot environment. This >> is useful, >> + * for example, in SPL, when the environment is not initialized or >> available. >> + * >> + * @param fdt        FDT blob to update >> + * @param ethnum    Ethernet device index, or negative for any ethernet >> + * @param mac_addr    Pointer to 6-byte array containing the MAC address >> + * >> + * @return 0 if ok, or -FDT_ERR_... on error >> + */ >> +int fdt_ethernet_set_macaddr(void *fdt, int ethnum, const uint8_t >> *mac_addr); >>   int fdt_find_and_setprop(void *fdt, const char *node, const char *prop, >>                const void *val, int len, int create); >>   void fdt_fixup_qe_firmware(void *fdt); >>