NuttX build in place

- cmake NuttX build wrapper compile in place instead of copying source tree to build directory
    - slightly faster skipping necessary copying (depending on system)
    - allows debugging in place
    - easier to work directly in NuttX following official documentation
    - simplifies overall build which should make it easier to resolve any remaining NuttX dependency issues in the build system
 - the downside is switching back and forth between different builds always require rebuilding NuttX, but I think this is worth the improved developer experience
 - also no longer builds px4io and bootloader in every single build, for most users these rarely change and we're wasting a lot of build time
This commit is contained in:
Daniel Agar
2021-11-15 18:47:38 -05:00
committed by GitHub
parent 7b7b7acd36
commit f5d9b01f5c
164 changed files with 351 additions and 751 deletions
+2 -2
View File
@@ -71,13 +71,13 @@ if(NOT "${PX4_BOARD_LABEL}" MATCHES "canbootloader")
${PX4_BINARY_DIR}/${uavcan_bl_image_name}
${PX4_BINARY_DIR}/deploy/${HWBOARD_ID}.bin
COMMAND
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/make_can_boot_descriptor.py -v --padding ${uavcanbl_padding} --use-git-hash ${PX4_BOARD}.bin ${uavcan_bl_image_name}
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/make_can_boot_descriptor.py -v --padding ${uavcanbl_padding} --use-git-hash ${PX4_CONFIG}.bin ${uavcan_bl_image_name}
COMMAND
COMMAND ${CMAKE_COMMAND} -E make_directory deploy
COMMAND
${CMAKE_COMMAND} -E copy ${uavcan_bl_image_name} deploy/${HWBOARD_ID}.bin
DEPENDS
${PX4_BINARY_DIR}/${PX4_BOARD}.bin
${PX4_BINARY_DIR}/${PX4_CONFIG}.bin
${CMAKE_CURRENT_SOURCE_DIR}/make_can_boot_descriptor.py
WORKING_DIRECTORY
${PX4_BINARY_DIR}
+24 -24
View File
@@ -48,31 +48,31 @@ px4_add_module(
)
# include the px4io binary in ROMFS
message(STATUS "Building and including ${config_io_board}")
if(CONFIG_BOARD_IO)
message(STATUS "drivers/px4io: ROMFS including ${CONFIG_BOARD_IO}")
include(ExternalProject)
ExternalProject_Add(px4io_firmware
SOURCE_DIR ${CMAKE_SOURCE_DIR}
DOWNLOAD_COMMAND ""
UPDATE_COMMAND ""
CMAKE_ARGS -DCONFIG=${config_io_board}
INSTALL_COMMAND ""
USES_TERMINAL_BUILD true
DEPENDS git_nuttx git_nuttx_apps
BUILD_ALWAYS 1
BUILD_BYPRODUCTS ${PX4_BINARY_DIR}/external/Build/px4io_firmware/${config_io_board}.elf
)
# ExternalProject_Add() with GIT_SUBMODULES "" initializes no submodules.
cmake_policy(SET CMP0097 NEW)
set(fw_io_exe "${PX4_BINARY_DIR}/external/Build/px4io_firmware/${config_io_board}.elf")
set(fw_io_bin "${PX4_BINARY_DIR}/romfs_extras/${config_io_board}.bin" CACHE FILEPATH "px4io binary path")
include(ExternalProject)
file(RELATIVE_PATH fw_io_exe_relative ${CMAKE_CURRENT_BINARY_DIR} ${fw_io_exe})
file(RELATIVE_PATH fw_io_bin_relative ${CMAKE_CURRENT_BINARY_DIR} ${fw_io_bin})
add_custom_command(OUTPUT ${fw_io_bin}
COMMAND ${CMAKE_COMMAND} -E make_directory ${PX4_BINARY_DIR}/romfs_extras
COMMAND ${CMAKE_OBJCOPY} -O binary ${fw_io_exe_relative} ${fw_io_bin_relative}
DEPENDS ${fw_io_exe} px4io_firmware
COMMENT "Copying ${config_io_board} to ROMFS extras"
ExternalProject_Add(px4io_firmware_build
DOWNLOAD_COMMAND rsync -a --safe-links --delete --exclude=build --exclude=*.o --exclude=*.a --exclude=.config ${PX4_SOURCE_DIR}/ ${PX4_BINARY_DIR}/external/Source/px4io_firmware_build/
UPDATE_COMMAND rsync -a --safe-links --delete --exclude=build --exclude=*.o --exclude=*.a --exclude=.config ${PX4_SOURCE_DIR}/ ${PX4_BINARY_DIR}/external/Source/px4io_firmware_build/
DEPENDS git_nuttx git_nuttx_apps
SOURCE_DIR ${PX4_BINARY_DIR}/external/Source/px4io_firmware_build/
CMAKE_ARGS -DCONFIG=${CONFIG_BOARD_IO}
INSTALL_COMMAND ""
USES_TERMINAL_BUILD true
EXCLUDE_FROM_ALL true
BUILD_ALWAYS true
)
add_custom_target(copy_px4io_bin DEPENDS ${fw_io_bin})
ExternalProject_Get_Property(px4io_firmware_build BINARY_DIR)
add_custom_target(px4io_firmware_update
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${BINARY_DIR}/${CONFIG_BOARD_IO}.bin ${PX4_BOARD_DIR}/extras/${CONFIG_BOARD_IO}.bin
DEPENDS px4io_firmware_build
COMMENT "Copying ${CONFIG_BOARD_IO} to board extras"
)
endif()
+1 -1
View File
@@ -2,4 +2,4 @@ menuconfig DRIVERS_PX4IO
bool "px4io"
default n
---help---
Enable support for px4io
Enable support for px4io
+5 -3
View File
@@ -79,7 +79,7 @@ endif()
if(PX4_ETHERNET)
set(added_arguments --ethernet)
endif()
if(config_io_board)
if(CONFIG_BOARD_IO)
set(board_with_io_arg --board-with-io)
endif()
add_custom_command(OUTPUT ${generated_serial_params_file} ${generated_module_params_file}
@@ -87,13 +87,15 @@ add_custom_command(OUTPUT ${generated_serial_params_file} ${generated_module_par
COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/serial/generate_config.py
--params-file ${generated_serial_params_file}
--serial-ports ${board_serial_ports} ${added_arguments} ${constrained_flash_arg}
--config-files ${module_config_files} #--verbose
--config-files ${module_config_files}
#--verbose
COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/module_config/generate_params.py
--params-file ${generated_module_params_file}
${added_arguments} ${board_with_io_arg}
--timer-config ${PX4_BOARD_DIR}/src/timer_config.cpp
--config-files ${module_config_files} #--verbose
--config-files ${module_config_files}
--board ${PX4_BOARD}
#--verbose
DEPENDS
${module_config_files}
${jinja_templates}
+3 -3
View File
@@ -148,9 +148,9 @@ if (os.path.exists('src/modules/mavlink/mavlink/.git')):
# NuttX
if (os.path.exists('platforms/nuttx/NuttX/nuttx/.git')):
nuttx_git_tag = subprocess.check_output('git describe --always --tags --match nuttx-* --dirty'.split(),
cwd='platforms/nuttx/NuttX/nuttx', stderr=subprocess.STDOUT).decode('utf-8').strip().replace("nuttx-","v")
nuttx_git_tag = re.sub('-.*','.0',nuttx_git_tag)
nuttx_git_tag = subprocess.check_output('git describe --always --tags --match nuttx-* --dirty'.split(),
cwd='platforms/nuttx/NuttX/nuttx', stderr=subprocess.STDOUT).decode('utf-8').strip().replace("nuttx-", "v")
nuttx_git_tag = re.sub('-.*', '.0', nuttx_git_tag)
nuttx_git_version = subprocess.check_output('git rev-parse --verify HEAD'.split(),
cwd='platforms/nuttx/NuttX/nuttx', stderr=subprocess.STDOUT).decode('utf-8').strip()
nuttx_git_version_short = nuttx_git_version[0:16]
-71
View File
@@ -39,74 +39,3 @@ px4_add_module(
SRCS
bl_update.c
)
if(config_build_bootloader)
# include the bootloader binary in ROMFS
set(bootloader_config "${PX4_BOARD_VENDOR}_${PX4_BOARD_MODEL}_bootloader")
if(NOT EXISTS ${PX4_BOARD_DIR}/nuttx-config/bootloader)
message(FATAL_ERROR "${bootloader_config} does not exist")
endif()
message(STATUS "Building and including bootloader ${bootloader_config}")
include(ExternalProject)
ExternalProject_Add(bootloader_firmware
SOURCE_DIR ${CMAKE_SOURCE_DIR}
DOWNLOAD_COMMAND ""
UPDATE_COMMAND ""
CMAKE_ARGS -DCONFIG=${bootloader_config}
INSTALL_COMMAND ""
USES_TERMINAL_BUILD true
DEPENDS git_nuttx git_nuttx_apps
BUILD_ALWAYS 1
)
ExternalProject_Get_Property(bootloader_firmware BINARY_DIR)
set(board_bootloader_firmware "${BINARY_DIR}/${bootloader_config}.elf" CACHE FILEPATH "bootloader original binary path")
set(bootloader_bin "${PX4_BINARY_DIR}/romfs_extras/bootloader.bin" CACHE FILEPATH "bootloader binary path")
file(RELATIVE_PATH bootloader_exe_relative ${CMAKE_CURRENT_BINARY_DIR} ${board_bootloader_firmware})
file(RELATIVE_PATH bootloader_bin_relative ${CMAKE_CURRENT_BINARY_DIR} ${bootloader_bin})
add_custom_command(
OUTPUT ${bootloader_bin}
COMMAND ${CMAKE_COMMAND} -E make_directory ${PX4_BINARY_DIR}/romfs_extras
COMMAND ${CMAKE_OBJCOPY} -O binary ${bootloader_exe_relative} ${bootloader_bin_relative}
DEPENDS bootloader_firmware
COMMENT "Copying ${bootloader_config} to ROMFS extras"
)
add_custom_target(copy_bootloader_bin DEPENDS ${bootloader_bin})
# copy bootloader.elf to top level build directory
add_custom_command(
OUTPUT ${PX4_BINARY_DIR}/${PX4_BOARD_VENDOR}_${PX4_BOARD_MODEL}_bootloader.elf
COMMAND ${CMAKE_COMMAND} -E copy ${BINARY_DIR}/${bootloader_config}.elf ${PX4_BINARY_DIR}/${PX4_BOARD_VENDOR}_${PX4_BOARD_MODEL}_bootloader.elf
DEPENDS bootloader_firmware
WORKING_DIRECTORY ${PX4_BINARY_DIR}
)
add_custom_target(bootloader_elf DEPENDS ${PX4_BINARY_DIR}/${PX4_BOARD_VENDOR}_${PX4_BOARD_MODEL}_bootloader.elf)
elseif(EXISTS "${PX4_BOARD_DIR}/bootloader/")
if(EXISTS ${PX4_BOARD_DIR}/bootloader/${PX4_BOARD_VENDOR}_${PX4_BOARD_MODEL}_bootloader.bin)
set(board_bootloader_firmware ${PX4_BOARD_DIR}/bootloader/${PX4_BOARD_VENDOR}_${PX4_BOARD_MODEL}_bootloader.bin CACHE FILEPATH "bootloader original binary path")
set(bootloader_bin "${PX4_BINARY_DIR}/romfs_extras/bootloader.bin" CACHE FILEPATH "bootloader binary path")
add_custom_command(
OUTPUT ${bootloader_bin}
COMMAND ${CMAKE_COMMAND} -E make_directory ${PX4_BINARY_DIR}/romfs_extras
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${board_bootloader_firmware} ${PX4_BINARY_DIR}/romfs_extras/bootloader.bin
DEPENDS ${board_bootloader_firmware}
COMMENT "Copying ${board_bootloader_firmware} to ROMFS extras"
)
add_custom_target(copy_bootloader_bin DEPENDS ${bootloader_bin})
else()
file(GLOB bootloader_bin_files ${PX4_BOARD_DIR}/bootloader/*.bin)
foreach(bin_file ${bootloader_bin_files})
message(FATAL_ERROR "incorrect bootloader filename ${bin_file} should be ${PX4_BOARD_VENDOR}_${PX4_BOARD_MODEL}_bootloader.bin")
endforeach()
endif()
endif()