Kconfig: Add build type support

Signed-off-by: Jianliang Shen <jianliang.shen@arm.com>
Change-Id: Id66fb82d8f3f3e406111c86040cbaac8f2076bba
diff --git a/Kconfig b/Kconfig
index 3f7049b..254db6e 100644
--- a/Kconfig
+++ b/Kconfig
@@ -9,6 +9,7 @@
 
 # Load platform Kconfig file if exists
 osource "$(PLATFORM_PATH)/Kconfig"
+osource "$(TFM_SOURCE_DIR)/config/build_type/Kconfig.$(CMAKE_BUILD_TYPE)"
 
 ################################# System options ###############################
 
diff --git a/config/build_type/Kconfig.debug b/config/build_type/Kconfig.debug
new file mode 100644
index 0000000..295f0b0
--- /dev/null
+++ b/config/build_type/Kconfig.debug
@@ -0,0 +1,18 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2023, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+config MBEDCRYPTO_BUILD_TYPE
+    default "relwithdebinfo"
+
+config TFM_SPM_LOG_LEVEL
+    default 3
+
+config TFM_PARTITION_LOG_LEVEL
+    default 3
+
+config CONFIG_TFM_HALT_ON_CORE_PANIC
+    default y
diff --git a/config/build_type/Kconfig.minsizerel b/config/build_type/Kconfig.minsizerel
new file mode 100644
index 0000000..2d54287
--- /dev/null
+++ b/config/build_type/Kconfig.minsizerel
@@ -0,0 +1,22 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2023, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+if BL2
+config MCUBOOT_LOG_LEVEL
+    default "OFF"
+endif
+
+config TFM_SPM_LOG_LEVEL
+    default 0
+
+config TFM_PARTITION_LOG_LEVEL
+    default 0
+
+if BL1 && PLATFORM_DEFAULT_BL1
+config TFM_BL1_LOGGING
+    default n
+endif
diff --git a/config/build_type/Kconfig.release b/config/build_type/Kconfig.release
new file mode 100644
index 0000000..c2bd1ea
--- /dev/null
+++ b/config/build_type/Kconfig.release
@@ -0,0 +1,25 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2023, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+config MBEDCRYPTO_BUILD_TYPE
+    default "minsizerel"
+
+if BL2
+config MCUBOOT_LOG_LEVEL
+    default "OFF"
+endif
+
+config TFM_SPM_LOG_LEVEL
+    default 0
+
+config TFM_PARTITION_LOG_LEVEL
+    default 0
+
+if BL1 && PLATFORM_DEFAULT_BL1
+config TFM_BL1_LOGGING
+    default n
+endif
diff --git a/config/kconfig.cmake b/config/kconfig.cmake
index 38b28c6..02707dd 100644
--- a/config/kconfig.cmake
+++ b/config/kconfig.cmake
@@ -187,6 +187,10 @@
 endif()
 get_filename_component(PLATFORM_KCONFIG_PATH ${PLATFORM_KCONFIG} DIRECTORY)
 
+# Build type Kconfig file, for example 'Kconfig.minsizerel', the suffix passed
+# by Kconfig environment variables and it shall be lowercase.
+string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWERCASE)
+
 # TF-M profile config file
 if(TFM_PROFILE)
     set(TFM_PROFILE_KCONFIG_FILE ${CMAKE_SOURCE_DIR}/config/profile/${TFM_PROFILE}.conf)
@@ -228,7 +232,7 @@
 set(KCONFIG_ENV_VARS "TFM_SOURCE_DIR=${CMAKE_SOURCE_DIR} \
                       TFM_VERSION=${TFM_VERSION} \
                       PLATFORM_PATH=${PLATFORM_KCONFIG_PATH} \
-                      CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
+                      CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE_LOWERCASE}")
 
 if(MENUCONFIG)
     # Note: Currently, only GUI menuconfig can be supported with CMake integration
@@ -283,10 +287,5 @@
     include(${TARGET_PLATFORM_PATH}/reg_config_override.cmake)
 endif()
 
-# Load build type config, setting options not already set
-if(EXISTS ${CMAKE_SOURCE_DIR}/config/build_type/${CMAKE_BUILD_TYPE_LOWERCASE}.cmake)
-    include(${CMAKE_SOURCE_DIR}/config/build_type/${CMAKE_BUILD_TYPE_LOWERCASE}.cmake)
-endif()
-
 # Load defaults, setting options not already set
 include(config/config_base.cmake)