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
175#ifdef CONFIG_OPENAMP_RSC_TABLE
176    SECTION_PROLOGUE(.resource_table,, SUBALIGN(4))
177    {
178      KEEP(*(.resource_table*))
179    } GROUP_LINK_IN(ROMABLE_REGION)
180#endif
181
182#include <zephyr/linker/rel-sections.ld>
183
184#ifdef CONFIG_LLEXT
185#include <zephyr/linker/llext-sections.ld>
186#endif
187  .ResetVector.text : ALIGN(4)
188  {
189    _ResetVector_text_start = ABSOLUTE(.);
190    KEEP (*(.ResetVector.text))
191    _ResetVector_text_end = ABSOLUTE(.);
192  } >vector_reset_text :vector_reset_text_phdr
193
194  .ResetVector.literal : ALIGN(4)
195  {
196    _ResetVector_literal_start = ABSOLUTE(.);
197    *(.ResetVector.literal)
198    _ResetVector_literal_end = ABSOLUTE(.);
199  } >vector_reset_lit :vector_reset_lit_phdr
200
201  .WindowVectors.text : ALIGN(4)
202  {
203    _WindowVectors_text_start = ABSOLUTE(.);
204    KEEP (*(.WindowVectors.text))
205    _WindowVectors_text_end = ABSOLUTE(.);
206  } >vector_base_text :vector_base_text_phdr
207
208  .Level2InterruptVector.literal : ALIGN(4)
209  {
210    _Level2InterruptVector_literal_start = ABSOLUTE(.);
211    *(.Level2InterruptVector.literal)
212    _Level2InterruptVector_literal_end = ABSOLUTE(.);
213  } >vector_int2_lit :vector_int2_lit_phdr
214
215  .Level2InterruptVector.text : ALIGN(4)
216  {
217    _Level2InterruptVector_text_start = ABSOLUTE(.);
218    KEEP (*(.Level2InterruptVector.text))
219    _Level2InterruptVector_text_end = ABSOLUTE(.);
220  } >vector_int2_text :vector_int2_text_phdr
221
222  .Level3InterruptVector.literal : ALIGN(4)
223  {
224    _Level3InterruptVector_literal_start = ABSOLUTE(.);
225    *(.Level3InterruptVector.literal)
226    _Level3InterruptVector_literal_end = ABSOLUTE(.);
227  } >vector_int3_lit :vector_int3_lit_phdr
228
229  .Level3InterruptVector.text : ALIGN(4)
230  {
231    _Level3InterruptVector_text_start = ABSOLUTE(.);
232    KEEP (*(.Level3InterruptVector.text))
233    _Level3InterruptVector_text_end = ABSOLUTE(.);
234  } >vector_int3_text :vector_int3_text_phdr
235
236  .DebugExceptionVector.literal : ALIGN(4)
237  {
238    _DebugExceptionVector_literal_start = ABSOLUTE(.);
239    *(.DebugExceptionVector.literal)
240    _DebugExceptionVector_literal_end = ABSOLUTE(.);
241  } >vector_int4_lit :vector_int4_lit_phdr
242
243  .DebugExceptionVector.text : ALIGN(4)
244  {
245    _DebugExceptionVector_text_start = ABSOLUTE(.);
246    KEEP (*(.DebugExceptionVector.text))
247    _DebugExceptionVector_text_end = ABSOLUTE(.);
248  } >vector_int4_text :vector_int4_text_phdr
249
250  .NMIExceptionVector.literal : ALIGN(4)
251  {
252    _NMIExceptionVector_literal_start = ABSOLUTE(.);
253    *(.NMIExceptionVector.literal)
254    _NMIExceptionVector_literal_end = ABSOLUTE(.);
255  } >vector_int5_lit :vector_int5_lit_phdr
256
257  .NMIExceptionVector.text : ALIGN(4)
258  {
259    _NMIExceptionVector_text_start = ABSOLUTE(.);
260    KEEP (*(.NMIExceptionVector.text))
261    _NMIExceptionVector_text_end = ABSOLUTE(.);
262  } >vector_int5_text :vector_int5_text_phdr
263
264  .KernelExceptionVector.literal : ALIGN(4)
265  {
266    _KernelExceptionVector_literal_start = ABSOLUTE(.);
267    *(.KernelExceptionVector.literal)
268    _KernelExceptionVector_literal_end = ABSOLUTE(.);
269  } >vector_kernel_lit :vector_kernel_lit_phdr
270
271  .KernelExceptionVector.text : ALIGN(4)
272  {
273    _KernelExceptionVector_text_start = ABSOLUTE(.);
274    KEEP (*(.KernelExceptionVector.text))
275    _KernelExceptionVector_text_end = ABSOLUTE(.);
276  } >vector_kernel_text :vector_kernel_text_phdr
277
278  .UserExceptionVector.literal : ALIGN(4)
279  {
280    _UserExceptionVector_literal_start = ABSOLUTE(.);
281    *(.UserExceptionVector.literal)
282    _UserExceptionVector_literal_end = ABSOLUTE(.);
283  } >vector_user_lit :vector_user_lit_phdr
284
285  .UserExceptionVector.text : ALIGN(4)
286  {
287    _UserExceptionVector_text_start = ABSOLUTE(.);
288    KEEP (*(.UserExceptionVector.text))
289    _UserExceptionVector_text_end = ABSOLUTE(.);
290  } >vector_user_text :vector_user_text_phdr
291
292  .DoubleExceptionVector.literal : ALIGN(4)
293  {
294    _DoubleExceptionVector_literal_start = ABSOLUTE(.);
295    *(.DoubleExceptionVector.literal)
296    _DoubleExceptionVector_literal_end = ABSOLUTE(.);
297  } >vector_double_lit :vector_double_lit_phdr
298
299  .DoubleExceptionVector.text : ALIGN(4)
300  {
301    _DoubleExceptionVector_text_start = ABSOLUTE(.);
302    KEEP (*(.DoubleExceptionVector.text))
303    _DoubleExceptionVector_text_end = ABSOLUTE(.);
304  } >vector_double_text :vector_double_text_phdr
305
306  .iram.text : ALIGN(4)
307  {
308    _stext = .;
309    _iram_text_start = ABSOLUTE(.);
310    *(.iram0.literal .iram.literal .iram.text.literal .iram0.text .iram.text)
311    _iram_text_end = ABSOLUTE(.);
312  } >iram_text_start :iram_text_start_phdr
313
314  .rodata : ALIGN(4)
315  {
316    __rodata_region_start = ABSOLUTE(.);
317    *(.rodata)
318    *(.rodata.*)
319    *(.gnu.linkonce.r.*)
320    *(.rodata1)
321    __XT_EXCEPTION_TABLE__ = ABSOLUTE(.);
322    KEEP (*(.xt_except_table))
323    KEEP (*(.gcc_except_table .gcc_except_table.*))
324    *(.gnu.linkonce.e.*)
325    *(.gnu.version_r)
326    KEEP (*(.eh_frame))
327    KEEP (*crtbegin.o(.ctors))
328    KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
329    KEEP (*(SORT(.ctors.*)))
330    KEEP (*(.ctors))
331    KEEP (*crtbegin.o(.dtors))
332    KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
333    KEEP (*(SORT(.dtors.*)))
334    KEEP (*(.dtors))
335    __XT_EXCEPTION_DESCS__ = ABSOLUTE(.);
336    *(.xt_except_desc)
337    *(.gnu.linkonce.h.*)
338    __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.);
339    *(.xt_except_desc_end)
340    *(.dynamic)
341    *(.gnu.version_d)
342    . = ALIGN(4);
343    _bss_table_start = ABSOLUTE(.);
344    LONG(_bss_start)
345    LONG(_bss_end)
346    _bss_table_end = ABSOLUTE(.);
347    __rodata_region_end = ABSOLUTE(.);
348  } >sdram0 :sdram0_phdr
349
350  .module_init : ALIGN(4)
351  {
352   _module_init_start = ABSOLUTE(.);
353    *(*.initcall)
354    _module_init_end = ABSOLUTE(.);
355  } >sdram0 :sdram0_phdr
356
357  .text : ALIGN(4)
358  {
359    _stext = .;
360    __text_region_start = ABSOLUTE(.);
361    KEEP (*(.ResetVector.text))
362    *(.ResetVector.literal)
363    *(.entry.text)
364    *(.init.literal)
365    KEEP(*(.init))
366    *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
367    *(.fini.literal)
368    KEEP(*(.fini))
369    *(.gnu.version)
370    __text_region_end = ABSOLUTE(.);
371    _etext = .;
372  } >sdram0 :sdram0_phdr
373
374#include <zephyr/linker/common-rom.ld>
375/* Located in generated directory. This file is populated by calling
376 * zephyr_linker_sources(ROM_SECTIONS ...). Useful for grouping iterable RO structs.
377 */
378#include <snippets-rom-sections.ld>
379
380  .fw_ready : ALIGN(4)
381  {
382    KEEP(*(".fw_ready"));
383    KEEP (*(.fw_ready_metadata))
384  } >sdram0 :sdram0_phdr
385
386  .noinit : ALIGN(4)
387  {
388    *(.noinit)
389    *(.noinit.*)
390  } >sdram0 :sdram0_phdr
391
392  .data : ALIGN(4)
393  {
394    __data_start = ABSOLUTE(.);
395    *(.data)
396    *(.data.*)
397    *(.gnu.linkonce.d.*)
398    KEEP(*(.gnu.linkonce.d.*personality*))
399    *(.data1)
400    *(.sdata)
401    *(.sdata.*)
402    *(.gnu.linkonce.s.*)
403    *(.sdata2)
404    *(.sdata2.*)
405    *(.gnu.linkonce.s2.*)
406    KEEP(*(.jcr))
407    _trace_ctx_start = ABSOLUTE(.);
408    *(.trace_ctx)
409    _trace_ctx_end = ABSOLUTE(.);
410    . = ALIGN(4);
411    *(.gna_model)
412    __data_end = ABSOLUTE(.);
413    . = ALIGN(4096);
414  } >sdram0 :sdram0_phdr
415
416  .lit4 : ALIGN(4)
417  {
418    _lit4_start = ABSOLUTE(.);
419    *(*.lit4)
420    *(.lit4.*)
421    *(.gnu.linkonce.lit4.*)
422    _lit4_end = ABSOLUTE(.);
423  } >sdram0 :sdram0_phdr
424
425#include <zephyr/linker/common-ram.ld>
426
427  .bss (NOLOAD) : ALIGN(8)
428  {
429    . = ALIGN (8);
430    _bss_start = ABSOLUTE(.);
431    *(.dynsbss)
432    *(.sbss)
433    *(.sbss.*)
434    *(.gnu.linkonce.sb.*)
435    *(.scommon)
436    *(.sbss2)
437    *(.sbss2.*)
438    *(.gnu.linkonce.sb2.*)
439    *(.dynbss)
440    *(.bss)
441    *(.bss.*)
442    *(.gnu.linkonce.b.*)
443    *(COMMON)
444    . = ALIGN (8);
445    _bss_end = ABSOLUTE(.);
446  } >sdram0 :sdram0_phdr
447
448  .heap_mem (NOLOAD) : ALIGN(8)
449  {
450    . = ALIGN (8);
451    _heap_mem_start = ABSOLUTE(.);
452    *(*.heap_mem)
453    _heap_mem_end = ABSOLUTE(.);
454  } >sdram1 :sdram1_phdr
455
456  /* stack */
457  _end = ALIGN (8);
458  PROVIDE(end = ALIGN (8));
459
460  __stack = SDRAM1_BASE + SDRAM1_SIZE;
461  .comment  0 :  { *(.comment) }
462  .debug  0 :  { *(.debug) }
463  .line  0 :  { *(.line) }
464  .debug_srcinfo  0 :  { *(.debug_srcinfo) }
465  .debug_sfnames  0 :  { *(.debug_sfnames) }
466  .debug_aranges  0 :  { *(.debug_aranges) }
467  .debug_pubnames  0 :  { *(.debug_pubnames) }
468  .debug_info  0 :  { *(.debug_info) }
469  .debug_abbrev  0 :  { *(.debug_abbrev) }
470  .debug_line  0 :  { *(.debug_line) }
471  .debug_frame  0 :  { *(.debug_frame) }
472  .debug_str  0 :  { *(.debug_str) }
473  .debug_loc  0 :  { *(.debug_loc) }
474  .debug_macinfo  0 :  { *(.debug_macinfo) }
475  .debug_weaknames  0 :  { *(.debug_weaknames) }
476  .debug_funcnames  0 :  { *(.debug_funcnames) }
477  .debug_typenames  0 :  { *(.debug_typenames) }
478  .debug_varnames  0 :  { *(.debug_varnames) }
479  .debug_ranges  0 :  { *(.debug_ranges) }
480  .debug_addr  0 :  { *(.debug_addr) }
481  .debug_line_str  0 :  { *(.debug_line_str) }
482  .debug_loclists  0 :  { *(.debug_loclists) }
483  .debug_macro  0 :  { *(.debug_macro) }
484  .debug_names  0 :  { *(.debug_names) }
485  .debug_rnglists  0 :  { *(.debug_rnglists) }
486  .debug_str_offsets  0 :  { *(.debug_str_offsets) }
487  .debug_sup  0 :  { *(.debug_sup) }
488  .xtensa.info  0 :  { *(.xtensa.info) }
489  .xt.insn 0 :
490  {
491    KEEP (*(.xt.insn))
492    KEEP (*(.gnu.linkonce.x.*))
493  }
494  .xt.prop 0 :
495  {
496    KEEP (*(.xt.prop))
497    KEEP (*(.xt.prop.*))
498    KEEP (*(.gnu.linkonce.prop.*))
499  }
500  .xt.lit 0 :
501  {
502    KEEP (*(.xt.lit))
503    KEEP (*(.xt.lit.*))
504    KEEP (*(.gnu.linkonce.p.*))
505  }
506  .xt.profile_range 0 :
507  {
508    KEEP (*(.xt.profile_range))
509    KEEP (*(.gnu.linkonce.profile_range.*))
510  }
511  .xt.profile_ranges 0 :
512  {
513    KEEP (*(.xt.profile_ranges))
514    KEEP (*(.gnu.linkonce.xt.profile_ranges.*))
515  }
516  .xt.profile_files 0 :
517  {
518    KEEP (*(.xt.profile_files))
519    KEEP (*(.gnu.linkonce.xt.profile_files.*))
520  }
521#ifdef CONFIG_GEN_ISR_TABLES
522#include <zephyr/linker/intlist.ld>
523#endif
524
525  .static_uuid_entries (COPY) : ALIGN(1024)
526  {
527    *(*.static_uuids)
528  } > static_uuid_entries_seg :static_uuid_entries_phdr
529
530  .static_log_entries (COPY) : ALIGN(1024)
531  {
532    *(*.static_log*)
533  } > static_log_entries_seg :static_log_entries_phdr
534
535  .fw_metadata (COPY) : ALIGN(1024)
536  {
537    KEEP (*(.fw_metadata))
538    . = ALIGN(_EXT_MAN_ALIGN_);
539  } >fw_metadata_seg :metadata_entries_phdr
540
541  /DISCARD/ : { *(.note.GNU-stack) }
542}
543