Skip to content

Commit 33ffe00

Browse files
raffi-gdleach02
authored andcommitted
linker: Generate snippets files for dtcm and itcm
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 <[email protected]>
1 parent acfb87d commit 33ffe00

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

cmake/modules/extensions.cmake

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,8 @@ endfunction(zephyr_check_compiler_flag_hardcoded)
11701170
# DATA_SECTIONS Inside the RAMABLE_REGION GROUP, initialized.
11711171
# RAMFUNC_SECTION Inside the RAMFUNC RAMABLE_REGION GROUP, not initialized.
11721172
# NOCACHE_SECTION Inside the NOCACHE section
1173+
# ITCM_SECTION Inside the itcm section.
1174+
# DTCM_SECTION Inside the dtcm data section.
11731175
# SECTIONS Near the end of the file. Don't use this when linking into
11741176
# RAMABLE_REGION, use RAM_SECTIONS instead.
11751177
# PINNED_RODATA Similar to RODATA but pinned in memory.
@@ -1184,8 +1186,9 @@ endfunction(zephyr_check_compiler_flag_hardcoded)
11841186
# Use NOINIT, RWDATA, and RODATA unless they don't work for your use case.
11851187
#
11861188
# When placing into NOINIT, RWDATA, RODATA, ROM_START, RAMFUNC_SECTION,
1187-
# NOCACHE_SECTION the contents of the files will be placed inside
1188-
# an output section, so assume the section definition is already present, e.g.:
1189+
# NOCACHE_SECTION, DTCM_SECTION or ITCM_SECTION the contents of the files will
1190+
# be placed inside an output section, so assume the section definition is
1191+
# already present, e.g.:
11891192
# _mysection_start = .;
11901193
# KEEP(*(.mysection));
11911194
# _mysection_end = .;
@@ -1220,6 +1223,8 @@ function(zephyr_linker_sources location)
12201223
set(rodata_path "${snippet_base}/snippets-rodata.ld")
12211224
set(ramfunc_path "${snippet_base}/snippets-ramfunc-section.ld")
12221225
set(nocache_path "${snippet_base}/snippets-nocache-section.ld")
1226+
set(itcm_path "${snippet_base}/snippets-itcm-section.ld")
1227+
set(dtcm_path "${snippet_base}/snippets-dtcm-section.ld")
12231228

12241229
set(pinned_ram_sections_path "${snippet_base}/snippets-pinned-ram-sections.ld")
12251230
set(pinned_data_sections_path "${snippet_base}/snippets-pinned-data-sections.ld")
@@ -1237,6 +1242,8 @@ function(zephyr_linker_sources location)
12371242
file(WRITE ${rodata_path} "")
12381243
file(WRITE ${ramfunc_path} "")
12391244
file(WRITE ${nocache_path} "")
1245+
file(WRITE ${itcm_path} "")
1246+
file(WRITE ${dtcm_path} "")
12401247
file(WRITE ${pinned_ram_sections_path} "")
12411248
file(WRITE ${pinned_data_sections_path} "")
12421249
file(WRITE ${pinned_rodata_path} "")
@@ -1262,6 +1269,10 @@ function(zephyr_linker_sources location)
12621269
set(snippet_path "${ramfunc_path}")
12631270
elseif("${location}" STREQUAL "NOCACHE_SECTION")
12641271
set(snippet_path "${nocache_path}")
1272+
elseif("${location}" STREQUAL "ITCM_SECTION")
1273+
set(snippet_path "${itcm_path}")
1274+
elseif("${location}" STREQUAL "DTCM_SECTION")
1275+
set(snippet_path "${dtcm_path}")
12651276
elseif("${location}" STREQUAL "PINNED_RAM_SECTIONS")
12661277
set(snippet_path "${pinned_ram_sections_path}")
12671278
elseif("${location}" STREQUAL "PINNED_DATA_SECTIONS")

include/zephyr/arch/arm/cortex_m/scripts/linker.ld

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,11 @@ GROUP_START(ITCM)
396396
__itcm_start = .;
397397
*(.itcm)
398398
*(".itcm.*")
399+
400+
/* Located in generated directory. This file is populated by the
401+
* zephyr_linker_sources() Cmake function. */
402+
#include <snippets-itcm-section.ld>
403+
399404
__itcm_end = .;
400405
} GROUP_LINK_IN(ITCM AT> ROMABLE_REGION)
401406

@@ -430,6 +435,11 @@ GROUP_START(DTCM)
430435
__dtcm_data_start = .;
431436
*(.dtcm_data)
432437
*(".dtcm_data.*")
438+
439+
/* Located in generated directory. This file is populated by the
440+
* zephyr_linker_sources() Cmake function. */
441+
#include <snippets-dtcm-section.ld>
442+
433443
__dtcm_data_end = .;
434444
} GROUP_LINK_IN(DTCM AT> ROMABLE_REGION)
435445

include/zephyr/arch/riscv/common/linker.ld

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,11 @@ GROUP_START(ITCM)
327327
__itcm_start = .;
328328
*(.itcm)
329329
*(".itcm.*")
330+
331+
/* Located in generated directory. This file is populated by the
332+
* zephyr_linker_sources() Cmake function. */
333+
#include <snippets-itcm-section.ld>
334+
330335
__itcm_end = .;
331336
} GROUP_LINK_IN(ITCM AT> ROMABLE_REGION)
332337

@@ -361,6 +366,11 @@ GROUP_START(DTCM)
361366
__dtcm_data_start = .;
362367
*(.dtcm_data)
363368
*(".dtcm_data.*")
369+
370+
/* Located in generated directory. This file is populated by the
371+
* zephyr_linker_sources() Cmake function. */
372+
#include <snippets-dtcm-section.ld>
373+
364374
__dtcm_data_end = .;
365375
} GROUP_LINK_IN(DTCM AT> ROMABLE_REGION)
366376

soc/riscv/andes_v5/ae350/linker.ld

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,11 @@ GROUP_START(ITCM)
322322
__itcm_start = .;
323323
*(.itcm)
324324
*(".itcm.*")
325+
326+
/* Located in generated directory. This file is populated by the
327+
* zephyr_linker_sources() Cmake function. */
328+
#include <snippets-itcm-section.ld>
329+
325330
__itcm_end = .;
326331
} GROUP_LINK_IN(ITCM AT> ROMABLE_REGION)
327332

@@ -356,6 +361,11 @@ GROUP_START(DTCM)
356361
__dtcm_data_start = .;
357362
*(.dtcm_data)
358363
*(".dtcm_data.*")
364+
365+
/* Located in generated directory. This file is populated by the
366+
* zephyr_linker_sources() Cmake function. */
367+
#include <snippets-dtcm-section.ld>
368+
359369
__dtcm_data_end = .;
360370
} GROUP_LINK_IN(DTCM AT> ROMABLE_REGION)
361371

0 commit comments

Comments
 (0)