Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3FB67C433F5 for ; Fri, 8 Oct 2021 19:58:11 +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 A951C60F57 for ; Fri, 8 Oct 2021 19:58:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A951C60F57 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 8CBB78361E; Fri, 8 Oct 2021 21:57:30 +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="Wq7FpDzf"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B835E83626; Fri, 8 Oct 2021 21:57:12 +0200 (CEST) Received: from mail-oo1-xc2e.google.com (mail-oo1-xc2e.google.com [IPv6:2607:f8b0:4864:20::c2e]) (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 621D7833B1 for ; Fri, 8 Oct 2021 21:57:07 +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-oo1-xc2e.google.com with SMTP id b5-20020a4ac285000000b0029038344c3dso3229718ooq.8 for ; Fri, 08 Oct 2021 12:57:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=F6ypv7lSle0yrOOKVW8WLRDr2xAddUVun11WFZ4Jy/s=; b=Wq7FpDzf6jiW+l4jP56R6lfW275u740mkF9P0LZryzU4VqphvwHymC8wDWdjEYlN3J CZx5dCG7UBAzuo58+pLm+AHgR3gOWmami9vpvMeMLPY4e2U0sPLZ7IVUIJAKIIGc+yF6 Br56JbbecQ8IEq7ZnQJm+cs9wX/6aPIEXRaOCR+D30bMDXD/mZISRgZG3viy1Qe6X5ju hMErTK+HtI3Cmu0MDBtIzJzMjmbencGsMo2LiRM0pEOdiUYJv6b/Vzif5p7mMjdPmYEB 2KN8tk+A+vNgnvJk7B6hMox+g4A0W/BxvvKQyubpfAMIgvSvwyur1LY8/HHv/xgXrAA6 +yVg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=F6ypv7lSle0yrOOKVW8WLRDr2xAddUVun11WFZ4Jy/s=; b=LEvpOAHufyzU8QniWheI75bugHNX3aWXWmbuCa4KGu+X9yaOdRNjVVciraRNRKqYm3 msFbpaZ7oCYf97K46sEwkTLyg4/mGfaQw2SqKl4pUPOzcgkfNJGJpq6vXYvBArbIz5L6 M+0EGyfHZRTjHz50kVwsC8ruDt+VcpVhs4tairYu/oK1AwmBmQ9whleTEgpZn3TgXEKU eHlA7NiLnzMImBCsABdzMWeUQPjCkZGAnM2HXNttCGsrk1LhR0vAgjs54j5jLkZvmuQe 58gcf9DwLI2cMEnCMkiQrjtESPPQCIGXOyK9/GoOkAGJosvpDERurrBDLoJQH4VTce0p nAPw== X-Gm-Message-State: AOAM533FKhKtCo7KMW+uCuYtTbOevw1G1pA/JzLTdNujYGl4AyfjwhXg AHd+cixNaIsotZbec0yYSBWAIG29SoQ= X-Google-Smtp-Source: ABdhPJwqrC0Zgwy92+BIKph85Yse00dWGv0BqIR3Z3npByERDvMW5PMcmKOxPdp/VBd29i6B1bXS/Q== X-Received: by 2002:a4a:3859:: with SMTP id o25mr5106693oof.10.1633723025663; Fri, 08 Oct 2021 12:57:05 -0700 (PDT) Received: from nuclearis3.lan (c-98-195-139-126.hsd1.tx.comcast.net. [98.195.139.126]) by smtp.gmail.com with ESMTPSA id x8sm67409otg.31.2021.10.08.12.57.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Oct 2021 12:57:05 -0700 (PDT) From: Alexandru Gagniuc To: u-boot@lists.denx.de, uboot-stm32@st-md-mailman.stormreply.com, patrick.delaunay@foss.st.com Cc: Alexandru Gagniuc , patrice.chotard@foss.st.com, etienne.carriere@linaro.org Subject: [PATCH v3 06/13] fdt_support: Implement fdt_ethernet_set_macaddr() Date: Fri, 8 Oct 2021 14:56:48 -0500 Message-Id: <20211008195655.46046-7-mr.nuke.me@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211008195655.46046-1-mr.nuke.me@gmail.com> References: <20211008195655.46046-1-mr.nuke.me@gmail.com> MIME-Version: 1.0 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 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. 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 8992ac5d3f..1c43640cf7 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -610,6 +610,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 72a5b90c97..8453fc8d76 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); -- 2.31.1