From b4c5f4b32b8121f1852467e9879869266a8d3126 Mon Sep 17 00:00:00 2001 From: Alexander Wachter Date: Wed, 3 Jul 2019 14:19:29 +0200 Subject: [PATCH] linker: Add dtcm section for Cortex M7 MCUs This commit adds a DTCM (Device Tightly Coupled Memory) section for Cortex F7 MCUs. The Address and length is defined in the corresponding device tree file. Signed-off-by: Alexander Wachter --- dts/bindings/arm/arm,dtcm.yaml | 17 +++++++++ include/arch/arm/cortex_m/scripts/linker.ld | 39 +++++++++++++++++++++ include/linker/linker-defs.h | 12 +++++++ include/linker/section_tags.h | 3 ++ include/linker/sections.h | 4 +++ kernel/init.c | 8 +++++ scripts/dts/extract/globals.py | 3 +- 7 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 dts/bindings/arm/arm,dtcm.yaml diff --git a/dts/bindings/arm/arm,dtcm.yaml b/dts/bindings/arm/arm,dtcm.yaml new file mode 100644 index 00000000000..3733065e7e1 --- /dev/null +++ b/dts/bindings/arm/arm,dtcm.yaml @@ -0,0 +1,17 @@ + +# SPDX-License-Identifier: Apache-2.0 +title: DTCM +version: 0.1 + +description: > + This binding gives a base representation of the Cortex M7 DTCM (Data Tightly Coupled Memory) + +inherits: + !include base.yaml + +properties: + compatible: + constraint: "arm,dtcm" + + reg: + category: required diff --git a/include/arch/arm/cortex_m/scripts/linker.ld b/include/arch/arm/cortex_m/scripts/linker.ld index f05465ff69f..765f1832e72 100644 --- a/include/arch/arm/cortex_m/scripts/linker.ld +++ b/include/arch/arm/cortex_m/scripts/linker.ld @@ -100,6 +100,9 @@ MEMORY #endif #ifdef DT_CCM_BASE_ADDRESS CCM (rw) : ORIGIN = DT_CCM_BASE_ADDRESS, LENGTH = DT_CCM_SIZE * 1K +#endif +#ifdef DT_DTCM_BASE_ADDRESS + DTCM (rw) : ORIGIN = DT_DTCM_BASE_ADDRESS, LENGTH = DT_DTCM_SIZE * 1K #endif SRAM (wx) : ORIGIN = RAM_ADDR, LENGTH = RAM_SIZE #ifdef CONFIG_BT_STM32_IPM @@ -425,6 +428,42 @@ SECTIONS GROUP_END(RAMABLE_REGION) +#ifdef DT_DTCM_BASE_ADDRESS +GROUP_START(DTCM) + + SECTION_PROLOGUE(_DTCM_BSS_SECTION_NAME, (NOLOAD),SUBALIGN(4)) + { + __dtcm_start = .; + __dtcm_bss_start = .; + *(.dtcm_bss) + *(".dtcm_bss.*") + } GROUP_LINK_IN(DTCM) + + __dtcm_bss_end = .; + + SECTION_PROLOGUE(_DTCM_NOINIT_SECTION_NAME, (NOLOAD),SUBALIGN(4)) + { + __dtcm_noinit_start = .; + *(.dtcm_noinit) + *(".dtcm_noinit.*") + } GROUP_LINK_IN(DTCM) + + __dtcm_noinit_end = .; + + SECTION_PROLOGUE(_DTCM_DATA_SECTION_NAME,,SUBALIGN(4)) + { + __dtcm_data_start = .; + *(.dtcm_data) + *(".dtcm_data.*") + } GROUP_LINK_IN(DTCM AT> ROMABLE_REGION) + + __dtcm_data_end = .; + __dtcm_end = .; + + __dtcm_data_rom_start = LOADADDR(_DTCM_DATA_SECTION_NAME); + +GROUP_END(DTCM) +#endif /* DT_DTCM_BASE_ADDRESS */ #ifdef CONFIG_CUSTOM_SECTIONS_LD /* Located in project source directory */ #include diff --git a/include/linker/linker-defs.h b/include/linker/linker-defs.h index 869add38a13..4ea3dc07d51 100644 --- a/include/linker/linker-defs.h +++ b/include/linker/linker-defs.h @@ -216,6 +216,18 @@ extern char __ccm_noinit_end[]; extern char __ccm_end[]; #endif /* DT_CCM_BASE_ADDRESS */ +#ifdef DT_DTCM_BASE_ADDRESS +extern char __dtcm_data_start[]; +extern char __dtcm_data_end[]; +extern char __dtcm_bss_start[]; +extern char __dtcm_bss_end[]; +extern char __dtcm_noinit_start[]; +extern char __dtcm_noinit_end[]; +extern char __dtcm_data_rom_start[]; +extern char __dtcm_start[]; +extern char __dtcm_end[]; +#endif /* DT_DTCM_BASE_ADDRESS */ + /* Used by the Security Attribution Unit to configure the * Non-Secure Callable region. */ diff --git a/include/linker/section_tags.h b/include/linker/section_tags.h index 14ca8b86002..a578e8609d2 100644 --- a/include/linker/section_tags.h +++ b/include/linker/section_tags.h @@ -23,6 +23,9 @@ #define __ccm_data_section Z_GENERIC_SECTION(_CCM_DATA_SECTION_NAME) #define __ccm_bss_section Z_GENERIC_SECTION(_CCM_BSS_SECTION_NAME) #define __ccm_noinit_section Z_GENERIC_SECTION(_CCM_NOINIT_SECTION_NAME) +#define __dtcm_data_section Z_GENERIC_SECTION(_DTCM_DATA_SECTION_NAME) +#define __dtcm_bss_section Z_GENERIC_SECTION(_DTCM_BSS_SECTION_NAME) +#define __dtcm_noinit_section Z_GENERIC_SECTION(_DTCM_NOINIT_SECTION_NAME) #define __imx_boot_conf_section Z_GENERIC_SECTION(IMX_BOOT_CONF) #define __imx_boot_data_section Z_GENERIC_SECTION(IMX_BOOT_DATA) #define __imx_boot_ivt_section Z_GENERIC_SECTION(IMX_BOOT_IVT) diff --git a/include/linker/sections.h b/include/linker/sections.h index e64a76b9a67..5348af159e9 100644 --- a/include/linker/sections.h +++ b/include/linker/sections.h @@ -56,6 +56,10 @@ #define _CCM_DATA_SECTION_NAME .ccm_data #define _CCM_BSS_SECTION_NAME .ccm_bss #define _CCM_NOINIT_SECTION_NAME .ccm_noinit + +#define _DTCM_DATA_SECTION_NAME .dtcm_data +#define _DTCM_BSS_SECTION_NAME .dtcm_bss +#define _DTCM_NOINIT_SECTION_NAME .dtcm_noinit #endif #define IMX_BOOT_CONF .boot_hdr.conf diff --git a/kernel/init.c b/kernel/init.c index 67b8e96dbcf..73a413be8b4 100644 --- a/kernel/init.c +++ b/kernel/init.c @@ -155,6 +155,10 @@ void z_bss_zero(void) (void)memset(&__ccm_bss_start, 0, ((u32_t) &__ccm_bss_end - (u32_t) &__ccm_bss_start)); #endif +#ifdef DT_DTCM_BASE_ADDRESS + (void)memset(&__dtcm_bss_start, 0, + ((u32_t) &__dtcm_bss_end - (u32_t) &__dtcm_bss_start)); +#endif #ifdef CONFIG_CODE_DATA_RELOCATION extern void bss_zeroing_relocation(void); @@ -192,6 +196,10 @@ void z_data_copy(void) (void)memcpy(&__ccm_data_start, &__ccm_data_rom_start, __ccm_data_end - __ccm_data_start); #endif +#ifdef DT_DTCM_BASE_ADDRESS + (void)memcpy(&__dtcm_data_start, &__dtcm_data_rom_start, + __dtcm_data_end - __dtcm_data_start); +#endif #ifdef CONFIG_CODE_DATA_RELOCATION extern void data_copy_xip_relocation(void); diff --git a/scripts/dts/extract/globals.py b/scripts/dts/extract/globals.py index 22438937b4e..426699ef2fc 100644 --- a/scripts/dts/extract/globals.py +++ b/scripts/dts/extract/globals.py @@ -24,7 +24,8 @@ old_alias_names = False regs_config = { 'zephyr,sram' : 'DT_SRAM', - 'zephyr,ccm' : 'DT_CCM' + 'zephyr,ccm' : 'DT_CCM', + 'zephyr,dtcm' : 'DT_DTCM' } name_config = {