From: Alexandru Gagniuc <mr.nuke.me@gmail.com>
To: u-boot@lists.denx.de, uboot-stm32@st-md-mailman.stormreply.com,
patrick.delaunay@foss.st.com
Cc: Alexandru Gagniuc <mr.nuke.me@gmail.com>,
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 [thread overview]
Message-ID: <20210907235933.2798330-9-mr.nuke.me@gmail.com> (raw)
In-Reply-To: <20210907235933.2798330-1-mr.nuke.me@gmail.com>
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 <mr.nuke.me@gmail.com>
---
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 <cpu_func.h>
#include <debug_uart.h>
#include <env.h>
+#include <fdt_support.h>
#include <init.h>
#include <log.h>
#include <lmb.h>
@@ -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
next prev parent reply other threads:[~2021-09-08 0:01 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-07 23:59 [PATCH v2 00/11] stm32mp1: Support falcon mode with OP-TEE payloads Alexandru Gagniuc
2021-09-07 23:59 ` [PATCH v2 01/11] spl: Move SYS_MMCSD_RAW_MODE_KERNEL_SECTOR to Kconfig Alexandru Gagniuc
2021-10-04 13:26 ` [Uboot-stm32] " Patrick DELAUNAY
2021-09-07 23:59 ` [PATCH v2 02/11] stm32mp1: Add support for baudrates higher than 115200 Alexandru Gagniuc
2021-09-07 23:59 ` [PATCH v2 03/11] stm32mp1: Add support for falcon mode boot from SD card Alexandru Gagniuc
2021-10-04 14:57 ` [Uboot-stm32] " Patrick DELAUNAY
2021-10-07 19:09 ` Alex G.
2021-09-07 23:59 ` [PATCH v2 04/11] board: stm32mp1: Implement board_fit_config_name_match() for SPL Alexandru Gagniuc
2021-09-07 23:59 ` [PATCH v2 05/11] fdt_support: Implement fdt_ethernet_set_macaddr() Alexandru Gagniuc
2021-09-07 23:59 ` [PATCH v2 06/11] arm: stm32mp: bsec: Update OTP shadow registers in SPL Alexandru Gagniuc
2021-09-07 23:59 ` [PATCH v2 07/11] arm: stm32mp: Factor out reading MAC address from OTP Alexandru Gagniuc
2021-09-07 23:59 ` Alexandru Gagniuc [this message]
2021-09-07 23:59 ` [PATCH v2 09/11] lib: Makefile: Make optee library available in SPL Alexandru Gagniuc
2021-09-07 23:59 ` [PATCH v2 10/11] ARM: dts: stm32mp: Add OP-TEE "/firmware" node to SPL dtb Alexandru Gagniuc
2021-09-07 23:59 ` [PATCH v2 11/11] stm32mp1: spl: Copy optee nodes to target FDT for OP-TEE payloads Alexandru Gagniuc
2021-10-04 15:04 ` [PATCH v2 00/11] stm32mp1: Support falcon mode with " Patrick DELAUNAY
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210907235933.2798330-9-mr.nuke.me@gmail.com \
--to=mr.nuke.me@gmail.com \
--cc=etienne.carriere@linaro.org \
--cc=patrice.chotard@foss.st.com \
--cc=patrick.delaunay@foss.st.com \
--cc=u-boot@lists.denx.de \
--cc=uboot-stm32@st-md-mailman.stormreply.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox