Skip to content

Commit 460e631

Browse files
author
Alexander Zilberkant
committed
rewrite linker scripts and addresses part configuration
1 parent a9d4851 commit 460e631

File tree

1 file changed

+153
-64
lines changed

1 file changed

+153
-64
lines changed

docs/porting/psa/spm.md

Lines changed: 153 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -7,84 +7,176 @@ For more information about SPM, refer to [TODO: WHEN READY, SPM OVERVIEW PAGE LI
77
**This page gives guidelines for silicon partners wishing to have Secure Partition Manager capabilities**
88

99

10-
## Linker Scripts
10+
## Memory layout
11+
12+
Typically PSA platforms will share same RAM and flash between secure and non secure cores.
13+
In order to provide PSA isolation level 1 or higher we need to partition both RAM and flash
14+
in a way described by following drawing:
15+
16+
```text
17+
RAM
18+
+-----------+-------------+--------------------------------------------------+
19+
| Secure | Shared | Non-Secure |
20+
| RAM | RAM | RAM |
21+
+-----------+-------------+--------------------------------------------------+
1122
12-
Silicon partners must edit the secure and non-secure linker scripts to define sections for RAM, FLASH and SHARED_RAM.
23+
Flash
24+
+-----------------------+----------------------------------------------------+
25+
| Secure | Non-Secure |
26+
| Flash | Flash |
27+
+-----------------------+----------------------------------------------------+
28+
29+
```
30+
In order to achieve RAM and Flash partitioning start and size values must be added to target a configuration in `targets.json`.
31+
The process of defining can be described in the following steps:
32+
1. secure target must inherit from `SPE_Target` meta-target
33+
2. non-secure target must inherit from `NSPE_Target`
34+
3. both targets must override default configuration by specifying flash RAM and shared RAM regions.
35+
36+
```json
37+
"FUTURE_SEQUANA_M0_PSA": {
38+
"inherits": ["SPE_Target", "FUTURE_SEQUANA_M0"],
39+
"extra_labels_add": ["PSOC6_PSA"],
40+
"components_add": ["SPM_MAILBOX"],
41+
"macros_add": ["PSOC6_DYNSRM_DISABLE=1"],
42+
"deliver_to_target": "FUTURE_SEQUANA_PSA",
43+
"overrides": {
44+
"secure-rom-start": "0x10000000",
45+
"secure-rom-size": "0x78000",
46+
"non-secure-rom-start": "0x10080000",
47+
"non-secure-rom-size": "0x78000",
48+
"secure-ram-start": "0x08000000",
49+
"secure-ram-size": "0x10000",
50+
"non-secure-ram-start": "0x08011000",
51+
"non-secure-ram-size": "0x36800",
52+
"shared-ram-start": "0x08010000",
53+
"shared-ram-size": "0x1000"
54+
}
55+
},
56+
"FUTURE_SEQUANA_PSA": {
57+
"inherits": ["NSPE_Target", "FUTURE_SEQUANA"],
58+
"sub_target": "FUTURE_SEQUANA_M0_PSA",
59+
"extra_labels_remove": ["CORDIO"],
60+
"extra_labels_add": ["PSOC6_PSA"],
61+
"components_add": ["SPM_MAILBOX"],
62+
"macros_add": ["PSOC6_DYNSRM_DISABLE=1"],
63+
"overrides": {
64+
"secure-rom-start": "0x10000000",
65+
"secure-rom-size": "0x78000",
66+
"non-secure-rom-start": "0x10080000",
67+
"non-secure-rom-size": "0x78000",
68+
"secure-ram-start": "0x08000000",
69+
"secure-ram-size": "0x10000",
70+
"non-secure-ram-start": "0x08011000",
71+
"non-secure-ram-size": "0x36800",
72+
"shared-ram-start": "0x08010000",
73+
"shared-ram-size": "0x1000"
74+
}
75+
}
76+
```
1377

14-
Linker scripts guidelines:
15-
- *__shared_memory_start* symbol is used in SPM code so it must be set with the start address of the shared memory
16-
- *__shared_memory_start* must be 4 bytes aligned
17-
- *__shared_memory_end* symbol is used in SPM code so it must be set with the end address of the shared memory
18-
- SHARED_RAM must have Read/Write permissions from secure and non-secure cores
19-
- SHARED_RAM address must be 4 bytes aligned
20-
- SHARED_RAM must be given a minimum memory space of 256 bytes
21-
- Secure RAM base address must be 4 bytes aligned and have Read/Write permissions only from secure core
22-
- Secure FLASH base address must be 4 bytes aligned and have Read/Write/Execute permissions only from secure core
23-
- Non-Secure RAM base address must be 4 bytes aligned and have Read/Write permissions from secure and non-secure cores
24-
- Non-Secure FLASH base address must be 4 bytes aligned; must have Read permissions from secure and non-secure cores, and Execute permissions from non-secure core; May have Write permissions from secure and non-secure cores
78+
> Note: shared memory region is required only for multi core architectures.
2579
26-
This is an example of the relevant parts inside the linker scripts:
80+
## Linker Scripts
2781

28-
#### SECURE Core Linker Script
82+
Linker scripts mast include `MBED_ROM_START`, `MBED_ROM_SIZE`, `MBED_RAM_START` and `MBED_RAM_START` macros for defining memory regions.
83+
Shared memory region is defined by reserving RAM space for shared memory usage. Shared memory location is target specific and depends on the memory protection scheme applied.
84+
Typically shared memory will be located before/after non-secure RAM, for saving MPU regions. Shared memory region is considered non-secure memory used by both cores.
2985

86+
### Linker Script example GCC_ARM
3087
```
31-
...
32-
...
33-
MEMORY
34-
{
35-
/* The ram and flash regions control RAM and flash memory allocation for the SECURE core.
36-
* You can change the memory allocation by editing the 'ram' and 'flash' regions.
37-
* Your changes must be aligned with the corresponding memory regions for the NON-SECURE core in the
38-
* NON-SECURE linker script.
39-
*/
40-
ram (rwx) : ORIGIN = 0x08000000, LENGTH = 0x10000
41-
shared_ram (rw) : ORIGIN = 0x08010000, LENGTH = 0x1000
42-
flash (rx) : ORIGIN = 0x10000000, LENGTH = 0x78000
43-
44-
...
45-
...
46-
}
88+
#if !defined(MBED_ROM_START)
89+
#define MBED_ROM_START 0x10000000
90+
#endif
4791
48-
...
49-
...
92+
#if !defined(MBED_ROM_SIZE)
93+
#define MBED_ROM_SIZE 0x78000
94+
#endif
5095
51-
/* .shared_mem section contains memory shared between SECURE core and NON-SECURE core */
52-
.shared_mem :
53-
{
54-
__shared_memory_start = .;
55-
. += 0x1000;
56-
__shared_memory_end = .;
96+
#if !defined(MBED_RAM_START)
97+
#define MBED_RAM_START 0x08000000
98+
#endif
5799
58-
/* Check if section is 4 bytes aligned */
59-
ASSERT (((__shared_memory_start % 4) == 0), "Error: shared_mem section is not 4 bytes aligned!!");
60-
} > shared_ram
100+
#if !defined(MBED_RAM_SIZE)
101+
#define MBED_RAM_SIZE 0x10000
102+
#endif
61103
62-
...
104+
/* The MEMORY section below describes the location and size of blocks of memory in the target.
105+
* Use this section to specify the memory regions available for allocation.
106+
*/
107+
MEMORY
108+
{
109+
ram (rwx) : ORIGIN = MBED_RAM_START, LENGTH = MBED_RAM_SIZE
110+
flash (rx) : ORIGIN = MBED_ROM_START, LENGTH = MBED_ROM_SIZE
111+
}
63112
...
64113
```
114+
### Linker Script example ARM
65115

66-
#### NON-SECURE Core Linker Script
67116
```
68-
...
69-
...
70-
MEMORY
71-
{
72-
/* The ram and flash regions control RAM and flash memory allocation for the NON-SECURE core.
73-
* You can change the memory allocation by editing the 'ram' and 'flash' regions.
74-
* Your changes must be aligned with the corresponding memory regions for the SECURE core in the
75-
* SECURE linker script.
76-
*/
77-
ram (rwx) : ORIGIN = 0x08011000, LENGTH = 0x36800
78-
flash (rx) : ORIGIN = 0x10080000, LENGTH = 0x78000
79-
80-
...
81-
...
117+
#if !defined(MBED_ROM_START)
118+
#define MBED_ROM_START 0x10000000
119+
#endif
120+
121+
#if !defined(MBED_ROM_SIZE)
122+
#define MBED_ROM_SIZE 0x78000
123+
#endif
124+
125+
#if !defined(MBED_RAM_START)
126+
#define MBED_RAM_START 0x08000000
127+
#endif
128+
129+
#if !defined(MBED_RAM_SIZE)
130+
#define MBED_RAM_SIZE 0x10000
131+
#endif
132+
133+
#define MBED_RAM0_START MBED_RAM_START
134+
#define MBED_RAM0_SIZE 0x100
135+
#define MBED_RAM1_START (MBED_RAM_START + MBED_RAM0_SIZE)
136+
#define MBED_RAM1_SIZE (MBED_RAM_SIZE - MBED_RAM0_SIZE)
137+
138+
LR_IROM1 MBED_ROM_START MBED_ROM_SIZE {
139+
ER_IROM1 MBED_ROM_START MBED_ROM_SIZE {
140+
*.o (RESET, +First)
141+
*(InRoot$$Sections)
142+
.ANY (+RO)
143+
}
144+
RW_IRAM0 MBED_RAM0_START UNINIT MBED_RAM0_SIZE { ;no init section
145+
*(*nvictable)
146+
}
147+
RW_IRAM1 MBED_RAM1_START MBED_RAM1_SIZE {
148+
.ANY (+RW +ZI)
149+
}
82150
}
151+
```
152+
### Linker Script example IAR
83153

84-
...
85-
...
86154
```
155+
if (!isdefinedsymbol(MBED_ROM_START)) {
156+
define symbol MBED_ROM_START = 0x10000000;
157+
}
158+
159+
if (!isdefinedsymbol(MBED_ROM_SIZE)) {
160+
define symbol MBED_ROM_SIZE = 0x78000;
161+
}
162+
163+
if (!isdefinedsymbol(MBED_RAM_START)) {
164+
define symbol MBED_RAM_START = 0x08000000;
165+
}
166+
167+
if (!isdefinedsymbol(MBED_RAM_SIZE)) {
168+
define symbol MBED_RAM_SIZE = 0x10000;
169+
}
87170
171+
/* RAM */
172+
define symbol __ICFEDIT_region_IRAM1_start__ = MBED_RAM_START;
173+
define symbol __ICFEDIT_region_IRAM1_end__ = (MBED_RAM_START + MBED_RAM_SIZE);
174+
175+
/* Flash */
176+
define symbol __ICFEDIT_region_IROM1_start__ = MBED_ROM_START;
177+
define symbol __ICFEDIT_region_IROM1_end__ = (MBED_ROM_START + MBED_ROM_SIZE);
178+
...
179+
```
88180

89181
## Mailbox
90182

@@ -115,10 +207,7 @@ Target specific code of silicon partners who wish to have SPM capabilities must:
115207
- Implement a list of functions which are being called by SPM code
116208
- Call other functions supplied by ARM
117209

118-
The HAL can be logically divided into 3 different fields:
119-
120-
#### Addresses
121-
This part of HAL allows the silicon partner to share the addresses set in the linker scripts with the SPM code. The SPM uses these addresses mostly to enforce access permissions.
210+
The HAL can be logically divided into 2 different fields:
122211

123212
#### Mailbox
124213
This part of HAL allows the silicon partner to implement a thin layer of the mailbox mechanism which is specific to their platform.

0 commit comments

Comments
 (0)