Tools: Add support to include STACK SIZE from header file

Signed-off-by: Xinyu Zhang <xinyu.zhang@arm.com>
Change-Id: Ic9c7405c2b81278f207ad8031bb466b322134146
diff --git a/interface/include/config_impl.h.template b/interface/include/config_impl.h.template
index f97c2a6..713b0b8 100644
--- a/interface/include/config_impl.h.template
+++ b/interface/include/config_impl.h.template
@@ -9,6 +9,8 @@
 #ifndef __CONFIG_IMPL_H__
 #define __CONFIG_IMPL_H__
 
+#include "config_tfm.h"
+
 /* Backends */
 #define {{"%-56s"|format("CONFIG_TFM_SPM_BACKEND_IPC")}} {{config_impl['CONFIG_TFM_SPM_BACKEND_IPC']}}
 #define {{"%-56s"|format("CONFIG_TFM_SPM_BACKEND_SFN")}} {{config_impl['CONFIG_TFM_SPM_BACKEND_SFN']}}
@@ -36,13 +38,9 @@
             {{"%-56s"|format("CONFIG_TFM_NS_AGENT_TZ_STACK_SIZE")}}
 
 #elif CONFIG_TFM_SPM_BACKEND_SFN == 1
-    {% set total_stk = namespace(size=0) %}
+    {% set total_stk = namespace(size="0") %}
     {% for partition in partitions %}
-        {% if "0x" in partition.manifest.stack_size or "0X" in partition.manifest.stack_size %}
-            {% set total_stk.size = total_stk.size + partition.manifest.stack_size|int(base=16) %}
-        {% else %}
-            {% set total_stk.size = total_stk.size + partition.manifest.stack_size|int(base=10) %}
-        {% endif %}
+        {% set total_stk.size = total_stk.size + " + " + partition.manifest.stack_size %}
     {% endfor %}
 /*
  * In isolation level 1 SFN model, all subsequent components work on NS agent
@@ -54,12 +52,15 @@
  * The minimum value is 0x400 to satisfy the SPM functional requirement.
  * Manifest tool will assure this.
  */
-    {% if total_stk.size|int < 2048 %}
-        {% set total_stk.size = 2048 %}
-    {% endif %}
+#define {{"%-56s"|format("CONFIG_TFM_TOTAL_STACK_SIZE")}} ({{total_stk.size}})
+#if (CONFIG_TFM_TOTAL_STACK_SIZE < 2048)
+#undef {{"%-56s"|format("CONFIG_TFM_TOTAL_STACK_SIZE")}}
+#define {{"%-56s"|format("CONFIG_TFM_TOTAL_STACK_SIZE")}} 2048
+#endif
+
 #define CONFIG_TFM_NS_AGENT_TZ_STK_SIZE_SHIFT_FACTOR             1
 #define {{"%-56s"|format("CONFIG_TFM_NS_AGENT_TZ_STACK_SIZE")}}  \
-    ((({{"0x%x"|format(total_stk.size)}} >> CONFIG_TFM_NS_AGENT_TZ_STK_SIZE_SHIFT_FACTOR) + 0x7) & (~0x7))
+    (((CONFIG_TFM_TOTAL_STACK_SIZE >> CONFIG_TFM_NS_AGENT_TZ_STK_SIZE_SHIFT_FACTOR) + 0x7) & (~0x7))
 
 #endif /* CONFIG_TFM_SPM_BACKEND_IPC == 1 */