39#include "region_defs.h"
49#define LOG_MODULE "TZSecureWorld"
50#define LOG_LEVEL LOG_LEVEL_INFO
52typedef void __attribute__((cmse_nonsecure_call)) (*tz_ns_func_ptr_t)(void);
53#define TZ_NONSECURE_FUNC_PTR_DECLARE(fptr) tz_ns_func_ptr_t fptr
54#define TZ_NONSECURE_FUNC_PTR_CREATE(fptr) \
55 ((tz_ns_func_ptr_t)(cmse_nsfptr_create(fptr)))
60 LOG_INFO(
"Initializing TrustZone\n");
63 LOG_INFO(
"Enabling fault handlers: ");
64 if(enable_fault_handlers() == TFM_PLAT_ERR_SUCCESS) {
65 LOG_INFO_(
"success\n");
67 LOG_INFO_(
"failure\n");
77 non_secure_configuration();
81 void *ptr = (
void *)NS_CODE_START;
82 if(cmse_check_address_range(ptr,
sizeof(ptr), CMSE_NONSECURE) == ptr) {
84 LOG_INFO(
"Non-secure image has correct permissions\n");
86 LOG_ERR(
"Non-secure image has incorrect permissions\n");
91 if(tfm_err != TFM_PLAT_ERR_SUCCESS) {
92 LOG_DBG(
"Interrupt state: 0x%x\n", tfm_err);
95 uintptr_t *vtor_ns = (uintptr_t *)NS_CODE_START;
96 LOG_DBG(
"NS image at %p\n", vtor_ns);
97 LOG_DBG(
"NS main stack pointer at 0x%"PRIxPTR
"\n", vtor_ns[0]);
98 LOG_DBG(
"NS reset vector at 0x%"PRIxPTR
"\n", vtor_ns[1]);
104 LOG_DBG(
"Secure gateway region: %p - %p\n", &__sg_start, &__sg_end);
105 LOG_DBG(
"NSC size %p\n", &__nsc_size);
106 spu_regions_flash_config_non_secure_callable((uint32_t)&__sg_start,
107 (uint32_t)&__sg_end - 1);
109 LOG_DBG(
"__ARM_FEATURE_CMSE = %d\n", __ARM_FEATURE_CMSE);
113 .vtor_ns = (uintptr_t)vtor_ns,
114 .msp_ns = vtor_ns[0],
115 .psp_ns = vtor_ns[0],
116 .control_ns.npriv = 0,
117 .control_ns.spsel = 0,
120 tz_nonsecure_state_setup(&spm_ns_conf);
131 process_num_events_t r;
137 uintptr_t *vtor_ns = setup();
138 if(vtor_ns == NULL) {
139 LOG_ERR(
"Not jumping to the normal world due to initialization error\n");
143 TZ_NONSECURE_FUNC_PTR_DECLARE(reset_ns);
144 reset_ns = TZ_NONSECURE_FUNC_PTR_CREATE(vtor_ns[1]);
145 if(!cmse_is_nsfptr(reset_ns)) {
146 LOG_ERR(
"Invalid non-secure pointer type\n");
150 LOG_INFO(
"Preparing to jump to the normal world\n");
151 spu_periph_config_uarte();
void watchdog_periodic(void)
Writes the WDT clear sequence.
void platform_main_loop(void)
The platform's main loop, if provided.
process_num_events_t process_run(void)
Run the system once - call poll handlers and process one event.
Header file for the logging system.
A convenient struct to include all required Non-Secure state configuration.
nRF5340 target configuration header
tfm_plat_err_t
TFM error codes.