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));