Skip to content

Commit eb9d124

Browse files
AlessandroAmeriac
authored andcommitted
K64F: Add uVisor sections to the linker script
This commit includes all sections that are just added to the linker script. These changes are backwards-compatible, meaning that they will not affect the existing code. Targets that do not support uVisor will leave those sections empty.
1 parent f81cf5d commit eb9d124

File tree

1 file changed

+92
-5
lines changed

1 file changed

+92
-5
lines changed

hal/targets/cmsis/TARGET_Freescale/TARGET_K64F/TOOLCHAIN_GCC_ARM/MK64FN1M0xxx12.ld

Lines changed: 92 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ SECTIONS
9292
/* The program code and other data goes into internal flash */
9393
.text :
9494
{
95+
/* uVisor code and data */
96+
. = ALIGN(4);
97+
__uvisor_main_start = .;
98+
*(.uvisor.main)
99+
__uvisor_main_end = .;
100+
95101
. = ALIGN(4);
96102
*(.text) /* .text sections (code) */
97103
*(.text*) /* .text* sections (code) */
@@ -175,9 +181,6 @@ SECTIONS
175181
PROVIDE_HIDDEN (__fini_array_end = .);
176182
} > m_text
177183

178-
__etext = .; /* define a global symbol at end of code */
179-
__DATA_ROM = .; /* Symbol is used by startup for data initialization */
180-
181184
.interrupts_ram :
182185
{
183186
. = ALIGN(4);
@@ -189,11 +192,44 @@ SECTIONS
189192
__interrupts_ram_end__ = .; /* Define a global symbol at data end */
190193
} > m_data
191194

195+
/* Ensure that the uVisor BSS section is put first after the relocated
196+
* interrupt table in SRAM. */
197+
/* Note: The uVisor expects this section at a fixed location, as specified by
198+
* the porting process configuration parameter: SRAM_OFFSET. */
199+
__UVISOR_SRAM_OFFSET = 0x400;
200+
__UVISOR_BSS_START = ORIGIN(m_data) + __UVISOR_SRAM_OFFSET;
201+
ASSERT(__interrupts_ram_end__ <= __UVISOR_BSS_START,
202+
"The ISR relocation region overlaps with the uVisor BSS section.")
203+
.uvisor.bss (NOLOAD):
204+
{
205+
. = ALIGN(32);
206+
__uvisor_bss_start = .;
207+
208+
/* protected uvisor main bss */
209+
. = ALIGN(32);
210+
__uvisor_bss_main_start = .;
211+
KEEP(*(.keep.uvisor.bss.main))
212+
. = ALIGN(32);
213+
__uvisor_bss_main_end = .;
214+
215+
/* protected uvisor secure boxes bss */
216+
. = ALIGN(32);
217+
__uvisor_bss_boxes_start = .;
218+
KEEP(*(.keep.uvisor.bss.boxes))
219+
. = ALIGN(32);
220+
__uvisor_bss_boxes_end = .;
221+
222+
. = ALIGN(32);
223+
__uvisor_bss_end = .;
224+
} > m_data
225+
192226
__VECTOR_RAM = DEFINED(__ram_vector_table__) ? __VECTOR_RAM__ : ORIGIN(m_interrupts);
193227
__RAM_VECTOR_TABLE_SIZE_BYTES = DEFINED(__ram_vector_table__) ? (__interrupts_ram_end__ - __interrupts_ram_start__) : 0x0;
194228

195-
.data : AT(__DATA_ROM)
229+
.data :
196230
{
231+
PROVIDE(__etext = LOADADDR(.data)); /* Define a global symbol at end of code, */
232+
PROVIDE(__DATA_ROM = LOADADDR(.data)); /* Symbol is used by startup for data initialization. */
197233
. = ALIGN(4);
198234
__DATA_RAM = .;
199235
__data_start__ = .; /* create a global symbol at data start */
@@ -202,12 +238,57 @@ SECTIONS
202238
KEEP(*(.jcr*))
203239
. = ALIGN(4);
204240
__data_end__ = .; /* define a global symbol at data end */
205-
} > m_data_2
241+
} > m_data_2 AT > m_text
206242

207243
__DATA_END = __DATA_ROM + (__data_end__ - __data_start__);
208244
text_end = ORIGIN(m_text) + LENGTH(m_text);
209245
ASSERT(__DATA_END <= text_end, "region m_text overflowed with text and data")
210246

247+
/* uVisor configuration section
248+
* This section must be located after all other flash regions. */
249+
.uvisor.secure :
250+
{
251+
. = ALIGN(32);
252+
__uvisor_secure_start = .;
253+
254+
/* uVisor secure boxes configuration tables */
255+
. = ALIGN(32);
256+
__uvisor_cfgtbl_start = .;
257+
KEEP(*(.keep.uvisor.cfgtbl))
258+
. = ALIGN(32);
259+
__uvisor_cfgtbl_end = .;
260+
261+
/* Pointers to the uVisor secure boxes configuration tables */
262+
/* Note: Do not add any further alignment here, as uVisor will need to have
263+
* access to the exact list of pointers. */
264+
__uvisor_cfgtbl_ptr_start = .;
265+
KEEP(*(.keep.uvisor.cfgtbl_ptr_first))
266+
KEEP(*(.keep.uvisor.cfgtbl_ptr))
267+
__uvisor_cfgtbl_ptr_end = .;
268+
269+
/* Pointers to all boxes register gateways. These are grouped here to allow
270+
* discoverability and firmware verification. */
271+
__uvisor_register_gateway_ptr_start = .;
272+
KEEP(*(.keep.uvisor.register_gateway_ptr))
273+
__uvisor_register_gateway_ptr_end = .;
274+
275+
. = ALIGN(32);
276+
__uvisor_secure_end = .;
277+
} > m_text
278+
279+
/* Uninitialized data section
280+
* This region is not initialized by the C/C++ library and can be used to
281+
* store state across soft reboots. */
282+
.uninitialized (NOLOAD):
283+
{
284+
. = ALIGN(32);
285+
__uninitialized_start = .;
286+
*(.uninitialized)
287+
KEEP(*(.keep.uninitialized))
288+
. = ALIGN(32);
289+
__uninitialized_end = .;
290+
} > m_data_2
291+
211292
USB_RAM_GAP = DEFINED(__usb_ram_size__) ? __usb_ram_size__ : 0x800;
212293
/* Uninitialized data section */
213294
.bss :
@@ -263,5 +344,11 @@ SECTIONS
263344
.ARM.attributes 0 : { *(.ARM.attributes) }
264345

265346
ASSERT(__StackLimit >= __HeapLimit, "region m_data_2 overflowed with stack and heap")
347+
348+
/* Provide the physical memory boundaries for uVisor. */
349+
__uvisor_flash_start = ORIGIN(m_interrupts);
350+
__uvisor_flash_end = ORIGIN(m_text) + LENGTH(m_text);
351+
__uvisor_sram_start = ORIGIN(m_data);
352+
__uvisor_sram_end = ORIGIN(m_data_2) + LENGTH(m_data_2);
266353
}
267354

0 commit comments

Comments
 (0)