Build: IAR support
- This patch contains IAR specific changes to a few source files,
mostly #pragmas to allow calling external functions from inline.
- Startup code and linker scripts
- cmake files
- cmsis file for the IAR compiler
Other targets are added in later commits
There are still lots of warnings generated for non-standard C, which
I plan to address in later updates
- Cleaned out some dead definitions in the common linker script in
preparation for psoc64 integration.
- Made sure that .rodata from tfm_its_secure_api.o is placed in
TFM_UNPRIV_CODE, which otherwised caused a memory management fault
in test TFM_ITS_TEST_2023 when compiled without optimization.
- Added dummy initializers to tfm_secure_irq_handlers.inc.template to
avoid illegal empty arrays.
- Reworked the iovec_args_t struct handling in tfm_func_api.c, which
was causing runtime errors when compiled with optimization.
According to the compiler developers the old implemetation is
illegal, you are not allowed to use the address of a scalar as an
address outside of that scalar.
- Added conditional around ".syntax unified" in tfm_nspm_ipc.c.
- Added "template" attribute for the IAR linker script in
tfm_generated_file_list.yaml.
- Cleaned up some indentation and tab/space issues
Change-Id: I8599d461f62194bc734e472a28d7111ba3b5046a
Signed-off-by: TTornblom <thomas.tornblom@iar.com>
diff --git a/secure_fw/core/arch/tfm_arch_v8m_main.c b/secure_fw/core/arch/tfm_arch_v8m_main.c
index bf257e2..5b030cb 100644
--- a/secure_fw/core/arch/tfm_arch_v8m_main.c
+++ b/secure_fw/core/arch/tfm_arch_v8m_main.c
@@ -61,6 +61,10 @@
* thread SP/SP_LIMIT. R2 holds dummy data due to stack operation is 8 bytes
* aligned.
*/
+#if defined(__ICCARM__)
+#pragma required = tfm_pendsv_do_schedule
+#endif
+
__attribute__((naked)) void PendSV_Handler(void)
{
__ASM volatile(
@@ -181,6 +185,11 @@
}
}
+#if defined(__ICCARM__)
+uint32_t tfm_core_svc_handler(uint32_t *svc_args, uint32_t exc_return);
+#pragma required = tfm_core_svc_handler
+#endif
+
__attribute__((naked)) void SVC_Handler(void)
{
__ASM volatile(
@@ -228,7 +237,6 @@
__attribute__((naked, noinline)) void tfm_arch_clear_fp_status(void)
{
__ASM volatile(
- ".syntax unified \n"
"mrs r0, control \n"
"bics r0, r0, #4 \n"
"msr control, r0 \n"
diff --git a/secure_fw/core/ipc/tfm_secure_irq_handlers_ipc.inc b/secure_fw/core/ipc/tfm_secure_irq_handlers_ipc.inc
index 6b0cbf0..d44f7c6 100644
--- a/secure_fw/core/ipc/tfm_secure_irq_handlers_ipc.inc
+++ b/secure_fw/core/ipc/tfm_secure_irq_handlers_ipc.inc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, Arm Limited. All rights reserved.
+ * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -29,10 +29,11 @@
#ifdef TFM_ENABLE_IRQ_TEST
{ TFM_IRQ_TEST_1, SPM_CORE_IRQ_TEST_1_SIGNAL_TIMER_0_IRQ, TFM_TIMER0_IRQ, 64 },
#endif /* TFM_ENABLE_IRQ_TEST */
+ {0, 0, 0, 0} /* add dummy element to avoid non-standard empty array */
};
-const size_t tfm_core_irq_signals_count = sizeof(tfm_core_irq_signals) /
- sizeof(*tfm_core_irq_signals);
+const size_t tfm_core_irq_signals_count = (sizeof(tfm_core_irq_signals) /
+ sizeof(*tfm_core_irq_signals)) - 1; /* adjust for the dummy element */
/* Definitions of privileged IRQ handlers (if any) */
#ifdef TFM_ENABLE_IRQ_TEST
diff --git a/secure_fw/core/ipc/tfm_secure_irq_handlers_ipc.inc.template b/secure_fw/core/ipc/tfm_secure_irq_handlers_ipc.inc.template
index 0bf4415..5e9d44c 100644
--- a/secure_fw/core/ipc/tfm_secure_irq_handlers_ipc.inc.template
+++ b/secure_fw/core/ipc/tfm_secure_irq_handlers_ipc.inc.template
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, Arm Limited. All rights reserved.
+ * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -41,10 +41,11 @@
{% endif %}
{% endif %}
{% endfor %}
+ {0, 0, 0, 0} /* add dummy element to avoid non-standard empty array */
};
-const size_t tfm_core_irq_signals_count = sizeof(tfm_core_irq_signals) /
- sizeof(*tfm_core_irq_signals);
+const size_t tfm_core_irq_signals_count = (sizeof(tfm_core_irq_signals) /
+ sizeof(*tfm_core_irq_signals)) - 1; /* adjust for the dummy element */
/* Definitions of privileged IRQ handlers (if any) */
{% for manifest in manifests %}
diff --git a/secure_fw/core/tfm_nspm_ipc.c b/secure_fw/core/tfm_nspm_ipc.c
index 255ef25..2633e1b 100644
--- a/secure_fw/core/tfm_nspm_ipc.c
+++ b/secure_fw/core/tfm_nspm_ipc.c
@@ -89,7 +89,9 @@
void tfm_nspm_thread_entry(void)
{
__ASM volatile(
+#ifndef __ICCARM__
".syntax unified \n"
+#endif
"mov r4, r0 \n"
"movs r2, #1 \n" /* Clear Bit[0] for S to NS transition */
"bics r4, r2 \n"
diff --git a/secure_fw/core/tfm_secure_irq_handlers.inc b/secure_fw/core/tfm_secure_irq_handlers.inc
index 76116fe..0793403 100644
--- a/secure_fw/core/tfm_secure_irq_handlers.inc
+++ b/secure_fw/core/tfm_secure_irq_handlers.inc
@@ -29,10 +29,11 @@
#ifdef TFM_ENABLE_IRQ_TEST
{ TFM_IRQ_TEST_1, SPM_CORE_IRQ_TEST_1_SIGNAL_TIMER_0_IRQ, TFM_TIMER0_IRQ, 64 },
#endif /* TFM_ENABLE_IRQ_TEST */
+ {0, 0, (IRQn_Type) 0, 0} /* add dummy element to avoid non-standard empty array */
};
-const size_t tfm_core_irq_signals_count = sizeof(tfm_core_irq_signals) /
- sizeof(*tfm_core_irq_signals);
+const size_t tfm_core_irq_signals_count = (sizeof(tfm_core_irq_signals) /
+ sizeof(*tfm_core_irq_signals)) - 1; /* adjust for the dummy element */
extern void priv_irq_handler_main(uint32_t partition_id,
uint32_t unpriv_handler,
diff --git a/secure_fw/core/tfm_secure_irq_handlers.inc.template b/secure_fw/core/tfm_secure_irq_handlers.inc.template
index 872c4b0..3fabdc0 100644
--- a/secure_fw/core/tfm_secure_irq_handlers.inc.template
+++ b/secure_fw/core/tfm_secure_irq_handlers.inc.template
@@ -41,10 +41,11 @@
{% endif %}
{% endif %}
{% endfor %}
+ {0, 0, (IRQn_Type) 0, 0} /* add dummy element to avoid non-standard empty array */
};
-const size_t tfm_core_irq_signals_count = sizeof(tfm_core_irq_signals) /
- sizeof(*tfm_core_irq_signals);
+const size_t tfm_core_irq_signals_count = (sizeof(tfm_core_irq_signals) /
+ sizeof(*tfm_core_irq_signals)) - 1; /* adjust for the dummy element */
extern void priv_irq_handler_main(uint32_t partition_id,
uint32_t unpriv_handler,
diff --git a/secure_fw/spm/spm_func.c b/secure_fw/spm/spm_func.c
index ca11814..6b9c46b 100644
--- a/secure_fw/spm/spm_func.c
+++ b/secure_fw/spm/spm_func.c
@@ -302,9 +302,7 @@
static struct iovec_args_t *get_iovec_args_stack_address(uint32_t partition_idx)
{
/* Save the iovecs on the common stack. */
- return (struct iovec_args_t *)((uint8_t *)®ION_NAME(Image$$,
- TFM_SECURE_STACK, $$ZI$$Limit) -
- sizeof(struct iovec_args_t));
+ return ®ION_NAME(Image$$, TFM_SECURE_STACK, $$ZI$$Limit)[-1];
}
static enum tfm_status_e tfm_start_partition(
@@ -321,7 +319,6 @@
uint32_t partition_psp, partition_psplim;
uint32_t partition_state;
uint32_t caller_partition_state;
- uint32_t partition_flags;
struct tfm_state_context_t *svc_ctx;
uint32_t caller_partition_id;
int32_t client_id;
@@ -344,7 +341,6 @@
caller_part_data = tfm_spm_partition_get_runtime_data(caller_partition_idx);
partition_state = curr_part_data->partition_state;
caller_partition_state = caller_part_data->partition_state;
- partition_flags = tfm_spm_partition_get_flags(partition_idx);
caller_partition_id = tfm_spm_partition_get_partition_id(
caller_partition_idx);
@@ -361,8 +357,7 @@
* as stack by the partitions starts at a lower address
*/
partition_psp =
- (uint32_t)®ION_NAME(Image$$, TFM_SECURE_STACK, $$ZI$$Limit)-
- sizeof(struct iovec_args_t);
+ (uint32_t)®ION_NAME(Image$$, TFM_SECURE_STACK, $$ZI$$Limit)[-1];
partition_psplim =
(uint32_t)®ION_NAME(Image$$, TFM_SECURE_STACK, $$ZI$$Base);
@@ -472,7 +467,6 @@
uint32_t current_partition_idx =
tfm_spm_partition_get_running_partition_idx();
const struct spm_partition_runtime_data_t *curr_part_data, *ret_part_data;
- uint32_t current_partition_flags;
uint32_t return_partition_idx;
uint32_t return_partition_flags;
uint32_t psp = __get_PSP();
@@ -494,8 +488,6 @@
ret_part_data = tfm_spm_partition_get_runtime_data(return_partition_idx);
return_partition_flags = tfm_spm_partition_get_flags(return_partition_idx);
- current_partition_flags = tfm_spm_partition_get_flags(
- current_partition_idx);
tfm_secure_lock--;
@@ -509,14 +501,12 @@
(struct tfm_state_context_t *)ret_part_data->stack_ptr);
*excReturn = ret_part_data->lr;
__set_PSP(ret_part_data->stack_ptr);
- REGION_DECLARE(Image$$, ARM_LIB_STACK, $$ZI$$Base)[];
+ REGION_DECLARE_T(Image$$, ARM_LIB_STACK, $$ZI$$Base, uint32_t)[];
uint32_t psp_stack_bottom =
(uint32_t)REGION_NAME(Image$$, ARM_LIB_STACK, $$ZI$$Base);
tfm_arch_set_psplim(psp_stack_bottom);
- iovec_args = (struct iovec_args_t *)
- ((uint8_t *)®ION_NAME(Image$$, TFM_SECURE_STACK, $$ZI$$Limit) -
- sizeof(struct iovec_args_t));
+ iovec_args = ®ION_NAME(Image$$, TFM_SECURE_STACK, $$ZI$$Limit)[-1];
for (i = 0; i < curr_part_data->iovec_args.out_len; ++i) {
curr_part_data->orig_outvec[i].len = iovec_args->out_vec[i].len;