Skip to content

Commit 6e899b3

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. However they autogenerate region details (code, ro, rw, zi and stack ) using linker scripts and in mbed-os we also autogenerate region details but using mix of service definition in json file and other template files. Signed-off-by: Devaraj Ranganna <[email protected]>
1 parent 9a51105 commit 6e899b3

File tree

2 files changed

+60
-48
lines changed

2 files changed

+60
-48
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ struct spm_partition_desc_t {
6868
/* Macros to pick linker symbols and allow to form the partition data base */
6969
#define REGION(a, b, c) a##b##c
7070
#define REGION_NAME(a, b, c) REGION(a, b, c)
71-
#if (TFM_LVL == 1) && !defined(TFM_PSA_API)
71+
/* Changed from #if (TFM_LVL == 1) && !defined(TFM_PSA_API) to #if (TFM_LVL == 1) to avoid linker error.
72+
TF-M build autogenerates region details (code, ro, rw, zi and stack ) using linker scripts. We do not
73+
hve that in mbed-os build yet.
74+
*/
75+
#if (TFM_LVL == 1)
7276
#define REGION_DECLARE(a, b, c)
7377
#else
7478
#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: 55 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ 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+
/* Changed from #if (TFM_LVL == 1) && !defined(TFM_PSA_API) to #if (TFM_LVL == 1) to avoid linker error.
42+
TF-M build autogenerates region details (code, ro, rw, zi and stack ) using linker scripts. We do not
43+
hve that in mbed-os build yet.
44+
*/
45+
#if (TFM_LVL == 1)
4246
#define PARTITION_INIT_MEMORY_DATA(data, partition)
4347
#else
4448
#define PARTITION_INIT_MEMORY_DATA(data, partition) \
@@ -75,56 +79,60 @@ struct spm_partition_db_t {
7579
} while (0)
7680
#endif
7781

78-
#define PARTITION_DECLARE(partition, flag, type, id, priority) \
79-
do { \
80-
REGION_DECLARE(Image$$, partition, $$Base); \
81-
REGION_DECLARE(Image$$, partition, $$Limit); \
82-
REGION_DECLARE(Image$$, partition, $$RO$$Base); \
83-
REGION_DECLARE(Image$$, partition, $$RO$$Limit); \
84-
REGION_DECLARE(Image$$, partition, _DATA$$RW$$Base); \
85-
REGION_DECLARE(Image$$, partition, _DATA$$RW$$Limit); \
86-
REGION_DECLARE(Image$$, partition, _DATA$$ZI$$Base); \
87-
REGION_DECLARE(Image$$, partition, _DATA$$ZI$$Limit); \
88-
REGION_DECLARE(Image$$, partition, _STACK$$ZI$$Base); \
89-
REGION_DECLARE(Image$$, partition, _STACK$$ZI$$Limit); \
90-
int32_t flags = flag; \
91-
if (tfm_memcmp(type, TFM_PARTITION_TYPE_APP, \
92-
strlen(TFM_PARTITION_TYPE_APP)) == 0) { \
93-
flags |= SPM_PART_FLAG_APP_ROT; \
94-
} else if (tfm_memcmp(type, TFM_PARTITION_TYPE_PSA, \
95-
strlen(TFM_PARTITION_TYPE_PSA)) == 0) { \
96-
flags |= SPM_PART_FLAG_PSA_ROT | SPM_PART_FLAG_APP_ROT; \
97-
} else { \
98-
return SPM_ERR_INVALID_CONFIG; \
99-
} \
100-
struct spm_partition_desc_t *part_ptr; \
101-
if (g_spm_partition_db.partition_count >= SPM_MAX_PARTITIONS) { \
102-
return SPM_ERR_INVALID_CONFIG; \
103-
} \
104-
part_ptr = &(g_spm_partition_db.partitions[ \
105-
g_spm_partition_db.partition_count]); \
106-
PARTITION_INIT_STATIC_DATA(part_ptr->static_data, partition, flags, \
107-
id, priority); \
108-
PARTITION_INIT_RUNTIME_DATA(part_ptr->runtime_data, partition); \
109-
PARTITION_INIT_MEMORY_DATA(part_ptr->memory_data, partition); \
110-
++g_spm_partition_db.partition_count; \
82+
#define PARTITION_DECLARE(partition, flag, type, id, priority, part_stack_size) \
83+
do { \
84+
REGION_DECLARE(Image$$, partition, $$Base); \
85+
REGION_DECLARE(Image$$, partition, $$Limit); \
86+
REGION_DECLARE(Image$$, partition, $$RO$$Base); \
87+
REGION_DECLARE(Image$$, partition, $$RO$$Limit); \
88+
REGION_DECLARE(Image$$, partition, _DATA$$RW$$Base); \
89+
REGION_DECLARE(Image$$, partition, _DATA$$RW$$Limit); \
90+
REGION_DECLARE(Image$$, partition, _DATA$$ZI$$Base); \
91+
REGION_DECLARE(Image$$, partition, _DATA$$ZI$$Limit); \
92+
REGION_DECLARE(Image$$, partition, _STACK$$ZI$$Base); \
93+
REGION_DECLARE(Image$$, partition, _STACK$$ZI$$Limit); \
94+
int32_t flags = flag; \
95+
if (tfm_memcmp(type, TFM_PARTITION_TYPE_APP, \
96+
strlen(TFM_PARTITION_TYPE_APP)) == 0) { \
97+
flags |= SPM_PART_FLAG_APP_ROT; \
98+
} else if (tfm_memcmp(type, TFM_PARTITION_TYPE_PSA, \
99+
strlen(TFM_PARTITION_TYPE_PSA)) == 0) { \
100+
flags |= SPM_PART_FLAG_PSA_ROT | SPM_PART_FLAG_APP_ROT; \
101+
} else { \
102+
return SPM_ERR_INVALID_CONFIG; \
103+
} \
104+
struct spm_partition_desc_t *part_ptr; \
105+
if (g_spm_partition_db.partition_count >= SPM_MAX_PARTITIONS) { \
106+
return SPM_ERR_INVALID_CONFIG; \
107+
} \
108+
__attribute__((section(".data.partitions_stacks"))) \
109+
static uint8_t partition##_stack[part_stack_size] __attribute__((aligned(8))); \
110+
part_ptr = &(g_spm_partition_db.partitions[ \
111+
g_spm_partition_db.partition_count]); \
112+
part_ptr->memory_data.stack_bottom = (uint32_t)partition##_stack; \
113+
part_ptr->memory_data.stack_top = part_ptr->memory_data.stack_bottom + part_stack_size; \
114+
PARTITION_INIT_STATIC_DATA(part_ptr->static_data, partition, flags, \
115+
id, priority); \
116+
PARTITION_INIT_RUNTIME_DATA(part_ptr->runtime_data, partition); \
117+
PARTITION_INIT_MEMORY_DATA(part_ptr->memory_data, partition); \
118+
++g_spm_partition_db.partition_count; \
111119
} while (0)
112120

113-
#define PARTITION_ADD_INIT_FUNC(partition, init_func) \
114-
do { \
115-
extern int32_t init_func(void); \
116-
uint32_t partition_idx = get_partition_idx(partition##_ID); \
117-
struct spm_partition_desc_t *part_ptr = \
118-
&(g_spm_partition_db.partitions[partition_idx]); \
119-
part_ptr->static_data.partition_init = init_func; \
121+
#define PARTITION_ADD_INIT_FUNC(partition, init_func) \
122+
do { \
123+
extern int32_t init_func(void); \
124+
uint32_t partition_idx = get_partition_idx(partition##_ID); \
125+
struct spm_partition_desc_t *part_ptr = \
126+
&(g_spm_partition_db.partitions[partition_idx]); \
127+
part_ptr->static_data.partition_init = init_func; \
120128
} while (0)
121129

122-
#define PARTITION_ADD_PERIPHERAL(partition, peripheral) \
123-
do { \
124-
uint32_t partition_idx = get_partition_idx(partition##_ID); \
125-
struct spm_partition_desc_t *part_ptr = \
126-
&(g_spm_partition_db.partitions[partition_idx]); \
127-
part_ptr->platform_data = peripheral; \
130+
#define PARTITION_ADD_PERIPHERAL(partition, peripheral) \
131+
do { \
132+
uint32_t partition_idx = get_partition_idx(partition##_ID); \
133+
struct spm_partition_desc_t *part_ptr = \
134+
&(g_spm_partition_db.partitions[partition_idx]); \
135+
part_ptr->platform_data = peripheral; \
128136
} while (0)
129137

130138
#endif /* __SPM_DB_SETUP_H__ */

0 commit comments

Comments
 (0)