diff --git a/cmake/modules/extensions.cmake b/cmake/modules/extensions.cmake index 9c2abfe7526db..3ba47fc2baf70 100644 --- a/cmake/modules/extensions.cmake +++ b/cmake/modules/extensions.cmake @@ -468,6 +468,8 @@ endfunction() # # zephyr_library versions of normal CMake target_ functions +# Note, paths passed to this function must be relative in order +# to support the library relocation feature of zephyr_code_relocate # function(zephyr_library_sources source) target_sources(${ZEPHYR_CURRENT_LIBRARY} PRIVATE ${source} ${ARGN}) @@ -1283,22 +1285,85 @@ endfunction(zephyr_linker_sources) # Helper function for CONFIG_CODE_DATA_RELOCATION -# Call this function with 2 arguments file and then memory location. -# One optional [NOCOPY] flag can be used. -function(zephyr_code_relocate file location) +# This function may either be invoked with a list of files, or a library +# name to relocate. +# +# The FILES directive will relocate a list of files (wildcards supported) +# This directive will relocate file1. and file2.c to SRAM: +# zephyr_code_relocate(FILES file1.c file2.c LOCATION SRAM) +# Note, files can also be passed as a comma separated list to support using +# cmake generator arguments +# +# The LIBRARY directive will relocate a library +# This directive will relocate the target my_lib to SRAM: +# zephyr_code_relocate(LIBRARY my_lib SRAM) +# +# The following optional arguments are supported: +# - NOCOPY: this flag indicates that the file data does not need to be copied +# at boot time (For example, for flash XIP). +# - PHDR [program_header]: add program header. Used on Xtensa platforms. +function(zephyr_code_relocate) set(options NOCOPY) - cmake_parse_arguments(CODE_REL "${options}" "" "" ${ARGN}) - if(NOT IS_ABSOLUTE ${file}) - set(file ${CMAKE_CURRENT_SOURCE_DIR}/${file}) + set(single_args LIBRARY LOCATION PHDR) + set(multi_args FILES) + cmake_parse_arguments(CODE_REL "${options}" "${single_args}" + "${multi_args}" ${ARGN}) + # Argument validation + if(CODE_REL_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "zephyr_code_relocate(${ARGV0} ...) " + "given unknown arguments: ${CODE_REL_UNPARSED_ARGUMENTS}") + endif() + if((NOT CODE_REL_FILES) AND (NOT CODE_REL_LIBRARY)) + message(FATAL_ERROR + "zephyr_code_relocate() requires either FILES or LIBRARY be provided") + endif() + if(CODE_REL_FILES AND CODE_REL_LIBRARY) + message(FATAL_ERROR "zephyr_code_relocate() only accepts " + "one argument between FILES and LIBRARY") + endif() + if(NOT CODE_REL_LOCATION) + message(FATAL_ERROR "zephyr_code_relocate() requires a LOCATION argument") + endif() + if(CODE_REL_LIBRARY) + # Use cmake generator expression to convert library to file list + set(genex_src_dir "$") + set(genex_src_list "$") + set(file_list + "${genex_src_dir}/$${genex_src_dir}/>") + else() + # Check if CODE_REL_FILES is a generator expression, if so leave it + # untouched. + string(GENEX_STRIP "${CODE_REL_FILES}" no_genex) + if(CODE_REL_FILES STREQUAL no_genex) + # no generator expression in CODE_REL_FILES, check if list of files + # is absolute + foreach(file ${CODE_REL_FILES}) + if(NOT IS_ABSOLUTE ${file}) + set(file ${CMAKE_CURRENT_SOURCE_DIR}/${file}) + endif() + list(APPEND file_list ${file}) + endforeach() + else() + # Generator expression is present in file list. Leave the list untouched. + set(file_list ${CODE_REL_FILES}) + endif() endif() if(NOT CODE_REL_NOCOPY) set(copy_flag COPY) else() set(copy_flag NOCOPY) endif() + if(CODE_REL_PHDR) + set(CODE_REL_LOCATION "${CODE_REL_LOCATION}\ :${CODE_REL_PHDR}") + endif() + # We use the "|" character to separate code relocation directives instead + # of using CMake lists. This way, the ";" character can be reserved for + # generator expression file lists. + get_property(code_rel_str TARGET code_data_relocation_target + PROPERTY COMPILE_DEFINITIONS) set_property(TARGET code_data_relocation_target - APPEND PROPERTY COMPILE_DEFINITIONS - "${location}:${copy_flag}:${file}") + PROPERTY COMPILE_DEFINITIONS + "${code_rel_str}|${CODE_REL_LOCATION}:${copy_flag}:${file_list}") endfunction() # Usage: diff --git a/doc/kernel/code-relocation.rst b/doc/kernel/code-relocation.rst index 90ce99d0ba2d3..2e75b5427872e 100644 --- a/doc/kernel/code-relocation.rst +++ b/doc/kernel/code-relocation.rst @@ -54,14 +54,13 @@ for data copy operations from ROM to required memory type. * Inside the ``CMakeLists.txt`` file in the project, mention all the files that need relocation. - ``zephyr_code_relocate(src/*.c SRAM2)`` + ``zephyr_code_relocate(FILES src/*.c LOCATION SRAM2)`` Where the first argument is the file/files and the second argument is the memory where it must be placed. .. note:: - The file argument supports limited regular expressions. function zephyr_code_relocate() can be called as many times as required. This step has to be performed before calling find_package(Zephyr ...) in the application's CMakeLists.txt. @@ -77,8 +76,8 @@ This section shows additional configuration options that can be set in .. code-block:: none - zephyr_code_relocate(src/file1.c SRAM2) - zephyr_code_relocate(src/file2.c.c SRAM) + zephyr_code_relocate(FILES src/file1.c LOCATION SRAM2) + zephyr_code_relocate(FILES src/file2.c LOCATION SRAM) * if the memory type is appended with _DATA, _TEXT, _RODATA or _BSS, only the selected memory is placed in the required memory region. @@ -86,12 +85,21 @@ This section shows additional configuration options that can be set in .. code-block:: none - zephyr_code_relocate(src/file1.c SRAM2_DATA) - zephyr_code_relocate(src/file2.c.c SRAM2_TEXT) + zephyr_code_relocate(FILES src/file1.c LOCATION SRAM2_DATA) + zephyr_code_relocate(FILES src/file2.c LOCATION SRAM2_TEXT) * Multiple regions can also be appended together such as: SRAM2_DATA_BSS. This will place data and bss inside SRAM2. +* Multiple files can be passed to the FILES argument, or CMake generator + expressions can be used to relocate a comma-separated list of files + + .. code-block:: none + + file(GLOB sources "file*.c") + zephyr_code_relocate(FILES ${sources} LOCATION SRAM) + zephyr_code_relocate(FILES $ LOCATION SRAM) + NOCOPY flag =========== @@ -106,8 +114,20 @@ to the ``EXTFLASH`` memory region where it will be executed from (XIP). The .. code-block:: none - zephyr_code_relocate(src/xip_external_flash.c EXTFLASH_TEXT NOCOPY) - zephyr_code_relocate(src/xip_external_flash.c SRAM_DATA) + zephyr_code_relocate(FILES src/xip_external_flash.c LOCATION EXTFLASH_TEXT NOCOPY) + zephyr_code_relocate(FILES src/xip_external_flash.c LOCATION SRAM_DATA) + +Relocating libraries +==================== + +Libraries can be relocated using the LIBRARY argument to +``zephyr_code_relocation()`` with the library name. For example, the following +snippet will relocate kernel code to ITCM and serial drivers to SRAM2: + + .. code-block:: none + + zephyr_code_relocate(LIBRARY kernel LOCATION ITCM_TEXT) + zephyr_code_relocate(LIBRARY drivers__serial LOCATION SRAM2) Sample ====== diff --git a/doc/releases/release-notes-3.3.rst b/doc/releases/release-notes-3.3.rst index 7a8ab8f25c5ee..0a5a5caf7e8bd 100644 --- a/doc/releases/release-notes-3.3.rst +++ b/doc/releases/release-notes-3.3.rst @@ -311,6 +311,11 @@ Boards & SoC Support Build system and infrastructure ******************************* +* Code relocation + + * ``zephyr_code_relocate`` API has changed to accept a list of files to + relocate and a location to place the files. + Drivers and Sensors ******************* diff --git a/drivers/flash/CMakeLists.txt b/drivers/flash/CMakeLists.txt index 6a2ad6eca8b21..a9b11e0d7a300 100644 --- a/drivers/flash/CMakeLists.txt +++ b/drivers/flash/CMakeLists.txt @@ -35,11 +35,11 @@ if(CONFIG_FLASH_MCUX_FLEXSPI_XIP) dt_chosen(chosen_flash PROPERTY "zephyr,flash") dt_prop(compat_flash PATH ${chosen_flash} PROPERTY compatible) if(compat_flash MATCHES "nxp,imx-flexspi-nor") - zephyr_code_relocate(flash_mcux_flexspi_nor.c ${CONFIG_FLASH_MCUX_FLEXSPI_XIP_MEM}_TEXT) + zephyr_code_relocate(FILES flash_mcux_flexspi_nor.c LOCATION ${CONFIG_FLASH_MCUX_FLEXSPI_XIP_MEM}_TEXT) elseif(compat_flash MATCHES "nxp,imx-flexspi-mx25um51345g") - zephyr_code_relocate(flash_mcux_flexspi_mx25um51345g.c ${CONFIG_FLASH_MCUX_FLEXSPI_XIP_MEM}_TEXT) + zephyr_code_relocate(FILES flash_mcux_flexspi_mx25um51345g.c LOCATION ${CONFIG_FLASH_MCUX_FLEXSPI_XIP_MEM}_TEXT) elseif(compat_flash MATCHES "nxp,imx-flexspi-hyperflash") - zephyr_code_relocate(flash_mcux_flexspi_hyperflash.c ${CONFIG_FLASH_MCUX_FLEXSPI_XIP_MEM}_TEXT) + zephyr_code_relocate(FILES flash_mcux_flexspi_hyperflash.c LOCATION ${CONFIG_FLASH_MCUX_FLEXSPI_XIP_MEM}_TEXT) endif() endif() diff --git a/drivers/memc/CMakeLists.txt b/drivers/memc/CMakeLists.txt index 3b802529fdd36..11c7a090c6c15 100644 --- a/drivers/memc/CMakeLists.txt +++ b/drivers/memc/CMakeLists.txt @@ -14,5 +14,5 @@ zephyr_library_sources_ifdef(CONFIG_MEMC_MCUX_FLEXSPI_APS6408L memc_mcux_flexspi zephyr_library_sources_ifdef(CONFIG_MEMC_SAM_SMC memc_sam_smc.c) if((DEFINED CONFIG_FLASH_MCUX_FLEXSPI_XIP) AND (DEFINED CONFIG_FLASH)) - zephyr_code_relocate(memc_mcux_flexspi.c ${CONFIG_FLASH_MCUX_FLEXSPI_XIP_MEM}_TEXT) + zephyr_code_relocate(FILES memc_mcux_flexspi.c LOCATION ${CONFIG_FLASH_MCUX_FLEXSPI_XIP_MEM}_TEXT) endif() diff --git a/samples/application_development/code_relocation_nocopy/CMakeLists.txt b/samples/application_development/code_relocation_nocopy/CMakeLists.txt index 37aaf60a4ddf2..0da6192fa11f6 100644 --- a/samples/application_development/code_relocation_nocopy/CMakeLists.txt +++ b/samples/application_development/code_relocation_nocopy/CMakeLists.txt @@ -10,10 +10,10 @@ target_sources(app PRIVATE ${app_sources}) target_sources_ifdef(CONFIG_NRFX_QSPI app PRIVATE boards/nrf5340dk_nrf5340_cpuapp/ext_mem_init.c) # Run ext_code from the external flash (XIP). No need to copy. -zephyr_code_relocate(src/ext_code.c EXTFLASH_TEXT NOCOPY) +zephyr_code_relocate(FILES src/ext_code.c LOCATION EXTFLASH_TEXT NOCOPY) # But still relocate (copy) the data to RAM -zephyr_code_relocate(src/ext_code.c RAM_DATA) +zephyr_code_relocate(FILES src/ext_code.c LOCATION RAM_DATA) # sram_code instead runs entirely from SRAM after being copied there. -zephyr_code_relocate(src/sram_code.c RAM) +zephyr_code_relocate(FILES src/sram_code.c LOCATION RAM) diff --git a/samples/boards/intel_adsp/code_relocation/CMakeLists.txt b/samples/boards/intel_adsp/code_relocation/CMakeLists.txt index c2dd56e76498a..17c7be3fc6530 100644 --- a/samples/boards/intel_adsp/code_relocation/CMakeLists.txt +++ b/samples/boards/intel_adsp/code_relocation/CMakeLists.txt @@ -7,8 +7,8 @@ project(adsp_cavs_code_relocation) target_sources(app PRIVATE src/main.c src/reloc.c) -zephyr_code_relocate(src/reloc.c SRAM2_LITERAL) -zephyr_code_relocate(src/reloc.c SRAM2_TEXT) -zephyr_code_relocate(src/reloc.c SRAM3_DATA) -zephyr_code_relocate(src/reloc.c SRAM3_RODATA) -zephyr_code_relocate(src/reloc.c SRAM4_BSS) +zephyr_code_relocate(FILES src/reloc.c LOCATION SRAM2_LITERAL) +zephyr_code_relocate(FILES src/reloc.c LOCATION SRAM2_TEXT) +zephyr_code_relocate(FILES src/reloc.c LOCATION SRAM3_DATA) +zephyr_code_relocate(FILES src/reloc.c LOCATION SRAM3_RODATA) +zephyr_code_relocate(FILES src/reloc.c LOCATION SRAM4_BSS) diff --git a/scripts/build/gen_relocate_app.py b/scripts/build/gen_relocate_app.py index d72a107d681cb..fb312ac2d624d 100644 --- a/scripts/build/gen_relocate_app.py +++ b/scripts/build/gen_relocate_app.py @@ -464,24 +464,35 @@ def create_dict_wrt_mem(): if args.input_rel_dict == '': sys.exit("Disable CONFIG_CODE_DATA_RELOCATION if no file needs relocation") - for line in args.input_rel_dict.split(';'): + for line in args.input_rel_dict.split('|'): if ':' not in line: continue - mem_region, phdr, copy_flag, file_name = parse_input_string(line) + mem_region, phdr, copy_flag, file_list = parse_input_string(line) # Handle any program header if phdr != '': phdrs[mem_region] = f':{phdr}' - file_name_list = glob.glob(file_name) - if not file_name_list: - warnings.warn("File: "+file_name+" Not found") + # Split file names by semicolons, to support generator expressions + file_glob_list = file_list.split(';') + file_name_list = [] + # Use glob matching on each file in the list + for file_glob in file_glob_list: + glob_results = glob.glob(file_glob) + if not glob_results: + warnings.warn("File: "+file_glob+" Not found") + continue + elif len(glob_results) > 1: + warnings.warn("Regex in file lists is deprecated, please use file(GLOB) instead") + file_name_list.extend(glob_results) + if len(file_name_list) == 0: + warnings.warn("No files in string: "+file_list+" found") continue if mem_region == '': continue if args.verbose: - print("Memory region ", mem_region, " Selected for file:", file_name_list) + print("Memory region ", mem_region, " Selected for files:", file_name_list) mem_region = "|".join((mem_region, copy_flag)) diff --git a/soc/arm/nxp_imx/rt/CMakeLists.txt b/soc/arm/nxp_imx/rt/CMakeLists.txt index b388d1ca6a19b..f4ae882900493 100644 --- a/soc/arm/nxp_imx/rt/CMakeLists.txt +++ b/soc/arm/nxp_imx/rt/CMakeLists.txt @@ -31,10 +31,10 @@ endif() if (CONFIG_PM AND CONFIG_SOC_SERIES_IMX_RT10XX) zephyr_sources(power_rt10xx.c) - zephyr_code_relocate(power_rt10xx.c ITCM_TEXT) + zephyr_code_relocate(FILES power_rt10xx.c LOCATION ITCM_TEXT) if (CONFIG_SOC_MIMXRT1064) zephyr_sources(lpm_rt1064.c) - zephyr_code_relocate(lpm_rt1064.c ITCM_TEXT) + zephyr_code_relocate(FILES lpm_rt1064.c LOCATION ITCM_TEXT) endif() endif() diff --git a/soc/arm/nxp_imx/rt5xx/CMakeLists.txt b/soc/arm/nxp_imx/rt5xx/CMakeLists.txt index 56f19414ab0e5..9e494659df1fc 100644 --- a/soc/arm/nxp_imx/rt5xx/CMakeLists.txt +++ b/soc/arm/nxp_imx/rt5xx/CMakeLists.txt @@ -26,4 +26,4 @@ zephyr_linker_sources_ifdef(CONFIG_NXP_IMX_RT5XX_BOOT_HEADER zephyr_linker_sources_ifdef(CONFIG_USB_DEVICE_DRIVER SECTIONS usb.ld) -zephyr_code_relocate(flash_clock_setup.c RAM) +zephyr_code_relocate(FILES flash_clock_setup.c LOCATION RAM) diff --git a/soc/arm/nxp_imx/rt6xx/CMakeLists.txt b/soc/arm/nxp_imx/rt6xx/CMakeLists.txt index 36636e1b7c918..a5a853cd853f1 100644 --- a/soc/arm/nxp_imx/rt6xx/CMakeLists.txt +++ b/soc/arm/nxp_imx/rt6xx/CMakeLists.txt @@ -30,5 +30,5 @@ zephyr_linker_sources_ifdef(CONFIG_USB_DEVICE_DRIVER SECTIONS usb.ld) if(CONFIG_FLASH_MCUX_FLEXSPI_XIP) -zephyr_code_relocate(flash_clock_setup.c RAM) + zephyr_code_relocate(FILES flash_clock_setup.c LOCATION RAM) endif() diff --git a/tests/application_development/code_relocation/CMakeLists.txt b/tests/application_development/code_relocation/CMakeLists.txt index ddc8091cf01dc..f731fea70eddb 100644 --- a/tests/application_development/code_relocation/CMakeLists.txt +++ b/tests/application_development/code_relocation/CMakeLists.txt @@ -1,4 +1,5 @@ # SPDX-License-Identifier: Apache-2.0 +# Copyright 2022 NXP cmake_minimum_required(VERSION 3.20.0) @@ -9,24 +10,39 @@ FILE(GLOB app_sources src/*.c) target_sources(app PRIVATE ${app_sources}) if (CONFIG_BOARD_QEMU_XTENSA) - set(RAM_PHDR :sram0_phdr) - set(SRAM2_PHDR :sram2_phdr) + set(RAM_PHDR PHDR sram0_phdr) + set(SRAM2_PHDR PHDR sram2_phdr) endif() # Code relocation feature -zephyr_code_relocate(src/test_file1.c "SRAM2 ${SRAM2_PHDR}") +zephyr_code_relocate(FILES src/test_file1.c ${SRAM2_PHDR} LOCATION SRAM2) -zephyr_code_relocate(src/test_file2.c "RAM ${RAM_PHDR}") +zephyr_code_relocate(FILES src/test_file2.c ${RAM_PHDR} LOCATION RAM) -zephyr_code_relocate(src/test_file3.c SRAM2_LITERAL) -zephyr_code_relocate(src/test_file3.c SRAM2_TEXT) -zephyr_code_relocate(src/test_file3.c RAM_DATA) -zephyr_code_relocate(src/test_file3.c SRAM2_BSS) +# Add custom library that we can relocate code for +add_subdirectory(test_lib) +target_link_libraries(app PUBLIC test_lib) +target_include_directories(app PUBLIC ${CMAKE_CURRENT_LIST_DIR}/test_lib) +# Relocate library code +zephyr_code_relocate(LIBRARY test_lib LOCATION SRAM2) -zephyr_code_relocate(../../../kernel/sem.c "RAM ${RAM_PHDR}") +# Test support for a simple generator expression to relocate two files +set(reloc_files src/test_file4.c src/test_file5.c) +set(genex_expr + ${CMAKE_CURRENT_LIST_DIR}/$${CMAKE_CURRENT_LIST_DIR}/>) +zephyr_code_relocate(FILES ${genex_expr} LOCATION SRAM2) + +zephyr_code_relocate(FILES src/test_file3.c LOCATION SRAM2_LITERAL) +zephyr_code_relocate(FILES src/test_file3.c LOCATION SRAM2_TEXT) +zephyr_code_relocate(FILES src/test_file3.c LOCATION RAM_DATA) +zephyr_code_relocate(FILES src/test_file3.c LOCATION SRAM2_BSS) + + +zephyr_code_relocate(FILES ${ZEPHYR_BASE}/kernel/sem.c ${RAM_PHDR} LOCATION RAM) if (CONFIG_RELOCATE_TO_ITCM) -zephyr_code_relocate(../../../lib/libc/minimal/source/string/string.c ITCM_TEXT) +zephyr_code_relocate(FILES ${ZEPHYR_BASE}/lib/libc/minimal/source/string/string.c + LOCATION ITCM_TEXT) endif() zephyr_linker_sources(SECTIONS custom-sections.ld) diff --git a/tests/application_development/code_relocation/src/test_file1.c b/tests/application_development/code_relocation/src/test_file1.c index 55fa850c1c92d..ff4f537ec0296 100644 --- a/tests/application_development/code_relocation/src/test_file1.c +++ b/tests/application_development/code_relocation/src/test_file1.c @@ -8,6 +8,8 @@ #include #include +#include "test_lib.h" + /* * These values will typically be placed in the appropriate sections, but may be moved around * by the compiler; for instance var_sram2_data might end up in .rodata if the compiler can prove @@ -63,6 +65,8 @@ ZTEST(code_relocation, test_function_in_sram2) /* Print values from sram */ function_in_sram(var_sram2_data); + /* Call library function */ + relocated_library(); /* Print values which were placed using attributes */ printk("Address of custom_section, func placed using attributes %p\n", diff --git a/tests/application_development/code_relocation/src/test_file2.c b/tests/application_development/code_relocation/src/test_file2.c index 2139187d796ee..d8b56730d39e5 100644 --- a/tests/application_development/code_relocation/src/test_file2.c +++ b/tests/application_development/code_relocation/src/test_file2.c @@ -16,6 +16,6 @@ void function_in_sram(int32_t value) printk("Hello World! %s\n", CONFIG_BOARD); memcpy(dst, src, 8); - printk("Address of memcpy %p\n", &memcpy); + printk("Address of memcpy %p\n\n", &memcpy); zassert_mem_equal(src, dst, 8, "memcpy compare error"); } diff --git a/tests/application_development/code_relocation/src/test_file4.c b/tests/application_development/code_relocation/src/test_file4.c new file mode 100644 index 0000000000000..19d9a6f29b33b --- /dev/null +++ b/tests/application_development/code_relocation/src/test_file4.c @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2022, NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +__in_section(data, sram2, var) uint32_t var_file4_sram2_data = 10U; +__in_section(bss, sram2, var) uint32_t var_file4_sram2_bss; + +ZTEST(code_relocation, test_function_genex_relocate_1) +{ + extern uintptr_t __sram2_data_start; + extern uintptr_t __sram2_data_end; + extern uintptr_t __sram2_bss_start; + extern uintptr_t __sram2_bss_end; + + printk("Address of var_file4_sram2_data %p\n", &var_file4_sram2_data); + printk("Address of var_file4_sram2_bss %p\n\n", &var_file4_sram2_bss); + + zassert_between_inclusive((uintptr_t)&var_file4_sram2_data, + (uintptr_t)&__sram2_data_start, + (uintptr_t)&__sram2_data_end, + "var_file4_sram2_data not in sram2_data region"); + zassert_between_inclusive((uintptr_t)&var_file4_sram2_bss, + (uintptr_t)&__sram2_bss_start, + (uintptr_t)&__sram2_bss_end, + "var_file4_sram2_bss not in sram2_bss region"); +} diff --git a/tests/application_development/code_relocation/src/test_file5.c b/tests/application_development/code_relocation/src/test_file5.c new file mode 100644 index 0000000000000..b06004dc34926 --- /dev/null +++ b/tests/application_development/code_relocation/src/test_file5.c @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2022, NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +__in_section(data, sram2, var) uint32_t var_file5_sram2_data = 10U; +__in_section(bss, sram2, var) uint32_t var_file5_sram2_bss; + +ZTEST(code_relocation, test_function_genex_relocate_2) +{ + extern uintptr_t __sram2_data_start; + extern uintptr_t __sram2_data_end; + extern uintptr_t __sram2_bss_start; + extern uintptr_t __sram2_bss_end; + + printk("Address of var_file5_sram2_data %p\n", &var_file5_sram2_data); + printk("Address of var_file5_sram2_bss %p\n\n", &var_file5_sram2_bss); + + zassert_between_inclusive((uintptr_t)&var_file5_sram2_data, + (uintptr_t)&__sram2_data_start, + (uintptr_t)&__sram2_data_end, + "var_file5_sram2_data not in sram2_data region"); + zassert_between_inclusive((uintptr_t)&var_file5_sram2_bss, + (uintptr_t)&__sram2_bss_start, + (uintptr_t)&__sram2_bss_end, + "var_file5_sram2_bss not in sram2_bss region"); +} diff --git a/tests/application_development/code_relocation/test_lib/CMakeLists.txt b/tests/application_development/code_relocation/test_lib/CMakeLists.txt new file mode 100644 index 0000000000000..86fa18b38d6a7 --- /dev/null +++ b/tests/application_development/code_relocation/test_lib/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright 2022 NXP + +add_library(test_lib STATIC "") +target_sources(test_lib PRIVATE test_lib1.c test_lib2.c) +get_target_property(include_dirs app INCLUDE_DIRECTORIES) +target_link_libraries(test_lib PUBLIC zephyr_interface) +add_dependencies(test_lib zephyr_generated_headers) diff --git a/tests/application_development/code_relocation/test_lib/test_lib.h b/tests/application_development/code_relocation/test_lib/test_lib.h new file mode 100644 index 0000000000000..20820cccef869 --- /dev/null +++ b/tests/application_development/code_relocation/test_lib/test_lib.h @@ -0,0 +1,8 @@ +/* + * Copyright 2022 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* External library function, called from test_file1.c */ +void relocated_library(void); diff --git a/tests/application_development/code_relocation/test_lib/test_lib1.c b/tests/application_development/code_relocation/test_lib/test_lib1.c new file mode 100644 index 0000000000000..d0b693102a8ed --- /dev/null +++ b/tests/application_development/code_relocation/test_lib/test_lib1.c @@ -0,0 +1,43 @@ +/* + * Copyright 2022 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +__in_section(data, sram2, var) uint32_t var_lib1_sram2_data = 10U; +__in_section(bss, sram2, var) uint32_t var_lib1_sram2_bss; + +/* Helper function, declared in test_lib2.c */ +extern void relocated_helper(void); + +void relocated_library(void) +{ + extern uintptr_t __sram2_text_start; + extern uintptr_t __sram2_text_end; + extern uintptr_t __sram2_data_start; + extern uintptr_t __sram2_data_end; + extern uintptr_t __sram2_bss_start; + extern uintptr_t __sram2_bss_end; + + printk("Address of var_lib1_sram2_data %p\n", &var_lib1_sram2_data); + printk("Address of var_lib1_sram2_bss %p\n", &var_lib1_sram2_bss); + printk("Address of relocated_lib_helper %p\n\n", &relocated_helper); + + zassert_between_inclusive((uintptr_t)&var_lib1_sram2_data, + (uintptr_t)&__sram2_data_start, + (uintptr_t)&__sram2_data_end, + "var_lib1_sram2_data not in sram2_data region"); + zassert_between_inclusive((uintptr_t)&var_lib1_sram2_bss, + (uintptr_t)&__sram2_bss_start, + (uintptr_t)&__sram2_bss_end, + "var_lib1_sram2_bss not in sram2_bss region"); + zassert_between_inclusive((uintptr_t)&relocated_helper, + (uintptr_t)&__sram2_text_start, + (uintptr_t)&__sram2_text_end, + "relocated_helper not in sram2_text region"); + relocated_helper(); +} diff --git a/tests/application_development/code_relocation/test_lib/test_lib2.c b/tests/application_development/code_relocation/test_lib/test_lib2.c new file mode 100644 index 0000000000000..d5a29c070398d --- /dev/null +++ b/tests/application_development/code_relocation/test_lib/test_lib2.c @@ -0,0 +1,13 @@ +/* + * Copyright 2022 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +void relocated_helper(void) +{ + printk("Relocated helper function running on %s\n\n", CONFIG_BOARD); +} diff --git a/west.yml b/west.yml index 4af3390cc7695..ec8a4fe95adfa 100644 --- a/west.yml +++ b/west.yml @@ -93,7 +93,7 @@ manifest: groups: - hal - name: hal_nxp - revision: b74522c2e452b170922f639bf5720461e533fb7e + revision: 3ee6020efc1f8323d0fdc85615d3477161f0aa1f path: modules/hal/nxp groups: - hal