2018-03-26 12:19:00 -03:00
|
|
|
############################################################################
|
|
|
|
#
|
|
|
|
# Copyright (c) 2018 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.
|
|
|
|
#
|
|
|
|
############################################################################
|
2017-08-29 18:22:05 -03:00
|
|
|
|
|
|
|
message(STATUS "ROMFS: ${config_romfs_root}")
|
|
|
|
|
|
|
|
set(romfs_src_dir ${PX4_SOURCE_DIR}/ROMFS/${config_romfs_root})
|
2018-07-23 18:14:07 -03:00
|
|
|
set(romfs_gen_root_dir ${PX4_BINARY_DIR}/genromfs)
|
|
|
|
|
|
|
|
set_property(GLOBAL PROPERTY PX4_ROMFS_FILES)
|
|
|
|
set_property(GLOBAL PROPERTY PX4_ROMFS_CMAKE_FILES)
|
2018-03-26 12:19:00 -03:00
|
|
|
|
|
|
|
#=============================================================================
|
|
|
|
#
|
|
|
|
# px4_add_romfs_files
|
|
|
|
#
|
|
|
|
# This function builds a list of files to be included in the ROMFS.
|
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
# px4_add_romfs_files(<list of files in current directory to be added to the project>)
|
|
|
|
#
|
|
|
|
# Output:
|
|
|
|
# list config_romfs_files_list populated with a list of ROMFS src files including their full file path.
|
|
|
|
#
|
|
|
|
# Example:
|
|
|
|
# px4_add_module(
|
|
|
|
# <ROMFS_file_1>
|
|
|
|
# <ROMFS_file_2>
|
|
|
|
# <ROMFS_file_3>
|
|
|
|
# )
|
|
|
|
#
|
|
|
|
function(px4_add_romfs_files)
|
2018-07-23 18:14:07 -03:00
|
|
|
set_property(GLOBAL APPEND PROPERTY PX4_ROMFS_CMAKE_FILES ${CMAKE_CURRENT_LIST_FILE})
|
|
|
|
|
2018-03-26 12:19:00 -03:00
|
|
|
foreach(arg IN LISTS ARGN)
|
2019-12-12 13:56:39 -04:00
|
|
|
if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/${arg})
|
|
|
|
message(FATAL_ERROR "${CMAKE_CURRENT_LIST_DIR}/${arg} doesn't exist")
|
|
|
|
endif()
|
2018-07-23 18:14:07 -03:00
|
|
|
set_property(GLOBAL APPEND PROPERTY PX4_ROMFS_FILES ${CMAKE_CURRENT_LIST_DIR}/${arg})
|
2018-03-26 12:19:00 -03:00
|
|
|
endforeach()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# get list of all ROMFS files
|
|
|
|
add_subdirectory(${romfs_src_dir})
|
2017-08-29 18:22:05 -03:00
|
|
|
|
2018-07-24 11:23:35 -03:00
|
|
|
# directory setup
|
2018-12-17 11:59:56 -04:00
|
|
|
# copy all romfs files, process airframes
|
2018-07-23 18:14:07 -03:00
|
|
|
get_property(romfs_cmake_files GLOBAL PROPERTY PX4_ROMFS_CMAKE_FILES)
|
|
|
|
get_property(romfs_copy_files GLOBAL PROPERTY PX4_ROMFS_FILES)
|
2018-08-27 06:35:11 -03:00
|
|
|
get_property(module_config_files GLOBAL PROPERTY PX4_MODULE_CONFIG_FILES)
|
|
|
|
file(GLOB jinja_templates ${PX4_SOURCE_DIR}/Tools/serial/*.jinja)
|
|
|
|
if (px4_constrained_flash_build)
|
|
|
|
set(added_arguments --constrained-flash)
|
|
|
|
endif()
|
2019-04-03 10:56:58 -03:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT
|
|
|
|
${romfs_gen_root_dir}/init.d/rcS
|
|
|
|
${romfs_gen_root_dir}/init.d/rc.serial
|
|
|
|
${romfs_gen_root_dir}/init.d/rc.autostart
|
2019-07-20 15:09:42 -03:00
|
|
|
${romfs_gen_root_dir}/init.d/rc.autostart.post
|
2019-04-03 10:56:58 -03:00
|
|
|
romfs_copy.stamp
|
2018-07-23 18:14:07 -03:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E remove_directory ${romfs_gen_root_dir}
|
2018-08-07 03:11:55 -03:00
|
|
|
# TODO: we should only copy the files in ${romfs_copy_files}
|
2018-07-23 18:14:07 -03:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory ${romfs_src_dir} ${romfs_gen_root_dir}
|
2018-08-07 03:11:55 -03:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E remove_directory ${romfs_gen_root_dir}/init.d-posix
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E remove_directory ${romfs_gen_root_dir}/mixers-sitl
|
2018-12-18 08:48:22 -04:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E remove ${romfs_gen_root_dir}/mixers/CMakeLists.txt
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E remove ${romfs_gen_root_dir}/init.d/CMakeLists.txt
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E remove ${romfs_gen_root_dir}/init.d/airframes/CMakeLists.txt
|
2017-08-29 18:22:05 -03:00
|
|
|
COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/px_process_airframes.py
|
2018-07-23 18:14:07 -03:00
|
|
|
--airframes-path ${romfs_gen_root_dir}/init.d
|
|
|
|
--start-script ${romfs_gen_root_dir}/init.d/rc.autostart
|
2018-11-16 13:52:37 -04:00
|
|
|
--board ${PX4_BOARD}
|
2018-06-07 09:02:47 -03:00
|
|
|
COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/serial/generate_config.py
|
2018-08-27 06:35:11 -03:00
|
|
|
--rc-dir ${romfs_gen_root_dir}/init.d
|
|
|
|
--serial-ports ${board_serial_ports} ${added_arguments}
|
|
|
|
--config-files ${module_config_files} #--verbose
|
2019-04-03 10:56:58 -03:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E touch romfs_copy.stamp
|
2018-07-23 18:14:07 -03:00
|
|
|
DEPENDS
|
2018-08-27 06:35:11 -03:00
|
|
|
${jinja_templates}
|
|
|
|
${module_config_files}
|
2018-07-24 11:23:35 -03:00
|
|
|
${romfs_cmake_files}
|
|
|
|
${romfs_copy_files}
|
|
|
|
${PX4_SOURCE_DIR}/Tools/px_process_airframes.py
|
2019-07-20 14:31:42 -03:00
|
|
|
${PX4_SOURCE_DIR}/Tools/px4airframes/markdownout.py
|
|
|
|
${PX4_SOURCE_DIR}/Tools/px4airframes/rcout.py
|
|
|
|
${PX4_SOURCE_DIR}/Tools/px4airframes/srcparser.py
|
|
|
|
${PX4_SOURCE_DIR}/Tools/px4airframes/srcscanner.py
|
|
|
|
${PX4_SOURCE_DIR}/Tools/px4airframes/xmlout.py
|
2018-06-07 09:02:47 -03:00
|
|
|
${PX4_SOURCE_DIR}/Tools/serial/generate_config.py
|
2018-12-17 11:59:56 -04:00
|
|
|
COMMENT "ROMFS: copying, generating airframes"
|
2017-08-29 18:22:05 -03:00
|
|
|
)
|
2018-07-23 18:14:07 -03:00
|
|
|
|
|
|
|
# copy extras into ROMFS
|
|
|
|
set(extras_dependencies)
|
2018-11-16 13:52:37 -04:00
|
|
|
|
2019-11-14 15:47:42 -04:00
|
|
|
if(config_bl_file)
|
|
|
|
file(MAKE_DIRECTORY ${PX4_BINARY_DIR}/romfs_extras)
|
|
|
|
configure_file(${config_bl_file} ${PX4_BINARY_DIR}/romfs_extras COPYONLY)
|
|
|
|
|
|
|
|
list(APPEND extras_dependencies
|
|
|
|
${config_bl_file}
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2018-02-09 13:57:34 -04:00
|
|
|
# copy px4io binary if configured
|
2018-11-16 13:52:37 -04:00
|
|
|
if(config_io_board)
|
2018-07-23 18:14:07 -03:00
|
|
|
list(APPEND extras_dependencies
|
2018-02-09 13:57:34 -04:00
|
|
|
copy_px4io_bin
|
|
|
|
${fw_io_bin}
|
2019-11-14 15:47:42 -04:00
|
|
|
)
|
2018-02-09 13:57:34 -04:00
|
|
|
endif()
|
|
|
|
|
2019-11-14 15:47:42 -04:00
|
|
|
if(config_build_bootloader)
|
2018-09-14 04:53:23 -03:00
|
|
|
list(APPEND extras_dependencies
|
2019-11-14 15:47:42 -04:00
|
|
|
copy_bootloader_bin
|
|
|
|
${bootloader_bin}
|
|
|
|
)
|
2018-09-14 04:53:23 -03:00
|
|
|
endif()
|
|
|
|
|
2018-12-14 13:36:32 -04:00
|
|
|
set(OPTIONAL_BOARD_RC)
|
|
|
|
list(APPEND OPTIONAL_BOARD_RC
|
|
|
|
rc.board_defaults
|
|
|
|
rc.board_sensors
|
|
|
|
rc.board_extras
|
2019-09-19 05:47:32 -03:00
|
|
|
rc.board_mavlink
|
2018-12-14 13:36:32 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
foreach(board_rc_file ${OPTIONAL_BOARD_RC})
|
|
|
|
|
|
|
|
if(EXISTS "${PX4_BOARD_DIR}/init/${board_rc_file}")
|
|
|
|
message(STATUS "ROMFS: Adding ${board_rc_file}")
|
|
|
|
|
2019-04-03 10:56:58 -03:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT
|
|
|
|
${romfs_gen_root_dir}/init.d/${board_rc_file}
|
|
|
|
${board_rc_file}.stamp
|
2019-11-09 16:28:07 -04:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PX4_BOARD_DIR}/init/${board_rc_file} ${romfs_gen_root_dir}/init.d/${board_rc_file}
|
2019-04-03 10:56:58 -03:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E touch ${board_rc_file}.stamp
|
2018-12-14 13:36:32 -04:00
|
|
|
DEPENDS
|
|
|
|
${PX4_BOARD_DIR}/init/${board_rc_file}
|
2019-04-03 10:56:58 -03:00
|
|
|
romfs_copy.stamp
|
2018-12-14 13:36:32 -04:00
|
|
|
COMMENT "ROMFS: copying ${board_rc_file}"
|
2018-11-30 14:46:41 -04:00
|
|
|
)
|
|
|
|
|
2018-12-14 13:36:32 -04:00
|
|
|
list(APPEND extras_dependencies
|
2019-04-03 10:56:58 -03:00
|
|
|
${board_rc_file}.stamp
|
2018-12-14 13:36:32 -04:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
endforeach()
|
2018-11-30 14:46:41 -04:00
|
|
|
|
2018-07-23 18:14:07 -03:00
|
|
|
add_custom_command(OUTPUT romfs_extras.stamp
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${romfs_gen_root_dir}/extras/
|
2018-09-03 21:27:32 -03:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${PX4_BINARY_DIR}/romfs_extras/
|
2018-07-23 18:14:07 -03:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PX4_BINARY_DIR}/romfs_extras/ ${romfs_gen_root_dir}/extras/
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E touch romfs_extras.stamp
|
|
|
|
DEPENDS
|
2019-04-03 10:56:58 -03:00
|
|
|
romfs_copy.stamp
|
2018-07-23 18:14:07 -03:00
|
|
|
${extras_dependencies}
|
|
|
|
COMMENT "ROMFS: copying extras"
|
|
|
|
)
|
|
|
|
|
2019-01-29 15:38:32 -04:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT romfs_pruned.stamp
|
|
|
|
COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/px_romfs_pruner.py --folder ${romfs_gen_root_dir} --board ${PX4_BOARD}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E touch romfs_pruned.stamp
|
2018-12-17 11:59:56 -04:00
|
|
|
DEPENDS
|
2019-04-03 10:56:58 -03:00
|
|
|
romfs_copy.stamp
|
2018-12-17 11:59:56 -04:00
|
|
|
romfs_extras.stamp
|
|
|
|
${PX4_SOURCE_DIR}/Tools/px_romfs_pruner.py
|
|
|
|
COMMENT "ROMFS: pruning"
|
|
|
|
)
|
|
|
|
|
2018-12-10 17:55:12 -04:00
|
|
|
if("${CONFIG_FS_CROMFS}" STREQUAL "y")
|
|
|
|
add_custom_command(
|
2019-01-29 15:38:32 -04:00
|
|
|
OUTPUT ${CMAKE_BINARY_DIR}/gencromfs
|
|
|
|
COMMAND make --no-print-directory --silent -f Makefile.host gencromfs
|
2019-11-09 16:28:07 -04:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different gencromfs ${CMAKE_BINARY_DIR}/gencromfs
|
2018-12-10 17:55:12 -04:00
|
|
|
DEPENDS ${PX4_SOURCE_DIR}/platforms/nuttx/NuttX/nuttx/tools/gencromfs.c
|
|
|
|
WORKING_DIRECTORY ${NUTTX_DIR}/tools
|
2019-04-03 10:56:58 -03:00
|
|
|
)
|
2017-08-29 18:22:05 -03:00
|
|
|
|
2018-11-29 19:05:51 -04:00
|
|
|
# create nsh_romfsimg.c
|
|
|
|
add_custom_command(OUTPUT nsh_romfsimg.c
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E remove -f nsh_romfsimg.c
|
2019-01-29 15:38:32 -04:00
|
|
|
COMMAND ${CMAKE_BINARY_DIR}/gencromfs ${romfs_gen_root_dir} nsh_romfsimg.c
|
2018-11-29 19:05:51 -04:00
|
|
|
DEPENDS
|
2018-12-10 17:55:12 -04:00
|
|
|
${CMAKE_BINARY_DIR}/gencromfs
|
2018-11-29 19:05:51 -04:00
|
|
|
romfs_pruned.stamp
|
|
|
|
COMMENT "ROMFS: generating image"
|
2019-04-03 10:56:58 -03:00
|
|
|
)
|
2018-11-29 19:05:51 -04:00
|
|
|
|
|
|
|
else()
|
2018-12-10 17:55:12 -04:00
|
|
|
# create romfs.img
|
2018-11-29 19:05:51 -04:00
|
|
|
find_program(GENROMFS genromfs)
|
|
|
|
if(NOT GENROMFS)
|
2019-04-03 10:56:58 -03:00
|
|
|
message(FATAL_ERROR "genromfs not found")
|
2018-11-29 19:05:51 -04:00
|
|
|
endif()
|
2019-04-03 10:56:58 -03:00
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT
|
|
|
|
romfs.img
|
|
|
|
romfs.txt
|
2018-11-29 19:05:51 -04:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E remove -f romfs.img romfs.txt
|
|
|
|
COMMAND ${GENROMFS} -f romfs.img -d ${romfs_gen_root_dir} -V "NSHInitVol" -v > romfs.txt 2>&1
|
2019-01-29 15:38:32 -04:00
|
|
|
DEPENDS romfs_pruned.stamp
|
2018-11-29 19:05:51 -04:00
|
|
|
COMMENT "ROMFS: generating image"
|
2019-04-03 10:56:58 -03:00
|
|
|
)
|
2018-11-29 19:05:51 -04:00
|
|
|
|
2019-04-03 10:56:58 -03:00
|
|
|
|
|
|
|
# create nsh_romfsimg.c
|
|
|
|
find_program(XXD xxd)
|
|
|
|
if(NOT XXD)
|
|
|
|
message(FATAL_ERROR "xxd not found")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
find_program(SED sed)
|
|
|
|
if(NOT SED)
|
|
|
|
message(FATAL_ERROR "sed not found")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
add_custom_command(OUTPUT nsh_romfsimg.c
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E remove -f nsh_romfsimg.c
|
|
|
|
COMMAND ${XXD} -i romfs.img nsh_romfsimg.c
|
|
|
|
COMMAND ${SED} 's/unsigned/const unsigned/g' nsh_romfsimg.c > nsh_romfsimg.c.tmp && ${CMAKE_COMMAND} -E rename nsh_romfsimg.c.tmp nsh_romfsimg.c
|
|
|
|
DEPENDS romfs.img
|
|
|
|
)
|
2018-07-23 18:14:07 -03:00
|
|
|
endif()
|
2018-11-29 19:05:51 -04:00
|
|
|
|
2017-08-29 18:22:05 -03:00
|
|
|
|
|
|
|
add_library(romfs STATIC nsh_romfsimg.c)
|
2018-02-09 13:57:34 -04:00
|
|
|
add_dependencies(romfs prebuild_targets)
|
2017-08-29 18:22:05 -03:00
|
|
|
set_target_properties(romfs PROPERTIES LINKER_LANGUAGE C)
|
2018-08-25 13:04:12 -03:00
|
|
|
|
|
|
|
|
|
|
|
# shellcheck
|
|
|
|
find_program(SHELLCHECK_PATH shellcheck)
|
|
|
|
|
|
|
|
if(SHELLCHECK_PATH)
|
2018-11-30 22:01:29 -04:00
|
|
|
|
2018-09-27 06:11:12 -03:00
|
|
|
# TODO: fix SC2086, SC2166
|
2018-08-25 13:04:12 -03:00
|
|
|
add_custom_target(shellcheck
|
|
|
|
COMMAND ${SHELLCHECK_PATH} --shell=sh
|
|
|
|
--exclude=SC2121 # SC2121: To assign a variable, use just 'var=value'
|
|
|
|
--exclude=SC2086 # SC2086: Double quote to prevent globbing and word splitting.
|
|
|
|
--exclude=SC2166 # SC2166: Prefer [ p ] || [ q ] as [ p -o q ] is not well defined.
|
2018-09-05 12:03:58 -03:00
|
|
|
--exclude=SC2154 # SC2154: <var> is referenced but not assigned (NuttX uses different asssignment)
|
2018-12-03 09:52:45 -04:00
|
|
|
--exclude=SC2164 # SC2164: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
|
2019-07-09 13:45:18 -03:00
|
|
|
--exclude=SC2181 # SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.
|
2018-11-30 22:01:29 -04:00
|
|
|
`find ${romfs_gen_root_dir}/init.d -type f`
|
2018-08-25 13:04:12 -03:00
|
|
|
DEPENDS ${romfs_gen_root_dir}/init.d/rc.autostart
|
|
|
|
WORKING_DIRECTORY ${romfs_gen_root_dir}
|
|
|
|
USES_TERMINAL
|
2019-04-03 10:56:58 -03:00
|
|
|
)
|
2018-08-25 13:04:12 -03:00
|
|
|
endif()
|