Skip to content

Commit 3915c54

Browse files
Michael SchwarczOren Cohen
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 82a8dc3 commit 3915c54

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
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
@@ -432,15 +432,19 @@ tfm_spm_partition_get_thread_info_ext(uint32_t partition_idx)
432432
return &g_spm_partition_db.partitions[partition_idx].sp_thrd;
433433
}
434434

435-
static uint32_t tfm_spm_partition_get_stack_base_ext(uint32_t partition_idx)
435+
static uint32_t tfm_spm_partition_get_stack_size_ext(uint32_t partition_idx)
436436
{
437-
return (uint32_t)&(g_spm_partition_db.partitions[partition_idx].
438-
stack[TFM_STACK_SIZE]);
437+
return g_spm_partition_db.partitions[partition_idx].stack_size;
439438
}
440439

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

446450
static tfm_thrd_func_t

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)