|
| 1 | +set(COMMON_ZEPHYR_LINKER_DIR ${ZEPHYR_BASE}/cmake/linker_script/common) |
| 2 | + |
| 3 | +set_ifndef(region_min_align CONFIG_CUSTOM_SECTION_MIN_ALIGN_SIZE) |
| 4 | + |
| 5 | +# Set alignment to CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE if not set above |
| 6 | +# to make linker section alignment comply with MPU granularity. |
| 7 | +set_ifndef(region_min_align CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE) |
| 8 | + |
| 9 | +# If building without MPU support, use default 4-byte alignment.. if not set abve. |
| 10 | +set_ifndef(region_min_align 4) |
| 11 | + |
| 12 | +# Note, the `+ 0` in formulas below avoids errors in cases where a Kconfig |
| 13 | +# variable is undefined and thus expands to nothing. |
| 14 | +math(EXPR FLASH_ADDR |
| 15 | + "${CONFIG_FLASH_BASE_ADDRESS} + ${CONFIG_FLASH_LOAD_OFFSET} + 0" |
| 16 | + OUTPUT_FORMAT HEXADECIMAL |
| 17 | +) |
| 18 | + |
| 19 | +math(EXPR FLASH_SIZE |
| 20 | + "(${CONFIG_FLASH_SIZE} + 0) * 1024 - (${CONFIG_FLASH_LOAD_OFFSET} + 0)" |
| 21 | + OUTPUT_FORMAT HEXADECIMAL |
| 22 | +) |
| 23 | + |
| 24 | +set(RAM_ADDR ${CONFIG_SRAM_BASE_ADDRESS}) |
| 25 | +math(EXPR RAM_SIZE "(${CONFIG_SRAM_SIZE} + 0) * 1024" OUTPUT_FORMAT HEXADECIMAL) |
| 26 | +math(EXPR IDT_ADDR "${RAM_ADDR} + ${RAM_SIZE}" OUTPUT_FORMAT HEXADECIMAL) |
| 27 | + |
| 28 | +# ToDo: decide on the optimal location for this. |
| 29 | +# linker/ld/target.cmake based on arch, or directly in arch and scatter_script.cmake can ignore |
| 30 | +zephyr_linker(FORMAT "elf32-littlearm") |
| 31 | +zephyr_linker(ENTRY ${CONFIG_KERNEL_ENTRY}) |
| 32 | + |
| 33 | +zephyr_linker_memory(NAME FLASH FLAGS rx START ${FLASH_ADDR} SIZE ${FLASH_SIZE}) |
| 34 | +zephyr_linker_memory(NAME RAM FLAGS wx START ${RAM_ADDR} SIZE ${RAM_SIZE}) |
| 35 | +zephyr_linker_memory(NAME IDT_LIST FLAGS wx START ${IDT_ADDR} SIZE 2K) |
| 36 | + |
| 37 | +if(CONFIG_XIP) |
| 38 | + zephyr_linker_group(NAME ROM_REGION LMA FLASH) |
| 39 | + set(rom_start ${FLASH_ADDR}) |
| 40 | + set(XIP_ALIGN_WITH_INPUT ALIGN_WITH_INPUT) |
| 41 | +else() |
| 42 | + zephyr_linker_group(NAME ROM_REGION LMA RAM) |
| 43 | + set(rom_start ${RAM_ADDR}) |
| 44 | +endif() |
| 45 | + |
| 46 | +zephyr_linker_group(NAME RAM_REGION VMA RAM LMA ROM_REGION) |
| 47 | +zephyr_linker_group(NAME TEXT_REGION GROUP ROM_REGION) |
| 48 | +zephyr_linker_group(NAME RODATA_REGION GROUP ROM_REGION) |
| 49 | +zephyr_linker_group(NAME DATA_REGION GROUP RAM_REGION) |
| 50 | + |
| 51 | +# should go to a relocation.cmake - from include/linker/rel-sections.ld - start |
| 52 | +zephyr_linker_section(NAME .rel.plt HIDDEN) |
| 53 | +zephyr_linker_section(NAME .rela.plt HIDDEN) |
| 54 | +zephyr_linker_section(NAME .rel.dyn) |
| 55 | +zephyr_linker_section(NAME .rela.dyn) |
| 56 | +# should go to a relocation.cmake - from include/linker/rel-sections.ld - end |
| 57 | + |
| 58 | +# Discard sections for GNU ld. |
| 59 | +zephyr_linker_section_configure(SECTION /DISCARD/ INPUT ".plt") |
| 60 | +zephyr_linker_section_configure(SECTION /DISCARD/ INPUT ".iplt") |
| 61 | +zephyr_linker_section_configure(SECTION /DISCARD/ INPUT ".got.plt") |
| 62 | +zephyr_linker_section_configure(SECTION /DISCARD/ INPUT ".igot.plt") |
| 63 | +zephyr_linker_section_configure(SECTION /DISCARD/ INPUT ".got") |
| 64 | +zephyr_linker_section_configure(SECTION /DISCARD/ INPUT ".igot") |
| 65 | + |
| 66 | +zephyr_linker_section(NAME .rom_start ADDRESS ${rom_start} GROUP ROM_REGION NOINPUT) |
| 67 | + |
| 68 | +zephyr_linker_section(NAME .text GROUP TEXT_REGION) |
| 69 | + |
| 70 | +zephyr_linker_section_configure(SECTION .rel.plt INPUT ".rel.iplt") |
| 71 | +zephyr_linker_section_configure(SECTION .rela.plt INPUT ".rela.iplt") |
| 72 | + |
| 73 | +zephyr_linker_section_configure(SECTION .text INPUT ".TEXT.*") |
| 74 | +zephyr_linker_section_configure(SECTION .text INPUT ".gnu.linkonce.t.*") |
| 75 | + |
| 76 | +zephyr_linker_section_configure(SECTION .text INPUT ".glue_7t") |
| 77 | +zephyr_linker_section_configure(SECTION .text INPUT ".glue_7") |
| 78 | +zephyr_linker_section_configure(SECTION .text INPUT ".vfp11_veneer") |
| 79 | +zephyr_linker_section_configure(SECTION .text INPUT ".v4_bx") |
| 80 | + |
| 81 | +if(CONFIG_CPLUSPLUS) |
| 82 | + zephyr_linker_section(NAME .ARM.extab GROUP ROM_REGION) |
| 83 | + zephyr_linker_section_configure(SECTION .ARM.extab INPUT ".gnu.linkonce.armextab.*") |
| 84 | +endif() |
| 85 | + |
| 86 | +zephyr_linker_section(NAME .ARM.exidx GROUP ROM_REGION) |
| 87 | +# Here the original linker would check for __GCC_LINKER_CMD__, need to check toolchain linker ? |
| 88 | +#if(__GCC_LINKER_CMD__) |
| 89 | + zephyr_linker_section_configure(SECTION .ARM.exidx INPUT ".gnu.linkonce.armexidx.*") |
| 90 | +#endif() |
| 91 | + |
| 92 | + |
| 93 | +include(${COMMON_ZEPHYR_LINKER_DIR}/common-rom.cmake) |
| 94 | +include(${COMMON_ZEPHYR_LINKER_DIR}/thread-local-storage.cmake) |
| 95 | + |
| 96 | +zephyr_linker_section(NAME .rodata GROUP RODATA_REGION) |
| 97 | +zephyr_linker_section_configure(SECTION .rodata INPUT ".gnu.linkonce.r.*") |
| 98 | +if(CONFIG_USERSPACE AND CONFIG_XIP) |
| 99 | + zephyr_linker_section_configure(SECTION .rodata INPUT ".kobject_data.rodata*") |
| 100 | +endif() |
| 101 | +zephyr_linker_section_configure(SECTION .rodata ALIGN 4) |
| 102 | + |
| 103 | +# ToDo - . = ALIGN(_region_min_align); |
| 104 | +# Symbol to add _image_ram_start = .; |
| 105 | + |
| 106 | +# This comes from ramfunc.ls, via snippets-ram-sections.ld |
| 107 | +zephyr_linker_section(NAME .ramfunc GROUP RAM_REGION SUBALIGN 8) |
| 108 | +# Todo: handle MPU_ALIGN(_ramfunc_size); |
| 109 | + |
| 110 | +# ToDo - handle if(CONFIG_USERSPACE) |
| 111 | + |
| 112 | +zephyr_linker_section(NAME .data GROUP DATA_REGION) |
| 113 | +zephyr_linker_section_configure(SECTION .data INPUT ".kernel.*") |
| 114 | + |
| 115 | +include(${COMMON_ZEPHYR_LINKER_DIR}/common-ram.cmake) |
| 116 | +#include(kobject.ld) |
| 117 | + |
| 118 | +if(NOT CONFIG_USERSPACE) |
| 119 | + zephyr_linker_section(NAME .bss VMA RAM LMA FLASH TYPE BSS) |
| 120 | + zephyr_linker_section_configure(SECTION .bss INPUT COMMON) |
| 121 | + zephyr_linker_section_configure(SECTION .bss INPUT ".kernel_bss.*") |
| 122 | + # As memory is cleared in words only, it is simpler to ensure the BSS |
| 123 | + # section ends on a 4 byte boundary. This wastes a maximum of 3 bytes. |
| 124 | + zephyr_linker_section_configure(SECTION .bss ALIGN 4) |
| 125 | + |
| 126 | + zephyr_linker_section(NAME .noinit GROUP RAM_REGION TYPE NOLOAD NOINIT) |
| 127 | + # This section is used for non-initialized objects that |
| 128 | + # will not be cleared during the boot process. |
| 129 | + zephyr_linker_section_configure(SECTION .noinit INPUT ".kernel_noinit.*") |
| 130 | +endif() |
| 131 | + |
| 132 | +zephyr_linker_symbol(SYMBOL __kernel_ram_start EXPR "(%__bss_start%)") |
| 133 | +zephyr_linker_symbol(SYMBOL __kernel_ram_end EXPR "(${RAM_ADDR} + ${RAM_SIZE})") |
| 134 | +zephyr_linker_symbol(SYMBOL __kernel_ram_size EXPR "(%__kernel_ram_end% - %__bss_start%)") |
| 135 | +zephyr_linker_symbol(SYMBOL _image_ram_start EXPR "(${RAM_ADDR})" SUBALIGN 32) # ToDo calculate 32 correctly |
| 136 | +zephyr_linker_symbol(SYMBOL ARM_LIB_STACKHEAP EXPR "(${RAM_ADDR} + ${RAM_SIZE})" SIZE -0x1000) |
| 137 | + |
| 138 | +set(VECTOR_ALIGN 4) |
| 139 | +if(CONFIG_CPU_CORTEX_M_HAS_VTOR) |
| 140 | + math(EXPR VECTOR_ALIGN "4 * (16 + ${CONFIG_NUM_IRQS})") |
| 141 | + if(${VECTOR_ALIGN} LESS 128) |
| 142 | + set(VECTOR_ALIGN 128) |
| 143 | + else() |
| 144 | + pow2round(VECTOR_ALIGN) |
| 145 | + endif() |
| 146 | +endif() |
| 147 | + |
| 148 | +zephyr_linker_section_configure( |
| 149 | + SECTION .rom_start |
| 150 | + INPUT ".exc_vector_table*" |
| 151 | + ".gnu.linkonce.irq_vector_table*" |
| 152 | + ".vectors" |
| 153 | + OFFSET ${CONFIG_ROM_START_OFFSET} |
| 154 | + KEEP FIRST |
| 155 | + SYMBOLS _vector_start _vector_end |
| 156 | + ALIGN ${VECTOR_ALIGN} |
| 157 | + PRIO 50 |
| 158 | +) |
| 159 | + |
| 160 | +zephyr_linker_section(NAME .ARM.attributes ADDRESS 0 NOINPUT) |
| 161 | +zephyr_linker_section_configure(SECTION .ARM.attributes INPUT ".ARM.attributes" KEEP) |
| 162 | +zephyr_linker_section_configure(SECTION .ARM.attributes INPUT ".gnu.attributes" KEEP) |
| 163 | + |
| 164 | +# armlink specific flags |
| 165 | +zephyr_linker_section_configure(SECTION .text ANY FLAGS "+RO" "+XO") |
| 166 | +zephyr_linker_section_configure(SECTION .data ANY FLAGS "+RW") |
| 167 | +zephyr_linker_section_configure(SECTION .bss ANY FLAGS "+ZI") |
| 168 | + |
| 169 | +include(${COMMON_ZEPHYR_LINKER_DIR}/debug-sections.cmake) |
0 commit comments