Contiki-NG
Loading...
Searching...
No Matches
tz-api.h
1/*
2 * Copyright (c) 2023, RISE Research Institutes of Sweden
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * 3. Neither the name of the copyright holder nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31 * OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/*
35 * \file
36 * TrustZone API for communication between zones.
37 * \author
38 * Niclas Finne <niclas.finne@ri.se>
39 * Nicolas Tsiftes <nicolas.tsiftes@ri.se>
40 */
41
42/** \addtogroup arm
43 * @{
44 */
45
46/**
47 * \defgroup trustzone TrustZone for Arm Cortex-M
48 *
49 * This subsystem implements TrustZone support for Arm Cortex-M
50 * processors. The archtiecture is based on dual Contiki-NG firmwares:
51 * the secure world contains an instance of Contiki-NG with reduced
52 * functionality, and the normal world contains an instance with
53 * regular functionality. When programming an IoT device, the hex
54 * files with the two firmwares are merged into a single hex file,
55 * which is flashed to the device.
56 *
57 * Both worlds can access core system functionality such as processes,
58 * timers, and library functions. The normal world is expected to
59 * contain applications and networking functionality. By contrast, the
60 * secure world will contain secret information and functionality for
61 * monitoring the normal world. Hardware peripherals can be configured
62 * to be accessible in either of the worlds.
63 *
64 * Currently, the only supported Contiki-NG platform is the nRF5340
65 * development kit, which is equipped with two different Arm
66 * Cortex-M33 processors.
67 *
68 * @{
69 */
70
71#ifndef TZ_API_H
72#define TZ_API_H
73
74#include <stdbool.h>
75#include <stdlib.h>
76
77#ifdef TRUSTZONE_SECURE
78
79/**
80 * The CC_TRUSTZONE_SECURE_CALL marks a function in the secure world
81 * as being possible to call from the normal world. When executing
82 * such a function, the processor will be in secure state.
83 */
84#define CC_TRUSTZONE_SECURE_CALL __attribute__((cmse_nonsecure_entry))
85
86/**
87 * The CC_TRUSTZONE_NONSECURE_CALL marks a function in the normal
88 * world as being possible to call from the secure world. When
89 * executing such a function, the processor will be in non-secure
90 * state.
91 */
92#define CC_TRUSTZONE_NONSECURE_CALL __attribute__((cmse_nonsecure_call))
93
94/**
95 * The trustzone_init_event is posted to all automatically started
96 * processes when both the secure world and the normal world have
97 * finished their initialization.
98 *
99 * This allows user processes to wait until they can begin their
100 * execution of tasks that may depend on TrustZone-specific
101 * functionality.
102 */
103extern process_event_t trustzone_init_event;
104
105/**
106 * Linker symbols.
107 */
108
109/* End of the text region. */
110extern uint32_t __etext;
111
112/* Start of the Secure Gateway region. */
113extern uint32_t __sg_start;
114
115/* End of the Secure Gateway region. */
116extern uint32_t __sg_end;
117
118/* Secure Gateway region size, aligned to the next 32 byte boundary. */
119extern uint32_t __nsc_size;
120/******************************************************************************/
121
122#else /* TRUSTZONE_SECURE */
123
124#define CC_TRUSTZONE_NONSECURE_CALL
125
126#endif /* TRUSTZONE_SECURE */
127
128typedef bool (*ns_poll_t)(void) CC_TRUSTZONE_NONSECURE_CALL;
129
130struct tz_api {
131 ns_poll_t request_poll;
132};
133
134/**
135 * \brief Initialize the TrustZone API.
136 * \param apip A pointer to a tz_api structure.
137 * \retval false Error (apip pointed to invalid memory,
138 * or the API has been initialized already.)
139 * \retval true Success.
140 */
141bool tz_api_init(struct tz_api *apip);
142
143/**
144 * \brief Poll the secure world and process all events in the queue.
145 * \retval true If the secure world has more events to process.
146 * \retval false If the secure world has no more events to process.
147 *
148 */
149bool tz_api_poll(void);
150
151/**
152 * \brief Print the specified message via the secure world.
153 *
154 */
155void tz_api_println(const char *text);
156
157/**
158 * \brief Request poll from normal world.
159 *
160 * Only called from secure world.
161 */
163
164#endif /* !TZ_API_H */
165/** @} */
166/** @} */
void tz_api_println(const char *text)
Print the specified message via the secure world.
Definition tz-api.c:118
bool tz_api_request_poll_from_ns(void)
Request poll from normal world.
Definition tz-api.c:124
bool tz_api_init(struct tz_api *apip)
Initialize the TrustZone API.
Definition tz-api.c:59
bool tz_api_poll(void)
Poll the secure world and process all events in the queue.
Definition tz-api.c:90