Skip to contentSkip to conversation

Add support to boot TI K3 HSM M4 core

PATCH Superseded Beleswar Padhi 5 participants 29 messages May 6, 2025 – Nov 19, 2025

Subsystems (2)

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add support to boot TI K3 HSM M4 core

Some TI K3 SoCs like J721S2, and J784S4 have a HSM (High Security Module) M4F core in the Wakeup Voltage Domain which could be used to run secure services like Authentication. Boot flow for HSM M4 core is different than the general purpose M4F cores, and is as below:

1. Request control of HSM M4F remote processor.
2. Assert Reset on the HSM M4F remote processor.
3. Request Secure Entity to Authenticate and Load HSM firmware into core's internal SRAM memory region. For GP device, load the firmware manually into core's SRAM region.
4. Deassert Reset on the HSM M4F remote processor.
5. Release control of HSM M4F remote processor.

This series adds support to boot HSM M4 core from R5 SPL stage. The HSM firmware is packed inside the tispl.bin fit image. The firmware is unpacked into a temporary DDR address which is then used to load HSM core. The configs to boot HSM M4 core are disabled by default.

v2: Changelog:
[Andrew]:
1. Added support in SPL to load FIT images with no 'load' property.
2. Removed 'default = n' in CONFIG option.
3. Used __maybe_unused to decrease preprocessing.
4. Better error messages with error code.
[Udit]:
1. Added 'HSM' entries in enum at the last.
2. Added error condition in if-elseif-else ladder.
3. Hang System boot when HSM failed to boot properly.

Link to v1:
https://lore.kernel.org/all/[email protected]/

Test logs after enabling HSM boot configs:
https://gist.github.com/3V3RYONE/ad33683652c8c49e4fedab49f0493e79

Beleswar Padhi (7):
arm: mach-k3: Add config option for booting HSM core
spl: Use FIT data address as fallback when 'load' property is absent
arm: dts: k3-binman: Add template for packing HSM firmware
arm: dts: k3-{j721s2/j784s4}-binman: Pack HSM firmware inside
tispl.bin
arm: mach-k3: Use FIT image data addr as fallback if 'load' prop is
missing
arm: mach-k3: Explicitly identify TIFSSTUB images when discarding
buffers
arm: mach-k3: r5: common: Add support to boot HSM M4 core

 arch/arm/dts/k3-binman.dtsi        |   9 +++
 arch/arm/dts/k3-j721s2-binman.dtsi |  12 ++++
 arch/arm/dts/k3-j784s4-binman.dtsi |  14 ++++
 arch/arm/mach-k3/Kconfig           |   7 ++
 arch/arm/mach-k3/r5/common.c       | 111 +++++++++++++++++++++++++++--
 common/spl/spl_fit.c               |  16 ++++-
 6 files changed, 164 insertions(+), 5 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/7 arm: mach-k3: Add config option for booting HSM core

Some K3 SoCs like J721S2, and J784S4 have a HSM (High Security Module) M4F core in the Wakeup Voltage Domain which could be used to run secure services like Authentication. Add a config option which indicates that the SoC has a HSM core and the firmware for the core is available.

---
v2: Changelog:
1. Removed 'default = n' line from CONFIG.

Link to v1:
https://lore.kernel.org/all/[email protected]/

 arch/arm/mach-k3/Kconfig | 7 +++++++
 1 file changed, 7 insertions(+)
arch/arm/mach-k3/Kconfig +7 -0
index 1b8c0b1eb96..8448f23c053 100644
@@ -181,6 +181,13 @@ config K3_REMOTEPROC_PRU
 	imply REMOTEPROC_TI_PRU
 	default y if (SOC_K3_AM642 || SOC_K3_AM654)
 
+config K3_HSM_FW
+	bool "Load and Boot HSM core"
+	help
+	  Enabling this will indicate that the system has a HSM (High Security
+	  Module) M4 Core and the firmware for the core is present. When
+	  enabled, HSM core will be booted at R5 SPL execution time.
+
 if CPU_V7R
 source "arch/arm/mach-k3/r5/Kconfig"
 endif
Signature · 1 line
2.34.1
#2 lore raw

PATCH v2 2/7 spl: Use FIT data address as fallback when 'load' property is absent

In reply to Beleswar Padhi

In cases where the 'load' property is not defined in a FIT image node, fallback to using the data address returned by fit_image_get_data(). This enables FIT images to omit the 'load' property during FIT creation.

---
v2: Changelog:
1. New patch. Add support to load images without 'load' property.

 common/spl/spl_fit.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
common/spl/spl_fit.c +15 -1
index 86506d6905c..bf26f96c77b 100644
@@ -742,6 +742,8 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 {
 	struct spl_image_info image_info;
 	struct spl_fit_info ctx;
+	const void *fit_image_loadaddr;
+	size_t fit_image_size;
 	int node = -1;
 	int ret;
 	int index = 0;
@@ -832,7 +834,19 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 		if (firmware_node == node)
 			continue;
 
-		image_info.load_addr = 0;
+		/*
+		 * If the 'load' property is not present in the image node,
+		 * use the FIT image's data address as the fallback load
+		 * address. This allows flexibility in omitting the load address
+		 * during FIT creation time.
+		 */
+		ret = fit_image_get_data(ctx.fit, node,
+					 &fit_image_loadaddr, &fit_image_size);
+		if (ret < 0)
+			panic("Error accessing node = %d in FIT (%d)\n", node,
+			      ret);
+
+		image_info.load_addr = (ulong)fit_image_loadaddr;
 		ret = load_simple_fit(info, offset, &ctx, node, &image_info);
 		if (ret < 0 && ret != -EPERM) {
 			printf("%s: can't load image loadables index %d (ret = %d)\n",
Signature · 1 line
2.34.1
#3 lore raw

PATCH v2 3/7 arm: dts: k3-binman: Add template for packing HSM firmware

In reply to Beleswar Padhi

The HSM M4 core needs to be booted at R5 SPL stage so that it can be used for further Authentication and security services. Therefore, the firmware for the HSM core needs to be packed in tispl.bin fit image so that it can be used by R5 SPL to boot the HSM core.

Add a template for packing the HSM firmware in tispl.bin.

---
v2: Changelog:
1. Got rid of 'load' and 'entry' properties. Rely on U-Boot to set it.

Link to v1:
https://lore.kernel.org/all/[email protected]/

 arch/arm/dts/k3-binman.dtsi | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/arm/dts/k3-binman.dtsi +9 -0
index 5163161b94d..1c65ac44626 100644
@@ -297,6 +297,15 @@
 					};
 				};
 
+#ifdef CONFIG_K3_HSM_FW
+				hsm {
+					description = "HSM binary";
+					type = "standalone";
+					compression = "none";
+					os = "hsm";
+				};
+#endif
+
 				dm {
 					description = "DM binary";
 					type = "firmware";
Signature · 1 line
2.34.1
#4 lore raw

PATCH v2 4/7 arm: dts: k3-{j721s2/j784s4}-binman: Pack HSM firmware inside tispl.bin

In reply to Beleswar Padhi

Pack the HSM firmware in tispl.bin fit image so that it can be unloaded and used by R5 SPL to boot the HSM core. By default, point to the firmware for HS-SE device type. This needs to be changed to point to appropriate firmware when using a different device type.

---
v2: Changelog:
None to this patch.

Link to v1:
https://lore.kernel.org/all/[email protected]/

 arch/arm/dts/k3-j721s2-binman.dtsi | 12 ++++++++++++
 arch/arm/dts/k3-j784s4-binman.dtsi | 14 ++++++++++++++
 2 files changed, 26 insertions(+)
arch/arm/dts/k3-j721s2-binman.dtsi +12 -0
index 73af184d27e..9c8b29f53bb 100644
@@ -273,6 +273,14 @@
 
 					};
 				};
+#ifdef CONFIG_K3_HSM_FW
+				hsm {
+					hsm: blob-ext {
+						filename = "ti-hsm/hsm-demo-firmware-j721s2-hs.bin";
+					};
+				};
+#endif
+
 				dm {
 					ti-secure {
 						content = <&dm>;
@@ -306,7 +314,11 @@
 				conf-0 {
 					description = "k3-j721s2-common-proc-board";
 					firmware = "atf";
+#ifdef CONFIG_K3_HSM_FW
+					loadables = "hsm", "tee", "dm", "spl";
+#else
 					loadables = "tee", "dm", "spl";
+#endif
 					fdt = "fdt-0";
 				};
 			};
arch/arm/dts/k3-j784s4-binman.dtsi +14 -0
index cb1fbc65923..7c8e580a8a3 100644
@@ -159,6 +159,16 @@
 
 		fit {
 			images {
+
+#ifdef CONFIG_K3_HSM_FW
+				hsm {
+					hsm: blob-ext {
+						filename = "ti-hsm/hsm-demo-firmware-j784s4-hs.bin";
+					};
+				};
+
+#endif
+
 				dm {
 					ti-secure {
 						content = <&dm>;
@@ -194,7 +204,11 @@
 				conf-0 {
 					description = BOARD_DESCRIPTION;
 					firmware = "atf";
+#ifdef CONFIG_K3_HSM_FW
+					loadables = "hsm", "tee", "dm", "spl";
+#else
 					loadables = "tee", "dm", "spl";
+#endif
 					fdt = "fdt-0";
 				};
 			};
Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH v2 4/7] arm: dts: k3-{j721s2/j784s4}-binman: Pack HSM firmware inside tispl.bin

Quoted 23 lines · Beleswar Padhi

Pack the HSM firmware in tispl.bin fit image so that it can be unloaded and used by R5 SPL to boot the HSM core. By default, point to the firmware for HS-SE device type. This needs to be changed to point to appropriate firmware when using a different device type.

---
v2: Changelog:
None to this patch.

Link to v1:
https://lore.kernel.org/all/[email protected]/

 arch/arm/dts/k3-j721s2-binman.dtsi | 12 ++++++++++++
 arch/arm/dts/k3-j784s4-binman.dtsi | 14 ++++++++++++++
 2 files changed, 26 insertions(+)
arch/arm/dts/k3-j721s2-binman.dtsi +0 -0
index 73af184d27e..9c8b29f53bb 100644
@@ -273,6 +273,14 @@
 

arch/arm/dts/k3-j721s2-binman.dtsi line 283

Quoted 10 lines
arch/arm/dts/k3-j721s2-binman.dtsi +8 -0
 					};
 				};
+#ifdef CONFIG_K3_HSM_FW
+				hsm {
+					hsm: blob-ext {
+						filename = "ti-hsm/hsm-demo-firmware-j721s2-hs.bin";
+					};
+				};
+#endif
+

Why do we have the hsm binaries pre-signed? Having a common binary like the DM with signing using ti-secure might be a better option.

Regards,

Quoted 48 lines
arch/arm/dts/k3-j721s2-binman.dtsi +4 -0
 				dm {
 					ti-secure {
 						content = <&dm>;
@@ -306,7 +314,11 @@
 				conf-0 {
 					description = "k3-j721s2-common-proc-board";
 					firmware = "atf";
+#ifdef CONFIG_K3_HSM_FW
+					loadables = "hsm", "tee", "dm", "spl";
+#else
 					loadables = "tee", "dm", "spl";
+#endif
 					fdt = "fdt-0";
 				};
 			};
arch/arm/dts/k3-j784s4-binman.dtsi +14 -0
index cb1fbc65923..7c8e580a8a3 100644
@@ -159,6 +159,16 @@
 
 		fit {
 			images {
+
+#ifdef CONFIG_K3_HSM_FW
+				hsm {
+					hsm: blob-ext {
+						filename = "ti-hsm/hsm-demo-firmware-j784s4-hs.bin";
+					};
+				};
+
+#endif
+
 				dm {
 					ti-secure {
 						content = <&dm>;
@@ -194,7 +204,11 @@
 				conf-0 {
 					description = BOARD_DESCRIPTION;
 					firmware = "atf";
+#ifdef CONFIG_K3_HSM_FW
+					loadables = "hsm", "tee", "dm", "spl";
+#else
 					loadables = "tee", "dm", "spl";
+#endif
 					fdt = "fdt-0";
 				};
 			};
#6 lore raw

Re: [PATCH v2 4/7] arm: dts: k3-{j721s2/j784s4}-binman: Pack HSM firmware inside tispl.bin

Quoted 24 lines · Anshul Dalal
Quoted 23 lines · Beleswar Padhi

Pack the HSM firmware in tispl.bin fit image so that it can be unloaded and used by R5 SPL to boot the HSM core. By default, point to the firmware for HS-SE device type. This needs to be changed to point to appropriate firmware when using a different device type.

---
v2: Changelog:
None to this patch.

Link to v1:
https://lore.kernel.org/all/[email protected]/

  arch/arm/dts/k3-j721s2-binman.dtsi | 12 ++++++++++++
  arch/arm/dts/k3-j784s4-binman.dtsi | 14 ++++++++++++++
  2 files changed, 26 insertions(+)
arch/arm/dts/k3-j721s2-binman.dtsi +0 -0
index 73af184d27e..9c8b29f53bb 100644
@@ -273,6 +273,14 @@
 
Quoted 12 lines

arch/arm/dts/k3-j721s2-binman.dtsi line 283

Quoted 10 lines
arch/arm/dts/k3-j721s2-binman.dtsi +8 -0
  					};
  				};
+#ifdef CONFIG_K3_HSM_FW
+				hsm {
+					hsm: blob-ext {
+						filename = "ti-hsm/hsm-demo-firmware-j721s2-hs.bin";
+					};
+				};
+#endif
+

Why do we have the hsm binaries pre-signed? Having a common binary like the DM with signing using ti-secure might be a better option.

Andrew can correct me if I am wrong,
HSM is meant to run secure software stack and services like Authentication etc. It is a +1 to TIFS. To establish ROT, we need the HSM binary to be encrypted, and authenticated by TIFS first before it can do stuff by itself. DM is not a secure entity, so signing the image doesn't make sense for me.

Quoted 51 lines

Regards,

Quoted 48 lines
arch/arm/dts/k3-j721s2-binman.dtsi +4 -0
  				dm {
  					ti-secure {
  						content = <&dm>;
@@ -306,7 +314,11 @@
  				conf-0 {
  					description = "k3-j721s2-common-proc-board";
  					firmware = "atf";
+#ifdef CONFIG_K3_HSM_FW
+					loadables = "hsm", "tee", "dm", "spl";
+#else
  					loadables = "tee", "dm", "spl";
+#endif
  					fdt = "fdt-0";
  				};
  			};
arch/arm/dts/k3-j784s4-binman.dtsi +14 -0
index cb1fbc65923..7c8e580a8a3 100644
@@ -159,6 +159,16 @@
 
  		fit {
  			images {
+
+#ifdef CONFIG_K3_HSM_FW
+				hsm {
+					hsm: blob-ext {
+						filename = "ti-hsm/hsm-demo-firmware-j784s4-hs.bin";
+					};
+				};
+
+#endif
+
  				dm {
  					ti-secure {
  						content = <&dm>;
@@ -194,7 +204,11 @@
  				conf-0 {
  					description = BOARD_DESCRIPTION;
  					firmware = "atf";
+#ifdef CONFIG_K3_HSM_FW
+					loadables = "hsm", "tee", "dm", "spl";
+#else
  					loadables = "tee", "dm", "spl";
+#endif
  					fdt = "fdt-0";
  				};
  			};
#7 lore raw

Re: [PATCH v2 4/7] arm: dts: k3-{j721s2/j784s4}-binman: Pack HSM firmware inside tispl.bin

Quoted 39 lines · Beleswar Prasad Padhi
Quoted 27 lines · Anshul Dalal
Quoted 26 lines · Beleswar Padhi

Pack the HSM firmware in tispl.bin fit image so that it can be unloaded and used by R5 SPL to boot the HSM core. By default, point to the firmware for HS-SE device type. This needs to be changed to point to appropriate firmware when using a different device type.

---
v2: Changelog:
None to this patch.

Link to v1:
https://lore.kernel.org/all/[email protected]/

  arch/arm/dts/k3-j721s2-binman.dtsi | 12 ++++++++++++ arch/arm/dts/k3-j784s4-binman.dtsi | 14 ++++++++++++++

  2 files changed, 26 insertions(+)
arch/arm/dts/k3-j721s2-binman.dtsi +2 -0
index 73af184d27e..9c8b29f53bb 100644
@@ -273,6 +273,14 @@
                       };
                   };
+#ifdef CONFIG_K3_HSM_FW
+                hsm {
Quoted 8 lines

arch/arm/dts/k3-j721s2-binman.dtsi line 283

Quoted 6 lines
arch/arm/dts/k3-j721s2-binman.dtsi +6 -0
+                    hsm: blob-ext {
+                        filename = "ti-hsm/hsm-demo-firmware-j721s2-hs.bin";
+                    };
+                };
+#endif
+

Why do we have the hsm binaries pre-signed? Having a common binary like the DM with signing using ti-secure might be a better option.

Quoted 3 lines

Andrew can correct me if I am wrong,
HSM is meant to run secure software stack and services like Authentication etc. It is a +1 to TIFS. To establish ROT, we need the HSM binary to be encrypted, and authenticated by TIFS first before it can do stuff by itself. DM is not a secure entity, so signing the image doesn't make sense for me.

I think Anshul is not suggesting that the HSM binary be unencrypted/unauthenticated. Rather that the encrypting/signing be done here in binman like we do with TF-A/OP-TEE. (which both are part trusted images to be loaded by TIFS).

To that suggestion I agree, the customer will be doing the signing of this binary, right? If so then since all other customer signing is done as part of binman, it makes sense to also sign HSM firmware here too.

Andrew

Quoted 50 lines
Quoted 50 lines

Regards,

Quoted 47 lines
arch/arm/dts/k3-j721s2-binman.dtsi +4 -0
                   dm {
                       ti-secure {
                           content = <&dm>;
@@ -306,7 +314,11 @@
                   conf-0 {
                       description = "k3-j721s2-common-proc-board";
                       firmware = "atf";
+#ifdef CONFIG_K3_HSM_FW
+                    loadables = "hsm", "tee", "dm", "spl";
+#else
                       loadables = "tee", "dm", "spl";
+#endif
                       fdt = "fdt-0";
                   };
               };
arch/arm/dts/k3-j784s4-binman.dtsi +14 -0
index cb1fbc65923..7c8e580a8a3 100644
@@ -159,6 +159,16 @@
           fit {
               images {
+
+#ifdef CONFIG_K3_HSM_FW
+                hsm {
+                    hsm: blob-ext {
+                        filename = "ti-hsm/hsm-demo-firmware-j784s4-hs.bin";
+                    };
+                };
+
+#endif
+
                   dm {
                       ti-secure {
                           content = <&dm>;
@@ -194,7 +204,11 @@
                   conf-0 {
                       description = BOARD_DESCRIPTION;
                       firmware = "atf";
+#ifdef CONFIG_K3_HSM_FW
+                    loadables = "hsm", "tee", "dm", "spl";
+#else
                       loadables = "tee", "dm", "spl";
+#endif
                       fdt = "fdt-0";
                   };
               };
#8 lore raw

Re: [PATCH v2 4/7] arm: dts: k3-{j721s2/j784s4}-binman: Pack HSM firmware inside tispl.bin

Quoted 44 lines · Andrew Davis
Quoted 39 lines · Beleswar Prasad Padhi
Quoted 27 lines · Anshul Dalal
Quoted 26 lines · Beleswar Padhi

Pack the HSM firmware in tispl.bin fit image so that it can be unloaded and used by R5 SPL to boot the HSM core. By default, point to the firmware for HS-SE device type. This needs to be changed to point to appropriate firmware when using a different device type.

---
v2: Changelog:
None to this patch.

Link to v1:
https://lore.kernel.org/all/[email protected]/

  arch/arm/dts/k3-j721s2-binman.dtsi | 12 ++++++++++++ arch/arm/dts/k3-j784s4-binman.dtsi | 14 ++++++++++++++

  2 files changed, 26 insertions(+)
arch/arm/dts/k3-j721s2-binman.dtsi +2 -0
index 73af184d27e..9c8b29f53bb 100644
@@ -273,6 +273,14 @@
                       };
                   };
+#ifdef CONFIG_K3_HSM_FW
+                hsm {
Quoted 8 lines

arch/arm/dts/k3-j721s2-binman.dtsi line 283

Quoted 6 lines
arch/arm/dts/k3-j721s2-binman.dtsi +6 -0
+                    hsm: blob-ext {
+                        filename = "ti-hsm/hsm-demo-firmware-j721s2-hs.bin";
+                    };
+                };
+#endif
+

Why do we have the hsm binaries pre-signed? Having a common binary like the DM with signing using ti-secure might be a better option.

Quoted 3 lines

Andrew can correct me if I am wrong,
HSM is meant to run secure software stack and services like Authentication etc. It is a +1 to TIFS. To establish ROT, we need the HSM binary to be encrypted, and authenticated by TIFS first before it can do stuff by itself. DM is not a secure entity, so signing the image doesn't make sense for me.

Quoted 8 lines

I think Anshul is not suggesting that the HSM binary be unencrypted/unauthenticated. Rather that the encrypting/signing be done here in binman like we do with TF-A/OP-TEE. (which both are part trusted images to be loaded by TIFS).

To that suggestion I agree, the customer will be doing the signing of this binary, right? If so then since all other customer signing is done as part of binman, it makes sense to also sign HSM firmware here too.

Yeah, that is what I was going for. With that change it could be possible to also have a single binary for all platforms (gp, hs, hs-fs) in ti-linux-firmware?

Also, why are we not adding an unsigned variant of the hsm binary in tispl.bin_unsigned?

[snip]

#9 lore raw

Re: [PATCH v2 4/7] arm: dts: k3-{j721s2/j784s4}-binman: Pack HSM firmware inside tispl.bin

In reply to Andrew Davis
Quoted 48 lines · Andrew Davis
Quoted 39 lines · Beleswar Prasad Padhi
Quoted 27 lines · Anshul Dalal
Quoted 26 lines · Beleswar Padhi

Pack the HSM firmware in tispl.bin fit image so that it can be unloaded and used by R5 SPL to boot the HSM core. By default, point to the firmware for HS-SE device type. This needs to be changed to point to appropriate firmware when using a different device type.

---
v2: Changelog:
None to this patch.

Link to v1:
https://lore.kernel.org/all/[email protected]/

  arch/arm/dts/k3-j721s2-binman.dtsi | 12 ++++++++++++ arch/arm/dts/k3-j784s4-binman.dtsi | 14 ++++++++++++++

  2 files changed, 26 insertions(+)
arch/arm/dts/k3-j721s2-binman.dtsi +2 -0
index 73af184d27e..9c8b29f53bb 100644
@@ -273,6 +273,14 @@
                       };
                   };
+#ifdef CONFIG_K3_HSM_FW
+                hsm {
Quoted 8 lines

arch/arm/dts/k3-j721s2-binman.dtsi line 283

Quoted 6 lines
arch/arm/dts/k3-j721s2-binman.dtsi +6 -0
+                    hsm: blob-ext {
+                        filename = "ti-hsm/hsm-demo-firmware-j721s2-hs.bin";
+                    };
+                };
+#endif
+

Why do we have the hsm binaries pre-signed? Having a common binary like the DM with signing using ti-secure might be a better option.

Quoted 3 lines

Andrew can correct me if I am wrong,
HSM is meant to run secure software stack and services like Authentication etc. It is a +1 to TIFS. To establish ROT, we need the HSM binary to be encrypted, and authenticated by TIFS first before it can do stuff by itself. DM is not a secure entity, so signing the image doesn't make sense for me.

I think Anshul is not suggesting that the HSM binary be unencrypted/unauthenticated. Rather that the encrypting/signing be done here in binman like we do with TF-A/OP-TEE. (which both are part trusted images to be loaded by TIFS).

Quoted 5 lines

To that suggestion I agree, the customer will be doing the signing of this binary, right? If so then since all other customer signing is done as part of binman, it makes sense to also sign HSM firmware here too.

Andrew

Yeah, that is what I was going for. With that change it could be possible to also have a single binary for all platforms (gp, hs, hs-fs) in ti-linux-firmware?

Also, why are we not adding an unsigned variant of the hsm binary in tispl.bin_unsigned?

[snip]

#10 lore raw

Re: [PATCH v2 4/7] arm: dts: k3-{j721s2/j784s4}-binman: Pack HSM firmware inside tispl.bin

Quoted 50 lines · Anshul Dalal
Quoted 49 lines · Andrew Davis
Quoted 37 lines · Beleswar Prasad Padhi
Quoted 27 lines · Anshul Dalal
Quoted 26 lines · Beleswar Padhi

Pack the HSM firmware in tispl.bin fit image so that it can be unloaded and used by R5 SPL to boot the HSM core. By default, point to the firmware for HS-SE device type. This needs to be changed to point to appropriate firmware when using a different device type.

---
v2: Changelog:
None to this patch.

Link to v1:
https://lore.kernel.org/all/[email protected]/

   arch/arm/dts/k3-j721s2-binman.dtsi | 12 ++++++++++++
   arch/arm/dts/k3-j784s4-binman.dtsi | 14 ++++++++++++++
   2 files changed, 26 insertions(+)
arch/arm/dts/k3-j721s2-binman.dtsi +2 -0
index 73af184d27e..9c8b29f53bb 100644
@@ -273,6 +273,14 @@
                       };
                   };
+#ifdef CONFIG_K3_HSM_FW
+                hsm {
Quoted 8 lines

arch/arm/dts/k3-j721s2-binman.dtsi line 283

Quoted 6 lines
arch/arm/dts/k3-j721s2-binman.dtsi +6 -0
+                    hsm: blob-ext {
+                        filename = "ti-hsm/hsm-demo-firmware-j721s2-hs.bin";
+                    };
+                };
+#endif
+

Why do we have the hsm binaries pre-signed? Having a common binary like the DM with signing using ti-secure might be a better option.

Quoted 3 lines

Andrew can correct me if I am wrong,
HSM is meant to run secure software stack and services like Authentication etc. It is a +1 to TIFS. To establish ROT, we need the HSM binary to be encrypted, and authenticated by TIFS first before it can do stuff by itself. DM is not a secure entity, so signing the image doesn't make sense for me.

I think Anshul is not suggesting that the HSM binary be unencrypted/unauthenticated. Rather that the encrypting/signing be done here in binman like we do with TF-A/OP-TEE. (which both are part trusted images to be loaded by TIFS).

To that suggestion I agree, the customer will be doing the signing of this binary, right? If so then since all other customer signing is done as part of binman, it makes sense to also sign HSM firmware here too.

Quoted 7 lines
Quoted 1 line

Andrew

Yeah, that is what I was going for. With that change it could be possible to also have a single binary for all platforms (gp, hs, hs-fs) in ti-linux-firmware?

Also, why are we not adding an unsigned variant of the hsm binary in tispl.bin_unsigned?

What's the use case for that? I think we established that HSM won't be used unsigned. So it will just bloat the FIT and never be used.

#11 lore raw

Re: [PATCH v2 4/7] arm: dts: k3-{j721s2/j784s4}-binman: Pack HSM firmware inside tispl.bin

Quoted 57 lines · Beleswar Prasad Padhi
Quoted 55 lines · Anshul Dalal
Quoted 45 lines · Andrew Davis
Quoted 37 lines · Beleswar Prasad Padhi
Quoted 27 lines · Anshul Dalal
Quoted 26 lines · Beleswar Padhi

Pack the HSM firmware in tispl.bin fit image so that it can be unloaded and used by R5 SPL to boot the HSM core. By default, point to the firmware for HS-SE device type. This needs to be changed to point to appropriate firmware when using a different device type.

---
v2: Changelog:
None to this patch.

Link to v1:
https://lore.kernel.org/all/[email protected]/

   arch/arm/dts/k3-j721s2-binman.dtsi | 12 ++++++++++++ arch/arm/dts/k3-j784s4-binman.dtsi | 14 ++++++++++++++

   2 files changed, 26 insertions(+)
arch/arm/dts/k3-j721s2-binman.dtsi +2 -0
index 73af184d27e..9c8b29f53bb 100644
@@ -273,6 +273,14 @@
                        };
                    };
+#ifdef CONFIG_K3_HSM_FW
+                hsm {
Quoted 8 lines

arch/arm/dts/k3-j721s2-binman.dtsi line 283

Quoted 6 lines
arch/arm/dts/k3-j721s2-binman.dtsi +6 -0
+                    hsm: blob-ext {
+                        filename = "ti-hsm/hsm-demo-firmware-j721s2-hs.bin";
+                    };
+                };
+#endif
+

Why do we have the hsm binaries pre-signed? Having a common binary like the DM with signing using ti-secure might be a better option.

Quoted 3 lines

Andrew can correct me if I am wrong,
HSM is meant to run secure software stack and services like Authentication etc. It is a +1 to TIFS. To establish ROT, we need the HSM binary to be encrypted, and authenticated by TIFS first before it can do stuff by itself. DM is not a secure entity, so signing the image doesn't make sense for me.

I think Anshul is not suggesting that the HSM binary be unencrypted/unauthenticated. Rather that the encrypting/signing be done here in binman like we do with TF-A/OP-TEE. (which both are part trusted images to be loaded by TIFS).

Quoted 5 lines

To that suggestion I agree, the customer will be doing the signing of this binary, right? If so then since all other customer signing is done as part of binman, it makes sense to also sign HSM firmware here too.

Andrew

Yeah, that is what I was going for. With that change it could be possible to also have a single binary for all platforms (gp, hs, hs-fs) in ti-linux-firmware?

Quoted 6 lines
Quoted 2 lines

Also, why are we not adding an unsigned variant of the hsm binary in tispl.bin_unsigned?

What's the use case for that? I think we established that HSM won't be used unsigned. So it will just bloat the FIT and never be used.

We ship an unsigned HSM firmware for GP devices[0], and in patch [7/7] of this series you add support for loading that unsigned HSM firmware. Seems odd to then not ever package it here in binman and claim we will never use it?

Andrew

[0] https://git.ti.com/cgit/processor-firmware/ti-linux-firmware/tree/ti-hsm?h=ti-linux-firmware

#12 lore raw

Re: [PATCH v2 4/7] arm: dts: k3-{j721s2/j784s4}-binman: Pack HSM firmware inside tispl.bin

Hi Andrew,

Quoted 62 lines · Andrew Davis
Quoted 61 lines · Beleswar Prasad Padhi
Quoted 57 lines · Anshul Dalal
Quoted 45 lines · Andrew Davis
Quoted 37 lines · Beleswar Prasad Padhi
Quoted 27 lines · Anshul Dalal
Quoted 26 lines · Beleswar Padhi

Pack the HSM firmware in tispl.bin fit image so that it can be unloaded and used by R5 SPL to boot the HSM core. By default, point to the firmware for HS-SE device type. This needs to be changed to point to appropriate firmware when using a different device type.

---
v2: Changelog:
None to this patch.

Link to v1:
https://lore.kernel.org/all/[email protected]/

   arch/arm/dts/k3-j721s2-binman.dtsi | 12 ++++++++++++ arch/arm/dts/k3-j784s4-binman.dtsi | 14 ++++++++++++++

   2 files changed, 26 insertions(+)
arch/arm/dts/k3-j721s2-binman.dtsi +2 -0
index 73af184d27e..9c8b29f53bb 100644
@@ -273,6 +273,14 @@
                        };
                    };
+#ifdef CONFIG_K3_HSM_FW
+                hsm {
Quoted 8 lines

arch/arm/dts/k3-j721s2-binman.dtsi line 282

Quoted 6 lines
arch/arm/dts/k3-j721s2-binman.dtsi +6 -0
+                    hsm: blob-ext {
+                        filename = "ti-hsm/hsm-demo-firmware-j721s2-hs.bin";
+                    };
+                };
+#endif
+

Why do we have the hsm binaries pre-signed? Having a common binary like the DM with signing using ti-secure might be a better option.

Quoted 3 lines

Andrew can correct me if I am wrong,
HSM is meant to run secure software stack and services like Authentication etc. It is a +1 to TIFS. To establish ROT, we need the HSM binary to be encrypted, and authenticated by TIFS first before it can do stuff by itself. DM is not a secure entity, so signing the image doesn't make sense for me.

I think Anshul is not suggesting that the HSM binary be unencrypted/unauthenticated. Rather that the encrypting/signing be done here in binman like we do with TF-A/OP-TEE. (which both are part trusted images to be loaded by TIFS).

Quoted 5 lines

To that suggestion I agree, the customer will be doing the signing of this binary, right? If so then since all other customer signing is done as part of binman, it makes sense to also sign HSM firmware here too.

Andrew

Yeah, that is what I was going for. With that change it could be possible to also have a single binary for all platforms (gp, hs, hs-fs) in ti-linux-firmware?

Also, why are we not adding an unsigned variant of the hsm binary in tispl.bin_unsigned?

Quoted 5 lines
Quoted 2 lines

What's the use case for that? I think we established that HSM won't be used unsigned. So it will just bloat the FIT and never be used.

We ship an unsigned HSM firmware for GP devices[0], and in patch [7/7] of this series you add support for loading that unsigned HSM firmware.

That is a System Firmware limitation; i.e., no support of loading HSM FW for GP devices. We are providing a workaround for that by manually loading it from MCU R5 core. Besides, HSM SRAM should not even be accessible by MCU R5F core in the first place. HSM should only be accessible & loaded by TIFS. So once the SRAM is firewalled, this flow for loading GP bins won't work, and SYSFW will somehow have to support that, or we just give up unsigned bin load support.

Quoted 2 lines

Seems odd to
then not ever package it here in binman and claim we will never use it?

IMHO, users can "choose" to package that unsigned HSM bin and boot it in the current flow. Please let me know, if you are okay with packaging an unsigned HSM binary "by default", given the above caveat?

Thanks,
Beleswar

Quoted 4 lines

Andrew

[0] https://git.ti.com/cgit/processor-firmware/ti-linux-firmware/tree/ti-hsm?h=ti-linux-firmware

#13 lore raw

Re: [PATCH v2 4/7] arm: dts: k3-{j721s2/j784s4}-binman: Pack HSM firmware inside tispl.bin

In reply to Anshul Dalal

Hi Andrew, Anshul, all

Reviving this old thread, this is ready for a re-spin now as unsigned HSM firmware is available. Please see below.

Quoted 46 lines · Anshul Dalal
Quoted 45 lines · Andrew Davis
Quoted 37 lines · Beleswar Prasad Padhi
Quoted 27 lines · Anshul Dalal
Quoted 26 lines · Beleswar Padhi

Pack the HSM firmware in tispl.bin fit image so that it can be unloaded and used by R5 SPL to boot the HSM core. By default, point to the firmware for HS-SE device type. This needs to be changed to point to appropriate firmware when using a different device type.

---
v2: Changelog:
None to this patch.

Link to v1:
https://lore.kernel.org/all/[email protected]/

  arch/arm/dts/k3-j721s2-binman.dtsi | 12 ++++++++++++ arch/arm/dts/k3-j784s4-binman.dtsi | 14 ++++++++++++++

  2 files changed, 26 insertions(+)
arch/arm/dts/k3-j721s2-binman.dtsi +2 -0
index 73af184d27e..9c8b29f53bb 100644
@@ -273,6 +273,14 @@
                       };
                   };
+#ifdef CONFIG_K3_HSM_FW
+                hsm {
Quoted 8 lines

arch/arm/dts/k3-j721s2-binman.dtsi line 283

Quoted 6 lines
arch/arm/dts/k3-j721s2-binman.dtsi +6 -0
+                    hsm: blob-ext {
+                        filename = "ti-hsm/hsm-demo-firmware-j721s2-hs.bin";
+                    };
+                };
+#endif
+

Why do we have the hsm binaries pre-signed? Having a common binary like the DM with signing using ti-secure might be a better option.

Quoted 3 lines

Andrew can correct me if I am wrong,
HSM is meant to run secure software stack and services like Authentication etc. It is a +1 to TIFS. To establish ROT, we need the HSM binary to be encrypted, and authenticated by TIFS first before it can do stuff by itself. DM is not a secure entity, so signing the image doesn't make sense for me.

I think Anshul is not suggesting that the HSM binary be unencrypted/unauthenticated. Rather that the encrypting/signing be done here in binman like we do with TF-A/OP-TEE. (which both are part trusted images to be loaded by TIFS).

Quoted 8 lines
Quoted 5 lines

To that suggestion I agree, the customer will be doing the signing of this binary, right? If so then since all other customer signing is done as part of binman, it makes sense to also sign HSM firmware here too.

Andrew

Yeah, that is what I was going for. With that change it could be possible to also have a single binary for all platforms (gp, hs, hs-fs) in ti-linux-firmware?

I don't think its possible to have a single HSM firmware for all device types currently. GP devices might not use all security IPs which the hs-se device uses. So having a common firmware would mean we sacrifice using those secure services on a HS-SE capable device as well. Of course, whenever we can support a single TIFS binary for all device types, we can support a single HSM too. I have copied firmware folks here (@Tanu, @Saurabh) who can help in answering this query better, if any follow up.

But yes, we do have the unsigned HSM firmware for each device type now[0]: GP, HS, HS-FS. Which means we can add the signing support here in U-Boot to match the flow with other components like ATF/OPTEE/DM etc.

So, I will re-spin the v3 for this patch series with following changes:
1. Dedicated remoteproc driver for booting HSM M4 core.
2. Signing HSM binary in binman/U-Boot.
3. Other minor code comments from Anshul/Andrew.

Note: We will continue to pack the HS-SE variant of HSM firmware in tispl.bin fit image by default. Any other variant can be packaged by changing the path in binman node to corresponding firmware blob.

Let me know, if you have any comments over the above, otherwise I will send out an v3 soon. Thanks!

[0]: https://git.ti.com/cgit/processor-firmware/ti-linux-firmware/commit/ti-hsm?h=ti-linux-firmware&id=560c226d763018de7adb892fc215b31286cc2831

Thanks,
Beleswar

#14 lore raw

PATCH v2 5/7 arm: mach-k3: Use FIT image data addr as fallback if 'load' prop is missing

In reply to Beleswar Padhi

It is possible for FIT Images to skip mentioning the pre-defined 'load' address property. In those cases, SPL uses the actual address of the FIT Image data as the fallback load address. Use this FIT data address for referencing the image when the 'load' property is missing.

---
v2: Changelog:
1. New patch. Fetch FDT Data addr for accessing image if 'load' prop is not present in node.

 arch/arm/mach-k3/r5/common.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)
arch/arm/mach-k3/r5/common.c +21 -2
index 0b6604039f3..da5184e615c 100644
@@ -327,12 +327,15 @@ void board_fit_image_post_process(const void *fit, int node, void **p_image,
 				  size_t *p_size)
 {
 	int len;
-	int i;
+	int i, ret;
 	const char *os;
-	u32 addr;
+	u32 addr, load_addr;
+	const void *fit_image_loadaddr;
+	size_t fit_image_size;
 
 	os = fdt_getprop(fit, node, "os", &len);
 	addr = fdt_getprop_u32_default_node(fit, node, 0, "entry", -1);
+	load_addr = fdt_getprop_u32_default_node(fit, node, 0, "load", -1);
 
 	debug("%s: processing image: addr=%x, size=%d, os=%s\n", __func__,
 	      addr, *p_size, os);
@@ -341,6 +344,22 @@ void board_fit_image_post_process(const void *fit, int node, void **p_image,
 		if (!strcmp(os, image_os_match[i])) {
 			fit_image_info[i].image_start = addr;
 			fit_image_info[i].image_len = *p_size;
+			/*
+			 * If the 'load' property is missing in the FIT image,
+			 * fall back to using the actual in-memory address of
+			 * the FIT image data.
+			 */
+			if (load_addr == -1) {
+				ret = fit_image_get_data(fit, node,
+							 &fit_image_loadaddr,
+							 &fit_image_size);
+				if (ret < 0)
+					panic("Error accessing node os = %s in FIT (%d)\n",
+					      os, ret);
+				fit_image_info[i].load = (ulong)fit_image_loadaddr;
+			} else {
+				fit_image_info[i].load = load_addr;
+			}
 			debug("%s: matched image for ID %d\n", __func__, i);
 			break;
 		}
Signature · 1 line
2.34.1
#15 lore raw

PATCH v2 6/7 arm: mach-k3: Explicitly identify TIFSSTUB images when discarding buffers

In reply to Beleswar Padhi

The board_fit_image_post_process() function assumes that all TIFSSTUB images appear at the end of the image_os_match[] array by using the condition:

i > IMAGE_ID_DM_FW

However, this assumption breaks when new image types are appended to the enum and the array, causing unintended image types to match this condition and having their buffer sizes incorrectly set to 0 with:

	*p_size = 0

To avoid this issue, replace the range-based check with an explicit match for TIFSSTUB image IDs.

---
v2: Changelog:
1. New patch. Fixes condition to allow new images to be added at the end of the enum.

 arch/arm/mach-k3/r5/common.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/arm/mach-k3/r5/common.c +3 -1
index da5184e615c..81fc67a0023 100644
@@ -365,7 +365,9 @@ void board_fit_image_post_process(const void *fit, int node, void **p_image,
 		}
 	}
 
-	if (i < IMAGE_AMT && i > IMAGE_ID_DM_FW) {
+	if (i < IMAGE_AMT &&
+	    (i == IMAGE_ID_TIFSSTUB_HS || i == IMAGE_ID_TIFSSTUB_FS ||
+	     i == IMAGE_ID_T)) {
 		int device_type = get_device_type();
 
 		if ((device_type == K3_DEVICE_TYPE_HS_SE &&
Signature · 1 line
2.34.1
#16 lore raw

PATCH v2 7/7 arm: mach-k3: r5: common: Add support to boot HSM M4 core

In reply to Beleswar Padhi

The tispl.bin fit image is packed with the HSM firmware image. Populate the "os" info of the image so that it can be detected and used to load the HSM core. Further, invoke the load and boot of HSM core at R5 SPL stage. Boot flow for HSM M4 core is as below:

1. Request control of HSM M4F remote processor.
2. Assert Reset on the HSM M4F remote processor.
3. For HS devices, Request Secure Entity to Authenticate and Load HSM firmware into core's internal SRAM memory region. For GP devices, load the unsigned firmware manually.
4. Deassert Reset on the HSM M4F remote processor.
5. Release control of HSM M4F remote processor.

---
v2: Changelog:
1. Hang system boot if HSM firmware failed to boot.
2. __maybe_unused to decrease preprocessor usage.
3. Better error messages with return code.
4. Added Error case in if-elseif-else ladder.

Note:
#define PROC_ID_HSM_M4F seems to have extra tab in the diff/patch. But when patch gets applied in file, all of them have consistent tabs.

Link to v1:
https://lore.kernel.org/all/[email protected]

 arch/arm/mach-k3/r5/common.c | 84 +++++++++++++++++++++++++++++++++++-
 1 file changed, 83 insertions(+), 1 deletion(-)
arch/arm/mach-k3/r5/common.c +83 -1
index 81fc67a0023..1aa3869cec2 100644
@@ -15,9 +15,14 @@
 #include <spl.h>
 #include <remoteproc.h>
 #include <elf.h>
+#include <cpu_func.h>
 
 #include "../common.h"
 
+#define PROC_BOOT_CTRL_RESET_FLAG_HSM_M4	0x00000001
+#define HSM_SRAM0_0_ADDR			0x43C00000
+#define PROC_ID_HSM_M4F				0x00000080
+
 #if IS_ENABLED(CONFIG_SYS_K3_SPL_ATF)
 enum {
 	IMAGE_ID_ATF,
@@ -27,6 +32,7 @@ enum {
 	IMAGE_ID_TIFSSTUB_HS,
 	IMAGE_ID_TIFSSTUB_FS,
 	IMAGE_ID_T,
+	IMAGE_ID_HSM,
 	IMAGE_AMT,
 };
 
@@ -39,6 +45,7 @@ static const char *image_os_match[IMAGE_AMT] = {
 	"tifsstub-hs",
 	"tifsstub-fs",
 	"tifsstub-gp",
+	"hsm",
 };
 #endif
 
@@ -136,6 +143,73 @@ void release_resources_for_core_shutdown(void)
 	}
 }
 
+static int __maybe_unused boot_hsm_core(void)
+{
+	struct ti_sci_handle *ti_sci = get_ti_sci_handle();
+	struct ti_sci_proc_ops *proc_ops = &ti_sci->ops.proc_ops;
+	u64 hsm_image_addr;
+	u32 hsm_image_size;
+	int device_type, ret;
+
+	hsm_image_addr = (u64)fit_image_info[IMAGE_ID_HSM].load;
+	hsm_image_size = (u32)fit_image_info[IMAGE_ID_HSM].image_len;
+
+	/* Request Control of Remote Processor */
+	ret = proc_ops->proc_request(ti_sci, PROC_ID_HSM_M4F);
+	if (ret) {
+		printf("Unable to request HSM processor control: %d\n", ret);
+		return ret;
+	}
+
+	/* Put the remote processor into reset */
+	ret = proc_ops->set_proc_boot_ctrl(ti_sci, PROC_ID_HSM_M4F,
+					   PROC_BOOT_CTRL_RESET_FLAG_HSM_M4, 0);
+	if (ret) {
+		printf("Unable to Halt HSM core: %d\n", ret);
+		goto release_proc_ctrl;
+	}
+
+	/*
+	 * Load the HSM firmware into core's internal memory.
+	 *
+	 * In case of HS device types, request secure entity to authenticate and
+	 * load the HSM firmware into the core memory.
+	 * In case of GP device types, copy the HSM firmware into the core
+	 * memory manually.
+	 */
+	device_type = get_device_type();
+	if (device_type == K3_DEVICE_TYPE_HS_SE ||
+	    device_type == K3_DEVICE_TYPE_HS_FS) {
+		ret = proc_ops->proc_auth_boot_image(ti_sci, &hsm_image_addr,
+						     &hsm_image_size);
+		if (ret) {
+			printf("Unable to Authenticate and Boot HSM image; ret = %d\n",
+			       ret);
+			goto release_proc_ctrl;
+		}
+	} else if (device_type == K3_DEVICE_TYPE_GP) {
+		debug("Loading HSM GP binary into SRAM0_0\n");
+		memcpy((void *)HSM_SRAM0_0_ADDR, (void *)(u32)hsm_image_addr,
+		       hsm_image_size);
+		flush_dcache_range(HSM_SRAM0_0_ADDR,
+				   HSM_SRAM0_0_ADDR + hsm_image_size);
+	} else {
+		printf("Invalid Device Type\n");
+		return -EINVAL;
+	}
+
+	/* Release the reset from the remote processor*/
+	ret = proc_ops->set_proc_boot_ctrl(ti_sci, PROC_ID_HSM_M4F, 0,
+					   PROC_BOOT_CTRL_RESET_FLAG_HSM_M4);
+	if (ret)
+		printf("Unable to Run HSM core: %d\n", ret);
+
+release_proc_ctrl:
+	/* Release Control of Remote Processor */
+	proc_ops->proc_release(ti_sci, PROC_ID_HSM_M4F);
+	return ret;
+}
+
 void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
 {
 	typedef void __noreturn (*image_entry_noargs_t)(void);
@@ -157,6 +231,14 @@ void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
 				     &loadaddr);
 	}
 
+#if IS_ENABLED(CONFIG_K3_HSM_FW)
+	ret = boot_hsm_core();
+	if (ret)
+		panic("HSM core failed to boot, %d\n", ret);
+	else
+		printf("Successfully booted HSM core\n");
+#endif
+
 	/*
 	 * It is assumed that remoteproc device 1 is the corresponding
 	 * Cortex-A core which runs ATF. Make sure DT reflects the same.
@@ -388,7 +470,7 @@ void board_fit_image_post_process(const void *fit, int node, void **p_image,
 	 * Only DM and the DTBs are being authenticated here,
 	 * rest will be authenticated when A72 cluster is up
 	 */
-	if ((i != IMAGE_ID_ATF) && (i != IMAGE_ID_OPTEE)) {
+	if (i != IMAGE_ID_ATF && i != IMAGE_ID_OPTEE && i != IMAGE_ID_HSM) {
 		ti_secure_image_check_binary(p_image, p_size);
 		ti_secure_image_post_process(p_image, p_size);
 	} else {
Signature · 1 line
2.34.1
#17 lore raw

Re: [PATCH v2 7/7] arm: mach-k3: r5: common: Add support to boot HSM M4 core

Quoted 52 lines · Beleswar Padhi

The tispl.bin fit image is packed with the HSM firmware image. Populate the "os" info of the image so that it can be detected and used to load the HSM core. Further, invoke the load and boot of HSM core at R5 SPL stage. Boot flow for HSM M4 core is as below:

1. Request control of HSM M4F remote processor.
2. Assert Reset on the HSM M4F remote processor.
3. For HS devices, Request Secure Entity to Authenticate and Load HSM firmware into core's internal SRAM memory region. For GP devices, load the unsigned firmware manually.
4. Deassert Reset on the HSM M4F remote processor.
5. Release control of HSM M4F remote processor.

---
v2: Changelog:
1. Hang system boot if HSM firmware failed to boot.
2. __maybe_unused to decrease preprocessor usage.
3. Better error messages with return code.
4. Added Error case in if-elseif-else ladder.

Note:
#define PROC_ID_HSM_M4F seems to have extra tab in the diff/patch. But when patch gets applied in file, all of them have consistent tabs.

Link to v1:
https://lore.kernel.org/all/[email protected]

  arch/arm/mach-k3/r5/common.c | 84 +++++++++++++++++++++++++++++++++++-
  1 file changed, 83 insertions(+), 1 deletion(-)
arch/arm/mach-k3/r5/common.c +5 -0
index 81fc67a0023..1aa3869cec2 100644
@@ -15,9 +15,14 @@
  #include <spl.h>
  #include <remoteproc.h>
  #include <elf.h>
+#include <cpu_func.h>
 
  #include "../common.h"
 
+#define PROC_BOOT_CTRL_RESET_FLAG_HSM_M4	0x00000001
+#define HSM_SRAM0_0_ADDR			0x43C00000
+#define PROC_ID_HSM_M4F				0x00000080
+
  #if IS_ENABLED(CONFIG_SYS_K3_SPL_ATF)
  enum {
  	IMAGE_ID_ATF,

arch/arm/mach-k3/r5/common.c enum { · line 34

Quoted 3 lines
arch/arm/mach-k3/r5/common.c +0 -0
@@ -27,6 +32,7 @@ enum {
  	IMAGE_ID_TIFSSTUB_HS,
  	IMAGE_ID_TIFSSTUB_FS,
  	IMAGE_ID_T,

The above line looks to be a typo, must have been meant to be IMAGE_ID_TIFSSTUB_GP.

I know this series didn't introduce this typo, but could you fix it in this series since you touch lines around it and use it in patch [6/7]. That way we don't get any merge conflicts if fixed in standalone patch.

Quoted 45 lines
arch/arm/mach-k3/r5/common.c +31 -0
+	IMAGE_ID_HSM,
  	IMAGE_AMT,
  };
 
@@ -39,6 +45,7 @@ static const char *image_os_match[IMAGE_AMT] = {
  	"tifsstub-hs",
  	"tifsstub-fs",
  	"tifsstub-gp",
+	"hsm",
  };
  #endif
 
@@ -136,6 +143,73 @@ void release_resources_for_core_shutdown(void)
  	}
  }
 
+static int __maybe_unused boot_hsm_core(void)
+{
+	struct ti_sci_handle *ti_sci = get_ti_sci_handle();
+	struct ti_sci_proc_ops *proc_ops = &ti_sci->ops.proc_ops;
+	u64 hsm_image_addr;
+	u32 hsm_image_size;
+	int device_type, ret;
+
+	hsm_image_addr = (u64)fit_image_info[IMAGE_ID_HSM].load;
+	hsm_image_size = (u32)fit_image_info[IMAGE_ID_HSM].image_len;
+
+	/* Request Control of Remote Processor */
+	ret = proc_ops->proc_request(ti_sci, PROC_ID_HSM_M4F);
+	if (ret) {
+		printf("Unable to request HSM processor control: %d\n", ret);
+		return ret;
+	}
+
+	/* Put the remote processor into reset */
+	ret = proc_ops->set_proc_boot_ctrl(ti_sci, PROC_ID_HSM_M4F,
+					   PROC_BOOT_CTRL_RESET_FLAG_HSM_M4, 0);
+	if (ret) {
+		printf("Unable to Halt HSM core: %d\n", ret);
+		goto release_proc_ctrl;
+	}
+
+	/*
+	 * Load the HSM firmware into core's internal memory.
+	 *

arch/arm/mach-k3/r5/common.c void release_resources_for_core_shutdown(void) · line 184

Quoted 10 lines
arch/arm/mach-k3/r5/common.c +10 -0
+	 * In case of HS device types, request secure entity to authenticate and
+	 * load the HSM firmware into the core memory.
+	 * In case of GP device types, copy the HSM firmware into the core
+	 * memory manually.
+	 */
+	device_type = get_device_type();
+	if (device_type == K3_DEVICE_TYPE_HS_SE ||
+	    device_type == K3_DEVICE_TYPE_HS_FS) {
+		ret = proc_ops->proc_auth_boot_image(ti_sci, &hsm_image_addr,
+						     &hsm_image_size);

Could you use ti_secure_image_post_process() here? It should be able to replace a bunch of the surrounding code too. If it returns without modifying &size the you can go down the GP path.

ti_secure_image_post_process() also flushes the image out of caches before the TI-SCI call, without that there are cases where the image will not be readable by the TIFS core.

Andrew

Quoted 55 lines
arch/arm/mach-k3/r5/common.c +37 -1
+		if (ret) {
+			printf("Unable to Authenticate and Boot HSM image; ret = %d\n",
+			       ret);
+			goto release_proc_ctrl;
+		}
+	} else if (device_type == K3_DEVICE_TYPE_GP) {
+		debug("Loading HSM GP binary into SRAM0_0\n");
+		memcpy((void *)HSM_SRAM0_0_ADDR, (void *)(u32)hsm_image_addr,
+		       hsm_image_size);
+		flush_dcache_range(HSM_SRAM0_0_ADDR,
+				   HSM_SRAM0_0_ADDR + hsm_image_size);
+	} else {
+		printf("Invalid Device Type\n");
+		return -EINVAL;
+	}
+
+	/* Release the reset from the remote processor*/
+	ret = proc_ops->set_proc_boot_ctrl(ti_sci, PROC_ID_HSM_M4F, 0,
+					   PROC_BOOT_CTRL_RESET_FLAG_HSM_M4);
+	if (ret)
+		printf("Unable to Run HSM core: %d\n", ret);
+
+release_proc_ctrl:
+	/* Release Control of Remote Processor */
+	proc_ops->proc_release(ti_sci, PROC_ID_HSM_M4F);
+	return ret;
+}
+
  void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
  {
  	typedef void __noreturn (*image_entry_noargs_t)(void);
@@ -157,6 +231,14 @@ void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
  				     &loadaddr);
  	}
 
+#if IS_ENABLED(CONFIG_K3_HSM_FW)
+	ret = boot_hsm_core();
+	if (ret)
+		panic("HSM core failed to boot, %d\n", ret);
+	else
+		printf("Successfully booted HSM core\n");
+#endif
+
  	/*
  	 * It is assumed that remoteproc device 1 is the corresponding
  	 * Cortex-A core which runs ATF. Make sure DT reflects the same.
@@ -388,7 +470,7 @@ void board_fit_image_post_process(const void *fit, int node, void **p_image,
  	 * Only DM and the DTBs are being authenticated here,
  	 * rest will be authenticated when A72 cluster is up
  	 */
-	if ((i != IMAGE_ID_ATF) && (i != IMAGE_ID_OPTEE)) {
+	if (i != IMAGE_ID_ATF && i != IMAGE_ID_OPTEE && i != IMAGE_ID_HSM) {
  		ti_secure_image_check_binary(p_image, p_size);
  		ti_secure_image_post_process(p_image, p_size);
  	} else {
#18 lore raw

Re: [PATCH v2 7/7] arm: mach-k3: r5: common: Add support to boot HSM M4 core

Hi Andrew,

Quoted 57 lines · Andrew Davis
Quoted 50 lines · Beleswar Padhi

The tispl.bin fit image is packed with the HSM firmware image. Populate the "os" info of the image so that it can be detected and used to load the HSM core. Further, invoke the load and boot of HSM core at R5 SPL stage. Boot flow for HSM M4 core is as below:

1. Request control of HSM M4F remote processor.
2. Assert Reset on the HSM M4F remote processor.
3. For HS devices, Request Secure Entity to Authenticate and Load HSM firmware into core's internal SRAM memory region. For GP devices, load the unsigned firmware manually.
4. Deassert Reset on the HSM M4F remote processor.
5. Release control of HSM M4F remote processor.

---
v2: Changelog:
1. Hang system boot if HSM firmware failed to boot.
2. __maybe_unused to decrease preprocessor usage.
3. Better error messages with return code.
4. Added Error case in if-elseif-else ladder.

Note:
#define PROC_ID_HSM_M4F seems to have extra tab in the diff/patch. But when patch gets applied in file, all of them have consistent tabs.

Link to v1:
https://lore.kernel.org/all/[email protected]

  arch/arm/mach-k3/r5/common.c | 84 +++++++++++++++++++++++++++++++++++-

  1 file changed, 83 insertions(+), 1 deletion(-)
arch/arm/mach-k3/r5/common.c +1 -0
index 81fc67a0023..1aa3869cec2 100644
@@ -15,9 +15,14 @@
   #include <spl.h>
   #include <remoteproc.h>
   #include <elf.h>
+#include <cpu_func.h>
     #include "../common.h"

  +#define PROC_BOOT_CTRL_RESET_FLAG_HSM_M4    0x00000001

arch/arm/mach-k3/r5/common.c +3 -0
+#define HSM_SRAM0_0_ADDR            0x43C00000
+#define PROC_ID_HSM_M4F                0x00000080
+

  #if IS_ENABLED(CONFIG_SYS_K3_SPL_ATF)
  enum {
      IMAGE_ID_ATF,

arch/arm/mach-k3/r5/common.c enum { · line 34

Quoted 3 lines
arch/arm/mach-k3/r5/common.c +0 -0
@@ -27,6 +32,7 @@ enum {
       IMAGE_ID_TIFSSTUB_HS,
       IMAGE_ID_TIFSSTUB_FS,
       IMAGE_ID_T,

The above line looks to be a typo, must have been meant to be IMAGE_ID_TIFSSTUB_GP.

Quoted 3 lines

I know this series didn't introduce this typo, but could you fix it in this series since you touch lines around it and use it in patch [6/7]. That way we don't get any merge conflicts if fixed in standalone patch.

Sure, I will fix that in PATCH 6/7.

Quoted 59 lines
Quoted 46 lines
arch/arm/mach-k3/r5/common.c +1 -0
+    IMAGE_ID_HSM,
       IMAGE_AMT,
   };
   @@ -39,6 +45,7 @@ static const char *image_os_match[IMAGE_AMT] = {

      "tifsstub-hs",
      "tifsstub-fs",
      "tifsstub-gp",
+    "hsm",
  };
  #endif
  @@ -136,6 +143,73 @@ void release_resources_for_core_shutdown(void) }
  }
  +static int __maybe_unused boot_hsm_core(void)

arch/arm/mach-k3/r5/common.c +29 -0
+{
+    struct ti_sci_handle *ti_sci = get_ti_sci_handle();
+    struct ti_sci_proc_ops *proc_ops = &ti_sci->ops.proc_ops;
+    u64 hsm_image_addr;
+    u32 hsm_image_size;
+    int device_type, ret;
+
+    hsm_image_addr = (u64)fit_image_info[IMAGE_ID_HSM].load;
+    hsm_image_size = (u32)fit_image_info[IMAGE_ID_HSM].image_len;
+
+    /* Request Control of Remote Processor */
+    ret = proc_ops->proc_request(ti_sci, PROC_ID_HSM_M4F);
+    if (ret) {
+        printf("Unable to request HSM processor control: %d\n", ret);
+        return ret;
+    }
+
+    /* Put the remote processor into reset */
+    ret = proc_ops->set_proc_boot_ctrl(ti_sci, PROC_ID_HSM_M4F,
+                       PROC_BOOT_CTRL_RESET_FLAG_HSM_M4, 0);
+    if (ret) {
+        printf("Unable to Halt HSM core: %d\n", ret);
+        goto release_proc_ctrl;
+    }
+
+    /*
+     * Load the HSM firmware into core's internal memory.
+     *
+     * In case of HS device types, request secure entity to 

authenticate and
+     * load the HSM firmware into the core memory.

Quoted 8 lines

+     * In case of GP device types, copy the HSM firmware into the core +     * memory manually.
+     */
+    device_type = get_device_type();
+    if (device_type == K3_DEVICE_TYPE_HS_SE ||
+        device_type == K3_DEVICE_TYPE_HS_FS) {
+        ret = proc_ops->proc_auth_boot_image(ti_sci, &hsm_image_addr, +                             &hsm_image_size);

Could you use ti_secure_image_post_process() here? It should be able to replace a bunch of the surrounding code too. If it returns without modifying &size the you can go down the GP path.

Quoted 3 lines

ti_secure_image_post_process() also flushes the image out of caches before the TI-SCI call, without that there are cases where the image will not be readable by the TIFS core.

Thanks, that's cleaner, will do. Will wait for more reviews before re-spinning.

Thanks,
Beleswar

Quoted 61 lines

Andrew

Quoted 58 lines

+        if (ret) {
+            printf("Unable to Authenticate and Boot HSM image; ret = %d\n",
+                   ret);
+            goto release_proc_ctrl;
+        }
+    } else if (device_type == K3_DEVICE_TYPE_GP) {
+        debug("Loading HSM GP binary into SRAM0_0\n");
+        memcpy((void *)HSM_SRAM0_0_ADDR, (void *)(u32)hsm_image_addr, +               hsm_image_size);
+        flush_dcache_range(HSM_SRAM0_0_ADDR,
+                   HSM_SRAM0_0_ADDR + hsm_image_size);
+    } else {
+        printf("Invalid Device Type\n");
+        return -EINVAL;
+    }

arch/arm/mach-k3/r5/common.c +13 -0
+
+    /* Release the reset from the remote processor*/
+    ret = proc_ops->set_proc_boot_ctrl(ti_sci, PROC_ID_HSM_M4F, 0,
+                       PROC_BOOT_CTRL_RESET_FLAG_HSM_M4);
+    if (ret)
+        printf("Unable to Run HSM core: %d\n", ret);
+
+release_proc_ctrl:
+    /* Release Control of Remote Processor */
+    proc_ops->proc_release(ti_sci, PROC_ID_HSM_M4F);
+    return ret;
+}
+

  void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image) {
      typedef void __noreturn (*image_entry_noargs_t)(void);

arch/arm/mach-k3/r5/common.c +7 -0
@@ -157,6 +231,14 @@ void __noreturn jump_to_image_no_args(struct 
 spl_image_info *spl_image)
                        &loadaddr);
       }
   +#if IS_ENABLED(CONFIG_K3_HSM_FW)
+    ret = boot_hsm_core();
+    if (ret)
+        panic("HSM core failed to boot, %d\n", ret);
+    else
+        printf("Successfully booted HSM core\n");
+#endif
+
       /*
        * It is assumed that remoteproc device 1 is the corresponding

       * Cortex-A core which runs ATF. Make sure DT reflects the same.

arch/arm/mach-k3/r5/common.c +1 -1
@@ -388,7 +470,7 @@ void board_fit_image_post_process(const void 
 *fit, int node, void **p_image,
        * Only DM and the DTBs are being authenticated here,
        * rest will be authenticated when A72 cluster is up
        */
-    if ((i != IMAGE_ID_ATF) && (i != IMAGE_ID_OPTEE)) {
+    if (i != IMAGE_ID_ATF && i != IMAGE_ID_OPTEE && i != 
 IMAGE_ID_HSM) {
           ti_secure_image_check_binary(p_image, p_size);

          ti_secure_image_post_process(p_image, p_size); } else {

#19 lore raw

Re: [PATCH v2 7/7] arm: mach-k3: r5: common: Add support to boot HSM M4 core

In reply to Beleswar Padhi
Quoted 157 lines · Beleswar Padhi

The tispl.bin fit image is packed with the HSM firmware image. Populate the "os" info of the image so that it can be detected and used to load the HSM core. Further, invoke the load and boot of HSM core at R5 SPL stage. Boot flow for HSM M4 core is as below:

1. Request control of HSM M4F remote processor.
2. Assert Reset on the HSM M4F remote processor.
3. For HS devices, Request Secure Entity to Authenticate and Load HSM firmware into core's internal SRAM memory region. For GP devices, load the unsigned firmware manually.
4. Deassert Reset on the HSM M4F remote processor.
5. Release control of HSM M4F remote processor.

---
v2: Changelog:
1. Hang system boot if HSM firmware failed to boot.
2. __maybe_unused to decrease preprocessor usage.
3. Better error messages with return code.
4. Added Error case in if-elseif-else ladder.

Note:
#define PROC_ID_HSM_M4F seems to have extra tab in the diff/patch. But when patch gets applied in file, all of them have consistent tabs.

Link to v1:
https://lore.kernel.org/all/[email protected]

 arch/arm/mach-k3/r5/common.c | 84 +++++++++++++++++++++++++++++++++++-
 1 file changed, 83 insertions(+), 1 deletion(-)
arch/arm/mach-k3/r5/common.c +82 -0
index 81fc67a0023..1aa3869cec2 100644
@@ -15,9 +15,14 @@
 #include <spl.h>
 #include <remoteproc.h>
 #include <elf.h>
+#include <cpu_func.h>
 
 #include "../common.h"
 
+#define PROC_BOOT_CTRL_RESET_FLAG_HSM_M4	0x00000001
+#define HSM_SRAM0_0_ADDR			0x43C00000
+#define PROC_ID_HSM_M4F				0x00000080
+
 #if IS_ENABLED(CONFIG_SYS_K3_SPL_ATF)
 enum {
 	IMAGE_ID_ATF,
@@ -27,6 +32,7 @@ enum {
 	IMAGE_ID_TIFSSTUB_HS,
 	IMAGE_ID_TIFSSTUB_FS,
 	IMAGE_ID_T,
+	IMAGE_ID_HSM,
 	IMAGE_AMT,
 };
 
@@ -39,6 +45,7 @@ static const char *image_os_match[IMAGE_AMT] = {
 	"tifsstub-hs",
 	"tifsstub-fs",
 	"tifsstub-gp",
+	"hsm",
 };
 #endif
 
@@ -136,6 +143,73 @@ void release_resources_for_core_shutdown(void)
 	}
 }
 
+static int __maybe_unused boot_hsm_core(void)
+{
+	struct ti_sci_handle *ti_sci = get_ti_sci_handle();
+	struct ti_sci_proc_ops *proc_ops = &ti_sci->ops.proc_ops;
+	u64 hsm_image_addr;
+	u32 hsm_image_size;
+	int device_type, ret;
+
+	hsm_image_addr = (u64)fit_image_info[IMAGE_ID_HSM].load;
+	hsm_image_size = (u32)fit_image_info[IMAGE_ID_HSM].image_len;
+
+	/* Request Control of Remote Processor */
+	ret = proc_ops->proc_request(ti_sci, PROC_ID_HSM_M4F);
+	if (ret) {
+		printf("Unable to request HSM processor control: %d\n", ret);
+		return ret;
+	}
+
+	/* Put the remote processor into reset */
+	ret = proc_ops->set_proc_boot_ctrl(ti_sci, PROC_ID_HSM_M4F,
+					   PROC_BOOT_CTRL_RESET_FLAG_HSM_M4, 0);
+	if (ret) {
+		printf("Unable to Halt HSM core: %d\n", ret);
+		goto release_proc_ctrl;
+	}
+
+	/*
+	 * Load the HSM firmware into core's internal memory.
+	 *
+	 * In case of HS device types, request secure entity to authenticate and
+	 * load the HSM firmware into the core memory.
+	 * In case of GP device types, copy the HSM firmware into the core
+	 * memory manually.
+	 */
+	device_type = get_device_type();
+	if (device_type == K3_DEVICE_TYPE_HS_SE ||
+	    device_type == K3_DEVICE_TYPE_HS_FS) {
+		ret = proc_ops->proc_auth_boot_image(ti_sci, &hsm_image_addr,
+						     &hsm_image_size);
+		if (ret) {
+			printf("Unable to Authenticate and Boot HSM image; ret = %d\n",
+			       ret);
+			goto release_proc_ctrl;
+		}
+	} else if (device_type == K3_DEVICE_TYPE_GP) {
+		debug("Loading HSM GP binary into SRAM0_0\n");
+		memcpy((void *)HSM_SRAM0_0_ADDR, (void *)(u32)hsm_image_addr,
+		       hsm_image_size);
+		flush_dcache_range(HSM_SRAM0_0_ADDR,
+				   HSM_SRAM0_0_ADDR + hsm_image_size);
+	} else {
+		printf("Invalid Device Type\n");
+		return -EINVAL;
+	}
+
+	/* Release the reset from the remote processor*/
+	ret = proc_ops->set_proc_boot_ctrl(ti_sci, PROC_ID_HSM_M4F, 0,
+					   PROC_BOOT_CTRL_RESET_FLAG_HSM_M4);
+	if (ret)
+		printf("Unable to Run HSM core: %d\n", ret);
+
+release_proc_ctrl:
+	/* Release Control of Remote Processor */
+	proc_ops->proc_release(ti_sci, PROC_ID_HSM_M4F);
+	return ret;
+}
+
 void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
 {
 	typedef void __noreturn (*image_entry_noargs_t)(void);
@@ -157,6 +231,14 @@ void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
 				     &loadaddr);
 	}
 
+#if IS_ENABLED(CONFIG_K3_HSM_FW)
+	ret = boot_hsm_core();
+	if (ret)
+		panic("HSM core failed to boot, %d\n", ret);
+	else
+		printf("Successfully booted HSM core\n");
+#endif
+
 	/*
 	 * It is assumed that remoteproc device 1 is the corresponding
 	 * Cortex-A core which runs ATF. Make sure DT reflects the same.

arch/arm/mach-k3/r5/common.c void board_fit_image_post_process(const void *fit, int node, void **p_image, · line 476

Quoted 8 lines
arch/arm/mach-k3/r5/common.c +1 -1
@@ -388,7 +470,7 @@ void board_fit_image_post_process(const void *fit, int node, void **p_image,
 	 * Only DM and the DTBs are being authenticated here,
 	 * rest will be authenticated when A72 cluster is up
 	 */
-	if ((i != IMAGE_ID_ATF) && (i != IMAGE_ID_OPTEE)) {
+	if (i != IMAGE_ID_ATF && i != IMAGE_ID_OPTEE && i != IMAGE_ID_HSM) {
 		ti_secure_image_check_binary(p_image, p_size);
 		ti_secure_image_post_process(p_image, p_size);
 	} else {

A minor nit but this and the following else block can be refactored as:

ti_secure_image_check_binary(p_image, p_size);

if (i != IMAGE_ID_ATF && i != IMAGE_ID_OPTEE && i != IMAGE_ID_HSM) {
	ti_secure_image_post_process(p_image, p_size);
}

Regards,
Anshul

#20 lore raw
In reply to Beleswar Padhi
Quoted 5 lines · Beleswar Padhi

Some TI K3 SoCs like J721S2, and J784S4 have a HSM (High Security Module) M4F core in the Wakeup Voltage Domain which could be used to run secure services like Authentication. Boot flow for HSM M4 core is different than the general purpose M4F cores, and is as below:

The below flow looks exactly like the general purpose M4F cores.. Why is the HSM core treated differently and this loader not made into a normal remote proc driver?

Andrew

Quoted 50 lines

1. Request control of HSM M4F remote processor.
2. Assert Reset on the HSM M4F remote processor.
3. Request Secure Entity to Authenticate and Load HSM firmware into core's internal SRAM memory region. For GP device, load the firmware manually into core's SRAM region.
4. Deassert Reset on the HSM M4F remote processor.
5. Release control of HSM M4F remote processor.

This series adds support to boot HSM M4 core from R5 SPL stage. The HSM firmware is packed inside the tispl.bin fit image. The firmware is unpacked into a temporary DDR address which is then used to load HSM core. The configs to boot HSM M4 core are disabled by default.

v2: Changelog:
[Andrew]:
1. Added support in SPL to load FIT images with no 'load' property.
2. Removed 'default = n' in CONFIG option.
3. Used __maybe_unused to decrease preprocessing.
4. Better error messages with error code.
[Udit]:
1. Added 'HSM' entries in enum at the last.
2. Added error condition in if-elseif-else ladder.
3. Hang System boot when HSM failed to boot properly.

Link to v1:
https://lore.kernel.org/all/[email protected]/

Test logs after enabling HSM boot configs:
https://gist.github.com/3V3RYONE/ad33683652c8c49e4fedab49f0493e79

Beleswar Padhi (7):
arm: mach-k3: Add config option for booting HSM core
spl: Use FIT data address as fallback when 'load' property is absent
arm: dts: k3-binman: Add template for packing HSM firmware
arm: dts: k3-{j721s2/j784s4}-binman: Pack HSM firmware inside
tispl.bin
arm: mach-k3: Use FIT image data addr as fallback if 'load' prop is
missing
arm: mach-k3: Explicitly identify TIFSSTUB images when discarding
buffers
arm: mach-k3: r5: common: Add support to boot HSM M4 core

  arch/arm/dts/k3-binman.dtsi        |   9 +++
  arch/arm/dts/k3-j721s2-binman.dtsi |  12 ++++
  arch/arm/dts/k3-j784s4-binman.dtsi |  14 ++++
  arch/arm/mach-k3/Kconfig           |   7 ++
  arch/arm/mach-k3/r5/common.c       | 111 +++++++++++++++++++++++++++--
  common/spl/spl_fit.c               |  16 ++++-
  6 files changed, 164 insertions(+), 5 deletions(-)
#21 lore raw

Hi Andrew,

Quoted 10 lines · Andrew Davis
Quoted 5 lines · Beleswar Padhi

Some TI K3 SoCs like J721S2, and J784S4 have a HSM (High Security Module) M4F core in the Wakeup Voltage Domain which could be used to run secure services like Authentication. Boot flow for HSM M4 core is different than the general purpose M4F cores, and is as below:

The below flow looks exactly like the general purpose M4F cores.. Why is the HSM core treated differently and this loader not made into a normal remote proc driver?

Not exactly, HSM core is treated differently because of following exceptions:
1. Device operations for HSM core (like reset/reset release) are not handled by DM. TIFS handles that with proc_boot_ctrl TI-SCI calls.
2. The HSM firmware is not an ELF image. So we can't use rproc elf loader with it. Manual memcpy has to be done.

All of that can still be accounted in the existing M4 rproc driver, but it will be a lot of if-else checks, which I don't prefer. Let me know if you prefer that way.

Patch having HSM support in M4 remoteproc driver:
https://gist.github.com/3V3RYONE/a15a5c6933bbc83278da9860c25ec21c

Quoted 53 lines

Andrew

Quoted 50 lines

1. Request control of HSM M4F remote processor.
2. Assert Reset on the HSM M4F remote processor.
3. Request Secure Entity to Authenticate and Load HSM firmware into core's internal SRAM memory region. For GP device, load the firmware manually into core's SRAM region.
4. Deassert Reset on the HSM M4F remote processor.
5. Release control of HSM M4F remote processor.

This series adds support to boot HSM M4 core from R5 SPL stage. The HSM firmware is packed inside the tispl.bin fit image. The firmware is unpacked into a temporary DDR address which is then used to load HSM core. The configs to boot HSM M4 core are disabled by default.

v2: Changelog:
[Andrew]:
  1. Added support in SPL to load FIT images with no 'load' property.
  2. Removed 'default = n' in CONFIG option.
  3. Used __maybe_unused to decrease preprocessing.
  4. Better error messages with error code.
[Udit]:
  1. Added 'HSM' entries in enum at the last.
  2. Added error condition in if-elseif-else ladder.
  3. Hang System boot when HSM failed to boot properly.

Link to v1:
https://lore.kernel.org/all/[email protected]/

Test logs after enabling HSM boot configs:
https://gist.github.com/3V3RYONE/ad33683652c8c49e4fedab49f0493e79

Beleswar Padhi (7):
   arm: mach-k3: Add config option for booting HSM core
   spl: Use FIT data address as fallback when 'load' property is absent
   arm: dts: k3-binman: Add template for packing HSM firmware
   arm: dts: k3-{j721s2/j784s4}-binman: Pack HSM firmware inside tispl.bin
   arm: mach-k3: Use FIT image data addr as fallback if 'load' prop is missing
   arm: mach-k3: Explicitly identify TIFSSTUB images when discarding buffers
   arm: mach-k3: r5: common: Add support to boot HSM M4 core

  arch/arm/dts/k3-binman.dtsi        |   9 +++ arch/arm/dts/k3-j721s2-binman.dtsi |  12 ++++ arch/arm/dts/k3-j784s4-binman.dtsi |  14 ++++ arch/arm/mach-k3/Kconfig           |   7 ++ arch/arm/mach-k3/r5/common.c       | 111 +++++++++++++++++++++++++++-- common/spl/spl_fit.c               |  16 ++++-

  6 files changed, 164 insertions(+), 5 deletions(-)
#22 lore raw
Quoted 10 lines · Beleswar Prasad Padhi

Hi Andrew,

Quoted 7 lines · Andrew Davis
Quoted 5 lines · Beleswar Padhi

Some TI K3 SoCs like J721S2, and J784S4 have a HSM (High Security Module) M4F core in the Wakeup Voltage Domain which could be used to run secure services like Authentication. Boot flow for HSM M4 core is different than the general purpose M4F cores, and is as below:

Quoted 7 lines
Quoted 3 lines

The below flow looks exactly like the general purpose M4F cores.. Why is the HSM core treated differently and this loader not made into a normal remote proc driver?

Not exactly, HSM core is treated differently because of following exceptions:
1. Device operations for HSM core (like reset/reset release) are not handled by DM. TIFS handles that with proc_boot_ctrl TI-SCI calls.

This could be added to the commit message then.

Quoted 2 lines

2. The HSM firmware is not an ELF image. So we can't use rproc elf loader with it. Manual memcpy has to be done.

Why is the HSM firmware not an ELF image?

Quoted 2 lines

All of that can still be accounted in the existing M4 rproc driver, but it will be a lot of if-else checks, which I don't prefer. Let me know if you prefer that way.

I'm not a fan of if-else checks either, just trying to get an idea of how many would really be needed. Judging from the below commit I'd agree keeping it here would be the cleaner option for now.

Andrew

Quoted 56 lines

Patch having HSM support in M4 remoteproc driver:
https://gist.github.com/3V3RYONE/a15a5c6933bbc83278da9860c25ec21c

Quoted 53 lines

Andrew

Quoted 50 lines

1. Request control of HSM M4F remote processor.
2. Assert Reset on the HSM M4F remote processor.
3. Request Secure Entity to Authenticate and Load HSM firmware into core's internal SRAM memory region. For GP device, load the firmware manually into core's SRAM region.
4. Deassert Reset on the HSM M4F remote processor.
5. Release control of HSM M4F remote processor.

This series adds support to boot HSM M4 core from R5 SPL stage. The HSM firmware is packed inside the tispl.bin fit image. The firmware is unpacked into a temporary DDR address which is then used to load HSM core. The configs to boot HSM M4 core are disabled by default.

v2: Changelog:
[Andrew]:
  1. Added support in SPL to load FIT images with no 'load' property.
  2. Removed 'default = n' in CONFIG option.
  3. Used __maybe_unused to decrease preprocessing.
  4. Better error messages with error code.
[Udit]:
  1. Added 'HSM' entries in enum at the last.
  2. Added error condition in if-elseif-else ladder.
  3. Hang System boot when HSM failed to boot properly.

Link to v1:
https://lore.kernel.org/all/[email protected]/

Test logs after enabling HSM boot configs:
https://gist.github.com/3V3RYONE/ad33683652c8c49e4fedab49f0493e79

Beleswar Padhi (7):
   arm: mach-k3: Add config option for booting HSM core
   spl: Use FIT data address as fallback when 'load' property is absent
   arm: dts: k3-binman: Add template for packing HSM firmware
   arm: dts: k3-{j721s2/j784s4}-binman: Pack HSM firmware inside tispl.bin
   arm: mach-k3: Use FIT image data addr as fallback if 'load' prop is missing
   arm: mach-k3: Explicitly identify TIFSSTUB images when discarding buffers
   arm: mach-k3: r5: common: Add support to boot HSM M4 core

  arch/arm/dts/k3-binman.dtsi        |   9 +++ arch/arm/dts/k3-j721s2-binman.dtsi |  12 ++++ arch/arm/dts/k3-j784s4-binman.dtsi |  14 ++++ arch/arm/mach-k3/Kconfig           |   7 ++ arch/arm/mach-k3/r5/common.c       | 111 +++++++++++++++++++++++++++-- common/spl/spl_fit.c               |  16 ++++-

  6 files changed, 164 insertions(+), 5 deletions(-)
#23 lore raw
Quoted 19 lines · Andrew Davis
Quoted 10 lines · Beleswar Prasad Padhi

Hi Andrew,

Quoted 7 lines · Andrew Davis
Quoted 5 lines · Beleswar Padhi

Some TI K3 SoCs like J721S2, and J784S4 have a HSM (High Security Module) M4F core in the Wakeup Voltage Domain which could be used to run secure services like Authentication. Boot flow for HSM M4 core is different than the general purpose M4F cores, and is as below:

Quoted 7 lines
Quoted 3 lines

The below flow looks exactly like the general purpose M4F cores.. Why is the HSM core treated differently and this loader not made into a normal remote proc driver?

Not exactly, HSM core is treated differently because of following exceptions:
1. Device operations for HSM core (like reset/reset release) are not handled by DM. TIFS handles that with proc_boot_ctrl TI-SCI calls.

Quoted 6 lines

This could be added to the commit message then.

Quoted 2 lines

2. The HSM firmware is not an ELF image. So we can't use rproc elf loader with it. Manual memcpy has to be done.

Why is the HSM firmware not an ELF image?

HSM firmwares are loaded by TIFS (in non-GP) flow, and TIFS does not have elf parser.

Quoted 67 lines
Quoted 3 lines

All of that can still be accounted in the existing M4 rproc driver, but it will be a lot of if-else checks, which I don't prefer. Let me know if you prefer that way.

I'm not a fan of if-else checks either, just trying to get an idea of how many would really be needed. Judging from the below commit I'd agree keeping it here would be the cleaner option for now.

Andrew

Quoted 57 lines

Patch having HSM support in M4 remoteproc driver:
https://gist.github.com/3V3RYONE/a15a5c6933bbc83278da9860c25ec21c

Quoted 54 lines

Andrew

Quoted 51 lines

1. Request control of HSM M4F remote processor.
2. Assert Reset on the HSM M4F remote processor.
3. Request Secure Entity to Authenticate and Load HSM firmware into core's internal SRAM memory region. For GP device, load the firmware manually into core's SRAM region.
4. Deassert Reset on the HSM M4F remote processor.
5. Release control of HSM M4F remote processor.

This series adds support to boot HSM M4 core from R5 SPL stage. The HSM firmware is packed inside the tispl.bin fit image. The firmware is unpacked into a temporary DDR address which is then used to load HSM core. The configs to boot HSM M4 core are disabled by default.

v2: Changelog:
[Andrew]:
  1. Added support in SPL to load FIT images with no 'load' property.
  2. Removed 'default = n' in CONFIG option.
  3. Used __maybe_unused to decrease preprocessing.
  4. Better error messages with error code.
[Udit]:
  1. Added 'HSM' entries in enum at the last.
  2. Added error condition in if-elseif-else ladder.
  3. Hang System boot when HSM failed to boot properly.

Link to v1:
https://lore.kernel.org/all/[email protected]/

Test logs after enabling HSM boot configs:
https://gist.github.com/3V3RYONE/ad33683652c8c49e4fedab49f0493e79

Beleswar Padhi (7):
   arm: mach-k3: Add config option for booting HSM core
   spl: Use FIT data address as fallback when 'load' property is absent
   arm: dts: k3-binman: Add template for packing HSM firmware
   arm: dts: k3-{j721s2/j784s4}-binman: Pack HSM firmware inside tispl.bin
   arm: mach-k3: Use FIT image data addr as fallback if 'load' prop is missing
   arm: mach-k3: Explicitly identify TIFSSTUB images when discarding buffers
   arm: mach-k3: r5: common: Add support to boot HSM M4 core

  arch/arm/dts/k3-binman.dtsi        |   9 +++
  arch/arm/dts/k3-j721s2-binman.dtsi |  12 ++++
  arch/arm/dts/k3-j784s4-binman.dtsi |  14 ++++
  arch/arm/mach-k3/Kconfig           |   7 ++
  arch/arm/mach-k3/r5/common.c       | 111
+++++++++++++++++++++++++++--
  common/spl/spl_fit.c               |  16 ++++-

  6 files changed, 164 insertions(+), 5 deletions(-)
#24 lore raw
Quoted 29 lines · Udit
Quoted 27 lines · Andrew Davis
Quoted 15 lines · Beleswar Prasad Padhi

Hi Andrew,

Quoted 10 lines · Andrew Davis
Quoted 5 lines · Beleswar Padhi

Some TI K3 SoCs like J721S2, and J784S4 have a HSM (High Security Module) M4F core in the Wakeup Voltage Domain which could be used to run secure services like Authentication. Boot flow for HSM M4 core is different than the general purpose M4F cores, and is as below:

The below flow looks exactly like the general purpose M4F cores.. Why is the HSM core treated differently and this loader not made into a normal remote proc driver?

Quoted 4 lines

Not exactly, HSM core is treated differently because of following exceptions:
1. Device operations for HSM core (like reset/reset release) are not handled by DM. TIFS handles that with proc_boot_ctrl TI-SCI calls.

This could be added to the commit message then.

Quoted 3 lines

2. The HSM firmware is not an ELF image. So we can't use rproc elf loader with it. Manual memcpy has to be done.

Quoted 5 lines
Quoted 1 line

Why is the HSM firmware not an ELF image?

HSM firmwares are loaded by TIFS (in non-GP) flow, and TIFS does not have elf parser.

And to be clear, why is that? Since it's preventing the use other existing workflows...

Signature · 1 line
Tom
#25 lore raw
Quoted 30 lines · Tom Rini
Quoted 29 lines · Udit
Quoted 27 lines · Andrew Davis
Quoted 15 lines · Beleswar Prasad Padhi

Hi Andrew,

Quoted 10 lines · Andrew Davis
Quoted 5 lines · Beleswar Padhi

Some TI K3 SoCs like J721S2, and J784S4 have a HSM (High Security Module) M4F core in the Wakeup Voltage Domain which could be used to run secure services like Authentication. Boot flow for HSM M4 core is different than the general purpose M4F cores, and is as below:

The below flow looks exactly like the general purpose M4F cores.. Why is the HSM core treated differently and this loader not made into a normal remote proc driver?

Quoted 4 lines

Not exactly, HSM core is treated differently because of following exceptions:
1. Device operations for HSM core (like reset/reset release) are not handled by DM. TIFS handles that with proc_boot_ctrl TI-SCI calls.

This could be added to the commit message then.

Quoted 3 lines

2. The HSM firmware is not an ELF image. So we can't use rproc elf loader with it. Manual memcpy has to be done.

Quoted 9 lines
Quoted 5 lines
Quoted 1 line

Why is the HSM firmware not an ELF image?

HSM firmwares are loaded by TIFS (in non-GP) flow, and TIFS does not have elf parser.

And to be clear, why is that? Since it's preventing the use other existing workflows...

Even if the firmware is only delivered as a raw blob we should still be able to use existing workflows and make a proper rproc driver for this HSM core here.

TF-A, TIFS, and PMMC firmware are all raw bins and we have ti_k3_arm64_rproc.c / k3_system_controller.c / ti_power_proc.c rproc drivers.

Andrew

#26 lore raw
Quoted 37 lines · Andrew Davis
Quoted 36 lines · Tom Rini
Quoted 34 lines · Udit
Quoted 21 lines · Andrew Davis
Quoted 15 lines · Beleswar Prasad Padhi

Hi Andrew,

Quoted 10 lines · Andrew Davis
Quoted 5 lines · Beleswar Padhi

Some TI K3 SoCs like J721S2, and J784S4 have a HSM (High Security Module) M4F core in the Wakeup Voltage Domain which could be used to run secure services like Authentication. Boot flow for HSM M4 core is different than the general purpose M4F cores, and is as below:

The below flow looks exactly like the general purpose M4F cores.. Why is the HSM core treated differently and this loader not made into a normal remote proc driver?

Quoted 4 lines

Not exactly, HSM core is treated differently because of following exceptions:
1. Device operations for HSM core (like reset/reset release) are not handled by DM. TIFS handles that with proc_boot_ctrl TI-SCI calls.

Quoted 7 lines

This could be added to the commit message then.

Quoted 3 lines

2. The HSM firmware is not an ELF image. So we can't use rproc elf loader with it. Manual memcpy has to be done.

Why is the HSM firmware not an ELF image?

HSM firmwares are loaded by TIFS (in non-GP) flow, and TIFS does not have elf parser.

Quoted 7 lines
Quoted 3 lines

And to be clear, why is that? Since it's preventing the use other existing workflows...

Even if the firmware is only delivered as a raw blob we should still be able to use existing workflows and make a proper rproc driver for this HSM core here.

I misunderstood your previous comment,

I thought you was asking to move to elf based flow.  which is not possible.

Quoted 5 lines

TF-A, TIFS, and PMMC firmware are all raw bins and we have ti_k3_arm64_rproc.c / k3_system_controller.c / ti_power_proc.c rproc drivers.

another option to add support in ti_k3_m4_rproc.c driver for HSM

Quoted 1 line

Andrew

#27 lore raw
In reply to Andrew Davis

Hi Andrew,

Quoted 37 lines · Andrew Davis
Quoted 36 lines · Tom Rini
Quoted 34 lines · Udit
Quoted 21 lines · Andrew Davis
Quoted 15 lines · Beleswar Prasad Padhi

Hi Andrew,

Quoted 10 lines · Andrew Davis
Quoted 5 lines · Beleswar Padhi

Some TI K3 SoCs like J721S2, and J784S4 have a HSM (High Security Module) M4F core in the Wakeup Voltage Domain which could be used to run secure services like Authentication. Boot flow for HSM M4 core is different than the general purpose M4F cores, and is as below:

The below flow looks exactly like the general purpose M4F cores.. Why is the HSM core treated differently and this loader not made into a normal remote proc driver?

Quoted 4 lines

Not exactly, HSM core is treated differently because of following exceptions:
1. Device operations for HSM core (like reset/reset release) are not handled by DM. TIFS handles that with proc_boot_ctrl TI-SCI calls.

Quoted 7 lines

This could be added to the commit message then.

Quoted 3 lines

2. The HSM firmware is not an ELF image. So we can't use rproc elf loader with it. Manual memcpy has to be done.

Why is the HSM firmware not an ELF image?

HSM firmwares are loaded by TIFS (in non-GP) flow, and TIFS does not have elf parser.

Quoted 7 lines
Quoted 3 lines

And to be clear, why is that? Since it's preventing the use other existing workflows...

Even if the firmware is only delivered as a raw blob we should still be able to use existing workflows and make a proper rproc driver for this HSM core here.

Sure, so do you wish to see a new HSM rproc driver rather than putting the code in R5 SPL Common file?

Thanks,
Beleswar

Quoted 6 lines

TF-A, TIFS, and PMMC firmware are all raw bins and we have ti_k3_arm64_rproc.c / k3_system_controller.c / ti_power_proc.c rproc drivers.

Andrew

#28 lore raw
Quoted 44 lines · Beleswar Prasad Padhi

Hi Andrew,

Quoted 41 lines · Andrew Davis
Quoted 39 lines · Tom Rini
Quoted 29 lines · Udit
Quoted 27 lines · Andrew Davis
Quoted 15 lines · Beleswar Prasad Padhi

Hi Andrew,

Quoted 10 lines · Andrew Davis
Quoted 5 lines · Beleswar Padhi

Some TI K3 SoCs like J721S2, and J784S4 have a HSM (High Security Module) M4F core in the Wakeup Voltage Domain which could be used to run secure services like Authentication. Boot flow for HSM M4 core is different than the general purpose M4F cores, and is as below:

The below flow looks exactly like the general purpose M4F cores.. Why is the HSM core treated differently and this loader not made into a normal remote proc driver?

Quoted 4 lines

Not exactly, HSM core is treated differently because of following exceptions:
1. Device operations for HSM core (like reset/reset release) are not handled by DM. TIFS handles that with proc_boot_ctrl TI-SCI calls.

This could be added to the commit message then.

Quoted 3 lines

2. The HSM firmware is not an ELF image. So we can't use rproc elf loader with it. Manual memcpy has to be done.

Quoted 5 lines
Quoted 1 line

Why is the HSM firmware not an ELF image?

HSM firmwares are loaded by TIFS (in non-GP) flow, and TIFS does not have elf parser.

And to be clear, why is that? Since it's preventing the use other existing workflows...

Quoted 7 lines
Quoted 3 lines

Even if the firmware is only delivered as a raw blob we should still be able to use existing workflows and make a proper rproc driver for this HSM core here.

Sure, so do you wish to see a new HSM rproc driver rather than putting the code in R5 SPL Common file?

That does seem more clean, it will probably result in more code in total, but it will be mostly in the rproc driver. And that is better than putting all the rproc loading directly in the R5 SPL common file.

Andrew

Quoted 9 lines

Thanks,
Beleswar

Quoted 6 lines

TF-A, TIFS, and PMMC firmware are all raw bins and we have ti_k3_arm64_rproc.c / k3_system_controller.c / ti_power_proc.c rproc drivers.

Andrew