Skip to content

Commit 123d55d

Browse files
authored
Merge pull request #1753 from meriac/master
Add initial uVisor port
2 parents 9714a0e + 08ba670 commit 123d55d

File tree

60 files changed

+3486
-16
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+3486
-16
lines changed

features/FEATURE_UVISOR/AUTHORS.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
519 Milosch Meriac
2+
420 Alessandro Angelino
3+
16 Niklas Hauser
4+
15 Jaeden Amero
5+
3 Hugo Vincent
6+
3 JaredCJR
7+
3 Jim Huang
8+
2 tonyyanxuan
9+
1 Aksel Skauge Mellbye
10+
1 Irit Arkin
11+
1 Nathan Chong
12+
1 ccli8

features/FEATURE_UVISOR/VERSION.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v0.9.14-alpha
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
###########################################################################
2+
#
3+
# Copyright (c) 2013-2016, ARM Limited, All Rights Reserved
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
7+
# not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
###########################################################################
19+
20+
# Toolchain
21+
PREFIX:=arm-none-eabi-
22+
GDB:=$(PREFIX)gdb
23+
OBJDUMP:=$(PREFIX)objdump
24+
25+
# Translate between uVisor namespace and mbed namespace
26+
TARGET_TRANSLATION:=MCU_K64F.kinetis EFM32.efm32 STM32F4.stm32
27+
TARGET_PREFIX:=../
28+
TARGET_SUPPORTED:=$(TARGET_PREFIX)targets/TARGET_UVISOR_SUPPORTED
29+
TARGET_UNSUPPORTED:=$(TARGET_PREFIX)targets/TARGET_UVISOR_UNSUPPORTED
30+
TARGET_INC:=$(TARGET_PREFIX)includes/uvisor/api
31+
TARGET_LIB_SRC:=$(TARGET_PREFIX)source
32+
TARGET_LIB_INC:=$(TARGET_PREFIX)includes/uvisor-lib
33+
34+
# uVisor source directory - hidden from mbed via TARGET_IGNORE
35+
UVISOR_GIT_URL:=https://github.com/ARMmbed/uvisor
36+
UVISOR_GIT_BRANCH:=dev
37+
UVISOR_DIR:=TARGET_IGNORE/uvisor
38+
UVISOR_API:=$(UVISOR_DIR)/api
39+
UVISOR_GIT_CFG=$(UVISOR_DIR)/.git/config
40+
41+
# Derive variables from user configuration
42+
TARGET_LIST:=$(subst .,,$(suffix $(TARGET_TRANSLATION)))
43+
TARGET_LIST_DIR_SRC:=$(addprefix $(UVISOR_API)/lib/,$(TARGET_LIST))
44+
TARGET_LIST_DIR_DST:=$(addprefix $(TARGET_SUPPORTED)/,$(TARGET_LIST))
45+
TARGET_LIST_RELEASE:=$(addsuffix /release,$(TARGET_LIST_DIR_DST))
46+
TARGET_LIST_DEBUG:=$(addsuffix /debug,$(TARGET_LIST_DIR_DST))
47+
48+
.PHONY: all deploy rsync publish uvisor uvisor-compile clean cache update
49+
50+
all: uvisor
51+
52+
uvisor: uvisor-compile publish
53+
54+
rsync:
55+
#
56+
# Copying uVisor into mbed library...
57+
rm -rf $(TARGET_SUPPORTED)
58+
mkdir -p $(TARGET_SUPPORTED)
59+
rsync -a --exclude='*.txt' $(TARGET_LIST_DIR_SRC) $(TARGET_SUPPORTED)
60+
#
61+
# Copying uVisor headers to mbed includes...
62+
rm -rf $(TARGET_INC)
63+
mkdir -p $(TARGET_INC)
64+
rsync -a --delete $(UVISOR_API)/inc $(TARGET_INC)
65+
rsync -a --delete $(UVISOR_API)/rtx/inc/ $(TARGET_LIB_INC)/rtx
66+
#
67+
# Copying uVisor unsupported sources to unsupported target source...
68+
mkdir -p $(TARGET_UNSUPPORTED)
69+
cp $(UVISOR_API)/src/unsupported.c $(TARGET_UNSUPPORTED)/
70+
#
71+
# Copying uVisor shared sources to mbed source...
72+
rm -rf $(TARGET_LIB_SRC)
73+
mkdir -p $(TARGET_LIB_SRC)
74+
cp $(UVISOR_DIR)/core/system/src/page_allocator.c $(TARGET_LIB_SRC)/page_allocator.c_inc
75+
rsync -a --delete $(UVISOR_API)/rtx/src/ $(TARGET_LIB_SRC)/rtx
76+
#
77+
# Copying licenses
78+
cp $(UVISOR_DIR)/LICENSE* $(TARGET_SUPPORTED)
79+
80+
TARGET_M%: $(TARGET_SUPPORTED)/*/*/*_m%_*.a
81+
@printf "#\n# Copying $@ files...\n"
82+
mkdir $(foreach file,$^,$(dir $(file))$@)
83+
$(foreach file,$^,mv $(file) $(dir $(file))$@/lib$(notdir $(file));)
84+
85+
publish: rsync TARGET_M3 TARGET_M4
86+
#
87+
# Rename release directorires to TARGET_RELEASE filters...
88+
$(foreach dir, $(TARGET_LIST_RELEASE),mv $(dir) $(dir $(dir))TARGET_RELEASE;)
89+
#
90+
# Rename debug directorires to TARGET_DEBUG filters...
91+
$(foreach dir, $(TARGET_LIST_DEBUG),mv $(dir) $(dir $(dir))TARGET_DEBUG;)
92+
#
93+
# Rename target directorires to TARGET_* filters...
94+
$(foreach target, $(TARGET_TRANSLATION),mv $(TARGET_SUPPORTED)/$(subst .,,$(suffix $(target))) $(TARGET_SUPPORTED)/TARGET_$(basename $(target));)
95+
96+
uvisor-compile: $(UVISOR_GIT_CFG)
97+
make -C $(UVISOR_DIR)
98+
99+
update: $(UVISOR_GIT_CFG)
100+
#
101+
# Updating to latest uVisor library version
102+
git -C $(UVISOR_DIR) pull --rebase
103+
#
104+
# Updating checked out version tag
105+
git -C $(UVISOR_DIR) describe --tags --abbrev=40 --dirty > $(TARGET_PREFIX)VERSION.txt
106+
#
107+
# Updated list of authors, sorted by contributions
108+
git -C $(UVISOR_DIR) shortlog -s -n > $(TARGET_PREFIX)AUTHORS.txt
109+
110+
$(UVISOR_GIT_CFG):
111+
rm -rf $(UVISOR_DIR)
112+
git clone -b $(UVISOR_GIT_BRANCH) $(UVISOR_GIT_URL) $(UVISOR_DIR)
113+
114+
clean: $(UVISOR_GIT_CFG)
115+
make -C $(UVISOR_DIR) clean
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Rebuilding the uVisor mbed Library
2+
3+
This directory contains scripts to import and rebuild the latest uVisor library to mbed Classic.
4+
uVisor does not need to be re-deployed for normal application development.
5+
6+
For uVisor development and code contributions please visit the [uVisor repository](https://github.com/ARMmbed/uvisor).
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/uvisor
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2016, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#ifndef __RTX_PROCESS_MALLOC_H__
18+
#define __RTX_PROCESS_MALLOC_H__
19+
20+
#include "secure_allocator.h"
21+
22+
#ifdef __cplusplus
23+
extern "C" {
24+
#endif
25+
26+
/* Allocate memory on the process heap. */
27+
void * malloc_p(size_t size);
28+
/* Reallocate memory on the process heap. */
29+
void * realloc_p(void * ptr, size_t size);
30+
/* Free memory on the process heap. */
31+
void free_p(void * ptr);
32+
33+
#ifdef __cplusplus
34+
} /* extern "C" */
35+
#endif
36+
37+
#endif /* __RTX_PROCESS_MALLOC_H__ */
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2016, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#ifndef __RTX_BOX_INDEX_H__
18+
#define __RTX_BOX_INDEX_H__
19+
20+
#include "cmsis_os.h"
21+
22+
#ifdef __cplusplus
23+
extern "C" {
24+
#endif
25+
26+
typedef struct
27+
{
28+
/* The uvisor box index must be placed at the beginning */
29+
UvisorBoxIndex index;
30+
31+
/* Id of the mutex */
32+
osMutexId mutex_id;
33+
/* Pointer to the data of the mutex */
34+
osMutexDef_t mutex;
35+
/* Internal data of the mutex */
36+
int32_t mutex_data[4];
37+
} RtxBoxIndex;
38+
39+
#ifdef __cplusplus
40+
} /* extern "C" */
41+
#endif
42+
43+
#endif /* __RTX_BOX_INDEX_H__ */
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright (c) 2016, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#ifndef __SECURE_ALLOCATOR_H__
18+
#define __SECURE_ALLOCATOR_H__
19+
20+
#include <stdint.h>
21+
#include <stddef.h>
22+
23+
#ifdef __cplusplus
24+
extern "C" {
25+
#endif
26+
27+
/** Contains the allocator data and backing page table. */
28+
typedef void * SecureAllocator;
29+
30+
/** Create an allocator in-place in an existing pool without using pages.
31+
* Use this to turn statically allocated memory into a heap.
32+
* Or allocate a large piece of memory and then turn that into a heap.
33+
*
34+
* @param mem Pointer to the origin of the memory pool
35+
* @param bytes Length of the memory pool in bytes
36+
* @returns the allocator or `NULL` on failure
37+
*/
38+
SecureAllocator secure_allocator_create_with_pool(
39+
void * mem,
40+
size_t bytes);
41+
42+
/** Create an allocator using pages from the page heap.
43+
* Use this to request secure dynamic memory for your process.
44+
* Note that this memory is not guaranteed to be consecutive, therefore you
45+
* must specify the maximum allocation size that you plan to use in this
46+
* allocator. This function will then compute the number and size of required
47+
* pages and request them from the secure page heap.
48+
*
49+
* @param total_size The minimal total size of the heap
50+
* @param maximum_malloc_size The largest size to be allocated in one chunk
51+
* @returns the allocator or `NULL` on failure (out of memory,
52+
* maximum malloc size cannot be fulfilled)
53+
*/
54+
SecureAllocator secure_allocator_create_with_pages(
55+
size_t total_size,
56+
size_t maximum_malloc_size);
57+
58+
/** Destroy the allocator and free the backing pages.
59+
* An attempt to destroy a memory-pool backed allocator will fail and return
60+
* with an error code.
61+
*
62+
* @retval 0 Allocator successfully destroyed.
63+
* @retval -1 Allocator is static (memory-pool), or freeing memory pages failed.
64+
*/
65+
int secure_allocator_destroy(
66+
SecureAllocator allocator);
67+
68+
/** Drop-in for `malloc`. */
69+
void * secure_malloc(
70+
SecureAllocator allocator,
71+
size_t size);
72+
73+
/** Drop-in for `realloc`. */
74+
void * secure_realloc(
75+
SecureAllocator allocator,
76+
void * ptr,
77+
size_t size);
78+
79+
/** Drop-in for `free`. */
80+
void secure_free(
81+
SecureAllocator allocator,
82+
void * ptr);
83+
84+
#ifdef __cplusplus
85+
} /* extern "C" */
86+
#endif
87+
88+
#endif /* __SECURE_ALLOCATOR_H__ */
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2013-2016, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#ifndef __UVISOR_LIB_UVISOR_LIB_H__
18+
#define __UVISOR_LIB_UVISOR_LIB_H__
19+
20+
/* This file translates mbed-specific pre-processor symbols into
21+
* uVisor-specific ones. Then the main uvisor-lib.h file is included. */
22+
23+
/* mbed uses UVISOR_SUPPORTED to determine whether the full uVisor binaries
24+
* should be included or not. This symbol maps to the uVisor-internal symbol
25+
* UVISOR_PRESENT. */
26+
/* By default uVisor is not supported. */
27+
#if !defined(FEATURE_UVISOR) || !defined(TARGET_UVISOR_SUPPORTED) || defined(TARGET_UVISOR_UNSUPPORTED)
28+
#define UVISOR_PRESENT 0
29+
#else
30+
#define UVISOR_PRESENT 1
31+
#endif
32+
33+
/* Detect the target using the mbed-specific symbols and determine the MPU
34+
* architecture accordingly. */
35+
#if defined(TARGET_KINETIS)
36+
#define ARCH_MPU_KINETIS
37+
#else
38+
#define ARCH_MPU_ARMv7M
39+
#endif
40+
41+
/* The uVisor API main header file will use the above definitions. */
42+
#include "uvisor/api/inc/uvisor-lib.h"
43+
#include "uvisor-lib/rtx/process_malloc.h"
44+
#include "uvisor-lib/rtx/rtx_box_index.h"
45+
#include "uvisor-lib/rtx/secure_allocator.h"
46+
47+
#endif /* __UVISOR_LIB_UVISOR_LIB_H__ */
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2013-2015, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#ifndef __UVISOR_API_BENCHMARK_H__
18+
#define __UVISOR_API_BENCHMARK_H__
19+
20+
#include "api/inc/uvisor_exports.h"
21+
#include <stdint.h>
22+
23+
UVISOR_EXTERN void uvisor_benchmark_configure(void);
24+
UVISOR_EXTERN void uvisor_benchmark_start(void);
25+
UVISOR_EXTERN uint32_t uvisor_benchmark_stop(void);
26+
27+
#endif /* __UVISOR_API_BENCHMARK_H__ */

0 commit comments

Comments
 (0)