Skip to contentSkip to conversation

Add support to boot TI K3 HSM M4 core

PATCH Superseded Beleswar Padhi 5 participants 37 messages Apr 25 – May 4

Subsystems (3)

v4 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v4 cover Add support to boot TI K3 HSM M4 core

Some TI K3 SoCs like J721S2, J784S4, and J722S 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.

v4: Changelog:
Re-spinning after Device Tree Syncup happened from Linux to U-Boot. [Andrew]:
1. Reworded commit message on [PATCH v4 03/11].
[Simon]:
1. Add a binman test for the boot & load extensions in certificate in

     [PATCH v4 08/11].

General:
1. Drop J722S defconfig changes out of this series. Will be posted/discussed separately.

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

v3: Changelog:
[Andrew]:
1. Added dedicated remoteproc driver for booting HSM core.
2. Added support for signing HSM firmware images in U-Boot. [Anshul]
General:
1. Add support for booting HSM on J722S SoC as well.

Link to v2:
http://lore.kernel.org/all/[email protected]/

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]/

Testing done:
1. Tested HSM boot across GP, HS-FS, HS-SE device types for J721S2, J784S4 and J722S SoCs.

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

Beleswar Padhi (11):
spl: Use FIT data address as fallback when 'load' property is absent
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: Add config option for packaging HSM firmware
arm: dts: k3-binman: Add template for packing HSM firmware
arm: dts: k3-{j721s2/j722s/j784s4}-binman: Pack HSM firmware inside
tispl.bin
binman: openssl: Add boot and load extensions to x509 cert
tools: binman: Add a test for boot and load extensions
arm: dts: k3-{j721s2/j722s/j784s4}-r5.dtsi: Enable HSM core
remoteproc: k3-hsm: Introduce a remoteproc driver for K3 HSM core
arm: mach-k3: r5: common: Invoke boot of HSM M4 core

 MAINTAINERS                                   |   1 +
 arch/arm/dts/k3-binman.dtsi                   |  20 ++
 arch/arm/dts/k3-j721s2-binman.dtsi            |  12 +
 arch/arm/dts/k3-j721s2-r5.dtsi                |   5 +
 arch/arm/dts/k3-j722s-binman.dtsi             |  12 +
 arch/arm/dts/k3-j722s-r5.dtsi                 |   5 +
 arch/arm/dts/k3-j784s4-binman.dtsi            |  14 +
 arch/arm/dts/k3-j784s4-r5.dtsi                |   4 +
 arch/arm/mach-k3/Kconfig                      |   7 +
 arch/arm/mach-k3/r5/common.c                  |  42 ++-
 common/spl/spl_fit.c                          |  16 +-
 drivers/remoteproc/Kconfig                    |  10 +
 drivers/remoteproc/Makefile                   |   1 +
 drivers/remoteproc/ti_k3_hsm_rproc.c          | 252 ++++++++++++++++++
 tools/binman/btool/openssl.py                 |  49 +++-
 tools/binman/etype/ti_secure.py               |  18 ++
 tools/binman/etype/x509_cert.py               |   4 +-
 tools/binman/ftest.py                         |  10 +
 .../test/vendor/ti_secure_boot_load_ext.dts   |  23 ++
 19 files changed, 496 insertions(+), 9 deletions(-)
 create mode 100644 drivers/remoteproc/ti_k3_hsm_rproc.c
 create mode 100644 tools/binman/test/vendor/ti_secure_boot_load_ext.dts
Signature · 1 line
2.34.1
#1 lore raw

PATCH v4 1/11 spl: Use FIT data address as fallback when 'load' property is absent

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.

---
Cc: Simon Glass <[email protected]>

v4: Changelog:
1. None

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

v3: Changelog:
1. None

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

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 46ebcabe56a..87d01b8b8e6 100644
@@ -799,6 +799,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;
@@ -889,7 +891,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 != -EBADSLT) {
 			printf("%s: can't load image loadables index %d (ret = %d)\n",
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v4 01/11] spl: Use FIT data address as fallback when 'load' property is absent

Quoted 50 lines · 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.

---
Cc: Simon Glass <[email protected]>

v4: Changelog:
1. None

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

v3: Changelog:
1. None

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

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 +8 -1
index 46ebcabe56a..87d01b8b8e6 100644
@@ -799,6 +799,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;
@@ -889,7 +891,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.
+		 */

common/spl/spl_fit.c int spl_load_simple_fit(struct spl_image_info *spl_image, · line 909

Quoted 10 lines
common/spl/spl_fit.c +7 -0
+		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 != -EBADSLT) {
 			printf("%s: can't load image loadables index %d (ret = %d)\n",

I guess the real question here is, does the spec allow this to be omitted like that?

Signature · 1 line
Tom
#3 lore raw

Re: [PATCH v4 01/11] spl: Use FIT data address as fallback when 'load' property is absent

Hi Tom,

Quoted 55 lines · Tom Rini
Quoted 54 lines · 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.

---
Cc: Simon Glass <[email protected]>

v4: Changelog:
1. None

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

v3: Changelog:
1. None

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

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 +12 -1
index 46ebcabe56a..87d01b8b8e6 100644
@@ -799,6 +799,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;
@@ -889,7 +891,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,
Quoted 8 lines

common/spl/spl_fit.c int spl_load_simple_fit(struct spl_image_info *spl_image, · line 909

Quoted 6 lines
common/spl/spl_fit.c +3 -0
+			      ret);
+
+		image_info.load_addr = (ulong)fit_image_loadaddr;
 		ret = load_simple_fit(info, offset, &ctx, node, &image_info);
 		if (ret < 0 && ret != -EBADSLT) {
 			printf("%s: can't load image loadables index %d (ret = %d)\n",

I guess the real question here is, does the spec allow this to be omitted like that?

Could you please point me to the spec? I could not find it.

Thanks,
Beleswar

#4 lore raw

Re: [PATCH v4 01/11] spl: Use FIT data address as fallback when 'load' property is absent

Quoted 68 lines · Beleswar Prasad Padhi

Hi Tom,

Quoted 55 lines · Tom Rini
Quoted 54 lines · 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.

---
Cc: Simon Glass <[email protected]>

v4: Changelog:
1. None

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

v3: Changelog:
1. None

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

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 +12 -1
index 46ebcabe56a..87d01b8b8e6 100644
@@ -799,6 +799,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;
@@ -889,7 +891,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,
Quoted 8 lines

common/spl/spl_fit.c int spl_load_simple_fit(struct spl_image_info *spl_image, · line 909

Quoted 6 lines
common/spl/spl_fit.c +3 -0
+			      ret);
+
+		image_info.load_addr = (ulong)fit_image_loadaddr;
 		ret = load_simple_fit(info, offset, &ctx, node, &image_info);
 		if (ret < 0 && ret != -EBADSLT) {
 			printf("%s: can't load image loadables index %d (ret = %d)\n",

I guess the real question here is, does the spec allow this to be omitted like that?

Quoted 1 line

Could you please point me to the spec? I could not find it.

Sure: https://github.com/open-source-firmware/flat-image-tree/

Signature · 1 line
Tom
#5 lore raw

Re: [PATCH v4 01/11] spl: Use FIT data address as fallback when 'load' property is absent

Hi,

Quoted 70 lines · Tom Rini
Quoted 68 lines · Beleswar Prasad Padhi

Hi Tom,

Quoted 63 lines · Tom Rini
Quoted 50 lines · 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.

---
Cc: Simon Glass <[email protected]>

v4: Changelog:
1. None

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

v3: Changelog:
1. None

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

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 +8 -1
index 46ebcabe56a..87d01b8b8e6 100644
@@ -799,6 +799,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;
@@ -889,7 +891,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.
+           */

common/spl/spl_fit.c int spl_load_simple_fit(struct spl_image_info *spl_image, · line 909

Quoted 10 lines
common/spl/spl_fit.c +7 -0
+          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 != -EBADSLT) {
                   printf("%s: can't load image loadables index %d (ret = %d)\n",

I guess the real question here is, does the spec allow this to be omitted like that?

Quoted 3 lines
Quoted 1 line

Could you please point me to the spec? I could not find it.

Sure: https://github.com/open-source-firmware/flat-image-tree/

It is mandatory for kernel and firmware images. Instead of allowing it to be optional for 'kernel', we created 'kernel_noload' some years back.

Which image type are you using in your case?

Regards,
Simon

#6 lore raw

Re: [PATCH v4 01/11] spl: Use FIT data address as fallback when 'load' property is absent

Hello,

Quoted 8 lines · Simon Glass
Quoted 7 lines · Tom Rini
Quoted 5 lines · Beleswar Prasad Padhi
Quoted 2 lines

I guess the real question here is, does the spec allow this to be omitted like that?

Could you please point me to the spec? I could not find it.

Quoted 7 lines
Quoted 1 line

Sure: https://github.com/open-source-firmware/flat-image-tree/

It is mandatory for kernel and firmware images. Instead of allowing it to be optional for 'kernel', we created 'kernel_noload' some years back.

Which image type are you using in your case?

FWIW, barebox has always interpreted lack of the load property to mean that it should just compute a suitable address itself (i.e. free memory aligned as Linux expects on that platform - same as kernel_noload).

Writing that into the spec also allows for Beleswar's use case here, although it doesn't give the guarantee that the address will always be the image address.

I think that giving a guarantee about the image address is wrong:

- If the code is not relocatable, then its load address can equally well be written into the FIT image node

- If the code is relocatable, then forcing the load address to be the image data addresses will make non-external FIT unfeasible for most users, because of code having the wrong alignment and for external FIT, it will mean careful placement of the FIT itself is required, so we don't end up with misbehavior at runtime.

I thus suggest, the spec leaves it to bootloaders to select appropriate load addresses if its missing and if the bootloader can't, it should refuse boot (current U-Boot behavior). Future U-Boot behavior will likely need to be adapted, so this loading at image data address is only done for these specific firmware images and not in general as otherwise it would preclude any other use in future.

Cheers,
Ahmad

Quoted 4 lines

Regards,
Simon

Signature · 4 lines
Pengutronix e.K.                  |                             |
Steuerwalder Str. 21              | http://www.pengutronix.de/  |
31137 Hildesheim, Germany         | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |
#7 lore raw

Re: [PATCH v4 01/11] spl: Use FIT data address as fallback when 'load' property is absent

Hi Ahmad,

Quoted 39 lines · Ahmad Fatoum

Hello,

Quoted 8 lines · Simon Glass
Quoted 7 lines · Tom Rini
Quoted 5 lines · Beleswar Prasad Padhi
Quoted 2 lines

I guess the real question here is, does the spec allow this to be omitted like that?

Could you please point me to the spec? I could not find it.

Quoted 7 lines
Quoted 1 line

Sure: https://github.com/open-source-firmware/flat-image-tree/

It is mandatory for kernel and firmware images. Instead of allowing it to be optional for 'kernel', we created 'kernel_noload' some years back.

Which image type are you using in your case?

FWIW, barebox has always interpreted lack of the load property to mean that it should just compute a suitable address itself (i.e. free memory aligned as Linux expects on that platform - same as kernel_noload).

Writing that into the spec also allows for Beleswar's use case here, although it doesn't give the guarantee that the address will always be the image address.

I think that giving a guarantee about the image address is wrong:

- If the code is not relocatable, then its load address can equally well be written into the FIT image node

- If the code is relocatable, then forcing the load address to be the image data addresses will make non-external FIT unfeasible for most users, because of code having the wrong alignment and for external FIT, it will mean careful placement of the FIT itself is required, so we don't end up with misbehavior at runtime.

Quoted 6 lines

I thus suggest, the spec leaves it to bootloaders to select appropriate load addresses if its missing and if the bootloader can't, it should refuse boot (current U-Boot behavior). Future U-Boot behavior will likely need to be adapted, so this loading at image data address is only done for these specific firmware images and not in general as otherwise it would preclude any other use in future.

This seems reasonable to me.

So load becomes optional for all image types, not just kernel_noload/fpga.

I drafted something here:

https://github.com/open-source-firmware/flat-image-tree/pull/50

Regards,
Simon

#8 lore raw

PATCH v4 2/11 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.

---
v4: Changelog:
1. None

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

v3: Changelog:
1. None

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

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 484d96f9536..50c4231655e 100644
@@ -328,12 +328,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);
@@ -342,6 +345,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
#9 lore raw

Re: [PATCH v4 02/11] arm: mach-k3: Use FIT image data addr as fallback if 'load' prop is missing

Quoted 61 lines · 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.

---
v4: Changelog:
1. None

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

v3: Changelog:
1. None

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

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 +14 -2
index 484d96f9536..50c4231655e 100644
@@ -328,12 +328,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);
@@ -342,6 +345,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);

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

Quoted 10 lines
arch/arm/mach-k3/r5/common.c +7 -0
+				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;
 		}

Does the spec allow this, or is this based on the previous patch? Thanks.

Signature · 1 line
Tom
#10 lore raw

Re: [PATCH v4 02/11] arm: mach-k3: Use FIT image data addr as fallback if 'load' prop is missing

Quoted 67 lines · Tom Rini
Quoted 65 lines · 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.

---
v4: Changelog:
1. None

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

v3: Changelog:
1. None

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

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 +18 -2
index 484d96f9536..50c4231655e 100644
@@ -328,12 +328,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);
@@ -342,6 +345,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;
Quoted 8 lines

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

Quoted 6 lines
arch/arm/mach-k3/r5/common.c +3 -0
+			} else {
+				fit_image_info[i].load = load_addr;
+			}
 			debug("%s: matched image for ID %d\n", __func__, i);
 			break;
 		}

Does the spec allow this, or is this based on the previous patch? Thanks.

It is based on the previous patch...

Thanks,
Beleswar

Reviewed-by on v4 2/11
#11 lore raw

Re: [PATCH v4 02/11] arm: mach-k3: Use FIT image data addr as fallback if 'load' prop is missing

In reply to Beleswar Padhi

Hi Beleswar,

Quoted 14 lines · Beleswar

arm: mach-k3: Use FIT image data addr as fallback if 'load' prop is missing

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.

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

 1 file changed, 21 insertions(+), 2 deletions(-)

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

Quoted 8 lines
arch/arm/mach-k3/r5/common.c +8 -0
@@ -342,6 +345,22 @@ void board_fit_image_post_process(const void *fit, int node, void **p_image,
+                     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;

We might need a spec change to deal with the 'load' address being omitted.

By the time board_fit_image_post_process() runs, *p_image already points at the in-memory FIT data (it's the 'src' that patch 1 reads via fit_image_get_data() and feeds in here). Re-resolving it with a second fit_image_get_data() (and adding a panic() path for the failure!) does the same work that has just succeeded one frame up. How about just using (ulong)*p_image here and then drop the local fit_image_loadaddr/fit_image_size/ret ?

Regards,
Simon

#12 lore raw

PATCH v4 3/11 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_AMT && 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.

---
v4: Changelog:
1. Added the correct condition in commit message. [Andrew]

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

v3: Changelog:
1. None

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

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 | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/mach-k3/r5/common.c +2 -1
index 50c4231655e..f075b881901 100644
@@ -366,7 +366,8 @@ 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_ID_TIFSSTUB_HS || i == IMAGE_ID_TIFSSTUB_FS ||
+	    i == IMAGE_ID_TIFSSTUB_GP) {
 		int device_type = get_device_type();
 
 		if ((device_type == K3_DEVICE_TYPE_HS_SE &&
Signature · 1 line
2.34.1
Reviewed-by on v4 3/11
#13 lore raw

Re: [PATCH v4 03/11] arm: mach-k3: Explicitly identify TIFSSTUB images when discarding buffers

Quoted 11 lines · 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_AMT && 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:

[...]

Signature · 1 line
Neha Malcom Francis <[email protected]>
Reviewed-by on v4 3/11
#14 lore raw

Re: [PATCH v4 03/11] arm: mach-k3: Explicitly identify TIFSSTUB images when discarding buffers

In reply to Beleswar Padhi
Quoted 14 lines · Beleswar

arm: mach-k3: Explicitly identify TIFSSTUB images when discarding buffers

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_AMT && 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
Quoted 7 lines

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

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

 1 file changed, 2 insertions(+), 1 deletion(-)
#15 lore raw

PATCH v4 4/11 arm: mach-k3: Add config option for packaging HSM firmware

In reply to Beleswar Padhi

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.

---
v4: Changelog:
1. None

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

v3: Changelog:
1. Updated description of config to match with functionality.

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

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 a32ed3a9683..df7290f74e0 100644
@@ -198,6 +198,13 @@ config K3_REMOTEPROC_PRU
 	imply REMOTEPROC_TI_PRU
 	default y if (SOC_K3_AM642 || SOC_K3_AM654)
 
+config K3_HSM_FW
+	bool "Package firmware for 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 available. When
+	  enabled, the firmware for HSM core will be packaged inside tispl.bin.
+
 if CPU_V7R
 source "arch/arm/mach-k3/r5/Kconfig"
 endif
Signature · 1 line
2.34.1
Reviewed-by on v4 4/11
#16 lore raw

Re: [PATCH v4 04/11] arm: mach-k3: Add config option for packaging HSM firmware

Quoted 4 lines · Beleswar Padhi

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.

Signature · 1 line
Neha Malcom Francis <[email protected]>
Reviewed-by on v4 4/11
#17 lore raw

Re: [PATCH v4 04/11] arm: mach-k3: Add config option for packaging HSM firmware

In reply to Beleswar Padhi

Hi Beleswar,

Quoted 14 lines · Beleswar

arm: mach-k3: Add config option for packaging HSM firmware

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.

arch/arm/mach-k3/Kconfig | 7 +++++++

 1 file changed, 7 insertions(+)

arch/arm/mach-k3/Kconfig config K3_REMOTEPROC_PRU · line 203

Quoted 6 lines
arch/arm/mach-k3/Kconfig +6 -0
@@ -198,6 +198,13 @@ config K3_REMOTEPROC_PRU
+config K3_HSM_FW
+     bool "Package firmware for 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 available. When
+       enabled, the firmware for HSM core will be packaged inside tispl.bin.

Since this option only makes sense on SoCs that actually have an HSM core, a 'depends on SOC_K3_J721S2 || SOC_K3_J784S4 || SOC_K3_J722S' would prevent it from being offered on unrelated K3 configurations - compare to how K3_DM_FW gates itself. What do you think?

Regards,
Simon

#18 lore raw

PATCH v4 5/11 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. The template also contains necessary fields which will be populated in the boot extension and load extension in the x509 certificate for HSM firmware. This is required as the HSM firmware needs to be signed before invoking TIFS to authenticate and load the blob to HSM core.

---
v4: Changelog:
1. Changed phandle from hsm to hsm_fw in 'content' field to match with node label.

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

v3: Changelog:
1. Added ti-secure node for signing hsm firmware image in U-Boot.

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

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 | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
arch/arm/dts/k3-binman.dtsi +20 -0
index ad127663d03..e6bb05a0bb8 100644
@@ -297,6 +297,26 @@
 					};
 				};
 
+#ifdef CONFIG_K3_HSM_FW
+				hsm {
+					description = "HSM binary";
+					type = "standalone";
+					compression = "none";
+					os = "hsm";
+
+					ti-secure {
+						content = <&hsm_fw>;
+						keyfile = "custMpk.pem";
+						proc_id = <0x80>;
+						flags_set = <0x04>;
+						flags_clr = <0x00>;
+						reset_vector = <0x00>;
+						dest_addr = <0x43C00000>;
+						auth_type = <0xFD00>;
+					};
+				};
+#endif
+
 				dm {
 					description = "DM binary";
 					type = "firmware";
Signature · 1 line
2.34.1
#19 lore raw

Re: [PATCH v4 05/11] arm: dts: k3-binman: Add template for packing HSM firmware

Quoted 7 lines · Beleswar Padhi
arch/arm/dts/k3-binman.dtsi +0 -0
index ad127663d03..e6bb05a0bb8 100644
@@ -297,6 +297,26 @@
 					};
 				};

arch/arm/dts/k3-binman.dtsi line 308

Quoted 10 lines
arch/arm/dts/k3-binman.dtsi +9 -0
 
+#ifdef CONFIG_K3_HSM_FW
+				hsm {
+					description = "HSM binary";
+					type = "standalone";
+					compression = "none";
+					os = "hsm";
+
+					ti-secure {
+						content = <&hsm_fw>;

This breaks bisectability as hsm_fw is introduced later in the commits

Signature · 1 line
Neha Malcom Francis <[email protected]>
#20 lore raw

Re: [PATCH v4 05/11] arm: dts: k3-binman: Add template for packing HSM firmware

Quoted 9 lines · Neha Malcom Francis
Quoted 8 lines · Beleswar Padhi
arch/arm/dts/k3-binman.dtsi +0 -0
index ad127663d03..e6bb05a0bb8 100644
@@ -297,6 +297,26 @@
 					};
 				};
 
Quoted 10 lines

arch/arm/dts/k3-binman.dtsi line 308

Quoted 9 lines
arch/arm/dts/k3-binman.dtsi +9 -0
+#ifdef CONFIG_K3_HSM_FW
+				hsm {
+					description = "HSM binary";
+					type = "standalone";
+					compression = "none";
+					os = "hsm";
+
+					ti-secure {
+						content = <&hsm_fw>;

This breaks bisectability as hsm_fw is introduced later in the commits

Thanks for catching this, will squash both commits in revision.

Thanks,
Beleswar

Reviewed-by on v4 5/11
#21 lore raw

Re: [PATCH v4 05/11] arm: dts: k3-binman: Add template for packing HSM firmware

In reply to Beleswar Padhi

Hi Beleswar,

Quoted 20 lines · Beleswar

arm: dts: k3-binman: Add template for packing HSM firmware

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. The template also contains necessary fields which will be populated in the boot extension and load extension in the x509 certificate for HSM firmware. This is required as the HSM firmware needs to be signed before invoking TIFS to authenticate and load the blob to HSM core.

arch/arm/dts/k3-binman.dtsi | 20 ++++++++++++++++++++

 1 file changed, 20 insertions(+)

arch/arm/dts/k3-binman.dtsi line 306

Quoted 10 lines
arch/arm/dts/k3-binman.dtsi +10 -0
@@ -297,6 +297,26 @@
+                                     ti-secure {
+                                             content = <&hsm_fw>;
+                                             keyfile = 'custMpk.pem';
+                                             proc_id = <0x80>;
+                                             flags_set = <0x04>;
+                                             flags_clr = <0x00>;
+                                             reset_vector = <0x00>;
+                                             dest_addr = <0x43C00000>;
+                                             auth_type = <0xFD00>;
+                                     };

We should use hyphens in DT property names. The existing ti-secure properties (auth-in-place, firewall-cert-data) already follow this convention; the python side can still expose them as proc_id etc after the usual hyphen-to-underscore translation.

arch/arm/dts/k3-binman.dtsi line 302

Quoted 8 lines
arch/arm/dts/k3-binman.dtsi +6 -0
@@ -297,6 +297,26 @@
+                                             proc_id = <0x80>;
+                                             flags_set = <0x04>;
+                                             flags_clr = <0x00>;
+                                             reset_vector = <0x00>;
+                                             dest_addr = <0x43C00000>;
+                                             auth_type = <0xFD00>;

Please use lower case hex. Also these could use a short comment above the node (or alongside each value) describing what proc-id 0x80 names, what bits flags-set 0x04 selects, and what auth-type 0xFD00 means. A reference to the TIFS interface doc would also help.

arch/arm/dts/k3-binman.dtsi line 302

Quoted 8 lines
arch/arm/dts/k3-binman.dtsi +6 -0
@@ -297,6 +297,26 @@
+#ifdef CONFIG_K3_HSM_FW
+                             hsm {
+                                     description = "HSM binary";
+                                     type = 'standalone';
+                                     compression = 'none';
+                                     os = 'hsm';

The os = 'hsm' string is what r5/common.c keys on via image_os_match[IMAGE_ID_HSM] to identify this image. Please mention that coupling in the commit message (or add a brief comment) so it is clear this string is not free-form - i.e. changing it silently breaks the post-process matcher.

Regards,
Simon

#22 lore raw

PATCH v4 6/11 arm: dts: k3-{j721s2/j722s/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.

---
v4: Changelog:
1. Changed node labels from 'hsm' to 'hsm_fw' as 'hsm' was already used by the device tree remoteproc node definiton.

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

v3: Changelog:
1. Pack firmware for J722S SoC as well.

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

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-j722s-binman.dtsi  | 12 ++++++++++++
 arch/arm/dts/k3-j784s4-binman.dtsi | 14 ++++++++++++++
 3 files changed, 38 insertions(+)
arch/arm/dts/k3-j721s2-binman.dtsi +12 -0
index f79b3e543ae..2b36b04965e 100644
@@ -268,6 +268,14 @@
 
 					};
 				};
+#ifdef CONFIG_K3_HSM_FW
+				hsm {
+					hsm_fw: blob-ext {
+						filename = "ti-hsm/hsm-demo-firmware-j721s2-hs.bin";
+					};
+				};
+#endif
+
 				dm {
 					ti-secure {
 						content = <&dm>;
@@ -300,7 +308,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-j722s-binman.dtsi +12 -0
index 278b7bfac7f..3834d081c30 100644
@@ -117,6 +117,14 @@
 
 		fit {
 			images {
+#ifdef CONFIG_K3_HSM_FW
+				hsm {
+					hsm_fw: blob-ext {
+						filename = "ti-hsm/hsm-demo-firmware-j722s-hs.bin";
+					};
+				};
+#endif
+
 				dm {
 					ti-secure {
 						content = <&dm>;
@@ -153,7 +161,11 @@
 				conf-0 {
 					description = "k3-j722s-evm";
 					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 34b2cc1e681..1da98228ff8 100644
@@ -154,6 +154,16 @@
 
 		fit {
 			images {
+
+#ifdef CONFIG_K3_HSM_FW
+				hsm {
+					hsm_fw: blob-ext {
+						filename = "ti-hsm/hsm-demo-firmware-j784s4-hs.bin";
+					};
+				};
+
+#endif
+
 				dm {
 					ti-secure {
 						content = <&dm>;
@@ -188,7 +198,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
Reviewed-by on v4 6/11
#23 lore raw

Re: [PATCH v4 06/11] arm: dts: k3-{j721s2/j722s/j784s4}-binman: Pack HSM firmware inside tispl.bin

Hi Beleswar,

Quoted 18 lines · Beleswar

arm: dts: k3-{j721s2/j722s/j784s4}-binman: Pack HSM firmware inside tispl.bin

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.

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

 arch/arm/dts/k3-j722s-binman.dtsi  | 12 ++++++++++++
 arch/arm/dts/k3-j784s4-binman.dtsi | 14 ++++++++++++++
 3 files changed, 38 insertions(+)
arch/arm/dts/k3-j784s4-binman.dtsi +0 -0
@@ -154,6 +154,16 @@
              fit {
                      images {

arch/arm/dts/k3-j784s4-binman.dtsi line 165

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

Note that the whitespace here is inconsistent with the j721s2 and j722s changes.

Regards,
Simon

#24 lore raw

PATCH v4 7/11 binman: openssl: Add boot and load extensions to x509 cert

In reply to Beleswar Padhi

The boot and load extensions in the x509 certificate are required for requesting the secure entity (TIFS) to boot a core. These fields are defined in the binman node for each core that must be booted by TIFS and must be included when generating the signed certificate.

Add support to parse the boot and load extension properties from the binman node and populate them into the certificate. If any of the mandatory properties for an extension are missing, that respective extension section is NOT added to the certificate.

---
Cc: Simon Glass <[email protected]>

v4: Changelog:
1. None

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

v3: Changelog:
1. New patch. Add support to sign HSM firmware here in U-Boot.

 tools/binman/btool/openssl.py   | 49 ++++++++++++++++++++++++++++++---
 tools/binman/etype/ti_secure.py | 18 ++++++++++++
 tools/binman/etype/x509_cert.py |  4 ++-
 3 files changed, 66 insertions(+), 5 deletions(-)
tools/binman/btool/openssl.py +45 -4
index b26f087c447..35898aa488b 100644
@@ -82,7 +82,8 @@ imageSize              = INTEGER:{len(indata)}
         return self.run_cmd(*args)
 
     def x509_cert_sysfw(self, cert_fname, input_fname, key_fname, sw_rev,
-                  config_fname, req_dist_name_dict, firewall_cert_data):
+                  config_fname, req_dist_name_dict, firewall_cert_data,
+                  boot_ext_data, load_ext_data):
         """Create a certificate to be booted by system firmware
 
         Args:
@@ -101,12 +102,52 @@ imageSize              = INTEGER:{len(indata)}
                 extended certificate
               - certificate (str): Extended firewall certificate with
                 the information for the firewall configurations.
+            boot_ext_data (dict):
+              - proc_id (int): The processor ID of core being booted
+              - flags_set (int): The config flags to set for core being booted
+              - flags_clr (int): The config flags to clear for core being booted
+              - reset_vector (int): The location of reset vector for core being
+                booted
+            load_ext_data (dict):
+              - dest_addr (int): The address to which image has to be copied
+              - auth_type (int): Contains the host ID for core being booted and
+                how the image is to be copied
 
         Returns:
             str: Tool output
         """
         indata = tools.read_file(input_fname)
         hashval = hashlib.sha512(indata).hexdigest()
+
+        if boot_ext_data is not None:
+            boot_ext = f'''
+[ sysfw_boot_seq ]
+bootCore = INTEGER:{boot_ext_data['proc_id']}
+bootCoreOpts_set = INTEGER:{boot_ext_data['flags_set']}
+bootCoreOpts_clr = INTEGER:{boot_ext_data['flags_clr']}
+resetVec = FORMAT:HEX,OCT:{boot_ext_data['reset_vector']:08x}
+# Reserved for future use
+flagsValid = FORMAT:HEX,OCT:00000000
+rsvd1 = INTEGER:0x00
+rsdv2 = INTEGER:0x00
+rsdv3 = INTEGER:0x00
+'''
+        else:
+            boot_ext = ""
+
+        if load_ext_data is not None:
+            load_ext = f'''
+[ sysfw_image_load ]
+destAddr = FORMAT:HEX,OCT:{load_ext_data['dest_addr']:08x}
+authInPlace = INTEGER:{load_ext_data['auth_type']}
+'''
+        else:
+            load_ext = f'''
+[ sysfw_image_load ]
+destAddr = FORMAT:HEX,OCT:00000000
+authInPlace = INTEGER:{hex(firewall_cert_data['auth_in_place'])}
+'''
+
         with open(config_fname, 'w', encoding='utf-8') as outf:
             print(f'''[ req ]
 distinguished_name     = req_distinguished_name
@@ -138,9 +179,9 @@ shaType                = OID:2.16.840.1.101.3.4.2.3
 shaValue               = FORMAT:HEX,OCT:{hashval}
 imageSize              = INTEGER:{len(indata)}
 
-[ sysfw_image_load ]
-destAddr = FORMAT:HEX,OCT:00000000
-authInPlace = INTEGER:{hex(firewall_cert_data['auth_in_place'])}
+{boot_ext}
+
+{load_ext}
 
 [ firewall ]
 numFirewallRegions = INTEGER:{firewall_cert_data['num_firewalls']}
tools/binman/etype/ti_secure.py +18 -0
index f6caa0286d9..bc44b684892 100644
@@ -116,6 +116,7 @@ class Entry_ti_secure(Entry_x509_cert):
         if auth_in_place:
             self.firewall_cert_data['auth_in_place'] = auth_in_place
             self.ReadFirewallNode()
+        self.ReadLoadableCoreNode()
         self.sha = fdt_util.GetInt(self._node, 'sha', 512)
         self.req_dist_name = {'C': 'US',
                 'ST': 'TX',
@@ -126,6 +127,23 @@ class Entry_ti_secure(Entry_x509_cert):
                 'emailAddress': '[email protected]'}
         self.debug = fdt_util.GetBool(self._node, 'debug', False)
 
+    def ReadLoadableCoreNode(self):
+        boot_ext_props = ['proc_id', 'flags_set', 'flags_clr', 'reset_vector']
+        load_ext_props = ['dest_addr', 'auth_type']
+
+        self.boot_ext = self.ReadDictFromList(boot_ext_props)
+        self.load_ext = self.ReadDictFromList(load_ext_props)
+
+    def ReadDictFromList(self, props):
+        props_dict = dict.fromkeys(props)
+        for prop in props:
+            val = fdt_util.GetInt(self._node, prop)
+            if val is None:
+                return None
+            else:
+                props_dict[prop] = val
+        return props_dict
+
     def ReadFirewallNode(self):
         self.firewall_cert_data['certificate'] = ""
         self.firewall_cert_data['num_firewalls'] = 0
tools/binman/etype/x509_cert.py +3 -1
index b6e8b0b4fb0..b6028f6be84 100644
@@ -102,7 +102,9 @@ class Entry_x509_cert(Entry_collection):
                 config_fname=config_fname,
                 sw_rev=self.sw_rev,
                 req_dist_name_dict=self.req_dist_name,
-                firewall_cert_data=self.firewall_cert_data)
+                firewall_cert_data=self.firewall_cert_data,
+                boot_ext_data=self.boot_ext,
+                load_ext_data=self.load_ext)
         elif type == 'rom':
             stdout = self.openssl.x509_cert_rom(
                 cert_fname=output_fname,
Signature · 1 line
2.34.1
#25 lore raw

Re: [PATCH v4 07/11] binman: openssl: Add boot and load extensions to x509 cert

Quoted 21 lines · Beleswar Padhi

The boot and load extensions in the x509 certificate are required for requesting the secure entity (TIFS) to boot a core. These fields are defined in the binman node for each core that must be booted by TIFS and must be included when generating the signed certificate.

Add support to parse the boot and load extension properties from the binman node and populate them into the certificate. If any of the mandatory properties for an extension are missing, that respective extension section is NOT added to the certificate.

---
Cc: Simon Glass <[email protected]>

v4: Changelog:
1. None

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

Quoted 7 lines

v3: Changelog:
1. New patch. Add support to sign HSM firmware here in U-Boot.

 tools/binman/btool/openssl.py   | 49 ++++++++++++++++++++++++++++++---
 tools/binman/etype/ti_secure.py | 18 ++++++++++++
 tools/binman/etype/x509_cert.py |  4 ++-
 3 files changed, 66 insertions(+), 5 deletions(-)

Is there some testing we could be adding here? Does CI pass (and so yes, everything that coverage checks for has been caught already) ? Thanks.

Signature · 1 line
Tom
Reviewed-by on v4 7/11
#26 lore raw

Re: [PATCH v4 07/11] binman: openssl: Add boot and load extensions to x509 cert

In reply to Beleswar Padhi

Hi Beleswar,

Quoted 21 lines · Beleswar

binman: openssl: Add boot and load extensions to x509 cert

The boot and load extensions in the x509 certificate are required for requesting the secure entity (TIFS) to boot a core. These fields are defined in the binman node for each core that must be booted by TIFS and must be included when generating the signed certificate.

Add support to parse the boot and load extension properties from the binman node and populate them into the certificate. If any of the mandatory properties for an extension are missing, that respective extension section is NOT added to the certificate.

tools/binman/btool/openssl.py | 49 +++++++++++++++++++++++++++++++++++++----

 tools/binman/etype/ti_secure.py | 18 +++++++++++++++
 tools/binman/etype/x509_cert.py |  4 +++-
 3 files changed, 66 insertions(+), 5 deletions(-)

tools/binman/btool/openssl.py imageSize = INTEGER:{len(indata)} · line 108

Quoted 7 lines
tools/binman/btool/openssl.py +7 -0
@@ -101,12 +102,52 @@ imageSize              = INTEGER:{len(indata)}
+        if boot_ext_data is not None:
+            boot_ext = f'''
+[ sysfw_boot_seq ]
+bootCore = INTEGER:{boot_ext_data['proc_id']}
+bootCoreOpts_set = INTEGER:{boot_ext_data['flags_set']}
+bootCoreOpts_clr = INTEGER:{boot_ext_data['flags_clr']}
+resetVec = FORMAT:HEX,OCT:{boot_ext_data['reset_vector']:08x}

Does this section actually make it into the certificate? The test in patch 8 only checks the file is non-empty, so it would not catch this.

tools/binman/btool/openssl.py imageSize = INTEGER:{len(indata)} · line 104

Quoted 5 lines
tools/binman/btool/openssl.py +3 -0
@@ -101,12 +102,52 @@ imageSize              = INTEGER:{len(indata)}
+rsvd1 = INTEGER:0x00
+rsdv2 = INTEGER:0x00
+rsdv3 = INTEGER:0x00

rsdv2 / rsdv3 should be rsvd2 / rsvd3 to match rsvd1 above.

tools/binman/etype/ti_secure.py class Entry_ti_secure(Entry_x509_cert): · line 119

Quoted 6 lines
tools/binman/etype/ti_secure.py +1 -0
@@ -116,6 +116,7 @@ class Entry_ti_secure(Entry_x509_cert):
         if auth_in_place:
             self.firewall_cert_data['auth_in_place'] = auth_in_place
             self.ReadFirewallNode()
+        self.ReadLoadableCoreNode()

The new properties (proc_id, flags_set, flags_clr, reset_vector, dest_addr, auth_type) are not described in the Entry_ti_secure docstring. Please document them alongside auth-in-place, including whether each group is optional and what the values mean.

Quoted 8 lines
tools/binman/etype/ti_secure.py +6 -0
@@ -126,6 +127,23 @@ class Entry_ti_secure(Entry_x509_cert):
+    def ReadLoadableCoreNode(self):
+        boot_ext_props = ['proc_id', 'flags_set', 'flags_clr', 'reset_vector']
+        load_ext_props = ['dest_addr', 'auth_type']
+
+        self.boot_ext = self.ReadDictFromList(boot_ext_props)
+        self.load_ext = self.ReadDictFromList(load_ext_props)

tools/binman/etype/ti_secure.py class Entry_ti_secure(Entry_x509_cert): · line 142

Quoted 10 lines
tools/binman/etype/ti_secure.py +10 -0
+
+    def ReadDictFromList(self, props):
+        props_dict = dict.fromkeys(props)
+        for prop in props:
+            val = fdt_util.GetInt(self._node, prop)
+            if val is None:
+                return None
+            else:
+                props_dict[prop] = val
+        return props_dict

A few things:

- ReadDictFromList() is a misleading name as it reads from a node, using a list of property names, into a dict. How about ReadIntProps() ?
- Drop the else after 'return None' — just fall through, that's the usual Python style.
- Silently returning None on the first missing prop means a partially-specified set (e.g. user provides proc_id and flags_set but forgets reset_vector) is treated identically to "no boot extension wanted". That is going to be very hard to debug. Best to raise an explicit error listing the missing properties (similar to what Firewall.ensure_props() does) when some but not all of the group are present. Then you can test it too.

Regards,
Simon

#27 lore raw

PATCH v4 8/11 tools: binman: Add a test for boot and load extensions

In reply to Beleswar Padhi

Add test coverage for the boot and load extension functionality in ti-secure certificates. This verifies that a certificate can be generated having boot and load extensions.

---
Cc: Simon Glass <[email protected]>

v4: Changelog:
1. New patch. Added binman test for load & boot extensions in certificate.

 tools/binman/ftest.py                         | 10 ++++++++
 .../test/vendor/ti_secure_boot_load_ext.dts   | 23 +++++++++++++++++++
 2 files changed, 33 insertions(+)
 create mode 100644 tools/binman/test/vendor/ti_secure_boot_load_ext.dts
tools/binman/ftest.py +10 -0
index ca5149ee654..f36d760375d 100644
@@ -7270,6 +7270,16 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
                                 entry_args=entry_args)[0]
         self.assertGreater(len(data), len(TI_UNSECURE_DATA))
 
+    def testPackTiSecureBootLoadExt(self):
+        """Test that an image with TI secured binary having boot & load extensions can be created"""
+        keyfile = self.TestFile('security/key.key')
+        entry_args = {
+            'keyfile': keyfile,
+        }
+        data = self._DoReadFileDtb('vendor/ti_secure_boot_load_ext.dts',
+                                   entry_args=entry_args)[0]
+        self.assertGreater(len(data), len(TI_UNSECURE_DATA))
+
     def testEncryptedNoAlgo(self):
         """Test encrypted node with missing required properties"""
         with self.assertRaises(ValueError) as e:
tools/binman/test/vendor/ti_secure_boot_load_ext.dts new file +23 -0
new file mode 100644
index 00000000000..5c29d18e627
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	binman {
+		ti-secure {
+			content = <&unsecure_binary>;
+			proc_id = <0x20>;
+			flags_set = <0x00000001>;
+			flags_clr = <0x00000002>;
+			reset_vector = <0x70000000>;
+			dest_addr = <0x80000000>;
+			auth_type = <0x02>;
+		};
+		unsecure_binary: blob-ext {
+			filename = "ti_unsecure.bin";
+		};
+	};
+};
Signature · 1 line
2.34.1
#28 lore raw

Re: [PATCH v4 08/11] tools: binman: Add a test for boot and load extensions

Quoted 5 lines · Beleswar Padhi

Add test coverage for the boot and load extension functionality in ti-secure certificates. This verifies that a certificate can be generated having boot and load extensions.

Oh tests are here. This should be folded in please, thanks.

Signature · 1 line
Tom
Reviewed-by on v4 8/11
#29 lore raw

Re: [PATCH v4 08/11] tools: binman: Add a test for boot and load extensions

In reply to Beleswar Padhi

Hi Beleswar,

Quoted 14 lines · Beleswar

tools: binman: Add a test for boot and load extensions

Add test coverage for the boot and load extension functionality in ti-secure certificates. This verifies that a certificate can be generated having boot and load extensions.

tools/binman/ftest.py | 10 ++++++++++

 .../binman/test/vendor/ti_secure_boot_load_ext.dts | 23 ++++++++++++++++++++++
 2 files changed, 33 insertions(+)

tools/binman/ftest.py fdt fdtmap Extract the devicetree blob from the fdtmap · line 7278

Quoted 9 lines
tools/binman/ftest.py +9 -0
@@ -7270,6 +7270,16 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
+    def testPackTiSecureBootLoadExt(self):
+        """Test that an image with TI secured binary having boot & load extensions can be created"""
+        keyfile = self.TestFile('security/key.key')
+        entry_args = {
+            'keyfile': keyfile,
+        }
+        data = self._DoReadFileDtb('vendor/ti_secure_boot_load_ext.dts',
+                                   entry_args=entry_args)[0]
+        self.assertGreater(len(data), len(TI_UNSECURE_DATA))

This only asserts that the resulting blob is larger than the unsecured input, which is true for any signed output and tells us nothing about the new code paths in patch 7. Please verify the actual behaviour - e.g. read back the generated config.* file (or parse the cert) and check that the sysfw_boot_seq and sysfw_image_load sections contain the expected bootCore, resetVec, destAddr and authInPlace values from the DTS. Otherwise this would happily pass even if ReadLoadableCoreNode() returned None for both extensions.

tools/binman/ftest.py fdt fdtmap Extract the devicetree blob from the fdtmap · line 7270

Quoted 3 lines
tools/binman/ftest.py +1 -0
@@ -7270,6 +7270,16 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
+    def testPackTiSecureBootLoadExt(self):

Since ReadDictFromList() in patch 7 returns None as soon as any single property is missing, please add at least one negative case, like a DTS with proc_id only, to confirm that boot_ext ends up None and the certificate falls back to the firewall authInPlace branch. As it stands, only the all-properties-present path is exercised here.

Regards,
Simon

#30 lore raw

PATCH v4 9/11 arm: dts: k3-{j721s2/j722s/j784s4}-r5.dtsi: Enable HSM core

In reply to Beleswar Padhi

The HSM M4F node is disabled by default in the device tree. Enable the node here as we have to load and boot the core in R5 SPL stage. Assign the alias of 'remoteproc2' to the hsm node. This assigns the sequence number '2' to HSM core which can be used during rproc_load() and rproc_start() calls.

---
v4: Changelog:
1. Changed node labels from 'hsm_m4fss' to 'hsm' to match with device tree definition.

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

v3: Changelog:
1. New patch. Enable HSM nodes from DT.

 arch/arm/dts/k3-j721s2-r5.dtsi | 5 +++++
 arch/arm/dts/k3-j722s-r5.dtsi  | 5 +++++
 arch/arm/dts/k3-j784s4-r5.dtsi | 4 ++++
 3 files changed, 14 insertions(+)
arch/arm/dts/k3-j721s2-r5.dtsi +5 -0
index 7d4a6dc5301..cba7bbb7c2d 100644
@@ -11,6 +11,7 @@
 	aliases {
 		remoteproc0 = &sysctrler;
 		remoteproc1 = &a72_0;
+		remoteproc2 = &hsm;
 	};
 
 	a72_0: a72@0 {
@@ -102,3 +103,7 @@
 	ranges = <0x0 0x47000000 0x0 0x47000000 0x0 0x00068400>,
 			 <0x0 0x50000000 0x0 0x50000000 0x0 0x08000000>;
 };
+
+&hsm {
+	status = "okay";
+};
arch/arm/dts/k3-j722s-r5.dtsi +5 -0
index 06a63fb83ba..2133a083871 100644
@@ -7,6 +7,7 @@
 	aliases {
 		remoteproc0 = &sysctrler;
 		remoteproc1 = &a53_0;
+		remoteproc2 = &hsm;
 		serial0 = &wkup_uart0;
 		serial2 = &main_uart0;
 	};
@@ -82,3 +83,7 @@
 	reg = <0x00 0x0fc40000 0x00 0x100>,
 	      <0x00 0x60000000 0x00 0x08000000>;
 };
+
+&hsm {
+	status = "okay";
+};
arch/arm/dts/k3-j784s4-r5.dtsi +4 -0
index 78444dc4e14..ccdea7ab5b8 100644
@@ -11,6 +11,7 @@
 	aliases {
 		remoteproc0 = &sysctrler;
 		remoteproc1 = &a72_0;
+		remoteproc2 = &hsm;
 	};
 
 	a72_0: a72@0 {
@@ -113,3 +114,6 @@
 	vdd-supply-2 = <&tps62873a>;
 };
 
+&hsm {
+	status = "okay";
+};
Signature · 1 line
2.34.1
Reviewed-by on v4 9/11
#31 lore raw

Re: [PATCH v4 09/11] arm: dts: k3-{j721s2/j722s/j784s4}-r5.dtsi: Enable HSM core

Hi Beleswar,

Quoted 17 lines · Beleswar

arm: dts: k3-{j721s2/j722s/j784s4}-r5.dtsi: Enable HSM core

The HSM M4F node is disabled by default in the device tree. Enable the node here as we have to load and boot the core in R5 SPL stage. Assign the alias of 'remoteproc2' to the hsm node. This assigns the sequence number '2' to HSM core which can be used during rproc_load() and rproc_start() calls.

arch/arm/dts/k3-j721s2-r5.dtsi | 5 +++++

 arch/arm/dts/k3-j722s-r5.dtsi  | 5 +++++
 arch/arm/dts/k3-j784s4-r5.dtsi | 4 ++++
 3 files changed, 14 insertions(+)

arch/arm/dts/k3-j721s2-r5.dtsi line 105

Quoted 3 lines
arch/arm/dts/k3-j721s2-r5.dtsi +3 -0
@@ -102,3 +103,7 @@
+&hsm {
+     status = 'okay';
+};

Does this have or need bootph-pre-ram here so that the node is present in SPL?

arch/arm/dts/k3-j721s2-r5.dtsi line 15

Quoted 7 lines
arch/arm/dts/k3-j721s2-r5.dtsi +1 -0
@@ -11,6 +11,7 @@
      aliases {
              remoteproc0 = &sysctrler;
              remoteproc1 = &a72_0;
+             remoteproc2 = &hsm;
      };

Hard-coding sequence 2 in the alias and then using a literal '2' in jump_to_image() (patch 11) is not great - anyone adding a remoteproc later, or building without HSM enabled on a board that adds another rproc, will quietly shift the index. Can you look it up by compatible or phandle in the caller, or at least add a comment in both this file and arch/arm/mach-k3/r5/common.c explaining this connection.

Regards,
Simon

#32 lore raw

PATCH v4 10/11 remoteproc: k3-hsm: Introduce a remoteproc driver for K3 HSM core

In reply to Beleswar Padhi

Some K3 SoCs like J721S2, J784S4, J722S, AM62X and AM62PX 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. 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.

Add a new remoteproc driver to support this boot flow for HSM M4F core.

---
v4: Changelog:
1. None

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

v3: Changelog:
1. New patch. Add a dedicated remoteproc driver to boot HSM core.

 MAINTAINERS                          |   1 +
 drivers/remoteproc/Kconfig           |  10 ++
 drivers/remoteproc/Makefile          |   1 +
 drivers/remoteproc/ti_k3_hsm_rproc.c | 252 +++++++++++++++++++++++++++
 4 files changed, 264 insertions(+)
 create mode 100644 drivers/remoteproc/ti_k3_hsm_rproc.c
MAINTAINERS +1 -0
index fc5cd553ec3..0678f4d59e8 100644
@@ -814,6 +814,7 @@ F:	drivers/phy/ti-pipe3-phy.c
 F:	drivers/ram/k3*
 F:	drivers/ram/k3*/
 F:	drivers/remoteproc/ipu_rproc.c
+F:	drivers/remoteproc/ti_k3_hsm_rproc.c
 F:	drivers/remoteproc/k3_system_controller.c
 F:	drivers/remoteproc/pruc_rpoc.c
 F:	drivers/remoteproc/ti*
drivers/remoteproc/Kconfig +10 -0
index f07ae903a28..c09905b46d7 100644
@@ -99,6 +99,16 @@ config REMOTEPROC_TI_K3_M4F
 	  on various TI K3 family of SoCs through the remote processor
 	  framework.
 
+config REMOTEPROC_TI_K3_HSM_M4F
+	bool "TI K3 HSM M4F remoteproc support"
+	select REMOTEPROC
+	depends on ARCH_K3
+	depends on TI_SCI_PROTOCOL
+	help
+	  Say y here to support TI's HSM M4F remote processor subsystems
+	  on various TI K3 family of SoCs through the remote processor
+	  framework.
+
 config REMOTEPROC_TI_K3_R5F
 	bool "TI K3 R5F remoteproc support"
 	select REMOTEPROC
drivers/remoteproc/Makefile +1 -0
index 7ea8023c50b..d29e1bf9db2 100644
@@ -16,6 +16,7 @@ obj-$(CONFIG_REMOTEPROC_STM32_COPRO) += stm32_copro.o
 obj-$(CONFIG_REMOTEPROC_TI_K3_ARM64) += ti_k3_arm64_rproc.o
 obj-$(CONFIG_REMOTEPROC_TI_K3_DSP) += ti_k3_dsp_rproc.o
 obj-$(CONFIG_REMOTEPROC_TI_K3_M4F) += ti_k3_m4_rproc.o
+obj-$(CONFIG_REMOTEPROC_TI_K3_HSM_M4F) += ti_k3_hsm_rproc.o
 obj-$(CONFIG_REMOTEPROC_TI_K3_R5F) += ti_k3_r5f_rproc.o
 obj-$(CONFIG_REMOTEPROC_TI_POWER) += ti_power_proc.o
 obj-$(CONFIG_REMOTEPROC_TI_PRU) += pru_rproc.o
drivers/remoteproc/ti_k3_hsm_rproc.c new file +252 -0

252 lines not on this page · raw message

Signature · 1 line
2.34.1
Reviewed-by on v4 10/11
#33 lore raw

Re: [PATCH v4 10/11] remoteproc: k3-hsm: Introduce a remoteproc driver for K3 HSM core

Hi Beleswar,

Quoted 33 lines · Beleswar

remoteproc: k3-hsm: Introduce a remoteproc driver for K3 HSM core

Some K3 SoCs like J721S2, J784S4, J722S, AM62X and AM62PX 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. 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.

Add a new remoteproc driver to support this boot flow for HSM M4F core.

MAINTAINERS | 1 +

 drivers/remoteproc/Kconfig           |  10 ++
 drivers/remoteproc/Makefile          |   1 +
 drivers/remoteproc/ti_k3_hsm_rproc.c | 252 +++++++++++++++++++++++++++++++++++
 4 files changed, 264 insertions(+)
drivers/remoteproc/ti_k3_hsm_rproc.c +6 -0
@@ -0,0 +1,252 @@
+static int k3_hsm_load(struct udevice *dev, ulong addr, ulong size)
+{
+     struct k3_hsm_privdata *hsm = dev_get_priv(dev);
+     size_t image_size = size;
+     int ret;
+

drivers/remoteproc/ti_k3_hsm_rproc.c line 16

Quoted 10 lines
drivers/remoteproc/ti_k3_hsm_rproc.c +10 -0
+     ret = ti_sci_proc_request(&hsm->tsp);
+     if (ret)
+             return ret;
+
+     ret = ti_sci_proc_set_control(&hsm->tsp,
+                                   PROC_BOOT_CTRL_RESET_FLAG_HSM_M4, 0);
+     if (ret)
+             goto proc_release;
+
+     ti_secure_image_post_process((void *)&addr, &image_size);

Better to pass a proper 'void *image_addr = (void *)addr' here. Casting &addr (a ulong *) to void ** happens to work on a 32-bit R5 SPL but it relies on sizeof(ulong) == sizeof(void *) and on the compiler being willing to alias-write a void * back through that ulong storage.

drivers/remoteproc/ti_k3_hsm_rproc.c line 6

Quoted 8 lines
drivers/remoteproc/ti_k3_hsm_rproc.c +6 -0
@@ -0,0 +1,252 @@
+     if (image_size == size) {
+             debug("Loading HSM GP binary into SRAM0_0\n");
+             memcpy((void *)hsm->mem[0].cpu_addr, (void *)(u32)addr, size);
+             flush_dcache_range((unsigned long)hsm->mem[0].cpu_addr,
+                                (unsigned long)(hsm->mem[0].cpu_addr + size));
+     }

A few things on this block:

1. Detecting "this is a GP device, do the manual load" by comparing image_size against the original size is brittle - e.g. on HS-FS without a certificate, ti_secure_image_post_process() also returns with the size unchanged (after printing a warning), so we would silently fall into the GP path. Can you add a check for test get_device_type() == K3_DEVICE_TYPE_GP explicitly - that would match the commit message and the debug() line.

2. The (u32)addr cast truncates addr on any 64-bit build. R5 SPL is 32-bit today, but please drop the (u32) and just do (void *)addr so the code is correct independent of target width.

3. There is no check that size fits in hsm->mem[0].size before the memcpy(). If a malformed FIT delivers an oversized image, this scribbles past SRAM0_0. A simple bounds test with an error return would help.

Quoted 6 lines
drivers/remoteproc/ti_k3_hsm_rproc.c +4 -0
@@ -0,0 +1,252 @@
+static int k3_hsm_stop(struct udevice *dev)
+{
+     struct k3_hsm_privdata *hsm = dev_get_priv(dev);
+     int ret;

drivers/remoteproc/ti_k3_hsm_rproc.c line 14

Quoted 10 lines
drivers/remoteproc/ti_k3_hsm_rproc.c +10 -0
+
+     ti_sci_proc_request(&hsm->tsp);
+
+     ret = ti_sci_proc_set_control(&hsm->tsp,
+                                   PROC_BOOT_CTRL_RESET_FLAG_HSM_M4, 0);
+
+     ti_sci_proc_release(&hsm->tsp);
+
+     return ret;
+}

The return value of ti_sci_proc_request() is silently dropped. If the request fails, the set_control() call below will also fail and the user gets a misleading error. Please check it and bail early like the rest of the driver does.

drivers/remoteproc/ti_k3_hsm_rproc.c line 6

Quoted 8 lines
drivers/remoteproc/ti_k3_hsm_rproc.c +6 -0
@@ -0,0 +1,252 @@
+     tsp->dev_id = dev_read_u32_default(dev, 'ti,sci-dev-id',
+                                        TI_SCI_RESOURCE_NULL);
+     if (tsp->dev_id == TI_SCI_RESOURCE_NULL) {
+             dev_err(dev, "Device ID not populated %d\n", ret);
+             return -ENODEV;
+     }

ret is 0 here (last set by the successful dev_read_u32_array() call), so the %d is meaningless. I realise this was copied from ti_k3_m4_rproc.c, but please drop the %d and the argument while introducing a new copy.

Regards,
Simon

#34 lore raw

PATCH v4 11/11 arm: mach-k3: r5: common: Invoke boot of 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 using the remoteprocessor framework.

---
v4: Changelog:
1. None

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

v3: Changelog:
1. Use remoteproc framework to boot HSM core.

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

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 | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
arch/arm/mach-k3/r5/common.c +16 -0
index f075b881901..df93b2bba5f 100644
@@ -28,6 +28,7 @@ enum {
 	IMAGE_ID_TIFSSTUB_HS,
 	IMAGE_ID_TIFSSTUB_FS,
 	IMAGE_ID_TIFSSTUB_GP,
+	IMAGE_ID_HSM,
 	IMAGE_AMT,
 };
 
@@ -40,6 +41,7 @@ static const char *image_os_match[IMAGE_AMT] = {
 	"tifsstub-hs",
 	"tifsstub-fs",
 	"tifsstub-gp",
+	"hsm",
 };
 #endif
 
@@ -158,6 +160,20 @@ void __noreturn jump_to_image(struct spl_image_info *spl_image)
 				     &loadaddr);
 	}
 
+	if (IS_ENABLED(CONFIG_REMOTEPROC_TI_K3_HSM_M4F)) {
+		ret = rproc_load(2, fit_image_info[IMAGE_ID_HSM].load,
+				 fit_image_info[IMAGE_ID_HSM].image_len);
+		if (ret) {
+			panic("Error while loading HSM firmware, ret = %d\n", ret);
+		} else {
+			ret = rproc_start(2);
+			if (ret)
+				panic("Error while starting HSM core\n");
+			else
+				printf("Successfully loaded and started HSM core\n");
+		}
+	}
+
 	/*
 	 * It is assumed that remoteproc device 1 is the corresponding
 	 * Cortex-A core which runs ATF. Make sure DT reflects the same.
Signature · 1 line
2.34.1
Reviewed-by on v4 11/11
#35 lore raw

Re: [PATCH v4 11/11] arm: mach-k3: r5: common: Invoke boot of HSM M4 core

Hi Beleswar,

Quoted 17 lines · Beleswar

arm: mach-k3: r5: common: Invoke boot of HSM M4 core

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 using the remoteprocessor framework.

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

 1 file changed, 16 insertions(+)
arch/arm/mach-k3/r5/common.c +3 -0
@@ -158,6 +160,20 @@ void __noreturn jump_to_image(struct spl_image_info *spl_image)
+     if (IS_ENABLED(CONFIG_REMOTEPROC_TI_K3_HSM_M4F)) {
+             ret = rproc_load(2, fit_image_info[IMAGE_ID_HSM].load,
+                              fit_image_info[IMAGE_ID_HSM].image_len);

arch/arm/mach-k3/r5/common.c void __noreturn jump_to_image(struct spl_image_info *spl_image) · line 172

Quoted 10 lines
arch/arm/mach-k3/r5/common.c +10 -0
+             if (ret) {
+                     panic("Error while loading HSM firmware, ret = %d\n", ret);
+             } else {
+                     ret = rproc_start(2);
+                     if (ret)
+                             panic("Error while starting HSM core\n");
+                     else
+                             printf("Successfully loaded and started HSM core\n");
+             }
+     }

panic() is __noreturn, so how about:

ret = rproc_load(2, ...);
if (ret)

           panic("Error while loading HSM firmware, ret = %d\n", ret);

ret = rproc_start(2);
if (ret)

           panic("Error while starting HSM core, ret = %d\n", ret);
   printf("Successfully loaded and started HSM core\n");

arch/arm/mach-k3/r5/common.c void __noreturn jump_to_image(struct spl_image_info *spl_image) · line 161

Quoted 4 lines
arch/arm/mach-k3/r5/common.c +2 -0
@@ -158,6 +160,20 @@ void __noreturn jump_to_image(struct spl_image_info *spl_image)
+             ret = rproc_load(2, fit_image_info[IMAGE_ID_HSM].load,
+                              fit_image_info[IMAGE_ID_HSM].image_len);

The bare 2 here mirrors the bare 1 below, which at least has a comment explaining the DT alias assumption ("It is assumed that remoteproc device 1 is …"). Please add an equivalent comment for the HSM, pointing at the 'remoteproc2 = &hsm' alias added in patch 9.

arch/arm/mach-k3/r5/common.c void __noreturn jump_to_image(struct spl_image_info *spl_image) · line 161

Quoted 4 lines
arch/arm/mach-k3/r5/common.c +2 -0
@@ -158,6 +160,20 @@ void __noreturn jump_to_image(struct spl_image_info *spl_image)
+             ret = rproc_load(2, fit_image_info[IMAGE_ID_HSM].load,
+                              fit_image_info[IMAGE_ID_HSM].image_len);

Just to check: on HS-SE/HS-FS, board_fit_image_post_process() already invokes ti_secure_image_post_process() on the HSM image (since IMAGE_ID_HSM is not in the ATF/OPTEE skip list), and then k3_hsm_load() in patch 10 calls ti_secure_image_post_process() a second time on &addr. Is this intentional? It looks like the image is post-processed twice on HS devices. If so, please mention it in the commit message; otherwise one of the two calls should go.

Also, image_len recorded in fit_image_info[] is the pre-post-process size (set before the HS-side post_process runs), but 'load' is the original FIT data address - so on HS, the (load, image_len) pair you pass to rproc_load() may not describe what is actually sitting at that address after the first post_process. Worth checking on a HS-SE board.

Regards,
Simon

#36 lore raw
In reply to Beleswar Padhi

Hi Beleswar,

Quoted 1 line · Beleswar

This series adds support to boot HSM M4 core from R5 SPL stage.

Could we have something in doc/ for this series?

Regards,
Simon