Skip to content

Commit fc78640

Browse files
author
Michael Schwarcz
committed
TF-M patch: Fix fixed-size partitions stack size (TF-M issue #240)
- Link to bug tracking: https://developer.trustedfirmware.org/T240
1 parent 0c23e86 commit fc78640

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
@@ -435,15 +435,19 @@ tfm_spm_partition_get_thread_info_ext(uint32_t partition_idx)
435435
return &g_spm_partition_db.partitions[partition_idx].sp_thrd;
436436
}
437437

438-
static uint32_t tfm_spm_partition_get_stack_base_ext(uint32_t partition_idx)
438+
static uint32_t tfm_spm_partition_get_stack_size_ext(uint32_t partition_idx)
439439
{
440-
return (uint32_t)&(g_spm_partition_db.partitions[partition_idx].
441-
stack[TFM_STACK_SIZE]);
440+
return g_spm_partition_db.partitions[partition_idx].stack_size;
442441
}
443442

444443
static uint32_t tfm_spm_partition_get_stack_limit_ext(uint32_t partition_idx)
445444
{
446-
return (uint32_t)&g_spm_partition_db.partitions[partition_idx].stack;
445+
return g_spm_partition_db.partitions[partition_idx].stack_limit;
446+
}
447+
448+
static uint32_t tfm_spm_partition_get_stack_base_ext(uint32_t partition_idx)
449+
{
450+
return tfm_spm_partition_get_stack_limit_ext(partition_idx) + tfm_spm_partition_get_stack_size_ext(partition_idx);
447451
}
448452

449453
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
@@ -66,11 +66,10 @@ struct spm_partition_desc_t {
6666
#ifdef TFM_PSA_API
6767
struct tfm_thrd_ctx sp_thrd;
6868
/*
69-
* FixMe: Hard code stack is not aligned with the definition in the
70-
* manifest. It will use the partition stacks in the linker scripts/sct
71-
* files include Level 1 to 3.
69+
* stack_limit points to starting address of the partitions' stack plus the partitions' stack size.
7270
*/
73-
uint8_t stack[TFM_STACK_SIZE] __attribute__((aligned(8)));
71+
uint32_t stack_limit;
72+
uint32_t stack_size;
7473
#endif
7574
};
7675

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
@@ -71,7 +71,7 @@ struct spm_partition_db_t {
7171
} while (0)
7272
#endif
7373

74-
#define PARTITION_DECLARE(partition, flag, type, id, priority) \
74+
#define PARTITION_DECLARE(partition, flag, type, id, priority, part_stack_size) \
7575
do { \
7676
REGION_DECLARE(Image$$, partition, $$Base); \
7777
REGION_DECLARE(Image$$, partition, $$Limit); \
@@ -97,8 +97,12 @@ struct spm_partition_db_t {
9797
if (g_spm_partition_db.partition_count >= SPM_MAX_PARTITIONS) { \
9898
return SPM_ERR_INVALID_CONFIG; \
9999
} \
100+
__attribute__((section(".data.partitions_stacks"))) \
101+
static uint8_t partition##_stack[part_stack_size] __attribute__((aligned(8))); \
100102
part_ptr = &(g_spm_partition_db.partitions[ \
101103
g_spm_partition_db.partition_count]); \
104+
part_ptr->stack_limit = (uint32_t)partition##_stack; \
105+
part_ptr->stack_size = part_stack_size; \
102106
PARTITION_INIT_STATIC_DATA(part_ptr->static_data, partition, flags, \
103107
id, priority); \
104108
PARTITION_INIT_RUNTIME_DATA(part_ptr->runtime_data, partition); \

0 commit comments

Comments
 (0)