CMake: link TF-M for both memory partition

This patch introduces the MCUBOOT_NO_SWAP compiler switch:
  - Default value is False to preserve swapping functionality to be
    default
  - When disabling it then TF-M is built in one instance:
    - tfm_sign.bin:   linked to run in XIP mode from slot 0 memory
      partition
  - When enabling it then TF-M is built in two instances:
    - tfm_sign_0.bin: linked to run in XIP mode from slot 0 memory
      partition
    - tfm_sign_1.bin: linked to run in XIP mode from slot 1 memory
      partition

Change-Id: I2757601295c80a42aba351a6d89c17f78dad3a0f
Signed-off-by: Tamas Ban <tamas.ban@arm.com>
Co-Authored-By: Mate Toth-Pal <mate.toth-pal@arm.com>
Co-Authored-By: Gyorgy Szing <Gyorgy.Szing@arm.com>
diff --git a/bl2/ext/mcuboot/MCUBoot.cmake b/bl2/ext/mcuboot/MCUBoot.cmake
new file mode 100644
index 0000000..cdcfcbd
--- /dev/null
+++ b/bl2/ext/mcuboot/MCUBoot.cmake
@@ -0,0 +1,62 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2018, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+cmake_minimum_required(VERSION 3.7)
+
+function(mcuboot_create_boot_payload)
+	set( _OPTIONS_ARGS)                                          #Option (on/off) arguments (e.g. IGNORE_CASE)
+	set( _ONE_VALUE_ARGS S_BIN NS_BIN FULL_BIN SIGN_BIN POSTFIX) #Single option arguments (e.g. PATH "./foo/bar")
+	set( _MULTI_VALUE_ARGS)                                      #List arguments (e.g. LANGUAGES C ASM CXX)
+	cmake_parse_arguments(_MY_PARAMS "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN})
+
+	if (NOT DEFINED _MY_PARAMS_S_BIN)
+		message(FATAL_ERROR "mcuboot_create_boot_payload(): mandatory parameter 'S_BIN' missing.")
+	endif()
+
+	if (NOT DEFINED _MY_PARAMS_NS_BIN)
+		message(FATAL_ERROR "mcuboot_create_boot_payload(): mandatory parameter 'NS_BIN' missing.")
+	endif()
+
+	if (NOT DEFINED _MY_PARAMS_FULL_BIN)
+		message(FATAL_ERROR "mcuboot_create_boot_payload(): mandatory parameter 'FULL_BIN' missing.")
+	endif()
+
+	if (NOT DEFINED _MY_PARAMS_SIGN_BIN)
+		message(FATAL_ERROR "mcuboot_create_boot_payload(): mandatory parameter 'SIGN_BIN' missing.")
+	endif()
+
+	#Find Python3.x interpreter
+	find_package(PythonInterp 3)
+	if (NOT PYTHONINTERP_FOUND)
+		message(FATAL_ERROR "Failed to find Python3.x interpreter. Pyhton3 must be installed and available on the PATH.")
+	endif()
+
+	if(NOT DEFINED FLASH_LAYOUT)
+		message(FATAL_ERROR "ERROR: Incomplete Configuration: FLASH_LAYOUT is not defined.")
+	endif()
+
+	add_custom_command(TARGET ${_MY_PARAMS_NS_BIN}
+						POST_BUILD
+
+						#Create concatenated binary image from the two binary file
+						COMMAND ${PYTHON_EXECUTABLE} ${MCUBOOT_DIR}/scripts/assemble.py
+						ARGS -l ${FLASH_LAYOUT}
+							 -s $<TARGET_FILE_DIR:${_MY_PARAMS_S_BIN}>/${_MY_PARAMS_S_BIN}.bin
+							 -n $<TARGET_FILE_DIR:${_MY_PARAMS_NS_BIN}>/${_MY_PARAMS_NS_BIN}.bin
+							 -o ${CMAKE_BINARY_DIR}/${_MY_PARAMS_FULL_BIN}.bin
+
+						#Sign concatenated binary image with default public key in mcuboot folder
+						COMMAND ${PYTHON_EXECUTABLE} ${MCUBOOT_DIR}/scripts/imgtool.py
+						ARGS sign
+							 -k ${MCUBOOT_DIR}/root-rsa-2048.pem
+							 --align 1
+							 -v 1.0
+							 -H 0x400
+							 --pad ${SIGN_BIN_SIZE}
+							 ${CMAKE_BINARY_DIR}/${_MY_PARAMS_FULL_BIN}.bin
+							 ${CMAKE_BINARY_DIR}/${_MY_PARAMS_SIGN_BIN}.bin)
+endfunction()
\ No newline at end of file