scripts: code_relocate: support section filter

One might want to select the symbols to be relocated inside a file or
a library. To do this, one can use the FILTER argument of
zephyr_code_relocate which must contain a regular expression of the
section names to be selected for relocation.

The test_function_in_sram2 test case in
`tests/application_development/code_relocation` has been updated to
verify that only one function `function_in_sram()` is relocated to ram
and that the function `function_not_relocated()` is not being relocated
when using relocation filter.

Signed-off-by: Sylvain Chouleur <sylvain.chouleur@gmail.com>
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
Sylvain Chouleur 2024-06-17 12:11:04 +02:00 committed by Benjamin Cabé
commit 4454734d12
6 changed files with 96 additions and 27 deletions

View file

@ -17,7 +17,7 @@ endif()
# Code relocation feature
zephyr_code_relocate(FILES src/test_file1.c ${SRAM2_PHDR} LOCATION SRAM2)
zephyr_code_relocate(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/test_file2.c ${RAM_PHDR} LOCATION RAM)
zephyr_code_relocate(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/test_file2.c ${RAM_PHDR} LOCATION RAM FILTER ".*sram")
# Add custom library that we can relocate code for
add_subdirectory(test_lib)

View file

@ -23,12 +23,15 @@ __in_section(rodata, sram2, var) const uint32_t var_sram2_rodata = 100U;
__in_section(custom_section, static, var) uint32_t var_custom_data = 1U;
extern void function_in_sram(int32_t value);
extern void function_not_relocated(int32_t value);
void function_in_custom_section(void);
#define HAS_SRAM2_DATA_SECTION (CONFIG_ARM)
ZTEST(code_relocation, test_function_in_sram2)
{
extern uintptr_t __ram_text_reloc_start;
extern uintptr_t __ram_text_reloc_end;
extern uintptr_t __sram2_text_reloc_start;
extern uintptr_t __sram2_text_reloc_end;
extern uintptr_t __sram2_data_reloc_start;
@ -64,7 +67,20 @@ ZTEST(code_relocation, test_function_in_sram2)
"var_sram2_bss not in sram2_bss region");
/* Print values from sram */
printk("Address of function_in_sram %p\n", &function_in_sram);
zassert_between_inclusive((uintptr_t)&function_in_sram,
(uintptr_t)&__ram_text_reloc_start,
(uintptr_t)&__ram_text_reloc_end,
"function_in_sram is not in ram region");
function_in_sram(var_sram2_data);
/* Print values from non-relocated function */
printk("Address of function_not_relocated %p\n", &function_not_relocated);
zassert_between_inclusive((uintptr_t)&function_not_relocated,
(uintptr_t)&__text_region_start,
(uintptr_t)&__text_region_end,
"function_not_relocated is not in flash region");
function_not_relocated(var_sram2_data);
/* Call library function */
relocated_library();

View file

@ -19,3 +19,14 @@ void function_in_sram(int32_t value)
printk("Address of memcpy %p\n\n", &memcpy);
zassert_mem_equal(src, dst, 8, "memcpy compare error");
}
void function_not_relocated(int32_t value)
{
char src[8] = "data\n";
char dst[8];
printk("Hello World! %s\n", CONFIG_BOARD);
memcpy(dst, src, 8);
printk("Address of memcpy %p\n\n", &memcpy);
zassert_mem_equal(src, dst, 8, "memcpy compare error");
}