1/* 2 * Copyright (c) 2022-2023 HPMicro 3 * SPDX-License-Identifier: BSD-3-Clause 4 */ 5 6 7define memory with size = 4G; 8 9/* Regions */ 10define region NOR_CFG_OPTION = [ from 0x80000400 size 0x1000 ]; 11define region BOOT_HEADER = [ from 0x80001000 size 0x2000 ]; 12define region XPI0 = [from 0x80003000 size _flash_size - 0x3000 ]; /* XPI0 */ 13define region ILM = [from 0x00000000 size 256k]; /* ILM */ 14define region DLM = [from 0x00200000 size 256k]; /* DLM */ 15define region AXI_SRAM = [from 0x01200000 size 512k]; 16define region NONCACHEABLE_RAM = [from 0x01280000 size 256k]; 17define region SHARE_RAM = [from 0x012FC000 size 16k]; 18define region AHB_SRAM = [from 0xF0200000 size 32k]; 19 20/* Blocks */ 21define block vectors with fixed order { section .vector_table, section .isr_vector }; 22define block vectors_s with fixed order { section .vector_s_table, section .isr_s_vector }; 23define block ctors { section .ctors, section .ctors.*, block with alphabetical order { init_array } }; 24define block dtors { section .dtors, section .dtors.*, block with reverse alphabetical order { fini_array } }; 25define block eh_frame { section .eh_frame, section .eh_frame.* }; 26define block tbss { section .tbss, section .tbss.* }; 27define block tdata { section .tdata, section .tdata.* }; 28define block tls with fixed order { block tbss, block tdata }; 29define block tdata_load { copy of block tdata }; 30define block heap with size = __HEAPSIZE__, alignment = 8, /* fill =0x00, */ readwrite access { }; 31define block stack with size = __STACKSIZE__, alignment = 16, /* fill =0xCD, */ readwrite access { }; 32define block cherryusb_usbh_class_info with alignment = 8 { section .usbh_class_info }; 33define block framebuffer with alignment = 8 { section .framebuffer }; 34define block boot_header with fixed order { section .boot_header, section .fw_info_table, section .dc_info }; 35define block rtthread_FSymTab { section FSymTab }; 36define block rtthread_VSymTab { section VSymTab }; 37define block rtthread_rti_fn with alphabetical order { section .rti_fn* }; 38define block rtthread_RTMSymTab { section RTMSymTab }; 39 40/* Symbols */ 41define exported symbol __nor_cfg_option_load_addr__ = start of region NOR_CFG_OPTION; 42define exported symbol __boot_header_load_addr__ = start of region BOOT_HEADER; 43define exported symbol __app_load_addr__ = start of region XPI0; 44define exported symbol __app_offset__ = __app_load_addr__ - __boot_header_load_addr__; 45define exported symbol __boot_header_length__ = size of block boot_header; 46define exported symbol __fw_size__ = 0x1000; 47 48define exported symbol __noncacheable_start__ = start of region NONCACHEABLE_RAM; 49define exported symbol __noncacheable_end__ = end of region NONCACHEABLE_RAM + 1; 50define exported symbol __share_mem_start__ = start of region SHARE_RAM; 51define exported symbol __share_mem_end__ = end of region SHARE_RAM + 1; 52 53define exported symbol _stack_safe = end of block stack + 1; 54define exported symbol _stack = end of block stack + 1; 55define exported symbol __usbh_class_info_start__ = start of block cherryusb_usbh_class_info; 56define exported symbol __usbh_class_info_end__ = end of block cherryusb_usbh_class_info + 1; 57 58define exported symbol __fsymtab_start = start of block rtthread_FSymTab; 59define exported symbol __fsymtab_end = end of block rtthread_FSymTab + 1; 60 61define exported symbol __vsymtab_start = start of block rtthread_VSymTab; 62define exported symbol __vsymtab_end = end of block rtthread_VSymTab + 1; 63 64define exported symbol __rt_init_start = start of block rtthread_rti_fn; 65define exported symbol __rt_init_end = end of block rtthread_rti_fn + 1; 66 67define exported symbol __rtmsymtab_start = start of block rtthread_RTMSymTab; 68define exported symbol __rtmsymtab_end = end of block rtthread_RTMSymTab + 1; 69 70/* Initialization */ 71do not initialize { section .noncacheable, section .fast_ram }; 72do not initialize { section .non_init, section .non_init.*, section .*.non_init, section .*.non_init.* }; 73do not initialize { section .no_init, section .no_init.*, section .*.no_init, section .*.no_init.* }; // Legacy sections, kept for backwards compatibility 74do not initialize { section .noinit, section .noinit.*, section .*.noinit, section .*.noinit.* }; // Legacy sections, used by some SDKs/HALs 75 76initialize by copy with packing=auto { section .noncacheable.init, section .fast_ram.init }; 77initialize by copy with packing=none { section .data, section .data.*, section .*.data, section .*.data.* }; // Static data sections 78initialize by copy with packing=auto { section .sdata, section .sdata.* }; 79initialize by copy with packing=auto { section .fast, section .fast.*, section .*.fast, section .*.fast.* }; // "RAM Code" sections 80 81initialize by calling __SEGGER_init_heap { block heap }; // Init the heap if there is one 82initialize by calling __SEGGER_init_ctors { block ctors }; // Call constructors for global objects which need to be constructed before reaching main (if any). Make sure this is done after setting up heap. 83initialize by copy { block vectors, block vectors_s }; 84initialize by copy { block cherryusb_usbh_class_info }; 85 86/* Placement */ 87place in NOR_CFG_OPTION { section .nor_cfg_option }; 88place in BOOT_HEADER with fixed order { block boot_header }; 89place at start of XPI0 with fixed order { symbol _start }; 90place at start of ILM with fixed order { block vectors, block vectors_s }; 91place in XPI0 with minimum size order { 92 block tdata_load, // Thread-local-storage load image 93 block ctors, // Constructors block 94 block dtors, // Destructors block 95 block eh_frame, // Exception frames placed directly into flash overriding default placement (sections writable) 96 block rtthread_FSymTab, 97 block rtthread_VSymTab, 98 block rtthread_rti_fn, 99 block rtthread_RTMSymTab, 100 readonly, // Catch-all for readonly data (e.g. .rodata, .srodata) 101 readexec // Catch-all for (readonly) executable code (e.g. .text) 102 }; 103 104// 105// The GNU compiler creates these exception-related sections as writeable. 106// Override the section header flag and make them readonly so they can be 107// placed into flash. 108// 109define access readonly { section .gcc_except_table, section .gcc_except_table.* }; 110define access readonly { section .eh_frame, section .eh_frame.* }; 111define access readonly { section .sdata.DW.* }; 112 113place in ILM { section .fast, section .fast.* }; // "ramfunc" section 114place in AXI_SRAM { block cherryusb_usbh_class_info }; 115place in AXI_SRAM { block framebuffer }; 116place in AXI_SRAM { 117 block tls, // Thread-local-storage block 118 readwrite, // Catch-all for initialized/uninitialized data sections (e.g. .data, .noinit) 119 zeroinit // Catch-all for zero-initialized data sections (e.g. .bss) 120 }; 121place in NONCACHEABLE_RAM { section .noncacheable, section .noncacheable.init, section .noncacheable.bss }; 122place in SHARE_RAM { section .sh_mem}; // Share memory 123place in AHB_SRAM { section .ahb_sram}; // AHB SRAM memory 124place in DLM { section .fast_ram.init, section .fast_ram, section .fast_ram.bss}; // Fast access memory 125place in DLM { block heap }; // Heap reserved block 126place at end of DLM { block stack }; // Stack reserved block 127 128/* Keep */ 129keep { section .nor_cfg_option, section .boot_header, section .fw_info_table, section .dc_info }; 130keep { section .usbh_class_info, section FSymTab, section VSymTab, section .rti_fn*, section RTMSymTab }; 131