aboutsummaryrefslogtreecommitdiff
path: root/platform/ext/common/gcc/tfm_isolation_l3.ld.template
blob: ccbe7bcf036a3f471c5e130c61f2446f363f36a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
;/*
; * Copyright (c) 2009-2021 Arm Limited
; *
; * Licensed under the Apache License, Version 2.0 (the "License");
; * you may not use this file except in compliance with the License.
; * You may obtain a copy of the License at
; *
; *     http://www.apache.org/licenses/LICENSE-2.0
; *
; * Unless required by applicable law or agreed to in writing, software
; * distributed under the License is distributed on an "AS IS" BASIS,
; * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; * See the License for the specific language governing permissions and
; * limitations under the License.
; *
; *
; * This file is derivative of CMSIS V5.00 gcc_arm.ld
; */

{{utilities.donotedit_warning}}

/* Linker script to configure memory regions. */
/* This file will be run trough the pre-processor. */

#include "region_defs.h"

MEMORY
{
  FLASH    (rx)  : ORIGIN = S_CODE_START, LENGTH = S_CODE_SIZE
  RAM      (rwx) : ORIGIN = S_DATA_START, LENGTH = S_DATA_SIZE
#if defined(S_CODE_SRAM_ALIAS_BASE)
  CODE_RAM (rwx) : ORIGIN = S_CODE_SRAM_ALIAS_BASE, LENGTH = TOTAL_CODE_SRAM_SIZE
#endif
  VENEERS  (rx)  : ORIGIN = CMSE_VENEER_REGION_START, LENGTH = CMSE_VENEER_REGION_SIZE
}

__heap_size__  = S_HEAP_SIZE;
__psp_stack_size__ = S_PSP_STACK_SIZE;
__msp_init_stack_size__ = S_MSP_STACK_SIZE_INIT;

/* Library configurations */
GROUP(libgcc.a libc.a libm.a libnosys.a libc_nano.a)

ENTRY(Reset_Handler)

SECTIONS
{
    .TFM_VECTORS : ALIGN(4)
    {
        __vectors_start__ = .;
        KEEP(*(.vectors))
        __vectors_end__ = .;
        *startup*(.text*)
        . = ALIGN(4);
    } > FLASH

    .copy.table : ALIGN(4)
    {
        __copy_table_start__ = .;
        LONG (LOADADDR(.TFM_DATA))
        LONG (ADDR(.TFM_DATA))
        LONG (SIZEOF(.TFM_DATA))
{% for partition in partitions %}
    {% if partition.attr.conditional %}
#ifdef {{partition.attr.conditional}}
    {% endif %}
        LONG (LOADADDR(.ER_{{partition.manifest.name}}_RWZI))
        LONG (ADDR(.ER_{{partition.manifest.name}}_RWZI))
        LONG (SIZEOF(.ER_{{partition.manifest.name}}_RWZI))
    {% if partition.attr.conditional %}
#endif /* {{partition.attr.conditional}} */
    {% endif %}
{% endfor %}
#if defined(S_CODE_SRAM_ALIAS_BASE)
        LONG (LOADADDR(.ER_EFLASH_DRIVER_RO))
        LONG (ADDR(.ER_EFLASH_DRIVER_RO))
        LONG (SIZEOF(.ER_EFLASH_DRIVER_RO))
#endif
        __copy_table_end__ = .;
    } > FLASH

    .zero.table : ALIGN(4)
    {
        __zero_table_start__ = .;
        LONG (ADDR(.TFM_BSS))
        LONG (SIZEOF(.TFM_BSS))
{% for partition in partitions %}
    {% if partition.attr.conditional %}
#ifdef {{partition.attr.conditional}}
    {% endif %}
        LONG (ADDR(.{{partition.manifest.name}}_RWZI_BSS))
        LONG (SIZEOF(.{{partition.manifest.name}}_RWZI_BSS))
        {% if partition.attr.conditional %}
#endif /* {{partition.attr.conditional}} */
    {% endif %}
{% endfor %}
        __zero_table_end__ = .;
    } > FLASH

    /* Position tag */
    . = ALIGN(32);
    Image$$PT_RO_START$$Base = .;

    /**** Section for holding partition static RO data */
    .TFM_SP_STATIC_LIST : ALIGN(4)
    {
       KEEP(*(.partition_info))
    } > FLASH
    Image$$TFM_SP_STATIC_LIST$$RO$$Base = ADDR(.TFM_SP_STATIC_LIST);
    Image$$TFM_SP_STATIC_LIST$$RO$$Limit = ADDR(.TFM_SP_STATIC_LIST) + SIZEOF(.TFM_SP_STATIC_LIST);
    . = ALIGN(32);

    /**** PSA RoT RO CODE + RO-data starts here */
{% for partition in partitions %}
    {% if partition.manifest.type == 'PSA-ROT' %}
    {% if partition.attr.conditional %}
#ifdef {{partition.attr.conditional}}
    {% endif %}
    .{{partition.manifest.name}}_RO : ALIGN(32)
    {
    {% if partition.attr.linker_pattern.library_list %}
        {% for pattern in partition.attr.linker_pattern.library_list %}
        {{pattern}}:*(.text*)
        {{pattern}}:*(.rodata*)
        {% endfor %}
    {% endif %}
    {% if partition.attr.linker_pattern.object_list %}
        {% for pattern in partition.attr.linker_pattern.object_list %}
        {{pattern}}(.text*)
        {{pattern}}:*(.rodata*)
        {% endfor %}
    {% endif %}
        *({{partition.manifest.name}}_PSA-ROT_ATTR_FN)
        . = ALIGN(32);
    } > FLASH
    Image$${{partition.manifest.name}}_RO$$Base = ADDR(.{{partition.manifest.name}}_RO);
    Image$${{partition.manifest.name}}_RO$$Limit = ADDR(.{{partition.manifest.name}}_RO) + SIZEOF(.{{partition.manifest.name}}_RO);
    {% if partition.attr.conditional %}
#endif /* {{partition.attr.conditional}} */
    {% endif %}

    {% endif %}
{% endfor %}
    /**** PSA RoT RO CODE + data ends here */

    /**** APPLICATION RoT RO CODE + data starts here */
{% for partition in partitions %}
    {% if partition.manifest.type == 'APPLICATION-ROT' %}
    {% if partition.attr.conditional %}
#ifdef {{partition.attr.conditional}}
    {% endif %}
    .{{partition.manifest.name}}_RO : ALIGN(32)
    {
    {% if partition.attr.linker_pattern.library_list %}
        {% for pattern in partition.attr.linker_pattern.library_list %}
        {{pattern}}:*(.text*)
        {{pattern}}:*(.rodata*)
        {% endfor %}
    {% endif %}
    {% if partition.attr.linker_pattern.object_list %}
        {% for pattern in partition.attr.linker_pattern.object_list %}
        {{pattern}}(.text*)
        {{pattern}}:*(.rodata*)
        {% endfor %}
    {% endif %}
        *({{partition.manifest.name}}_APP-ROT_ATTR_FN)
        . = ALIGN(32);
    } > FLASH
    Image$${{partition.manifest.name}}_CODE$$Base = ADDR(.{{partition.manifest.name}}_RO);
    Image$${{partition.manifest.name}}_CODE$$Limit = ADDR(.{{partition.manifest.name}}_RO) + SIZEOF(.{{partition.manifest.name}}_RO);
    {% if partition.attr.conditional %}
#endif /* {{partition.attr.conditional}} */
    {% endif %}

    {% endif %}
{% endfor %}
    /**** APPLICATION RoT RO CODE + data ends here */

    /**** Unprivileged Secure code starts here */
    .ER_UNPRIV_CODE : ALIGN(32)
    {
        *(SFN)
        *armlib*:*(.text*)
        *armlib*:*(.rodata*)
        *libtfm_sprt*:*(.text*)
        *libtfm_sprt*:*(.rodata*)
        *psa_client.*(.text*)              /* NXP */
        *psa_client.*(.rodata*)
        *psa_service.*(.text*)             /* NXP */
        *psa_service.*(.rodata*)
        *psa_lifecycle.*(.text*)             /* NXP */
        *psa_lifecycle.*(.rodata*)
        . = ALIGN(32);
    } > FLASH
    Image$$TFM_UNPRIV_CODE$$RO$$Base = ADDR(.ER_UNPRIV_CODE);
    Image$$TFM_UNPRIV_CODE$$RO$$Limit = ADDR(.ER_UNPRIV_CODE) + SIZEOF(.ER_UNPRIV_CODE);

    .ER_TFM_CODE : ALIGN(4)
    {
        *(.text*)

        KEEP(*(.init))
        KEEP(*(.fini))


        /* .ctors */
        *crtbegin.o(.ctors)
        *crtbegin?.o(.ctors)
        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
        *(SORT(.ctors.*))
        *(.ctors)

        /* .dtors */
         *crtbegin.o(.dtors)
         *crtbegin?.o(.dtors)
         *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
         *(SORT(.dtors.*))
         *(.dtors)

        *(.rodata*)

        KEEP(*(.eh_frame*))
    } > FLASH

    /* Position tag */
    . = ALIGN(32);
    Image$$PT_RO_END$$Base = .;

#if defined(S_CODE_SRAM_ALIAS_BASE)
    .ER_EFLASH_DRIVER_RO : ALIGN(4)
    {
        *Driver_GFC100_EFlash.o(.text*)
        *Driver_GFC100_EFlash.o(.rodata*)
        *gfc100_eflash_drv.o(.text*)
        *gfc100_eflash_drv.o(.rodata*)
        *musca_b1_eflash_drv.o(.text*)
        *musca_b1_eflash_drv.o(.rodata*)
        . = ALIGN(4); /* This alignment is needed to make the section size 4 bytes aligned */
    } > CODE_RAM AT > FLASH
    Image$$ER_EFLASH_DRIVER_RO$$Base = ADDR(.ER_EFLASH_DRIVER_RO);
    Image$$ER_EFLASH_DRIVER_RO$$Limit = ADDR(.ER_EFLASH_DRIVER_RO) + SIZEOF(.ER_EFLASH_DRIVER_RO);
#endif

    .ARM.extab :
    {
        *(.ARM.extab* .gnu.linkonce.armextab.*)
    } > FLASH

    __exidx_start = .;
    .ARM.exidx :
    {
        *(.ARM.exidx* .gnu.linkonce.armexidx.*)
    } > FLASH
    __exidx_end = .;

    /**** Base address of secure data area */
    .tfm_secure_data_start :
    {
        . = ABSOLUTE(S_DATA_START) ;
    } > RAM

   /* Position tag */
    . = ALIGN(32);
    Image$$PT_PRIV_RWZI_START$$Base = .;

    /* shared_data and msp_stack are overlapping on purpose when
     * msp_stack is extended until the beginning of RAM, when shared_date
     * was read out by partitions
     */
    .tfm_bl2_shared_data : ALIGN(32)
    {
        . += BOOT_TFM_SHARED_DATA_SIZE;
    } > RAM

    .msp_stack : ALIGN(32)
    {
        . += __msp_init_stack_size__;
    } > RAM
    Image$$ARM_LIB_STACK_MSP$$ZI$$Base = ADDR(.msp_stack);
    Image$$ARM_LIB_STACK_MSP$$ZI$$Limit = ADDR(.msp_stack) + SIZEOF(.msp_stack);

    /**** PSA RoT DATA start here */
{% for partition in partitions %}
    {% if partition.manifest.type == 'PSA-ROT' %}
    {% if partition.attr.conditional %}
#ifdef {{partition.attr.conditional}}
    {% endif %}

    /* Position tag */
    . = ALIGN(32);
    Image$$PT_{{partition.manifest.name}}_PRIVATE_DATA_START$$Base = .;

    .ER_{{partition.manifest.name}}_RWZI : ALIGN(32)
    {
    {% if partition.attr.linker_pattern.library_list %}
        {% for pattern in partition.attr.linker_pattern.library_list %}
        {{pattern}}:*(.data*)
        {% endfor %}
    {% endif %}
    {% if partition.attr.linker_pattern.object_list %}
        {% for pattern in partition.attr.linker_pattern.object_list %}
        {{pattern}}(.data*)
        {% endfor %}
    {% endif %}
        *({{partition.manifest.name}}_PSA-ROT_ATTR_RW)
        . = ALIGN(32);
    } > RAM AT> FLASH
    Image$$ER_{{partition.manifest.name}}_RWZI$$RW$$Base = ADDR(.ER_{{partition.manifest.name}}_RWZI);
    Image$$ER_{{partition.manifest.name}}_RWZI$$RW$$Limit = ADDR(.ER_{{partition.manifest.name}}_RWZI) + SIZEOF(.ER_{{partition.manifest.name}}_RWZI);

    .{{partition.manifest.name}}_RWZI_BSS : ALIGN(32)
    {
        start_of_{{partition.manifest.name}}_RWZI = .;
    {% if partition.attr.linker_pattern.library_list %}
        {% for pattern in partition.attr.linker_pattern.library_list %}
        {{pattern}}:*(.bss*)
        {{pattern}}:*(COMMON)
        {% endfor %}
    {% endif %}
    {% if partition.attr.linker_pattern.object_list %}
        {% for pattern in partition.attr.linker_pattern.object_list %}
        {{pattern}}(.bss*)
        {{pattern}}(COMMON)
        {% endfor %}
    {% endif %}
        *({{partition.manifest.name}}_PSA-ROT_ATTR_ZI)
        . += (. - start_of_{{partition.manifest.name}}_RWZI) ? 0 : 4;
        . = ALIGN(32);
    } > RAM AT> RAM
    Image$$ER_{{partition.manifest.name}}_RWZI$$ZI$$Base = ADDR(.{{partition.manifest.name}}_RWZI_BSS);
    Image$$ER_{{partition.manifest.name}}_RWZI$$ZI$$Limit = ADDR(.{{partition.manifest.name}}_RWZI_BSS) + SIZEOF(.{{partition.manifest.name}}_RWZI_BSS);

    /* Position tag */
    . = ALIGN(32);
    Image$$PT_{{partition.manifest.name}}_PRIVATE_DATA_END$$Base = .;

    {% if partition.attr.conditional %}
#endif /* {{partition.attr.conditional}} */
    {% endif %}

    {% endif %}
{% endfor %}
    /**** PSA RoT DATA end here */
    . = ALIGN(32);

    /* Position tag */
    Image$$PT_PRIV_RWZI_END$$Base = .;

    /* PSP is unprivileged in single-core topology */
    .psp_stack : ALIGN(32)
    {
        . += (__psp_stack_size__);
    } > RAM
    Image$$ARM_LIB_STACK$$ZI$$Base = ADDR(.psp_stack);
    Image$$ARM_LIB_STACK$$ZI$$Limit = ADDR(.psp_stack) + SIZEOF(.psp_stack);

    /**** APPLICATION RoT DATA start here */
{% for partition in partitions %}
    {% if partition.manifest.type == 'APPLICATION-ROT' %}
    {% if partition.attr.conditional %}
#ifdef {{partition.attr.conditional}}
    {% endif %}

    /* Position tag */
    . = ALIGN(32);
    Image$$PT_{{partition.manifest.name}}_PRIVATE_DATA_START$$Base = .;

    .ER_{{partition.manifest.name}}_RWZI : ALIGN(32)
    {
    {% if partition.attr.linker_pattern.library_list %}
        {% for pattern in partition.attr.linker_pattern.library_list %}
        {{pattern}}:*(.data*)
        {% endfor %}
    {% endif %}
    {% if partition.attr.linker_pattern.object_list %}
        {% for pattern in partition.attr.linker_pattern.object_list %}
        {{pattern}}(.data*)
        {% endfor %}
    {% endif %}
        *({{partition.manifest.name}}_APP-ROT_ATTR_RW)
        . = ALIGN(32);
    } > RAM AT> FLASH
    Image$$.ER_{{partition.manifest.name}}_RWZI$$RW$$Base = ADDR(.ER_{{partition.manifest.name}}_RWZI);
    Image$$.ER_{{partition.manifest.name}}_RWZI$$RW$$Limit = ADDR(.ER_{{partition.manifest.name}}_RWZI) + SIZEOF(.ER_{{partition.manifest.name}}_RWZI);

    .{{partition.manifest.name}}_RWZI_BSS : ALIGN(32)
    {
        start_of_{{partition.manifest.name}}_RWZI = .;
    {% if partition.attr.linker_pattern.library_list %}
        {% for pattern in partition.attr.linker_pattern.library_list %}
        {{pattern}}:*(.bss*)
        {{pattern}}:*(COMMON)
        {% endfor %}
    {% endif %}
    {% if partition.attr.linker_pattern.object_list %}
        {% for pattern in partition.attr.linker_pattern.object_list %}
        {{pattern}}(.bss*)
        {{pattern}}(COMMON)
        {% endfor %}
    {% endif %}
        *({{partition.manifest.name}}_APP-ROT_ATTR_ZI)
        . += (. - start_of_{{partition.manifest.name}}_RWZI) ? 0 : 4;
        . = ALIGN(32);
    } > RAM AT> RAM
    Image$$ER_{{partition.manifest.name}}_RWZI$$ZI$$Base = ADDR(.{{partition.manifest.name}}_RWZI_BSS);
    Image$$ER_{{partition.manifest.name}}_RWZI$$ZI$$Limit = ADDR(.{{partition.manifest.name}}_RWZI_BSS) + SIZEOF(.{{partition.manifest.name}}_RWZI_BSS);

    /* Position tag */
    . = ALIGN(32);
    Image$$PT_{{partition.manifest.name}}_PRIVATE_DATA_END$$Base = .;

    {% if partition.attr.conditional %}
#endif /* {{partition.attr.conditional}} */
    {% endif %}

    {% endif %}
{% endfor %}
    /**** APPLICATION RoT DATA end here */

    /* Position tag */
    . = ALIGN(32);
    Image$$PT_APP_RWZI_END$$Base = .;

#ifdef TFM_PARTITION_TEST_SECURE_SERVICES
    .TFM_SP_SECURE_TEST_PARTITION_LINKER_DATA : ALIGN(32)
    {
        *libc_nano*:*(.data*)
        . = ALIGN(32);
    } > RAM AT> FLASH

    .TFM_SP_SECURE_TEST_PARTITION_LINKER_BSS : ALIGN(32)
    {
        /* FixMe:
         * Test framework use printf to print out test result. Implementation of
         * printf in GCC libc use static data and heap as well. To be able to
         * execute test suites with TFM_LVL=3 this workaround is needed to
         * allocate libc static data and heap within the data section of secure
         * test partition. This can be removed if test service will be executed
         * in privileged mode.
         */
        *libc_nano*:*(.bss*)
        *libc_nano*:*(COMMON)

        __end__ = .;
        PROVIDE(end = .);
        __HeapBase = .;
        . += __heap_size__;
        __HeapLimit = .;
        __heap_limit = .; /* Add for _sbrk */

        . = ALIGN(32);
    } > RAM AT> RAM
#else /* TFM_PARTITION_TEST_SECURE_SERVICES */
    .heap : ALIGN(8)
    {
        __end__ = .;
        PROVIDE(end = .);
        __HeapBase = .;
        . += __heap_size__;
        __HeapLimit = .;
        __heap_limit = .; /* Add for _sbrk */
    } > RAM AT> RAM
#endif /* TFM_PARTITION_TEST_SECURE_SERVICES */

    .TFM_DATA : ALIGN(4)
    {
        *(.data*)

        . = ALIGN(4);
        /* preinit data */
        PROVIDE_HIDDEN (__preinit_array_start = .);
        KEEP(*(.preinit_array))
        PROVIDE_HIDDEN (__preinit_array_end = .);

        . = ALIGN(4);
        /* init data */
        PROVIDE_HIDDEN (__init_array_start = .);
        KEEP(*(SORT(.init_array.*)))
        KEEP(*(.init_array))
        PROVIDE_HIDDEN (__init_array_end = .);

        . = ALIGN(4);
        /* finit data */
        PROVIDE_HIDDEN (__fini_array_start = .);
        KEEP(*(SORT(.fini_array.*)))
        KEEP(*(.fini_array))
        PROVIDE_HIDDEN (__fini_array_end = .);

        KEEP(*(.jcr*))
        . = ALIGN(4);

    } > RAM AT> FLASH
    Image$$ER_TFM_DATA$$RW$$Base = ADDR(.TFM_DATA);
    Image$$ER_TFM_DATA$$RW$$Limit = ADDR(.TFM_DATA) + SIZEOF(.TFM_DATA);

    .TFM_BSS : ALIGN(4)
    {
        __bss_start__ = .;
        *(.bss*)
        *(COMMON)
        . = ALIGN(4);
        __bss_end__ = .;
    } > RAM AT> RAM
    Image$$ER_TFM_DATA$$ZI$$Base = ADDR(.TFM_BSS);
    Image$$ER_TFM_DATA$$ZI$$Limit = ADDR(.TFM_BSS) + SIZEOF(.TFM_BSS);

    Image$$ER_TFM_DATA$$Base = ADDR(.TFM_DATA);
    Image$$ER_TFM_DATA$$Limit = ADDR(.TFM_DATA) + SIZEOF(.TFM_DATA) + SIZEOF(.TFM_BSS);

    /*
     * Place the CMSE Veneers (containing the SG instruction) after the code, in a
     * separate 32 bytes aligned region so that the SAU can programmed to just set
     * this region as Non-Secure Callable.
     */
    .gnu.sgstubs : ALIGN(32)
    {
        *(.gnu.sgstubs*)
        . = ALIGN(32);
    } > VENEERS AT> VENEERS
    Load$$LR$$LR_VENEER$$Base = ADDR(.gnu.sgstubs);
    Load$$LR$$LR_VENEER$$Limit = ADDR(.gnu.sgstubs) + SIZEOF(.gnu.sgstubs);

    Load$$LR$$LR_NS_PARTITION$$Base = NS_PARTITION_START;

#ifdef BL2
    Load$$LR$$LR_SECONDARY_PARTITION$$Base = SECONDARY_PARTITION_START;
#endif /* BL2 */

    PROVIDE(__stack = Image$$ARM_LIB_STACK$$ZI$$Limit);
}