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 */
diff --git a/tools/templates/partition_intermedia.template b/tools/templates/partition_intermedia.template
index ad76662..b6d45c4 100644
--- a/tools/templates/partition_intermedia.template
+++ b/tools/templates/partition_intermedia.template
@@ -8,6 +8,7 @@
/***********{{utilities.donotedit_warning}}***********/
#include <stdint.h>
+#include "config_tfm.h"
{% if config_impl['CONFIG_TFM_SPM_BACKEND_IPC'] == '1' or manifest.model == "IPC" %}
uint8_t {{manifest.name.lower()}}_stack[{{manifest.stack_size}}] __attribute__((aligned(8)));
diff --git a/tools/templates/partition_load_info.template b/tools/templates/partition_load_info.template
index c347d01..28db89a 100644
--- a/tools/templates/partition_load_info.template
+++ b/tools/templates/partition_load_info.template
@@ -12,6 +12,7 @@
#include <stdint.h>
#include <stddef.h>
+#include "config_tfm.h"
#include "region.h"
#include "region_defs.h"
#include "spm_ipc.h"
diff --git a/tools/tfm_parse_manifest_list.py b/tools/tfm_parse_manifest_list.py
index 99798ab..9a9ba16 100644
--- a/tools/tfm_parse_manifest_list.py
+++ b/tools/tfm_parse_manifest_list.py
@@ -216,29 +216,6 @@
validate_dependency_chain(dependency, dependency_table, dependency_chain)
dependency_table[partition]['validated'] = True
-def manifest_attribute_to_int(manifest, attribute, configs):
- """
- This method tries to convert the value of the given `attribute` in the given
- `manifest` to an integer.
- If the value is a decimal/hexadecimal int, return it directly.
- Otherwise, treat it as a configuration and find the value in the given `configs`.
- If the configuration is not found, exit script with error.
- """
-
- value = manifest[attribute]
- try:
- # base 16 works for both decimal and hexadecimal
- int(value, base=16)
- except ValueError:
- # Not an int, find the value in configs
- if value not in configs.keys():
- logging.error('{} is not defined in configurations'.format(value))
- exit(1)
-
- value = configs[value]
-
- return value
-
def process_partition_manifests(manifest_lists, configs):
"""
Parse the input manifest lists, check if manifest settings are valid,
@@ -358,12 +335,6 @@
if manifest['model'] == 'IPC':
partition_statistics['ipc_partitions'].append(manifest['name'])
- # Convert stack_size and heap_size to int. They might be configurations.
- manifest['stack_size'] = manifest_attribute_to_int(manifest, 'stack_size', configs)
-
- if 'heap_size' in manifest.keys():
- manifest['heap_size'] = manifest_attribute_to_int(manifest, 'heap_size', configs)
-
# Set initial value to -1 to make (srv_idx + 1) reflect the correct
# number (0) when there are no services.
srv_idx = -1