SPM: Enhance build control for IPC and SFN models

Currently, different models configuration such as
CONFIG_TFM_PSA_API_xxx_CALL are configured in generated header
file config_impl.h. CMake build system has no information on
which model should be built. As a result, files for different
models are always build in IPC model, such as psa_interface_cross.c,
psa_interface_sfn.c and psa_interface_svc.c.
This patch:
- Generate CMake variables for each model.
- Configure the build system based on generated CMake variables.

Signed-off-by: Sherry Zhang <sherry.zhang2@arm.com>
Change-Id: If3f92b07b618b13ca596306ffd19867010de83b7
diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt
index ec7f2d1..14594ce 100644
--- a/interface/CMakeLists.txt
+++ b/interface/CMakeLists.txt
@@ -1,5 +1,5 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2020-2021, Arm Limited. All rights reserved.
+# Copyright (c) 2020-2022, Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -52,6 +52,9 @@
         $<$<BOOL:${TFM_MULTI_CORE_TOPOLOGY}>:TFM_MULTI_CORE_TOPOLOGY>
         $<$<BOOL:${FORWARD_PROT_MSG}>:FORWARD_PROT_MSG=${FORWARD_PROT_MSG}>
         $<$<BOOL:${TFM_SP_META_PTR_ENABLE}>:TFM_SP_META_PTR_ENABLE>
+        $<$<BOOL:${CONFIG_TFM_PSA_API_SUPERVISOR_CALL}>:CONFIG_TFM_PSA_API_SUPERVISOR_CALL>
+        $<$<BOOL:${CONFIG_TFM_PSA_API_CROSS_CALL}>:CONFIG_TFM_PSA_API_CROSS_CALL>
+        $<$<BOOL:${CONFIG_TFM_PSA_API_SFN_CALL}>:CONFIG_TFM_PSA_API_SFN_CALL>
 )
 
 ###################### PSA api (S lib) #########################################
diff --git a/interface/include/config_impl.h.template b/interface/include/config_impl.h.template
index 8c79f04..bc29ac0 100644
--- a/interface/include/config_impl.h.template
+++ b/interface/include/config_impl.h.template
@@ -4,8 +4,7 @@
  * SPDX-License-Identifier: BSD-3-Clause
  *
  */
-
-{{utilities.donotedit_warning}}
+/***********{{utilities.donotedit_warning}}***********/
 
 #ifndef __CONFIG_IMPL_H__
 #define __CONFIG_IMPL_H__
@@ -13,30 +12,16 @@
 {% if partition_statistics['ipc_partition_num'] > 0
     and partition_statistics['sfn_partition_num'] == 0 %}
 /* IPC model */
-#define {{"%-56s"|format("CONFIG_TFM_SPM_BACKEND_IPC")}} 1
-
 /* Trustzone NS agent working stack size. */
 #define {{"%-56s"|format("CONFIG_TFM_NS_AGENT_TZ_STACK_SIZE")}} 1024
 
-#if TFM_LVL > 1
-#define {{"%-56s"|format("CONFIG_TFM_PSA_API_SUPERVISOR_CALL")}} 1
-#else /* TFM_LVL > 1 */
-#define {{"%-56s"|format("CONFIG_TFM_PSA_API_CROSS_CALL")}} 1
-
 /* SPM re-uses Trustzone NS agent stack. */
 #define {{"%-56s"|format("CONFIG_TFM_SPM_THREAD_STACK_SIZE")}}     \
             {{"%-56s"|format("CONFIG_TFM_NS_AGENT_TZ_STACK_SIZE")}}
-#endif /* TFM_LVL > 1 */
 
 {% elif partition_statistics['sfn_partition_num'] > 0
     and partition_statistics['ipc_partition_num'] == 0 %}
 /* SFN model */
-#define {{"%-56s"|format("CONFIG_TFM_SPM_BACKEND_SFN")}} 1
-#define {{"%-56s"|format("CONFIG_TFM_PSA_API_SFN_CALL")}} 1
-
-#if TFM_LVL > 1
-#error "High isolation level SFN model is not supported."
-#endif
 
     {% set total_stk = namespace(size=0) %}
     {% for partition in partitions %}
@@ -70,8 +55,4 @@
 #error "Invalid partition number input, check configurations."
 {% endif %}
 
-#if (CONFIG_TFM_SPE_FP > 0) && (CONFIG_TFM_SPM_BACKEND_SFN == 1)
-#error "FP is not supported for SFN model."
-#endif
-
 #endif /* __CONFIG_IMPL_H__ */
diff --git a/interface/include/psa_interface_redirect.h b/interface/include/psa_interface_redirect.h
index 60915ef..1514f93 100644
--- a/interface/include/psa_interface_redirect.h
+++ b/interface/include/psa_interface_redirect.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021, Arm Limited. All rights reserved.
+ * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -82,10 +82,6 @@
 #define psa_unmap_outvec         psa_unmap_outvec_sfn
 #endif /* PSA_FRAMEWORK_HAS_MM_IOVEC */
 
-#else
-
-#error "NO ABI is chosen, check configurations."
-
 #endif
 
 #endif /* __PSA_INTERFACE_REDIRECT_H__ */
diff --git a/interface/include/psa_manifest/pid.h.template b/interface/include/psa_manifest/pid.h.template
index 4fba682..faf52d6 100644
--- a/interface/include/psa_manifest/pid.h.template
+++ b/interface/include/psa_manifest/pid.h.template
@@ -1,12 +1,12 @@
 /*
- * Copyright (c) 2019-2021, Arm Limited. All rights reserved.
+ * Copyright (c) 2019-2022, Arm Limited. All rights reserved.
  * Copyright (c) 2021, Cypress Semiconductor Corporation. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
  */
 
-{{utilities.donotedit_warning}}
+/***********{{utilities.donotedit_warning}}***********/
 
 #ifndef __PSA_MANIFEST_PID_H__
 #define __PSA_MANIFEST_PID_H__
diff --git a/interface/include/psa_manifest/sid.h.template b/interface/include/psa_manifest/sid.h.template
index 8a53a71..e754bd7 100644
--- a/interface/include/psa_manifest/sid.h.template
+++ b/interface/include/psa_manifest/sid.h.template
@@ -1,11 +1,11 @@
 /*
- * Copyright (c) 2019-2021, Arm Limited. All rights reserved.
+ * Copyright (c) 2019-2022, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
  */
 
-{{utilities.donotedit_warning}}
+/***********{{utilities.donotedit_warning}}***********/
 
 #ifndef __PSA_MANIFEST_SID_H__
 #define __PSA_MANIFEST_SID_H__
diff --git a/interface/include/tfm_veneers.h.template b/interface/include/tfm_veneers.h.template
index 0e9e993..68c23e8 100644
--- a/interface/include/tfm_veneers.h.template
+++ b/interface/include/tfm_veneers.h.template
@@ -1,11 +1,11 @@
 /*
- * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2022, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
  */
 
-{{utilities.donotedit_warning}}
+/***********{{utilities.donotedit_warning}}***********/
 
 #ifndef __TFM_VENEERS_H__
 #define __TFM_VENEERS_H__
diff --git a/platform/ext/common/armclang/tfm_isolation_l3.sct.template b/platform/ext/common/armclang/tfm_isolation_l3.sct.template
index a03a49f..726185d 100644
--- a/platform/ext/common/armclang/tfm_isolation_l3.sct.template
+++ b/platform/ext/common/armclang/tfm_isolation_l3.sct.template
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017-2021 Arm Limited. All rights reserved.
+ * Copyright (c) 2017-2022 Arm Limited. All rights reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-{{utilities.donotedit_warning}}
+/***********{{utilities.donotedit_warning}}***********/
 
 /*
  * Customized region name prefix abbreviation:
diff --git a/platform/ext/common/gcc/tfm_isolation_l3.ld.template b/platform/ext/common/gcc/tfm_isolation_l3.ld.template
index 2efd405..60f6f43 100644
--- a/platform/ext/common/gcc/tfm_isolation_l3.ld.template
+++ b/platform/ext/common/gcc/tfm_isolation_l3.ld.template
@@ -1,5 +1,5 @@
 ;/*
-; * Copyright (c) 2009-2021 Arm Limited
+; * Copyright (c) 2009-2022 Arm Limited
 ; *
 ; * Licensed under the Apache License, Version 2.0 (the "License");
 ; * you may not use this file except in compliance with the License.
@@ -17,7 +17,7 @@
 ; * This file is derivative of CMSIS V5.00 gcc_arm.ld
 ; */
 
-{{utilities.donotedit_warning}}
+/***********{{utilities.donotedit_warning}}***********/
 
 /* Linker script to configure memory regions. */
 /* This file will be run trough the pre-processor. */
diff --git a/platform/ext/common/iar/tfm_isolation_l3.icf.template b/platform/ext/common/iar/tfm_isolation_l3.icf.template
index 84b7ef4..393848d 100644
--- a/platform/ext/common/iar/tfm_isolation_l3.icf.template
+++ b/platform/ext/common/iar/tfm_isolation_l3.icf.template
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017-2021 Arm Limited. All rights reserved.
+ * Copyright (c) 2017-2022 Arm Limited. All rights reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-{{utilities.donotedit_warning}}
+/***********{{utilities.donotedit_warning}}***********/
 
 /*
  * Customized region name prefix abbreviation:
diff --git a/secure_fw/CMakeLists.txt b/secure_fw/CMakeLists.txt
index 51e3a00..9919329 100644
--- a/secure_fw/CMakeLists.txt
+++ b/secure_fw/CMakeLists.txt
@@ -1,5 +1,5 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2020-2021, Arm Limited. All rights reserved.
+# Copyright (c) 2020-2022, Arm Limited. All rights reserved.
 # Copyright (c) 2021, Cypress Semiconductor Corporation. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
@@ -113,9 +113,9 @@
 # into this target, also the SPE build indicator.
 target_sources(tfm_secure_api
     INTERFACE
-        $<$<BOOL:${TFM_PSA_API}>:${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_svc.c>
-        $<$<BOOL:${TFM_PSA_API}>:${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_cross.c>
-        $<$<BOOL:${TFM_PSA_API}>:${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_sfn.c>
+        $<$<BOOL:${CONFIG_TFM_PSA_API_SUPERVISOR_CALL}>:${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_svc.c>
+        $<$<BOOL:${CONFIG_TFM_PSA_API_CROSS_CALL}>:${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_cross.c>
+        $<$<BOOL:${CONFIG_TFM_PSA_API_SFN_CALL}>:${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_sfn.c>
 )
 
 target_compile_definitions(tfm_secure_api
diff --git a/secure_fw/spm/CMakeLists.txt b/secure_fw/spm/CMakeLists.txt
index 3892959..213f795 100755
--- a/secure_fw/spm/CMakeLists.txt
+++ b/secure_fw/spm/CMakeLists.txt
@@ -1,5 +1,5 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2020-2021, Arm Limited. All rights reserved.
+# Copyright (c) 2020-2022, Arm Limited. All rights reserved.
 # Copyright (c) 2021, Cypress Semiconductor Corporation. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
@@ -48,7 +48,7 @@
         $<$<BOOL:${TFM_PSA_API}>:cmsis_psa/arch/tfm_arch.c>
         $<$<BOOL:${TFM_PSA_API}>:cmsis_psa/main.c>
         $<$<BOOL:${TFM_PSA_API}>:cmsis_psa/spm_ipc.c>
-        $<$<BOOL:${TFM_PSA_API}>:cmsis_psa/spm_cross_call.c>
+        $<$<BOOL:${CONFIG_TFM_PSA_API_CROSS_CALL}>:cmsis_psa/spm_cross_call.c>
         $<$<BOOL:${TFM_PSA_API}>:cmsis_psa/static_load.c>
         $<$<BOOL:${TFM_PSA_API}>:ffm/psa_api.c>
         $<$<BOOL:${TFM_PSA_API}>:ffm/backend.c>
@@ -117,6 +117,8 @@
         $<$<BOOL:${TFM_EXCEPTION_INFO_DUMP}>:TFM_EXCEPTION_INFO_DUMP>
         $<$<BOOL:${TFM_NS_MANAGE_NSID}>:TFM_NS_MANAGE_NSID>
         CONFIG_TFM_SPE_FP=${CONFIG_TFM_SPE_FP}
+        $<$<BOOL:${CONFIG_TFM_SPM_BACKEND_IPC}>:CONFIG_TFM_SPM_BACKEND_IPC>
+        $<$<BOOL:${CONFIG_TFM_SPM_BACKEND_SFN}>:CONFIG_TFM_SPM_BACKEND_SFN>
 )
 
 target_compile_options(tfm_spm
diff --git a/secure_fw/spm/cmsis_func/tfm_secure_irq_handlers.inc.template b/secure_fw/spm/cmsis_func/tfm_secure_irq_handlers.inc.template
index 6bcea96..23f2434 100644
--- a/secure_fw/spm/cmsis_func/tfm_secure_irq_handlers.inc.template
+++ b/secure_fw/spm/cmsis_func/tfm_secure_irq_handlers.inc.template
@@ -1,11 +1,11 @@
 /*
- * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2022, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
  */
 
-{{utilities.donotedit_warning}}
+/***********{{utilities.donotedit_warning}}***********/
 
 #include "psa_manifest/pid.h"
 
diff --git a/secure_fw/spm/cmsis_func/tfm_spm_db_func.inc.template b/secure_fw/spm/cmsis_func/tfm_spm_db_func.inc.template
index c4598b6..ca19977 100644
--- a/secure_fw/spm/cmsis_func/tfm_spm_db_func.inc.template
+++ b/secure_fw/spm/cmsis_func/tfm_spm_db_func.inc.template
@@ -1,11 +1,11 @@
 /*
- * Copyright (c) 2019-2021, Arm Limited. All rights reserved.
+ * Copyright (c) 2019-2022, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
  */
 
-{{utilities.donotedit_warning}}
+/***********{{utilities.donotedit_warning}}***********/
 
 #ifndef __TFM_SPM_DB_FUNC_INC__
 #define __TFM_SPM_DB_FUNC_INC__
diff --git a/secure_fw/spm/cmsis_func/tfm_veneers.c.template b/secure_fw/spm/cmsis_func/tfm_veneers.c.template
index 3db710f..8edac73 100644
--- a/secure_fw/spm/cmsis_func/tfm_veneers.c.template
+++ b/secure_fw/spm/cmsis_func/tfm_veneers.c.template
@@ -1,11 +1,11 @@
 /*
- * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2022, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
  */
 
-{{utilities.donotedit_warning}}
+/***********{{utilities.donotedit_warning}}***********/
 
 #include "tfm_secure_api.h"
 #include "spm_partition_defs.h"
diff --git a/secure_fw/spm/cmsis_psa/psa_interface_cross.c b/secure_fw/spm/cmsis_psa/psa_interface_cross.c
index 4290d88..1d3a7c2 100644
--- a/secure_fw/spm/cmsis_psa/psa_interface_cross.c
+++ b/secure_fw/spm/cmsis_psa/psa_interface_cross.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021, Arm Limited. All rights reserved.
+ * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -15,8 +15,6 @@
 #include "psa/lifecycle.h"
 #include "psa/service.h"
 
-#ifdef CONFIG_TFM_PSA_API_CROSS_CALL
-
 #if defined(__ICCARM__)
 
 #pragma required = spm_interface_cross_dispatcher
@@ -409,5 +407,3 @@
 }
 
 #endif /* PSA_FRAMEWORK_HAS_MM_IOVEC */
-
-#endif /* CONFIG_TFM_PSA_API_CROSS_CALL */
diff --git a/secure_fw/spm/cmsis_psa/psa_interface_sfn.c b/secure_fw/spm/cmsis_psa/psa_interface_sfn.c
index 9774e32..e4eb05a 100644
--- a/secure_fw/spm/cmsis_psa/psa_interface_sfn.c
+++ b/secure_fw/spm/cmsis_psa/psa_interface_sfn.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021, Arm Limited. All rights reserved.
+ * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -12,8 +12,6 @@
 #include "ffm/psa_api.h"
 #include "psa/client.h"
 
-#ifdef CONFIG_TFM_PSA_API_SFN_CALL
-
 uint32_t psa_framework_version_sfn(void)
 {
     return tfm_spm_client_psa_framework_version();
@@ -137,5 +135,3 @@
 {
     tfm_spm_partition_psa_panic();
 }
-
-#endif /* CONFIG_TFM_PSA_API_SFN_CALL */
diff --git a/secure_fw/spm/cmsis_psa/psa_interface_svc.c b/secure_fw/spm/cmsis_psa/psa_interface_svc.c
index 3781332..129db54 100644
--- a/secure_fw/spm/cmsis_psa/psa_interface_svc.c
+++ b/secure_fw/spm/cmsis_psa/psa_interface_svc.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2022, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -14,8 +14,6 @@
 #include "psa/lifecycle.h"
 #include "psa/service.h"
 
-#if defined(CONFIG_TFM_PSA_API_SUPERVISOR_CALL)
-
 __naked uint32_t psa_framework_version_svc(void)
 {
     __asm volatile("svc     "M2S(TFM_SVC_PSA_FRAMEWORK_VERSION)"\n"
@@ -141,5 +139,3 @@
     __asm volatile("svc     "M2S(TFM_SVC_PSA_LIFECYCLE)"       \n"
                    "bx      lr                                 \n");
 }
-
-#endif /* CONFIG_TFM_PSA_API_SUPERVISOR_CALL */
diff --git a/secure_fw/spm/cmsis_psa/spm_cross_call.c b/secure_fw/spm/cmsis_psa/spm_cross_call.c
index b8d63db..cddea8e 100644
--- a/secure_fw/spm/cmsis_psa/spm_cross_call.c
+++ b/secure_fw/spm/cmsis_psa/spm_cross_call.c
@@ -13,8 +13,6 @@
 #include "ffm/backend.h"
 #include "ffm/psa_api.h"
 
-#ifdef CONFIG_TFM_PSA_API_CROSS_CALL
-
 /* Customized ABI format */
 struct cross_call_abi_frame_t {
     uint32_t      a0;
@@ -55,5 +53,3 @@
     spm_handle_programmer_errors(
                             ((struct cross_call_abi_frame_t *)frame_addr)->a0);
 }
-
-#endif /* CONFIG_TFM_PSA_API_CROSS_CALL */
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
index c55cd90..7e95643 100644
--- a/tools/CMakeLists.txt
+++ b/tools/CMakeLists.txt
@@ -143,6 +143,8 @@
     RESULT_VARIABLE RET
 )
 
-if(NOT RET EQUAL 0)
+if(RET EQUAL 0)
+    include(${CMAKE_BINARY_DIR}/generated/tools/config_impl.cmake)
+else()
     message(FATAL_ERROR "File generation failed")
 endif()
diff --git a/tools/config_impl.cmake.template b/tools/config_impl.cmake.template
new file mode 100644
index 0000000..59a327c
--- /dev/null
+++ b/tools/config_impl.cmake.template
@@ -0,0 +1,39 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2022, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+
+########{{utilities.donotedit_warning}}########
+
+if(TFM_PSA_API)
+{% if partition_statistics['ipc_partition_num'] > 0
+    and partition_statistics['sfn_partition_num'] == 0 %}
+    set(CONFIG_TFM_SPM_BACKEND_IPC ON PARENT_SCOPE)
+
+    if(TFM_ISOLATION_LEVEL GREATER 1)
+        set(CONFIG_TFM_PSA_API_SUPERVISOR_CALL ON PARENT_SCOPE)
+    else()
+        set(CONFIG_TFM_PSA_API_CROSS_CALL ON PARENT_SCOPE)
+    endif()
+{% elif partition_statistics['sfn_partition_num'] > 0
+    and partition_statistics['ipc_partition_num'] == 0 %}
+    set(CONFIG_TFM_SPM_BACKEND_SFN ON PARENT_SCOPE)
+    set(CONFIG_TFM_PSA_API_SFN_CALL ON PARENT_SCOPE)
+
+    if(TFM_ISOLATION_LEVEL GREATER 1)
+        message(FATAL_ERROR "High isolation level SFN model is not supported.")
+    endif()
+{% elif partition_statistics['sfn_partition_num'] > 0
+    and partition_statistics['ipc_partition_num'] > 0 %}
+    message(FATAL_ERROR "IPC and SFN co-work not supported yet.")
+{% else %}
+    message(FATAL_ERROR "Invalid partition number input, check configurations.")
+{% endif %}
+
+    if((CONFIG_TFM_SPE_FP GREATER 0) AND CONFIG_TFM_SPM_BACKEND_SFN)
+        message(FATAL_ERROR "FP is not supported for SFN model.")
+    endif()
+endif()
diff --git a/tools/templates/manifestfilename.template b/tools/templates/manifestfilename.template
index 54ba9dc..9f90907 100644
--- a/tools/templates/manifestfilename.template
+++ b/tools/templates/manifestfilename.template
@@ -1,11 +1,11 @@
 /*
- * Copyright (c) 2019-2021, Arm Limited. All rights reserved.
+ * Copyright (c) 2019-2022, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
  */
 
-{{utilities.donotedit_warning}}
+/***********{{utilities.donotedit_warning}}***********/
 
 #ifndef __PSA_MANIFEST_{{manifest_out_basename.upper()}}_H__
 #define __PSA_MANIFEST_{{manifest_out_basename.upper()}}_H__
diff --git a/tools/templates/partition_intermedia.template b/tools/templates/partition_intermedia.template
index ce3d08b..a52a2cb 100644
--- a/tools/templates/partition_intermedia.template
+++ b/tools/templates/partition_intermedia.template
@@ -1,11 +1,11 @@
 /*
- * Copyright (c) 2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2020-2022, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
  */
 
-{{utilities.donotedit_warning}}
+/***********{{utilities.donotedit_warning}}***********/
 
 #include <stdint.h>
 
diff --git a/tools/templates/partition_load_info.template b/tools/templates/partition_load_info.template
index a691ba2..d9e6bb2 100644
--- a/tools/templates/partition_load_info.template
+++ b/tools/templates/partition_load_info.template
@@ -1,12 +1,12 @@
 /*
- * Copyright (c) 2021, Arm Limited. All rights reserved.
+ * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
  * Copyright (c) 2021, Cypress Semiconductor Corporation. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
  */
 
-{{utilities.donotedit_warning}}
+/***********{{utilities.donotedit_warning}}***********/
 
 #include <stdint.h>
 #include <stddef.h>
diff --git a/tools/tfm_generated_file_list.yaml b/tools/tfm_generated_file_list.yaml
index 0c866c7..a8ffe19 100644
--- a/tools/tfm_generated_file_list.yaml
+++ b/tools/tfm_generated_file_list.yaml
@@ -1,5 +1,5 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2018-2021, Arm Limited. All rights reserved.
+# Copyright (c) 2018-2022, Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -56,6 +56,12 @@
         "short_name": "config_impl.h",
         "template": "interface/include/config_impl.h.template",
         "output": "interface/include/config_impl.h"
+    },
+    {
+        "name": "CMake variables generated",
+        "short_name": "config_impl.cmake",
+        "template": "tools/config_impl.cmake.template",
+        "output": "tools/config_impl.cmake"
     }
   ]
 }
diff --git a/tools/tfm_parse_manifest_list.py b/tools/tfm_parse_manifest_list.py
index 5652461..3a6bd71 100644
--- a/tools/tfm_parse_manifest_list.py
+++ b/tools/tfm_parse_manifest_list.py
@@ -20,9 +20,7 @@
     exit(1)
 
 donotedit_warning = \
-                    '/*********** ' + \
-                    'WARNING: This is an auto-generated file. Do not edit!' + \
-                    ' ***********/'
+                    '  WARNING: This is an auto-generated file. Do not edit!  '
 
 TFM_ROOT_DIR = os.path.join(sys.path[0], '..')
 OUT_DIR = None # The root directory that files are generated to
@@ -267,11 +265,8 @@
         context contains partition infos
     """
 
-    utilities = {}
-    utilities['donotedit_warning'] = donotedit_warning
-
     partition_context = {}
-    partition_context['utilities'] = utilities
+    partition_context['utilities'] = context['utilities']
 
     manifesttemplate = ENV.get_template(os.path.join(sys.path[0], 'templates/manifestfilename.template'))
     memorytemplate = ENV.get_template(os.path.join(sys.path[0], 'templates/partition_intermedia.template'))
@@ -337,7 +332,6 @@
         manifest_out_file = os.path.join(OUT_DIR, manifest_out_file)
 
         print ('Generating ' + manifest_out_file)
-
         outfile_path = os.path.dirname(manifest_out_file)
         if not os.path.exists(outfile_path):
             os.makedirs(outfile_path)