Skip to content

Commit 4dec7f7

Browse files
Michael Schwarczadbridge
authored andcommitted
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 fc78640)
1 parent 60b0626 commit 4dec7f7

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/tfm_spm.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,15 +433,19 @@ tfm_spm_partition_get_thread_info_ext(uint32_t partition_idx)
433433
return &g_spm_partition_db.partitions[partition_idx].sp_thrd;
434434
}
435435

436-
static uint32_t tfm_spm_partition_get_stack_base_ext(uint32_t partition_idx)
436+
static uint32_t tfm_spm_partition_get_stack_size_ext(uint32_t partition_idx)
437437
{
438-
return (uint32_t)&(g_spm_partition_db.partitions[partition_idx].
439-
stack[TFM_STACK_SIZE]);
438+
return g_spm_partition_db.partitions[partition_idx].stack_size;
440439
}
441440

442441
static uint32_t tfm_spm_partition_get_stack_limit_ext(uint32_t partition_idx)
443442
{
444-
return (uint32_t)&g_spm_partition_db.partitions[partition_idx].stack;
443+
return g_spm_partition_db.partitions[partition_idx].stack_limit;
444+
}
445+
446+
static uint32_t tfm_spm_partition_get_stack_base_ext(uint32_t partition_idx)
447+
{
448+
return tfm_spm_partition_get_stack_limit_ext(partition_idx) + tfm_spm_partition_get_stack_size_ext(partition_idx);
445449
}
446450

447451
static tfm_thrd_func_t

components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/spm_api.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,11 @@ enum spm_err_t tfm_spm_db_init(void)
9898
*/
9999

100100
/* For the non secure Execution environment */
101-
#if TFM_LVL != 1
102101
extern uint32_t Image$$ARM_LIB_STACK$$ZI$$Base[];
103102
extern uint32_t Image$$ARM_LIB_STACK$$ZI$$Limit[];
104103
uint32_t psp_stack_bottom = (uint32_t)Image$$ARM_LIB_STACK$$ZI$$Base;
105104
uint32_t psp_stack_top = (uint32_t)Image$$ARM_LIB_STACK$$ZI$$Limit;
106-
#endif
105+
107106
if (g_spm_partition_db.partition_count >= SPM_MAX_PARTITIONS) {
108107
return SPM_ERR_INVALID_CONFIG;
109108
}
@@ -119,6 +118,9 @@ enum spm_err_t tfm_spm_db_init(void)
119118
* RW start address to psp_stack_bottom to get RW access to stack
120119
*/
121120
part_ptr->memory_data.rw_start = psp_stack_bottom;
121+
#else
122+
part_ptr->stack_limit = psp_stack_bottom;
123+
part_ptr->stack_size = psp_stack_top - psp_stack_bottom;
122124
#endif
123125

124126
part_ptr->runtime_data.partition_state = SPM_PARTITION_STATE_UNINIT;

components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/spm_db.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,10 @@ struct spm_partition_desc_t {
6565
#ifdef TFM_PSA_API
6666
struct tfm_thrd_ctx sp_thrd;
6767
/*
68-
* FixMe: Hard code stack is not aligned with the definition in the
69-
* manifest. It will use the partition stacks in the linker scripts/sct
70-
* files include Level 1 to 3.
68+
* stack_limit points to starting address of the partitions' stack plus the partitions' stack size.
7169
*/
72-
uint8_t stack[TFM_STACK_SIZE] __attribute__((aligned(8)));
70+
uint32_t stack_limit;
71+
uint32_t stack_size;
7372
#endif
7473
};
7574

components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/spm_db_setup.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct spm_partition_db_t {
7676
} while (0)
7777
#endif
7878

79-
#define PARTITION_DECLARE(partition, flag, type, id, priority) \
79+
#define PARTITION_DECLARE(partition, flag, type, id, priority, part_stack_size) \
8080
do { \
8181
REGION_DECLARE(Image$$, partition, $$Base); \
8282
REGION_DECLARE(Image$$, partition, $$Limit); \
@@ -102,8 +102,12 @@ struct spm_partition_db_t {
102102
if (g_spm_partition_db.partition_count >= SPM_MAX_PARTITIONS) { \
103103
return SPM_ERR_INVALID_CONFIG; \
104104
} \
105+
__attribute__((section(".data.partitions_stacks"))) \
106+
static uint8_t partition##_stack[part_stack_size] __attribute__((aligned(8))); \
105107
part_ptr = &(g_spm_partition_db.partitions[ \
106108
g_spm_partition_db.partition_count]); \
109+
part_ptr->stack_limit = (uint32_t)partition##_stack; \
110+
part_ptr->stack_size = part_stack_size; \
107111
PARTITION_INIT_STATIC_DATA(part_ptr->static_data, partition, flags, \
108112
id, priority); \
109113
PARTITION_INIT_RUNTIME_DATA(part_ptr->runtime_data, partition); \

0 commit comments

Comments
 (0)