From ea8bff57b14dad0b8d7e09c698ed1a08c532f04b Mon Sep 17 00:00:00 2001 From: Michael Schwarcz Date: Thu, 7 Feb 2019 12:12:01 +0200 Subject: [PATCH] TF-M patch: Fix fixed-size partitions stack size (TF-M issue #240) - Link to bug tracking: https://developer.trustedfirmware.org/T240 (cherry picked from commit fc7864055982f3b8e7e556f9dd8d0c94a1c772bc) --- .../COMPONENT_SPE/secure_fw/core/ipc/tfm_spm.c | 12 ++++++++---- .../TARGET_TFM/COMPONENT_SPE/secure_fw/spm/spm_db.h | 7 +++---- .../COMPONENT_SPE/secure_fw/spm/spm_db_setup.h | 6 +++++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/tfm_spm.c b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/tfm_spm.c index 58080bbd58..4f64361731 100644 --- a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/tfm_spm.c +++ b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/tfm_spm.c @@ -435,15 +435,19 @@ tfm_spm_partition_get_thread_info_ext(uint32_t partition_idx) return &g_spm_partition_db.partitions[partition_idx].sp_thrd; } -static uint32_t tfm_spm_partition_get_stack_base_ext(uint32_t partition_idx) +static uint32_t tfm_spm_partition_get_stack_size_ext(uint32_t partition_idx) { - return (uint32_t)&(g_spm_partition_db.partitions[partition_idx]. - stack[TFM_STACK_SIZE]); + return g_spm_partition_db.partitions[partition_idx].stack_size; } static uint32_t tfm_spm_partition_get_stack_limit_ext(uint32_t partition_idx) { - return (uint32_t)&g_spm_partition_db.partitions[partition_idx].stack; + return g_spm_partition_db.partitions[partition_idx].stack_limit; +} + +static uint32_t tfm_spm_partition_get_stack_base_ext(uint32_t partition_idx) +{ + return tfm_spm_partition_get_stack_limit_ext(partition_idx) + tfm_spm_partition_get_stack_size_ext(partition_idx); } static tfm_thrd_func_t diff --git a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/spm_db.h b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/spm_db.h index fc3da43e45..60b5fbd456 100644 --- a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/spm_db.h +++ b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/spm_db.h @@ -66,11 +66,10 @@ struct spm_partition_desc_t { #ifdef TFM_PSA_API struct tfm_thrd_ctx sp_thrd; /* - * FixMe: Hard code stack is not aligned with the definition in the - * manifest. It will use the partition stacks in the linker scripts/sct - * files include Level 1 to 3. + * stack_limit points to starting address of the partitions' stack plus the partitions' stack size. */ - uint8_t stack[TFM_STACK_SIZE] __attribute__((aligned(8))); + uint32_t stack_limit; + uint32_t stack_size; #endif }; diff --git a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/spm_db_setup.h b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/spm_db_setup.h index 217cfaa39b..a15e7b7cb1 100644 --- a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/spm_db_setup.h +++ b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/spm_db_setup.h @@ -71,7 +71,7 @@ struct spm_partition_db_t { } while (0) #endif -#define PARTITION_DECLARE(partition, flag, type, id, priority) \ +#define PARTITION_DECLARE(partition, flag, type, id, priority, part_stack_size) \ do { \ REGION_DECLARE(Image$$, partition, $$Base); \ REGION_DECLARE(Image$$, partition, $$Limit); \ @@ -97,8 +97,12 @@ struct spm_partition_db_t { if (g_spm_partition_db.partition_count >= SPM_MAX_PARTITIONS) { \ return SPM_ERR_INVALID_CONFIG; \ } \ + __attribute__((section(".data.partitions_stacks"))) \ + static uint8_t partition##_stack[part_stack_size] __attribute__((aligned(8))); \ part_ptr = &(g_spm_partition_db.partitions[ \ g_spm_partition_db.partition_count]); \ + part_ptr->stack_limit = (uint32_t)partition##_stack; \ + part_ptr->stack_size = part_stack_size; \ PARTITION_INIT_STATIC_DATA(part_ptr->static_data, partition, flags, \ id, priority); \ PARTITION_INIT_RUNTIME_DATA(part_ptr->runtime_data, partition); \