Skip to content

Commit bd907b6

Browse files
authored
Merge pull request #40 from AlessandroA/apps_housekeeping
App housekeeping + Add support for DISCO_F429ZI and EFM32GG_STK3700
2 parents 5eacb59 + 051d8f6 commit bd907b6

File tree

10 files changed

+100
-45
lines changed

10 files changed

+100
-45
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ As usual, all the code/data that is not protected by a secure box ends up in the
2020

2121
Supported devices:
2222

23-
| Target | Toolchain | Baud rate |
24-
|--------|-----------|-----------|
25-
| `K64F` | `GCC_ARM` | 9600 |
23+
| Target | Toolchain | Baud rate |
24+
|-------------------|-----------|-----------|
25+
| `K64F` | `GCC_ARM` | 9600 |
26+
| `DISCO_F429ZI` | `GCC_ARM` | 9600 |
27+
| `EFM32GG_STK3700` | `GCC_ARM` | 9600 |
2628

2729
Latest release: [mbed-os-5.4.x](https://github.com/ARMmbed/mbed-os-example-uvisor/releases/tag/latest). Tested with [mbed-cli v1.0.0](https://github.com/ARMmbed/mbed-cli/releases/tag/1.0.0).
2830

mbed-os.lib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
https://github.com/ARMmbed/mbed-os/#fc1836545dcc2fc86f03b01292b62bf2089f67c3
1+
https://github.com/ARMmbed/mbed-os/#92fbf2a9b3988d430482fc25a6077f2462e2a634

source/client_a.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,11 @@ static void client_a_main(const void *);
3333
* This box has a smaller interrupt and main thread stack sizes as we do nothing
3434
* special in them. */
3535
UVISOR_BOX_NAMESPACE("client_a");
36-
UVISOR_BOX_HEAPSIZE(3072);
36+
UVISOR_BOX_HEAPSIZE(4096);
3737
UVISOR_BOX_MAIN(client_a_main, osPriorityNormal, 768);
3838
UVISOR_BOX_CONFIG(secure_number_client_a, acl, 512, box_context);
3939

40-
/* FIXME: The guard is needed for backwards-compatibility reasons. Remove it
41-
* when mbed OS is updated. */
42-
#ifdef __uvisor_ctx
4340
#define uvisor_ctx ((box_context *) __uvisor_ctx)
44-
#endif
4541

4642
static uint32_t get_a_number()
4743
{
@@ -71,7 +67,7 @@ static void box_async_runner(void)
7167
}
7268
}
7369

74-
Thread::wait(5000);
70+
Thread::wait(7000);
7571
}
7672
}
7773

@@ -88,6 +84,8 @@ static void box_sync_runner(void)
8884

8985
static void client_a_main(const void *)
9086
{
87+
Thread::wait(1000);
88+
9189
/* Create new threads. */
9290
/* Note: The stack must be at least 1kB since threads will use printf. */
9391
Thread sync(osPriorityNormal, 1024, NULL);

source/client_b.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ UVISOR_BOX_HEAPSIZE(3072);
3838
UVISOR_BOX_MAIN(client_b_main, osPriorityNormal, 1024);
3939
UVISOR_BOX_CONFIG(secure_number_client_b, acl, 512, box_context);
4040

41-
/* FIXME: The guard is needed for backwards-compatibility reasons. Remove it
42-
* when mbed OS is updated. */
43-
#ifdef __uvisor_ctx
4441
#define uvisor_ctx ((box_context *) __uvisor_ctx)
45-
#endif
4642

4743
static uint32_t get_a_number()
4844
{
@@ -52,6 +48,8 @@ static uint32_t get_a_number()
5248

5349
static void client_b_main(const void *)
5450
{
51+
Thread::wait(2000);
52+
5553
/* The entire box code runs in its main thread. */
5654
while (1) {
5755
uvisor_rpc_result_t result;
@@ -76,6 +74,6 @@ static void client_b_main(const void *)
7674
number = secure_number_get_number();
7775
shared_pc.printf("client_b: Attempt to read : 0x%08X (granted)\r\n", (unsigned int) number);
7876

79-
Thread::wait(3000);
77+
Thread::wait(7000);
8078
}
8179
}

source/main-hw.h

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ extern Serial shared_pc;
2525

2626
#if defined(TARGET_K64F)
2727

28-
#define LED_ON false
29-
#define LED_OFF true
28+
#define MAIN_LED LED1
29+
#define SECURE_LED LED2
30+
#define LED_ON false
31+
#define LED_OFF true
32+
#define SECURE_SWITCH SW2
33+
#define SECURE_SWITCH_PULL PullUp
34+
#define SHARED_SERIAL_BAUD 9600
3035

3136
#define MAIN_ACL(acl_list_name) \
3237
static const UvisorBoxAclItem acl_list_name[] = { \
@@ -47,6 +52,58 @@ extern Serial shared_pc;
4752
{SPI0, sizeof(*SPI0), UVISOR_TACLDEF_PERIPH}, \
4853
}
4954

55+
#elif defined(TARGET_EFM32GG_STK3700)
56+
57+
#define MAIN_LED LED1
58+
#define SECURE_LED LED2
59+
#define LED_ON true
60+
#define LED_OFF false
61+
#define SECURE_SWITCH SW0
62+
#define SECURE_SWITCH_PULL PullUp
63+
#define SHARED_SERIAL_BAUD 115200
64+
65+
#define MAIN_ACL(acl_list_name) \
66+
static const UvisorBoxAclItem acl_list_name[] = { \
67+
{CMU, sizeof(*CMU), UVISOR_TACLDEF_PERIPH}, \
68+
{MSC, sizeof(*MSC), UVISOR_TACLDEF_PERIPH}, \
69+
{GPIO, sizeof(*GPIO), UVISOR_TACLDEF_PERIPH}, \
70+
{TIMER0, sizeof(*TIMER0), UVISOR_TACLDEF_PERIPH}, \
71+
{UART0, sizeof(*UART0), UVISOR_TACLDEF_PERIPH}, \
72+
{(void *) 0x0FE08000, 0x1000, UVISOR_TACLDEF_PERIPH}, \
73+
{(void *) 0x42000000, 0x2000000, UVISOR_TACLDEF_PERIPH}, \
74+
}
75+
76+
#elif defined(TARGET_DISCO_F429ZI)
77+
78+
#define MAIN_LED LED1
79+
#define SECURE_LED LED2
80+
#define LED_ON true
81+
#define LED_OFF false
82+
#define SECURE_SWITCH USER_BUTTON
83+
#define SECURE_SWITCH_PULL PullDown
84+
#define SHARED_SERIAL_BAUD 9600
85+
86+
#define MAIN_ACL(acl_list_name) \
87+
static const UvisorBoxAclItem acl_list_name[] = { \
88+
{GPIOA, sizeof(*GPIOA), UVISOR_TACLDEF_PERIPH}, \
89+
{GPIOB, sizeof(*GPIOB), UVISOR_TACLDEF_PERIPH}, \
90+
{GPIOC, sizeof(*GPIOC), UVISOR_TACLDEF_PERIPH}, \
91+
{GPIOD, sizeof(*GPIOD), UVISOR_TACLDEF_PERIPH}, \
92+
{GPIOE, sizeof(*GPIOE), UVISOR_TACLDEF_PERIPH}, \
93+
{RTC, sizeof(*RTC), UVISOR_TACLDEF_PERIPH}, \
94+
{TIM5, sizeof(*TIM5), UVISOR_TACLDEF_PERIPH}, \
95+
{USART1, sizeof(*USART1), UVISOR_TACLDEF_PERIPH}, \
96+
{I2C1, sizeof(*I2C1), UVISOR_TACLDEF_PERIPH}, \
97+
{SPI1, sizeof(*SPI1), UVISOR_TACLDEF_PERIPH}, \
98+
{RCC, sizeof(*RCC), UVISOR_TACLDEF_PERIPH}, \
99+
{FLASH, sizeof(*FLASH), UVISOR_TACLDEF_PERIPH}, \
100+
{PWR, sizeof(*PWR), UVISOR_TACLDEF_PERIPH}, \
101+
{EXTI, sizeof(*EXTI), UVISOR_TACLDEF_PERIPH}, \
102+
{GPIOG, sizeof(*GPIOG), UVISOR_TACLDEF_PERIPH}, \
103+
{SYSCFG, sizeof(*SYSCFG), UVISOR_TACLDEF_PERIPH}, \
104+
{(void *) 0x42000000, 0x01000000, UVISOR_TACLDEF_PERIPH}, \
105+
}
106+
50107
#else /* Target-specific settings */
51108

52109
#error "Unsupported target. Checkout the README.md file for the list of supported targets for this app."

source/main.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,19 @@
2626
MAIN_ACL(g_main_acl);
2727
/* Enable uVisor. */
2828
UVISOR_SET_MODE_ACL(UVISOR_ENABLED, g_main_acl);
29-
UVISOR_SET_PAGE_HEAP(8 * 1024, 5);
29+
UVISOR_SET_PAGE_HEAP(1 * 1024, 1);
30+
31+
/* Targets with an ARMv7-M MPU needs this space adjustment to prevent a runtime
32+
* memory overflow error. The code below has been output directly by uVisor. */
33+
#if defined(TARGET_EFM32GG_STK3700) || defined(TARGET_DISCO_F429ZI)
34+
uint8_t __attribute__((section(".keep.uvisor.bss.boxes"), aligned(32))) __boxes_overhead[8064];
35+
#endif
3036

3137
DigitalOut led_red(LED1);
3238
DigitalOut led_green(LED2);
3339
DigitalOut led_blue(LED3);
3440

35-
Serial shared_pc(USBTX, USBRX);
41+
Serial shared_pc(USBTX, USBRX, SHARED_SERIAL_BAUD);
3642

3743
static uint32_t get_a_number()
3844
{
@@ -62,7 +68,7 @@ static void main_async_runner(void)
6268
}
6369
}
6470

65-
Thread::wait(13000);
71+
Thread::wait(7000);
6672
}
6773
}
6874

@@ -73,7 +79,7 @@ static void main_sync_runner(void)
7379
const uint32_t number = secure_number_get_number();
7480
shared_pc.printf("public : Attempt to read : 0x%08X (granted)\r\n", (unsigned int) number);
7581

76-
Thread::wait(11000);
82+
Thread::wait(7000);
7783
}
7884
}
7985

source/secure_number.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,10 @@ static int set_number(uint32_t number);
3636
/* Box configuration */
3737
UVISOR_BOX_NAMESPACE(NULL);
3838
UVISOR_BOX_HEAPSIZE(3072);
39-
UVISOR_BOX_MAIN(number_store_main, osPriorityNormal, UVISOR_BOX_STACK_SIZE);
40-
UVISOR_BOX_CONFIG(box_number_store, acl, UVISOR_BOX_STACK_SIZE, box_context);
39+
UVISOR_BOX_MAIN(number_store_main, osPriorityNormal, 1024);
40+
UVISOR_BOX_CONFIG(box_number_store, acl, 512, box_context);
4141

42-
/* FIXME: The guard is needed for backwards-compatibility reasons. Remove it
43-
* when mbed OS is updated. */
44-
#ifdef __uvisor_ctx
4542
#define uvisor_ctx ((box_context *) __uvisor_ctx)
46-
#endif
4743

4844
/* Gateways */
4945
UVISOR_BOX_RPC_GATEWAY_SYNC (box_number_store, secure_number_get_number, get_number, uint32_t, void);

source/secure_number.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
#ifndef SECURE_NUMBER_H
18-
#define SECURE_NUMBER_H
17+
#ifndef __SECURE_NUMBER_H__
18+
#define __SECURE_NUMBER_H__
1919

2020
#include "uvisor-lib/uvisor-lib.h"
2121
#include <stdint.h>
2222

23-
2423
UVISOR_EXTERN uint32_t (*secure_number_get_number)(void);
2524

2625
UVISOR_EXTERN uvisor_rpc_result_t (*secure_number_set_number)(uint32_t number);
2726

28-
#endif /* SECURE_NUMBER_H */
27+
#endif /* __SECURE_NUMBER_H__ */

test/filters.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"blacklist" : [ {
3-
"platforms" : ["EFM32GG_STK3700", "DISCO_F429ZI"]
3+
"platforms" : []
44
}
55
]
66
}

test/log.txt

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
2-
***** uVisor secure number store example *****
3-
vault : Only client_a can write into the vault
4-
vault : All clients can read the vault
5-
client_b: Attempt to write 0xFFFFFED4 (denied)
6-
client_a: Attempt to read : 0x00000000 (granted)
7-
client_a: Attempt to write 0xFFFFFE0C (granted)
8-
public : Attempt to read : 0xFFFFFE0C (granted)
9-
public : Attempt to write 0x00000019 (denied)
10-
client_b: Attempt to read : 0xFFFFFE0C (granted)
11-
client_a: Attempt to read : 0xFFFFFE0C (granted)
12-
client_a: Attempt to write 0xFFFFFC18 (granted)
13-
public : Attempt to read : 0xFFFFFC18 (granted)
1+
2+
***** uVisor secure number store example *****
3+
vault : Only client_a can write into the vault
4+
vault : All clients can read the vault
5+
public : Attempt to read : 0x00000000 (granted)
6+
public : Attempt to write 0x00000019 (denied)
7+
client_a: Attempt to read : 0x00000000 (granted)
8+
client_a: Attempt to write 0xFFFFFE0C (granted)
9+
client_b: Attempt to write 0xFFFFFED4 (denied)
10+
public : Attempt to read : 0xFFFFFE0C (granted)
11+
client_b: Attempt to read : 0xFFFFFE0C (granted)
12+
public : Attempt to write 0xFFFFFE89 (denied)

0 commit comments

Comments
 (0)