boards: mps2_an521: build non-secure Zephyr images together with TF-M

By default, if we build for a Non-Secure version of the board,
force building with TF-M as the Secure Execution Environment.
An exception is when we build openamp samples, where the non-
secure image is basically used for the remote core.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
diff --git a/boards/arm/mps2_an521/Kconfig.defconfig b/boards/arm/mps2_an521/Kconfig.defconfig
index 42536e0..38b7bb4 100644
--- a/boards/arm/mps2_an521/Kconfig.defconfig
+++ b/boards/arm/mps2_an521/Kconfig.defconfig
@@ -15,6 +15,14 @@
 	default "mps2_an521_nonsecure" if TRUSTED_EXECUTION_NONSECURE
 	default "mps2_an521"
 
+# By default, if we build for a Non-Secure version of the board,
+# force building with TF-M as the Secure Execution Environment.
+# Openamp samples assume the non-secure build is the remote
+# core image, so do not build with TF-M in this case.
+config BUILD_WITH_TFM
+	default y if TRUSTED_EXECUTION_NONSECURE && !OPENAMP
+
+
 if GPIO
 
 config GPIO_CMSDK_AHB
diff --git a/boards/arm/mps2_an521/board.cmake b/boards/arm/mps2_an521/board.cmake
index 7baa879..410abaf 100644
--- a/boards/arm/mps2_an521/board.cmake
+++ b/boards/arm/mps2_an521/board.cmake
@@ -11,3 +11,12 @@
   -vga none
   )
 board_set_debugger_ifnset(qemu)
+
+if (CONFIG_BUILD_WITH_TFM AND NOT CONFIG_OPENAMP)
+  # Override the binary used by qemu, to use the combined
+  # TF-M (Secure) & Zephyr (Non Secure) image (when running
+  # in-tree tests).
+  # Openamp samples assume the non-secure build is the remote
+  # core image, so do not use the merged .hex in this case.
+  set(QEMU_KERNEL_OPTION "-device;loader,file=${CMAKE_BINARY_DIR}/tfm_merged.hex")
+endif()