From 510d7dbfb68374239821b2ce2b5664cf342cb605 Mon Sep 17 00:00:00 2001 From: Torsten Rasmussen Date: Fri, 21 May 2021 21:29:59 +0200 Subject: [PATCH] linker: align _ramfunc_ram/rom_start/size linker symbol names Cleanup and preparation commit for linker script generator. Zephyr linker scripts provides start and end symbols for each section, and sometimes even size and LMA start symbols. Generally, start and end symbols uses the following pattern, as: Section name: foo Section start symbol: __foo_start Section end symbol: __foo_end However, this pattern is not followed consistently. To allow for linker script generation and ensure consistent naming of symbols then the following pattern is introduced consistently to allow for cleaner linker script generation. Section name: foo Section start symbol: __foo_start Section end symbol: __foo_end Section size symbol: __foo_size Section LMA start symbol: __foo_load_start This commit aligns the symbols for _ramfunc_ram/rom to other symbols and in such a way they follow consistent pattern which allows for linker script and scatter file generation. The symbols are named according to the section name they describe. Section name is `ramfunc` The following symbols are aligned in this commit: - _ramfunc_ram_start -> __ramfunc_start - _ramfunc_ram_end -> __ramfunc_end - _ramfunc_ram_size -> __ramfunc_size - _ramfunc_rom_start -> __ramfunc_load_start Signed-off-by: Torsten Rasmussen --- arch/arm/core/aarch32/mpu/arm_core_mpu.c | 4 ++-- arch/common/ramfunc.ld | 12 ++++++------ include/linker/linker-defs.h | 8 ++++---- kernel/xip.c | 4 ++-- tests/arch/arm/arm_ramfunc/src/arm_ramfunc.c | 14 +++++++------- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/arch/arm/core/aarch32/mpu/arm_core_mpu.c b/arch/arm/core/aarch32/mpu/arm_core_mpu.c index 5ad66fe5968..5f2e9d2cd21 100644 --- a/arch/arm/core/aarch32/mpu/arm_core_mpu.c +++ b/arch/arm/core/aarch32/mpu/arm_core_mpu.c @@ -82,8 +82,8 @@ static const struct z_arm_mpu_partition static_regions[] = { #if defined(CONFIG_ARCH_HAS_RAMFUNC_SUPPORT) { /* Special RAM area for program text */ - .start = (uint32_t)&_ramfunc_ram_start, - .size = (uint32_t)&_ramfunc_ram_size, + .start = (uint32_t)&__ramfunc_start, + .size = (uint32_t)&__ramfunc_size, .attr = K_MEM_PARTITION_P_RX_U_RX, }, #endif /* CONFIG_ARCH_HAS_RAMFUNC_SUPPORT */ diff --git a/arch/common/ramfunc.ld b/arch/common/ramfunc.ld index b22579ec8ce..1fe92f55d59 100644 --- a/arch/common/ramfunc.ld +++ b/arch/common/ramfunc.ld @@ -9,12 +9,12 @@ SECTION_DATA_PROLOGUE(.ramfunc,,) { - MPU_ALIGN(_ramfunc_ram_size); - _ramfunc_ram_start = .; + MPU_ALIGN(__ramfunc_size); + __ramfunc_start = .; *(.ramfunc) *(".ramfunc.*") - MPU_ALIGN(_ramfunc_ram_size); - _ramfunc_ram_end = .; + MPU_ALIGN(__ramfunc_size); + __ramfunc_end = .; } GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) -_ramfunc_ram_size = _ramfunc_ram_end - _ramfunc_ram_start; -_ramfunc_rom_start = LOADADDR(.ramfunc); +__ramfunc_size = __ramfunc_end - __ramfunc_start; +__ramfunc_load_start = LOADADDR(.ramfunc); diff --git a/include/linker/linker-defs.h b/include/linker/linker-defs.h index d28f3c39c9b..848692a4449 100644 --- a/include/linker/linker-defs.h +++ b/include/linker/linker-defs.h @@ -336,10 +336,10 @@ extern char _nocache_ram_size[]; * section, stored in RAM instead of FLASH. */ #ifdef CONFIG_ARCH_HAS_RAMFUNC_SUPPORT -extern char _ramfunc_ram_start[]; -extern char _ramfunc_ram_end[]; -extern char _ramfunc_ram_size[]; -extern char _ramfunc_rom_start[]; +extern char __ramfunc_start[]; +extern char __ramfunc_end[]; +extern char __ramfunc_size[]; +extern char __ramfunc_load_start[]; #endif /* CONFIG_ARCH_HAS_RAMFUNC_SUPPORT */ /* Memory owned by the kernel. Memory region for thread privilege stack buffers, diff --git a/kernel/xip.c b/kernel/xip.c index 0498ae6bcd8..2a2c89e9396 100644 --- a/kernel/xip.c +++ b/kernel/xip.c @@ -28,8 +28,8 @@ void z_data_copy(void) (void)memcpy(&__data_region_start, &__data_region_load_start, __data_region_end - __data_region_start); #ifdef CONFIG_ARCH_HAS_RAMFUNC_SUPPORT - (void)memcpy(&_ramfunc_ram_start, &_ramfunc_rom_start, - (uintptr_t) &_ramfunc_ram_size); + (void)memcpy(&__ramfunc_start, &__ramfunc_load_start, + (uintptr_t) &__ramfunc_size); #endif /* CONFIG_ARCH_HAS_RAMFUNC_SUPPORT */ #if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_ccm), okay) (void)memcpy(&__ccm_data_start, &__ccm_data_rom_start, diff --git a/tests/arch/arm/arm_ramfunc/src/arm_ramfunc.c b/tests/arch/arm/arm_ramfunc/src/arm_ramfunc.c index 378bc8527bf..74948fbf2e1 100644 --- a/tests/arch/arm/arm_ramfunc/src/arm_ramfunc.c +++ b/tests/arch/arm/arm_ramfunc/src/arm_ramfunc.c @@ -26,22 +26,22 @@ void test_arm_ramfunc(void) * inside SRAM, and that arm_ram_function(.) is located inside * the .ramfunc section. */ - zassert_true((uint32_t)&_ramfunc_ram_size != 0, + zassert_true((uint32_t)&__ramfunc_size != 0, ".ramfunc linker section is empty"); - zassert_true(((uint32_t)&_ramfunc_ram_start >= (uint32_t)&_image_ram_start) - && ((uint32_t)&_ramfunc_ram_end < (uint32_t)&_image_ram_end), + zassert_true(((uint32_t)&__ramfunc_start >= (uint32_t)&_image_ram_start) + && ((uint32_t)&__ramfunc_end < (uint32_t)&_image_ram_end), ".ramfunc linker section not in RAM"); zassert_true( - (((uint32_t)&_ramfunc_ram_start) <= (uint32_t)arm_ram_function) && - (((uint32_t)&_ramfunc_ram_end) > (uint32_t)arm_ram_function), + (((uint32_t)&__ramfunc_start) <= (uint32_t)arm_ram_function) && + (((uint32_t)&__ramfunc_end) > (uint32_t)arm_ram_function), "arm_ram_function not loaded into .ramfunc"); /* If we build with User Mode support, verify that the * arm_ram_function(.) is user (read) accessible. */ #if defined(CONFIG_USERSPACE) - zassert_true(arch_buffer_validate((void *)&_ramfunc_ram_start, - (size_t)&_ramfunc_ram_size, 0) == 0 /* Success */, + zassert_true(arch_buffer_validate((void *)&__ramfunc_start, + (size_t)&__ramfunc_size, 0) == 0 /* Success */, ".ramfunc section not user accessible"); #endif /* CONFIG_USERSPACE */