[PATCH 00/12] stm32: add bsec and OTP support to stm32mp25

Add BSEC support to STM32MP25 SoC family with SoC information: - SERIAL number with UUID (BSEC_OTP_DATA5) - RPN = Device part number (BSEC_OTP_DATA9) - PKG = package data register (Bits 2:0 of BSEC_OTP_DATA122)
and with board information for STMicroelectronics boards - BOARD identifier: OTP246 - MAC address: OTP247 and after
Patrice Chotard (1): stm32mp: add setup_serial_number for stm32mp25
Patrick Delaunay (10): arm64: dts: st: add bsec support to stm32mp25 stm32mp: bsec: add driver data stm32mp: bsec: add support of stm32mp25 configs: stm32mp25: add support of fuse command stm32mp: add soc.c file smt32mp: add setup_mac_address for stm32mp25 stm32mp: stm32prog: add support of stm32mp25 stm32mp: activate the command stboard for stm32mp25 boards board: st: stm32mp2: add checkboard board: st: stm32mp2: display the board identification
Yann Gautier (1): arm: stm32mp: add Rev.B support for STM32MP25
arch/arm/dts/stm32mp25-u-boot.dtsi | 4 + arch/arm/dts/stm32mp251.dtsi | 16 +++ arch/arm/mach-stm32mp/Makefile | 1 + arch/arm/mach-stm32mp/bsec.c | 45 +++++-- .../mach-stm32mp/cmd_stm32prog/stm32prog.h | 10 +- arch/arm/mach-stm32mp/include/mach/stm32.h | 4 +- .../arm/mach-stm32mp/include/mach/sys_proto.h | 1 + arch/arm/mach-stm32mp/soc.c | 118 ++++++++++++++++++ arch/arm/mach-stm32mp/stm32mp1/cpu.c | 96 +------------- arch/arm/mach-stm32mp/stm32mp2/cpu.c | 14 +-- arch/arm/mach-stm32mp/stm32mp2/stm32mp25x.c | 3 + board/st/common/Kconfig | 2 +- board/st/common/cmd_stboard.c | 2 + board/st/stm32mp2/stm32mp2.c | 37 ++++++ configs/stm32mp25_defconfig | 1 + 15 files changed, 237 insertions(+), 117 deletions(-) create mode 100644 arch/arm/mach-stm32mp/soc.c

Add BSEC support to STM32MP25 SoC family with SoC information: - RPN = Device part number (BSEC_OTP_DATA9) - PKG = package data register (Bits 2:0 of BSEC_OTP_DATA122)
Signed-off-by: Patrick Delaunay patrick.delaunay@foss.st.com Signed-off-by: Alexandre Torgue alexandre.torgue@foss.st.com ---
arch/arm/dts/stm32mp25-u-boot.dtsi | 4 ++++ arch/arm/dts/stm32mp251.dtsi | 16 ++++++++++++++++ 2 files changed, 20 insertions(+)
diff --git a/arch/arm/dts/stm32mp25-u-boot.dtsi b/arch/arm/dts/stm32mp25-u-boot.dtsi index f4f26add2a41..0c8e95b34163 100644 --- a/arch/arm/dts/stm32mp25-u-boot.dtsi +++ b/arch/arm/dts/stm32mp25-u-boot.dtsi @@ -37,6 +37,10 @@ }; };
+&bsec { + bootph-all; +}; + &gpioa { bootph-all; }; diff --git a/arch/arm/dts/stm32mp251.dtsi b/arch/arm/dts/stm32mp251.dtsi index cf2f28dc1582..44eb664fb510 100644 --- a/arch/arm/dts/stm32mp251.dtsi +++ b/arch/arm/dts/stm32mp251.dtsi @@ -127,6 +127,22 @@ }; };
+ bsec: efuse@44000000 { + compatible = "st,stm32mp25-bsec"; + reg = <0x44000000 0x1000>; + #address-cells = <1>; + #size-cells = <1>; + + part_number_otp@24 { + reg = <0x24 0x4>; + }; + + package_otp@1e8 { + reg = <0x1e8 0x1>; + bits = <0 3>; + }; + }; + syscfg: syscon@44230000 { compatible = "st,stm32mp25-syscfg", "syscon"; reg = <0x44230000 0x10000>;

On 1/15/24 13:46, Patrick Delaunay wrote:
Add BSEC support to STM32MP25 SoC family with SoC information:
- RPN = Device part number (BSEC_OTP_DATA9)
- PKG = package data register (Bits 2:0 of BSEC_OTP_DATA122)
Signed-off-by: Patrick Delaunay patrick.delaunay@foss.st.com Signed-off-by: Alexandre Torgue alexandre.torgue@foss.st.com
arch/arm/dts/stm32mp25-u-boot.dtsi | 4 ++++ arch/arm/dts/stm32mp251.dtsi | 16 ++++++++++++++++ 2 files changed, 20 insertions(+)
diff --git a/arch/arm/dts/stm32mp25-u-boot.dtsi b/arch/arm/dts/stm32mp25-u-boot.dtsi index f4f26add2a41..0c8e95b34163 100644 --- a/arch/arm/dts/stm32mp25-u-boot.dtsi +++ b/arch/arm/dts/stm32mp25-u-boot.dtsi @@ -37,6 +37,10 @@ }; };
+&bsec {
- bootph-all;
+};
&gpioa { bootph-all; }; diff --git a/arch/arm/dts/stm32mp251.dtsi b/arch/arm/dts/stm32mp251.dtsi index cf2f28dc1582..44eb664fb510 100644 --- a/arch/arm/dts/stm32mp251.dtsi +++ b/arch/arm/dts/stm32mp251.dtsi @@ -127,6 +127,22 @@ }; };
bsec: efuse@44000000 {
compatible = "st,stm32mp25-bsec";
reg = <0x44000000 0x1000>;
#address-cells = <1>;
#size-cells = <1>;
part_number_otp@24 {
reg = <0x24 0x4>;
};
package_otp@1e8 {
reg = <0x1e8 0x1>;
bits = <0 3>;
};
};
- syscfg: syscon@44230000 { compatible = "st,stm32mp25-syscfg", "syscon"; reg = <0x44230000 0x10000>;
Reviewed-by: Patrice Chotard patrice.chotard@foss.st.com
Thanks Patrice

From: Yann Gautier yann.gautier@foss.st.com
Add chip revision B support for STM32MP25, for displaying it in trace.
Signed-off-by: Yann Gautier yann.gautier@foss.st.com Signed-off-by: Patrick Delaunay patrick.delaunay@foss.st.com ---
arch/arm/mach-stm32mp/stm32mp2/stm32mp25x.c | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/arch/arm/mach-stm32mp/stm32mp2/stm32mp25x.c b/arch/arm/mach-stm32mp/stm32mp2/stm32mp25x.c index 4b2f70af9cc6..7f896a0d65d2 100644 --- a/arch/arm/mach-stm32mp/stm32mp2/stm32mp25x.c +++ b/arch/arm/mach-stm32mp/stm32mp2/stm32mp25x.c @@ -167,6 +167,9 @@ void get_soc_name(char name[SOC_NAME_SIZE]) case CPU_REV1: cpu_r = "A"; break; + case CPU_REV2: + cpu_r = "B"; + break; default: break; }

On 1/15/24 13:46, Patrick Delaunay wrote:
From: Yann Gautier yann.gautier@foss.st.com
Add chip revision B support for STM32MP25, for displaying it in trace.
Signed-off-by: Yann Gautier yann.gautier@foss.st.com Signed-off-by: Patrick Delaunay patrick.delaunay@foss.st.com
arch/arm/mach-stm32mp/stm32mp2/stm32mp25x.c | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/arch/arm/mach-stm32mp/stm32mp2/stm32mp25x.c b/arch/arm/mach-stm32mp/stm32mp2/stm32mp25x.c index 4b2f70af9cc6..7f896a0d65d2 100644 --- a/arch/arm/mach-stm32mp/stm32mp2/stm32mp25x.c +++ b/arch/arm/mach-stm32mp/stm32mp2/stm32mp25x.c @@ -167,6 +167,9 @@ void get_soc_name(char name[SOC_NAME_SIZE]) case CPU_REV1: cpu_r = "A"; break;
case CPU_REV2:
cpu_r = "B";
default: break; }break;
Reviewed-by: Patrice Chotard patrice.chotard@foss.st.com
Thanks Patrice

Add driver data in BSEC driver to test presence of OP-TEE TA, mandatory for STM32MP13 family and prepare the support of new device with more OTP than 95.
Signed-off-by: Patrick Delaunay patrick.delaunay@foss.st.com ---
arch/arm/mach-stm32mp/bsec.c | 38 ++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-)
diff --git a/arch/arm/mach-stm32mp/bsec.c b/arch/arm/mach-stm32mp/bsec.c index 28a8280b2804..705c994d9307 100644 --- a/arch/arm/mach-stm32mp/bsec.c +++ b/arch/arm/mach-stm32mp/bsec.c @@ -20,7 +20,6 @@ #include <linux/iopoll.h> #include <linux/printk.h>
-#define BSEC_OTP_MAX_VALUE 95 #define BSEC_OTP_UPPER_START 32 #define BSEC_TIMEOUT_US 10000
@@ -400,6 +399,11 @@ struct stm32mp_bsec_priv { struct udevice *tee; };
+struct stm32mp_bsec_drvdata { + int size; + bool ta; +}; + static int stm32mp_bsec_read_otp(struct udevice *dev, u32 *val, u32 otp) { struct stm32mp_bsec_plat *plat; @@ -609,6 +613,7 @@ static int stm32mp_bsec_read(struct udevice *dev, int offset, void *buf, int size) { struct stm32mp_bsec_priv *priv = dev_get_priv(dev); + struct stm32mp_bsec_drvdata *data = (struct stm32mp_bsec_drvdata *)dev_get_driver_data(dev); int ret; int i; bool shadow = true, lock = false; @@ -642,7 +647,7 @@ static int stm32mp_bsec_read(struct udevice *dev, int offset,
otp = offs / sizeof(u32);
- for (i = otp; i < (otp + nb_otp) && i <= BSEC_OTP_MAX_VALUE; i++) { + for (i = otp; i < (otp + nb_otp) && i < data->size; i++) { u32 *addr = &((u32 *)buf)[i - otp];
if (lock) @@ -665,6 +670,7 @@ static int stm32mp_bsec_write(struct udevice *dev, int offset, const void *buf, int size) { struct stm32mp_bsec_priv *priv = dev_get_priv(dev); + struct stm32mp_bsec_drvdata *data = (struct stm32mp_bsec_drvdata *)dev_get_driver_data(dev); int ret = 0; int i; bool shadow = true, lock = false; @@ -698,7 +704,7 @@ static int stm32mp_bsec_write(struct udevice *dev, int offset,
otp = offs / sizeof(u32);
- for (i = otp; i < otp + nb_otp && i <= BSEC_OTP_MAX_VALUE; i++) { + for (i = otp; i < otp + nb_otp && i < data->size; i++) { u32 *val = &((u32 *)buf)[i - otp];
if (lock) @@ -732,6 +738,7 @@ static int stm32mp_bsec_of_to_plat(struct udevice *dev)
static int stm32mp_bsec_probe(struct udevice *dev) { + struct stm32mp_bsec_drvdata *data = (struct stm32mp_bsec_drvdata *)dev_get_driver_data(dev); int otp; struct stm32mp_bsec_plat *plat; struct clk_bulk clk_bulk; @@ -745,16 +752,22 @@ static int stm32mp_bsec_probe(struct udevice *dev) }
if (IS_ENABLED(CONFIG_OPTEE)) - bsec_optee_open(dev); + ret = bsec_optee_open(dev); + else + ret = -ENOTSUPP; + /* failed if OP-TEE TA is required */ + if (data->ta && !ret) + return ret;
/* * update unlocked shadow for OTP cleared by the rom code * only executed in SPL, it is done in TF-A for TFABOOT */ - if (IS_ENABLED(CONFIG_SPL_BUILD)) { + if (IS_ENABLED(CONFIG_SPL_BUILD) && !data->ta) { plat = dev_get_plat(dev);
- for (otp = 57; otp <= BSEC_OTP_MAX_VALUE; otp++) + /* here 57 is the value for STM32MP15x ROM code, only MPU with SPL support*/ + for (otp = 57; otp < data->size; otp++) if (!bsec_read_SR_lock(plat->base, otp)) bsec_shadow_register(dev, plat->base, otp); } @@ -762,9 +775,18 @@ static int stm32mp_bsec_probe(struct udevice *dev) return 0; }
+static const struct stm32mp_bsec_drvdata stm32mp13_data = { + .size = 96, + .ta = true, +}; + +static const struct stm32mp_bsec_drvdata stm32mp15_data = { + .size = 96, + .ta = false, +}; static const struct udevice_id stm32mp_bsec_ids[] = { - { .compatible = "st,stm32mp13-bsec" }, - { .compatible = "st,stm32mp15-bsec" }, + { .compatible = "st,stm32mp13-bsec", .data = (ulong)&stm32mp13_data}, + { .compatible = "st,stm32mp15-bsec", .data = (ulong)&stm32mp15_data}, {} };

On 1/15/24 13:46, Patrick Delaunay wrote:
Add driver data in BSEC driver to test presence of OP-TEE TA, mandatory for STM32MP13 family and prepare the support of new device with more OTP than 95.
Signed-off-by: Patrick Delaunay patrick.delaunay@foss.st.com
arch/arm/mach-stm32mp/bsec.c | 38 ++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-)
diff --git a/arch/arm/mach-stm32mp/bsec.c b/arch/arm/mach-stm32mp/bsec.c index 28a8280b2804..705c994d9307 100644 --- a/arch/arm/mach-stm32mp/bsec.c +++ b/arch/arm/mach-stm32mp/bsec.c @@ -20,7 +20,6 @@ #include <linux/iopoll.h> #include <linux/printk.h>
-#define BSEC_OTP_MAX_VALUE 95 #define BSEC_OTP_UPPER_START 32 #define BSEC_TIMEOUT_US 10000
@@ -400,6 +399,11 @@ struct stm32mp_bsec_priv { struct udevice *tee; };
+struct stm32mp_bsec_drvdata {
- int size;
- bool ta;
+};
static int stm32mp_bsec_read_otp(struct udevice *dev, u32 *val, u32 otp) { struct stm32mp_bsec_plat *plat; @@ -609,6 +613,7 @@ static int stm32mp_bsec_read(struct udevice *dev, int offset, void *buf, int size) { struct stm32mp_bsec_priv *priv = dev_get_priv(dev);
- struct stm32mp_bsec_drvdata *data = (struct stm32mp_bsec_drvdata *)dev_get_driver_data(dev); int ret; int i; bool shadow = true, lock = false;
@@ -642,7 +647,7 @@ static int stm32mp_bsec_read(struct udevice *dev, int offset,
otp = offs / sizeof(u32);
- for (i = otp; i < (otp + nb_otp) && i <= BSEC_OTP_MAX_VALUE; i++) {
for (i = otp; i < (otp + nb_otp) && i < data->size; i++) { u32 *addr = &((u32 *)buf)[i - otp];
if (lock)
@@ -665,6 +670,7 @@ static int stm32mp_bsec_write(struct udevice *dev, int offset, const void *buf, int size) { struct stm32mp_bsec_priv *priv = dev_get_priv(dev);
- struct stm32mp_bsec_drvdata *data = (struct stm32mp_bsec_drvdata *)dev_get_driver_data(dev); int ret = 0; int i; bool shadow = true, lock = false;
@@ -698,7 +704,7 @@ static int stm32mp_bsec_write(struct udevice *dev, int offset,
otp = offs / sizeof(u32);
- for (i = otp; i < otp + nb_otp && i <= BSEC_OTP_MAX_VALUE; i++) {
for (i = otp; i < otp + nb_otp && i < data->size; i++) { u32 *val = &((u32 *)buf)[i - otp];
if (lock)
@@ -732,6 +738,7 @@ static int stm32mp_bsec_of_to_plat(struct udevice *dev)
static int stm32mp_bsec_probe(struct udevice *dev) {
- struct stm32mp_bsec_drvdata *data = (struct stm32mp_bsec_drvdata *)dev_get_driver_data(dev); int otp; struct stm32mp_bsec_plat *plat; struct clk_bulk clk_bulk;
@@ -745,16 +752,22 @@ static int stm32mp_bsec_probe(struct udevice *dev) }
if (IS_ENABLED(CONFIG_OPTEE))
bsec_optee_open(dev);
ret = bsec_optee_open(dev);
else
ret = -ENOTSUPP;
/* failed if OP-TEE TA is required */
if (data->ta && !ret)
return ret;
/*
- update unlocked shadow for OTP cleared by the rom code
- only executed in SPL, it is done in TF-A for TFABOOT
*/
- if (IS_ENABLED(CONFIG_SPL_BUILD)) {
- if (IS_ENABLED(CONFIG_SPL_BUILD) && !data->ta) { plat = dev_get_plat(dev);
for (otp = 57; otp <= BSEC_OTP_MAX_VALUE; otp++)
/* here 57 is the value for STM32MP15x ROM code, only MPU with SPL support*/
}for (otp = 57; otp < data->size; otp++) if (!bsec_read_SR_lock(plat->base, otp)) bsec_shadow_register(dev, plat->base, otp);
@@ -762,9 +775,18 @@ static int stm32mp_bsec_probe(struct udevice *dev) return 0; }
+static const struct stm32mp_bsec_drvdata stm32mp13_data = {
- .size = 96,
- .ta = true,
+};
+static const struct stm32mp_bsec_drvdata stm32mp15_data = {
- .size = 96,
- .ta = false,
+}; static const struct udevice_id stm32mp_bsec_ids[] = {
- { .compatible = "st,stm32mp13-bsec" },
- { .compatible = "st,stm32mp15-bsec" },
- { .compatible = "st,stm32mp13-bsec", .data = (ulong)&stm32mp13_data},
- { .compatible = "st,stm32mp15-bsec", .data = (ulong)&stm32mp15_data}, {}
};
Reviewed-by: Patrice Chotard patrice.chotard@foss.st.com
Thanks Patrice

Add support of BSEC for STM32MP25x family to access OTP.
Signed-off-by: Patrick Delaunay patrick.delaunay@foss.st.com ---
arch/arm/mach-stm32mp/bsec.c | 7 +++++++ arch/arm/mach-stm32mp/include/mach/stm32.h | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/arch/arm/mach-stm32mp/bsec.c b/arch/arm/mach-stm32mp/bsec.c index 705c994d9307..5b869017ec1a 100644 --- a/arch/arm/mach-stm32mp/bsec.c +++ b/arch/arm/mach-stm32mp/bsec.c @@ -784,9 +784,16 @@ static const struct stm32mp_bsec_drvdata stm32mp15_data = { .size = 96, .ta = false, }; + +static const struct stm32mp_bsec_drvdata stm32mp25_data = { + .size = 368, /* 384 but no access to HWKEY and STM32PRVKEY */ + .ta = true, +}; + static const struct udevice_id stm32mp_bsec_ids[] = { { .compatible = "st,stm32mp13-bsec", .data = (ulong)&stm32mp13_data}, { .compatible = "st,stm32mp15-bsec", .data = (ulong)&stm32mp15_data}, + { .compatible = "st,stm32mp25-bsec", .data = (ulong)&stm32mp25_data}, {} };
diff --git a/arch/arm/mach-stm32mp/include/mach/stm32.h b/arch/arm/mach-stm32mp/include/mach/stm32.h index 46d469881b32..45c929aa605d 100644 --- a/arch/arm/mach-stm32mp/include/mach/stm32.h +++ b/arch/arm/mach-stm32mp/include/mach/stm32.h @@ -197,7 +197,8 @@ enum forced_boot_mode { #ifdef CONFIG_STM32MP25X #define BSEC_OTP_SERIAL 5 #define BSEC_OTP_RPN 9 -#define BSEC_OTP_PKG 246 +#define BSEC_OTP_PKG 122 +#define BSEC_OTP_MAC 247 #endif
#ifndef __ASSEMBLY__

On 1/15/24 13:46, Patrick Delaunay wrote:
Add support of BSEC for STM32MP25x family to access OTP.
Signed-off-by: Patrick Delaunay patrick.delaunay@foss.st.com
arch/arm/mach-stm32mp/bsec.c | 7 +++++++ arch/arm/mach-stm32mp/include/mach/stm32.h | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/arch/arm/mach-stm32mp/bsec.c b/arch/arm/mach-stm32mp/bsec.c index 705c994d9307..5b869017ec1a 100644 --- a/arch/arm/mach-stm32mp/bsec.c +++ b/arch/arm/mach-stm32mp/bsec.c @@ -784,9 +784,16 @@ static const struct stm32mp_bsec_drvdata stm32mp15_data = { .size = 96, .ta = false, };
+static const struct stm32mp_bsec_drvdata stm32mp25_data = {
- .size = 368, /* 384 but no access to HWKEY and STM32PRVKEY */
- .ta = true,
+};
static const struct udevice_id stm32mp_bsec_ids[] = { { .compatible = "st,stm32mp13-bsec", .data = (ulong)&stm32mp13_data}, { .compatible = "st,stm32mp15-bsec", .data = (ulong)&stm32mp15_data},
- { .compatible = "st,stm32mp25-bsec", .data = (ulong)&stm32mp25_data}, {}
};
diff --git a/arch/arm/mach-stm32mp/include/mach/stm32.h b/arch/arm/mach-stm32mp/include/mach/stm32.h index 46d469881b32..45c929aa605d 100644 --- a/arch/arm/mach-stm32mp/include/mach/stm32.h +++ b/arch/arm/mach-stm32mp/include/mach/stm32.h @@ -197,7 +197,8 @@ enum forced_boot_mode { #ifdef CONFIG_STM32MP25X #define BSEC_OTP_SERIAL 5 #define BSEC_OTP_RPN 9 -#define BSEC_OTP_PKG 246 +#define BSEC_OTP_PKG 122 +#define BSEC_OTP_MAC 247 #endif
#ifndef __ASSEMBLY__
Reviewed-by: Patrice Chotard patrice.chotard@foss.st.com
Thanks Patrice

On Mon, Jan 15, 2024 at 1:47 PM Patrick Delaunay patrick.delaunay@foss.st.com wrote:
Add support of BSEC for STM32MP25x family to access OTP.
Signed-off-by: Patrick Delaunay patrick.delaunay@foss.st.com
arch/arm/mach-stm32mp/bsec.c | 7 +++++++ arch/arm/mach-stm32mp/include/mach/stm32.h | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/arch/arm/mach-stm32mp/bsec.c b/arch/arm/mach-stm32mp/bsec.c index 705c994d9307..5b869017ec1a 100644 --- a/arch/arm/mach-stm32mp/bsec.c +++ b/arch/arm/mach-stm32mp/bsec.c @@ -784,9 +784,16 @@ static const struct stm32mp_bsec_drvdata stm32mp15_data = { .size = 96, .ta = false, };
+static const struct stm32mp_bsec_drvdata stm32mp25_data = {
.size = 368, /* 384 but no access to HWKEY and STM32PRVKEY */
.ta = true,
+};
static const struct udevice_id stm32mp_bsec_ids[] = { { .compatible = "st,stm32mp13-bsec", .data = (ulong)&stm32mp13_data}, { .compatible = "st,stm32mp15-bsec", .data = (ulong)&stm32mp15_data},
{ .compatible = "st,stm32mp25-bsec", .data = (ulong)&stm32mp25_data}, {}
};
diff --git a/arch/arm/mach-stm32mp/include/mach/stm32.h b/arch/arm/mach-stm32mp/include/mach/stm32.h index 46d469881b32..45c929aa605d 100644 --- a/arch/arm/mach-stm32mp/include/mach/stm32.h +++ b/arch/arm/mach-stm32mp/include/mach/stm32.h @@ -197,7 +197,8 @@ enum forced_boot_mode { #ifdef CONFIG_STM32MP25X #define BSEC_OTP_SERIAL 5 #define BSEC_OTP_RPN 9 -#define BSEC_OTP_PKG 246 +#define BSEC_OTP_PKG 122 +#define BSEC_OTP_MAC 247 #endif
#ifndef __ASSEMBLY__
2.25.1
Reviewed-by: Igor Opaniuk igor.opaniuk@foundries.io

Add support of the command fuse with CONFIG_CMD_FUSE to allow access on OTP with command line.
Signed-off-by: Patrick Delaunay patrick.delaunay@foss.st.com ---
configs/stm32mp25_defconfig | 1 + 1 file changed, 1 insertion(+)
diff --git a/configs/stm32mp25_defconfig b/configs/stm32mp25_defconfig index 75f27c98b441..9fbd7eb15755 100644 --- a/configs/stm32mp25_defconfig +++ b/configs/stm32mp25_defconfig @@ -21,6 +21,7 @@ CONFIG_CMD_ADTIMG=y CONFIG_CMD_MEMINFO=y CONFIG_CMD_MEMTEST=y CONFIG_CMD_CLK=y +CONFIG_CMD_FUSE=y CONFIG_CMD_GPIO=y # CONFIG_CMD_LOADB is not set CONFIG_CMD_CACHE=y

On 1/15/24 13:46, Patrick Delaunay wrote:
Add support of the command fuse with CONFIG_CMD_FUSE to allow access on OTP with command line.
Signed-off-by: Patrick Delaunay patrick.delaunay@foss.st.com
configs/stm32mp25_defconfig | 1 + 1 file changed, 1 insertion(+)
diff --git a/configs/stm32mp25_defconfig b/configs/stm32mp25_defconfig index 75f27c98b441..9fbd7eb15755 100644 --- a/configs/stm32mp25_defconfig +++ b/configs/stm32mp25_defconfig @@ -21,6 +21,7 @@ CONFIG_CMD_ADTIMG=y CONFIG_CMD_MEMINFO=y CONFIG_CMD_MEMTEST=y CONFIG_CMD_CLK=y +CONFIG_CMD_FUSE=y CONFIG_CMD_GPIO=y # CONFIG_CMD_LOADB is not set CONFIG_CMD_CACHE=y
Reviewed-by: Patrice Chotard patrice.chotard@foss.st.com
Thanks Patrice

Add a new file soc.c for common functions between stm32mp1 and stm32mp2 family and move print_cpuinfo() in this new file.
Signed-off-by: Patrick Delaunay patrick.delaunay@foss.st.com ---
arch/arm/mach-stm32mp/Makefile | 1 + arch/arm/mach-stm32mp/soc.c | 17 +++++++++++++++++ arch/arm/mach-stm32mp/stm32mp1/cpu.c | 11 ----------- arch/arm/mach-stm32mp/stm32mp2/cpu.c | 11 ----------- 4 files changed, 18 insertions(+), 22 deletions(-) create mode 100644 arch/arm/mach-stm32mp/soc.c
diff --git a/arch/arm/mach-stm32mp/Makefile b/arch/arm/mach-stm32mp/Makefile index 00dc25bb275c..fdcbbf91dfd5 100644 --- a/arch/arm/mach-stm32mp/Makefile +++ b/arch/arm/mach-stm32mp/Makefile @@ -6,6 +6,7 @@ obj-y += dram_init.o obj-y += syscon.o obj-y += bsec.o +obj-y += soc.o
obj-$(CONFIG_STM32MP15x) += stm32mp1/ obj-$(CONFIG_STM32MP13x) += stm32mp1/ diff --git a/arch/arm/mach-stm32mp/soc.c b/arch/arm/mach-stm32mp/soc.c new file mode 100644 index 000000000000..8d5fa474ccaf --- /dev/null +++ b/arch/arm/mach-stm32mp/soc.c @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR BSD-3-Clause +/* + * Copyright (C) 2024, STMicroelectronics - All Rights Reserved + */ + +#include <asm/arch/sys_proto.h> + +/* used when CONFIG_DISPLAY_CPUINFO is activated */ +int print_cpuinfo(void) +{ + char name[SOC_NAME_SIZE]; + + get_soc_name(name); + printf("CPU: %s\n", name); + + return 0; +} diff --git a/arch/arm/mach-stm32mp/stm32mp1/cpu.c b/arch/arm/mach-stm32mp/stm32mp1/cpu.c index 55574fd4bebf..00fea7929b2f 100644 --- a/arch/arm/mach-stm32mp/stm32mp1/cpu.c +++ b/arch/arm/mach-stm32mp/stm32mp1/cpu.c @@ -158,17 +158,6 @@ void enable_caches(void) dcache_enable(); }
-/* used when CONFIG_DISPLAY_CPUINFO is activated */ -int print_cpuinfo(void) -{ - char name[SOC_NAME_SIZE]; - - get_soc_name(name); - printf("CPU: %s\n", name); - - return 0; -} - static void setup_boot_mode(void) { const u32 serial_addr[] = { diff --git a/arch/arm/mach-stm32mp/stm32mp2/cpu.c b/arch/arm/mach-stm32mp/stm32mp2/cpu.c index f43d1aaf72cc..c0f6519e8d7c 100644 --- a/arch/arm/mach-stm32mp/stm32mp2/cpu.c +++ b/arch/arm/mach-stm32mp/stm32mp2/cpu.c @@ -67,17 +67,6 @@ void enable_caches(void) dcache_enable(); }
-/* used when CONFIG_DISPLAY_CPUINFO is activated */ -int print_cpuinfo(void) -{ - char name[SOC_NAME_SIZE]; - - get_soc_name(name); - printf("CPU: %s\n", name); - - return 0; -} - int arch_misc_init(void) { return 0;

On 1/15/24 13:46, Patrick Delaunay wrote:
Add a new file soc.c for common functions between stm32mp1 and stm32mp2 family and move print_cpuinfo() in this new file.
Signed-off-by: Patrick Delaunay patrick.delaunay@foss.st.com
arch/arm/mach-stm32mp/Makefile | 1 + arch/arm/mach-stm32mp/soc.c | 17 +++++++++++++++++ arch/arm/mach-stm32mp/stm32mp1/cpu.c | 11 ----------- arch/arm/mach-stm32mp/stm32mp2/cpu.c | 11 ----------- 4 files changed, 18 insertions(+), 22 deletions(-) create mode 100644 arch/arm/mach-stm32mp/soc.c
diff --git a/arch/arm/mach-stm32mp/Makefile b/arch/arm/mach-stm32mp/Makefile index 00dc25bb275c..fdcbbf91dfd5 100644 --- a/arch/arm/mach-stm32mp/Makefile +++ b/arch/arm/mach-stm32mp/Makefile @@ -6,6 +6,7 @@ obj-y += dram_init.o obj-y += syscon.o obj-y += bsec.o +obj-y += soc.o
obj-$(CONFIG_STM32MP15x) += stm32mp1/ obj-$(CONFIG_STM32MP13x) += stm32mp1/ diff --git a/arch/arm/mach-stm32mp/soc.c b/arch/arm/mach-stm32mp/soc.c new file mode 100644 index 000000000000..8d5fa474ccaf --- /dev/null +++ b/arch/arm/mach-stm32mp/soc.c @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR BSD-3-Clause +/*
- Copyright (C) 2024, STMicroelectronics - All Rights Reserved
- */
+#include <asm/arch/sys_proto.h>
+/* used when CONFIG_DISPLAY_CPUINFO is activated */ +int print_cpuinfo(void) +{
- char name[SOC_NAME_SIZE];
- get_soc_name(name);
- printf("CPU: %s\n", name);
- return 0;
+} diff --git a/arch/arm/mach-stm32mp/stm32mp1/cpu.c b/arch/arm/mach-stm32mp/stm32mp1/cpu.c index 55574fd4bebf..00fea7929b2f 100644 --- a/arch/arm/mach-stm32mp/stm32mp1/cpu.c +++ b/arch/arm/mach-stm32mp/stm32mp1/cpu.c @@ -158,17 +158,6 @@ void enable_caches(void) dcache_enable(); }
-/* used when CONFIG_DISPLAY_CPUINFO is activated */ -int print_cpuinfo(void) -{
- char name[SOC_NAME_SIZE];
- get_soc_name(name);
- printf("CPU: %s\n", name);
- return 0;
-}
static void setup_boot_mode(void) { const u32 serial_addr[] = { diff --git a/arch/arm/mach-stm32mp/stm32mp2/cpu.c b/arch/arm/mach-stm32mp/stm32mp2/cpu.c index f43d1aaf72cc..c0f6519e8d7c 100644 --- a/arch/arm/mach-stm32mp/stm32mp2/cpu.c +++ b/arch/arm/mach-stm32mp/stm32mp2/cpu.c @@ -67,17 +67,6 @@ void enable_caches(void) dcache_enable(); }
-/* used when CONFIG_DISPLAY_CPUINFO is activated */ -int print_cpuinfo(void) -{
- char name[SOC_NAME_SIZE];
- get_soc_name(name);
- printf("CPU: %s\n", name);
- return 0;
-}
int arch_misc_init(void) { return 0;
Reviewed-by: Patrice Chotard patrice.chotard@foss.st.com
Thanks Patrice

From: Patrice Chotard patrice.chotard@foss.st.com
Add support of serial number for stm32mp25, gets from OTP with BSEC driver.
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com Signed-off-by: Patrick Delaunay patrick.delaunay@foss.st.com ---
.../arm/mach-stm32mp/include/mach/sys_proto.h | 1 + arch/arm/mach-stm32mp/soc.c | 31 +++++++++++++++++++ arch/arm/mach-stm32mp/stm32mp1/cpu.c | 27 ---------------- arch/arm/mach-stm32mp/stm32mp2/cpu.c | 2 ++ 4 files changed, 34 insertions(+), 27 deletions(-)
diff --git a/arch/arm/mach-stm32mp/include/mach/sys_proto.h b/arch/arm/mach-stm32mp/include/mach/sys_proto.h index 83388fdb7371..2a65efc0a50a 100644 --- a/arch/arm/mach-stm32mp/include/mach/sys_proto.h +++ b/arch/arm/mach-stm32mp/include/mach/sys_proto.h @@ -97,6 +97,7 @@ u32 get_bootauth(void);
int get_eth_nb(void); int setup_mac_address(void); +int setup_serial_number(void);
/* board power management : configure vddcore according OPP */ void board_vddcore_init(u32 voltage_mv); diff --git a/arch/arm/mach-stm32mp/soc.c b/arch/arm/mach-stm32mp/soc.c index 8d5fa474ccaf..ff70ebe97464 100644 --- a/arch/arm/mach-stm32mp/soc.c +++ b/arch/arm/mach-stm32mp/soc.c @@ -3,7 +3,11 @@ * Copyright (C) 2024, STMicroelectronics - All Rights Reserved */
+#include <env.h> +#include <misc.h> #include <asm/arch/sys_proto.h> +#include <dm/device.h> +#include <dm/uclass.h>
/* used when CONFIG_DISPLAY_CPUINFO is activated */ int print_cpuinfo(void) @@ -15,3 +19,30 @@ int print_cpuinfo(void)
return 0; } + +int setup_serial_number(void) +{ + char serial_string[25]; + u32 otp[3] = {0, 0, 0 }; + struct udevice *dev; + int ret; + + if (env_get("serial#")) + return 0; + + ret = uclass_get_device_by_driver(UCLASS_MISC, + DM_DRIVER_GET(stm32mp_bsec), + &dev); + if (ret) + return ret; + + ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_SERIAL), + otp, sizeof(otp)); + if (ret < 0) + return ret; + + sprintf(serial_string, "%08X%08X%08X", otp[0], otp[1], otp[2]); + env_set("serial#", serial_string); + + return 0; +} diff --git a/arch/arm/mach-stm32mp/stm32mp1/cpu.c b/arch/arm/mach-stm32mp/stm32mp1/cpu.c index 00fea7929b2f..f84cb26fa565 100644 --- a/arch/arm/mach-stm32mp/stm32mp1/cpu.c +++ b/arch/arm/mach-stm32mp/stm32mp1/cpu.c @@ -336,33 +336,6 @@ __weak int setup_mac_address(void) return 0; }
-static int setup_serial_number(void) -{ - char serial_string[25]; - u32 otp[3] = {0, 0, 0 }; - struct udevice *dev; - int ret; - - if (env_get("serial#")) - return 0; - - ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_DRIVER_GET(stm32mp_bsec), - &dev); - if (ret) - return ret; - - ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_SERIAL), - otp, sizeof(otp)); - if (ret < 0) - return ret; - - sprintf(serial_string, "%08X%08X%08X", otp[0], otp[1], otp[2]); - env_set("serial#", serial_string); - - return 0; -} - __weak void stm32mp_misc_init(void) { } diff --git a/arch/arm/mach-stm32mp/stm32mp2/cpu.c b/arch/arm/mach-stm32mp/stm32mp2/cpu.c index c0f6519e8d7c..301e365cf4f4 100644 --- a/arch/arm/mach-stm32mp/stm32mp2/cpu.c +++ b/arch/arm/mach-stm32mp/stm32mp2/cpu.c @@ -69,6 +69,8 @@ void enable_caches(void)
int arch_misc_init(void) { + setup_serial_number(); + return 0; }

On 1/15/24 13:46, Patrick Delaunay wrote:
From: Patrice Chotard patrice.chotard@foss.st.com
Add support of serial number for stm32mp25, gets from OTP with BSEC driver.
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com Signed-off-by: Patrick Delaunay patrick.delaunay@foss.st.com
.../arm/mach-stm32mp/include/mach/sys_proto.h | 1 + arch/arm/mach-stm32mp/soc.c | 31 +++++++++++++++++++ arch/arm/mach-stm32mp/stm32mp1/cpu.c | 27 ---------------- arch/arm/mach-stm32mp/stm32mp2/cpu.c | 2 ++ 4 files changed, 34 insertions(+), 27 deletions(-)
diff --git a/arch/arm/mach-stm32mp/include/mach/sys_proto.h b/arch/arm/mach-stm32mp/include/mach/sys_proto.h index 83388fdb7371..2a65efc0a50a 100644 --- a/arch/arm/mach-stm32mp/include/mach/sys_proto.h +++ b/arch/arm/mach-stm32mp/include/mach/sys_proto.h @@ -97,6 +97,7 @@ u32 get_bootauth(void);
int get_eth_nb(void); int setup_mac_address(void); +int setup_serial_number(void);
/* board power management : configure vddcore according OPP */ void board_vddcore_init(u32 voltage_mv); diff --git a/arch/arm/mach-stm32mp/soc.c b/arch/arm/mach-stm32mp/soc.c index 8d5fa474ccaf..ff70ebe97464 100644 --- a/arch/arm/mach-stm32mp/soc.c +++ b/arch/arm/mach-stm32mp/soc.c @@ -3,7 +3,11 @@
- Copyright (C) 2024, STMicroelectronics - All Rights Reserved
*/
+#include <env.h> +#include <misc.h> #include <asm/arch/sys_proto.h> +#include <dm/device.h> +#include <dm/uclass.h>
/* used when CONFIG_DISPLAY_CPUINFO is activated */ int print_cpuinfo(void) @@ -15,3 +19,30 @@ int print_cpuinfo(void)
return 0; }
+int setup_serial_number(void) +{
- char serial_string[25];
- u32 otp[3] = {0, 0, 0 };
- struct udevice *dev;
- int ret;
- if (env_get("serial#"))
return 0;
- ret = uclass_get_device_by_driver(UCLASS_MISC,
DM_DRIVER_GET(stm32mp_bsec),
&dev);
- if (ret)
return ret;
- ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_SERIAL),
otp, sizeof(otp));
- if (ret < 0)
return ret;
- sprintf(serial_string, "%08X%08X%08X", otp[0], otp[1], otp[2]);
- env_set("serial#", serial_string);
- return 0;
+} diff --git a/arch/arm/mach-stm32mp/stm32mp1/cpu.c b/arch/arm/mach-stm32mp/stm32mp1/cpu.c index 00fea7929b2f..f84cb26fa565 100644 --- a/arch/arm/mach-stm32mp/stm32mp1/cpu.c +++ b/arch/arm/mach-stm32mp/stm32mp1/cpu.c @@ -336,33 +336,6 @@ __weak int setup_mac_address(void) return 0; }
-static int setup_serial_number(void) -{
- char serial_string[25];
- u32 otp[3] = {0, 0, 0 };
- struct udevice *dev;
- int ret;
- if (env_get("serial#"))
return 0;
- ret = uclass_get_device_by_driver(UCLASS_MISC,
DM_DRIVER_GET(stm32mp_bsec),
&dev);
- if (ret)
return ret;
- ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_SERIAL),
otp, sizeof(otp));
- if (ret < 0)
return ret;
- sprintf(serial_string, "%08X%08X%08X", otp[0], otp[1], otp[2]);
- env_set("serial#", serial_string);
- return 0;
-}
__weak void stm32mp_misc_init(void) { } diff --git a/arch/arm/mach-stm32mp/stm32mp2/cpu.c b/arch/arm/mach-stm32mp/stm32mp2/cpu.c index c0f6519e8d7c..301e365cf4f4 100644 --- a/arch/arm/mach-stm32mp/stm32mp2/cpu.c +++ b/arch/arm/mach-stm32mp/stm32mp2/cpu.c @@ -69,6 +69,8 @@ void enable_caches(void)
int arch_misc_init(void) {
- setup_serial_number();
- return 0;
}
Reviewed-by: Patrice Chotard patrice.chotard@foss.st.com
Thanks Patrice

Add a function setup_mac_address() to update the MAC address from the default location in OTP for stm32mp2 platform.
The max number of OTP for MAC address is increased to 8 for STM32MP25, defined with get_eth_nb() and checked in setup_mac_address.
The MAC address FF:FF:FF:FF:FF:FF, the broadcast ethaddr, is a invalid value used for unused MAC address slot in OTP, for example for board with STM32MP25x part number allows up to 5 ethernet ports but it is not supported by the hardware, without switch; the associated variable "enetaddr%d" is not created.
Signed-off-by: Patrick Delaunay patrick.delaunay@foss.st.com ---
arch/arm/mach-stm32mp/soc.c | 70 ++++++++++++++++++++++++++++ arch/arm/mach-stm32mp/stm32mp1/cpu.c | 58 +---------------------- arch/arm/mach-stm32mp/stm32mp2/cpu.c | 1 + 3 files changed, 72 insertions(+), 57 deletions(-)
diff --git a/arch/arm/mach-stm32mp/soc.c b/arch/arm/mach-stm32mp/soc.c index ff70ebe97464..fa56b0d2e0f1 100644 --- a/arch/arm/mach-stm32mp/soc.c +++ b/arch/arm/mach-stm32mp/soc.c @@ -5,10 +5,14 @@
#include <env.h> #include <misc.h> +#include <net.h> #include <asm/arch/sys_proto.h> #include <dm/device.h> #include <dm/uclass.h>
+/* max: 8 OTP for 5 mac address on stm32mp2*/ +#define MAX_NB_OTP 8 + /* used when CONFIG_DISPLAY_CPUINFO is activated */ int print_cpuinfo(void) { @@ -46,3 +50,69 @@ int setup_serial_number(void)
return 0; } + +/* + * If there is no MAC address in the environment, then it will be initialized + * (silently) from the value in the OTP. + */ +__weak int setup_mac_address(void) +{ + int ret; + int i; + u32 otp[MAX_NB_OTP]; + uchar enetaddr[ARP_HLEN]; + struct udevice *dev; + int nb_eth, nb_otp, index; + + if (!IS_ENABLED(CONFIG_NET)) + return 0; + + nb_eth = get_eth_nb(); + if (!nb_eth) + return 0; + + /* 6 bytes for each MAC addr and 4 bytes for each OTP */ + nb_otp = DIV_ROUND_UP(ARP_HLEN * nb_eth, 4); + if (nb_otp > MAX_NB_OTP) { + log_err("invalid number of OTP = %d, max = %d\n", nb_otp, MAX_NB_OTP); + return -EINVAL; + } + + ret = uclass_get_device_by_driver(UCLASS_MISC, + DM_DRIVER_GET(stm32mp_bsec), + &dev); + if (ret) + return ret; + + ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_MAC), otp, 4 * nb_otp); + if (ret < 0) + return ret; + + for (index = 0; index < nb_eth; index++) { + /* MAC already in environment */ + if (eth_env_get_enetaddr_by_index("eth", index, enetaddr)) + continue; + + for (i = 0; i < ARP_HLEN; i++) + enetaddr[i] = ((uint8_t *)&otp)[i + ARP_HLEN * index]; + + /* skip FF:FF:FF:FF:FF:FF */ + if (is_broadcast_ethaddr(enetaddr)) + continue; + + if (!is_valid_ethaddr(enetaddr)) { + log_err("invalid MAC address %d in OTP %pM\n", + index, enetaddr); + return -EINVAL; + } + log_debug("OTP MAC address %d = %pM\n", index, enetaddr); + ret = eth_env_set_enetaddr_by_index("eth", index, enetaddr); + if (ret) { + log_err("Failed to set mac address %pM from OTP: %d\n", + enetaddr, ret); + return ret; + } + } + + return 0; +} diff --git a/arch/arm/mach-stm32mp/stm32mp1/cpu.c b/arch/arm/mach-stm32mp/stm32mp1/cpu.c index f84cb26fa565..524778f00c67 100644 --- a/arch/arm/mach-stm32mp/stm32mp1/cpu.c +++ b/arch/arm/mach-stm32mp/stm32mp1/cpu.c @@ -14,8 +14,8 @@ #include <log.h> #include <lmb.h> #include <misc.h> -#include <net.h> #include <spl.h> +#include <asm/cache.h> #include <asm/io.h> #include <asm/arch/stm32.h> #include <asm/arch/sys_proto.h> @@ -280,62 +280,6 @@ static void setup_boot_mode(void) clrsetbits_le32(TAMP_BOOT_CONTEXT, TAMP_BOOT_FORCED_MASK, BOOT_NORMAL); }
-/* - * If there is no MAC address in the environment, then it will be initialized - * (silently) from the value in the OTP. - */ -__weak int setup_mac_address(void) -{ - int ret; - int i; - u32 otp[3]; - uchar enetaddr[6]; - struct udevice *dev; - int nb_eth, nb_otp, index; - - if (!IS_ENABLED(CONFIG_NET)) - return 0; - - nb_eth = get_eth_nb(); - - /* 6 bytes for each MAC addr and 4 bytes for each OTP */ - nb_otp = DIV_ROUND_UP(6 * nb_eth, 4); - - ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_DRIVER_GET(stm32mp_bsec), - &dev); - if (ret) - return ret; - - ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_MAC), otp, 4 * nb_otp); - if (ret < 0) - return ret; - - for (index = 0; index < nb_eth; index++) { - /* MAC already in environment */ - if (eth_env_get_enetaddr_by_index("eth", index, enetaddr)) - continue; - - for (i = 0; i < 6; i++) - enetaddr[i] = ((uint8_t *)&otp)[i + 6 * index]; - - if (!is_valid_ethaddr(enetaddr)) { - log_err("invalid MAC address %d in OTP %pM\n", - index, enetaddr); - return -EINVAL; - } - log_debug("OTP MAC address %d = %pM\n", index, enetaddr); - ret = eth_env_set_enetaddr_by_index("eth", index, enetaddr); - if (ret) { - log_err("Failed to set mac address %pM from OTP: %d\n", - enetaddr, ret); - return ret; - } - } - - return 0; -} - __weak void stm32mp_misc_init(void) { } diff --git a/arch/arm/mach-stm32mp/stm32mp2/cpu.c b/arch/arm/mach-stm32mp/stm32mp2/cpu.c index 301e365cf4f4..9530aa8534b7 100644 --- a/arch/arm/mach-stm32mp/stm32mp2/cpu.c +++ b/arch/arm/mach-stm32mp/stm32mp2/cpu.c @@ -70,6 +70,7 @@ void enable_caches(void) int arch_misc_init(void) { setup_serial_number(); + setup_mac_address();
return 0; }

On 1/15/24 13:46, Patrick Delaunay wrote:
Add a function setup_mac_address() to update the MAC address from the default location in OTP for stm32mp2 platform.
The max number of OTP for MAC address is increased to 8 for STM32MP25, defined with get_eth_nb() and checked in setup_mac_address.
The MAC address FF:FF:FF:FF:FF:FF, the broadcast ethaddr, is a invalid value used for unused MAC address slot in OTP, for example for board with STM32MP25x part number allows up to 5 ethernet ports but it is not supported by the hardware, without switch; the associated variable "enetaddr%d" is not created.
Signed-off-by: Patrick Delaunay patrick.delaunay@foss.st.com
arch/arm/mach-stm32mp/soc.c | 70 ++++++++++++++++++++++++++++ arch/arm/mach-stm32mp/stm32mp1/cpu.c | 58 +---------------------- arch/arm/mach-stm32mp/stm32mp2/cpu.c | 1 + 3 files changed, 72 insertions(+), 57 deletions(-)
diff --git a/arch/arm/mach-stm32mp/soc.c b/arch/arm/mach-stm32mp/soc.c index ff70ebe97464..fa56b0d2e0f1 100644 --- a/arch/arm/mach-stm32mp/soc.c +++ b/arch/arm/mach-stm32mp/soc.c @@ -5,10 +5,14 @@
#include <env.h> #include <misc.h> +#include <net.h> #include <asm/arch/sys_proto.h> #include <dm/device.h> #include <dm/uclass.h>
+/* max: 8 OTP for 5 mac address on stm32mp2*/ +#define MAX_NB_OTP 8
/* used when CONFIG_DISPLAY_CPUINFO is activated */ int print_cpuinfo(void) { @@ -46,3 +50,69 @@ int setup_serial_number(void)
return 0; }
+/*
- If there is no MAC address in the environment, then it will be initialized
- (silently) from the value in the OTP.
- */
+__weak int setup_mac_address(void) +{
- int ret;
- int i;
- u32 otp[MAX_NB_OTP];
- uchar enetaddr[ARP_HLEN];
- struct udevice *dev;
- int nb_eth, nb_otp, index;
- if (!IS_ENABLED(CONFIG_NET))
return 0;
- nb_eth = get_eth_nb();
- if (!nb_eth)
return 0;
- /* 6 bytes for each MAC addr and 4 bytes for each OTP */
- nb_otp = DIV_ROUND_UP(ARP_HLEN * nb_eth, 4);
- if (nb_otp > MAX_NB_OTP) {
log_err("invalid number of OTP = %d, max = %d\n", nb_otp, MAX_NB_OTP);
return -EINVAL;
- }
- ret = uclass_get_device_by_driver(UCLASS_MISC,
DM_DRIVER_GET(stm32mp_bsec),
&dev);
- if (ret)
return ret;
- ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_MAC), otp, 4 * nb_otp);
- if (ret < 0)
return ret;
- for (index = 0; index < nb_eth; index++) {
/* MAC already in environment */
if (eth_env_get_enetaddr_by_index("eth", index, enetaddr))
continue;
for (i = 0; i < ARP_HLEN; i++)
enetaddr[i] = ((uint8_t *)&otp)[i + ARP_HLEN * index];
/* skip FF:FF:FF:FF:FF:FF */
if (is_broadcast_ethaddr(enetaddr))
continue;
if (!is_valid_ethaddr(enetaddr)) {
log_err("invalid MAC address %d in OTP %pM\n",
index, enetaddr);
return -EINVAL;
}
log_debug("OTP MAC address %d = %pM\n", index, enetaddr);
ret = eth_env_set_enetaddr_by_index("eth", index, enetaddr);
if (ret) {
log_err("Failed to set mac address %pM from OTP: %d\n",
enetaddr, ret);
return ret;
}
- }
- return 0;
+} diff --git a/arch/arm/mach-stm32mp/stm32mp1/cpu.c b/arch/arm/mach-stm32mp/stm32mp1/cpu.c index f84cb26fa565..524778f00c67 100644 --- a/arch/arm/mach-stm32mp/stm32mp1/cpu.c +++ b/arch/arm/mach-stm32mp/stm32mp1/cpu.c @@ -14,8 +14,8 @@ #include <log.h> #include <lmb.h> #include <misc.h> -#include <net.h> #include <spl.h> +#include <asm/cache.h> #include <asm/io.h> #include <asm/arch/stm32.h> #include <asm/arch/sys_proto.h> @@ -280,62 +280,6 @@ static void setup_boot_mode(void) clrsetbits_le32(TAMP_BOOT_CONTEXT, TAMP_BOOT_FORCED_MASK, BOOT_NORMAL); }
-/*
- If there is no MAC address in the environment, then it will be initialized
- (silently) from the value in the OTP.
- */
-__weak int setup_mac_address(void) -{
- int ret;
- int i;
- u32 otp[3];
- uchar enetaddr[6];
- struct udevice *dev;
- int nb_eth, nb_otp, index;
- if (!IS_ENABLED(CONFIG_NET))
return 0;
- nb_eth = get_eth_nb();
- /* 6 bytes for each MAC addr and 4 bytes for each OTP */
- nb_otp = DIV_ROUND_UP(6 * nb_eth, 4);
- ret = uclass_get_device_by_driver(UCLASS_MISC,
DM_DRIVER_GET(stm32mp_bsec),
&dev);
- if (ret)
return ret;
- ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_MAC), otp, 4 * nb_otp);
- if (ret < 0)
return ret;
- for (index = 0; index < nb_eth; index++) {
/* MAC already in environment */
if (eth_env_get_enetaddr_by_index("eth", index, enetaddr))
continue;
for (i = 0; i < 6; i++)
enetaddr[i] = ((uint8_t *)&otp)[i + 6 * index];
if (!is_valid_ethaddr(enetaddr)) {
log_err("invalid MAC address %d in OTP %pM\n",
index, enetaddr);
return -EINVAL;
}
log_debug("OTP MAC address %d = %pM\n", index, enetaddr);
ret = eth_env_set_enetaddr_by_index("eth", index, enetaddr);
if (ret) {
log_err("Failed to set mac address %pM from OTP: %d\n",
enetaddr, ret);
return ret;
}
- }
- return 0;
-}
__weak void stm32mp_misc_init(void) { } diff --git a/arch/arm/mach-stm32mp/stm32mp2/cpu.c b/arch/arm/mach-stm32mp/stm32mp2/cpu.c index 301e365cf4f4..9530aa8534b7 100644 --- a/arch/arm/mach-stm32mp/stm32mp2/cpu.c +++ b/arch/arm/mach-stm32mp/stm32mp2/cpu.c @@ -70,6 +70,7 @@ void enable_caches(void) int arch_misc_init(void) { setup_serial_number();
setup_mac_address();
return 0;
}
Reviewed-by: Patrice Chotard patrice.chotard@foss.st.com
Thanks Patrice

Change OTP number to 364 for STM32MP25 as it is done in bsec driver.
Signed-off-by: Patrick Delaunay patrick.delaunay@foss.st.com ---
arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.h b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.h index ae4bd8842f53..eda98eb61d76 100644 --- a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.h +++ b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.h @@ -28,7 +28,15 @@ #else #define OTP_SIZE_SMC 0 #endif -#define OTP_SIZE_TA 776 +/* size of the OTP struct in NVMEM PTA */ +#define _OTP_SIZE_TA(otp) (((otp) * 2 + 2) * 4) +#if defined(CONFIG_STM32MP13x) || defined(CONFIG_STM32MP15x) +/* STM32MP1 with BSEC2 */ +#define OTP_SIZE_TA _OTP_SIZE_TA(96) +#else +/* STM32MP2 with BSEC3 */ +#define OTP_SIZE_TA _OTP_SIZE_TA(368) +#endif #define PMIC_SIZE 8
enum stm32prog_target {

On 1/15/24 13:46, Patrick Delaunay wrote:
Change OTP number to 364 for STM32MP25 as it is done in bsec driver.
Signed-off-by: Patrick Delaunay patrick.delaunay@foss.st.com
arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.h b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.h index ae4bd8842f53..eda98eb61d76 100644 --- a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.h +++ b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.h @@ -28,7 +28,15 @@ #else #define OTP_SIZE_SMC 0 #endif -#define OTP_SIZE_TA 776 +/* size of the OTP struct in NVMEM PTA */ +#define _OTP_SIZE_TA(otp) (((otp) * 2 + 2) * 4) +#if defined(CONFIG_STM32MP13x) || defined(CONFIG_STM32MP15x)
Should we convert are all STM32MP13x and STM32MP15x in upper case ?
+/* STM32MP1 with BSEC2 */ +#define OTP_SIZE_TA _OTP_SIZE_TA(96) +#else +/* STM32MP2 with BSEC3 */ +#define OTP_SIZE_TA _OTP_SIZE_TA(368) +#endif #define PMIC_SIZE 8
enum stm32prog_target {

Activate the command stboard for stm32mp25 STMicroelectronics boards, add the default used OTP identifier and the associated board identifier: - stm32mp25xx-ev1 = MB1936 - stm32mp25xx-dk = MB1605
Signed-off-by: Patrick Delaunay patrick.delaunay@foss.st.com ---
arch/arm/mach-stm32mp/include/mach/stm32.h | 1 + board/st/common/Kconfig | 2 +- board/st/common/cmd_stboard.c | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/arch/arm/mach-stm32mp/include/mach/stm32.h b/arch/arm/mach-stm32mp/include/mach/stm32.h index 45c929aa605d..726c390977e3 100644 --- a/arch/arm/mach-stm32mp/include/mach/stm32.h +++ b/arch/arm/mach-stm32mp/include/mach/stm32.h @@ -198,6 +198,7 @@ enum forced_boot_mode { #define BSEC_OTP_SERIAL 5 #define BSEC_OTP_RPN 9 #define BSEC_OTP_PKG 122 +#define BSEC_OTP_BOARD 246 #define BSEC_OTP_MAC 247 #endif
diff --git a/board/st/common/Kconfig b/board/st/common/Kconfig index c1c254d07354..5efac658cf4d 100644 --- a/board/st/common/Kconfig +++ b/board/st/common/Kconfig @@ -1,7 +1,7 @@ config CMD_STBOARD bool "stboard - command for OTP board information" depends on ARCH_STM32MP - default y if TARGET_ST_STM32MP15x || TARGET_ST_STM32MP13x + default y if TARGET_ST_STM32MP25X || TARGET_ST_STM32MP15X || TARGET_ST_STM32MP13X help This compile the stboard command to read and write the board in the OTP. diff --git a/board/st/common/cmd_stboard.c b/board/st/common/cmd_stboard.c index 853ab78bbf16..cb103e69b369 100644 --- a/board/st/common/cmd_stboard.c +++ b/board/st/common/cmd_stboard.c @@ -49,7 +49,9 @@ static bool check_stboard(u16 board) 0x1298, 0x1341, 0x1497, + 0x1605, /* stm32mp25xx-dk */ 0x1635, + 0x1936, /* stm32mp25xx-ev1 */ };
for (i = 0; i < ARRAY_SIZE(st_board_id); i++)

On 1/15/24 13:46, Patrick Delaunay wrote:
Activate the command stboard for stm32mp25 STMicroelectronics boards, add the default used OTP identifier and the associated board identifier:
- stm32mp25xx-ev1 = MB1936
- stm32mp25xx-dk = MB1605
Signed-off-by: Patrick Delaunay patrick.delaunay@foss.st.com
arch/arm/mach-stm32mp/include/mach/stm32.h | 1 + board/st/common/Kconfig | 2 +- board/st/common/cmd_stboard.c | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/arch/arm/mach-stm32mp/include/mach/stm32.h b/arch/arm/mach-stm32mp/include/mach/stm32.h index 45c929aa605d..726c390977e3 100644 --- a/arch/arm/mach-stm32mp/include/mach/stm32.h +++ b/arch/arm/mach-stm32mp/include/mach/stm32.h @@ -198,6 +198,7 @@ enum forced_boot_mode { #define BSEC_OTP_SERIAL 5 #define BSEC_OTP_RPN 9 #define BSEC_OTP_PKG 122 +#define BSEC_OTP_BOARD 246 #define BSEC_OTP_MAC 247 #endif
diff --git a/board/st/common/Kconfig b/board/st/common/Kconfig index c1c254d07354..5efac658cf4d 100644 --- a/board/st/common/Kconfig +++ b/board/st/common/Kconfig @@ -1,7 +1,7 @@ config CMD_STBOARD bool "stboard - command for OTP board information" depends on ARCH_STM32MP
- default y if TARGET_ST_STM32MP15x || TARGET_ST_STM32MP13x
- default y if TARGET_ST_STM32MP25X || TARGET_ST_STM32MP15X || TARGET_ST_STM32MP13X
TARGET_ST_STM32MP15x or TARGET_ST_STM32MP15X ? ;-) Internally, we use all our flags in uppercase, whereas at upstream there are some camelcase as TARGET_ST_STM32MP15x or TARGET_ST_STM32MP13x
help This compile the stboard command to read and write the board in the OTP. diff --git a/board/st/common/cmd_stboard.c b/board/st/common/cmd_stboard.c index 853ab78bbf16..cb103e69b369 100644 --- a/board/st/common/cmd_stboard.c +++ b/board/st/common/cmd_stboard.c @@ -49,7 +49,9 @@ static bool check_stboard(u16 board) 0x1298, 0x1341, 0x1497,
0x1605, /* stm32mp25xx-dk */
0x1635,
0x1936, /* stm32mp25xx-ev1 */
};
for (i = 0; i < ARRAY_SIZE(st_board_id); i++)

Hi,
On 1/15/24 14:03, Patrice CHOTARD wrote:
On 1/15/24 13:46, Patrick Delaunay wrote:
Activate the command stboard for stm32mp25 STMicroelectronics boards, add the default used OTP identifier and the associated board identifier:
- stm32mp25xx-ev1 = MB1936
- stm32mp25xx-dk = MB1605
Signed-off-by: Patrick Delaunay patrick.delaunay@foss.st.com
arch/arm/mach-stm32mp/include/mach/stm32.h | 1 + board/st/common/Kconfig | 2 +- board/st/common/cmd_stboard.c | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/arch/arm/mach-stm32mp/include/mach/stm32.h b/arch/arm/mach-stm32mp/include/mach/stm32.h index 45c929aa605d..726c390977e3 100644 --- a/arch/arm/mach-stm32mp/include/mach/stm32.h +++ b/arch/arm/mach-stm32mp/include/mach/stm32.h @@ -198,6 +198,7 @@ enum forced_boot_mode { #define BSEC_OTP_SERIAL 5 #define BSEC_OTP_RPN 9 #define BSEC_OTP_PKG 122 +#define BSEC_OTP_BOARD 246 #define BSEC_OTP_MAC 247 #endif
diff --git a/board/st/common/Kconfig b/board/st/common/Kconfig index c1c254d07354..5efac658cf4d 100644 --- a/board/st/common/Kconfig +++ b/board/st/common/Kconfig @@ -1,7 +1,7 @@ config CMD_STBOARD bool "stboard - command for OTP board information" depends on ARCH_STM32MP
- default y if TARGET_ST_STM32MP15x || TARGET_ST_STM32MP13x
- default y if TARGET_ST_STM32MP25X || TARGET_ST_STM32MP15X || TARGET_ST_STM32MP13X
TARGET_ST_STM32MP15x or TARGET_ST_STM32MP15X ? ;-) Internally, we use all our flags in uppercase, whereas at upstream there are some camelcase as TARGET_ST_STM32MP15x or TARGET_ST_STM32MP13x
Thks, I don't see that the Simon patches was not merged.
I will correct this part in V2
and also include the 2 Simon patches which rename the stm32mp config to avoid the same issue in futur.
See series "Clean up of bad Kconfig options"
https://patchwork.ozlabs.org/project/uboot/list/?series=339004&state=*
=> [v2,67/87] arm: Rename STM32MP13x
https://patchwork.ozlabs.org/project/uboot/patch/20230129005903.74918-68-sjg...
=> [v2,68/87] arm: Rename STM32MP15x
https://patchwork.ozlabs.org/project/uboot/patch/20230129005903.74918-69-sjg...
help This compile the stboard command to read and write the board in the OTP. diff --git a/board/st/common/cmd_stboard.c b/board/st/common/cmd_stboard.c index 853ab78bbf16..cb103e69b369 100644 --- a/board/st/common/cmd_stboard.c +++ b/board/st/common/cmd_stboard.c @@ -49,7 +49,9 @@ static bool check_stboard(u16 board) 0x1298, 0x1341, 0x1497,
0x1605, /* stm32mp25xx-dk */
0x1635,
0x1936, /* stm32mp25xx-ev1 */
};
for (i = 0; i < ARRAY_SIZE(st_board_id); i++)

Implement the weak function checkboard to identify the used board with compatible in device tree for the support of stm32mp2 STMicroelectronics boards.
Signed-off-by: Patrick Delaunay patrick.delaunay@foss.st.com ---
board/st/stm32mp2/stm32mp2.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
diff --git a/board/st/stm32mp2/stm32mp2.c b/board/st/stm32mp2/stm32mp2.c index c97a7efff46e..9a881583d904 100644 --- a/board/st/stm32mp2/stm32mp2.c +++ b/board/st/stm32mp2/stm32mp2.c @@ -8,14 +8,28 @@ #include <config.h> #include <env.h> #include <fdt_support.h> +#include <log.h> #include <asm/global_data.h> #include <asm/arch/sys_proto.h> +#include <dm/ofnode.h>
/* * Get a global data pointer */ DECLARE_GLOBAL_DATA_PTR;
+int checkboard(void) +{ + const char *fdt_compat; + int fdt_compat_len; + + fdt_compat = ofnode_get_property(ofnode_root(), "compatible", &fdt_compat_len); + + log_info("Board: stm32mp2 (%s)\n", fdt_compat && fdt_compat_len ? fdt_compat : ""); + + return 0; +} + /* board dependent setup after realloc */ int board_init(void) {

On 1/15/24 13:46, Patrick Delaunay wrote:
Implement the weak function checkboard to identify the used board with compatible in device tree for the support of stm32mp2 STMicroelectronics boards.
Signed-off-by: Patrick Delaunay patrick.delaunay@foss.st.com
board/st/stm32mp2/stm32mp2.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
diff --git a/board/st/stm32mp2/stm32mp2.c b/board/st/stm32mp2/stm32mp2.c index c97a7efff46e..9a881583d904 100644 --- a/board/st/stm32mp2/stm32mp2.c +++ b/board/st/stm32mp2/stm32mp2.c @@ -8,14 +8,28 @@ #include <config.h> #include <env.h> #include <fdt_support.h> +#include <log.h> #include <asm/global_data.h> #include <asm/arch/sys_proto.h> +#include <dm/ofnode.h>
/*
- Get a global data pointer
*/ DECLARE_GLOBAL_DATA_PTR;
+int checkboard(void) +{
- const char *fdt_compat;
- int fdt_compat_len;
- fdt_compat = ofnode_get_property(ofnode_root(), "compatible", &fdt_compat_len);
- log_info("Board: stm32mp2 (%s)\n", fdt_compat && fdt_compat_len ? fdt_compat : "");
- return 0;
+}
/* board dependent setup after realloc */ int board_init(void) {
Reviewed-by: Patrice Chotard patrice.chotard@foss.st.com
Thanks Patrice

Add the display of the STMicroelectronics board identification saved in OTP in stm32mp2 checkboard function.
Signed-off-by: Patrick Delaunay patrick.delaunay@foss.st.com ---
board/st/stm32mp2/stm32mp2.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
diff --git a/board/st/stm32mp2/stm32mp2.c b/board/st/stm32mp2/stm32mp2.c index 9a881583d904..aa7dd31996ea 100644 --- a/board/st/stm32mp2/stm32mp2.c +++ b/board/st/stm32mp2/stm32mp2.c @@ -9,9 +9,12 @@ #include <env.h> #include <fdt_support.h> #include <log.h> +#include <misc.h> #include <asm/global_data.h> #include <asm/arch/sys_proto.h> +#include <dm/device.h> #include <dm/ofnode.h> +#include <dm/uclass.h>
/* * Get a global data pointer @@ -20,6 +23,9 @@ DECLARE_GLOBAL_DATA_PTR;
int checkboard(void) { + int ret; + u32 otp; + struct udevice *dev; const char *fdt_compat; int fdt_compat_len;
@@ -27,6 +33,23 @@ int checkboard(void)
log_info("Board: stm32mp2 (%s)\n", fdt_compat && fdt_compat_len ? fdt_compat : "");
+ /* display the STMicroelectronics board identification */ + if (CONFIG_IS_ENABLED(CMD_STBOARD)) { + ret = uclass_get_device_by_driver(UCLASS_MISC, + DM_DRIVER_GET(stm32mp_bsec), + &dev); + if (!ret) + ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_BOARD), + &otp, sizeof(otp)); + if (ret > 0 && otp) + log_info("Board: MB%04x Var%d.%d Rev.%c-%02d\n", + otp >> 16, + (otp >> 12) & 0xF, + (otp >> 4) & 0xF, + ((otp >> 8) & 0xF) - 1 + 'A', + otp & 0xF); + } + return 0; }

On 1/15/24 13:46, Patrick Delaunay wrote:
Add the display of the STMicroelectronics board identification saved in OTP in stm32mp2 checkboard function.
Signed-off-by: Patrick Delaunay patrick.delaunay@foss.st.com
board/st/stm32mp2/stm32mp2.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
diff --git a/board/st/stm32mp2/stm32mp2.c b/board/st/stm32mp2/stm32mp2.c index 9a881583d904..aa7dd31996ea 100644 --- a/board/st/stm32mp2/stm32mp2.c +++ b/board/st/stm32mp2/stm32mp2.c @@ -9,9 +9,12 @@ #include <env.h> #include <fdt_support.h> #include <log.h> +#include <misc.h> #include <asm/global_data.h> #include <asm/arch/sys_proto.h> +#include <dm/device.h> #include <dm/ofnode.h> +#include <dm/uclass.h>
/*
- Get a global data pointer
@@ -20,6 +23,9 @@ DECLARE_GLOBAL_DATA_PTR;
int checkboard(void) {
- int ret;
- u32 otp;
- struct udevice *dev; const char *fdt_compat; int fdt_compat_len;
@@ -27,6 +33,23 @@ int checkboard(void)
log_info("Board: stm32mp2 (%s)\n", fdt_compat && fdt_compat_len ? fdt_compat : "");
- /* display the STMicroelectronics board identification */
- if (CONFIG_IS_ENABLED(CMD_STBOARD)) {
ret = uclass_get_device_by_driver(UCLASS_MISC,
DM_DRIVER_GET(stm32mp_bsec),
&dev);
if (!ret)
ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_BOARD),
&otp, sizeof(otp));
if (ret > 0 && otp)
log_info("Board: MB%04x Var%d.%d Rev.%c-%02d\n",
otp >> 16,
(otp >> 12) & 0xF,
(otp >> 4) & 0xF,
((otp >> 8) & 0xF) - 1 + 'A',
otp & 0xF);
- }
- return 0;
}
Reviewed-by: Patrice Chotard patrice.chotard@foss.st.com
Thanks Patrice
participants (4)
-
Igor Opaniuk
-
Patrice CHOTARD
-
Patrick DELAUNAY
-
Patrick Delaunay