1/*
2 * Copyright 2021, 2024 NXP
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7/**
8 * @file
9 * @brief Linker command/script file
10 *
11 * Linker script for the NXP i.MX8 platform
12 */
13
14OUTPUT_ARCH(xtensa)
15
16#include <zephyr/devicetree.h>
17#include <xtensa/config/core-isa.h>
18#include <memory.h>
19#include <zephyr/linker/sections.h>
20
21#include <zephyr/linker/linker-defs.h>
22#include <zephyr/linker/linker-tool.h>
23
24PROVIDE(__memctl_default = 0x00000000);
25PROVIDE(_MemErrorHandler = 0x00000000);
26
27#define RAMABLE_REGION sdram0 :sdram0_phdr
28#define ROMABLE_REGION sdram0 :sdram0_phdr
29
30MEMORY
31{
32  vector_reset_text :
33        org = XCHAL_RESET_VECTOR0_PADDR_IRAM,
34        len = MEM_RESET_TEXT_SIZE
35  vector_reset_lit :
36        org = XCHAL_RESET_VECTOR0_PADDR_IRAM + MEM_RESET_TEXT_SIZE,
37        len = MEM_RESET_LIT_SIZE
38  vector_base_text :
39	org = XCHAL_VECBASE_RESET_PADDR_IRAM,
40        len = MEM_VECBASE_LIT_SIZE
41  vector_int2_lit :
42	org = XCHAL_INTLEVEL2_VECTOR_PADDR_IRAM - MEM_VECT_LIT_SIZE,
43        len = MEM_VECT_LIT_SIZE
44  vector_int2_text :
45	org = XCHAL_INTLEVEL2_VECTOR_PADDR_IRAM,
46        len = MEM_VECT_TEXT_SIZE
47  vector_int3_lit :
48	org = XCHAL_INTLEVEL3_VECTOR_PADDR_IRAM - MEM_VECT_LIT_SIZE,
49        len = MEM_VECT_LIT_SIZE
50  vector_int3_text :
51	org = XCHAL_INTLEVEL3_VECTOR_PADDR_IRAM,
52        len = MEM_VECT_TEXT_SIZE
53  vector_int4_lit :
54	org = XCHAL_INTLEVEL4_VECTOR_PADDR_IRAM - MEM_VECT_LIT_SIZE,
55        len = MEM_VECT_LIT_SIZE
56  vector_int4_text :
57	org = XCHAL_INTLEVEL4_VECTOR_PADDR_IRAM,
58        len = MEM_VECT_TEXT_SIZE
59  vector_int5_lit :
60	org = XCHAL_INTLEVEL5_VECTOR_PADDR_IRAM - MEM_VECT_LIT_SIZE,
61        len = MEM_VECT_LIT_SIZE
62  vector_int5_text :
63	org = XCHAL_INTLEVEL5_VECTOR_PADDR_IRAM,
64        len = MEM_VECT_TEXT_SIZE
65  vector_kernel_lit :
66	org = XCHAL_KERNEL_VECTOR_PADDR_IRAM - MEM_VECT_LIT_SIZE,
67        len = MEM_VECT_LIT_SIZE
68  vector_kernel_text :
69	org = XCHAL_KERNEL_VECTOR_PADDR_IRAM,
70        len = MEM_VECT_TEXT_SIZE
71  vector_user_lit :
72	org = XCHAL_USER_VECTOR_PADDR_IRAM - MEM_VECT_LIT_SIZE,
73        len = MEM_VECT_LIT_SIZE
74  vector_user_text :
75	org = XCHAL_USER_VECTOR_PADDR_IRAM,
76        len = MEM_VECT_TEXT_SIZE
77  vector_double_lit :
78	org = XCHAL_DOUBLEEXC_VECTOR_PADDR_IRAM - MEM_VECT_LIT_SIZE,
79        len = MEM_VECT_LIT_SIZE
80  vector_double_text :
81	org = XCHAL_DOUBLEEXC_VECTOR_PADDR_IRAM,
82        len = MEM_VECT_TEXT_SIZE
83  iram_text_start :
84	org = XCHAL_DOUBLEEXC_VECTOR_PADDR_IRAM + MEM_VECT_TEXT_SIZE,
85        len = (IRAM_BASE + IRAM_SIZE) - (XCHAL_DOUBLEEXC_VECTOR_PADDR + MEM_VECT_TEXT_SIZE)
86  sdram0 :
87	org = SDRAM0_BASE,
88        len = SDRAM0_SIZE
89  sdram1 :
90	org = SDRAM1_BASE + SOF_MAILBOX_SIZE,
91        len = SDRAM1_SIZE - SOF_MAILBOX_SIZE
92#ifdef CONFIG_GEN_ISR_TABLES
93  IDT_LIST :
94	org = IDT_BASE,
95        len = IDT_SIZE
96#endif
97
98  static_uuid_entries_seg (!ari) :
99        org = UUID_ENTRY_ELF_BASE,
100        len = UUID_ENTRY_ELF_SIZE
101  static_log_entries_seg (!ari) :
102        org = LOG_ENTRY_ELF_BASE,
103        len = LOG_ENTRY_ELF_SIZE
104  fw_metadata_seg (!ari) :
105        org = EXT_MANIFEST_ELF_BASE,
106        len = EXT_MANIFEST_ELF_SIZE
107}
108
109PHDRS
110{
111  vector_reset_text_phdr PT_LOAD;
112  vector_reset_lit_phdr PT_LOAD;
113  vector_base_text_phdr PT_LOAD;
114  vector_base_lit_phdr PT_LOAD;
115  vector_int2_text_phdr PT_LOAD;
116  vector_int2_lit_phdr PT_LOAD;
117  vector_int3_text_phdr PT_LOAD;
118  vector_int3_lit_phdr PT_LOAD;
119  vector_int4_text_phdr PT_LOAD;
120  vector_int4_lit_phdr PT_LOAD;
121  vector_int5_text_phdr PT_LOAD;
122  vector_int5_lit_phdr PT_LOAD;
123  vector_kernel_text_phdr PT_LOAD;
124  vector_kernel_lit_phdr PT_LOAD;
125  vector_user_text_phdr PT_LOAD;
126  vector_user_lit_phdr PT_LOAD;
127  vector_double_text_phdr PT_LOAD;
128  vector_double_lit_phdr PT_LOAD;
129  iram_text_start_phdr PT_LOAD;
130  sdram0_phdr PT_LOAD;
131  sdram1_phdr PT_LOAD;
132  static_uuid_entries_phdr PT_NOTE;
133  static_log_entries_phdr PT_NOTE;
134  metadata_entries_phdr PT_NOTE;
135}
136
137_rom_store_table = 0;
138
139PROVIDE(_memmap_vecbase_reset = XCHAL_VECBASE_RESET_PADDR);
140
141ENTRY(CONFIG_KERNEL_ENTRY)
142
143/* Various memory-map dependent cache attribute settings: */
144_memmap_cacheattr_wb_base = 0x44024000;
145_memmap_cacheattr_wt_base = 0x11021000;
146_memmap_cacheattr_bp_base = 0x22022000;
147_memmap_cacheattr_unused_mask = 0x00F00FFF;
148_memmap_cacheattr_wb_trapnull = 0x4422422F;
149_memmap_cacheattr_wba_trapnull = 0x4422422F;
150_memmap_cacheattr_wbna_trapnull = 0x25222222;
151_memmap_cacheattr_wt_trapnull = 0x1122122F;
152_memmap_cacheattr_bp_trapnull = 0x2222222F;
153_memmap_cacheattr_wb_strict = 0x44F24FFF;
154_memmap_cacheattr_wt_strict = 0x11F21FFF;
155_memmap_cacheattr_bp_strict = 0x22F22FFF;
156_memmap_cacheattr_wb_allvalid = 0x44224222;
157_memmap_cacheattr_wt_allvalid = 0x11221222;
158_memmap_cacheattr_bp_allvalid = 0x22222222;
159/*
160 * Every 512M in 4GB space has dedicate cache attribute.
161 * 1: write through
162 * 2: cache bypass
163 * 4: write back
164 * F: invalid access
165 */
166_memmap_cacheattr_imx8_wt_allvalid = 0x22212222;
167PROVIDE(_memmap_cacheattr_reset = _memmap_cacheattr_imx8_wt_allvalid);
168
169_EXT_MAN_ALIGN_ = 16;
170EXTERN(ext_man_fw_ver)
171
172SECTIONS
173{
174#ifdef CONFIG_OPENAMP_RSC_TABLE
175    SECTION_PROLOGUE(.resource_table,, SUBALIGN(4))
176    {
177      KEEP(*(.resource_table*))
178    } GROUP_LINK_IN(ROMABLE_REGION)
179#endif
180
181#include <zephyr/linker/rel-sections.ld>
182
183#ifdef CONFIG_LLEXT
184#include <zephyr/linker/llext-sections.ld>
185#endif
186  .ResetVector.text : ALIGN(4)
187  {
188    _ResetVector_text_start = ABSOLUTE(.);
189    KEEP (*(.ResetVector.text))
190    _ResetVector_text_end = ABSOLUTE(.);
191  } >vector_reset_text :vector_reset_text_phdr
192
193  .ResetVector.literal : ALIGN(4)
194  {
195    _ResetVector_literal_start = ABSOLUTE(.);
196    *(.ResetVector.literal)
197    _ResetVector_literal_end = ABSOLUTE(.);
198  } >vector_reset_lit :vector_reset_lit_phdr
199
200  .WindowVectors.text : ALIGN(4)
201  {
202    _WindowVectors_text_start = ABSOLUTE(.);
203    KEEP (*(.WindowVectors.text))
204    _WindowVectors_text_end = ABSOLUTE(.);
205  } >vector_base_text :vector_base_text_phdr
206
207  .Level2InterruptVector.literal : ALIGN(4)
208  {
209    _Level2InterruptVector_literal_start = ABSOLUTE(.);
210    *(.Level2InterruptVector.literal)
211    _Level2InterruptVector_literal_end = ABSOLUTE(.);
212  } >vector_int2_lit :vector_int2_lit_phdr
213
214  .Level2InterruptVector.text : ALIGN(4)
215  {
216    _Level2InterruptVector_text_start = ABSOLUTE(.);
217    KEEP (*(.Level2InterruptVector.text))
218    _Level2InterruptVector_text_end = ABSOLUTE(.);
219  } >vector_int2_text :vector_int2_text_phdr
220
221  .Level3InterruptVector.literal : ALIGN(4)
222  {
223    _Level3InterruptVector_literal_start = ABSOLUTE(.);
224    *(.Level3InterruptVector.literal)
225    _Level3InterruptVector_literal_end = ABSOLUTE(.);
226  } >vector_int3_lit :vector_int3_lit_phdr
227
228  .Level3InterruptVector.text : ALIGN(4)
229  {
230    _Level3InterruptVector_text_start = ABSOLUTE(.);
231    KEEP (*(.Level3InterruptVector.text))
232    _Level3InterruptVector_text_end = ABSOLUTE(.);
233  } >vector_int3_text :vector_int3_text_phdr
234
235  .DebugExceptionVector.literal : ALIGN(4)
236  {
237    _DebugExceptionVector_literal_start = ABSOLUTE(.);
238    *(.DebugExceptionVector.literal)
239    _DebugExceptionVector_literal_end = ABSOLUTE(.);
240  } >vector_int4_lit :vector_int4_lit_phdr
241
242  .DebugExceptionVector.text : ALIGN(4)
243  {
244    _DebugExceptionVector_text_start = ABSOLUTE(.);
245    KEEP (*(.DebugExceptionVector.text))
246    _DebugExceptionVector_text_end = ABSOLUTE(.);
247  } >vector_int4_text :vector_int4_text_phdr
248
249  .NMIExceptionVector.literal : ALIGN(4)
250  {
251    _NMIExceptionVector_literal_start = ABSOLUTE(.);
252    *(.NMIExceptionVector.literal)
253    _NMIExceptionVector_literal_end = ABSOLUTE(.);
254  } >vector_int5_lit :vector_int5_lit_phdr
255
256  .NMIExceptionVector.text : ALIGN(4)
257  {
258    _NMIExceptionVector_text_start = ABSOLUTE(.);
259    KEEP (*(.NMIExceptionVector.text))
260    _NMIExceptionVector_text_end = ABSOLUTE(.);
261  } >vector_int5_text :vector_int5_text_phdr
262
263  .KernelExceptionVector.literal : ALIGN(4)
264  {
265    _KernelExceptionVector_literal_start = ABSOLUTE(.);
266    *(.KernelExceptionVector.literal)
267    _KernelExceptionVector_literal_end = ABSOLUTE(.);
268  } >vector_kernel_lit :vector_kernel_lit_phdr
269
270  .KernelExceptionVector.text : ALIGN(4)
271  {
272    _KernelExceptionVector_text_start = ABSOLUTE(.);
273    KEEP (*(.KernelExceptionVector.text))
274    _KernelExceptionVector_text_end = ABSOLUTE(.);
275  } >vector_kernel_text :vector_kernel_text_phdr
276
277  .UserExceptionVector.literal : ALIGN(4)
278  {
279    _UserExceptionVector_literal_start = ABSOLUTE(.);
280    *(.UserExceptionVector.literal)
281    _UserExceptionVector_literal_end = ABSOLUTE(.);
282  } >vector_user_lit :vector_user_lit_phdr
283
284  .UserExceptionVector.text : ALIGN(4)
285  {
286    _UserExceptionVector_text_start = ABSOLUTE(.);
287    KEEP (*(.UserExceptionVector.text))
288    _UserExceptionVector_text_end = ABSOLUTE(.);
289  } >vector_user_text :vector_user_text_phdr
290
291  .DoubleExceptionVector.literal : ALIGN(4)
292  {
293    _DoubleExceptionVector_literal_start = ABSOLUTE(.);
294    *(.DoubleExceptionVector.literal)
295    _DoubleExceptionVector_literal_end = ABSOLUTE(.);
296  } >vector_double_lit :vector_double_lit_phdr
297
298  .DoubleExceptionVector.text : ALIGN(4)
299  {
300    _DoubleExceptionVector_text_start = ABSOLUTE(.);
301    KEEP (*(.DoubleExceptionVector.text))
302    _DoubleExceptionVector_text_end = ABSOLUTE(.);
303  } >vector_double_text :vector_double_text_phdr
304
305  .iram.text : ALIGN(4)
306  {
307    _stext = .;
308    _iram_text_start = ABSOLUTE(.);
309    *(.iram0.literal .iram.literal .iram.text.literal .iram0.text .iram.text)
310    _iram_text_end = ABSOLUTE(.);
311  } >iram_text_start :iram_text_start_phdr
312
313  .rodata : ALIGN(4)
314  {
315    __rodata_region_start = ABSOLUTE(.);
316    *(.rodata)
317    *(.rodata.*)
318    *(.gnu.linkonce.r.*)
319    *(.rodata1)
320    __XT_EXCEPTION_TABLE__ = ABSOLUTE(.);
321    KEEP (*(.xt_except_table))
322    KEEP (*(.gcc_except_table .gcc_except_table.*))
323    *(.gnu.linkonce.e.*)
324    *(.gnu.version_r)
325    KEEP (*(.eh_frame))
326    KEEP (*crtbegin.o(.ctors))
327    KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
328    KEEP (*(SORT(.ctors.*)))
329    KEEP (*(.ctors))
330    KEEP (*crtbegin.o(.dtors))
331    KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
332    KEEP (*(SORT(.dtors.*)))
333    KEEP (*(.dtors))
334    __XT_EXCEPTION_DESCS__ = ABSOLUTE(.);
335    *(.xt_except_desc)
336    *(.gnu.linkonce.h.*)
337    __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.);
338    *(.xt_except_desc_end)
339    *(.dynamic)
340    *(.gnu.version_d)
341    . = ALIGN(4);
342    _bss_table_start = ABSOLUTE(.);
343    LONG(_bss_start)
344    LONG(_bss_end)
345    _bss_table_end = ABSOLUTE(.);
346    __rodata_region_end = ABSOLUTE(.);
347  } >sdram0 :sdram0_phdr
348
349  .module_init : ALIGN(4)
350  {
351   _module_init_start = ABSOLUTE(.);
352    *(*.initcall)
353    _module_init_end = ABSOLUTE(.);
354  } >sdram0 :sdram0_phdr
355
356  .text : ALIGN(4)
357  {
358    _stext = .;
359    __text_region_start = ABSOLUTE(.);
360    KEEP (*(.ResetVector.text))
361    *(.ResetVector.literal)
362    *(.entry.text)
363    *(.init.literal)
364    KEEP(*(.init))
365    *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
366    *(.fini.literal)
367    KEEP(*(.fini))
368    *(.gnu.version)
369    __text_region_end = ABSOLUTE(.);
370    _etext = .;
371  } >sdram0 :sdram0_phdr
372
373#include <zephyr/linker/common-rom.ld>
374/* Located in generated directory. This file is populated by calling
375 * zephyr_linker_sources(ROM_SECTIONS ...). Useful for grouping iterable RO structs.
376 */
377#include <snippets-rom-sections.ld>
378
379  .fw_ready : ALIGN(4)
380  {
381    KEEP(*(".fw_ready"));
382    KEEP (*(.fw_ready_metadata))
383  } >sdram0 :sdram0_phdr
384
385  .noinit : ALIGN(4)
386  {
387    *(.noinit)
388    *(.noinit.*)
389  } >sdram0 :sdram0_phdr
390
391  .data : ALIGN(4)
392  {
393    __data_start = ABSOLUTE(.);
394    *(.data)
395    *(.data.*)
396    *(.gnu.linkonce.d.*)
397    KEEP(*(.gnu.linkonce.d.*personality*))
398    *(.data1)
399    *(.sdata)
400    *(.sdata.*)
401    *(.gnu.linkonce.s.*)
402    *(.sdata2)
403    *(.sdata2.*)
404    *(.gnu.linkonce.s2.*)
405    KEEP(*(.jcr))
406    _trace_ctx_start = ABSOLUTE(.);
407    *(.trace_ctx)
408    _trace_ctx_end = ABSOLUTE(.);
409    . = ALIGN(4);
410    *(.gna_model)
411    __data_end = ABSOLUTE(.);
412    . = ALIGN(4096);
413  } >sdram0 :sdram0_phdr
414
415  .lit4 : ALIGN(4)
416  {
417    _lit4_start = ABSOLUTE(.);
418    *(*.lit4)
419    *(.lit4.*)
420    *(.gnu.linkonce.lit4.*)
421    _lit4_end = ABSOLUTE(.);
422  } >sdram0 :sdram0_phdr
423
424#include <zephyr/linker/common-ram.ld>
425
426  .bss (NOLOAD) : ALIGN(8)
427  {
428    . = ALIGN (8);
429    _bss_start = ABSOLUTE(.);
430    *(.dynsbss)
431    *(.sbss)
432    *(.sbss.*)
433    *(.gnu.linkonce.sb.*)
434    *(.scommon)
435    *(.sbss2)
436    *(.sbss2.*)
437    *(.gnu.linkonce.sb2.*)
438    *(.dynbss)
439    *(.bss)
440    *(.bss.*)
441    *(.gnu.linkonce.b.*)
442    *(COMMON)
443    . = ALIGN (8);
444    _bss_end = ABSOLUTE(.);
445  } >sdram0 :sdram0_phdr
446
447  .heap_mem (NOLOAD) : ALIGN(8)
448  {
449    . = ALIGN (8);
450    _heap_mem_start = ABSOLUTE(.);
451    *(*.heap_mem)
452    _heap_mem_end = ABSOLUTE(.);
453  } >sdram1 :sdram1_phdr
454
455  /* stack */
456  _end = ALIGN (8);
457  PROVIDE(end = ALIGN (8));
458
459  __stack = SDRAM1_BASE + SDRAM1_SIZE;
460  .comment  0 :  { *(.comment) }
461  .debug  0 :  { *(.debug) }
462  .line  0 :  { *(.line) }
463  .debug_srcinfo  0 :  { *(.debug_srcinfo) }
464  .debug_sfnames  0 :  { *(.debug_sfnames) }
465  .debug_aranges  0 :  { *(.debug_aranges) }
466  .debug_pubnames  0 :  { *(.debug_pubnames) }
467  .debug_info  0 :  { *(.debug_info) }
468  .debug_abbrev  0 :  { *(.debug_abbrev) }
469  .debug_line  0 :  { *(.debug_line) }
470  .debug_frame  0 :  { *(.debug_frame) }
471  .debug_str  0 :  { *(.debug_str) }
472  .debug_loc  0 :  { *(.debug_loc) }
473  .debug_macinfo  0 :  { *(.debug_macinfo) }
474  .debug_weaknames  0 :  { *(.debug_weaknames) }
475  .debug_funcnames  0 :  { *(.debug_funcnames) }
476  .debug_typenames  0 :  { *(.debug_typenames) }
477  .debug_varnames  0 :  { *(.debug_varnames) }
478  .debug_ranges  0 :  { *(.debug_ranges) }
479  .debug_addr  0 :  { *(.debug_addr) }
480  .debug_line_str  0 :  { *(.debug_line_str) }
481  .debug_loclists  0 :  { *(.debug_loclists) }
482  .debug_macro  0 :  { *(.debug_macro) }
483  .debug_names  0 :  { *(.debug_names) }
484  .debug_rnglists  0 :  { *(.debug_rnglists) }
485  .debug_str_offsets  0 :  { *(.debug_str_offsets) }
486  .debug_sup  0 :  { *(.debug_sup) }
487  .xtensa.info  0 :  { *(.xtensa.info) }
488  .xt.insn 0 :
489  {
490    KEEP (*(.xt.insn))
491    KEEP (*(.gnu.linkonce.x.*))
492  }
493  .xt.prop 0 :
494  {
495    KEEP (*(.xt.prop))
496    KEEP (*(.xt.prop.*))
497    KEEP (*(.gnu.linkonce.prop.*))
498  }
499  .xt.lit 0 :
500  {
501    KEEP (*(.xt.lit))
502    KEEP (*(.xt.lit.*))
503    KEEP (*(.gnu.linkonce.p.*))
504  }
505  .xt.profile_range 0 :
506  {
507    KEEP (*(.xt.profile_range))
508    KEEP (*(.gnu.linkonce.profile_range.*))
509  }
510  .xt.profile_ranges 0 :
511  {
512    KEEP (*(.xt.profile_ranges))
513    KEEP (*(.gnu.linkonce.xt.profile_ranges.*))
514  }
515  .xt.profile_files 0 :
516  {
517    KEEP (*(.xt.profile_files))
518    KEEP (*(.gnu.linkonce.xt.profile_files.*))
519  }
520#ifdef CONFIG_GEN_ISR_TABLES
521#include <zephyr/linker/intlist.ld>
522#endif
523
524  .static_uuid_entries (COPY) : ALIGN(1024)
525  {
526    *(*.static_uuids)
527  } > static_uuid_entries_seg :static_uuid_entries_phdr
528
529  .static_log_entries (COPY) : ALIGN(1024)
530  {
531    *(*.static_log*)
532  } > static_log_entries_seg :static_log_entries_phdr
533
534  .fw_metadata (COPY) : ALIGN(1024)
535  {
536    KEEP (*(.fw_metadata))
537    . = ALIGN(_EXT_MAN_ALIGN_);
538  } >fw_metadata_seg :metadata_entries_phdr
539
540  /DISCARD/ : { *(.note.GNU-stack) }
541}
542