From 91c5b84cd5aa58bef2025815956ee02022a08ac8 Mon Sep 17 00:00:00 2001 From: Adithya Baglody Date: Tue, 13 Nov 2018 16:57:45 +0530 Subject: [PATCH] kernel: init.c: Added required hooks for the relocation This patch splits the text section into 2 parts. The first section will have some info regarding vector tables and debug info. The second section will have the complete text section. This is needed to force the required functions and data variables the correct locations. This is due to the behavior of the linker. The linker will only link once and hence this text section had to be split to make room for the generated linker script. Added a new Kconfig CODE_DATA_RELOCATION which when enabled will invoke the script, which does the required relocation. Added hooks inside init.c for bss zeroing and data copy operations. Needed when we have to copy data from ROM to required memory type. Signed-off-by: Adithya Baglody --- Kconfig.zephyr | 9 +++++++++ include/arch/arm/cortex_m/scripts/linker.ld | 10 ++++++++++ kernel/init.c | 10 ++++++++++ 3 files changed, 29 insertions(+) diff --git a/Kconfig.zephyr b/Kconfig.zephyr index 476cf87c132..ccd4adbd6ae 100644 --- a/Kconfig.zephyr +++ b/Kconfig.zephyr @@ -69,6 +69,15 @@ config LINKER_ORPHAN_SECTION_ERROR endchoice +config CODE_DATA_RELOCATION + bool "Relocate code/data sections" + depends on ARM + help + When selected this will relocate .text, data and .bss sections from + the specified files and places it in the required memory region. The + files should be specified in the CMakeList.txt file with + a cmake API zephyr_code_relocation(). + config HAS_FLASH_LOAD_OFFSET bool help diff --git a/include/arch/arm/cortex_m/scripts/linker.ld b/include/arch/arm/cortex_m/scripts/linker.ld index 1f8b1cc5a59..9c95c5d0cdf 100644 --- a/include/arch/arm/cortex_m/scripts/linker.ld +++ b/include/arch/arm/cortex_m/scripts/linker.ld @@ -161,6 +161,16 @@ SECTIONS KEEP(*(".kinetis_flash_config.*")) _vector_end = .; + } GROUP_LINK_IN(ROMABLE_REGION) + +#ifdef CONFIG_CODE_DATA_RELOCATION + +#include + +#endif /* CONFIG_CODE_DATA_RELOCATION */ + + SECTION_PROLOGUE(_TEXT_SECTION_NAME_2,,) + { _image_text_start = .; *(.text) *(".text.*") diff --git a/kernel/init.c b/kernel/init.c index 59d2ed61f4e..d8c3bc3b953 100644 --- a/kernel/init.c +++ b/kernel/init.c @@ -147,6 +147,11 @@ void _bss_zero(void) (void)memset(&__ccm_bss_start, 0, ((u32_t) &__ccm_bss_end - (u32_t) &__ccm_bss_start)); #endif +#ifdef CONFIG_CODE_DATA_RELOCATION + extern void bss_zeroing_relocation(void); + + bss_zeroing_relocation(); +#endif /* CONFIG_CODE_DATA_RELOCATION */ #ifdef CONFIG_APPLICATION_MEMORY (void)memset(&__app_bss_start, 0, ((u32_t) &__app_bss_end - (u32_t) &__app_bss_start)); @@ -171,6 +176,11 @@ void _data_copy(void) (void)memcpy(&__ccm_data_start, &__ccm_data_rom_start, ((u32_t) &__ccm_data_end - (u32_t) &__ccm_data_start)); #endif +#ifdef CONFIG_CODE_DATA_RELOCATION + extern void data_copy_xip_relocation(void); + + data_copy_xip_relocation(); +#endif /* CONFIG_CODE_DATA_RELOCATION */ #ifdef CONFIG_APP_SHARED_MEM (void)memcpy(&_app_smem_start, &_app_smem_rom_start, ((u32_t) &_app_smem_end - (u32_t) &_app_smem_start));