diff --git a/arch/common/CMakeLists.txt b/arch/common/CMakeLists.txt index 3f6e5984c26..b39cc404ac0 100644 --- a/arch/common/CMakeLists.txt +++ b/arch/common/CMakeLists.txt @@ -38,6 +38,7 @@ zephyr_linker_sources_ifdef(CONFIG_NOCACHE_MEMORY if (DEFINED CONFIG_ARM OR DEFINED CONFIG_X86 OR DEFINED CONFIG_ARM64 OR DEFINED CONFIG_SOC_OPENISA_RV32M1_RISCV32) zephyr_linker_sources(ROM_START SORT_KEY 0x0 rom_start_offset.ld) + # Handled in ld.cmake endif() diff --git a/cmake/linker_script/common/common-ram.cmake b/cmake/linker_script/common/common-ram.cmake new file mode 100644 index 00000000000..bb38b79e309 --- /dev/null +++ b/cmake/linker_script/common/common-ram.cmake @@ -0,0 +1,104 @@ +# originates from common-ram.ld + +if(CONFIG_GEN_SW_ISR_TABLE AND CONFIG_DYNAMIC_INTERRUPTS) + # ld align has been changed to subalign to provide identical behavior scatter vs. ld. + zephyr_linker_section(NAME sw_isr_table + GROUP DATA_REGION + ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_ARCH_SW_ISR_TABLE_ALIGN} + ) + zephyr_linker_section_configure( + SECTION sw_isr_table + INPUT ".gnu.linkonce.sw_isr_table*" + ) +endif() + +zephyr_linker_section(NAME device_states GROUP DATA_REGION NOINPUT ${XIP_ALIGN_WITH_INPUT}) +zephyr_linker_section_configure(SECTION device_states + KEEP INPUT ".z_devstate" ".z_devstate.*" +) + +if(CONFIG_PM_DEVICE) + zephyr_linker_section(NAME pm_device_slots GROUP DATA_REGION TYPE NOLOAD NOINPUT ${XIP_ALIGN_WITH_INPUT}) + zephyr_linker_section_configure(SECTION pm_device_slots KEEP INPUT ".z_pm_device_slots") +endif() + +zephyr_linker_section(NAME initshell GROUP DATA_REGION NOINPUT ${XIP_ALIGN_WITH_INPUT}) +zephyr_linker_section_configure(SECTION initshell + KEEP INPUT ".shell_module_*" + SYMBOLS __shell_module_start __shell_module_end +) +zephyr_linker_section_configure(SECTION initshell + KEEP INPUT ".shell_cmd_*" + SYMBOLS __shell_cmd_start __shell_end_end +) + +zephyr_linker_section(NAME log_dynamic GROUP DATA_REGION NOINPUT) +zephyr_linker_section_configure(SECTION log_dynamic KEEP INPUT ".log_dynamic_*") + +zephyr_iterable_section(NAME _static_thread_data GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) + +if(CONFIG_USERSPACE) + # All kernel objects within are assumed to be either completely + # initialized at build time, or initialized automatically at runtime + # via iteration before the POST_KERNEL phase. + # + # These two symbols only used by gen_kobject_list.py + # _static_kernel_objects_begin = .; +endif() + +zephyr_iterable_section(NAME k_timer GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) +zephyr_iterable_section(NAME k_mem_slab GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) +zephyr_iterable_section(NAME k_mem_pool GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) +zephyr_iterable_section(NAME k_heap GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) +zephyr_iterable_section(NAME k_mutex GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) +zephyr_iterable_section(NAME k_stack GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) +zephyr_iterable_section(NAME k_msgq GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) +zephyr_iterable_section(NAME k_mbox GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) +zephyr_iterable_section(NAME k_pipe GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) +zephyr_iterable_section(NAME k_sem GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) +zephyr_iterable_section(NAME k_queue GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) +zephyr_iterable_section(NAME k_condvar GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) + +zephyr_linker_section(NAME _net_buf_pool_area GROUP DATA_REGION NOINPUT ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) +zephyr_linker_section_configure(SECTION _net_buf_pool_area + KEEP SORT NAME INPUT "._net_buf_pool.static.*" + SYMBOLS _net_buf_pool_list +) + +if(CONFIG_NETWORKING) + zephyr_iterable_section(NAME net_if GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) + zephyr_iterable_section(NAME net_if_dev GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) + zephyr_iterable_section(NAME net_l2 GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) + zephyr_iterable_section(NAME eth_bridge GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) +endif() + +if(CONFIG_UART_MUX) + zephyr_linker_section(NAME uart_mux GROUP DATA_REGION NOINPUT ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) + zephyr_linker_section_configure(SECTION uart_mux + KEEP SORT NAME INPUT ".uart_mux.*" + ) +endif() + +if(CONFIG_USB_DEVICE_STACK) + zephyr_linker_section(NAME usb_descriptor GROUP DATA_REGION NOINPUT ${XIP_ALIGN_WITH_INPUT} SUBALIGN 1) + zephyr_linker_section_configure(SECTION usb_descriptor + KEEP SORT NAME INPUT ".usb.descriptor*" + ) + + zephyr_linker_section(NAME usb_data GROUP DATA_REGION NOINPUT ${XIP_ALIGN_WITH_INPUT} SUBALIGN 1) + zephyr_linker_section_configure(SECTION usb_data + KEEP SORT NAME INPUT ".usb.data*" + ) +endif() + +if(CONFIG_USB_DEVICE_BOS) + zephyr_linker_section(NAME usb_bos_desc GROUP DATA_REGION NOINPUT ${XIP_ALIGN_WITH_INPUT} SUBALIGN 1) + zephyr_linker_section_configure(SECTION usb_data + KEEP SORT NAME INPUT ".usb.bos_desc" + ) +endif() + +#if(CONFIG_USERSPACE) +# _static_kernel_objects_end = .; +#endif() +# diff --git a/cmake/linker_script/common/common-rom.cmake b/cmake/linker_script/common/common-rom.cmake new file mode 100644 index 00000000000..6f873e5d6d0 --- /dev/null +++ b/cmake/linker_script/common/common-rom.cmake @@ -0,0 +1,183 @@ +# originates from common-rom.ld + +zephyr_linker_section(NAME init KVMA RAM_REGION GROUP RODATA_REGION) +zephyr_linker_section_obj_level(SECTION init LEVEL PRE_KERNEL_1) +zephyr_linker_section_obj_level(SECTION init LEVEL PRE_KERNEL_2) +zephyr_linker_section_obj_level(SECTION init LEVEL POST_KERNEL) +zephyr_linker_section_obj_level(SECTION init LEVEL APPLICATION) +zephyr_linker_section_obj_level(SECTION init LEVEL SMP) + +zephyr_linker_section(NAME device KVMA RAM_REGION GROUP RODATA_REGION) +zephyr_linker_section_obj_level(SECTION device LEVEL PRE_KERNEL_1) +zephyr_linker_section_obj_level(SECTION device LEVEL PRE_KERNEL_2) +zephyr_linker_section_obj_level(SECTION device LEVEL POST_KERNEL) +zephyr_linker_section_obj_level(SECTION device LEVEL APPLICATION) +zephyr_linker_section_obj_level(SECTION device LEVEL SMP) + +if(CONFIG_GEN_SW_ISR_TABLE AND NOT CONFIG_DYNAMIC_INTERRUPTS) + # ld align has been changed to subalign to provide identical behavior scatter vs. ld. + zephyr_linker_section(NAME sw_isr_table KVMA FLASH GROUP RODATA_REGION SUBALIGN ${CONFIG_ARCH_SW_ISR_TABLE_ALIGN} NOINPUT) + zephyr_linker_section_configure( + SECTION sw_isr_table + INPUT ".gnu.linkonce.sw_isr_table*" + ) +endif() + +zephyr_linker_section(NAME initlevel_error KVMA RAM_REGION GROUP RODATA_REGION NOINPUT) +zephyr_linker_section_configure(SECTION initlevel_error INPUT ".z_init_[_A-Z0-9]*" KEEP SORT NAME) +# How to do cross linker ? +# ASSERT(SIZEOF(initlevel_error) == 0, "Undefined initialization levels used.") + + +if(CONFIG_CPLUSPLUS) + zephyr_linker_section(NAME ctors KVMA RAM_REGION GROUP RODATA_REGION NOINPUT) + # + # The compiler fills the constructor pointers table below, + # hence symbol __CTOR_LIST__ must be aligned on word + # boundary. To align with the C++ standard, the first elment + # of the array contains the number of actual constructors. The + # last element is NULL. + # +# ToDo: Checkup on scatter loading. How to manage ? +# https://www.keil.com/support/man/docs/armlink/armlink_pge1362066006368.htm +# https://developer.arm.com/documentation/dui0378/g/The-ARM-C-and-C---Libraries +# if(CONFIG_64BIT) +# . = ALIGN(8); +# __CTOR_LIST__ = .; +# QUAD((__CTOR_END__ - __CTOR_LIST__) / 8 - 2) +# KEEP(*(SORT_BY_NAME(".ctors*"))) +# QUAD(0) +# __CTOR_END__ = .; +# else() +# . = ALIGN(4); +# __CTOR_LIST__ = .; +# LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2) +# KEEP(*(SORT_BY_NAME(".ctors*"))) +# LONG(0) +# __CTOR_END__ = .; +# endif() +# } GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) +# +# SECTION_PROLOGUE(init_array,,) +# { +# . = ALIGN(4); +# __init_array_start = .; +# KEEP(*(SORT_BY_NAME(".init_array*"))) +# __init_array_end = .; +# } GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) +endif() + +if(CONFIG_USERSPACE) + # Build-time assignment of permissions to kernel objects to + # threads declared with K_THREAD_DEFINE() + zephyr_linker_section( + NAME z_object_assignment_area + VMA FLASH NOINPUT + SUBALIGN 4 + ) + zephyr_linker_section_configure( + SECTION z_object_assignment + INPUT ".z_object_assignment.static.*" + KEEP SORT NAME + ) +endif() + +zephyr_linker_section( + NAME app_shmem_regions + KVMA RAM_REGION GROUP RODATA_REGION NOINPUT ${XIP_ALIGN_WITH_INPUT} +) +zephyr_linker_section_configure( + SECTION app_shmem_regions + INPUT ".app_regions.*" + KEEP SORT NAME +) + +if(CONFIG_NET_SOCKETS) + zephyr_iterable_section(NAME net_socket_register KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4) +endif() + + +if(CONFIG_NET_L2_PPP) + zephyr_iterable_section(NAME ppp_protocol_handler KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4) +endif() + +zephyr_iterable_section(NAME bt_l2cap_fixed_chan KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4) + +if(CONFIG_BT_BREDR) + zephyr_iterable_section(NAME bt_l2cap_br_fixed_chan KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4) +endif() + +if(CONFIG_BT_CONN) + zephyr_iterable_section(NAME bt_conn_cb KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4) +endif() + +zephyr_iterable_section(NAME bt_gatt_service_static KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4) + +if(CONFIG_BT_MESH) + zephyr_iterable_section(NAME bt_mesh_subnet_cb KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4) + zephyr_iterable_section(NAME bt_mesh_app_key_cb KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4) + + zephyr_iterable_section(NAME bt_mesh_hb_cb KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4) +endif() + +if(CONFIG_BT_MESH_FRIEND) + zephyr_iterable_section(NAME bt_mesh_friend_cb KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4) +endif() + +if(CONFIG_BT_MESH_LOW_POWER) + zephyr_iterable_section(NAME bt_mesh_lpn_cb KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4) +endif() + +if(CONFIG_BT_MESH_PROXY) + zephyr_iterable_section(NAME bt_mesh_proxy_cb KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4) +endif() + +if(CONFIG_EC_HOST_CMD) + zephyr_iterable_section(NAME ec_host_cmd_handler KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4) +endif() + +if(CONFIG_SETTINGS) + zephyr_iterable_section(NAME settings_handler_static KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4) +endif() + +zephyr_iterable_section(NAME k_p4wq_initparam KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4) + +if(CONFIG_EMUL) + zephyr_linker_section(NAME emulators_section GROUP RODATA_REGION) + zephyr_linker_section_configure(SECTION emulators_section INPUT ".emulators" KEEP SORT NAME ${XIP_ALIGN_WITH_INPUT}) +endif() + +if(CONFIG_DNS_SD) + zephyr_iterable_section(NAME dns_sd_rec KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4) +endif() + +if(CONFIG_PCIE) + zephyr_linker_section(NAME irq_alloc GROUP RODATA_REGION NOINPUT ${XIP_ALIGN_WITH_INPUT}) + zephyr_linker_section_configure(SECTION irq_alloc INPUT ".irq_alloc*" KEEP SORT NAME) +endif() + +zephyr_linker_section(NAME log_strings KVMA RAM_REGION GROUP RODATA_REGION NOINPUT ${XIP_ALIGN_WITH_INPUT}) +zephyr_linker_section_configure(SECTION log_strings INPUT ".log_strings*" KEEP SORT NAME) + +zephyr_linker_section(NAME log_const KVMA RAM_REGION GROUP RODATA_REGION NOINPUT ${XIP_ALIGN_WITH_INPUT}) +zephyr_linker_section_configure(SECTION log_const INPUT ".log_const_*" KEEP SORT NAME) + +zephyr_linker_section(NAME log_backends KVMA RAM_REGION GROUP RODATA_REGION NOINPUT ${XIP_ALIGN_WITH_INPUT}) +zephyr_linker_section_configure(SECTION log_backends INPUT ".log_backends.*" KEEP) + +zephyr_iterable_section(NAME shell KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4) + +zephyr_linker_section(NAME shell_root_cmds KVMA RAM_REGION GROUP RODATA_REGION NOINPUT ${XIP_ALIGN_WITH_INPUT}) +zephyr_linker_section_configure(SECTION shell_root_cmds INPUT ".shell_root_cmd_*" KEEP SORT NAME) + +zephyr_linker_section(NAME font_entry KVMA RAM_REGION GROUP RODATA_REGION NOINPUT ${XIP_ALIGN_WITH_INPUT}) +zephyr_linker_section_configure(SECTION font_entry INPUT "._cfb_font.*" KEEP SORT NAME) + +zephyr_iterable_section(NAME tracing_backend KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4) + +zephyr_linker_section(NAME zephyr_dbg_info KVMA RAM_REGION GROUP RODATA_REGION NOINPUT ${XIP_ALIGN_WITH_INPUT}) +zephyr_linker_section_configure(SECTION zephyr_dbg_info INPUT ".zephyr_dbg_info" KEEP) + +zephyr_linker_section(NAME device_handles KVMA RAM_REGION GROUP RODATA_REGION NOINPUT ${XIP_ALIGN_WITH_INPUT} ENDALIGN 16) +zephyr_linker_section_configure(SECTION device_handles INPUT .__device_handles_pass1* KEEP SORT NAME PASS 1) +zephyr_linker_section_configure(SECTION device_handles INPUT .__device_handles_pass2* KEEP SORT NAME PASS 2) diff --git a/cmake/linker_script/common/debug-sections.cmake b/cmake/linker_script/common/debug-sections.cmake new file mode 100644 index 00000000000..397d4bdb1d7 --- /dev/null +++ b/cmake/linker_script/common/debug-sections.cmake @@ -0,0 +1,50 @@ +# Content of this file originates from include/linker/debug-sections.ld +# Following sections are obtained via 'ld --verbose' + +# Stabs debugging sections. +zephyr_linker_section(NAME .stab ADDRESS 0) +zephyr_linker_section(NAME .stabstr ADDRESS 0) +zephyr_linker_section(NAME .stab.excl ADDRESS 0) +zephyr_linker_section(NAME .stab.exclstr ADDRESS 0) +zephyr_linker_section(NAME .stab.index ADDRESS 0) +zephyr_linker_section(NAME .stab.indexstr ADDRESS 0) +zephyr_linker_section(NAME .gnu.build.attributes ADDRESS 0) +zephyr_linker_section(NAME .comment ADDRESS 0) + +# DWARF debug sections. +# Symbols in the DWARF debugging sections are relative to the beginning +# of the section so we begin them at 0. +# DWARF 1 */ +zephyr_linker_section(NAME .debug ADDRESS 0) +zephyr_linker_section(NAME .line ADDRESS 0) + +# GNU DWARF 1 extensions +zephyr_linker_section(NAME .debug_srcinfo ADDRESS 0) +zephyr_linker_section(NAME .debug_sfnames ADDRESS 0) + +# DWARF 1.1 and DWARF 2 +zephyr_linker_section(NAME .debug_aranges ADDRESS 0) +zephyr_linker_section(NAME .debug_pubnames ADDRESS 0) + +# DWARF 2 +zephyr_linker_section(NAME .debug_info ADDRESS 0) +zephyr_linker_section_configure(SECTION .debug_info INPUT ".gnu.linkonce.wi.*") +zephyr_linker_section(NAME .debug_abbrev ADDRESS 0) +zephyr_linker_section(NAME .debug_line ADDRESS 0) +zephyr_linker_section_configure(SECTION .debug_line INPUT ".debug_line_end") +zephyr_linker_section(NAME .debug_frame ADDRESS 0) +zephyr_linker_section(NAME .debug_str ADDRESS 0) +zephyr_linker_section(NAME .debug_loc ADDRESS 0) +zephyr_linker_section(NAME .debug_macinfo ADDRESS 0) + + #SGI/MIPS DWARF 2 extensions +zephyr_linker_section(NAME .debug_weaknames ADDRESS 0) +zephyr_linker_section(NAME .debug_funcnames ADDRESS 0) +zephyr_linker_section(NAME .debug_typenames ADDRESS 0) +zephyr_linker_section(NAME .debug_varnames ADDRESS 0) + +# DWARF 3 +zephyr_linker_section(NAME .debug_pubtypes ADDRESS 0) +zephyr_linker_section(NAME .debug_ranges ADDRESS 0) +# DWARF Extension. +zephyr_linker_section(NAME .debug_macro ADDRESS 0) diff --git a/cmake/linker_script/common/thread-local-storage.cmake b/cmake/linker_script/common/thread-local-storage.cmake new file mode 100644 index 00000000000..96d09d6a04a --- /dev/null +++ b/cmake/linker_script/common/thread-local-storage.cmake @@ -0,0 +1,39 @@ +# originates from thread-local-storage.ld + +if(CONFIG_THREAD_LOCAL_STORAGE) + zephyr_linker_section(NAME .tdata LMA FLASH NOINPUT) + zephyr_linker_section_configure(SECTION .tdata INPUT ".gnu.linkonce.td.*") + # GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) + + zephyr_linker_section(NAME .tbss LMA FLASH NOINPUT) + zephyr_linker_section_configure(SECTION .tbss INPUT ".gnu.linkonce.tb.*") + zephyr_linker_section_configure(SECTION .tbss INPUT ".tcommon") + # GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) + + # + # These needs to be outside of the tdata/tbss + # sections or else they would be considered + # thread-local variables, and the code would use + # the wrong values. + # + # This scheme is not yet handled + if(CONFIG_XIP) +# /* The "master copy" of tdata should be only in flash on XIP systems */ +# PROVIDE(__tdata_start = LOADADDR(tdata)); + else() +# PROVIDE(__tdata_start = ADDR(tdata)); + endif() +# PROVIDE(__tdata_size = SIZEOF(tdata)); +# PROVIDE(__tdata_end = __tdata_start + __tdata_size); +# PROVIDE(__tdata_align = ALIGNOF(tdata)); +# +# PROVIDE(__tbss_start = ADDR(tbss)); +# PROVIDE(__tbss_size = SIZEOF(tbss)); +# PROVIDE(__tbss_end = __tbss_start + __tbss_size); +# PROVIDE(__tbss_align = ALIGNOF(tbss)); +# +# PROVIDE(__tls_start = __tdata_start); +# PROVIDE(__tls_end = __tbss_end); +# PROVIDE(__tls_size = __tbss_end - __tdata_start); + +endif()