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.2 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,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 18502C4320A for ; Tue, 31 Aug 2021 19:14:03 +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 EE54F61056 for ; Tue, 31 Aug 2021 19:14:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org EE54F61056 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 2B64982DB2; Tue, 31 Aug 2021 21:13:59 +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="Iu/14zj9"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DB09382D7C; Tue, 31 Aug 2021 21:13:56 +0200 (CEST) Received: from mail-ot1-x333.google.com (mail-ot1-x333.google.com [IPv6:2607:f8b0:4864:20::333]) (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 02E3D82DB2 for ; Tue, 31 Aug 2021 21:13:52 +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-x333.google.com with SMTP id g66-20020a9d12c8000000b0051aeba607f1so396488otg.11 for ; Tue, 31 Aug 2021 12:13:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=97W1Gkn1g32ZcQhRSHWTxq1+IY4zi24DH9VPI7IU8Z0=; b=Iu/14zj9YpnrVxdJ2AAnvyxlNCoduPm0PautnARDkUykVqeHwHHIe+iMuO0wg6bk04 r329wJh/SpqwchL2Ldp775yhWYcTN4RgmqDzK2hxq6CFoPnpQdlQP4vIVZfQmZV/RwXl ZHTFaHL0SpVO5zLvuwsIvq1E1MP2T00z8gEfoUEdoZWs6dYPTVrlc5II1DS5xrLdK8C9 SaRiaI8Q3oxJegytuIK26KlyO2FjBawMV/Q8oLPCHcQlYRU5Eo9eM1ucRHeVi9YEi9OU n8OaANUTTL8Us5ryTyy8gjoEycUF9SlTeiQFzzAviEzDFFfv0UNfJj7jxCgUTgpM+LpN JPew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=97W1Gkn1g32ZcQhRSHWTxq1+IY4zi24DH9VPI7IU8Z0=; b=QY3cN3K9otweDlvGnQoGkB1aa7+7p0yvAf8kKbZTPgeIJnFottrkn+QbgoYNZH1/Mh ibOK1Mlc5w/MtKNTsyhYBMj9uXTUVS2UzY3mugmuP1RtxinXP7iySL0Irqu9uB+g7OZy f8OPH/+iN8kS3JqQJ4L03guF8F2M3K0D15yFS0zhALIqnLvut2LFDwStg0dEzNJSDg19 P1PDInUQKD4h50hEMD+0/ZPJdJvV1CSSJd1tQqt5/VKNCqy983affQrHrTu8Xkv/wOL+ P9HHJtdAV+DTULj3XCW28wEe2mwltTkiDxahNxj+eyazgw72cDR6OqI0W/ap0NoQUmd1 36kg== X-Gm-Message-State: AOAM531yfRrXOChAUUJY1iFZzJ2AB53uTd3bhRU6gX0xoMbR5B8pi6Al 5JTzApfnYlquZ4clT87EIm6aCuaAWNY= X-Google-Smtp-Source: ABdhPJxMG9azh5LqJqMOSxuWXp6Cn65fLrQCV3QT+DJc7N+C4K17iTGl/FR//L22ISVKgX9W6th06w== X-Received: by 2002:a05:6830:1184:: with SMTP id u4mr25603314otq.55.1630437231334; Tue, 31 Aug 2021 12:13:51 -0700 (PDT) Received: from nuclearis3.gtech (c-98-195-139-126.hsd1.tx.comcast.net. [98.195.139.126]) by smtp.gmail.com with ESMTPSA id k23sm3840154ood.12.2021.08.31.12.13.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 31 Aug 2021 12:13:50 -0700 (PDT) Subject: Re: [PATCH 07/10] stm32mp1: spl: Configure MAC address when booting OP-TEE To: Patrick DELAUNAY , u-boot@lists.denx.de Cc: marex@denx.de, Patrice CHOTARD , Alexandre TORGUE , Christophe ROULLIER References: <20210826214209.254461-1-mr.nuke.me@gmail.com> <20210826214209.254461-8-mr.nuke.me@gmail.com> From: "Alex G." Message-ID: <2854b823-833a-c11c-249d-05cc7a7425ea@gmail.com> Date: Tue, 31 Aug 2021 14:13:49 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US 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 On 8/31/21 12:10 PM, Patrick DELAUNAY wrote: > Hi, > > > On 8/26/21 11:42 PM, Alexandru Gagniuc wrote: >> 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. >> >> 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(); >>   } > > > I think that all this part is not required for falcon mode: > > let the Linux driver fallback to nvmem access to read the MAC address in > OTP when the DT is not updated by boot loader > > remove also the patch 06/10 and 04/40 > > PS: it is already working in OpenSTLinux based on the device tree > modification for your board > > &bsec{ >             ethernet_mac_address: mac@e4 { >             reg = <0xe4 0x6>; > }; > > ðernet0 { >     nvmem-cells = <ðernet_mac_address>; >     nvmem-cell-names = "mac-address"; > }; I was looking at this, following Sean's suggestion from last week. The linux BSEC driver backends on stm32_bsec_smc(). This requires a corresponding secure-world callout. which is not currently implemented for SPL. We'd just get "Can't read data57 (-5)" error from linux, and a random MAC address. Is this change as proposed ideal? Probably not. It works with SPL and the current LTS linux (v5.10), and is likely the least intensive solution in terms of lines of code. Alex > PS: this part is not yet upstreamed in Linux That's not problematic. I can accommodate devicetree changes by using overlays in the FIT image. This flexibility is also a huge reason why I've chosen to go with FIT versus other image formats.