Skip to contentSkip to conversation

stm32: add bsec and OTP support to stm32mp25

PATCH Superseded Patrick Delaunay 3 participants 27 messages Jan 15, 2024

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover 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
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/12 arm64: dts: st: add bsec support to stm32mp25

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)

---

 arch/arm/dts/stm32mp25-u-boot.dtsi |  4 ++++
 arch/arm/dts/stm32mp251.dtsi       | 16 ++++++++++++++++
 2 files changed, 20 insertions(+)
arch/arm/dts/stm32mp25-u-boot.dtsi +4 -0
index f4f26add2a41..0c8e95b34163 100644
@@ -37,6 +37,10 @@
 	};
 };
 
+&bsec {
+	bootph-all;
+};
+
 &gpioa {
 	bootph-all;
 };
arch/arm/dts/stm32mp251.dtsi +16 -0
index cf2f28dc1582..44eb664fb510 100644
@@ -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>;
Signature · 1 line
2.25.1
Reviewed-by on v1 1/12
#2 lore raw

Re: [PATCH 01/12] arm64: dts: st: add bsec support to stm32mp25

Quoted 44 lines · Patrick Delaunay

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)

---

 arch/arm/dts/stm32mp25-u-boot.dtsi |  4 ++++
 arch/arm/dts/stm32mp251.dtsi       | 16 ++++++++++++++++
 2 files changed, 20 insertions(+)
arch/arm/dts/stm32mp25-u-boot.dtsi +4 -0
index f4f26add2a41..0c8e95b34163 100644
@@ -37,6 +37,10 @@
 	};
 };
 
+&bsec {
+	bootph-all;
+};
+
 &gpioa {
 	bootph-all;
 };
arch/arm/dts/stm32mp251.dtsi +9 -0
index cf2f28dc1582..44eb664fb510 100644
@@ -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>;
+			};

arch/arm/dts/stm32mp251.dtsi line 148

Quoted 10 lines
arch/arm/dts/stm32mp251.dtsi +7 -0
+
+			package_otp@1e8 {
+				reg = <0x1e8 0x1>;
+				bits = <0 3>;
+			};
+		};
+
 		syscfg: syscon@44230000 {
 			compatible = "st,stm32mp25-syscfg", "syscon";
 			reg = <0x44230000 0x10000>;

Thanks
Patrice

#3 lore raw

PATCH 2/12 arm: stm32mp: add Rev.B support for STM32MP25

In reply to Patrick Delaunay

From: Yann Gautier <[email protected]>

Add chip revision B support for STM32MP25, for displaying it in trace.

---

 arch/arm/mach-stm32mp/stm32mp2/stm32mp25x.c | 3 +++
 1 file changed, 3 insertions(+)
arch/arm/mach-stm32mp/stm32mp2/stm32mp25x.c +3 -0
index 4b2f70af9cc6..7f896a0d65d2 100644
@@ -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;
 		}
Signature · 1 line
2.25.1
Reviewed-by on v1 2/12
#4 lore raw

Re: [PATCH 02/12] arm: stm32mp: add Rev.B support for STM32MP25

Quoted 16 lines · Patrick Delaunay

From: Yann Gautier <[email protected]>

Add chip revision B support for STM32MP25, for displaying it in trace.

---

 arch/arm/mach-stm32mp/stm32mp2/stm32mp25x.c | 3 +++
 1 file changed, 3 insertions(+)
arch/arm/mach-stm32mp/stm32mp2/stm32mp25x.c +0 -0
index 4b2f70af9cc6..7f896a0d65d2 100644

arch/arm/mach-stm32mp/stm32mp2/stm32mp25x.c void get_soc_name(char name[SOC_NAME_SIZE]) · line 175

Quoted 9 lines
arch/arm/mach-stm32mp/stm32mp2/stm32mp25x.c +3 -0
@@ -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;
 		}

Thanks
Patrice

#5 lore raw

PATCH 3/12 stm32mp: bsec: add driver data

In reply to Patrick Delaunay

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.

---

 arch/arm/mach-stm32mp/bsec.c | 38 ++++++++++++++++++++++++++++--------
 1 file changed, 30 insertions(+), 8 deletions(-)
arch/arm/mach-stm32mp/bsec.c +30 -8
index 28a8280b2804..705c994d9307 100644
@@ -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},
 	{}
 };
 
Signature · 1 line
2.25.1
Reviewed-by on v1 3/12
#6 lore raw

Re: [PATCH 03/12] stm32mp: bsec: add driver data

Quoted 113 lines · Patrick Delaunay

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.

---

 arch/arm/mach-stm32mp/bsec.c | 38 ++++++++++++++++++++++++++++--------
 1 file changed, 30 insertions(+), 8 deletions(-)
arch/arm/mach-stm32mp/bsec.c +26 -6
index 28a8280b2804..705c994d9307 100644
@@ -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,

arch/arm/mach-stm32mp/bsec.c static int stm32mp_bsec_probe(struct udevice *dev) · line 792

Quoted 10 lines
arch/arm/mach-stm32mp/bsec.c +4 -2
+	.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},
 	{}
 };
 

Thanks
Patrice

#7 lore raw

PATCH 4/12 stm32mp: bsec: add support of stm32mp25

In reply to Patrick Delaunay

Add support of BSEC for STM32MP25x family to access OTP.

---

 arch/arm/mach-stm32mp/bsec.c               | 7 +++++++
 arch/arm/mach-stm32mp/include/mach/stm32.h | 3 ++-
 2 files changed, 9 insertions(+), 1 deletion(-)
arch/arm/mach-stm32mp/bsec.c +7 -0
index 705c994d9307..5b869017ec1a 100644
@@ -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},
 	{}
 };
 
arch/arm/mach-stm32mp/include/mach/stm32.h +2 -1
index 46d469881b32..45c929aa605d 100644
@@ -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__
Signature · 1 line
2.25.1
Reviewed-by on v1 4/12
#8 lore raw

Re: [PATCH 04/12] stm32mp: bsec: add support of stm32mp25

Quoted 35 lines · Patrick Delaunay

Add support of BSEC for STM32MP25x family to access OTP.

---

 arch/arm/mach-stm32mp/bsec.c               | 7 +++++++
 arch/arm/mach-stm32mp/include/mach/stm32.h | 3 ++-
 2 files changed, 9 insertions(+), 1 deletion(-)
arch/arm/mach-stm32mp/bsec.c +7 -0
index 705c994d9307..5b869017ec1a 100644
@@ -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},
 	{}
 };
 
arch/arm/mach-stm32mp/include/mach/stm32.h +0 -0
index 46d469881b32..45c929aa605d 100644

arch/arm/mach-stm32mp/include/mach/stm32.h enum forced_boot_mode { · line 204

Quoted 9 lines
arch/arm/mach-stm32mp/include/mach/stm32.h +2 -1
@@ -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__

Thanks
Patrice

Reviewed-by on v1 4/12
#9 lore raw

Re: [PATCH 04/12] stm32mp: bsec: add support of stm32mp25

In reply to Patrick Delaunay
Quoted 46 lines · Patrick Delaunay

Add support of BSEC for STM32MP25x family to access OTP.

---

 arch/arm/mach-stm32mp/bsec.c               | 7 +++++++
 arch/arm/mach-stm32mp/include/mach/stm32.h | 3 ++-
 2 files changed, 9 insertions(+), 1 deletion(-)
arch/arm/mach-stm32mp/bsec.c +7 -0
index 705c994d9307..5b869017ec1a 100644
@@ -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},
        {}
 };
 
arch/arm/mach-stm32mp/include/mach/stm32.h +2 -2
index 46d469881b32..45c929aa605d 100644
@@ -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__
--
Quoted 2 lines

2.25.1

Signature · 7 lines
Best regards - Freundliche Grüsse - Meilleures salutations

Igor Opaniuk
Embedded Software Engineer
T:  +380 938364067
E: [email protected]
W: www.foundries.io
#10 lore raw

PATCH 5/12 configs: stm32mp25: add support of fuse command

In reply to Patrick Delaunay

Add support of the command fuse with CONFIG_CMD_FUSE to allow access on OTP with command line.

---

 configs/stm32mp25_defconfig | 1 +
 1 file changed, 1 insertion(+)
configs/stm32mp25_defconfig +1 -0
index 75f27c98b441..9fbd7eb15755 100644
@@ -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
Signature · 1 line
2.25.1
Reviewed-by on v1 5/12
#11 lore raw

Re: [PATCH 05/12] configs: stm32mp25: add support of fuse command

Quoted 14 lines · Patrick Delaunay

Add support of the command fuse with CONFIG_CMD_FUSE to allow access on OTP with command line.

---

 configs/stm32mp25_defconfig | 1 +
 1 file changed, 1 insertion(+)
configs/stm32mp25_defconfig +0 -0
index 75f27c98b441..9fbd7eb15755 100644

configs/stm32mp25_defconfig CONFIG_CMD_ADTIMG=y · line 27

Quoted 7 lines
configs/stm32mp25_defconfig +1 -0
@@ -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

Thanks
Patrice

#12 lore raw

PATCH 6/12 stm32mp: add soc.c file

In reply to Patrick Delaunay

Add a new file soc.c for common functions between stm32mp1 and stm32mp2 family and move print_cpuinfo() in this new file.

---

 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
arch/arm/mach-stm32mp/Makefile +1 -0
index 00dc25bb275c..fdcbbf91dfd5 100644
@@ -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/
arch/arm/mach-stm32mp/soc.c new file +17 -0
new file mode 100644
index 000000000000..8d5fa474ccaf
@@ -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;
+}
arch/arm/mach-stm32mp/stm32mp1/cpu.c +0 -11
index 55574fd4bebf..00fea7929b2f 100644
@@ -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[] = {
arch/arm/mach-stm32mp/stm32mp2/cpu.c +0 -11
index f43d1aaf72cc..c0f6519e8d7c 100644
@@ -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;
Signature · 1 line
2.25.1
Reviewed-by on v1 6/12
#13 lore raw

Re: [PATCH 06/12] stm32mp: add soc.c file

Quoted 82 lines · Patrick Delaunay

Add a new file soc.c for common functions between stm32mp1 and stm32mp2 family and move print_cpuinfo() in this new file.

---

 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
arch/arm/mach-stm32mp/Makefile +1 -0
index 00dc25bb275c..fdcbbf91dfd5 100644
@@ -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/
arch/arm/mach-stm32mp/soc.c new file +17 -0
new file mode 100644
index 000000000000..8d5fa474ccaf
@@ -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;
+}
arch/arm/mach-stm32mp/stm32mp1/cpu.c +0 -11
index 55574fd4bebf..00fea7929b2f 100644
@@ -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[] = {
arch/arm/mach-stm32mp/stm32mp2/cpu.c +0 -4
index f43d1aaf72cc..c0f6519e8d7c 100644
@@ -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];

arch/arm/mach-stm32mp/stm32mp2/cpu.c void enable_caches(void) · line 72

Quoted 10 lines
arch/arm/mach-stm32mp/stm32mp2/cpu.c +0 -7
-
-	get_soc_name(name);
-	printf("CPU: %s\n", name);
-
-	return 0;
-}
-
 int arch_misc_init(void)
 {
 	return 0;

Thanks
Patrice

#14 lore raw

PATCH 7/12 stm32mp: add setup_serial_number for stm32mp25

In reply to Patrick Delaunay

From: Patrice Chotard <[email protected]>

Add support of serial number for stm32mp25, gets from OTP with BSEC driver.

---

 .../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(-)
arch/arm/mach-stm32mp/include/mach/sys_proto.h +1 -0
index 83388fdb7371..2a65efc0a50a 100644
@@ -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);
arch/arm/mach-stm32mp/soc.c +31 -0
index 8d5fa474ccaf..ff70ebe97464 100644
@@ -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;
+}
arch/arm/mach-stm32mp/stm32mp1/cpu.c +0 -27
index 00fea7929b2f..f84cb26fa565 100644
@@ -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)
 {
 }
arch/arm/mach-stm32mp/stm32mp2/cpu.c +2 -0
index c0f6519e8d7c..301e365cf4f4 100644
@@ -69,6 +69,8 @@ void enable_caches(void)
 
 int arch_misc_init(void)
 {
+	setup_serial_number();
+
 	return 0;
 }
 
Signature · 1 line
2.25.1
Reviewed-by on v1 7/12
#15 lore raw

Re: [PATCH 07/12] stm32mp: add setup_serial_number for stm32mp25

Quoted 116 lines · Patrick Delaunay

From: Patrice Chotard <[email protected]>

Add support of serial number for stm32mp25, gets from OTP with BSEC driver.

---

 .../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(-)
arch/arm/mach-stm32mp/include/mach/sys_proto.h +1 -0
index 83388fdb7371..2a65efc0a50a 100644
@@ -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);
arch/arm/mach-stm32mp/soc.c +31 -0
index 8d5fa474ccaf..ff70ebe97464 100644
@@ -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;
+}
arch/arm/mach-stm32mp/stm32mp1/cpu.c +0 -27
index 00fea7929b2f..f84cb26fa565 100644
@@ -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)
 {
 }
arch/arm/mach-stm32mp/stm32mp2/cpu.c +0 -0
index c0f6519e8d7c..301e365cf4f4 100644

arch/arm/mach-stm32mp/stm32mp2/cpu.c void enable_caches(void) · line 76

Quoted 8 lines
arch/arm/mach-stm32mp/stm32mp2/cpu.c +2 -0
@@ -69,6 +69,8 @@ void enable_caches(void)
 
 int arch_misc_init(void)
 {
+	setup_serial_number();
+
 	return 0;
 }
 

Thanks
Patrice

#16 lore raw

PATCH 8/12 smt32mp: add setup_mac_address for stm32mp25

In reply to Patrick Delaunay

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.

---

 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(-)
arch/arm/mach-stm32mp/soc.c +70 -0
index ff70ebe97464..fa56b0d2e0f1 100644
@@ -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;
+}
arch/arm/mach-stm32mp/stm32mp1/cpu.c +1 -57

71 lines not on this page · raw message

arch/arm/mach-stm32mp/stm32mp2/cpu.c +1 -0
index 301e365cf4f4..9530aa8534b7 100644
@@ -70,6 +70,7 @@ void enable_caches(void)
 int arch_misc_init(void)
 {
 	setup_serial_number();
+	setup_mac_address();
 
 	return 0;
 }
Signature · 1 line
2.25.1
Reviewed-by on v1 8/12
#17 lore raw

Re: [PATCH 08/12] smt32mp: add setup_mac_address for stm32mp25

Quoted 191 lines · Patrick Delaunay

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.

---

 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(-)
arch/arm/mach-stm32mp/soc.c +70 -0
index ff70ebe97464..fa56b0d2e0f1 100644
@@ -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;
+}
arch/arm/mach-stm32mp/stm32mp1/cpu.c +1 -57
index f84cb26fa565..524778f00c67 100644
@@ -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)
 {
 }
arch/arm/mach-stm32mp/stm32mp2/cpu.c +0 -0
index 301e365cf4f4..9530aa8534b7 100644

arch/arm/mach-stm32mp/stm32mp2/cpu.c void enable_caches(void) · line 76

Quoted 7 lines
arch/arm/mach-stm32mp/stm32mp2/cpu.c +1 -0
@@ -70,6 +70,7 @@ void enable_caches(void)
 int arch_misc_init(void)
 {
 	setup_serial_number();
+	setup_mac_address();
 
 	return 0;
 }

Thanks
Patrice

#18 lore raw

PATCH 9/12 stm32mp: stm32prog: add support of stm32mp25

In reply to Patrick Delaunay

Change OTP number to 364 for STM32MP25 as it is done in bsec driver.

---

 arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.h | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.h +9 -1
index ae4bd8842f53..eda98eb61d76 100644
@@ -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 {
Signature · 1 line
2.25.1
#19 lore raw

Re: [PATCH 09/12] stm32mp: stm32prog: add support of stm32mp25

Quoted 13 lines · Patrick Delaunay

Change OTP number to 364 for STM32MP25 as it is done in bsec driver.

---

 arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.h | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.h +0 -0
index ae4bd8842f53..eda98eb61d76 100644

arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.h line 33

Quoted 7 lines
arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.h +3 -1
@@ -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 ?

Quoted 9 lines
arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.h +6 -0
+/* 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 {
#20 lore raw

PATCH 10/12 stm32mp: activate the command stboard for stm32mp25 boards

In reply to Patrick Delaunay

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

---

 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(-)
arch/arm/mach-stm32mp/include/mach/stm32.h +1 -0
index 45c929aa605d..726c390977e3 100644
@@ -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
 
board/st/common/Kconfig +1 -1
index c1c254d07354..5efac658cf4d 100644
@@ -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.
board/st/common/cmd_stboard.c +2 -0
index 853ab78bbf16..cb103e69b369 100644
@@ -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++)
Signature · 1 line
2.25.1
#21 lore raw

Re: [PATCH 10/12] stm32mp: activate the command stboard for stm32mp25 boards

Quoted 30 lines · Patrick Delaunay

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

---

 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(-)
arch/arm/mach-stm32mp/include/mach/stm32.h +1 -0
index 45c929aa605d..726c390977e3 100644
@@ -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
 
board/st/common/Kconfig +0 -0
index c1c254d07354..5efac658cf4d 100644

board/st/common/Kconfig line 4

Quoted 5 lines
board/st/common/Kconfig +1 -1
@@ -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

Quoted 17 lines
board/st/common/Kconfig +0 -0
 	help
 	  This compile the stboard command to
 	  read and write the board in the OTP.
board/st/common/cmd_stboard.c +2 -0
index 853ab78bbf16..cb103e69b369 100644
@@ -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++)
#22 lore raw

Re: [PATCH 10/12] stm32mp: activate the command stboard for stm32mp25 boards

Hi,

Quoted 27 lines · Patrice CHOTARD
Quoted 25 lines · Patrick Delaunay

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

---

  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(-)
arch/arm/mach-stm32mp/include/mach/stm32.h +1 -0
index 45c929aa605d..726c390977e3 100644
@@ -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
 
Quoted 14 lines

board/st/common/Kconfig line 4

Quoted 10 lines
board/st/common/Kconfig +1 -1
index c1c254d07354..5efac658cf4d 100644
@@ -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/[email protected]/

=> [v2,68/87] arm: Rename STM32MP15x

https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

Quoted 17 lines
Quoted 17 lines
board/st/common/Kconfig +0 -0
  	help
  	  This compile the stboard command to
  	  read and write the board in the OTP.
board/st/common/cmd_stboard.c +2 -0
index 853ab78bbf16..cb103e69b369 100644
@@ -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++)
#23 lore raw

PATCH 11/12 board: st: stm32mp2: add checkboard

In reply to Patrick Delaunay

Implement the weak function checkboard to identify the used board with compatible in device tree for the support of stm32mp2 STMicroelectronics boards.

---

 board/st/stm32mp2/stm32mp2.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
board/st/stm32mp2/stm32mp2.c +14 -0
index c97a7efff46e..9a881583d904 100644
@@ -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)
 {
Signature · 1 line
2.25.1
Reviewed-by on v1 11/12
#24 lore raw

Re: [PATCH 11/12] board: st: stm32mp2: add checkboard

Quoted 33 lines · Patrick Delaunay

Implement the weak function checkboard to identify the used board with compatible in device tree for the support of stm32mp2 STMicroelectronics boards.

---

 board/st/stm32mp2/stm32mp2.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
board/st/stm32mp2/stm32mp2.c +7 -0
index c97a7efff46e..9a881583d904 100644
@@ -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;
+

board/st/stm32mp2/stm32mp2.c line 35

Quoted 10 lines
board/st/stm32mp2/stm32mp2.c +7 -0
+	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)
 {

Thanks
Patrice

#25 lore raw

PATCH 12/12 board: st: stm32mp2: display the board identification

In reply to Patrick Delaunay

Add the display of the STMicroelectronics board identification saved in OTP in stm32mp2 checkboard function.

---

 board/st/stm32mp2/stm32mp2.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
board/st/stm32mp2/stm32mp2.c +23 -0
index 9a881583d904..aa7dd31996ea 100644
@@ -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;
 }
 
Signature · 1 line
2.25.1
Reviewed-by on v1 12/12
#26 lore raw

Re: [PATCH 12/12] board: st: stm32mp2: display the board identification

Quoted 50 lines · Patrick Delaunay

Add the display of the STMicroelectronics board identification saved in OTP in stm32mp2 checkboard function.

---

 board/st/stm32mp2/stm32mp2.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
board/st/stm32mp2/stm32mp2.c +16 -0
index 9a881583d904..aa7dd31996ea 100644
@@ -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",

board/st/stm32mp2/stm32mp2.c int checkboard(void) · line 55

Quoted 10 lines
board/st/stm32mp2/stm32mp2.c +7 -0
+				 otp >> 16,
+				 (otp >> 12) & 0xF,
+				 (otp >> 4) & 0xF,
+				 ((otp >> 8) & 0xF) - 1 + 'A',
+				 otp & 0xF);
+	}
+
 	return 0;
 }
 

Thanks
Patrice