Build: Convert cypress targets to modern cmake

Add cmake files to cypress vendor directory. Alter scatter files to
remove preprocessor shebang. Alter header files where include paths have
changed.

WARNING: This change will not build in isolation, it requires _all_
other cmake changes to successfully build. It is split out only for ease
of understanding.

Change-Id: I5edfbe653927d897589ae20f320799368890e8d5
Signed-off-by: Raef Coles <raef.coles@arm.com>
diff --git a/platform/ext/psoc64.cmake b/platform/ext/psoc64.cmake
deleted file mode 100644
index c47dea3..0000000
--- a/platform/ext/psoc64.cmake
+++ /dev/null
@@ -1,260 +0,0 @@
-#-------------------------------------------------------------------------------
-# Copyright (c) 2018-2020, Arm Limited. All rights reserved.
-# Copyright (c) 2019-2020, Cypress Semiconductor Corporation. All rights reserved.
-#
-# SPDX-License-Identifier: BSD-3-Clause
-#
-#-------------------------------------------------------------------------------
-
-#This file gathers all Cypress PSoC 6 specific files in the application.
-
-include("Common/MultiCore")
-
-# Select configuration of multi-core topology
-enable_multi_core_topology_config()
-
-# Enable multiple outstanding NS PSA Client calls
-enable_multi_core_multi_client_call()
-
-set(TFM_NS_CLIENT_IDENTIFICATION OFF)
-
-add_definitions(-DCYB0644ABZI_S2D44=1)
-
-add_definitions(-DTFM_CORE_DEBUG)
-
-# psoc64 platform doesn't yet use TF-M BL2
-set(BL2 False)
-remove_definitions(-DBL2)
-
-# Skip peripheral access test
-set(TFM_ENABLE_PERIPH_ACCESS_TEST OFF)
-if (REGRESSION)
-    # Enable multi-core specific test cases
-    set(TFM_MULTI_CORE_TEST ON)
-endif()
-
-# Set Cortex-M0plus as secure core
-set_secure_cpu_type("CpuM0p")
-# Set Cortex-M4 as non-secure core
-set_ns_cpu_type("CpuM4")
-
-# Set PSoC62 specific secure definitions
-add_platform_secure_definitions(CY_PSOC6_CM0P=1)
-
-set(PLATFORM_DIR ${CMAKE_CURRENT_LIST_DIR})
-
-#Specify the location of platform specific build dependencies.
-if(COMPILER STREQUAL "ARMCLANG")
-    set (S_SCATTER_FILE_NAME   "${PLATFORM_DIR}/common/armclang/tfm_common_s.sct")
-    set (NS_SCATTER_FILE_NAME  "${PLATFORM_DIR}/target/cypress/psoc64/Device/Source/armclang/psoc6_ns.sct")
-    if (DEFINED CMSIS_DIR)
-      # not all project defines CMSIS_DIR, only the ones that use it.
-      set (RTX_LIB_PATH "${CMSIS_DIR}/RTOS2/RTX/Library/ARM/RTX_CM4F.lib")
-    endif()
-elseif(COMPILER STREQUAL "GNUARM")
-    set (S_SCATTER_FILE_NAME   "${PLATFORM_DIR}/common/gcc/tfm_common_s.ld")
-    set (NS_SCATTER_FILE_NAME  "${PLATFORM_DIR}/target/cypress/psoc64/Device/Source/gcc/psoc6_ns.ld")
-    if (DEFINED CMSIS_DIR)
-      # not all project defines CMSIS_DIR, only the ones that use it.
-      # [libRTX_CM3.a should be used for CM4 without FPU]
-      set (RTX_LIB_PATH "${CMSIS_DIR}/RTOS2/RTX/Library/GCC/libRTX_CM3.a")
-    endif()
-elseif(COMPILER STREQUAL "IARARM")
-    set (S_SCATTER_FILE_NAME   "${PLATFORM_DIR}/common/iar/tfm_common_s.icf")
-    set (NS_SCATTER_FILE_NAME  "${PLATFORM_DIR}/target/cypress/psoc64/Device/Source/iar/psoc6_ns.icf")
-    if (DEFINED CMSIS_DIR)
-      # not all project defines CMSIS_DIR, only the ones that use it.
-      # [RTX_CM3.a should be used for CM4 without FPU]
-      set (RTX_LIB_PATH "${CMSIS_DIR}/RTOS2/RTX/Library/IAR/RTX_CM3.a")
-    endif()
-else()
-    message(FATAL_ERROR "No startup file is available for compiler '${CMAKE_C_COMPILER_ID}'.")
-endif()
-set (FLASH_LAYOUT          "${PLATFORM_DIR}/target/cypress/psoc64/partition/flash_layout.h")
-set (PLATFORM_LINK_INCLUDES "${PLATFORM_DIR}/target/cypress/psoc64/partition")
-
-embedded_include_directories(PATH "${PLATFORM_DIR}/cmsis" ABSOLUTE)
-embedded_include_directories(PATH "${PLATFORM_DIR}/target/cypress/psoc64" ABSOLUTE)
-embedded_include_directories(PATH "${PLATFORM_DIR}/target/cypress/psoc64/CMSIS_Driver/Config" ABSOLUTE)
-embedded_include_directories(PATH "${PLATFORM_DIR}/target/cypress/psoc64/Device/Config" ABSOLUTE)
-embedded_include_directories(PATH "${PLATFORM_DIR}/target/cypress/psoc64/Device/Include" ABSOLUTE)
-embedded_include_directories(PATH "${PLATFORM_DIR}/target/cypress/psoc64/Native_Driver/include" ABSOLUTE)
-embedded_include_directories(PATH "${PLATFORM_DIR}/target/cypress/psoc64/Native_Driver/generated_source" ABSOLUTE)
-embedded_include_directories(PATH "${PLATFORM_DIR}/target/cypress/psoc64/mailbox" ABSOLUTE)
-embedded_include_directories(PATH "${PLATFORM_DIR}/target/cypress/psoc64/partition" ABSOLUTE)
-embedded_include_directories(PATH "${TFM_ROOT_DIR}/interface/include" ABSOLUTE)
-embedded_include_directories(PATH "${TFM_ROOT_DIR}/platform/include" ABSOLUTE)
-embedded_include_directories(PATH "${TFM_ROOT_DIR}/secure_fw/spm/arch" ABSOLUTE)
-embedded_include_directories(PATH "${TFM_ROOT_DIR}/secure_fw/spm/model_ipc/include" ABSOLUTE)
-
-#Gather all source files we need.
-list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/mailbox/platform_multicore.c")
-list(APPEND ALL_SRC_C_NS "${PLATFORM_DIR}/target/cypress/psoc64/mailbox/platform_ns_mailbox.c")
-list(APPEND ALL_SRC_C_S "${PLATFORM_DIR}/target/cypress/psoc64/mailbox/mailbox_ipc_intr.c")
-list(APPEND ALL_SRC_C_S "${PLATFORM_DIR}/target/cypress/psoc64/mailbox/platform_spe_mailbox.c")
-
-install(FILES ${PLATFORM_DIR}/target/cypress/psoc64/mailbox/ns_ipc_config.h
-        ${PLATFORM_DIR}/target/cypress/psoc64/mailbox/platform_multicore.h
-        DESTINATION export/tfm/include)
-
-install(FILES ${PLATFORM_DIR}/target/cypress/psoc64/mailbox/platform_multicore.c
-        ${PLATFORM_DIR}/target/cypress/psoc64/mailbox/platform_ns_mailbox.c
-        DESTINATION export/tfm/src)
-
-if (NOT DEFINED BUILD_CMSIS_CORE)
-  message(FATAL_ERROR "Configuration variable BUILD_CMSIS_CORE (true|false) is undefined!")
-elseif(BUILD_CMSIS_CORE)
-  list(APPEND ALL_SRC_C_S "${PLATFORM_DIR}/target/cypress/psoc64/Device/Source/system_psoc6_cm0plus.c")
-  list(APPEND ALL_SRC_C_NS "${PLATFORM_DIR}/target/cypress/psoc64/Device/Source/system_psoc6_cm4.c")
-endif()
-
-if (NOT DEFINED BUILD_RETARGET)
-  message(FATAL_ERROR "Configuration variable BUILD_RETARGET (true|false) is undefined!")
-elseif(BUILD_RETARGET)
-  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/Device/Source/device_definition.c")
-endif()
-
-if (NOT DEFINED BUILD_UART_STDOUT)
-  message(FATAL_ERROR "Configuration variable BUILD_UART_STDOUT (true|false) is undefined!")
-elseif(BUILD_UART_STDOUT)
-  if (NOT DEFINED SECURE_UART1)
-    message(FATAL_ERROR "Configuration variable SECURE_UART1 (true|false) is undefined!")
-  elseif(SECURE_UART1)
-    message(FATAL_ERROR "Configuration SECURE_UART1 TRUE is invalid for this target!")
-  endif()
-  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/common/uart_stdout.c")
-  embedded_include_directories(PATH "${PLATFORM_DIR}/common" ABSOLUTE)
-  set(BUILD_NATIVE_DRIVERS true)
-  set(BUILD_CMSIS_DRIVERS true)
-endif()
-
-if (NOT DEFINED BUILD_NATIVE_DRIVERS)
-  message(FATAL_ERROR "Configuration variable BUILD_NATIVE_DRIVERS (true|false) is undefined!")
-elseif(BUILD_NATIVE_DRIVERS)
-  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/Native_Driver/source/cy_device.c")
-  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/Native_Driver/source/cy_flash.c")
-  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/Native_Driver/source/cy_gpio.c")
-  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/Native_Driver/source/cy_prot.c")
-  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/Native_Driver/source/cy_ipc_drv.c")
-  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/Native_Driver/source/cy_ipc_pipe.c")
-  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/Native_Driver/source/cy_ipc_sema.c")
-  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/Native_Driver/source/cy_scb_common.c")
-  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/Native_Driver/source/cy_scb_uart.c")
-  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/Native_Driver/source/cy_sysclk.c")
-  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/Native_Driver/source/cy_sysint.c")
-  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/Native_Driver/source/cy_syslib.c")
-  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/Native_Driver/source/cy_syspm.c")
-  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/Native_Driver/source/cy_systick.c")
-  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/Native_Driver/source/cy_tcpwm_counter.c")
-  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/Native_Driver/source/cy_trigmux.c")
-  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/Native_Driver/source/cy_wdt.c")
-  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/Native_Driver/generated_source/cycfg.c")
-  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/Native_Driver/generated_source/cycfg_clocks.c")
-  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/Native_Driver/generated_source/cycfg_clocks.c")
-  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/Native_Driver/generated_source/cycfg_peripherals.c")
-  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/Native_Driver/generated_source/cycfg_pins.c")
-  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/Native_Driver/generated_source/cycfg_routing.c")
-  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/Native_Driver/generated_source/cycfg_system.c")
-  if(CMAKE_C_COMPILER_ID STREQUAL "ARMCLANG")
-	  list(APPEND ALL_SRC_ASM "${PLATFORM_DIR}/target/cypress/psoc64/Device/Source/armclang/cy_syslib_mdk.s")
-  elseif(CMAKE_C_COMPILER_ID STREQUAL "GNUARM")
-	  list(APPEND ALL_SRC_ASM "${PLATFORM_DIR}/target/cypress/psoc64/Device/Source/gcc/cy_syslib_gcc.S")
-  elseif(CMAKE_C_COMPILER_ID STREQUAL "IARARM")
-	  list(APPEND ALL_SRC_ASM "${PLATFORM_DIR}/target/cypress/psoc64/Device/Source/iar/cy_syslib_iar.c")
-  else()
-    message(FATAL_ERROR "No cy_syslib is available for compiler '${CMAKE_C_COMPILER_ID}'.")
-  endif()
-endif()
-
-if (NOT DEFINED BUILD_TIME)
-  message(FATAL_ERROR "Configuration variable BUILD_TIME (true|false) is undefined!")
-elseif(BUILD_TIME)
-endif()
-
-if (NOT DEFINED BUILD_STARTUP)
-  message(FATAL_ERROR "Configuration variable BUILD_STARTUP (true|false) is undefined!")
-elseif(BUILD_STARTUP)
-  if(CMAKE_C_COMPILER_ID STREQUAL "ARMCLANG")
-    list(APPEND ALL_SRC_ASM_S "${PLATFORM_DIR}/target/cypress/psoc64/Device/Source/armclang/startup_psoc64_s.s")
-    list(APPEND ALL_SRC_ASM_NS "${PLATFORM_DIR}/target/cypress/psoc64/Device/Source/armclang/startup_psoc64_ns.s")
-  elseif(CMAKE_C_COMPILER_ID STREQUAL "GNUARM")
-    list(APPEND ALL_SRC_ASM_S "${PLATFORM_DIR}/target/cypress/psoc64/Device/Source/gcc/startup_psoc64_s.S")
-    list(APPEND ALL_SRC_ASM_NS "${PLATFORM_DIR}/target/cypress/psoc64/Device/Source/gcc/startup_psoc64_ns.S")
-    set_property(SOURCE "${ALL_SRC_ASM_S}" "${ALL_SRC_ASM_NS}" APPEND
-      PROPERTY COMPILE_DEFINITIONS "__STARTUP_CLEAR_BSS_MULTIPLE" "__STARTUP_COPY_MULTIPLE")
-  elseif(CMAKE_C_COMPILER_ID STREQUAL "IARARM")
-    list(APPEND ALL_SRC_ASM_S "${PLATFORM_DIR}/target/cypress/psoc64/Device/Source/iar/startup_psoc64_s.s")
-    list(APPEND ALL_SRC_ASM_NS "${PLATFORM_DIR}/target/cypress/psoc64/Device/Source/iar/startup_psoc64_ns.s")
-  else()
-    message(FATAL_ERROR "No startup file is available for compiler '${CMAKE_C_COMPILER_ID}'.")
-  endif()
-endif()
-
-#Enable the checks of attestation claims against hard-coded values.
-set(ATTEST_CLAIM_VALUE_CHECK ON)
-
-if (NOT DEFINED BUILD_TARGET_CFG)
-  message(FATAL_ERROR "Configuration variable BUILD_TARGET_CFG (true|false) is undefined!")
-elseif(BUILD_TARGET_CFG)
-  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/target_cfg.c")
-  list(APPEND ALL_SRC_C_S "${PLATFORM_DIR}/target/cypress/psoc64/spm_hal.c")
-  list(APPEND ALL_SRC_C_S "${PLATFORM_DIR}/target/cypress/psoc64/attest_hal.c")
-  if (TFM_PARTITION_PLATFORM)
-    list(APPEND ALL_SRC_C_S "${PLATFORM_DIR}/target/cypress/psoc64/services/src/tfm_platform_system.c")
-  endif()
-  list(APPEND ALL_SRC_C_S "${PLATFORM_DIR}/common/tfm_hal_its.c")
-  list(APPEND ALL_SRC_C_S "${PLATFORM_DIR}/common/tfm_hal_ps.c")
-  list(APPEND ALL_SRC_C_S "${PLATFORM_DIR}/common/tfm_platform.c")
-  embedded_include_directories(PATH "${PLATFORM_DIR}/common" ABSOLUTE)
-endif()
-
-if (NOT DEFINED BUILD_PLAT_TEST)
-    message(FATAL_ERROR "Configuration variable BUILD_PLAT_TEST (true|false) is undefined!")
-elseif(BUILD_PLAT_TEST)
-    list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/plat_test.c")
-endif()
-
-if (NOT DEFINED BUILD_TARGET_HARDWARE_KEYS)
-  message(FATAL_ERROR "Configuration variable BUILD_TARGET_HARDWARE_KEYS (true|false) is undefined!")
-elseif(BUILD_TARGET_HARDWARE_KEYS)
-  list(APPEND ALL_SRC_C_S "${PLATFORM_DIR}/common/template/tfm_initial_attestation_key_material.c")
-  list(APPEND ALL_SRC_C_S "${PLATFORM_DIR}/common/template/tfm_rotpk.c")
-  list(APPEND ALL_SRC_C_S "${PLATFORM_DIR}/target/cypress/psoc64/dummy_crypto_keys.c")
-endif()
-
-if (NOT DEFINED BUILD_TARGET_NV_COUNTERS)
-  message(FATAL_ERROR "Configuration variable BUILD_TARGET_NV_COUNTERS (true|false) is undefined!")
-elseif(BUILD_TARGET_NV_COUNTERS)
-  list(APPEND ALL_SRC_C_S "${PLATFORM_DIR}/target/cypress/psoc64/nv_counters.c")
-  set(TARGET_NV_COUNTERS_ENABLE ON)
-  # Sets PS_ROLLBACK_PROTECTION flag to compile in the PS services
-  # rollback protection code as the target supports nv counters.
-  set (PS_ROLLBACK_PROTECTION ON)
-endif()
-
-if (NOT DEFINED BUILD_CMSIS_DRIVERS)
-  message(FATAL_ERROR "Configuration variable BUILD_CMSIS_DRIVERS (true|false) is undefined!")
-elseif(BUILD_CMSIS_DRIVERS)
-  list(APPEND ALL_SRC_C_S "${PLATFORM_DIR}/target/cypress/psoc64/driver_smpu.c")
-  list(APPEND ALL_SRC_C_S "${PLATFORM_DIR}/target/cypress/psoc64/driver_ppu.c")
-  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/driver_dap.c")
-  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/CMSIS_Driver/Driver_USART.c")
-  embedded_include_directories(PATH "${PLATFORM_DIR}/target/cypress/psoc64/CMSIS_Driver" ABSOLUTE)
-  embedded_include_directories(PATH "${PLATFORM_DIR}/driver" ABSOLUTE)
-endif()
-
-if (NOT DEFINED BUILD_FLASH)
-  message(FATAL_ERROR "Configuration variable BUILD_FLASH (true|false) is undefined!")
-elseif(BUILD_FLASH)
-  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/cypress/psoc64/CMSIS_Driver/Driver_Flash.c")
-  # As the PS area is going to be in RAM, it is required to set PS_CREATE_FLASH_LAYOUT
-  # to be sure the PS service knows that when it starts the PS area does not contain any
-  # valid PS flash layout and it needs to create one.
-  set(PS_CREATE_FLASH_LAYOUT ON)
-  set(ITS_CREATE_FLASH_LAYOUT ON)
-  embedded_include_directories(PATH "${PLATFORM_DIR}/target/cypress/psoc64/CMSIS_Driver" ABSOLUTE)
-  embedded_include_directories(PATH "${PLATFORM_DIR}/driver" ABSOLUTE)
-endif()
-
-list(APPEND ALL_SRC_C_S "${PLATFORM_DIR}/target/cypress/psoc64/dummy_boot_seed.c")
-list(APPEND ALL_SRC_C_S "${PLATFORM_DIR}/target/cypress/psoc64/dummy_device_id.c")
diff --git a/platform/ext/target/cypress/psoc64/CMakeLists.txt b/platform/ext/target/cypress/psoc64/CMakeLists.txt
new file mode 100644
index 0000000..21975f9
--- /dev/null
+++ b/platform/ext/target/cypress/psoc64/CMakeLists.txt
@@ -0,0 +1,183 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2020, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+cmake_policy(SET CMP0076 NEW)
+cmake_policy(SET CMP0079 NEW)
+set(CMAKE_CURRENT_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR})
+
+#========================= Platform region defs ===============================#
+
+target_include_directories(platform_region_defs
+    INTERFACE
+        partition
+)
+
+#========================= Platform common defs ===============================#
+
+target_sources(tfm_s
+    PRIVATE
+        $<$<C_COMPILER_ID:ARMClang>:${CMAKE_CURRENT_SOURCE_DIR}/Device/Source/armclang/startup_psoc64_s.s>
+        $<$<C_COMPILER_ID:ARMClang>:${CMAKE_CURRENT_SOURCE_DIR}/Device/Source/armclang/cy_syslib_mdk.s>
+        $<$<C_COMPILER_ID:GNU>:${CMAKE_CURRENT_SOURCE_DIR}/Device/Source/gcc/startup_psoc64_s.S>
+        $<$<C_COMPILER_ID:GNU>:${CMAKE_CURRENT_SOURCE_DIR}/Device/Source/gcc/cy_syslib_gcc.S>
+)
+target_add_scatter_file(tfm_s
+    $<$<C_COMPILER_ID:ARMClang>:${CMAKE_BINARY_DIR}/generated/platform/ext/common/armclang/tfm_common_s.sct>
+    $<$<C_COMPILER_ID:GNU>:${CMAKE_BINARY_DIR}/generated/platform/ext/common/gcc/tfm_common_s.ld>
+    $<$<C_COMPILER_ID:IAR>:${CMAKE_BINARY_DIR}/generated/platform/ext/common/iar/tfm_common_s.icf>
+)
+
+if(NS)
+    target_sources(tfm_ns
+        PRIVATE
+            $<$<C_COMPILER_ID:ARMClang>:${CMAKE_CURRENT_SOURCE_DIR}/Device/Source/armclang/startup_psoc64_ns.s>
+            $<$<C_COMPILER_ID:ARMClang>:${CMAKE_CURRENT_SOURCE_DIR}/Device/Source/armclang/cy_syslib_mdk.s>
+            $<$<C_COMPILER_ID:GNU>:${CMAKE_CURRENT_SOURCE_DIR}/Device/Source/gcc/startup_psoc64_ns.S>
+            $<$<C_COMPILER_ID:GNU>:${CMAKE_CURRENT_SOURCE_DIR}/Device/Source/gcc/cy_syslib_gcc.S>
+    )
+    target_add_scatter_file(tfm_ns
+            $<$<C_COMPILER_ID:ARMClang>:${CMAKE_CURRENT_SOURCE_DIR}/Device/Source/armclang/psoc6_ns.sct>
+            $<$<C_COMPILER_ID:GNU>:${CMAKE_CURRENT_SOURCE_DIR}/Device/Source/gcc/psoc6_ns.ld>
+    )
+    target_link_libraries(tfm_ns
+        PRIVATE
+            $<$<C_COMPILER_ID:ARMClang>:${CMSIS_5_PATH}/RTOS2/RTX/Library/ARM/RTX_CM3.lib>
+            $<$<C_COMPILER_ID:GNU>:${CMSIS_5_PATH}/RTOS2/RTX/Library/GCC/libRTX_CM3.a>
+    )
+endif()
+
+#========================= Platform Secure ====================================#
+
+target_include_directories(platform_s
+    PUBLIC
+        .
+        Device/Config
+        Device/Include
+        Native_Driver/include
+        Native_Driver/generated_source
+        ./CMSIS_Driver/Config
+        mailbox
+)
+
+target_sources(platform_s
+    PRIVATE
+        ./mailbox/platform_multicore.c
+        ./mailbox/platform_spe_mailbox.c
+        ./Device/Source/system_psoc6_cm0plus.c
+        ./Native_Driver/source/cy_device.c
+        ./Native_Driver/source/cy_flash.c
+        ./Native_Driver/source/cy_gpio.c
+        ./Native_Driver/source/cy_prot.c
+        ./Native_Driver/source/cy_ipc_drv.c
+        ./Native_Driver/source/cy_ipc_pipe.c
+        ./Native_Driver/source/cy_ipc_sema.c
+        ./Native_Driver/source/cy_scb_common.c
+        ./Native_Driver/source/cy_scb_uart.c
+        ./Native_Driver/source/cy_sysclk.c
+        ./Native_Driver/source/cy_sysint.c
+        ./Native_Driver/source/cy_syslib.c
+        ./Native_Driver/source/cy_syspm.c
+        ./Native_Driver/source/cy_systick.c
+        ./Native_Driver/source/cy_tcpwm_counter.c
+        ./Native_Driver/source/cy_trigmux.c
+        ./Native_Driver/source/cy_wdt.c
+        ./Native_Driver/generated_source/cycfg.c
+        ./Native_Driver/generated_source/cycfg_clocks.c
+        ./Native_Driver/generated_source/cycfg_clocks.c
+        ./Native_Driver/generated_source/cycfg_peripherals.c
+        ./Native_Driver/generated_source/cycfg_pins.c
+        ./Native_Driver/generated_source/cycfg_routing.c
+        ./Native_Driver/generated_source/cycfg_system.c
+        ./spm_hal.c
+        ./CMSIS_Driver/Driver_Flash.c
+        ./CMSIS_Driver/Driver_USART.c
+        ./target_cfg.c
+        ./driver_smpu.c
+        ./driver_ppu.c
+        ./driver_dap.c
+        ./nv_counters.c
+        ./services/src/tfm_platform_system.c
+        ./dummy_crypto_keys.c
+)
+
+target_compile_definitions(platform_s
+    PUBLIC
+        $<$<C_COMPILER_ID:GNU>:__STARTUP_CLEAR_BSS_MULTIPLE>
+        $<$<C_COMPILER_ID:GNU>:__STARTUP_COPY_MULTIPLE>
+    PRIVATE
+        RTE_USART5
+)
+
+target_link_libraries(platform_s
+    PRIVATE
+        tfm_spm
+)
+
+# GNU ld has some strange behaviour to do with weak functions, and does not deal
+# well with strong functions in static libraries overriding weak functions in
+# object files. For this reason, the file mailbox_ipc_intr is linked directly to
+# the s binary as an object file. This issue does not affect armclang, but the
+# fix is compatible.
+target_sources(tfm_s
+    PRIVATE
+        ./mailbox/mailbox_ipc_intr.c
+)
+
+#========================= Platform Non-Secure ================================#
+
+target_sources(platform_ns
+    PRIVATE
+        ./mailbox/platform_ns_mailbox.c
+        ./Device/Source/system_psoc6_cm4.c
+        ./Native_Driver/source/cy_device.c
+        ./Native_Driver/source/cy_flash.c
+        ./Native_Driver/source/cy_gpio.c
+        ./Native_Driver/source/cy_prot.c
+        ./Native_Driver/source/cy_ipc_drv.c
+        ./Native_Driver/source/cy_ipc_pipe.c
+        ./Native_Driver/source/cy_ipc_sema.c
+        ./Native_Driver/source/cy_scb_common.c
+        ./Native_Driver/source/cy_scb_uart.c
+        ./Native_Driver/source/cy_sysclk.c
+        ./Native_Driver/source/cy_sysint.c
+        ./Native_Driver/source/cy_syslib.c
+        ./Native_Driver/source/cy_syspm.c
+        ./Native_Driver/source/cy_systick.c
+        ./Native_Driver/source/cy_tcpwm_counter.c
+        ./Native_Driver/source/cy_trigmux.c
+        ./Native_Driver/source/cy_wdt.c
+        ./Native_Driver/generated_source/cycfg.c
+        ./Native_Driver/generated_source/cycfg_clocks.c
+        ./Native_Driver/generated_source/cycfg_clocks.c
+        ./Native_Driver/generated_source/cycfg_peripherals.c
+        ./Native_Driver/generated_source/cycfg_pins.c
+        ./Native_Driver/generated_source/cycfg_routing.c
+        ./Native_Driver/generated_source/cycfg_system.c
+        ./mailbox/platform_multicore.c
+        ./CMSIS_Driver/Driver_USART.c
+)
+
+target_include_directories(platform_ns
+    PUBLIC
+        .
+        Device/Config
+        Device/Include
+        Native_Driver/include
+        Native_Driver/generated_source
+        ./CMSIS_Driver/Config
+)
+
+target_compile_definitions(platform_ns
+    PUBLIC
+        TFM_MULTI_CORE_MULTI_CLIENT_CALL
+        RTE_USART5
+)
+
+target_link_libraries(platform_ns
+    PRIVATE
+        psa_interface
+)
diff --git a/platform/ext/target/cypress/psoc64/Device/Source/armclang/psoc6_ns.sct b/platform/ext/target/cypress/psoc64/Device/Source/armclang/psoc6_ns.sct
index 5abc37f..8191f68 100644
--- a/platform/ext/target/cypress/psoc64/Device/Source/armclang/psoc6_ns.sct
+++ b/platform/ext/target/cypress/psoc64/Device/Source/armclang/psoc6_ns.sct
@@ -1,5 +1,3 @@
-#! armclang --target=arm-arm-none-eabi -march=armv8-m.main -E -xc
-
 /*
  * Copyright (c) 2018-2020 ARM Limited
  *
diff --git a/platform/ext/target/cypress/psoc64/config.cmake b/platform/ext/target/cypress/psoc64/config.cmake
new file mode 100644
index 0000000..88e9371
--- /dev/null
+++ b/platform/ext/target/cypress/psoc64/config.cmake
@@ -0,0 +1,20 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2020, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+set(BL2                                 OFF         CACHE BOOL      "Whether to build BL2" FORCE)
+
+set(TFM_PSA_API                         ON          CACHE BOOL      "Use PSA api (IPC mode) instead of secure library mode" FORCE)
+
+set(TFM_NS_CLIENT_IDENTIFICATION        OFF         CACHE BOOL      "Enable NS client identification" FORCE)
+
+############################ Platform ##########################################
+
+set(TFM_MULTI_CORE_TOPOLOGY             ON          CACHE BOOL      "Whether to build for a dual-cpu architecture" FORCE)
+
+set(PLATFORM_DUMMY_ATTEST_HAL           FALSE       CACHE BOOL      "Use dummy attest hal implementation. Should not be used in production." FORCE)
+set(PLATFORM_DUMMY_NV_COUNTERS          FALSE       CACHE BOOL      "Use dummy nv counter implementation. Should not be used in production." FORCE)
+set(PLATFORM_DUMMY_CRYPTO_KEYS          FALSE       CACHE BOOL      "Use dummy crypto keys. Should not be used in production." FORCE)
diff --git a/platform/ext/target/cypress/psoc64/preload.cmake b/platform/ext/target/cypress/psoc64/preload.cmake
new file mode 100644
index 0000000..2661a22
--- /dev/null
+++ b/platform/ext/target/cypress/psoc64/preload.cmake
@@ -0,0 +1,20 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2020, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+# preload.cmake is used to set things that related to the platform that are both
+# immutable and global, which is to say they should apply to any kind of project
+# that uses this platform. In practise this is normally compiler definitions and
+# variables related to hardware.
+
+# Set architecture and CPU. Cypress PSoC64 runs the S code on its Cortex-m0+
+set(TFM_SYSTEM_PROCESSOR cortex-m0plus)
+set(TFM_SYSTEM_ARCHITECTURE armv6-m)
+
+add_definitions(-DCYB0644ABZI_S2D44)
+
+# Reload compiler to generate options from the CPU and architecture
+_compiler_reload()
diff --git a/platform/ext/target/cypress/psoc64/preload_ns.cmake b/platform/ext/target/cypress/psoc64/preload_ns.cmake
new file mode 100644
index 0000000..4e8f2b6
--- /dev/null
+++ b/platform/ext/target/cypress/psoc64/preload_ns.cmake
@@ -0,0 +1,20 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2020, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+# preload.cmake is used to set things that related to the platform that are both
+# immutable and global, which is to say they should apply to any kind of project
+# that uses this plaform. In practise this is normally compiler definitions and
+# variables related to hardware.
+
+# Set architecture and CPU. Cypress PSoC64 runs the NS code on its Cortex-M4
+set(TFM_SYSTEM_PROCESSOR cortex-m4)
+set(TFM_SYSTEM_ARCHITECTURE armv7-m)
+
+add_definitions(-DCYB0644ABZI_S2D44)
+
+# Reload compiler to generate options from the CPU and architecture
+_compiler_reload()