Skip to content

Commit 3a53a5a

Browse files
adustmAlessandroA
authored andcommitted
DISCO_F429ZI: Add support for uVisor
1 parent 3a326c0 commit 3a53a5a

File tree

10 files changed

+237
-49
lines changed

10 files changed

+237
-49
lines changed

targets/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/device/system_stm32f4xx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Cloc
100100
* @{
101101
*/
102102

103+
extern void SystemInitPre(void);
103104
extern void SystemInit(void);
104105
extern void SystemCoreClockUpdate(void);
105106
extern void SetSysClock(void);

targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F429ZI/device/TOOLCHAIN_GCC_ARM/STM32F429ZI.ld

Lines changed: 149 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
/* Linker script to configure memory regions. */
1+
M_VECTOR_RAM_SIZE = 0x400;
2+
3+
/* Heap: 1/4 of RAM. Stack: 1/8 of RAM. */
4+
STACK_SIZE = 0x6000;
5+
HEAP_SIZE = 0xC000;
6+
7+
/* Specify the memory areas */
28
MEMORY
3-
{
4-
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 2048k
5-
CCM (rwx) : ORIGIN = 0x10000000, LENGTH = 64K
6-
RAM (rwx) : ORIGIN = 0x200001AC, LENGTH = 192k - 0x1AC
9+
{
10+
VECTORS (rx) : ORIGIN = 0x08000000, LENGTH = 0x400
11+
FLASH (rx) : ORIGIN = 0x08000400, LENGTH = 2048k - 0x400
12+
CCM (rwx) : ORIGIN = 0x10000000, LENGTH = 64K
13+
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 192k
714
}
815

916
/* Linker script to place sections and symbol values. Should be used together
1017
* with other linker script that defines memory regions FLASH and RAM.
1118
* It references following symbols, which must be defined in code:
1219
* Reset_Handler : Entry of reset handler
13-
*
20+
*
1421
* It defines following symbols, which code can use without definition:
1522
* __exidx_start
1623
* __exidx_end
@@ -37,10 +44,28 @@ ENTRY(Reset_Handler)
3744

3845
SECTIONS
3946
{
40-
.text :
47+
.isr_vector :
4148
{
49+
__vector_table = .;
4250
KEEP(*(.isr_vector))
51+
. = ALIGN(4);
52+
} > VECTORS
53+
54+
/* Note: The uVisor expects this section at a fixed location, as specified
55+
* by the porting process configuration parameter:
56+
* FLASH_OFFSET. */
57+
__UVISOR_FLASH_OFFSET = 0x400;
58+
__UVISOR_FLASH_START = ORIGIN(VECTORS) + __UVISOR_FLASH_OFFSET;
59+
.text __UVISOR_FLASH_START :
60+
{
61+
/* uVisor code and data */
62+
. = ALIGN(4);
63+
__uvisor_main_start = .;
64+
*(.uvisor.main)
65+
__uvisor_main_end = .;
66+
4367
*(.text*)
68+
4469
KEEP(*(.init))
4570
KEEP(*(.fini))
4671

@@ -69,6 +94,7 @@ SECTIONS
6994
} > FLASH
7095

7196
__exidx_start = .;
97+
7298
.ARM.exidx :
7399
{
74100
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
@@ -78,8 +104,62 @@ SECTIONS
78104
__etext = .;
79105
_sidata = .;
80106

81-
.data : AT (__etext)
107+
.interrupts_ram :
108+
{
109+
. = ALIGN(4);
110+
__VECTOR_RAM__ = .;
111+
__interrupts_ram_start__ = .; /* Create a global symbol at data start */
112+
*(.m_interrupts_ram) /* This is a user defined section */
113+
. += M_VECTOR_RAM_SIZE;
114+
. = ALIGN(4);
115+
__interrupts_ram_end__ = .; /* Define a global symbol at data end */
116+
} > RAM
117+
118+
/* uVisor own memory and private box memories
119+
/* Note: The uVisor expects this section at a fixed location, as specified
120+
by the porting process configuration parameter: SRAM_OFFSET. */
121+
__UVISOR_SRAM_OFFSET = 0x0;
122+
__UVISOR_SRAM_START = ORIGIN(CCM) + __UVISOR_SRAM_OFFSET;
123+
.uvisor.bss __UVISOR_SRAM_START (NOLOAD):
124+
{
125+
. = ALIGN(32);
126+
__uvisor_bss_start = .;
127+
128+
/* Protected uVisor own BSS section */
129+
. = ALIGN(32);
130+
__uvisor_bss_main_start = .;
131+
KEEP(*(.keep.uvisor.bss.main))
132+
. = ALIGN(32);
133+
__uvisor_bss_main_end = .;
134+
135+
/* Protected uVisor boxes' static memories */
136+
. = ALIGN(32);
137+
__uvisor_bss_boxes_start = .;
138+
KEEP(*(.keep.uvisor.bss.boxes))
139+
. = ALIGN(32);
140+
__uvisor_bss_boxes_end = .;
141+
142+
. = ALIGN(32);
143+
__uvisor_bss_end = .;
144+
} > CCM
145+
146+
/* Heap space for the page allocator
147+
/* If uVisor shares the SRAM with the OS/app, ensure that this section is
148+
* the first one after the uVisor BSS section. Otherwise, ensure it is the
149+
* first one after the VTOR relocation section. */
150+
.page_heap (NOLOAD) :
82151
{
152+
. = ALIGN(32);
153+
__uvisor_page_start = .;
154+
KEEP(*(.keep.uvisor.page_heap))
155+
. = ALIGN((1 << LOG2CEIL(LENGTH(RAM))) / 8);
156+
__uvisor_page_end = .;
157+
} > RAM
158+
159+
.data :
160+
{
161+
PROVIDE( __etext = LOADADDR(.data) );
162+
83163
__data_start__ = .;
84164
_sdata = .;
85165
*(vtable)
@@ -112,9 +192,54 @@ SECTIONS
112192
__data_end__ = .;
113193
_edata = .;
114194

195+
} > RAM AT > FLASH
196+
197+
/* uVisor configuration section
198+
* This section must be located after all other flash regions. */
199+
.uvisor.secure :
200+
{
201+
. = ALIGN(32);
202+
__uvisor_secure_start = .;
203+
204+
/* uVisor secure boxes configuration tables */
205+
. = ALIGN(32);
206+
__uvisor_cfgtbl_start = .;
207+
KEEP(*(.keep.uvisor.cfgtbl))
208+
. = ALIGN(32);
209+
__uvisor_cfgtbl_end = .;
210+
211+
/* Pointers to the uVisor secure boxes configuration tables */
212+
/* Note: Do not add any further alignment here, as uVisor will need to
213+
* have access to the exact list of pointers. */
214+
__uvisor_cfgtbl_ptr_start = .;
215+
KEEP(*(.keep.uvisor.cfgtbl_ptr_first))
216+
KEEP(*(.keep.uvisor.cfgtbl_ptr))
217+
__uvisor_cfgtbl_ptr_end = .;
218+
219+
/* Pointers to all boxes register gateways. These are grouped here to
220+
allow discoverability and firmware verification. */
221+
__uvisor_register_gateway_ptr_start = .;
222+
KEEP(*(.keep.uvisor.register_gateway_ptr))
223+
__uvisor_register_gateway_ptr_end = .;
224+
225+
. = ALIGN(32);
226+
__uvisor_secure_end = .;
227+
} > FLASH
228+
229+
/* Uninitialized data section
230+
* This region is not initialized by the C/C++ library and can be used to
231+
* store state across soft reboots. */
232+
.uninitialized (NOLOAD):
233+
{
234+
. = ALIGN(32);
235+
__uninitialized_start = .;
236+
*(.uninitialized)
237+
KEEP(*(.keep.uninitialized))
238+
. = ALIGN(32);
239+
__uninitialized_end = .;
115240
} > RAM
116241

117-
.bss :
242+
.bss (NOLOAD):
118243
{
119244
. = ALIGN(4);
120245
__bss_start__ = .;
@@ -126,29 +251,27 @@ SECTIONS
126251
_ebss = .;
127252
} > RAM
128253

129-
.heap (COPY):
254+
.heap (NOLOAD):
130255
{
256+
__uvisor_heap_start = .;
131257
__end__ = .;
132258
end = __end__;
133-
*(.heap*)
259+
. += HEAP_SIZE;
134260
__HeapLimit = .;
261+
__uvisor_heap_end = .;
135262
} > RAM
136263

137-
/* .stack_dummy section doesn't contains any symbols. It is only
138-
* used for linker to calculate size of stack sections, and assign
139-
* values to stack symbols later */
140-
.stack_dummy (COPY):
141-
{
142-
*(.stack*)
143-
} > RAM
144-
145-
/* Set stack top to end of RAM, and stack limit move down by
146-
* size of stack_dummy section */
147264
__StackTop = ORIGIN(RAM) + LENGTH(RAM);
148-
_estack = __StackTop;
149-
__StackLimit = __StackTop - SIZEOF(.stack_dummy);
150-
PROVIDE(__stack = __StackTop);
265+
__stack = __StackTop;
266+
__StackLimit = __StackTop - STACK_SIZE;
267+
268+
ASSERT(__StackLimit >= __HeapLimit, "Region RAM overflowed with stack and heap")
151269

152-
/* Check if data + heap + stack exceeds RAM limit */
153-
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
270+
/* Provide physical memory boundaries for uVisor. */
271+
__uvisor_flash_start = ORIGIN(VECTORS);
272+
__uvisor_flash_end = ORIGIN(FLASH) + LENGTH(FLASH);
273+
__uvisor_sram_start = ORIGIN(CCM);
274+
__uvisor_sram_end = ORIGIN(CCM) + LENGTH(CCM);
275+
__uvisor_public_sram_start = ORIGIN(RAM);
276+
__uvisor_public_sram_end = ORIGIN(RAM) + LENGTH(RAM);
154277
}

targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F429ZI/device/TOOLCHAIN_GCC_ARM/startup_stm32f429xx.S

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ defined in linker script */
7272
.section .text.Reset_Handler
7373
.weak Reset_Handler
7474
.type Reset_Handler, %function
75-
Reset_Handler:
76-
ldr sp, =_estack /* set stack pointer */
77-
78-
/* Copy the data segment initializers from flash to SRAM */
75+
Reset_Handler:
76+
ldr sp, =__stack /* set stack pointer */
77+
78+
/* Copy the data segment initializers from flash to SRAM */
7979
movs r1, #0
8080
b LoopCopyDataInit
8181

@@ -93,6 +93,12 @@ LoopCopyDataInit:
9393
bcc CopyDataInit
9494

9595
/* Call the clock system intitialization function.*/
96+
bl SystemInitPre
97+
bl HAL_InitPre
98+
#if defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED)
99+
ldr r0, =uvisor_init
100+
blx r0
101+
#endif /* defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED) */
96102
bl SystemInit
97103
/* Call static constructors */
98104
//bl __libc_init_array
@@ -130,7 +136,7 @@ Infinite_Loop:
130136
.size g_pfnVectors, .-g_pfnVectors
131137

132138
g_pfnVectors:
133-
.word _estack
139+
.word __stack
134140
.word Reset_Handler
135141

136142
.word NMI_Handler

targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F429ZI/device/cmsis_nvic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#define NVIC_RAM_VECTOR_ADDRESS (0x20000000) // Vectors positioned at start of RAM
3434
#define NVIC_FLASH_VECTOR_ADDRESS (0x08000000) // Initial vector position in flash
3535

36-
void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) {
36+
void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) {
3737
uint32_t *vectors = (uint32_t *)SCB->VTOR;
3838
uint32_t i;
3939

@@ -49,7 +49,7 @@ void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) {
4949
vectors[IRQn + NVIC_USER_IRQ_OFFSET] = vector;
5050
}
5151

52-
uint32_t NVIC_GetVector(IRQn_Type IRQn) {
52+
uint32_t __NVIC_GetVector(IRQn_Type IRQn) {
5353
uint32_t *vectors = (uint32_t*)SCB->VTOR;
5454
return vectors[IRQn + NVIC_USER_IRQ_OFFSET];
5555
}

targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F429ZI/device/cmsis_nvic.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
extern "C" {
4646
#endif
4747

48-
void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector);
49-
uint32_t NVIC_GetVector(IRQn_Type IRQn);
48+
void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector);
49+
uint32_t __NVIC_GetVector(IRQn_Type IRQn);
5050

5151
#ifdef __cplusplus
5252
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2015-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+
#include "stm32f4xx.h"
18+
19+
/*!< Uncomment the following line if you need to relocate your vector Table in
20+
Internal SRAM. */
21+
/* note: if uVisor is present the definition must go in system_init_pre.c */
22+
/* #define VECT_TAB_SRAM */
23+
#define VECT_TAB_OFFSET 0x00 /*!< Vector Table base offset field.
24+
This value must be a multiple of 0x200. */
25+
26+
/* this function is needed to peform hardware initialization that must happen
27+
* before the uVisor; the whole SystemInit function for the STM32F4 cannot be
28+
* put here as it depends on some APIs that need uVisor to be enabled */
29+
void SystemInitPre(void)
30+
{
31+
/* FPU settings ------------------------------------------------------------*/
32+
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
33+
SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
34+
#endif
35+
36+
/* Configure the Vector Table location add offset address ------------------*/
37+
#ifdef VECT_TAB_SRAM
38+
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
39+
#else
40+
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
41+
#endif
42+
}

targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F429ZI/device/system_stm32f4xx.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,6 @@ void SetSysClock(void);
187187
*/
188188
void SystemInit(void)
189189
{
190-
/* FPU settings ------------------------------------------------------------*/
191-
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
192-
SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
193-
#endif
194190
/* Reset the RCC clock configuration to the default reset state ------------*/
195191
/* Set HSION bit */
196192
RCC->CR |= (uint32_t)0x00000001;
@@ -214,13 +210,6 @@ void SystemInit(void)
214210
SystemInit_ExtMemCtl();
215211
#endif /* DATA_IN_ExtSRAM || DATA_IN_ExtSDRAM */
216212

217-
/* Configure the Vector Table location add offset address ------------------*/
218-
#ifdef VECT_TAB_SRAM
219-
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
220-
#else
221-
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
222-
#endif
223-
224213
/* Configure the Cube driver */
225214
SystemCoreClock = 16000000; // At this stage the HSI is used as system clock
226215
HAL_Init();

0 commit comments

Comments
 (0)