Skip to contentSkip to conversation

stm32mp1: add trusted boot with TF-A

PATCH Superseded Patrick Delaunay 2 participants 5 messages Jan 28, 2019 – Feb 8, 2019

Subsystems (4)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover stm32mp1: add trusted boot with TF-A

This patch serie add a new configuration stm32mp15_trusted_defconfig to handle STM32MP157 boards with TF-A as secure first stage bootloader.

TF-A code is available in GitHub
https://github.com/ARM-software/arm-trusted-firmware

With platform stm32mp1 platform
https://github.com/ARM-software/arm-trusted-firmware/tree/master/plat/st/stm32mp1

For details, see documentation
https://github.com/ARM-software/arm-trusted-firmware/blob/master/docs/plat/stm32mp1.rst

PS: upstream of trusted boot for TF-A is still in progress.

Patrick Delaunay (3):
stm32mp1: add trusted boot with TF-A
stm32mp1: bsec: access with SMC for trusted boot
stm32mp1: display board information

 arch/arm/Kconfig                                  |  6 ++-
 arch/arm/mach-stm32mp/Kconfig                     | 17 ++++--
 arch/arm/mach-stm32mp/bsec.c                      | 28 ++++++++++
 arch/arm/mach-stm32mp/config.mk                   | 15 +++++-
 arch/arm/mach-stm32mp/cpu.c                       |  9 +++-
 arch/arm/mach-stm32mp/include/mach/stm32.h        |  4 ++
 arch/arm/mach-stm32mp/include/mach/stm32mp1_smc.h | 64 +++++++++++++++++++++++
 board/st/stm32mp1/MAINTAINERS                     |  5 +-
 board/st/stm32mp1/README                          | 56 ++++++++++++++------
 board/st/stm32mp1/stm32mp1.c                      | 44 +++++++++++++++-
 configs/stm32mp15_trusted_defconfig               | 57 ++++++++++++++++++++
 drivers/clk/clk_stm32mp1.c                        |  2 +
 drivers/ram/stm32mp1/stm32mp1_ram.c               |  3 +-
 include/configs/stm32mp1.h                        |  2 +
 14 files changed, 282 insertions(+), 30 deletions(-)
 create mode 100644 arch/arm/mach-stm32mp/include/mach/stm32mp1_smc.h
 create mode 100644 configs/stm32mp15_trusted_defconfig
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/3 stm32mp1: add trusted boot with TF-A

Add support of trusted boot, using TF-A as first stage bootloader, The boot sequence is
BootRom >=> TF-A.stm32 (clock & DDR) >=> U-Boot.stm32

The TF-A monitor provides secure monitor with support of SMC
- proprietary to manage secure devices (BSEC for example)
- PSCI for power

The same device tree is used for STMicroelectronics boards with basic boot and with trusted boot.

---

 arch/arm/Kconfig                    |  6 ++--
 arch/arm/mach-stm32mp/Kconfig       | 17 +++++++++--
 arch/arm/mach-stm32mp/config.mk     | 15 +++++++++-
 arch/arm/mach-stm32mp/cpu.c         |  9 ++++--
 board/st/stm32mp1/MAINTAINERS       |  5 ++--
 board/st/stm32mp1/README            | 56 +++++++++++++++++++++++++-----------
 configs/stm32mp15_trusted_defconfig | 57 +++++++++++++++++++++++++++++++++++++
 drivers/clk/clk_stm32mp1.c          |  2 ++
 drivers/ram/stm32mp1/stm32mp1_ram.c |  3 +-
 include/configs/stm32mp1.h          |  2 ++
 10 files changed, 144 insertions(+), 28 deletions(-)
 create mode 100644 configs/stm32mp15_trusted_defconfig
arch/arm/Kconfig +4 -2
index d6b1629..2ee1dfe 100644
@@ -1351,8 +1351,10 @@ config ARCH_STM32MP
 	help
 	  Support for STM32MP SoC family developed by STMicroelectronics,
 	  MPUs based on ARM cortex A core
-	  U-BOOT is running in DDR and SPL support is the unsecure First Stage
-	  BootLoader (FSBL)
+	  U-BOOT is running in DDR, loaded by the First Stage BootLoader (FSBL).
+	  FSBL can be TF-A: Trusted Firmware for Cortex A, for trusted boot
+	  chain.
+	  SPL is the unsecure FSBL for the basic boot chain.
 
 config ARCH_ROCKCHIP
 	bool "Support Rockchip SoCs"
arch/arm/mach-stm32mp/Kconfig +14 -3
index 8a929fa..3101d80 100644
@@ -25,19 +25,30 @@ config SYS_SOC
 
 config TARGET_STM32MP1
 	bool "Support stm32mp1xx"
-	select ARCH_SUPPORT_PSCI
+	select ARCH_SUPPORT_PSCI if !STM32MP1_TRUSTED
 	select CPU_V7A
-	select CPU_V7_HAS_NONSEC
+	select CPU_V7_HAS_NONSEC if !STM32MP1_TRUSTED
 	select CPU_V7_HAS_VIRT
 	select PINCTRL_STM32
 	select STM32_RCC
 	select STM32_RESET
 	select SYS_ARCH_TIMER
-	select SYSRESET_SYSCON
+	imply SYSRESET_PSCI if STM32MP1_TRUSTED
+	imply SYSRESET_SYSCON if !STM32MP1_TRUSTED
 	help
 		target STMicroelectronics SOC STM32MP1 family
 		STMicroelectronics MPU with core ARMv7
 
+config STM32MP1_TRUSTED
+	bool "Support trusted boot with TF-A"
+	default y if !SPL
+	select ARM_SMCCC
+	help
+		Say Y here to enable boot with TF-A
+		Trusted boot chain is :
+		BootRom => TF-A.stm32 (clock & DDR) => U-Boot.stm32
+		TF-A monitor provides proprietary smc to manage secure devices
+
 config SYS_TEXT_BASE
 	prompt "U-Boot base address"
 	default 0xC0100000
arch/arm/mach-stm32mp/config.mk +14 -1
index cde5850..c2d74a0 100644
@@ -3,7 +3,20 @@
 # Copyright (C) 2018, STMicroelectronics - All Rights Reserved
 #
 
-ALL-$(CONFIG_SPL_BUILD) += spl/u-boot-spl.stm32
+ifndef CONFIG_SPL
+ALL-y += u-boot.stm32
+else
+ifdef CONFIG_SPL_BUILD
+ALL-y += spl/u-boot-spl.stm32
+endif
+endif
+
+MKIMAGEFLAGS_u-boot.stm32 = -T stm32image -a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_TEXT_BASE)
+
+u-boot.stm32: MKIMAGEOUTPUT = u-boot.stm32.log
+
+u-boot.stm32: u-boot.bin FORCE
+	$(call if_changed,mkimage)
 
 MKIMAGEFLAGS_u-boot-spl.stm32 = -T stm32image -a $(CONFIG_SPL_TEXT_BASE) -e $(CONFIG_SPL_TEXT_BASE)
 
arch/arm/mach-stm32mp/cpu.c +7 -2
index b893358..b96720f 100644
@@ -59,6 +59,7 @@
 #define BSEC_OTP_MAC	57
 
 #if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD)
+#ifndef CONFIG_STM32MP1_TRUSTED
 static void security_init(void)
 {
 	/* Disable the backup domain write protection */
@@ -114,6 +115,7 @@ static void security_init(void)
 	 */
 	writel(0x0, TAMP_CR1);
 }
+#endif /* CONFIG_STM32MP1_TRUSTED */
 
 /*
  * Debug init
@@ -130,7 +132,8 @@ static void dbgmcu_init(void)
 static u32 get_bootmode(void)
 {
 	u32 boot_mode;
-#if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD)
+#if !defined(CONFIG_STM32MP1_TRUSTED) && \
+	(!defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD))
 	u32 bootrom_itf = readl(BOOTROM_PARAM_ADDR);
 	u32 bootrom_device, bootrom_instance;
 
@@ -167,9 +170,10 @@ int arch_cpu_init(void)
 
 #if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD)
 	dbgmcu_init();
-
+#ifndef CONFIG_STM32MP1_TRUSTED
 	security_init();
 #endif
+#endif
 
 	/* get bootmode from BootRom context: saved in TAMP register */
 	boot_mode = get_bootmode();
@@ -177,6 +181,7 @@ int arch_cpu_init(void)
 	if ((boot_mode & TAMP_BOOT_DEVICE_MASK) == BOOT_SERIAL_UART)
 		gd->flags |= GD_FLG_SILENT | GD_FLG_DISABLE_CONSOLE;
 #if defined(CONFIG_DEBUG_UART) && \
+	!defined(CONFIG_STM32MP1_TRUSTED) && \
 	(!defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD))
 	else
 		debug_uart_init();
board/st/stm32mp1/MAINTAINERS +3 -2
index 48d8fd2..0a2eddb 100644
@@ -2,7 +2,8 @@ STM32MP1 BOARD
 M:	Patrick Delaunay <[email protected]>
 L:	uboot-stm32 at st-md-mailman.stormreply.com (moderated for non-subscribers)
 S:	Maintained
+F:	arch/arm/dts/stm32mp157*
 F:	board/st/stm32mp1
-F:	include/configs/stm32mp1.h
 F:	configs/stm32mp15_basic_defconfig
-F:	arch/arm/dts/stm32mp157*
+F:	configs/stm32mp15_trusted_defconfig
+F:	include/configs/stm32mp1.h
board/st/stm32mp1/README +39 -17

139 lines not on this page · raw message

configs/stm32mp15_trusted_defconfig new file +57 -0

57 lines not on this page · raw message

drivers/clk/clk_stm32mp1.c +2 -0
index b7c5d34..9e9c667 100644
@@ -15,10 +15,12 @@
 #include <dt-bindings/clock/stm32mp1-clks.h>
 #include <dt-bindings/clock/stm32mp1-clksrc.h>
 
+#ifndef CONFIG_STM32MP1_TRUSTED
 #if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD)
 /* activate clock tree initialization in the driver */
 #define STM32MP1_CLOCK_TREE_INIT
 #endif
+#endif
 
 #define MAX_HSI_HZ		64000000
 
drivers/ram/stm32mp1/stm32mp1_ram.c +2 -1
index bd497a3..e45a3b2 100644
@@ -157,7 +157,8 @@ static int stm32mp1_ddr_probe(struct udevice *dev)
 
 	priv->info.base = STM32_DDR_BASE;
 
-#if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD)
+#if !defined(CONFIG_STM32MP1_TRUSTED) && \
+	(!defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD))
 	priv->info.size = 0;
 	return stm32mp1_ddr_setup(dev);
 #else
include/configs/stm32mp1.h +2 -0
index 701298c..4722672 100644
@@ -17,10 +17,12 @@
  */
 #define CONFIG_SYS_HZ				1000
 
+#ifndef CONFIG_STM32MP1_TRUSTED
 /* PSCI support */
 #define CONFIG_ARMV7_PSCI_1_0
 #define CONFIG_ARMV7_SECURE_BASE		STM32_SYSRAM_BASE
 #define CONFIG_ARMV7_SECURE_MAX_SIZE		STM32_SYSRAM_SIZE
+#endif
 
 /*
  * malloc() pool size
Signature · 1 line
2.7.4
#2 lore raw

PATCH 1/3 stm32mp1: add trusted boot with TF-A

Quoted 11 lines · Patrick Delaunay

Add support of trusted boot, using TF-A as first stage bootloader, The boot sequence is
BootRom >=> TF-A.stm32 (clock & DDR) >=> U-Boot.stm32

The TF-A monitor provides secure monitor with support of SMC
- proprietary to manage secure devices (BSEC for example)
- PSCI for power

The same device tree is used for STMicroelectronics boards with basic boot and with trusted boot.

Quoted 6 lines

---

 arch/arm/Kconfig                    |  6 ++--
 arch/arm/mach-stm32mp/Kconfig       | 17 +++++++++--
 arch/arm/mach-stm32mp/config.mk     | 15 +++++++++-

Sorry. My messing up of the patches to arch/arm/mach-stm32mp/config.mk before means this part doesn't apply cleanly and since I don't want to mess it up again and cause another round of changes here can you please rebase this series on master? Thanks and sorry for the trouble!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190208/b9d45520/attachment.sig>
#3 lore raw

PATCH 2/3 stm32mp1: bsec: access with SMC for trusted boot

In reply to Patrick Delaunay

As BSEC is secure aware, all register access need to be done by TF-A for TRUSTED boot chain, when U-Boot is executed in normal world.

---

 arch/arm/mach-stm32mp/bsec.c                      | 28 ++++++++++
 arch/arm/mach-stm32mp/include/mach/stm32mp1_smc.h | 64 +++++++++++++++++++++++
 2 files changed, 92 insertions(+)
 create mode 100644 arch/arm/mach-stm32mp/include/mach/stm32mp1_smc.h
arch/arm/mach-stm32mp/bsec.c +28 -0
index d087a31..920a6c9 100644
@@ -8,9 +8,12 @@
 #include <misc.h>
 #include <asm/io.h>
 #include <linux/iopoll.h>
+#include <asm/arch/stm32mp1_smc.h>
+#include <linux/arm-smccc.h>
 
 #define BSEC_OTP_MAX_VALUE		95
 
+#ifndef CONFIG_STM32MP1_TRUSTED
 #define BSEC_TIMEOUT_US			10000
 
 /* BSEC REGISTER OFFSET (base relative) */
@@ -270,6 +273,7 @@ static int bsec_program_otp(long base, u32 val, u32 otp)
 
 	return ret;
 }
+#endif /* CONFIG_STM32MP1_TRUSTED */
 
 /* BSEC MISC driver *******************************************************/
 struct stm32mp_bsec_platdata {
@@ -278,6 +282,11 @@ struct stm32mp_bsec_platdata {
 
 static int stm32mp_bsec_read_otp(struct udevice *dev, u32 *val, u32 otp)
 {
+#ifdef CONFIG_STM32MP1_TRUSTED
+	return stm32_smc(STM32_SMC_BSEC,
+			 STM32_SMC_READ_OTP,
+			 otp, 0, val);
+#else
 	struct stm32mp_bsec_platdata *plat = dev_get_platdata(dev);
 	u32 tmp_data = 0;
 	int ret;
@@ -299,27 +308,46 @@ static int stm32mp_bsec_read_otp(struct udevice *dev, u32 *val, u32 otp)
 	/* restore shadow value */
 	ret = bsec_write_shadow(plat->base, tmp_data, otp);
 	return ret;
+#endif
 }
 
 static int stm32mp_bsec_read_shadow(struct udevice *dev, u32 *val, u32 otp)
 {
+#ifdef CONFIG_STM32MP1_TRUSTED
+	return stm32_smc(STM32_SMC_BSEC,
+			 STM32_SMC_READ_SHADOW,
+			 otp, 0, val);
+#else
 	struct stm32mp_bsec_platdata *plat = dev_get_platdata(dev);
 
 	return bsec_read_shadow(plat->base, val, otp);
+#endif
 }
 
 static int stm32mp_bsec_write_otp(struct udevice *dev, u32 val, u32 otp)
 {
+#ifdef CONFIG_STM32MP1_TRUSTED
+	return stm32_smc_exec(STM32_SMC_BSEC,
+			      STM32_SMC_PROG_OTP,
+			      otp, val);
+#else
 	struct stm32mp_bsec_platdata *plat = dev_get_platdata(dev);
 
 	return bsec_program_otp(plat->base, val, otp);
+#endif
 }
 
 static int stm32mp_bsec_write_shadow(struct udevice *dev, u32 val, u32 otp)
 {
+#ifdef CONFIG_STM32MP1_TRUSTED
+	return stm32_smc_exec(STM32_SMC_BSEC,
+			      STM32_SMC_WRITE_SHADOW,
+			      otp, val);
+#else
 	struct stm32mp_bsec_platdata *plat = dev_get_platdata(dev);
 
 	return bsec_write_shadow(plat->base, val, otp);
+#endif
 }
 
 static int stm32mp_bsec_read(struct udevice *dev, int offset,
arch/arm/mach-stm32mp/include/mach/stm32mp1_smc.h new file +64 -0

64 lines not on this page · raw message

Signature · 1 line
2.7.4
#4 lore raw

PATCH 3/3 stm32mp1: display board information

In reply to Patrick Delaunay

Implement checkboard() function to display
- the boot chain used: basic or trusted
- the board compatible in device tree
- the board identifier and revision, saved in OTP59 for ST boards

---

 arch/arm/mach-stm32mp/include/mach/stm32.h |  4 +++
 board/st/stm32mp1/stm32mp1.c               | 44 ++++++++++++++++++++++++++++--
 2 files changed, 46 insertions(+), 2 deletions(-)
arch/arm/mach-stm32mp/include/mach/stm32.h +4 -0
index 5d0bdca..85d783c 100644
@@ -98,7 +98,11 @@ enum boot_device {
 
 /* offset used for BSEC driver: misc_read and misc_write */
 #define STM32_BSEC_SHADOW_OFFSET	0x0
+#define STM32_BSEC_SHADOW(id)		(STM32_BSEC_SHADOW_OFFSET + (id) * 4)
 #define STM32_BSEC_OTP_OFFSET		0x80000000
+#define STM32_BSEC_OTP(id)		(STM32_BSEC_OTP_OFFSET + (id) * 4)
+
+#define BSEC_OTP_BOARD	59
 
 #endif /* __ASSEMBLY__*/
 #endif /* _MACH_STM32_H_ */
board/st/stm32mp1/stm32mp1.c +42 -2

59 lines not on this page · raw message

Signature · 1 line
2.7.4