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 74A28C433F5 for ; Fri, 8 Oct 2021 19:58:41 +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 EAF8960F57 for ; Fri, 8 Oct 2021 19:58:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org EAF8960F57 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 5BB428363C; Fri, 8 Oct 2021 21:57:42 +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="niSgxxsf"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 42FC883620; Fri, 8 Oct 2021 21:57:18 +0200 (CEST) Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) (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 5424E833D4 for ; Fri, 8 Oct 2021 21:57:11 +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-ot1-x32c.google.com with SMTP id l7-20020a0568302b0700b0054e40740571so7287381otv.0 for ; Fri, 08 Oct 2021 12:57:11 -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=niSgxxsfLHGY9DOzqlhfRoCIAeX2pSps6IWe438a37jVfqanaR0vY8DvDesbeh2S7W oHcwVGkbQRZETOPtxYSqnmHJ8OE+mMOJ/+qLdZYCzD69+novsKYsQcvbMjoh9/PN6TnW JNjJt6mfze9rV3opun8GtQ8W29xgHQpiu76R2dWLHsbQX71TH2oXiTFC5sFSLXgeWFyH HnNt/BVEpWleFJYGWlHMWBCn6ED7KuPKSBjDSoKl6VOXZOFQFF+vtOsRYP7RLi0SDAUO 1BKES4ImeA/lOF1Rj3ug13cf7bL5h1MoCQzPi5yNLJIKMqKY9y0AsGVBUhXXy4XU3p+Z uXhQ== 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=sGEJu4EkxMZapoclpGORUy4+ClEcEKT2o0miuvPph5U=; b=gXMDOzxiQW1+ulQ2lM8M3pZheVc0zbGyqBehqDPBuyL6Ien5jglOar0iG4ABD690sa wFo7LU8e+UgxNxBURalb6furY38OepYZskrkEs4nfTrbVmAmp2yjwEZ4JOuGI/OXqoim 6Msb95/ZxajvxOLOaz8zKCzR7v9Urgr7nilZ4bZS1fEUn0Ed0GxQNNxg8C1qwiOVSERj RWNiP22jicRPSXGwGg64El1+nqUCOBOWaPJfxha+DhdNuXty3Nm8vcBbo9hrzMX+qYAD mhYB5lv8nVJmeGDSOgAzF/GTTAMzz3Sf5aLvdmkosnJIDLMW8EN1HiXzLFV+6MA81t29 8Y+g== X-Gm-Message-State: AOAM532MWcGBcztYa5saOzSR6CeTOuU3hOiC+usUyYiTVoagqnFVaogV 78WlKWGl7HIIHx77h73UlyUHtIFsxlg= X-Google-Smtp-Source: ABdhPJwOyJaGMS+rYFjDvnzM7HXlEHyKzKscunHwSAdnnvY+nxpr7FJjk/akt6X/vwVBzdOy521LmA== X-Received: by 2002:a05:6830:101:: with SMTP id i1mr10282758otp.107.1633723028852; Fri, 08 Oct 2021 12:57:08 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Oct 2021 12:57:08 -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 09/13] stm32mp1: spl: Configure MAC address when booting OP-TEE Date: Fri, 8 Oct 2021 14:56:51 -0500 Message-Id: <20211008195655.46046-10-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 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