Tool: Calculate total size of stacks for SFN backend

Under the SFN backend in isolation level 1, partitions do not need
dedicated stacks since they can work on the caller stack. Let the
tool calculate the sum of stacks and provide for further usage.
NS Agent can allocate stack with this sum since it is the initial
caller of all access.

Change-Id: Iee4ae996fc43cf1fc7f4c1d468372ae5c194bb4f
Signed-off-by: Mingyang Sun <mingyang.sun@arm.com>
Co-authored-by: Ken Liu <ken.liu@arm.com>
diff --git a/interface/include/config_impl.h.template b/interface/include/config_impl.h.template
index 6ef1a2b..96ea631 100644
--- a/interface/include/config_impl.h.template
+++ b/interface/include/config_impl.h.template
@@ -27,6 +27,16 @@
 #error "High isolation level SFN model is not supported."
 #endif
 
+    {% 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 %}
+    {% endfor %}
+#define {{"%-36s"|format("SUM_OF_PARTITION_STACK_SIZES")}} ((({{"0x%x"|format(total_stk.size)}} >> 1) + 0x7) & (~0x7))
+
 {% elif sfn_partition_num > 0 and ipc_partition_num > 0 %}
 #error "IPC and SFN co-work not supported yet."
 {% else %}