40#include "region_defs.h"
50#define LOG_MODULE "TZSecureWorld"
51#define LOG_LEVEL LOG_LEVEL_INFO
53typedef void __attribute__((cmse_nonsecure_call)) (*tz_ns_func_ptr_t)(void);
54#define TZ_NONSECURE_FUNC_PTR_DECLARE(fptr) tz_ns_func_ptr_t fptr
55#define TZ_NONSECURE_FUNC_PTR_CREATE(fptr) \
56 ((tz_ns_func_ptr_t)(cmse_nsfptr_create(fptr)))
61 LOG_INFO(
"Initializing TrustZone\n");
63 LOG_INFO(
"Enabling fault handlers\n");
64 enable_fault_handlers();
83 non_secure_configuration();
94 void *ptr = (
void *)NS_CODE_START;
95 if(cmse_check_address_range(ptr,
sizeof(ptr), CMSE_NONSECURE) != ptr) {
97 LOG_ERR(
"Non-secure image has incorrect permissions\n");
103 nvic_interrupt_target_state_cfg();
104 nvic_interrupt_enable();
106 uintptr_t *vtor_ns = (uintptr_t *)NS_CODE_START;
107 LOG_DBG(
"NS image at %p\n", vtor_ns);
108 LOG_DBG(
"NS main stack pointer at 0x%"PRIxPTR
"\n", vtor_ns[0]);
109 LOG_DBG(
"NS reset vector at 0x%"PRIxPTR
"\n", vtor_ns[1]);
115 LOG_DBG(
"Secure gateway region: %p - %p\n", &__sg_start, &__sg_end);
116 LOG_DBG(
"NSC size %p\n", &__nsc_size);
117 spu_regions_flash_config_non_secure_callable((uint32_t)&__sg_start,
118 (uint32_t)&__sg_end - 1);
120 LOG_DBG(
"__ARM_FEATURE_CMSE = %d\n", __ARM_FEATURE_CMSE);
124 .vtor_ns = (uintptr_t)vtor_ns,
125 .msp_ns = vtor_ns[0],
126 .psp_ns = vtor_ns[0],
127 .control_ns.npriv = 0,
128 .control_ns.spsel = 0,
131 tz_nonsecure_state_setup(&spm_ns_conf);
140 spu_report_violation();
143 process_num_events_t r;
149 uintptr_t *vtor_ns = setup();
150 if(vtor_ns == NULL) {
151 LOG_ERR(
"Not jumping to the normal world due to initialization error\n");
155 TZ_NONSECURE_FUNC_PTR_DECLARE(reset_ns);
156 reset_ns = TZ_NONSECURE_FUNC_PTR_CREATE(vtor_ns[1]);
157 if(!cmse_is_nsfptr(reset_ns)) {
158 LOG_ERR(
"Invalid non-secure pointer type\n");
163 LOG_INFO(
"Preparing to jump to the normal world\n");
165 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.
void uarte_uninit(void)
Tear down the UARTE driver, releasing the peripheral.
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
UARTE header file for the nRF.