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=-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 E6475C433F5 for ; Wed, 8 Sep 2021 00:01:27 +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 6241C61102 for ; Wed, 8 Sep 2021 00:01:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6241C61102 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 8A7CD8334E; Wed, 8 Sep 2021 02:00:50 +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="ZGQG3NOB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id ED69682BD6; Wed, 8 Sep 2021 02:00:08 +0200 (CEST) Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) (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 3365D832FC for ; Wed, 8 Sep 2021 01:59:47 +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-x730.google.com with SMTP id t190so689426qke.7 for ; Tue, 07 Sep 2021 16:59:47 -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=sGEJu4EkxMZapoclpGORUy4+ClEcEKT2o0miuvPph5U=; b=ZGQG3NOBDnLj2VF0/G+Gpyu91VT7SOXzZNbU59hT8yhf+vkUjyAXZqViyD10n8AYee ibHvwnTdl5omvc+uguEjm1UTiNO+yqLiJ52GW93GqUOqJ3yuHMHvFm6y5R/4S1QAeafl vCOCQOWJmS33RREsnuUWQrzDX6oRYxHz55vSVEu2n+yeKlIjhgtRCWcxVOTySEwi7p/m qyJwRKEanjGQKapPNy5TpNbFKZhaHlnV8x/LTTOQiFEpUfP60QgfjkWIqjQpYSXhliE2 A5W+PwqgJwGNzFhZ+xqDYdKKjGDkSV1l4YcmI/hv+Qc1P5OlDtBR7zSCgOW136tEkJSH Hlqw== 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=sGEJu4EkxMZapoclpGORUy4+ClEcEKT2o0miuvPph5U=; b=SarUNzKX6LUXzN7oDzSCpO9oNTOcXd4C1Durbq/SGvQVMFCh3eWMD0lGl3hZiaG03D MRCQRO99NGY7xxER+ciX0drUIZUAx165Yzc2xrhAd5sMucIp3TLwD53UYZIipf0vT+O1 Ed7uilafDm1oDLb0ULvC4GGvj+5aNjV1ZrBtY8ZHTfbFT23wAzGT8kTS2sBa9qY/RtIg NK6W8SI4j9oIPVwtIm5x0wpGLcSePcPpq490n5VNxEtdFP833eNnc478J9stVVyinKvi /3kC++iK7/rYY18Upw+z6wK7T+Ah/Zk2usUpUDG5EJ1yQxP/GET7YYOWs5xmk0iJlA1S Lqow== X-Gm-Message-State: AOAM530Dj1Td2aUmikM0haOPLaxD1qAJCjK9nQFPs+LrDgC6o/QjtZub e3yRhMgqamRjEft9X18gYAy5+qLefZE= X-Google-Smtp-Source: ABdhPJz4SgD9utpuhj/O2rCryETUcC3CW/lN9c/f39RAWRyPeFd7hLLCHRdO6EfXK6LtP5JCKYUSSg== X-Received: by 2002:a37:6d7:: with SMTP id 206mr856071qkg.251.1631059185611; Tue, 07 Sep 2021 16:59:45 -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.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 16:59:45 -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 08/11] stm32mp1: spl: Configure MAC address when booting OP-TEE Date: Tue, 7 Sep 2021 18:59:30 -0500 Message-Id: <20210907235933.2798330-9-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 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 When OP-TEE is booted as the SPL payload, the stage after OP-TEE is not guaranteed to be u-boot. Thus the FDT patching in u-boot is not guaranteed to occur. Add this step to SPL. The patching by stm32_fdt_setup_mac_addr() is done in SPL, and patches the target FDT directly. This differs is different from setup_mac_address(), which sets the "ethaddr" env variable, and does not work in SPL. An alternative way of setting the MAC is to patch the kernel's devicetree to use the "nvmem-cells" property. This would backend on the linux BSEC driver, which relies on an SMCC call. That call is implemented only by TF-A, not by SPL. Thus linux will not be able to read the MAC from OTP, and this alternative method will fail. Changing the linux driver is not feasible is our goal is to support the current linux LTS release (v5.14). Implementing the SMCC call would require SPL finagling, and possibly carry security side-effects. Thus, adding "mac-address" nodes to the kernel devicetree is the most economical method in terms of lines of code and complexity. Signed-off-by: Alexandru Gagniuc --- arch/arm/mach-stm32mp/cpu.c | 22 +++++++++++++++++++ .../arm/mach-stm32mp/include/mach/sys_proto.h | 3 +++ arch/arm/mach-stm32mp/spl.c | 1 + 3 files changed, 26 insertions(+) diff --git a/arch/arm/mach-stm32mp/cpu.c b/arch/arm/mach-stm32mp/cpu.c index 8727de513c..2b8b67bb40 100644 --- a/arch/arm/mach-stm32mp/cpu.c +++ b/arch/arm/mach-stm32mp/cpu.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -646,6 +647,27 @@ __weak int setup_mac_address(void) return 0; } +int stm32_fdt_setup_mac_addr(void *fdt) +{ + int ret; + uchar enetaddr[ARP_HLEN]; + + ret = stm32_read_otp_mac(enetaddr); + if (ret < 0) + return ret; + + if (!is_valid_ethaddr(enetaddr)) { + printf("invalid MAC address in OTP\n"); + return -EINVAL; + } + + ret = fdt_ethernet_set_macaddr(fdt, 0, enetaddr); + if (ret) + debug("Failed to set mac address from OTP: %d\n", ret); + + return ret; +} + static int setup_serial_number(void) { char serial_string[25]; diff --git a/arch/arm/mach-stm32mp/include/mach/sys_proto.h b/arch/arm/mach-stm32mp/include/mach/sys_proto.h index 4149d3a133..2d24cfee3f 100644 --- a/arch/arm/mach-stm32mp/include/mach/sys_proto.h +++ b/arch/arm/mach-stm32mp/include/mach/sys_proto.h @@ -47,7 +47,10 @@ void get_soc_name(char name[SOC_NAME_SIZE]); /* return boot mode */ u32 get_bootmode(void); +/* Set 'ethaddr' env variable with MAC from OTP (useful for u-boot proper) */ int setup_mac_address(void); +/* Patch the first 'ethernet' node of FDT with MAC from OTP (useful for SPL) */ +int stm32_fdt_setup_mac_addr(void *fdt); /* board power management : configure vddcore according OPP */ void board_vddcore_init(u32 voltage_mv); diff --git a/arch/arm/mach-stm32mp/spl.c b/arch/arm/mach-stm32mp/spl.c index 405eff68a3..d9fdc5926c 100644 --- a/arch/arm/mach-stm32mp/spl.c +++ b/arch/arm/mach-stm32mp/spl.c @@ -181,6 +181,7 @@ void stm32_init_tzc_for_optee(void) void spl_board_prepare_for_optee(void *fdt) { + stm32_fdt_setup_mac_addr(fdt); stm32_init_tzc_for_optee(); } -- 2.31.1