Skip to content

Commit da14bce

Browse files
authored
Merge pull request #2518 from fvincenzo/master
Enable uvisor on Beetle
2 parents 1eaa272 + 08e6f41 commit da14bce

File tree

7 files changed

+191
-79
lines changed

7 files changed

+191
-79
lines changed

features/FEATURE_UVISOR/importer/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ GDB:=$(PREFIX)gdb
2323
OBJDUMP:=$(PREFIX)objdump
2424

2525
# Translate between uVisor namespace and mbed namespace
26-
TARGET_TRANSLATION:=MCU_K64F.kinetis EFM32.efm32 STM32F4.stm32
26+
TARGET_TRANSLATION:=MCU_K64F.kinetis EFM32.efm32 STM32F4.stm32 ARM_BEETLE_SOC.beetle
2727
TARGET_PREFIX:=../
2828
TARGET_SUPPORTED:=$(TARGET_PREFIX)targets/TARGET_UVISOR_SUPPORTED
2929
TARGET_UNSUPPORTED:=$(TARGET_PREFIX)targets/TARGET_UVISOR_UNSUPPORTED

hal/targets/cmsis/TARGET_ARM_SSG/TARGET_BEETLE/TOOLCHAIN_GCC_ARM/BEETLE.ld

Lines changed: 137 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ MEMORY
2828
{
2929
VECTORS (rx) : ORIGIN = 0x00000000, LENGTH = 0x00000400
3030
FLASH (rx) : ORIGIN = 0x00000400, LENGTH = 0x00040000 - 0x00000400
31-
RAM (rwx) : ORIGIN = 0x20000140, LENGTH = 0x00020000 - 0x00000140
31+
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00020000
3232
}
3333

3434
/* Linker script to place sections and symbol values. Should be used together
@@ -59,25 +59,37 @@ MEMORY
5959
*/
6060
ENTRY(Reset_Handler)
6161

62+
/* Heap 1/4 of ram and stack 1/8 */
63+
__stack_size__ = 0x4000;
64+
__heap_size__ = 0x8000;
65+
66+
HEAP_SIZE = DEFINED(__heap_size__) ? __heap_size__ : 0x0400;
67+
STACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x0400;
68+
69+
/* Size of the vector table in SRAM */
70+
M_VECTOR_RAM_SIZE = 0x140;
71+
6272
SECTIONS
6373
{
6474
.isr_vector :
6575
{
6676
__vector_table = .;
6777
KEEP(*(.vector_table))
68-
*(.text.Reset_Handler)
69-
*(.text.System_Init)
7078
. = ALIGN(4);
7179
} > VECTORS
7280

73-
.cordio :
81+
/* Note: The uVisor expects this section at a fixed location, as specified
82+
by the porting process configuration parameter: FLASH_OFFSET. */
83+
__UVISOR_TEXT_OFFSET = 0x0;
84+
__UVISOR_TEXT_START = ORIGIN(FLASH) + __UVISOR_TEXT_OFFSET;
85+
.text __UVISOR_TEXT_START :
7486
{
75-
*CORDIO_RO_2.1.o
76-
*TRIM_2.1.o
77-
} > FLASH
87+
/* uVisor code and data */
88+
. = ALIGN(4);
89+
__uvisor_main_start = .;
90+
*(.uvisor.main)
91+
__uvisor_main_end = .;
7892

79-
.text :
80-
{
8193
*(.text*)
8294

8395
KEEP(*(.init))
@@ -114,12 +126,67 @@ SECTIONS
114126
} > FLASH
115127
__exidx_end = .;
116128

117-
__etext = .;
129+
.cordio :
130+
{
131+
*CORDIO_RO_2.1.o
132+
*TRIM_2.1.o
133+
} > FLASH
118134

119-
.data : AT (__etext)
135+
.interrupts_ram :
120136
{
137+
. = ALIGN(4);
138+
__VECTOR_RAM__ = .;
139+
__interrupts_ram_start__ = .; /* Create a global symbol at data start */
140+
. += M_VECTOR_RAM_SIZE;
141+
. = ALIGN(4);
142+
__interrupts_ram_end__ = .; /* Define a global symbol at data end */
143+
} > RAM
144+
145+
/* ensure that uvisor bss is at the beginning of memory */
146+
/* Note: The uVisor expects this section at a fixed location, as specified by
147+
* the porting process configuration parameter: SRAM_OFFSET. */
148+
__UVISOR_SRAM_OFFSET = 0x140;
149+
__UVISOR_BSS_START = ORIGIN(RAM) + __UVISOR_SRAM_OFFSET;
150+
.uvisor.bss __UVISOR_BSS_START (NOLOAD):
151+
{
152+
. = ALIGN(32);
153+
__uvisor_bss_start = .;
154+
155+
/* protected uvisor main bss */
156+
. = ALIGN(32);
157+
__uvisor_bss_main_start = .;
158+
KEEP(*(.keep.uvisor.bss.main))
159+
. = ALIGN(32);
160+
__uvisor_bss_main_end = .;
161+
162+
/* protected uvisor secure boxes bss */
163+
. = ALIGN(32);
164+
__uvisor_bss_boxes_start = .;
165+
KEEP(*(.keep.uvisor.bss.boxes))
166+
. = ALIGN(32);
167+
__uvisor_bss_boxes_end = .;
168+
169+
. = ALIGN((1 << LOG2CEIL(LENGTH(RAM))) / 8);
170+
__uvisor_bss_end = .;
171+
} > RAM
172+
173+
/* Heap space for the page allocator */
174+
.page_heap (NOLOAD) :
175+
{
176+
. = ALIGN(32);
177+
__uvisor_page_start = .;
178+
KEEP(*(.keep.uvisor.page_heap))
179+
. = ALIGN(32);
180+
__uvisor_page_end = .;
181+
} > RAM
182+
183+
.data :
184+
{
185+
PROVIDE(__etext = LOADADDR(.data));
186+
. = ALIGN(4);
121187
__data_start__ = .;
122188
*(vtable)
189+
*(.data)
123190
*(.data*)
124191

125192
. = ALIGN(4);
@@ -147,41 +214,89 @@ SECTIONS
147214
/* All data end */
148215
__data_end__ = .;
149216

217+
} > RAM AT > FLASH
218+
219+
/* uvisor configuration data */
220+
.uvisor.secure :
221+
{
222+
. = ALIGN(32);
223+
__uvisor_secure_start = .;
224+
225+
/* uvisor secure boxes configuration tables */
226+
. = ALIGN(32);
227+
__uvisor_cfgtbl_start = .;
228+
KEEP(*(.keep.uvisor.cfgtbl))
229+
. = ALIGN(32);
230+
__uvisor_cfgtbl_end = .;
231+
232+
__uvisor_cfgtbl_ptr_start = .;
233+
KEEP(*(.keep.uvisor.cfgtbl_ptr_first))
234+
KEEP(*(.keep.uvisor.cfgtbl_ptr))
235+
__uvisor_cfgtbl_ptr_end = .;
236+
237+
/* Pointers to all boxes register gateways. These are grouped here to allow
238+
* discoverability and firmware verification. */
239+
__uvisor_register_gateway_ptr_start = .;
240+
KEEP(*(.keep.uvisor.register_gateway_ptr))
241+
__uvisor_register_gateway_ptr_end = .;
242+
243+
. = ALIGN(32);
244+
__uvisor_secure_end = .;
245+
} > FLASH
246+
247+
/* From now on you can insert any other SRAM region. */
248+
249+
.uninitialized (NOLOAD):
250+
{
251+
. = ALIGN(32);
252+
__uninitialized_start = .;
253+
*(.uninitialized)
254+
KEEP(*(.keep.uninitialized))
255+
. = ALIGN(32);
256+
__uninitialized_end = .;
150257
} > RAM
151258

152259
.bss :
153260
{
261+
. = ALIGN(4);
262+
__START_BSS = .;
154263
__bss_start__ = .;
264+
*(.bss)
155265
*(.bss*)
156266
*(COMMON)
267+
. = ALIGN(4);
157268
__bss_end__ = .;
269+
__END_BSS = .;
270+
158271
} > RAM
159272

160273
bss_size = __bss_end__ - __bss_start__;
161274

162275
.heap :
163276
{
277+
. = ALIGN(8);
278+
__uvisor_heap_start = .;
164279
__end__ = .;
165-
end = __end__;
166-
*(.heap*)
280+
PROVIDE(end = .);
281+
__HeapBase = .;
282+
. += HEAP_SIZE;
167283
__HeapLimit = .;
168-
} > RAM
169-
170-
/* .stack_dummy section doesn't contains any symbols. It is only
171-
* used for linker to calculate size of stack sections, and assign
172-
* values to stack symbols later */
173-
.stack_dummy :
174-
{
175-
*(.stack)
284+
__heap_limit = .; /* Add for _sbrk */
285+
__uvisor_heap_end = .;
176286
} > RAM
177287

178288
/* Set stack top to end of RAM, and stack limit move down by
179289
* size of stack_dummy section */
180290
__StackTop = ORIGIN(RAM) + LENGTH(RAM);
181-
__StackLimit = __StackTop - SIZEOF(.stack_dummy);
291+
__StackLimit = __StackTop - STACK_SIZE;
182292
PROVIDE(__stack = __StackTop);
183293

184294
/* Check if data + heap + stack exceeds RAM limit */
185295
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
296+
/* Provide physical memory boundaries for uVisor. */
297+
__uvisor_flash_start = ORIGIN(VECTORS);
298+
__uvisor_flash_end = ORIGIN(FLASH) + LENGTH(FLASH);
299+
__uvisor_sram_start = ORIGIN(RAM);
300+
__uvisor_sram_end = ORIGIN(RAM) + LENGTH(RAM);
186301

187302
} /* End of sections */

hal/targets/cmsis/TARGET_ARM_SSG/TARGET_BEETLE/TOOLCHAIN_GCC_ARM/startup_BEETLE.S

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -24,48 +24,6 @@
2424
.syntax unified
2525
.arch armv7-m
2626

27-
/* Memory Model
28-
The HEAP starts at the end of the DATA section and grows upward.
29-
30-
The STACK starts at the end of the RAM and grows downward.
31-
32-
The HEAP and stack STACK are only checked at compile time:
33-
(DATA_SIZE + HEAP_SIZE + STACK_SIZE) < RAM_SIZE
34-
35-
This is just a check for the bare minimum for the Heap+Stack area before
36-
aborting compilation, it is not the run time limit:
37-
Heap_Size + Stack_Size = 0x80 + 0x80 = 0x100
38-
*/
39-
.section .stack
40-
.align 3
41-
#ifdef __STACK_SIZE
42-
.equ Stack_Size, __STACK_SIZE
43-
#else
44-
.equ Stack_Size, 0x400
45-
#endif
46-
.globl __StackTop
47-
.globl __StackLimit
48-
__StackLimit:
49-
.space Stack_Size
50-
.size __StackLimit, . - __StackLimit
51-
__StackTop:
52-
.size __StackTop, . - __StackTop
53-
54-
.section .heap
55-
.align 3
56-
#ifdef __HEAP_SIZE
57-
.equ Heap_Size, __HEAP_SIZE
58-
#else
59-
.equ Heap_Size, 0xC00
60-
#endif
61-
.globl __HeapBase
62-
.globl __HeapLimit
63-
__HeapBase:
64-
.space Heap_Size
65-
.size __HeapBase, . - __HeapBase
66-
__HeapLimit:
67-
.size __HeapLimit, . - __HeapLimit
68-
6927
.section .vector_table,"a",%progbits
7028
.align 2
7129
.globl __isr_vector
@@ -143,6 +101,15 @@ __isr_vector:
143101
.globl Reset_Handler
144102
.type Reset_Handler, %function
145103
Reset_Handler:
104+
ldr r0, =SystemInit
105+
blx r0
106+
/* The call to uvisor_init() happens independently of uVisor being enabled or
107+
* not, so it is conditionally compiled only based on FEATURE_UVISOR. */
108+
#if defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED)
109+
/* Call uvisor_init() */
110+
ldr r0, =uvisor_init
111+
blx r0
112+
#endif /* FEATURE_UVISOR && TARGET_UVISOR_SUPPORTED */
146113
/*
147114
* Loop to copy data from read only memory to RAM. The ranges
148115
* of copy from/to are specified by following symbols evaluated in

hal/targets/cmsis/TARGET_ARM_SSG/TARGET_BEETLE/cmsis_nvic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#define NVIC_RAM_VECTOR_ADDRESS (0x20000000) //Location of vectors in RAM
2222
#define NVIC_FLASH_VECTOR_ADDRESS (0x00000000) //Initial vector position in flash
2323

24-
void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) {
24+
void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) {
2525
uint32_t *vectors = (uint32_t*)SCB->VTOR;
2626
uint32_t i;
2727

@@ -37,7 +37,7 @@ void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) {
3737
vectors[IRQn + NVIC_USER_IRQ_OFFSET] = vector;
3838
}
3939

40-
uint32_t NVIC_GetVector(IRQn_Type IRQn) {
40+
uint32_t __NVIC_GetVector(IRQn_Type IRQn) {
4141
uint32_t *vectors = (uint32_t*)SCB->VTOR;
4242
return vectors[IRQn + NVIC_USER_IRQ_OFFSET];
4343
}

hal/targets/cmsis/TARGET_ARM_SSG/TARGET_BEETLE/cmsis_nvic.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
extern "C" {
3030
#endif
3131

32-
void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector);
33-
uint32_t NVIC_GetVector(IRQn_Type IRQn);
32+
void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector);
33+
uint32_t __NVIC_GetVector(IRQn_Type IRQn);
3434

3535
#ifdef __cplusplus
3636
}

0 commit comments

Comments
 (0)