Skip to content

Commit 0e3192e

Browse files
danieldegrassegithub-actions[bot]
authored andcommitted
arch: common: fix copy for ramfunc region during XIP init
ramfunc region is copied into RAM from FLASH region during XIP init. We copy from the loadaddr of the region, and were previously loading to the symbol __ramfunc_start. This is incorrect when using an MPU with alignment requirements, as the __ramfunc_start symbol may have padding placed before it in the region. The __ramfunc_start symbol still needs to be aligned in order to be used by the MPU though, so define a new symbol __ramfunc_region_start, and use that symbol when copying the __ramfunc region from FLASH to RAM. Fixes #75296 Signed-off-by: Daniel DeGrasse <[email protected]> (cherry picked from commit 6023d6a)
1 parent 1ddf975 commit 0e3192e

File tree

4 files changed

+5
-2
lines changed

4 files changed

+5
-2
lines changed

arch/common/ramfunc.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
SECTION_DATA_PROLOGUE(.ramfunc,,)
1111
{
12+
__ramfunc_region_start = .;
1213
MPU_ALIGN(__ramfunc_size);
1314
__ramfunc_start = .;
1415
*(.ramfunc)

cmake/linker_script/arm/linker.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ endif()
144144

145145
include(${COMMON_ZEPHYR_LINKER_DIR}/ram-end.cmake)
146146

147+
zephyr_linker_symbol(SYMBOL __ramfunc_region_start EXPR "ADDR(.ramfunc)")
147148
zephyr_linker_symbol(SYMBOL __kernel_ram_start EXPR "(@__bss_start@)")
148149
zephyr_linker_symbol(SYMBOL __kernel_ram_end EXPR "(${RAM_ADDR} + ${RAM_SIZE})")
149150
zephyr_linker_symbol(SYMBOL __kernel_ram_size EXPR "(@__kernel_ram_end@ - @__bss_start@)")

include/zephyr/linker/linker-defs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ extern char _nocache_ram_size[];
230230
* section, stored in RAM instead of FLASH.
231231
*/
232232
#ifdef CONFIG_ARCH_HAS_RAMFUNC_SUPPORT
233+
extern char __ramfunc_region_start[];
233234
extern char __ramfunc_start[];
234235
extern char __ramfunc_end[];
235236
extern char __ramfunc_size[];

kernel/xip.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ void z_data_copy(void)
2828
z_early_memcpy(&__data_region_start, &__data_region_load_start,
2929
__data_region_end - __data_region_start);
3030
#ifdef CONFIG_ARCH_HAS_RAMFUNC_SUPPORT
31-
z_early_memcpy(&__ramfunc_start, &__ramfunc_load_start,
32-
(uintptr_t) &__ramfunc_size);
31+
z_early_memcpy(&__ramfunc_region_start, &__ramfunc_load_start,
32+
__ramfunc_end - __ramfunc_region_start);
3333
#endif /* CONFIG_ARCH_HAS_RAMFUNC_SUPPORT */
3434
#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_ccm), okay)
3535
z_early_memcpy(&__ccm_data_start, &__ccm_data_rom_start,

0 commit comments

Comments
 (0)