Skip to content

Commit

Permalink
linker: Generate snippets files for dtcm and itcm
Browse files Browse the repository at this point in the history
This allows to link code and data blocks, e.g. the vector table, into
tightly coupled memory using `zephyr_linker_sources`.

Signed-off-by: Greter Raffael <rgreter@baumer.com>
  • Loading branch information
raffi-g authored and dleach02 committed Jan 25, 2024
1 parent acfb87d commit 33ffe00
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
15 changes: 13 additions & 2 deletions cmake/modules/extensions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,8 @@ endfunction(zephyr_check_compiler_flag_hardcoded)
# DATA_SECTIONS Inside the RAMABLE_REGION GROUP, initialized.
# RAMFUNC_SECTION Inside the RAMFUNC RAMABLE_REGION GROUP, not initialized.
# NOCACHE_SECTION Inside the NOCACHE section
# ITCM_SECTION Inside the itcm section.
# DTCM_SECTION Inside the dtcm data section.
# SECTIONS Near the end of the file. Don't use this when linking into
# RAMABLE_REGION, use RAM_SECTIONS instead.
# PINNED_RODATA Similar to RODATA but pinned in memory.
Expand All @@ -1184,8 +1186,9 @@ endfunction(zephyr_check_compiler_flag_hardcoded)
# Use NOINIT, RWDATA, and RODATA unless they don't work for your use case.
#
# When placing into NOINIT, RWDATA, RODATA, ROM_START, RAMFUNC_SECTION,
# NOCACHE_SECTION the contents of the files will be placed inside
# an output section, so assume the section definition is already present, e.g.:
# NOCACHE_SECTION, DTCM_SECTION or ITCM_SECTION the contents of the files will
# be placed inside an output section, so assume the section definition is
# already present, e.g.:
# _mysection_start = .;
# KEEP(*(.mysection));
# _mysection_end = .;
Expand Down Expand Up @@ -1220,6 +1223,8 @@ function(zephyr_linker_sources location)
set(rodata_path "${snippet_base}/snippets-rodata.ld")
set(ramfunc_path "${snippet_base}/snippets-ramfunc-section.ld")
set(nocache_path "${snippet_base}/snippets-nocache-section.ld")
set(itcm_path "${snippet_base}/snippets-itcm-section.ld")
set(dtcm_path "${snippet_base}/snippets-dtcm-section.ld")

set(pinned_ram_sections_path "${snippet_base}/snippets-pinned-ram-sections.ld")
set(pinned_data_sections_path "${snippet_base}/snippets-pinned-data-sections.ld")
Expand All @@ -1237,6 +1242,8 @@ function(zephyr_linker_sources location)
file(WRITE ${rodata_path} "")
file(WRITE ${ramfunc_path} "")
file(WRITE ${nocache_path} "")
file(WRITE ${itcm_path} "")
file(WRITE ${dtcm_path} "")
file(WRITE ${pinned_ram_sections_path} "")
file(WRITE ${pinned_data_sections_path} "")
file(WRITE ${pinned_rodata_path} "")
Expand All @@ -1262,6 +1269,10 @@ function(zephyr_linker_sources location)
set(snippet_path "${ramfunc_path}")
elseif("${location}" STREQUAL "NOCACHE_SECTION")
set(snippet_path "${nocache_path}")
elseif("${location}" STREQUAL "ITCM_SECTION")
set(snippet_path "${itcm_path}")
elseif("${location}" STREQUAL "DTCM_SECTION")
set(snippet_path "${dtcm_path}")
elseif("${location}" STREQUAL "PINNED_RAM_SECTIONS")
set(snippet_path "${pinned_ram_sections_path}")
elseif("${location}" STREQUAL "PINNED_DATA_SECTIONS")
Expand Down
10 changes: 10 additions & 0 deletions include/zephyr/arch/arm/cortex_m/scripts/linker.ld
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,11 @@ GROUP_START(ITCM)
__itcm_start = .;
*(.itcm)
*(".itcm.*")

/* Located in generated directory. This file is populated by the
* zephyr_linker_sources() Cmake function. */
#include <snippets-itcm-section.ld>

__itcm_end = .;
} GROUP_LINK_IN(ITCM AT> ROMABLE_REGION)

Expand Down Expand Up @@ -430,6 +435,11 @@ GROUP_START(DTCM)
__dtcm_data_start = .;
*(.dtcm_data)
*(".dtcm_data.*")

/* Located in generated directory. This file is populated by the
* zephyr_linker_sources() Cmake function. */
#include <snippets-dtcm-section.ld>

__dtcm_data_end = .;
} GROUP_LINK_IN(DTCM AT> ROMABLE_REGION)

Expand Down
10 changes: 10 additions & 0 deletions include/zephyr/arch/riscv/common/linker.ld
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ GROUP_START(ITCM)
__itcm_start = .;
*(.itcm)
*(".itcm.*")

/* Located in generated directory. This file is populated by the
* zephyr_linker_sources() Cmake function. */
#include <snippets-itcm-section.ld>

__itcm_end = .;
} GROUP_LINK_IN(ITCM AT> ROMABLE_REGION)

Expand Down Expand Up @@ -361,6 +366,11 @@ GROUP_START(DTCM)
__dtcm_data_start = .;
*(.dtcm_data)
*(".dtcm_data.*")

/* Located in generated directory. This file is populated by the
* zephyr_linker_sources() Cmake function. */
#include <snippets-dtcm-section.ld>

__dtcm_data_end = .;
} GROUP_LINK_IN(DTCM AT> ROMABLE_REGION)

Expand Down
10 changes: 10 additions & 0 deletions soc/riscv/andes_v5/ae350/linker.ld
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ GROUP_START(ITCM)
__itcm_start = .;
*(.itcm)
*(".itcm.*")

/* Located in generated directory. This file is populated by the
* zephyr_linker_sources() Cmake function. */
#include <snippets-itcm-section.ld>

__itcm_end = .;
} GROUP_LINK_IN(ITCM AT> ROMABLE_REGION)

Expand Down Expand Up @@ -356,6 +361,11 @@ GROUP_START(DTCM)
__dtcm_data_start = .;
*(.dtcm_data)
*(".dtcm_data.*")

/* Located in generated directory. This file is populated by the
* zephyr_linker_sources() Cmake function. */
#include <snippets-dtcm-section.ld>

__dtcm_data_end = .;
} GROUP_LINK_IN(DTCM AT> ROMABLE_REGION)

Expand Down

0 comments on commit 33ffe00

Please sign in to comment.