Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ set(PARSE_SYSCALLS_TARGET parse_syscalls_target)

define_property(GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT BRIEF_DOCS " " FULL_DOCS " ")
set_property( GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT elf32-little${ARCH}) # BFD format
define_property(GLOBAL PROPERTY PROPERTY_CODE_RELOCATION_TARGET
BRIEF_DOCS "Code relocation target location" FULL_DOCS " ")

# "zephyr_interface" is a source-less library that encapsulates all the global
# compiler options needed by all source files. All zephyr libraries,
Expand Down Expand Up @@ -815,6 +817,21 @@ foreach(zephyr_lib ${ZEPHYR_LIBS_PROPERTY})
list(REMOVE_ITEM ZEPHYR_LIBS_PROPERTY ${zephyr_lib})
continue()
endif()
# In order to allow zephyr_library_relocate to be called prior to adding
# library sources, we must parse and generate relocation information
# once all libraries have been defined
get_property(relocation_target TARGET ${zephyr_lib} PROPERTY
PROPERTY_CODE_RELOCATION_TARGET)
if(NOT "${relocation_target}" STREQUAL "")
get_property(lib_source_dir TARGET ${zephyr_lib} PROPERTY SOURCE_DIR)
foreach(file ${source_list})
if(NOT IS_ABSOLUTE ${file})
set(file ${lib_source_dir}/${file})
endif()
set_property(TARGET code_data_relocation_target APPEND PROPERTY
COMPILE_DEFINITIONS "${relocation_target}:${file}")
endforeach()
endif()
endif()

# TODO: Could this become an INTERFACE property of zephyr_interface?
Expand Down
14 changes: 14 additions & 0 deletions cmake/modules/extensions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,20 @@ function(zephyr_linker_sources location)
endforeach()
endfunction(zephyr_linker_sources)

function(zephyr_library_relocate location)
set(options NOCOPY)
cmake_parse_arguments(CODE_REL "${options}" "" "" ${ARGN})
if(NOT CODE_REL_NOCOPY)
set(copy_flag COPY)
else()
set(copy_flag NOCOPY)
endif()
# Set current library relocation property. This will be picked up
# in the root CMakeLists.txt file to relocate all sources added to
# this library
set_property(TARGET ${ZEPHYR_CURRENT_LIBRARY}
PROPERTY PROPERTY_CODE_RELOCATION_TARGET "${location}:${copy_flag}")
endfunction()

# Helper function for CONFIG_CODE_DATA_RELOCATION
# Call this function with 2 arguments file and then memory location.
Expand Down
26 changes: 26 additions & 0 deletions drivers/ethernet/Kconfig.mcux
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,30 @@ config ETH_MCUX_PTP_CLOCK_INIT_PRIO

endif # PTP_CLOCK_MCUX


# Add relocation options for networking code
if NET_CODE_RELOCATE

if CPU_CORTEX_M7

# Relocate code to ITCM for M7 cores

choice NET_CODE_RAM
default NET_CODE_RAM_ITCM

config NET_CODE_RAM_ITCM
bool "ITCM"
help
Relocate networking subsystem code to ITCM

endchoice

config NET_CODE_RAM_NAME
string
default "ITCM" if NET_CODE_RAM_ITCM

endif # CPU_CORTEX_M7

endif # NET_CODE_RELOCATE

endif # ETH_MCUX
1 change: 1 addition & 0 deletions samples/net/zperf/boards/mimxrt1050_evk.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Note: HW accleration does not support IPV6
CONFIG_ETH_MCUX_HW_ACCELERATION=y
CONFIG_NET_CODE_RELOCATE=y
1 change: 1 addition & 0 deletions samples/net/zperf/boards/mimxrt1060_evk.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Note: HW accleration does not support IPV6
CONFIG_ETH_MCUX_HW_ACCELERATION=y
CONFIG_NET_CODE_RELOCATE=y
3 changes: 1 addition & 2 deletions scripts/build/gen_relocate_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@


PRINT_TEMPLATE = """
KEEP(*({0}))
*({0})
"""

SECTION_LOAD_MEMORY_SEQ = """
Expand Down Expand Up @@ -495,7 +495,6 @@ def main():
mem_type = mem_type.split("|", 1)[0]
code_generation = generate_memcpy_code(mem_type,
list_of_sections, code_generation)

dump_header_file(args.output_code, code_generation)


Expand Down
4 changes: 4 additions & 0 deletions subsys/net/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ zephyr_library()
zephyr_library_sources_ifdef(CONFIG_NET_BUF buf.c)
zephyr_library_sources_ifdef(CONFIG_NET_HOSTNAME_ENABLE hostname.c)

if(CONFIG_NET_CODE_RELOCATE)
Copy link
Contributor

@tbursztyka tbursztyka Sep 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commit title would need to be revised, you are relocating both the net stack and the ethernet L2. And there is no dependency with each other on this. Perhaps splitting the patch in 2 would be clearer: first the net stack, then the ethernet L2.

zephyr_library_relocate("${CONFIG_NET_CODE_RAM_NAME}_TEXT")
endif()

if(CONFIG_NETWORKING)
add_subdirectory(l2)
add_subdirectory(pkt_filter)
Expand Down
32 changes: 32 additions & 0 deletions subsys/net/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,38 @@ config NETWORKING

if NETWORKING

config NET_CODE_RELOCATE
bool "Relocate network subsystem code into RAM"
select CODE_DATA_RELOCATION
help
Relocate networking subsystem code into RAM using zephyr_code_relocate
macro. This may enable significant performance gains on some
platforms, depending on the speed of their RAM versus FLASH region.
if NET_CODE_RELOCATE

choice NET_CODE_RAM
prompt "Location to relocate networking code to in RAM"
default NET_CODE_RAM_SRAM
help
Location to relocated networking code to. Defaults to SRAM unless
the platform selects a higher performance RAM region

config NET_CODE_RAM_SRAM
bool "SRAM"
select CODE_DATA_RELOCATION_SRAM
help
Relocate networking subsystem code to SRAM

endchoice

config NET_CODE_RAM_NAME
string
default "SRAM" if NET_CODE_RAM_SRAM
help
Hidden option for RAM bank to relocate networking code into

endif # NET_CODE_RELOCATE

# Such option should not be configured manually but by device drivers
# which supports PM properly.
config NET_POWER_MANAGEMENT
Expand Down
4 changes: 4 additions & 0 deletions subsys/net/ip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ zephyr_library_sources(
utils.c
)

if(CONFIG_NET_CODE_RELOCATE)
zephyr_library_relocate("${CONFIG_NET_CODE_RAM_NAME}_TEXT")
endif()

if(CONFIG_NET_OFFLOAD)
zephyr_library_sources(net_context.c net_pkt.c net_tc.c)
endif()
Expand Down