FWU: Set features with config header file

Signed-off-by: Xinyu Zhang <xinyu.zhang@arm.com>
Change-Id: If12a00857dbfc67bb83f982528f63bbeb15eb006
diff --git a/config/config_base.h b/config/config_base.h
index d0562c6..e524db7 100644
--- a/config/config_base.h
+++ b/config/config_base.h
@@ -75,4 +75,12 @@
 /* The stack size of the Crypto Secure Partition */
 #define CRYPTO_STACK_SIZE                      0x1B00
 
+/* FWU Partition Configs */
+
+/* Size of the FWU internal data transfer buffer */
+#define TFM_FWU_BUF_SIZE                       PSA_FWU_MAX_WRITE_SIZE
+
+/* The stack size of the Firmware Update Secure Partition */
+#define FWU_STACK_SIZE                         0x600
+
 #endif /* __CONFIG_BASE_H__ */
diff --git a/config/profile/config_profile_large.h b/config/profile/config_profile_large.h
index ec90b17..8e09d71 100644
--- a/config/profile/config_profile_large.h
+++ b/config/profile/config_profile_large.h
@@ -75,4 +75,12 @@
 /* The stack size of the Crypto Secure Partition */
 #define CRYPTO_STACK_SIZE                      0x1B00
 
+/* FWU Partition Configs */
+
+/* Size of the FWU internal data transfer buffer */
+#define TFM_FWU_BUF_SIZE                       PSA_FWU_MAX_WRITE_SIZE
+
+/* The stack size of the Firmware Update Secure Partition */
+#define FWU_STACK_SIZE                         0x600
+
 #endif /* __CONFIG_PROFILE_LARGE_H__ */
diff --git a/config/profile/config_profile_medium.h b/config/profile/config_profile_medium.h
index 5e6fd5f..83b93e4 100644
--- a/config/profile/config_profile_medium.h
+++ b/config/profile/config_profile_medium.h
@@ -75,4 +75,12 @@
 /* The stack size of the Crypto Secure Partition */
 #define CRYPTO_STACK_SIZE                      0x1B00
 
+/* FWU Partition Configs */
+
+/* Size of the FWU internal data transfer buffer */
+#define TFM_FWU_BUF_SIZE                       PSA_FWU_MAX_WRITE_SIZE
+
+/* The stack size of the Firmware Update Secure Partition */
+#define FWU_STACK_SIZE                         0x600
+
 #endif /* __CONFIG_PROFILE_MEDIUM_H__ */
diff --git a/config/profile/config_profile_medium_arotless.h b/config/profile/config_profile_medium_arotless.h
index 50d499e..59ca891 100644
--- a/config/profile/config_profile_medium_arotless.h
+++ b/config/profile/config_profile_medium_arotless.h
@@ -75,4 +75,12 @@
 /* The stack size of the Crypto Secure Partition */
 #define CRYPTO_STACK_SIZE                      0x1B00
 
+/* FWU Partition Configs */
+
+/* Size of the FWU internal data transfer buffer */
+#define TFM_FWU_BUF_SIZE                       PSA_FWU_MAX_WRITE_SIZE
+
+/* The stack size of the Firmware Update Secure Partition */
+#define FWU_STACK_SIZE                         0x600
+
 #endif /* __CONFIG_PROFILE_MEDIUM_AROTLESS_H__ */
diff --git a/config/profile/config_profile_small.h b/config/profile/config_profile_small.h
index 0c150b4..a3e0fac 100644
--- a/config/profile/config_profile_small.h
+++ b/config/profile/config_profile_small.h
@@ -72,4 +72,12 @@
 /* The stack size of the Crypto Secure Partition */
 #define CRYPTO_STACK_SIZE                      0x1B00
 
+/* FWU Partition Configs */
+
+/* Size of the FWU internal data transfer buffer */
+#define TFM_FWU_BUF_SIZE                       PSA_FWU_MAX_WRITE_SIZE
+
+/* The stack size of the Firmware Update Secure Partition */
+#define FWU_STACK_SIZE                         0x600
+
 #endif /* __CONFIG_PROFILE_SMALL_H__ */
diff --git a/config/tests/config_test_psa_api.h b/config/tests/config_test_psa_api.h
index 19510da..a4c02f2 100644
--- a/config/tests/config_test_psa_api.h
+++ b/config/tests/config_test_psa_api.h
@@ -75,4 +75,12 @@
 /* The stack size of the Crypto Secure Partition */
 #define CRYPTO_STACK_SIZE                      0x1B00
 
+/* FWU Partition Configs */
+
+/* Size of the FWU internal data transfer buffer */
+#define TFM_FWU_BUF_SIZE                       PSA_FWU_MAX_WRITE_SIZE
+
+/* The stack size of the Firmware Update Secure Partition */
+#define FWU_STACK_SIZE                         0x600
+
 #endif /* __CONFIG_TEST_PSA_API_H__ */
diff --git a/config/tfm_fwu_config.cmake b/config/tfm_fwu_config.cmake
index f7272c9..2015096 100755
--- a/config/tfm_fwu_config.cmake
+++ b/config/tfm_fwu_config.cmake
@@ -10,8 +10,6 @@
 set(TFM_FWU_BOOTLOADER_LIB                "mcuboot"   CACHE STRING    "Bootloader configure file for Firmware Update partition")
 set(TFM_CONFIG_FWU_MAX_WRITE_SIZE         1024        CACHE STRING    "The maximum permitted size for block in psa_fwu_write, in bytes.")
 set(TFM_CONFIG_FWU_MAX_MANIFEST_SIZE      0           CACHE STRING    "The maximum permitted size for manifest in psa_fwu_start(), in bytes.")
-set(TFM_FWU_BUF_SIZE                      ""          CACHE STRING    "Size of the FWU internal data transfer buffer (defaults to PSA_FWU_MAX_BLOCK_SIZE if not set)")
-set(FWU_STACK_SIZE                        "0x600"     CACHE STRING    "The stack size of the Firmware Update Secure Partition")
 set(FWU_DEVICE_CONFIG_FILE                ""          CACHE STRING    "The device configuration file for Firmware Update partition")
 if (DEFINED MCUBOOT_UPGRADE_STRATEGY)
     if(${MCUBOOT_UPGRADE_STRATEGY} STREQUAL "SWAP_USING_SCRATCH" OR ${MCUBOOT_UPGRADE_STRATEGY} STREQUAL "SWAP_USING_MOVE")
diff --git a/secure_fw/partitions/firmware_update/CMakeLists.txt b/secure_fw/partitions/firmware_update/CMakeLists.txt
index 0727579..1b58289 100644
--- a/secure_fw/partitions/firmware_update/CMakeLists.txt
+++ b/secure_fw/partitions/firmware_update/CMakeLists.txt
@@ -45,6 +45,7 @@
 target_link_libraries(tfm_psa_rot_partition_fwu
     PRIVATE
         platform_s
+        tfm_config
         tfm_sprt
 )
 
@@ -68,7 +69,6 @@
 target_compile_definitions(tfm_psa_rot_partition_fwu
     PRIVATE
         $<$<BOOL:${DEFAULT_MCUBOOT_FLASH_MAP}>:DEFAULT_MCUBOOT_FLASH_MAP>
-        $<$<BOOL:${TFM_FWU_BUF_SIZE}>:TFM_FWU_BUF_SIZE=${TFM_FWU_BUF_SIZE}>
         FWU_DEVICE_CONFIG_FILE="${FWU_DEVICE_CONFIG_FILE}"
 )
 
@@ -90,7 +90,6 @@
 dump_options("Firmware Update Partition config"
 "
     TFM_FWU_BOOTLOADER_LIB;
-    FWU_STACK_SIZE;
     FWU_DEVICE_CONFIG_FILE
 "
 )
diff --git a/secure_fw/partitions/firmware_update/config_fwu.h b/secure_fw/partitions/firmware_update/config_fwu.h
new file mode 100644
index 0000000..b168451
--- /dev/null
+++ b/secure_fw/partitions/firmware_update/config_fwu.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2022, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef __CONFIG_PARTITION_FWU_H__
+#define __CONFIG_PARTITION_FWU_H__
+
+#include "config_tfm.h"
+
+/* Size of the FWU internal data transfer buffer */
+#ifndef TFM_FWU_BUF_SIZE
+#pragma message ("TFM_FWU_BUF_SIZE is defaulted to PSA_FWU_MAX_WRITE_SIZE. Please check and set it explicitly.")
+#define TFM_FWU_BUF_SIZE               PSA_FWU_MAX_WRITE_SIZE
+#endif
+
+/* The stack size of the Firmware Update Secure Partition */
+#ifndef FWU_STACK_SIZE
+#pragma message ("FWU_STACK_SIZE is defaulted to 0x600. Please check and set it explicitly.")
+#define FWU_STACK_SIZE                 0x600
+#endif
+
+#endif /* __CONFIG_PARTITION_FWU_H__ */
diff --git a/secure_fw/partitions/firmware_update/tfm_fwu_req_mngr.c b/secure_fw/partitions/firmware_update/tfm_fwu_req_mngr.c
index b57cdff..be7dec0 100644
--- a/secure_fw/partitions/firmware_update/tfm_fwu_req_mngr.c
+++ b/secure_fw/partitions/firmware_update/tfm_fwu_req_mngr.c
@@ -8,6 +8,7 @@
 #include <stdint.h>
 #include <stdbool.h>
 #include <string.h>
+#include "config_fwu.h"
 #include "tfm_platform_api.h"
 #include "tfm_bootloader_fwu_abstraction.h"
 #include "psa/update.h"
@@ -32,9 +33,6 @@
 static tfm_fwu_ctx_t fwu_ctx[FWU_COMPONENT_NUMBER];
 
 #if PSA_FRAMEWORK_HAS_MM_IOVEC != 1
-#ifndef TFM_FWU_BUF_SIZE
-#define TFM_FWU_BUF_SIZE PSA_FWU_MAX_WRITE_SIZE
-#endif
 static uint8_t block[TFM_FWU_BUF_SIZE] __aligned(4);
 #endif