mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-24 07:52:44 +08:00
build(px4io): build IO firmware from source, drop committed binaries
Boards with a px4io took the IO firmware from a binary committed under
boards/<vendor>/io-v2/extras/. It had to be regenerated by hand with
"make px4io_update" whenever px4iofirmware, lib/rc, the IO board or
NuttX changed, and a CI job failed until it was.
Build it from source instead. A target with CONFIG_BOARD_IO set now
builds that IO target as part of its own build and puts the result in
its ROMFS. NuttX builds inside its source tree, so the IO build gets its
own copy of the NuttX sources in build/px4io/<BOARD_IO>/, shared by
every target built in the checkout. The IO build runs on every build of
the embedding target, so an IO source change reaches the ROMFS without
a clean.
PX4_NUTTX_TREE_DIR points a NuttX build at such a copy, and the
hardcoded platforms/nuttx/NuttX/{nuttx,apps} paths now go through
NUTTX_DIR and NUTTX_APPS_DIR.
Remove the two committed binaries, the px4io_update and check_px4io
make targets, and the CI job that compared them.
Assisted-by: Claude:claude-fable-5-2
This commit is contained in:
1 parent
53baa28a50
commit
170dfbbfe8
13 files changed
+217
-71
No files matched your search
@@ -48,27 +48,6 @@ jobs:
|
||||
PX4_SBOM_DISABLE: 1
|
||||
run: make ${{ matrix.check }}
|
||||
|
||||
# The committed px4io firmware binaries must match what the current sources build to.
|
||||
# The build is reproducible with a fixed toolchain, so a mismatch means a dependency
|
||||
# changed without "make px4io_update", and the job fails.
|
||||
px4io_firmware:
|
||||
name: IO Firmware Up To Date
|
||||
runs-on: [runs-on,runner=2cpu-linux-x64,image=ubuntu24-full-x64,"run-id=${{ github.run_id }}",spot=false,extras=s3-cache]
|
||||
container:
|
||||
image: ghcr.io/px4/px4-dev:v1.17.0-rc2
|
||||
steps:
|
||||
- uses: runs-on/action@v2
|
||||
- uses: actions/checkout@v6
|
||||
with:
|
||||
fetch-depth: 1
|
||||
- name: Configure Git Safe Directory
|
||||
run: git config --system --add safe.directory '*'
|
||||
|
||||
- name: Build and compare px4io firmware
|
||||
env:
|
||||
PX4_SBOM_DISABLE: 1
|
||||
run: make check_px4io
|
||||
|
||||
tests:
|
||||
name: Unit Tests
|
||||
runs-on: [runs-on,runner=8cpu-linux-x64,image=ubuntu24-full-x64,"run-id=${{ github.run_id }}",spot=false,extras=s3-cache]
|
||||
|
||||
@@ -335,27 +335,6 @@ uorb_graphs:
|
||||
@$(MAKE) --no-print-directory px4_fmu-v6x_default uorb_graph
|
||||
@$(MAKE) --no-print-directory px4_sitl_default uorb_graph
|
||||
|
||||
# The px4io firmware is committed once per IO board and embedded into the ROMFS of every
|
||||
# board with CONFIG_BOARD_IO set. The build is reproducible, but only with the same
|
||||
# toolchain, so regenerate it in the px4-dev image used by the check_px4io CI job
|
||||
# (.github/workflows/checks.yml):
|
||||
# PX4_DOCKER_REPO=<that image> ./Tools/docker_run.sh 'make px4io_update'
|
||||
.PHONY: px4io_build px4io_update check_px4io
|
||||
|
||||
px4io_build:
|
||||
@$(MAKE) --no-print-directory px4_io-v2_default
|
||||
@$(MAKE) --no-print-directory cubepilot_io-v2_default
|
||||
|
||||
px4io_update: px4io_build
|
||||
cp build/px4_io-v2_default/px4_io-v2_default.bin boards/px4/io-v2/extras/
|
||||
cp build/cubepilot_io-v2_default/cubepilot_io-v2_default.bin boards/cubepilot/io-v2/extras/
|
||||
|
||||
# compares without touching the committed binaries
|
||||
check_px4io: px4io_build
|
||||
@cmp build/px4_io-v2_default/px4_io-v2_default.bin boards/px4/io-v2/extras/px4_io-v2_default.bin \
|
||||
&& cmp build/cubepilot_io-v2_default/cubepilot_io-v2_default.bin boards/cubepilot/io-v2/extras/cubepilot_io-v2_default.bin \
|
||||
|| { echo "px4io firmware is out of date, regenerate it with 'make px4io_update' (see Makefile)"; exit 1; }
|
||||
|
||||
bootloaders_update: \
|
||||
3dr_ctrl-n1_bootloader \
|
||||
3dr_ctrl-zero-h7-oem-revg_bootloader \
|
||||
|
||||
+36
-11
@@ -297,25 +297,50 @@ foreach(board_extra_file ${OPTIONAL_BOARD_EXTRAS})
|
||||
list(REMOVE_ITEM OPTIONAL_BOARD_EXTRAS ${board_extra_file})
|
||||
endif()
|
||||
elseif(${extra_file_base_name} MATCHES "_io-v[0-9]+_default\\.bin$")
|
||||
# px4io firmware is no longer kept per board, see CONFIG_BOARD_IO below
|
||||
# px4io firmware is not kept in the tree, see CONFIG_BOARD_IO below
|
||||
file(RELATIVE_PATH extra_file_relative_source ${PX4_SOURCE_DIR} ${board_extra_file})
|
||||
message(FATAL_ERROR "Delete ${extra_file_relative_source}: the px4io firmware is now taken from "
|
||||
"boards/<vendor>/<io board>/extras/ via CONFIG_BOARD_IO and must not be kept per board.")
|
||||
message(FATAL_ERROR "Delete ${extra_file_relative_source}: the px4io firmware is built from source "
|
||||
"for CONFIG_BOARD_IO and must not be committed.")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# px4io firmware (optional)
|
||||
# - the binary is kept once per IO board, in boards/<vendor>/<model>/extras/<CONFIG_BOARD_IO>.bin
|
||||
# - regenerate it with "make px4io_update", CI checks it with "make check_px4io"
|
||||
# - built from source for CONFIG_BOARD_IO, once per checkout, in build/px4io/<CONFIG_BOARD_IO>/
|
||||
# - the build runs on every build of this target so that IO source changes reach the ROMFS,
|
||||
# the ROMFS is only regenerated when the IO binary changed
|
||||
if(CONFIG_DRIVERS_PX4IO AND CONFIG_BOARD_IO)
|
||||
if(NOT CONFIG_BOARD_IO MATCHES "^([^_]+)_(.+)_([^_]+)$")
|
||||
message(FATAL_ERROR "BOARD_IO '${CONFIG_BOARD_IO}' is not of the form <vendor>_<model>_<label>")
|
||||
endif()
|
||||
set(px4io_firmware_bin ${PX4_SOURCE_DIR}/boards/${CMAKE_MATCH_1}/${CMAKE_MATCH_2}/extras/${CONFIG_BOARD_IO}.bin)
|
||||
if(NOT EXISTS ${px4io_firmware_bin})
|
||||
message(FATAL_ERROR "px4io firmware not found at: ${px4io_firmware_bin} (run make px4io_update)")
|
||||
endif()
|
||||
list(APPEND OPTIONAL_BOARD_EXTRAS ${px4io_firmware_bin})
|
||||
set(px4io_firmware_bin ${PX4_SOURCE_DIR}/build/px4io/${CONFIG_BOARD_IO}/build/${CONFIG_BOARD_IO}.bin)
|
||||
message(STATUS "ROMFS: Adding px4io firmware ${CONFIG_BOARD_IO} -> /etc/extras/${CONFIG_BOARD_IO}.bin")
|
||||
|
||||
add_custom_target(px4io_firmware
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-DPX4_SOURCE_DIR=${PX4_SOURCE_DIR}
|
||||
-DBOARD_IO=${CONFIG_BOARD_IO}
|
||||
-DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
|
||||
-P ${PX4_SOURCE_DIR}/platforms/nuttx/cmake/px4io_firmware_build.cmake
|
||||
BYPRODUCTS ${px4io_firmware_bin}
|
||||
COMMENT "ROMFS: building px4io firmware ${CONFIG_BOARD_IO}"
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT
|
||||
${romfs_gen_root_dir}/extras/${CONFIG_BOARD_IO}.bin
|
||||
${CONFIG_BOARD_IO}.bin.stamp
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${px4io_firmware_bin} ${romfs_gen_root_dir}/extras/${CONFIG_BOARD_IO}.bin
|
||||
COMMAND ${CMAKE_COMMAND} -E touch ${CONFIG_BOARD_IO}.bin.stamp
|
||||
DEPENDS
|
||||
${px4io_firmware_bin}
|
||||
romfs_copy.stamp
|
||||
COMMENT "ROMFS: copying px4io firmware ${CONFIG_BOARD_IO}"
|
||||
)
|
||||
|
||||
list(APPEND extras_dependencies
|
||||
${CONFIG_BOARD_IO}.bin.stamp
|
||||
)
|
||||
endif()
|
||||
|
||||
foreach(board_extra_file ${OPTIONAL_BOARD_EXTRAS})
|
||||
@@ -390,7 +415,7 @@ if("${CONFIG_FS_CROMFS}" STREQUAL "y")
|
||||
OUTPUT ${CMAKE_BINARY_DIR}/gencromfs
|
||||
COMMAND make --no-print-directory --silent -f Makefile.host gencromfs
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different gencromfs ${CMAKE_BINARY_DIR}/gencromfs
|
||||
DEPENDS ${PX4_SOURCE_DIR}/platforms/nuttx/NuttX/nuttx/tools/gencromfs.c
|
||||
DEPENDS ${NUTTX_DIR}/tools/gencromfs.c
|
||||
WORKING_DIRECTORY ${NUTTX_DIR}/tools
|
||||
)
|
||||
|
||||
|
||||
@@ -40,6 +40,10 @@ METADATA = ('parameters.xml', 'parameters.json', 'parameters.json.xz',
|
||||
'actuators.json', 'actuators.json.xz')
|
||||
EVENTS = 'all_events.json.xz'
|
||||
GENERAL_SOURCE = 'px4_sitl_default'
|
||||
# build/px4io holds the px4io firmware that targets with an IO build for their
|
||||
# own ROMFS (platforms/nuttx/cmake/px4io_firmware_build.cmake). The published
|
||||
# IO image comes from the *_io-v*_default targets.
|
||||
NOT_TARGETS = ('px4io',)
|
||||
|
||||
|
||||
def target_labels(boards=BOARDS):
|
||||
@@ -142,7 +146,7 @@ def package(build=BUILD, artifacts=ARTIFACTS, labels=None, unpublished=None):
|
||||
|
||||
artifacts.mkdir(exist_ok=True)
|
||||
for build_dir in sorted(build.iterdir()):
|
||||
if not build_dir.is_dir() or build_dir.name.startswith('.'):
|
||||
if not build_dir.is_dir() or build_dir.name.startswith('.') or build_dir.name in NOT_TARGETS:
|
||||
continue
|
||||
reason = unpublished_reason(build_dir.name, labels, unpublished)
|
||||
if reason:
|
||||
|
||||
@@ -55,6 +55,8 @@ class PackageTest(unittest.TestCase):
|
||||
self.add_target('modalai_voxl2-io_default', mavlink=False)
|
||||
self.add_target('px4_sitl_default')
|
||||
(self.build / 'px4_sitl_default' / 'boardconfig').unlink()
|
||||
# build/px4io is the px4io firmware built for other targets, not a target
|
||||
self.add_target('px4io')
|
||||
|
||||
def with_metadata(target):
|
||||
return {f'{target}.px4', f'{target}.elf', f'{target}/{target}.sbom.spdx.json',
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -67,7 +67,9 @@ endif()
|
||||
add_subdirectory(px4_work_queue)
|
||||
add_subdirectory(work_queue)
|
||||
|
||||
if("${PX4_PLATFORM}" MATCHES "nuttx")
|
||||
if(PX4_NUTTX_TREE_DIR)
|
||||
# built for another target's ROMFS (px4io firmware): the editor config belongs to that target
|
||||
elseif("${PX4_PLATFORM}" MATCHES "nuttx")
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/c_cpp_properties.json.nuttx.in ${PX4_SOURCE_DIR}/.vscode/c_cpp_properties.json @ONLY)
|
||||
else()
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/c_cpp_properties.json.in ${PX4_SOURCE_DIR}/.vscode/c_cpp_properties.json @ONLY)
|
||||
|
||||
@@ -143,7 +143,7 @@ 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)
|
||||
|
||||
if((DEFINED ENV{SIGNING_TOOL}) AND (NOT NUTTX_DIR MATCHES "external"))
|
||||
if((DEFINED ENV{SIGNING_TOOL}) AND (NOT PX4_NUTTX_TREE_DIR))
|
||||
set(PX4_BINARY_OUTPUT ${PX4_BINARY_DIR}/${PX4_CONFIG}_unsigned.bin)
|
||||
|
||||
add_custom_command(OUTPUT ${PX4_BINARY_DIR_REL}/${PX4_CONFIG}.bin
|
||||
@@ -280,7 +280,7 @@ else()
|
||||
|
||||
if(CONFIG_ARCH_CHIP_ESP32)
|
||||
|
||||
set(PX4_STARTUP_DIR ${PX4_SOURCE_DIR}/platforms/nuttx/NuttX/nuttx/arch/xtensa/src)
|
||||
set(PX4_STARTUP_DIR ${NUTTX_DIR}/arch/xtensa/src)
|
||||
set(WIRELESS_LIB ${PX4_STARTUP_DIR}/esp32/esp-wireless-drivers-3rdparty/libs/esp32/)
|
||||
|
||||
set(NUTTX_STARTUP_OBJS
|
||||
@@ -642,8 +642,8 @@ endif()
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Debug/gdbinit.in ${PX4_BINARY_DIR}/.gdbinit)
|
||||
|
||||
# vscode launch.json
|
||||
# skip if built within another cmake project (eg px4_io-v2 with px4_fmu-v5)
|
||||
if(NOT NUTTX_DIR MATCHES "external")
|
||||
# skip if built for another target's ROMFS (eg px4_io-v2 with px4_fmu-v5)
|
||||
if(NOT PX4_NUTTX_TREE_DIR)
|
||||
if(CONFIG_ARCH_CHIP_MIMXRT1062DVL6A)
|
||||
set(DEBUG_DEVICE "MIMXRT1062XXX6A")
|
||||
set(DEBUG_SVD_FILE "MIMXRT1062.xml")
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
############################################################################
|
||||
|
||||
set(NUTTX_CONFIG_DIR ${PX4_BOARD_DIR}/nuttx-config)
|
||||
set(APPS_DIR ${NUTTX_SRC_DIR}/apps)
|
||||
set(APPS_DIR ${NUTTX_APPS_DIR})
|
||||
|
||||
###############################################################################
|
||||
# NuttX build
|
||||
@@ -181,8 +181,8 @@ function(add_nuttx_dir nuttx_lib nuttx_lib_dir kernel extra target)
|
||||
endif()
|
||||
|
||||
file(GLOB_RECURSE nuttx_lib_files LIST_DIRECTORIES false
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/nuttx/${nuttx_lib_dir}/*.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/nuttx/${nuttx_lib_dir}/*.h
|
||||
${NUTTX_DIR}/${nuttx_lib_dir}/*.c
|
||||
${NUTTX_DIR}/${nuttx_lib_dir}/*.h
|
||||
)
|
||||
|
||||
# Route kernel pass for mm/libc to kbin/; user pass uses bin/ for the
|
||||
|
||||
@@ -56,9 +56,22 @@ set(NUTTX_CONFIG_DIR ${PX4_BOARD_DIR}/nuttx-config CACHE FILEPATH "PX4 NuttX con
|
||||
set(NUTTX_DEFCONFIG ${NUTTX_CONFIG_DIR}/${NUTTX_CONFIG}/defconfig CACHE FILEPATH "path to defconfig" FORCE)
|
||||
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${NUTTX_DEFCONFIG})
|
||||
|
||||
# NUTTX_SRC_DIR holds PX4's NuttX glue (Make.defs.in, tools, include overlay) and
|
||||
# the nuttx and apps submodules. NuttX builds inside its source tree, so by
|
||||
# default the build happens in those submodules. PX4_NUTTX_TREE_DIR points the
|
||||
# build at another directory holding a copy of nuttx/ and apps/ instead, which
|
||||
# lets a second target build in the same checkout without sharing that state
|
||||
# (see px4io_firmware_build.cmake). Board defconfigs reach their board directory
|
||||
# with a path relative to nuttx/ (CONFIG_ARCH_BOARD_CUSTOM_DIR), so such a tree
|
||||
# has to sit three levels below PX4_SOURCE_DIR, like the submodules do.
|
||||
set(NUTTX_SRC_DIR ${PX4_SOURCE_DIR}/platforms/nuttx/NuttX)
|
||||
set(NUTTX_DIR ${PX4_SOURCE_DIR}/platforms/nuttx/NuttX/nuttx CACHE FILEPATH "NuttX directory" FORCE)
|
||||
set(NUTTX_APPS_DIR ${PX4_SOURCE_DIR}/platforms/nuttx/NuttX/apps CACHE FILEPATH "NuttX apps directory" FORCE)
|
||||
if(PX4_NUTTX_TREE_DIR)
|
||||
set(nuttx_tree_dir ${PX4_NUTTX_TREE_DIR})
|
||||
else()
|
||||
set(nuttx_tree_dir ${NUTTX_SRC_DIR})
|
||||
endif()
|
||||
set(NUTTX_DIR ${nuttx_tree_dir}/nuttx CACHE FILEPATH "NuttX directory" FORCE)
|
||||
set(NUTTX_APPS_DIR ${nuttx_tree_dir}/apps CACHE FILEPATH "NuttX apps directory" FORCE)
|
||||
|
||||
px4_add_git_submodule(TARGET git_nuttx PATH "${NUTTX_SRC_DIR}/nuttx")
|
||||
px4_add_git_submodule(TARGET git_nuttx_apps PATH "${NUTTX_SRC_DIR}/apps")
|
||||
|
||||
@@ -51,13 +51,13 @@
|
||||
function(px4_os_add_flags)
|
||||
|
||||
include_directories(BEFORE SYSTEM
|
||||
${PX4_SOURCE_DIR}/platforms/nuttx/NuttX/nuttx/include
|
||||
${NUTTX_DIR}/include
|
||||
)
|
||||
|
||||
if(CONFIG_LIB_TFLM) # Since TFLM uses the standard C++ library, we need to exclude the NuttX C++ include path
|
||||
add_custom_target(copy_header ALL
|
||||
COMMAND ${CMAKE_COMMAND} -E copy # One of the header files from nuttx is needed
|
||||
${PX4_SOURCE_DIR}/platforms/nuttx/NuttX/nuttx/include/cxx/cstdlib
|
||||
${NUTTX_DIR}/include/cxx/cstdlib
|
||||
${PX4_SOURCE_DIR}/src/lib/tensorflow_lite_micro/include/cstdlib
|
||||
)
|
||||
|
||||
@@ -66,18 +66,18 @@ function(px4_os_add_flags)
|
||||
)
|
||||
else()
|
||||
include_directories(BEFORE SYSTEM
|
||||
${PX4_SOURCE_DIR}/platforms/nuttx/NuttX/nuttx/include/cxx
|
||||
${NUTTX_DIR}/include/cxx
|
||||
${PX4_SOURCE_DIR}/platforms/nuttx/NuttX/include/cxx # custom new
|
||||
)
|
||||
|
||||
endif()
|
||||
|
||||
include_directories(
|
||||
${PX4_SOURCE_DIR}/platforms/nuttx/NuttX/nuttx/arch/${CONFIG_ARCH}/src/${CONFIG_ARCH_FAMILY}
|
||||
${PX4_SOURCE_DIR}/platforms/nuttx/NuttX/nuttx/arch/${CONFIG_ARCH}/src/chip
|
||||
${PX4_SOURCE_DIR}/platforms/nuttx/NuttX/nuttx/arch/${CONFIG_ARCH}/src/common
|
||||
${NUTTX_DIR}/arch/${CONFIG_ARCH}/src/${CONFIG_ARCH_FAMILY}
|
||||
${NUTTX_DIR}/arch/${CONFIG_ARCH}/src/chip
|
||||
${NUTTX_DIR}/arch/${CONFIG_ARCH}/src/common
|
||||
|
||||
${PX4_SOURCE_DIR}/platforms/nuttx/NuttX/apps/include
|
||||
${NUTTX_APPS_DIR}/include
|
||||
${PX4_SOURCE_DIR}/platforms/nuttx/NuttX/include
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
############################################################################
|
||||
#
|
||||
# Copyright (c) 2026 PX4 Development Team. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name PX4 nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
# Builds the px4io firmware that another target embeds in its ROMFS.
|
||||
#
|
||||
# cmake -DPX4_SOURCE_DIR=<dir> -DBOARD_IO=<vendor>_<model>_<label>
|
||||
# [-DPYTHON_EXECUTABLE=<python>] -P px4io_firmware_build.cmake
|
||||
#
|
||||
# NuttX builds inside its source tree, and the nuttx and apps submodules hold
|
||||
# the build state of the target that is being built. The IO firmware therefore
|
||||
# builds against its own copy of those sources:
|
||||
#
|
||||
# build/px4io/<BOARD_IO>/nuttx, apps copy of the tracked NuttX sources
|
||||
# build/px4io/<BOARD_IO>/build cmake build of the BOARD_IO target
|
||||
#
|
||||
# The directory is shared by every target of the checkout that embeds the same
|
||||
# BOARD_IO, and is created again when the NuttX sources change. It runs on every
|
||||
# build of the embedding target, so a build with nothing to do has to stay cheap.
|
||||
|
||||
foreach(required PX4_SOURCE_DIR BOARD_IO)
|
||||
if(NOT ${required})
|
||||
message(FATAL_ERROR "${required} must be set")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
set(nuttx_src_dir ${PX4_SOURCE_DIR}/platforms/nuttx/NuttX)
|
||||
set(io_dir ${PX4_SOURCE_DIR}/build/px4io/${BOARD_IO})
|
||||
set(io_build_dir ${io_dir}/build)
|
||||
set(sources_stamp ${io_dir}/nuttx_sources.stamp)
|
||||
|
||||
# Run a command quietly, and show its output only when it fails.
|
||||
function(px4io_run what)
|
||||
execute_process(
|
||||
COMMAND ${ARGN}
|
||||
RESULT_VARIABLE result
|
||||
OUTPUT_VARIABLE output
|
||||
ERROR_VARIABLE output
|
||||
)
|
||||
if(NOT result EQUAL 0)
|
||||
message(FATAL_ERROR "px4io ${BOARD_IO}: ${what} failed (${result})\n${output}")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(px4io_git result tree)
|
||||
execute_process(
|
||||
COMMAND git -C ${nuttx_src_dir}/${tree} ${ARGN}
|
||||
RESULT_VARIABLE git_result
|
||||
OUTPUT_VARIABLE git_output
|
||||
ERROR_VARIABLE git_error
|
||||
)
|
||||
if(NOT git_result EQUAL 0)
|
||||
message(FATAL_ERROR "px4io ${BOARD_IO}: git ${ARGN} failed in ${tree}\n${git_error}")
|
||||
endif()
|
||||
set(${result} "${git_output}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# The NuttX sources are identified by the submodule commits and by any
|
||||
# uncommitted change to a tracked file, so that NuttX work in progress reaches
|
||||
# the IO firmware too.
|
||||
set(sources_id "")
|
||||
foreach(tree nuttx apps)
|
||||
px4io_git(head ${tree} rev-parse HEAD)
|
||||
px4io_git(changes ${tree} diff --binary HEAD)
|
||||
string(SHA256 changes "${changes}")
|
||||
string(STRIP "${head}" head)
|
||||
string(APPEND sources_id "${tree} ${head} ${changes}\n")
|
||||
endforeach()
|
||||
|
||||
set(previous_sources_id "")
|
||||
if(EXISTS ${sources_stamp})
|
||||
file(READ ${sources_stamp} previous_sources_id)
|
||||
endif()
|
||||
|
||||
if(NOT "${previous_sources_id}" STREQUAL "${sources_id}")
|
||||
message(STATUS "px4io ${BOARD_IO}: copying NuttX sources to ${io_dir}")
|
||||
file(REMOVE_RECURSE ${io_dir})
|
||||
|
||||
foreach(tree nuttx apps)
|
||||
file(MAKE_DIRECTORY ${io_dir}/${tree})
|
||||
px4io_run("copying ${tree}"
|
||||
git -C ${nuttx_src_dir}/${tree} checkout-index --all --force --prefix=${io_dir}/${tree}/)
|
||||
|
||||
# checkout-index copies what is staged, bring the working tree changes along
|
||||
px4io_git(changed_files ${tree} diff --name-only HEAD)
|
||||
string(REPLACE "\n" ";" changed_files "${changed_files}")
|
||||
foreach(changed_file ${changed_files})
|
||||
if(EXISTS ${nuttx_src_dir}/${tree}/${changed_file})
|
||||
px4io_run("copying ${tree}/${changed_file}"
|
||||
${CMAKE_COMMAND} -E copy ${nuttx_src_dir}/${tree}/${changed_file} ${io_dir}/${tree}/${changed_file})
|
||||
else()
|
||||
file(REMOVE ${io_dir}/${tree}/${changed_file})
|
||||
endif()
|
||||
endforeach()
|
||||
endforeach()
|
||||
|
||||
file(WRITE ${sources_stamp} "${sources_id}")
|
||||
endif()
|
||||
|
||||
# Settings meant for the embedding target must not reach the IO firmware.
|
||||
set(io_env ${CMAKE_COMMAND} -E env --unset=PX4_EXTRA_NUTTX_CONFIG)
|
||||
|
||||
if(NOT EXISTS ${io_build_dir}/build.ninja)
|
||||
set(configure_args)
|
||||
if(PYTHON_EXECUTABLE)
|
||||
list(APPEND configure_args -DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE})
|
||||
endif()
|
||||
px4io_run("configure"
|
||||
${io_env} ${CMAKE_COMMAND} -S ${PX4_SOURCE_DIR} -B ${io_build_dir} -G Ninja
|
||||
-DCONFIG=${BOARD_IO} -DPX4_NUTTX_TREE_DIR=${io_dir} ${configure_args})
|
||||
endif()
|
||||
|
||||
px4io_run("build" ${io_env} ${CMAKE_COMMAND} --build ${io_build_dir} --target ${BOARD_IO}.bin)
|
||||
Reference in new issue
Block a user