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=-15.8 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,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 E6776C432BE for ; Thu, 26 Aug 2021 21:43:22 +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 60CC460F14 for ; Thu, 26 Aug 2021 21:43:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 60CC460F14 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 D868B8321D; Thu, 26 Aug 2021 23:43:13 +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="ZESMV7qj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 76D418311A; Thu, 26 Aug 2021 23:42:33 +0200 (CEST) Received: from mail-oo1-xc29.google.com (mail-oo1-xc29.google.com [IPv6:2607:f8b0:4864:20::c29]) (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 A04D38311A for ; Thu, 26 Aug 2021 23:42:18 +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-xc29.google.com with SMTP id t1-20020a4a54010000b02902638ef0f883so1389251ooa.11 for ; Thu, 26 Aug 2021 14:42:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RZT+HAZfrLyj8cHlQsqGduu6RYUYdMMQhft86KZ6OMA=; b=ZESMV7qj8GU5N9FTEfj18rMX+V5cd9WsxbOOLrLpRtaEJYYlJijE46VPzReSTJF1Mf EmDBtIKhRq+6VFkC24XWWfBa5YlKP7dq7T6fLCV/yjhApvZ57XWIo4egkyC6hIFcX29B DaiYSRaUlJJu3U56ziYDA0rjot0Bl1cR+Ai9xFrUqC4vXlwcnwumyQNj+T32cbPGF8wH 9vnnHDoAQXuBXgup4nciolmkfbkST1px5xfgI0b6sJKu9i5zkGKsNmZ9vyBMYFEIfHnh xHXCjSetxnj9G08tickJCcz8zsNtGiybJxaNRNNioau7n2NeHFlEYTGfS5ddULkKAijK qSpg== 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=RZT+HAZfrLyj8cHlQsqGduu6RYUYdMMQhft86KZ6OMA=; b=Ipp3Owby7je1qdBD9Tp1sPcDju+Ro0QOtB/x0BfH2jww3JiDLahHJHfzrL1BxjiVlO VuqqrOrD21QFKk7sjXgXG6+2pkOiOULliGG7ikilk8NXDC7iGOF6mR0yy+Uobl2ANfsZ Zz3guo/of5zNqedRLqAYLJx8hgSVFoLgb67c8peCPVmarKiSLwZJHp3GSg5f4kZ2EnXg 7cBW8EYtl/KxmNg/VWMPHMczrx9twa9NCeBuS/4ACPfn5K6eUKgCTd7dB7xHUslOuzm+ 92JGXou0jtt3ZxY8h9bvem+QsY7tI+IEOkYKhX5E3L/6OXn8bVM7NUZ11okilbBJBwh5 pcSw== X-Gm-Message-State: AOAM531L6vCQkrr1LqnOOnodoSgLFlHkgbNafoOFxBUrSGzBHJHhc13x S2rQUGJyVr7wDsSCFlhaMUj6xeBrkAo= X-Google-Smtp-Source: ABdhPJzIKuiG2b6pZ4/EG5eo5AeMKjMpYDh+Ch7gkq6GNbpc3GF0OCKpfpIUkcEjoulWnnzQBQ2cRg== X-Received: by 2002:a4a:a509:: with SMTP id v9mr5003466ook.73.1630014136878; Thu, 26 Aug 2021 14:42:16 -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 14sm858852otl.78.2021.08.26.14.42.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Aug 2021 14:42:16 -0700 (PDT) From: Alexandru Gagniuc To: u-boot@lists.denx.de Cc: patrick.delaunay@foss.st.com, marex@denx.de, Alexandru Gagniuc Subject: [PATCH 04/10] fdt_support: Implement fdt_ethernet_set_macaddr() Date: Thu, 26 Aug 2021 16:42:03 -0500 Message-Id: <20210826214209.254461-5-mr.nuke.me@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210826214209.254461-1-mr.nuke.me@gmail.com> References: <20210826214209.254461-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 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); -- 2.31.1