Add support for compiling modules into kernel side

Define __KERNEL__ macro during compilation and place the module in separate library

Remove default library linking to m or libc on NuttX. Add these in platform layer instead, since
they are different on kernel and user side

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
This commit is contained in:
Jukka Laitinen 2020-12-30 15:57:55 +02:00 committed by Daniel Agar
parent 714df398eb
commit 51ceb9a85e
5 changed files with 63 additions and 4 deletions

View File

@ -125,6 +125,11 @@ define_property(GLOBAL PROPERTY PX4_MODULE_LIBRARIES
FULL_DOCS "List of all PX4 module libraries"
)
define_property(GLOBAL PROPERTY PX4_KERNEL_MODULE_LIBRARIES
BRIEF_DOCS "PX4 kernel side module libs"
FULL_DOCS "List of all PX4 kernel module libraries"
)
define_property(GLOBAL PROPERTY PX4_MODULE_PATHS
BRIEF_DOCS "PX4 module paths"
FULL_DOCS "List of paths to all PX4 modules"
@ -142,6 +147,7 @@ set(CONFIG "px4_sitl_default" CACHE STRING "desired configuration")
include(px4_add_module)
set(config_module_list)
set(config_kernel_list)
# Find Python
# If using catkin, Python 2 is found since it points

View File

@ -118,6 +118,11 @@ config BOARD_CRYPTO
help
Enable PX4 Crypto Support. Select the implementation under drivers
config BOARD_PROTECTED
bool "Memory protection"
help
Enable memory protection via MPU/MMU
menu "Serial ports"
config BOARD_SERIAL_URT6

View File

@ -26,6 +26,8 @@ set(COMMON_KCONFIG_ENV_SETTINGS
ROMFSROOT=${config_romfs_root}
)
set(config_user_list)
if(EXISTS ${BOARD_DEFCONFIG})
# Depend on BOARD_DEFCONFIG so that we reconfigure on config change
@ -79,6 +81,17 @@ if(EXISTS ${BOARD_DEFCONFIG})
endif()
endif()
# Find variable name
string(REGEX MATCH "^CONFIG_USER[^=]+" Userspace ${NameAndValue})
if(Userspace)
# Find the value
string(REPLACE "${Name}=" "" Value ${NameAndValue})
string(REPLACE "CONFIG_USER_" "" module ${Name})
string(TOLOWER ${module} module)
list(APPEND config_user_list ${module})
endif()
# Find variable name
string(REGEX MATCH "^CONFIG_DRIVERS[^=]+" Drivers ${NameAndValue})
@ -171,6 +184,16 @@ if(EXISTS ${BOARD_DEFCONFIG})
endforeach()
# Put every module not in userspace also to kernel list
foreach(modpath ${config_module_list})
get_filename_component(module ${modpath} NAME)
list(FIND config_user_list ${module} _index)
if (${_index} EQUAL -1)
list(APPEND config_kernel_list ${modpath})
endif()
endforeach()
if(PLATFORM)
# set OS, and append specific platform module path
set(PX4_PLATFORM ${PLATFORM} CACHE STRING "PX4 board OS" FORCE)
@ -336,6 +359,7 @@ if(EXISTS ${BOARD_DEFCONFIG})
list(APPEND config_module_list ${board_support_src_rel}/src)
set(config_module_list ${config_module_list})
set(config_kernel_list ${config_kernel_list})
endif()

View File

@ -44,8 +44,8 @@ function(px4_add_library target)
target_compile_definitions(${target} PRIVATE MODULE_NAME="${target}")
# all PX4 libraries have access to parameters and uORB
add_dependencies(${target} uorb_headers)
target_link_libraries(${target} PRIVATE prebuild_targets parameters_interface px4_platform)
add_dependencies(${target} uorb_headers parameters)
target_link_libraries(${target} PRIVATE prebuild_targets)
set_property(GLOBAL APPEND PROPERTY PX4_MODULE_PATHS ${CMAKE_CURRENT_SOURCE_DIR})
px4_list_make_absolute(ABS_SRCS ${CMAKE_CURRENT_SOURCE_DIR} ${ARGN})

View File

@ -154,9 +154,29 @@ function(px4_add_module)
# all modules can potentially use parameters and uORB
add_dependencies(${MODULE} uorb_headers)
# Check if the modules source dir exists in config_kernel_list
# in this case, treat is as a kernel side component for
# protected build
get_target_property(MODULE_SOURCE_DIR ${MODULE} SOURCE_DIR)
file(RELATIVE_PATH module ${PROJECT_SOURCE_DIR}/src ${MODULE_SOURCE_DIR})
list (FIND config_kernel_list ${module} _index)
if (${_index} GREATER -1)
set (KERNEL TRUE)
endif()
if(NOT DYNAMIC)
target_link_libraries(${MODULE} PRIVATE prebuild_targets parameters_interface px4_layer px4_platform systemlib)
set_property(GLOBAL APPEND PROPERTY PX4_MODULE_LIBRARIES ${MODULE})
target_link_libraries(${MODULE} PRIVATE prebuild_targets parameters_interface px4_platform systemlib perf)
if (${PX4_PLATFORM} STREQUAL "nuttx" AND NOT CONFIG_BUILD_FLAT AND KERNEL)
target_link_libraries(${MODULE} PRIVATE px4_kernel_layer uORB_kernel)
set_property(GLOBAL APPEND PROPERTY PX4_KERNEL_MODULE_LIBRARIES ${MODULE})
else()
target_link_libraries(${MODULE} PRIVATE px4_layer uORB)
set_property(GLOBAL APPEND PROPERTY PX4_MODULE_LIBRARIES ${MODULE})
endif()
set_property(GLOBAL APPEND PROPERTY PX4_MODULE_PATHS ${CMAKE_CURRENT_SOURCE_DIR})
px4_list_make_absolute(ABS_SRCS ${CMAKE_CURRENT_SOURCE_DIR} ${SRCS})
set_property(GLOBAL APPEND PROPERTY PX4_SRC_FILES ${ABS_SRCS})
endif()
set_property(GLOBAL APPEND PROPERTY PX4_MODULE_PATHS ${CMAKE_CURRENT_SOURCE_DIR})
@ -197,6 +217,10 @@ function(px4_add_module)
target_compile_options(${MODULE} PRIVATE ${COMPILE_FLAGS})
endif()
if (KERNEL)
target_compile_options(${MODULE} PRIVATE -D__KERNEL__)
endif()
if(INCLUDES)
target_include_directories(${MODULE} PRIVATE ${INCLUDES})
endif()