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__          = 0x10000;
23}
24
25if (isdefinedsymbol(_flash_size)) {
26  define symbol __size_flash__          = _flash_size;
27} else {
28  define symbol __size_flash__          = 8M;
29}
30
31/* Regions */
32define region NOR_CFG_OPTION = mem:[ from 0x80000400 size 0x0C00 ];
33define region BOOT_HEADER = mem:[ from 0x80001000 size 0x90 ];
34define region XPI0 = mem:[from 0x80003000 size (__size_flash__ - 0x3000) ];   /* XPI0 */
35define region ILM = mem:[from 0x00000000 size 256k];        /* ILM */
36define region DLM = mem:[from 0x00080000 size 256k];        /* DLM */
37define region AXI_SRAM = mem:[from 0x01200000 size 256k];
38define region NONCACHEABLE_RAM = mem:[from 0x01240000 size 256k];
39define region AHB_SRAM = mem:[from 0xF0400000 size 32k];
40define region APB_SRAM = mem:[from 0xF4130000 size 16k];
41
42/* Blocks */
43define block vectors with fixed order                       { section .vector_table, section .isr_vector };
44define block vectors_s with fixed order                     { section .vector_s_table, section .isr_s_vector };
45
46define block HEAP  with size = __size_heap__,  alignment = 8 { };
47define block CSTACK with size = __size_cstack__, alignment = 16 { };
48define block SAFESTACK with size = __size_safestack__, alignment = 8 { };
49define block RW_DATA with static base GPREL { rw data };
50
51define block boot_header with fixed order                    { section .boot_header, section .fw_info_table, section .dc_info };
52define block cherryusb_usbh_class_info                       { section .usbh_class_info };
53define block framebuffer                                     { section .framebuffer };
54
55define block rtthread_FSymTab                                { section FSymTab };
56define block rtthread_VSymTab                                { section VSymTab };
57define block rtthread_rti_fn with alphabetical order         { section .rti_fn* };
58define block rtthread_RTMSymTab                              { section RTMSymTab };
59
60/* Symbols */
61define exported symbol __nor_cfg_option_load_addr__ = start(NOR_CFG_OPTION);
62define exported symbol __boot_header_load_addr__ = start(BOOT_HEADER);
63define exported symbol __app_load_addr__ = start(XPI0);
64define exported symbol __app_offset__ = __app_load_addr__ - __boot_header_load_addr__;
65define exported symbol __boot_header_length__ = size(BOOT_HEADER);
66define exported symbol __fw_size__ = 0x1000;
67
68define exported symbol __noncacheable_start__ = start(NONCACHEABLE_RAM);
69define exported symbol __noncacheable_end__ = end(NONCACHEABLE_RAM) + 1;
70
71/* Initialization */
72do not initialize                           { section .noncacheable, section .fast_ram };
73do not initialize                           { section .non_init, section .non_init.*, section .*.non_init, section .*.non_init.* };
74do not initialize                           { section .no_init, section .no_init.*, section .*.no_init, section .*.no_init.* };   // Legacy sections, kept for backwards compatibility
75do not initialize                           { section .noinit, section .noinit.*, section .*.noinit, section .*.noinit.* };       // Legacy sections, used by some SDKs/HALs
76do not initialize                           { section .backup_sram};
77
78initialize by copy with packing=auto        { section .noncacheable.init, section .fast_ram.init };
79initialize by copy with packing=auto        { section .fast, section .fast.*, section .*.fast, section .*.fast.* };               // "RAM Code" sections
80initialize by copy with packing=none        { section .vector_table };
81initialize by copy with packing=none        { section .isr_vector };
82initialize by copy with packing=none        { section .vector_s_table };
83initialize by copy with packing=none        { section .isr_s_vector };
84initialize by copy with packing=auto        { section .usbh_class_info };
85initialize by copy                          { readwrite };
86
87/* Placement */
88place in NOR_CFG_OPTION                     { section .nor_cfg_option };
89place in BOOT_HEADER                        { block boot_header };
90place at start of XPI0                      { symbol _start};
91place in XPI0                               { block rtthread_FSymTab,
92                                              block rtthread_VSymTab,
93                                              block rtthread_rti_fn,
94                                              block rtthread_RTMSymTab,
95                                              readonly
96                                            };
97place at start of ILM                       { block vectors, block vectors_s };
98place in ILM                                {
99                                              section .fast, section .fast.*,                       // "ramfunc" section
100                                            };
101place in AXI_SRAM                           { block cherryusb_usbh_class_info };
102place in AXI_SRAM                           { block framebuffer };
103place in AXI_SRAM                           {
104                                              block RW_DATA
105                                            };
106place in NONCACHEABLE_RAM                   { section .noncacheable, section .noncacheable.init, section .noncacheable.bss };  // Noncacheable
107place in AHB_SRAM                           { section .ahb_sram};                                   // AHB SRAM memory
108place in APB_SRAM                           { section .backup_sram};                                // Backup SRAM memory
109place in DLM                                { section .fast_ram.init, section .fast_ram, section .fast_ram.bss};   // Fast access memory
110place in DLM                                { block HEAP };                                         // Heap reserved block
111place at end of DLM                         { block SAFESTACK, block CSTACK };                      // Stack reserved block
112
113/* Keep */
114keep                                        { section .nor_cfg_option, section .boot_header, section .fw_info_table, section .dc_info };
115keep                                        { section .usbh_class_info,
116                                              section FSymTab,
117                                              section VSymTab,
118                                              section .rti_fn*,
119                                              section RTMSymTab
120                                            };
121keep symbol __iar_cstart_init_gp;
122