diff --git a/CMakeLists.txt b/CMakeLists.txt index bca9b38eaa..a6288819a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/Kconfig b/Kconfig index f44a72657c..425cf9fa82 100644 --- a/Kconfig +++ b/Kconfig @@ -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 diff --git a/cmake/kconfig.cmake b/cmake/kconfig.cmake index 1e4527e2d0..cb1ec7ac2e 100644 --- a/cmake/kconfig.cmake +++ b/cmake/kconfig.cmake @@ -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() diff --git a/cmake/px4_add_library.cmake b/cmake/px4_add_library.cmake index dc5190c565..7dc7b6cfd0 100644 --- a/cmake/px4_add_library.cmake +++ b/cmake/px4_add_library.cmake @@ -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}) diff --git a/cmake/px4_add_module.cmake b/cmake/px4_add_module.cmake index 4a6bcef6a0..ff6e1e4075 100644 --- a/cmake/px4_add_module.cmake +++ b/cmake/px4_add_module.cmake @@ -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()