Skip to contentSkip to conversation

ARM: stm32: Fix ECDSA authentication with Dcache enabled

PATCH Superseded Marek Vasut 3 participants 14 messages Dec 7, 2022 – Jan 13, 2023

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/4 ARM: stm32: Fix ECDSA authentication with Dcache enabled

In case Dcache is enabled while the ECDSA authentication function is called via BootROM ROM API, the MMU tables are set up and the BootROM region is not marked as executable, so an attempt to run code from it results in a hang. Mark the BootROM region as executable as suggested by Patrick to prevent the hang.

---
Cc: Alexandru Gagniuc <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
---
V2: - Initialize reenable_dcache variable
V3: - Mark BootROM as executable instead

---
 arch/arm/mach-stm32mp/ecdsa_romapi.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/arm/mach-stm32mp/ecdsa_romapi.c +4 -0
index a2f63ff879f..6156526253c 100644
@@ -81,6 +81,10 @@ static int romapi_ecdsa_verify(struct udevice *dev,
 	memcpy(raw_key + 32, pubkey->y, 32);
 
 	stm32mp_rom_get_ecdsa_functions(&rom);
+
+	/* Mark BootROM region as executable. */
+	mmu_set_region_dcache_behaviour(0, SZ_2M, DCACHE_DEFAULT_OPTION);
+
 	rom_ret = rom.ecdsa_verify_signature(hash, raw_key, signature, algo);
 
 	return rom_ret == ROM_API_SUCCESS ? 0 : -EPERM;
Signature · 1 line
2.35.1
#1 lore raw

PATCH v3 2/4 ARM: stm32: Factor out save_boot_params

The STM32MP15xx platform currently comes with two incompatible implementations of save_boot_params() weak function override. Factor the save_boot_params() implementation into common cpu.c code and provide accessors to read out both ROM API table address and DT address from any place in the code instead.

---
Cc: Alexandru Gagniuc <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
---
V2: Avoid #if CONFIG... , use if (CONFIG... instead
V3: No change

---
 arch/arm/mach-stm32mp/boot_params.c           | 20 ++---------
 arch/arm/mach-stm32mp/cpu.c                   | 35 +++++++++++++++++++
 arch/arm/mach-stm32mp/ecdsa_romapi.c          | 20 ++---------
 .../arm/mach-stm32mp/include/mach/sys_proto.h |  3 ++
 4 files changed, 42 insertions(+), 36 deletions(-)
arch/arm/mach-stm32mp/boot_params.c +2 -18
index e91ef1b2fc7..e40cca938ef 100644
@@ -11,30 +11,14 @@
 #include <asm/sections.h>
 #include <asm/system.h>
 
-/*
- * Force data-section, as .bss will not be valid
- * when save_boot_params is invoked.
- */
-static unsigned long nt_fw_dtb __section(".data");
-
-/*
- * Save the FDT address provided by TF-A in r2 at boot time
- * This function is called from start.S
- */
-void save_boot_params(unsigned long r0, unsigned long r1, unsigned long r2,
-		      unsigned long r3)
-{
-	nt_fw_dtb = r2;
-
-	save_boot_params_ret();
-}
-
 /*
  * Use the saved FDT address provided by TF-A at boot time (NT_FW_CONFIG =
  * Non Trusted Firmware configuration file) when the pointer is valid
  */
 void *board_fdt_blob_setup(int *err)
 {
+	unsigned long nt_fw_dtb = get_stm32mp_bl2_dtb();
+
 	log_debug("%s: nt_fw_dtb=%lx\n", __func__, nt_fw_dtb);
 
 	*err = 0;
arch/arm/mach-stm32mp/cpu.c +35 -0
index 855fc755fe0..ee59866bb73 100644
@@ -378,3 +378,38 @@ int arch_misc_init(void)
 
 	return 0;
 }
+
+/*
+ * Without forcing the ".data" section, this would get saved in ".bss". BSS
+ * will be cleared soon after, so it's not suitable.
+ */
+static uintptr_t rom_api_table __section(".data");
+static uintptr_t nt_fw_dtb __section(".data");
+
+/*
+ * The ROM gives us the API location in r0 when starting. This is only available
+ * during SPL, as there isn't (yet) a mechanism to pass this on to u-boot. Save
+ * the FDT address provided by TF-A in r2 at boot time. This function is called
+ * from start.S
+ */
+void save_boot_params(unsigned long r0, unsigned long r1, unsigned long r2,
+		      unsigned long r3)
+{
+	if (IS_ENABLED(CONFIG_STM32_ECDSA_VERIFY))
+		rom_api_table = r0;
+
+	if (IS_ENABLED(CONFIG_TFABOOT))
+		nt_fw_dtb = r2;
+
+	save_boot_params_ret();
+}
+
+uintptr_t get_stm32mp_rom_api_table(void)
+{
+	return rom_api_table;
+}
+
+uintptr_t get_stm32mp_bl2_dtb(void)
+{
+	return nt_fw_dtb;
+}
arch/arm/mach-stm32mp/ecdsa_romapi.c +2 -18
index 6156526253c..12b42b9d59c 100644
@@ -24,26 +24,10 @@ struct ecdsa_rom_api {
 					   uint32_t ecc_algo);
 };
 
-/*
- * Without forcing the ".data" section, this would get saved in ".bss". BSS
- * will be cleared soon after, so it's not suitable.
- */
-static uintptr_t rom_api_loc __section(".data");
-
-/*
- * The ROM gives us the API location in r0 when starting. This is only available
- * during SPL, as there isn't (yet) a mechanism to pass this on to u-boot.
- */
-void save_boot_params(unsigned long r0, unsigned long r1, unsigned long r2,
-		      unsigned long r3)
-{
-	rom_api_loc = r0;
-	save_boot_params_ret();
-}
-
 static void stm32mp_rom_get_ecdsa_functions(struct ecdsa_rom_api *rom)
 {
-	uintptr_t verify_ptr = rom_api_loc + ROM_API_OFFSET_ECDSA_VERIFY;
+	uintptr_t verify_ptr = get_stm32mp_rom_api_table() +
+			       ROM_API_OFFSET_ECDSA_VERIFY;
 
 	rom->ecdsa_verify_signature = *(void **)verify_ptr;
 }
arch/arm/mach-stm32mp/include/mach/sys_proto.h +3 -0
index f19a70e53e0..0d39b67178e 100644
@@ -77,3 +77,6 @@ void stm32mp_misc_init(void);
 
 /* helper function: read data from OTP */
 u32 get_otp(int index, int shift, int mask);
+
+uintptr_t get_stm32mp_rom_api_table(void);
+uintptr_t get_stm32mp_bl2_dtb(void);
Signature · 1 line
2.35.1
Reviewed-by on v3 2/4
#2 lore raw

Re: [PATCH v3 2/4] ARM: stm32: Factor out save_boot_params

Hi,

Quoted 14 lines · Marek Vasut

The STM32MP15xx platform currently comes with two incompatible implementations of save_boot_params() weak function override. Factor the save_boot_params() implementation into common cpu.c code and provide accessors to read out both ROM API table address and DT address from any place in the code instead.

---
Cc: Alexandru Gagniuc <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
---
V2: Avoid #if CONFIG... , use if (CONFIG... instead
V3: No change

Quoted 6 lines
---
  arch/arm/mach-stm32mp/boot_params.c           | 20 ++---------
  arch/arm/mach-stm32mp/cpu.c                   | 35 +++++++++++++++++++
  arch/arm/mach-stm32mp/ecdsa_romapi.c          | 20 ++---------
  .../arm/mach-stm32mp/include/mach/sys_proto.h |  3 ++
  4 files changed, 42 insertions(+), 36 deletions(-)

Thanks
Patrick

Reviewed-by on v3 2/4
#3 lore raw

Re: [PATCH v3 2/4] ARM: stm32: Factor out save_boot_params

In reply to Marek Vasut

Hi Marek

Quoted 139 lines · Marek Vasut

The STM32MP15xx platform currently comes with two incompatible implementations of save_boot_params() weak function override. Factor the save_boot_params() implementation into common cpu.c code and provide accessors to read out both ROM API table address and DT address from any place in the code instead.

---
Cc: Alexandru Gagniuc <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
---
V2: Avoid #if CONFIG... , use if (CONFIG... instead
V3: No change

---
 arch/arm/mach-stm32mp/boot_params.c           | 20 ++---------
 arch/arm/mach-stm32mp/cpu.c                   | 35 +++++++++++++++++++
 arch/arm/mach-stm32mp/ecdsa_romapi.c          | 20 ++---------
 .../arm/mach-stm32mp/include/mach/sys_proto.h |  3 ++
 4 files changed, 42 insertions(+), 36 deletions(-)
arch/arm/mach-stm32mp/boot_params.c +2 -18
index e91ef1b2fc7..e40cca938ef 100644
@@ -11,30 +11,14 @@
 #include <asm/sections.h>
 #include <asm/system.h>
 
-/*
- * Force data-section, as .bss will not be valid
- * when save_boot_params is invoked.
- */
-static unsigned long nt_fw_dtb __section(".data");
-
-/*
- * Save the FDT address provided by TF-A in r2 at boot time
- * This function is called from start.S
- */
-void save_boot_params(unsigned long r0, unsigned long r1, unsigned long r2,
-		      unsigned long r3)
-{
-	nt_fw_dtb = r2;
-
-	save_boot_params_ret();
-}
-
 /*
  * Use the saved FDT address provided by TF-A at boot time (NT_FW_CONFIG =
  * Non Trusted Firmware configuration file) when the pointer is valid
  */
 void *board_fdt_blob_setup(int *err)
 {
+	unsigned long nt_fw_dtb = get_stm32mp_bl2_dtb();
+
 	log_debug("%s: nt_fw_dtb=%lx\n", __func__, nt_fw_dtb);
 
 	*err = 0;
arch/arm/mach-stm32mp/cpu.c +35 -0
index 855fc755fe0..ee59866bb73 100644
@@ -378,3 +378,38 @@ int arch_misc_init(void)
 
 	return 0;
 }
+
+/*
+ * Without forcing the ".data" section, this would get saved in ".bss". BSS
+ * will be cleared soon after, so it's not suitable.
+ */
+static uintptr_t rom_api_table __section(".data");
+static uintptr_t nt_fw_dtb __section(".data");
+
+/*
+ * The ROM gives us the API location in r0 when starting. This is only available
+ * during SPL, as there isn't (yet) a mechanism to pass this on to u-boot. Save
+ * the FDT address provided by TF-A in r2 at boot time. This function is called
+ * from start.S
+ */
+void save_boot_params(unsigned long r0, unsigned long r1, unsigned long r2,
+		      unsigned long r3)
+{
+	if (IS_ENABLED(CONFIG_STM32_ECDSA_VERIFY))
+		rom_api_table = r0;
+
+	if (IS_ENABLED(CONFIG_TFABOOT))
+		nt_fw_dtb = r2;
+
+	save_boot_params_ret();
+}
+
+uintptr_t get_stm32mp_rom_api_table(void)
+{
+	return rom_api_table;
+}
+
+uintptr_t get_stm32mp_bl2_dtb(void)
+{
+	return nt_fw_dtb;
+}
arch/arm/mach-stm32mp/ecdsa_romapi.c +2 -18
index 6156526253c..12b42b9d59c 100644
@@ -24,26 +24,10 @@ struct ecdsa_rom_api {
 					   uint32_t ecc_algo);
 };
 
-/*
- * Without forcing the ".data" section, this would get saved in ".bss". BSS
- * will be cleared soon after, so it's not suitable.
- */
-static uintptr_t rom_api_loc __section(".data");
-
-/*
- * The ROM gives us the API location in r0 when starting. This is only available
- * during SPL, as there isn't (yet) a mechanism to pass this on to u-boot.
- */
-void save_boot_params(unsigned long r0, unsigned long r1, unsigned long r2,
-		      unsigned long r3)
-{
-	rom_api_loc = r0;
-	save_boot_params_ret();
-}
-
 static void stm32mp_rom_get_ecdsa_functions(struct ecdsa_rom_api *rom)
 {
-	uintptr_t verify_ptr = rom_api_loc + ROM_API_OFFSET_ECDSA_VERIFY;
+	uintptr_t verify_ptr = get_stm32mp_rom_api_table() +
+			       ROM_API_OFFSET_ECDSA_VERIFY;
 
 	rom->ecdsa_verify_signature = *(void **)verify_ptr;
 }
arch/arm/mach-stm32mp/include/mach/sys_proto.h +0 -0
index f19a70e53e0..0d39b67178e 100644

arch/arm/mach-stm32mp/include/mach/sys_proto.h void stm32mp_misc_init(void); · line 82

Quoted 6 lines
arch/arm/mach-stm32mp/include/mach/sys_proto.h +3 -0
@@ -77,3 +77,6 @@ void stm32mp_misc_init(void);
 
 /* helper function: read data from OTP */
 u32 get_otp(int index, int shift, int mask);
+
+uintptr_t get_stm32mp_rom_api_table(void);
+uintptr_t get_stm32mp_bl2_dtb(void);

Thanks
Patrice

#4 lore raw

Re: [PATCH v3 2/4] ARM: stm32: Factor out save_boot_params

Hi Marek

I am preparing the next STM32 U-Boot pull request, during testing, buidlman is complaining with the following warning:

03: ARM: stm32: Factor out save_boot_params

       arm:  +   stm32mp13

+../arch/arm/mach-stm32mp/boot_params.c: In function 'board_fdt_blob_setup':
+../arch/arm/mach-stm32mp/boot_params.c:20:35: error: implicit declaration of function 'get_stm32mp_bl2_dtb' [-Werror=implicit-function-declaration]
+ 20 | unsigned long nt_fw_dtb = get_stm32mp_bl2_dtb();
+ | ^~~~~~~~~~~~~~~~~~~
+cc1: all warnings being treated as errors

Same issue with stm32mp15_defconfig and stm32mp15_trusted_defconfig.

Regards
Patrice

Quoted 153 lines · Patrice CHOTARD

Hi Marek

Quoted 139 lines · Marek Vasut

The STM32MP15xx platform currently comes with two incompatible implementations of save_boot_params() weak function override. Factor the save_boot_params() implementation into common cpu.c code and provide accessors to read out both ROM API table address and DT address from any place in the code instead.

---
Cc: Alexandru Gagniuc <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
---
V2: Avoid #if CONFIG... , use if (CONFIG... instead
V3: No change

---
 arch/arm/mach-stm32mp/boot_params.c           | 20 ++---------
 arch/arm/mach-stm32mp/cpu.c                   | 35 +++++++++++++++++++
 arch/arm/mach-stm32mp/ecdsa_romapi.c          | 20 ++---------
 .../arm/mach-stm32mp/include/mach/sys_proto.h |  3 ++
 4 files changed, 42 insertions(+), 36 deletions(-)
arch/arm/mach-stm32mp/boot_params.c +2 -18
index e91ef1b2fc7..e40cca938ef 100644
@@ -11,30 +11,14 @@
 #include <asm/sections.h>
 #include <asm/system.h>
 
-/*
- * Force data-section, as .bss will not be valid
- * when save_boot_params is invoked.
- */
-static unsigned long nt_fw_dtb __section(".data");
-
-/*
- * Save the FDT address provided by TF-A in r2 at boot time
- * This function is called from start.S
- */
-void save_boot_params(unsigned long r0, unsigned long r1, unsigned long r2,
-		      unsigned long r3)
-{
-	nt_fw_dtb = r2;
-
-	save_boot_params_ret();
-}
-
 /*
  * Use the saved FDT address provided by TF-A at boot time (NT_FW_CONFIG =
  * Non Trusted Firmware configuration file) when the pointer is valid
  */
 void *board_fdt_blob_setup(int *err)
 {
+	unsigned long nt_fw_dtb = get_stm32mp_bl2_dtb();
+
 	log_debug("%s: nt_fw_dtb=%lx\n", __func__, nt_fw_dtb);
 
 	*err = 0;
arch/arm/mach-stm32mp/cpu.c +35 -0
index 855fc755fe0..ee59866bb73 100644
@@ -378,3 +378,38 @@ int arch_misc_init(void)
 
 	return 0;
 }
+
+/*
+ * Without forcing the ".data" section, this would get saved in ".bss". BSS
+ * will be cleared soon after, so it's not suitable.
+ */
+static uintptr_t rom_api_table __section(".data");
+static uintptr_t nt_fw_dtb __section(".data");
+
+/*
+ * The ROM gives us the API location in r0 when starting. This is only available
+ * during SPL, as there isn't (yet) a mechanism to pass this on to u-boot. Save
+ * the FDT address provided by TF-A in r2 at boot time. This function is called
+ * from start.S
+ */
+void save_boot_params(unsigned long r0, unsigned long r1, unsigned long r2,
+		      unsigned long r3)
+{
+	if (IS_ENABLED(CONFIG_STM32_ECDSA_VERIFY))
+		rom_api_table = r0;
+
+	if (IS_ENABLED(CONFIG_TFABOOT))
+		nt_fw_dtb = r2;
+
+	save_boot_params_ret();
+}
+
+uintptr_t get_stm32mp_rom_api_table(void)
+{
+	return rom_api_table;
+}
+
+uintptr_t get_stm32mp_bl2_dtb(void)
+{
+	return nt_fw_dtb;
+}
arch/arm/mach-stm32mp/ecdsa_romapi.c +2 -18
index 6156526253c..12b42b9d59c 100644
@@ -24,26 +24,10 @@ struct ecdsa_rom_api {
 					   uint32_t ecc_algo);
 };
 
-/*
- * Without forcing the ".data" section, this would get saved in ".bss". BSS
- * will be cleared soon after, so it's not suitable.
- */
-static uintptr_t rom_api_loc __section(".data");
-
-/*
- * The ROM gives us the API location in r0 when starting. This is only available
- * during SPL, as there isn't (yet) a mechanism to pass this on to u-boot.
- */
-void save_boot_params(unsigned long r0, unsigned long r1, unsigned long r2,
-		      unsigned long r3)
-{
-	rom_api_loc = r0;
-	save_boot_params_ret();
-}
-
 static void stm32mp_rom_get_ecdsa_functions(struct ecdsa_rom_api *rom)
 {
-	uintptr_t verify_ptr = rom_api_loc + ROM_API_OFFSET_ECDSA_VERIFY;
+	uintptr_t verify_ptr = get_stm32mp_rom_api_table() +
+			       ROM_API_OFFSET_ECDSA_VERIFY;
 
 	rom->ecdsa_verify_signature = *(void **)verify_ptr;
 }
arch/arm/mach-stm32mp/include/mach/sys_proto.h +0 -0
index f19a70e53e0..0d39b67178e 100644

arch/arm/mach-stm32mp/include/mach/sys_proto.h void stm32mp_misc_init(void); · line 82

Quoted 6 lines
arch/arm/mach-stm32mp/include/mach/sys_proto.h +3 -0
@@ -77,3 +77,6 @@ void stm32mp_misc_init(void);
 
 /* helper function: read data from OTP */
 u32 get_otp(int index, int shift, int mask);
+
+uintptr_t get_stm32mp_rom_api_table(void);
+uintptr_t get_stm32mp_bl2_dtb(void);

Thanks
Patrice

#5 lore raw

Re: [PATCH v3 2/4] ARM: stm32: Factor out save_boot_params

Quoted 1 line · Patrice CHOTARD

Hi Marek

Hi,

Quoted 11 lines

I am preparing the next STM32 U-Boot pull request, during testing, buidlman is complaining with the following warning:

03: ARM: stm32: Factor out save_boot_params

        arm:  +   stm32mp13

+../arch/arm/mach-stm32mp/boot_params.c: In function 'board_fdt_blob_setup':
+../arch/arm/mach-stm32mp/boot_params.c:20:35: error: implicit declaration of function 'get_stm32mp_bl2_dtb' [-Werror=implicit-function-declaration]

(quoted diff) +3 -0
+   20 |         unsigned long nt_fw_dtb = get_stm32mp_bl2_dtb();
+      |                                   ^~~~~~~~~~~~~~~~~~~
+cc1: all warnings being treated as errors
Quoted 1 line

Same issue with stm32mp15_defconfig and stm32mp15_trusted_defconfig.

Sorry for the inconvenience.

Does the change below help ?
If so, can you squash it into 2/4 or do you want v4 ?

arch/arm/mach-stm32mp/boot_params.c +1 -0
index e40cca938ef..24d04dcf0f9 100644
@@ -8,6 +8,7 @@
 #include <common.h>
 #include <log.h>
 #include <linux/libfdt.h>
+#include <asm/arch/sys_proto.h>
 #include <asm/sections.h>
 #include <asm/system.h>
#6 lore raw

Re: [PATCH v3 2/4] ARM: stm32: Factor out save_boot_params

Hi Marek

Quoted 16 lines · Marek Vasut
Quoted 1 line · Patrice CHOTARD

Hi Marek

Hi,

Quoted 11 lines

I am preparing the next STM32 U-Boot pull request, during testing, buidlman is complaining with the following warning:

03: ARM: stm32: Factor out save_boot_params
        arm:  +   stm32mp13
+../arch/arm/mach-stm32mp/boot_params.c: In function 'board_fdt_blob_setup':
+../arch/arm/mach-stm32mp/boot_params.c:20:35: error: implicit declaration of function 'get_stm32mp_bl2_dtb' [-Werror=implicit-function-declaration] +   20 |         unsigned long nt_fw_dtb = get_stm32mp_bl2_dtb();
+      |                                   ^~~~~~~~~~~~~~~~~~~
+cc1: all warnings being treated as errors

Quoted 6 lines
Quoted 1 line

Same issue with stm32mp15_defconfig and stm32mp15_trusted_defconfig.

Sorry for the inconvenience.

Does the change below help ?
If so, can you squash it into 2/4 or do you want v4 ?

Yes the change you proposed is OK.
I saw that you have submitted a v4 including this fix, i will add it to the next U-Boot STM32 PR.

Thanks for your reactivity ;-)

Patrice

Quoted 12 lines
arch/arm/mach-stm32mp/boot_params.c +1 -0
index e40cca938ef..24d04dcf0f9 100644
@@ -8,6 +8,7 @@
  #include <common.h>
  #include <log.h>
  #include <linux/libfdt.h>
+#include <asm/arch/sys_proto.h>
  #include <asm/sections.h>
  #include <asm/system.h>
#7 lore raw

Re: [PATCH v3 2/4] ARM: stm32: Factor out save_boot_params

Quoted 1 line · Patrice CHOTARD

Hi Marek

Hello Patrice,

Quoted 19 lines · Marek Vasut
Quoted 18 lines · Patrice CHOTARD
Quoted 1 line

Hi Marek

Hi,

Quoted 12 lines

I am preparing the next STM32 U-Boot pull request, during testing, buidlman is complaining with the following warning:

03: ARM: stm32: Factor out save_boot_params
        arm:  +   stm32mp13
+../arch/arm/mach-stm32mp/boot_params.c: In function 'board_fdt_blob_setup':
+../arch/arm/mach-stm32mp/boot_params.c:20:35: error: implicit declaration of function 'get_stm32mp_bl2_dtb' [-Werror=implicit-function-declaration] +   20 |         unsigned long nt_fw_dtb = get_stm32mp_bl2_dtb();
+      |                                   ^~~~~~~~~~~~~~~~~~~
+cc1: all warnings being treated as errors

Same issue with stm32mp15_defconfig and stm32mp15_trusted_defconfig.

Quoted 7 lines
Quoted 4 lines

Sorry for the inconvenience.

Does the change below help ?
If so, can you squash it into 2/4 or do you want v4 ?

Yes the change you proposed is OK.
I saw that you have submitted a v4 including this fix, i will add it to the next U-Boot STM32 PR.

Thanks !

Quoted 1 line

Thanks for your reactivity ;-)

:)

#8 lore raw

PATCH v3 3/4 ARM: stm32: Pass ROM API table pointer to U-Boot proper

In reply to Marek Vasut

The ROM API table pointer is no longer accessible from U-Boot, fix this by passing the ROM API pointer through. This makes it possible for U-Boot to call ROM API functions to authenticate payload like signed fitImages.

---
Cc: Alexandru Gagniuc <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
---
V2: - Rename image_entry_noargs_t to image_entry_stm32_t
- Add missing __noreturn
V3: No change

---
 arch/arm/mach-stm32mp/cpu.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
arch/arm/mach-stm32mp/cpu.c +15 -0
index ee59866bb73..dc4112d5e6c 100644
@@ -22,6 +22,7 @@
 #include <dm/device.h>
 #include <dm/uclass.h>
 #include <linux/bitops.h>
+#include <spl.h>
 
 /*
  * early TLB into the .data section so that it not get cleared
@@ -413,3 +414,17 @@ uintptr_t get_stm32mp_bl2_dtb(void)
 {
 	return nt_fw_dtb;
 }
+
+#ifdef CONFIG_SPL_BUILD
+void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
+{
+	typedef void __noreturn (*image_entry_stm32_t)(u32 romapi);
+	uintptr_t romapi = get_stm32mp_rom_api_table();
+
+	image_entry_stm32_t image_entry =
+		(image_entry_stm32_t)spl_image->entry_point;
+
+	printf("image entry point: 0x%lx\n", spl_image->entry_point);
+	image_entry(romapi);
+}
+#endif
Signature · 1 line
2.35.1
Reviewed-by on v3 3/4
#9 lore raw

Re: [PATCH v3 3/4] ARM: stm32: Pass ROM API table pointer to U-Boot proper

Hi,

Quoted 38 lines · Marek Vasut

The ROM API table pointer is no longer accessible from U-Boot, fix this by passing the ROM API pointer through. This makes it possible for U-Boot to call ROM API functions to authenticate payload like signed fitImages.

---
Cc: Alexandru Gagniuc <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
---
V2: - Rename image_entry_noargs_t to image_entry_stm32_t
- Add missing __noreturn
V3: No change

---
  arch/arm/mach-stm32mp/cpu.c | 15 +++++++++++++++
  1 file changed, 15 insertions(+)
arch/arm/mach-stm32mp/cpu.c +5 -0
index ee59866bb73..dc4112d5e6c 100644
@@ -22,6 +22,7 @@
  #include <dm/device.h>
  #include <dm/uclass.h>
  #include <linux/bitops.h>
+#include <spl.h>
 
  /*
   * early TLB into the .data section so that it not get cleared
@@ -413,3 +414,17 @@ uintptr_t get_stm32mp_bl2_dtb(void)
  {
  	return nt_fw_dtb;
  }
+
+#ifdef CONFIG_SPL_BUILD
+void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
+{

arch/arm/mach-stm32mp/cpu.c uintptr_t get_stm32mp_bl2_dtb(void) · line 430

Quoted 10 lines
arch/arm/mach-stm32mp/cpu.c +10 -0
+	typedef void __noreturn (*image_entry_stm32_t)(u32 romapi);
+	uintptr_t romapi = get_stm32mp_rom_api_table();
+
+	image_entry_stm32_t image_entry =
+		(image_entry_stm32_t)spl_image->entry_point;
+
+	printf("image entry point: 0x%lx\n", spl_image->entry_point);
+	image_entry(romapi);
+}
+#endif

Thanks
Patrick

Reviewed-by on v3 3/4
#10 lore raw

Re: [PATCH v3 3/4] ARM: stm32: Pass ROM API table pointer to U-Boot proper

In reply to Marek Vasut

Hi Marek

Quoted 38 lines · Marek Vasut

The ROM API table pointer is no longer accessible from U-Boot, fix this by passing the ROM API pointer through. This makes it possible for U-Boot to call ROM API functions to authenticate payload like signed fitImages.

---
Cc: Alexandru Gagniuc <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
---
V2: - Rename image_entry_noargs_t to image_entry_stm32_t
- Add missing __noreturn
V3: No change

---
 arch/arm/mach-stm32mp/cpu.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
arch/arm/mach-stm32mp/cpu.c +5 -0
index ee59866bb73..dc4112d5e6c 100644
@@ -22,6 +22,7 @@
 #include <dm/device.h>
 #include <dm/uclass.h>
 #include <linux/bitops.h>
+#include <spl.h>
 
 /*
  * early TLB into the .data section so that it not get cleared
@@ -413,3 +414,17 @@ uintptr_t get_stm32mp_bl2_dtb(void)
 {
 	return nt_fw_dtb;
 }
+
+#ifdef CONFIG_SPL_BUILD
+void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
+{

arch/arm/mach-stm32mp/cpu.c uintptr_t get_stm32mp_bl2_dtb(void) · line 430

Quoted 10 lines
arch/arm/mach-stm32mp/cpu.c +10 -0
+	typedef void __noreturn (*image_entry_stm32_t)(u32 romapi);
+	uintptr_t romapi = get_stm32mp_rom_api_table();
+
+	image_entry_stm32_t image_entry =
+		(image_entry_stm32_t)spl_image->entry_point;
+
+	printf("image entry point: 0x%lx\n", spl_image->entry_point);
+	image_entry(romapi);
+}
+#endif

Thanks
Patrice

#11 lore raw

PATCH v3 4/4 ARM: stm32: Make ECDSA authentication available to U-Boot

In reply to Marek Vasut

With U-Boot having access to ROM API call table, it is possible to use the ROM API call it authenticate e.g. signed kernel fitImages using the BootROM ECDSA support. Make this available by pulling the ECDSA BootROM call support from SPL-only guard.

---
Cc: Alexandru Gagniuc <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
---
V2: Add RB from Patrice and Patrick
V3: No change

---
 arch/arm/mach-stm32mp/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mach-stm32mp/Makefile +1 -1
index 1db9057e049..a19b2797c8b 100644
@@ -11,10 +11,10 @@ obj-y += bsec.o
 obj-$(CONFIG_STM32MP13x) += stm32mp13x.o
 obj-$(CONFIG_STM32MP15x) += stm32mp15x.o
 
+obj-$(CONFIG_STM32_ECDSA_VERIFY) += ecdsa_romapi.o
 ifdef CONFIG_SPL_BUILD
 obj-y += spl.o
 obj-y += tzc400.o
-obj-$(CONFIG_STM32_ECDSA_VERIFY) += ecdsa_romapi.o
 else
 obj-y += cmd_stm32prog/
 obj-$(CONFIG_CMD_STM32KEY) += cmd_stm32key.o
Signature · 1 line
2.35.1
Reviewed-by on v3 1/4
#12 lore raw
In reply to Marek Vasut

Hi,

Quoted 23 lines · Marek Vasut

In case Dcache is enabled while the ECDSA authentication function is called via BootROM ROM API, the MMU tables are set up and the BootROM region is not marked as executable, so an attempt to run code from it results in a hang. Mark the BootROM region as executable as suggested by Patrick to prevent the hang.

---
Cc: Alexandru Gagniuc <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
---
V2: - Initialize reenable_dcache variable
V3: - Mark BootROM as executable instead

---
  arch/arm/mach-stm32mp/ecdsa_romapi.c | 4 ++++
  1 file changed, 4 insertions(+)
arch/arm/mach-stm32mp/ecdsa_romapi.c +0 -0
index a2f63ff879f..6156526253c 100644

arch/arm/mach-stm32mp/ecdsa_romapi.c static int romapi_ecdsa_verify(struct udevice *dev, · line 90

Quoted 10 lines
arch/arm/mach-stm32mp/ecdsa_romapi.c +4 -0
@@ -81,6 +81,10 @@ static int romapi_ecdsa_verify(struct udevice *dev,
  	memcpy(raw_key + 32, pubkey->y, 32);
 
  	stm32mp_rom_get_ecdsa_functions(&rom);
+
+	/* Mark BootROM region as executable. */
+	mmu_set_region_dcache_behaviour(0, SZ_2M, DCACHE_DEFAULT_OPTION);
+
  	rom_ret = rom.ecdsa_verify_signature(hash, raw_key, signature, algo);
 
  	return rom_ret == ROM_API_SUCCESS ? 0 : -EPERM;

Thanks
Patrick

Reviewed-by on v3 1/4
#13 lore raw
In reply to Marek Vasut

Hi Marek

Quoted 23 lines · Marek Vasut

In case Dcache is enabled while the ECDSA authentication function is called via BootROM ROM API, the MMU tables are set up and the BootROM region is not marked as executable, so an attempt to run code from it results in a hang. Mark the BootROM region as executable as suggested by Patrick to prevent the hang.

---
Cc: Alexandru Gagniuc <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
---
V2: - Initialize reenable_dcache variable
V3: - Mark BootROM as executable instead

---
 arch/arm/mach-stm32mp/ecdsa_romapi.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/arm/mach-stm32mp/ecdsa_romapi.c +0 -0
index a2f63ff879f..6156526253c 100644

arch/arm/mach-stm32mp/ecdsa_romapi.c static int romapi_ecdsa_verify(struct udevice *dev, · line 90

Quoted 10 lines
arch/arm/mach-stm32mp/ecdsa_romapi.c +4 -0
@@ -81,6 +81,10 @@ static int romapi_ecdsa_verify(struct udevice *dev,
 	memcpy(raw_key + 32, pubkey->y, 32);
 
 	stm32mp_rom_get_ecdsa_functions(&rom);
+
+	/* Mark BootROM region as executable. */
+	mmu_set_region_dcache_behaviour(0, SZ_2M, DCACHE_DEFAULT_OPTION);
+
 	rom_ret = rom.ecdsa_verify_signature(hash, raw_key, signature, algo);
 
 	return rom_ret == ROM_API_SUCCESS ? 0 : -EPERM;

Thanks
Patrice