Skip to content

Update for feature_cmsis5 #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Supported devices:
|--------|-----------|-----------|
| `K64F` | `GCC_ARM` | 9600 |

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

## Quickstart

Expand Down
4 changes: 2 additions & 2 deletions source/fun_bag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ static int prn_verify(const void * mem, uint16_t seed, size_t len)
{
size_t i;
uint16_t state = seed;
uint8_t * m = (uint8_t *) mem;
const uint8_t * m = (const uint8_t *) mem;
bool matches = true;

/* Check all of the bytes, even if we find a match sooner. This tests that
* we can read all of the memory (and that it hasn't been securely taken
* over by another box. */
* over by another box). */
for (i = 0; i < len; ++i) {
if (m[i] != (state & 0xFF)) {
matches = false;
Expand Down
4 changes: 0 additions & 4 deletions source/led1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ UVISOR_BOX_HEAPSIZE(3 * 1024);
UVISOR_BOX_MAIN(led1_main, osPriorityNormal, 512);
UVISOR_BOX_CONFIG(box_led1, acl, 512, box_context);

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

static void led1_main(const void *)
{
Expand Down
4 changes: 0 additions & 4 deletions source/led2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ UVISOR_BOX_HEAPSIZE(3 * 1024);
UVISOR_BOX_MAIN(led2_main, osPriorityNormal, 512);
UVISOR_BOX_CONFIG(box_led2, acl, 512, box_context);

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

static void led2_main(const void *)
{
Expand Down
31 changes: 27 additions & 4 deletions source/led3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ UVISOR_BOX_HEAPSIZE(3 * 1024);
UVISOR_BOX_MAIN(led3_main, osPriorityNormal, 1024);
UVISOR_BOX_CONFIG(box_led3, acl, 512, box_context);

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

static void run_3(void)
{
Expand All @@ -40,6 +36,16 @@ static void run_3(void)
}
}

#if (osCMSIS >= 0x20000U)
/* A thin wrapper around run_3 that accepts and ignores a context. This avoid a
* cast, as mbed's Thread and RTX's osThreadContextNew operate on differently
* typed thread functions. */
static void run_3_context(void *)
{
run_3();
}
#endif

static void led3_main(const void *)
{
osStatus status;
Expand All @@ -64,6 +70,22 @@ static void led3_main(const void *)
const uint32_t kB = 1024;
SecureAllocator alloc = secure_allocator_create_with_pages(4 * kB, 1 * kB);
/* Prepare the thread definition structure. */
/* FIXME: Remove the dependency on the CMSIS OS version after mbed OS has
* completed its migration to CMSIS 5 RTX 2. We only need to keep both
* around so that the example will work both before and after the
* migration. */
#if (osCMSIS >= 0x20000U)
osThreadAttr_t thread_attr = {0};
os_thread_t thread_def = {0};
thread_def.stack_size = 512;
/* Allocate the stack inside the page allocator! */
thread_attr.stack_mem = (uint32_t *) secure_malloc(alloc, 512);
thread_def.priority = osPriorityNormal;
thread_attr.cb_size = sizeof(thread_def);
thread_attr.cb_mem = &thread_def;
/* Create a thread with the page allocator as heap. */
osThreadContextNew(run_3_context, NULL, &thread_attr, alloc);
#else
osThreadDef_t thread_def;
thread_def.stacksize = 512;
/* Allocate the stack inside the page allocator! */
Expand All @@ -72,6 +94,7 @@ static void led3_main(const void *)
thread_def.pthread = (void (*)(const void *)) &run_3;
/* Create a thread with the page allocator as heap. */
osThreadContextCreate(&thread_def, NULL, alloc);
#endif

while (1) {
static const size_t size = 20;
Expand Down
20 changes: 20 additions & 0 deletions source/main-hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@
{SPI0, sizeof(*SPI0), UVISOR_TACLDEF_PERIPH}, \
}

#elif defined (TARGET_EFM32GG_STK3700)

#define MAIN_LED LED1
#define SECURE_LED LED2
#define LED_ON true
#define LED_OFF false
#define SECURE_SWITCH SW2
#define SECURE_SWITCH_PULL PullUp

#define MAIN_ACL(acl_list_name) \
static const UvisorBoxAclItem acl_list_name[] = { \
{CMU, sizeof(*CMU), UVISOR_TACLDEF_PERIPH}, \
{MSC, sizeof(*MSC), UVISOR_TACLDEF_PERIPH}, \
{GPIO, sizeof(*GPIO), UVISOR_TACLDEF_PERIPH}, \
{TIMER0, sizeof(*TIMER0), UVISOR_TACLDEF_PERIPH}, \
{UART0, sizeof(*UART0), UVISOR_TACLDEF_PERIPH}, \
{(void *) 0x0FE08000, 0x1000, UVISOR_TACLDEF_PERIPH}, \
{(void *) 0x42000000, 0x2000000, UVISOR_TACLDEF_PERIPH}, \
}

#else /* Target-specific settings */

#error "Unsupported target. Checkout the README.md file for the list of supported targets for this app."
Expand Down
2 changes: 1 addition & 1 deletion test/filters.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"blacklist" : [ {
"platforms" : ["EFM32GG_STK3700", "DISCO_F429ZI"]
"platforms" : ["DISCO_F429ZI"]
}
]
}