Skip to content

Commit 820a372

Browse files
committed
Add a uvisor_init helper function
This way no startup script changes are necessary.
1 parent 3bf4df4 commit 820a372

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

api/inc/api.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
UVISOR_EXTERN_C_BEGIN
3333

34+
extern void uvisor_init(void);
35+
3436
typedef struct {
3537
uint32_t magic;
3638
uint32_t (*get_version)(uint32_t);

api/src/uvisor-lib.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
#include "api/inc/halt_exports.h"
1919
#include "rt_OsEventObserver.h"
2020

21+
void uvisor_init(void)
22+
{
23+
uvisor_api.init();
24+
}
25+
2126
int uvisor_lib_init(void)
2227
{
2328
/* osRegisterForOsEvents won't allow a second call. For systems that don't

docs/core/PORTING.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Although uVisor is highly self-contained, it still requires some support from th
3131

3232
1. **Library glue layer**. The [ARMmbed/uvisor](https://github.com/ARMmbed/uvisor) `Makefile` allows you to build both release and debug libraries for all family configurations. The logic to generate this libraries, publish them, and then pick the right library for the right target at build time is OS-specific. This logic must be provided by a glue layer.
3333
1. **Linker script**. It contains specific memory regions and symbols that uVisor relies on.
34-
1. **Start-up script**. uVisor boots right after the system basic initialization, and before the C/C++ library initialization. The start-up script needs to call `uvisor_api.init()` in between those two.
34+
1. **Start-up script**. uVisor boots right after the system basic initialization, and before the C/C++ library initialization. The start-up script needs to call `uvisor_init()` in between those two.
3535

3636
If you are porting uVisor to mbed OS, you will find that the library glue layer is already embedded in the [mbed OS code-base](https://github.com/ARMmbed/uvisor-lib). The linker script and start-up code also live in the same repository. We will guide you through the modifications needed in those files later in this guide.
3737

@@ -297,7 +297,7 @@ The build process generates as many static libraries (`*.a` files) as your famil
297297

298298
You now need to integrate uVisor in the mbed OS code-base for your target. This requires the following steps, which we will cover in detail:
299299

300-
* Add a hook to `uvisor_api.init()` in your start-up script.
300+
* Add a hook to `uvisor_init()` in your start-up script.
301301
* Add the uVisor-specific sections to your platforms' linker scripts.
302302
* Deploy the uVisor libraries for your target platforms.
303303
* Enable uVisor in your targets.
@@ -313,24 +313,23 @@ Assuming that you already ported your platform to mbed, the start-up script usua
313313
hal/targets/cmsis/TARGET_${vendor}/TARGET_${family}/TARGET_${device}/TOOLCHAIN_${toolchain}
314314
```
315315

316-
The start-up code must call the function `uvisor_api.init()` right after system initialization (usually called `SystemInit()`) and right before the C/C++ library initialization.
316+
The start-up code must call the function `uvisor_init()` right after system initialization (usually called `SystemInit()`) and right before the C/C++ library initialization.
317317

318318
```C
319319
ResetHandler:
320320
...
321321
ldr r0, =SystemInit
322322
blx r0
323323
#if defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED)
324-
ldr r0, =uvisor_api /* [*] Insert this. */
325-
ldr r0, [r0, #8] /* [*] Insert this. */
324+
ldr r0, =uvisor_init /* [*] Insert this. */
326325
blx r0 /* [*] Insert this. */
327326
#endif /* defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED) */
328327
ldr r0, =__start
329328
bx r0
330329
...
331330
```
332331

333-
Make sure that no static initialization (zeroing the BSS section, loading data from flash to SRAM) happens before the uVisor initialization. Even setting a single global variable before `uvisor_api.init()` and then referring to it later on might result in data corruption.
332+
Make sure that no static initialization (zeroing the BSS section, loading data from flash to SRAM) happens before the uVisor initialization. Even setting a single global variable before `uvisor_init()` and then referring to it later on might result in data corruption.
334333

335334
The conditional guards that we used in the example above rely on the `FEATURE_UVISOR` and `UVISOR_SUPPORTED` symbols, which will be covered shortly.
336335

0 commit comments

Comments
 (0)