Skip to content

Commit 5a0acd5

Browse files
Wayne Renioannisg
authored andcommitted
samples: add sample to show how ARC TEE works
* this is a simple sample to show how secure applicaiton and non-secure application work together. More details are in README.rst Signed-off-by: Wayne Ren <[email protected]>
1 parent 1e2d422 commit 5a0acd5

File tree

5 files changed

+201
-0
lines changed

5 files changed

+201
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.8.2)
4+
5+
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
6+
project(arc_secure_services)
7+
8+
target_sources(app PRIVATE src/main.c)
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
.. _arc_secure_service:
2+
3+
ARC Secure Service
4+
##################
5+
6+
Overview
7+
********
8+
9+
This sample implements a simple secure service based on ARC SecureShield to
10+
demonstrate how a secure zephyr application runs together with a normal
11+
Zephyr application.
12+
13+
In this sample:
14+
15+
* Secure application will be in the secure memory space defined in
16+
``arc_mpu_regions.c``. Half of RAM and ROM is allocated to secure world,
17+
the other half is allocated to normal world.
18+
19+
* Memory not allocated to the secure application is allocated to
20+
the normal application.
21+
22+
* By default, all the peripheral space is normal mode accessible, i.e.,
23+
the peripherals are shared between normal mode and secure mode. If some
24+
peripherals are required by secure world, it can be done by adding static
25+
mpu entry in ``arc_mpu_regions.c``.
26+
27+
* The interrupts of two internal timers are configure as normal interrupts,
28+
so the normal zephyr's kernel tick can work correctly.
29+
30+
* Secure interrupts priority > secure threads priority > normal interrupts
31+
priority > normal threads priority.
32+
33+
34+
Requirements
35+
************
36+
37+
To use this sample, ARC processor should be equipped with ARC SecureShield. In
38+
Zephyr, the following board configurations are supported:
39+
40+
* em_starterkit_em7d
41+
* secure application: em_starterkit_em7d_secure
42+
* normal application: em_starterkit_em7d_normal
43+
* nsim_sem
44+
* secure application: nsim_sem
45+
* normal application: nsim_sem_normal
46+
47+
Building and Running
48+
********************
49+
50+
Building
51+
========
52+
53+
Secure application
54+
^^^^^^^^^^^^^^^^^^
55+
56+
First, you should build the secure application.
57+
58+
.. zephyr-app-commands::
59+
:zephyr-app: samples/boards/arc_secure_services
60+
:board: em_starterkit_em7d_secure nsim_sem
61+
:goals: build
62+
:compact:
63+
64+
Normal application
65+
^^^^^^^^^^^^^^^^^^
66+
67+
Currently, in normal application, MPU is not accessible, so no user space and
68+
mpu-based stack checking.
69+
70+
Here,take :ref:'dining-philosophers-sample' as an example for normal
71+
application.
72+
73+
.. zephyr-app-commands::
74+
:zephyr-app: samples/philosophers
75+
:board: em_starterkit_em7d_normal nsim_sem_normal
76+
:goals: build
77+
:compact:
78+
79+
Running
80+
=======
81+
82+
* Run using the bootloader
83+
84+
The bootloader should load the secure and normal application into the correct place,
85+
then jump to the entry of the secure application. The entry of normal application
86+
is hardcoded in secure application. Secure application will boot normal application.
87+
88+
* Run using the debugger (recommended)
89+
90+
Use the gdb debugger to load and run the two applications.
91+
92+
For em starter kit, run the following commands
93+
94+
.. code-block:: console
95+
96+
# load secure application first
97+
$ cd samples/boards/arc_secure_services/build
98+
$ west debug
99+
# load normal application
100+
$ monitor load_image ../../../philosophers/build/zepher/zephyr.elf
101+
$ c
102+
103+
For nsim sem, you need two consoles: one for application output, and one for
104+
debugger.
105+
106+
In the console for output:
107+
108+
.. code-block:: console
109+
110+
# open debug server
111+
$ cd samples/boards/arc_secure_services/build
112+
$ west debugserver
113+
114+
In the console for debugger:
115+
116+
.. code-block:: console
117+
118+
# open debug server
119+
$ cd samples/boards/arc_secure_services/build
120+
$ arc-elf32-gdb zephyr/zephyr.elf
121+
$ target remote :3333
122+
# load normal application
123+
$ load ../../../philosophers/build/zepher/zephyr.elf
124+
# load secure application
125+
$ load
126+
$ c

samples/boards/arc_secure_services/prj.conf

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
sample:
2+
description: Sample application to verify the secure monitor for
3+
Designware ARC SecureShiled.
4+
name: Designware ARC Secure monitor
5+
tests:
6+
test:
7+
platform_whitelist: nsim_sem em_starterkit_em7d_secure
8+
tags: secure
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2018 Synopsys.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr.h>
8+
#include <misc/printk.h>
9+
#include <soc.h>
10+
11+
#if defined(CONFIG_SOC_NSIM_SEM)
12+
#define NORMAL_FIRMWARE_ENTRY 0x40000
13+
#elif defined(CONFIG_SOC_EMSK)
14+
#define NORMAL_FIRMWARE_ENTRY 0x20000
15+
#endif
16+
17+
18+
#define STACKSIZE 1024
19+
#define PRIORITY 7
20+
#define SLEEPTIME 1000
21+
22+
23+
void threadA(void *dummy1, void *dummy2, void *dummy3)
24+
{
25+
ARG_UNUSED(dummy1);
26+
ARG_UNUSED(dummy2);
27+
ARG_UNUSED(dummy3);
28+
29+
30+
printk("Go to normal application\n");
31+
32+
arc_go_to_normal(*((u32_t *)(NORMAL_FIRMWARE_ENTRY)));
33+
34+
printk("should not come here\n");
35+
36+
}
37+
38+
K_THREAD_DEFINE(thread_a, STACKSIZE, threadA, NULL, NULL, NULL,
39+
PRIORITY, 0, K_NO_WAIT);
40+
41+
42+
void main(void)
43+
{
44+
/* necessary configuration before go to normal */
45+
s32_t i = 0;
46+
47+
/* allocate timer 0 and timer1 to normal mode */
48+
z_arc_v2_irq_uinit_secure_set(IRQ_TIMER0, 0);
49+
z_arc_v2_irq_uinit_secure_set(IRQ_TIMER1, 0);
50+
51+
/* disable the secure interrupts for debug purpose*/
52+
/* _arc_v2_irq_unit_int_disable(IRQ_S_TIMER0); */
53+
54+
while (1) {
55+
printk("I am the %s thread in secure world: %d\n",
56+
__func__, i++);
57+
k_sleep(SLEEPTIME);
58+
}
59+
}

0 commit comments

Comments
 (0)