1/*
2 * Copyright (c) 2024 HPMicro
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6define exported symbol _link_file_version_2 = 1;
7
8define memory with size = 4G;
9
10/* Sizes */
11if (isdefinedsymbol(CSTACK_SIZE)) {
12  define symbol __size_cstack__        = CSTACK_SIZE;
13} else {
14  define symbol __size_cstack__        = 0x4000;
15}
16
17define symbol __size_safestack__       = 256;
18
19if (isdefinedsymbol(HEAP_SIZE)) {
20  define symbol __size_heap__          = HEAP_SIZE;
21} else {
22  define symbol __size_heap__          = 0x4000;
23}
24
25/* Regions */
26define region ILM = mem:[from 0x00000000 size 256k];    /* ILM */
27define region DLM = mem:[from 0x00200000 size 256k];    /* DLM */
28define region AXI_SRAM = mem:[from 0x01200000 size 512k];
29define region NONCACHEABLE_RAM = mem:[from 0x01280000 size 256k];
30define region SHARE_RAM = mem:[from 0x012FC000 size 16k];
31define region AHB_SRAM = mem:[from 0xF0200000 size 32k];
32
33/* Blocks */
34define block vectors with fixed order                       { section .vector_table, section .isr_vector };
35define block vectors_s with fixed order                     { section .vector_s_table, section .isr_s_vector };
36define block HEAP  with size = __size_heap__,  alignment = 8 { };
37define block CSTACK with size = __size_cstack__, alignment = 16 { };
38define block SAFESTACK with size = __size_safestack__, alignment = 8 { };
39define block RW_DATA with static base GPREL { rw data };
40
41define block cherryusb_usbh_class_info                       { section .usbh_class_info };
42define block framebuffer                                     { section .framebuffer };
43
44define block rtthread_FSymTab                                { section FSymTab };
45define block rtthread_VSymTab                                { section VSymTab };
46define block rtthread_rti_fn with alphabetical order         { section .rti_fn* };
47define block rtthread_RTMSymTab                              { section RTMSymTab };
48
49/* Symbols */
50define exported symbol __noncacheable_start__ = start(NONCACHEABLE_RAM);
51define exported symbol __noncacheable_end__ = end(NONCACHEABLE_RAM) + 1;
52define exported symbol __share_mem_start__ = start(SHARE_RAM);
53define exported symbol __share_mem_end__ = end(SHARE_RAM) + 1;
54
55/* Initialization */
56do not initialize                           { section .noncacheable, section .fast_ram };
57do not initialize                           { section .non_init, section .non_init.*, section .*.non_init, section .*.non_init.* };
58do not initialize                           { section .no_init, section .no_init.*, section .*.no_init, section .*.no_init.* };   // Legacy sections, kept for backwards compatibility
59do not initialize                           { section .noinit, section .noinit.*, section .*.noinit, section .*.noinit.* };       // Legacy sections, used by some SDKs/HALs
60
61initialize by copy with packing=auto        { section .noncacheable.init, section .fast_ram.init };
62initialize by copy with packing=auto        { section .fast, section .fast.*, section .*.fast, section .*.fast.* };               // "RAM Code" sections
63initialize by copy with packing=none        { section .vector_table };
64initialize by copy with packing=none        { section .isr_vector };
65initialize by copy with packing=none        { section .vector_s_table };
66initialize by copy with packing=none        { section .isr_s_vector };
67initialize by copy with packing=auto        { section .usbh_class_info };
68initialize by copy                          { readwrite };
69
70/* Placement */
71place at start of ILM                       { symbol _start };
72place in ILM                                { block vectors, block vectors_s };                     // Vector table section
73place in ILM                                { section .fast, section .fast.* };                     // "ramfunc" section
74place in ILM                                {
75                                              block rtthread_FSymTab,
76                                              block rtthread_VSymTab,
77                                              block rtthread_rti_fn,
78                                              block rtthread_RTMSymTab,
79                                              readonly
80                                            };
81place in AXI_SRAM                           { block cherryusb_usbh_class_info };
82place in AXI_SRAM                           { block framebuffer };
83place in AXI_SRAM                           {
84                                              block RW_DATA
85                                            };
86place in NONCACHEABLE_RAM                   { section .noncacheable, section .noncacheable.init, section .noncacheable.bss };  // Noncacheable
87place in SHARE_RAM                          { section .sh_mem};                                     // Share memory
88place in AHB_SRAM                           { section .ahb_sram};                                   // AHB SRAM memory
89place in DLM                                { section .fast_ram.init, section .fast_ram, section .fast_ram.bss};   // Fast access memory
90place in DLM                                { block HEAP };                                         // Heap reserved block
91place at end of DLM                         { block SAFESTACK, block CSTACK };                      // Stack reserved block
92
93/* Keep */
94keep                                        { section .usbh_class_info,
95                                              section FSymTab,
96                                              section VSymTab,
97                                              section .rti_fn*,
98                                              section RTMSymTab
99                                            };
100keep symbol __iar_cstart_init_gp;
101