Skip to content

Commit d3c610e

Browse files
committed
TF-M patch/workaround related to (TF-M issue #T240)
- Link to bug tracking: https://developer.trustedfirmware.org/T240 The issue is fixed by TF-M team. This work around allows existing stack allocation in mbed-os for different partitions to be used with the fix Signed-off-by: Devaraj Ranganna <[email protected]>
1 parent 910a402 commit d3c610e

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ enum spm_err_t tfm_spm_db_init(void)
128128
* RW start address to psp_stack_bottom to get RW access to stack
129129
*/
130130
part_ptr->memory_data.rw_start = psp_stack_bottom;
131+
132+
part_ptr->stack_bottom = psp_stack_bottom;
133+
part_ptr->stack_top = psp_stack_top;
134+
131135
#endif
132136

133137
part_ptr->runtime_data.partition_state = SPM_PARTITION_STATE_UNINIT;
@@ -205,12 +209,12 @@ enum spm_err_t tfm_spm_partition_init(void)
205209
uint32_t tfm_spm_partition_get_stack_bottom(uint32_t partition_idx)
206210
{
207211
return g_spm_partition_db.partitions[partition_idx].
208-
memory_data.stack_bottom;
212+
stack_bottom;
209213
}
210214

211215
uint32_t tfm_spm_partition_get_stack_top(uint32_t partition_idx)
212216
{
213-
return g_spm_partition_db.partitions[partition_idx].memory_data.stack_top;
217+
return g_spm_partition_db.partitions[partition_idx].stack_top;
214218
}
215219
#endif
216220

@@ -286,7 +290,6 @@ uint32_t tfm_spm_partition_get_flags(uint32_t partition_idx)
286290
partition_flags;
287291
}
288292

289-
#ifndef TFM_PSA_API
290293
void tfm_spm_partition_store_context(uint32_t partition_idx,
291294
uint32_t stack_ptr, uint32_t lr)
292295
{
@@ -397,7 +400,6 @@ void tfm_spm_partition_cleanup_context(uint32_t partition_idx)
397400
partition->runtime_data.orig_outvec = 0;
398401
partition->runtime_data.iovec_api = 0;
399402
}
400-
#endif /* !defined(TFM_PSA_API) */
401403

402404
__attribute__((section("SFN")))
403405
void tfm_spm_partition_change_privilege(uint32_t privileged)

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,18 @@ struct spm_partition_desc_t {
6262
#endif
6363
#ifdef TFM_PSA_API
6464
struct tfm_thrd_ctx sp_thrd;
65+
/*
66+
* stack_bottom points to starting address of the partitions' stack plus the partitions' stack top.
67+
*/
68+
uint32_t stack_bottom;
69+
uint32_t stack_top;
6570
#endif
6671
};
6772

6873
/* Macros to pick linker symbols and allow to form the partition data base */
6974
#define REGION(a, b, c) a##b##c
7075
#define REGION_NAME(a, b, c) REGION(a, b, c)
71-
#if (TFM_LVL == 1) && !defined(TFM_PSA_API)
76+
#if (TFM_LVL == 1)
7277
#define REGION_DECLARE(a, b, c)
7378
#else
7479
#define REGION_DECLARE(a, b, c) extern uint32_t REGION_NAME(a, b, c)

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct spm_partition_db_t {
3838
data.partition_priority = TFM_PRIORITY(priority); \
3939
} while (0)
4040

41-
#if (TFM_LVL == 1) && !defined(TFM_PSA_API)
41+
#if (TFM_LVL == 1)
4242
#define PARTITION_INIT_MEMORY_DATA(data, partition)
4343
#else
4444
#define PARTITION_INIT_MEMORY_DATA(data, partition) \
@@ -75,7 +75,7 @@ struct spm_partition_db_t {
7575
} while (0)
7676
#endif
7777

78-
#define PARTITION_DECLARE(partition, flag, type, id, priority) \
78+
#define PARTITION_DECLARE(partition, flag, type, id, priority, part_stack_size) \
7979
do { \
8080
REGION_DECLARE(Image$$, partition, $$Base); \
8181
REGION_DECLARE(Image$$, partition, $$Limit); \
@@ -101,8 +101,12 @@ struct spm_partition_db_t {
101101
if (g_spm_partition_db.partition_count >= SPM_MAX_PARTITIONS) { \
102102
return SPM_ERR_INVALID_CONFIG; \
103103
} \
104+
__attribute__((section(".data.partitions_stacks"))) \
105+
static uint8_t partition##_stack[part_stack_size] __attribute__((aligned(8))); \
104106
part_ptr = &(g_spm_partition_db.partitions[ \
105107
g_spm_partition_db.partition_count]); \
108+
part_ptr->stack_bottom = (uint32_t)partition##_stack; \
109+
part_ptr->stack_top = part_ptr->stack_bottom + part_stack_size; \
106110
PARTITION_INIT_STATIC_DATA(part_ptr->static_data, partition, flags, \
107111
id, priority); \
108112
PARTITION_INIT_RUNTIME_DATA(part_ptr->runtime_data, partition); \

0 commit comments

Comments
 (0)