From patchwork Tue Sep 7 23:59:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Gagniuc X-Patchwork-Id: 1525589 X-Patchwork-Delegate: patrice.chotard@st.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=qnJD6IVi; dkim-atps=neutral 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H42NN4pd5z9t0T for ; Wed, 8 Sep 2021 10:01:08 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5F6528332F; Wed, 8 Sep 2021 02:00:40 +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="qnJD6IVi"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4252E82E05; Wed, 8 Sep 2021 01:59:59 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) (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 B81B5832CD for ; Wed, 8 Sep 2021 01:59:43 +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-qk1-x729.google.com with SMTP id y144so694245qkb.6 for ; Tue, 07 Sep 2021 16:59:43 -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=hD1glrFe2f3M42mjA0Ks0yVEAoqE0B0Q78UH9jCi99A=; b=qnJD6IViSenjFh9WerYv+XnpgYJSoGbFtHfRL347E87QntiFEUvnui1Galaejxn6xj friYeC6ttVav5cqgJpIHnRI/mhPmfldyXjyl0GTay3EDzFtHw3eKxwOIz6S/3nuAgbct bWP8c8LAVnowH2Sxxa5hO7XP9+tHMQjK32Bok3k/5js02btLzk2ihqMcN6/sjl/wueUS 8e9ix/cA22I+pDqxez2G24+rWQZtxsFkRD390nBuiB4fDxbKKFWcoVXjhaNtN4lQtAQe ufo/8sw8oOAmXe2cE+oXP0deFzTC47NgzqDHds9aR5haH2vfQUVWqtf7H/1fJKSfzwMl uGDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hD1glrFe2f3M42mjA0Ks0yVEAoqE0B0Q78UH9jCi99A=; b=qIlg5FqUVsU5ToQx498+9V7FboxsLv/0VWthbftz1IY2Uvq6+zMzfxR+D/LW43G9Fp F0w8gbdRg7/pGXOVNRdrjEzQRlaEaEk8LBL4fwI1vMcIlNxZRdv+4LhN649qByh5D7h4 2wGDDJuVGjvJzTfhxXLGkilu3DRWNcnkyP+LQsD+CLBG66ze+m3Do6d3V+wYn9eSV2NI RlKM7AGx4jqD3ANiIS/X7MXXRdvnkpgwc39OobglH0R/jVN425iwyYPC+zuS031d5GXH ExhNt7/af9HmaKDB4GmWv63jcbO5r2mJZ+5Pl3EWPH+6dK8Rh6HQRBlznwJAxVfj8+QN LHhw== X-Gm-Message-State: AOAM532ibps18ylEc7sBErXUGHtyKjxPkEVcNB6wuHHrFx/FlAu0TeYR BngfriAd+nWxRfW9j9T1H/2hMrNXlQA= X-Google-Smtp-Source: ABdhPJwrh7WKLN3zfWKDzxUo/5AqDbrxYtFsfaXW3CBC27pc2AClHglLtpEgwVVON2qMQ7ly93RBJw== X-Received: by 2002:a05:620a:1453:: with SMTP id i19mr895009qkl.40.1631059182254; Tue, 07 Sep 2021 16:59:42 -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 d78sm460351qkg.92.2021.09.07.16.59.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 16:59:41 -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 v2 05/11] fdt_support: Implement fdt_ethernet_set_macaddr() Date: Tue, 7 Sep 2021 18:59:27 -0500 Message-Id: <20210907235933.2798330-6-mr.nuke.me@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210907235933.2798330-1-mr.nuke.me@gmail.com> References: <20210907235933.2798330-1-mr.nuke.me@gmail.com> MIME-Version: 1.0 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 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);