Browse Source

NuttX Cmake changes to build combined kernel+userspace image in nuttx protected build

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
master
Jukka Laitinen 4 years ago committed by Daniel Agar
parent
commit
3a6ebe5fc1
  1. 228
      platforms/nuttx/CMakeLists.txt

228
platforms/nuttx/CMakeLists.txt

@ -44,6 +44,14 @@ add_dependencies(px4 git_nuttx) @@ -44,6 +44,14 @@ add_dependencies(px4 git_nuttx)
get_property(module_libraries GLOBAL PROPERTY PX4_MODULE_LIBRARIES)
if (NOT CONFIG_BUILD_FLAT)
add_executable(px4_kernel ${PX4_SOURCE_DIR}/platforms/common/empty.c)
set(KERNEL_NAME ${PX4_BOARD_VENDOR}_${PX4_BOARD_MODEL}_${PX4_BOARD_LABEL}_kernel.elf)
set_target_properties(px4_kernel PROPERTIES OUTPUT_NAME ${KERNEL_NAME})
add_dependencies(px4_kernel git_nuttx)
get_property(kernel_module_libraries GLOBAL PROPERTY PX4_KERNEL_MODULE_LIBRARIES)
endif()
# build NuttX
add_subdirectory(NuttX ${PX4_BINARY_DIR}/NuttX)
@ -81,18 +89,31 @@ else() @@ -81,18 +89,31 @@ else()
endif()
list(APPEND nuttx_libs
nuttx_apps
nuttx_arch
nuttx_binfmt
nuttx_c
nuttx_boards
nuttx_xx
nuttx_drivers
nuttx_fs
nuttx_mm
nuttx_sched
nuttx_crypto
)
nuttx_binfmt
nuttx_xx
)
if (NOT CONFIG_BUILD_FLAT)
list(APPEND nuttx_libs
px4_board_ctrl
nuttx_karch
nuttx_kmm
nuttx_stubs
nuttx_kc
)
else()
list(APPEND nuttx_libs
nuttx_apps
nuttx_arch
nuttx_mm
nuttx_c
)
endif()
if(CONFIG_NET)
list(APPEND nuttx_libs nuttx_net)
@ -105,69 +126,166 @@ file(RELATIVE_PATH PX4_BINARY_DIR_REL ${CMAKE_CURRENT_BINARY_DIR} ${PX4_BINARY_D @@ -105,69 +126,166 @@ file(RELATIVE_PATH PX4_BINARY_DIR_REL ${CMAKE_CURRENT_BINARY_DIR} ${PX4_BINARY_D
# because even relative linker script paths are different for linux, mac and windows
CYGPATH(NUTTX_CONFIG_DIR NUTTX_CONFIG_DIR_CYG)
target_link_libraries(nuttx_c INTERFACE nuttx_sched) # nxsched_get_streams
if((DEFINED ENV{SIGNING_TOOL}) AND (NOT NUTTX_DIR MATCHES "external"))
set(PX4_BINARY_OUTPUT ${PX4_BINARY_DIR}/${PX4_CONFIG}_unsigned.bin)
target_link_libraries(nuttx_arch
INTERFACE
drivers_board
arch_hrt
arch_board_reset
)
add_custom_command(OUTPUT ${PX4_BINARY_DIR_REL}/${PX4_CONFIG}.bin
COMMAND $ENV{SIGNING_TOOL} $ENV{SIGNING_ARGS} ${PX4_BINARY_OUTPUT} ${PX4_BINARY_DIR}/${PX4_CONFIG}.bin
DEPENDS ${PX4_BINARY_OUTPUT}
WORKING_DIRECTORY ${PX4_SOURCE_DIR}
)
else()
set(PX4_BINARY_OUTPUT ${PX4_BINARY_DIR_REL}/${PX4_CONFIG}.bin)
endif()
target_link_libraries(nuttx_c INTERFACE nuttx_drivers)
target_link_libraries(nuttx_drivers INTERFACE nuttx_c)
target_link_libraries(nuttx_xx INTERFACE nuttx_c)
target_link_libraries(nuttx_fs INTERFACE nuttx_c)
if (NOT CONFIG_BUILD_FLAT)
target_link_libraries(px4 PRIVATE
target_link_libraries(nuttx_karch
INTERFACE
drivers_board
arch_hrt
)
-nostartfiles
-nodefaultlibs
-nostdlib
-nostdinc++
target_link_libraries(px4_kernel PRIVATE
-fno-exceptions
-fno-rtti
-Wl,--script=${NUTTX_CONFIG_DIR_CYG}/scripts/${SCRIPT_PREFIX}script.ld
-Wl,-Map=${PX4_CONFIG}.map
-Wl,--warn-common
-Wl,--gc-sections
-nostartfiles
-nodefaultlibs
-nostdlib
-nostdinc++
-Wl,--start-group
${nuttx_libs}
-Wl,--end-group
-fno-exceptions
-fno-rtti
m
gcc
)
-Wl,--script=${NUTTX_CONFIG_DIR}/scripts/${SCRIPT_PREFIX}memory.ld,--script=${NUTTX_CONFIG_DIR}/scripts/${SCRIPT_PREFIX}kernel-space.ld
if(NOT USE_LD_GOLD)
target_link_libraries(px4 PRIVATE -Wl,--print-memory-usage)
endif()
-Wl,-Map=${PX4_CONFIG}_kernel.map
-Wl,--warn-common
-Wl,--gc-sections
target_link_libraries(px4 PRIVATE ${module_libraries})
-Wl,--start-group
${nuttx_libs}
${kernel_module_libraries}
px4_work_queue # TODO, this shouldn't be needed here?
-Wl,--end-group
if(config_romfs_root)
add_subdirectory(${PX4_SOURCE_DIR}/ROMFS ${PX4_BINARY_DIR}/ROMFS)
target_link_libraries(px4 PRIVATE romfs)
endif()
m
gcc
)
if((DEFINED ENV{SIGNING_TOOL}) AND (NOT NUTTX_DIR MATCHES "external"))
set(PX4_BINARY_OUTPUT ${PX4_BINARY_DIR}/${PX4_CONFIG}_unsigned.bin)
if (config_romfs_root)
add_subdirectory(${PX4_SOURCE_DIR}/ROMFS ${PX4_BINARY_DIR}/ROMFS)
target_link_libraries(px4_kernel PRIVATE romfs)
endif()
add_custom_command(OUTPUT ${PX4_BINARY_DIR_REL}/${PX4_CONFIG}.bin
COMMAND $ENV{SIGNING_TOOL} $ENV{SIGNING_ARGS} ${PX4_BINARY_OUTPUT} ${PX4_BINARY_DIR}/${PX4_CONFIG}.bin
DEPENDS ${PX4_BINARY_OUTPUT}
WORKING_DIRECTORY ${PX4_SOURCE_DIR}
target_link_libraries(px4_kernel PRIVATE -Wl,--print-memory-usage)
set(nuttx_userspace)
list(APPEND nuttx_userspace
drivers_userspace
nuttx_arch
nuttx_apps
nuttx_mm
nuttx_proxies
nuttx_c
nuttx_xx
)
target_link_libraries(nuttx_c INTERFACE nuttx_proxies)
target_link_libraries(px4 PRIVATE
-nostartfiles
-nodefaultlibs
-nostdlib
-nostdinc++
-fno-exceptions
-fno-rtti
-Wl,--script=${NUTTX_CONFIG_DIR}/scripts/${SCRIPT_PREFIX}memory.ld,--script=${NUTTX_CONFIG_DIR}/scripts/${SCRIPT_PREFIX}user-space.ld
-Wl,-Map=${PX4_CONFIG}.map
-Wl,--warn-common
-Wl,--gc-sections
-Wl,--start-group
${nuttx_userspace}
-Wl,--end-group
m
gcc
)
target_link_libraries(px4 PRIVATE -Wl,--print-memory-usage)
target_link_libraries(px4 PRIVATE
${module_libraries}
)
add_custom_command(OUTPUT ${PX4_BINARY_OUTPUT}
COMMAND ${CMAKE_OBJCOPY} -O binary ${PX4_BINARY_DIR_REL}/${FW_NAME} ${PX4_BINARY_DIR_REL}/${PX4_BOARD}_user.bin
COMMAND ${CMAKE_OBJCOPY} --gap-fill 0xFF --pad-to ${CONFIG_NUTTX_USERSPACE} -O binary ${PX4_BINARY_DIR_REL}/${KERNEL_NAME} ${PX4_BINARY_OUTPUT}
COMMAND cat ${PX4_BINARY_DIR_REL}/${PX4_BOARD}_user.bin >> ${PX4_BINARY_OUTPUT}
DEPENDS px4 px4_kernel
)
else()
set(PX4_BINARY_OUTPUT ${PX4_BINARY_DIR_REL}/${PX4_CONFIG}.bin)
endif()
add_custom_command(OUTPUT ${PX4_BINARY_OUTPUT}
COMMAND ${CMAKE_OBJCOPY} -O binary ${PX4_BINARY_DIR_REL}/${FW_NAME} ${PX4_BINARY_OUTPUT}
DEPENDS px4
)
target_link_libraries(nuttx_c INTERFACE nuttx_sched) # nxsched_get_streams
target_link_libraries(nuttx_arch
INTERFACE
drivers_board
arch_hrt
arch_board_reset
)
target_link_libraries(nuttx_c INTERFACE nuttx_drivers)
target_link_libraries(nuttx_drivers INTERFACE nuttx_c)
target_link_libraries(nuttx_xx INTERFACE nuttx_c)
target_link_libraries(nuttx_fs INTERFACE nuttx_c)
target_link_libraries(px4 PRIVATE
-nostartfiles
-nodefaultlibs
-nostdlib
-nostdinc++
-fno-exceptions
-fno-rtti
-Wl,--script=${NUTTX_CONFIG_DIR_CYG}/scripts/${SCRIPT_PREFIX}script.ld
-Wl,-Map=${PX4_CONFIG}.map
-Wl,--warn-common
-Wl,--gc-sections
-Wl,--start-group
${nuttx_libs}
-Wl,--end-group
m
gcc
)
if(NOT USE_LD_GOLD)
target_link_libraries(px4 PRIVATE -Wl,--print-memory-usage)
endif()
target_link_libraries(px4 PRIVATE ${module_libraries})
if(config_romfs_root)
add_subdirectory(${PX4_SOURCE_DIR}/ROMFS ${PX4_BINARY_DIR}/ROMFS)
target_link_libraries(px4 PRIVATE romfs)
endif()
add_custom_command(OUTPUT ${PX4_BINARY_OUTPUT}
COMMAND ${CMAKE_OBJCOPY} -O binary ${PX4_BINARY_DIR_REL}/${FW_NAME} ${PX4_BINARY_OUTPUT}
DEPENDS px4
)
endif()
# create .px4 with parameter and airframe metadata
if (TARGET parameters_xml AND TARGET airframes_xml)

Loading…
Cancel
Save