diff --git a/CMakeLists.txt b/CMakeLists.txt index 95cb91398a..918e5bd875 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -277,10 +277,12 @@ foreach(module ${config_module_list}) endforeach() add_subdirectory(src/firmware/${OS}) + if (config_io_board) add_subdirectory(src/modules/px4iofirmware) endif() + #============================================================================= # generate git version # diff --git a/cmake/common/px4_base.cmake b/cmake/common/px4_base.cmake index 1d3f5b05a3..54ab915bfd 100644 --- a/cmake/common/px4_base.cmake +++ b/cmake/common/px4_base.cmake @@ -735,4 +735,54 @@ function(px4_generate_parameters) set(${OUT} ${generated_files} PARENT_SCOPE) endfunction() +#============================================================================= +# +# px4_copy_tracked +# +# Copy files to a directory and keep track of dependencies. +# +# Usage: +# px4_copy_tracked(OUT FILES DIR ) +# +# Input: +# FILES : the source files +# DEST : the directory to copy files to +# RELATIVE : relative directory for source files +# +# Output: +# OUT : the copied files +# +# Example: +# px4_copy_tracked(OUT copied_files FILES src_files DEST path RELATIVE path_rel) +# +function(px4_copy_tracked) + px4_parse_function_args( + NAME px4_copy_tracked + ONE_VALUE DEST OUT RELATIVE + MULTI_VALUE FILES + REQUIRED DEST OUT FILES + ARGN ${ARGN}) + set(files) + # before build, make sure dest directory exists + execute_process( + COMMAND cmake -E make_directory ${DEST}) + # create rule to copy each file and set dependency as source file + set(_files_out) + foreach(_file ${FILES}) + if (RELATIVE) + file(RELATIVE_PATH _file_path ${RELATIVE} ${_file}) + else() + set(_file_path ${_file}) + endif() + set(_dest_file ${DEST}/${_file_path}) + #message(STATUS "copy ${_file} -> ${_dest_file}") + add_custom_command(OUTPUT ${_dest_file} + COMMAND cmake -E copy ${_file} ${_dest_file} + DEPENDS ${_file}) + list(APPEND _files_out ${_dest_file}) + endforeach() + set(${OUT} ${_files_out} PARENT_SCOPE) +endfunction() + + # vim: set noet fenc=utf-8 ff=unix nowrap: diff --git a/cmake/nuttx/px4_impl_nuttx.cmake b/cmake/nuttx/px4_impl_nuttx.cmake index 3145de1cf9..b138e01e40 100644 --- a/cmake/nuttx/px4_impl_nuttx.cmake +++ b/cmake/nuttx/px4_impl_nuttx.cmake @@ -258,6 +258,41 @@ function(px4_nuttx_add_export) endfunction() +#============================================================================= +# +# px4_nuttx_create_bin +# +# The functions generates a bin image for nuttx. +# +# Usage: +# px4_nuttx_create_bin(BIN EXE ) +# +# Input: +# EXE : the exe file +# +# Output: +# OUT : the binary output file +# +# Example: +# px4_nuttx_create_bin(OUT my_exe.bin EXE my_exe) +# +function(px4_nuttx_create_bin) + + px4_parse_function_args( + NAME px4_nuttx_create_bin + ONE_VALUE EXE OUT + REQUIRED EXE OUT + ARGN ${ARGN}) + + add_custom_command(OUTPUT ${OUT} + COMMAND ${OBJCOPY} -O binary ${EXE} ${EXE}.bin + DEPENDS ${EXE}) + + set(${OUT} ${${OUT}} PARENT_SCOPE) + +endfunction() + + #============================================================================= # # px4_nuttx_generate_romfs @@ -265,10 +300,14 @@ endfunction() # The functions generates the ROMFS filesystem for nuttx. # # Usage: -# px4_nuttx_generate_romfs(OUT ROOT ) +# px4_nuttx_generate_romfs( +# OUT +# ROOT +# EXTRAS ) # # Input: # ROOT : the root of the ROMFS +# EXTRAS : list of extra files # # Output: # OUT : the generated ROMFS @@ -281,42 +320,50 @@ function(px4_nuttx_generate_romfs) px4_parse_function_args( NAME px4_nuttx_generate_romfs ONE_VALUE OUT ROOT + MULTI_VALUE EXTRAS REQUIRED OUT ROOT ARGN ${ARGN}) - file(GLOB_RECURSE romfs_files ${ROOT}/*) - set(romfs_temp_dir ${CMAKE_BINARY_DIR}/${ROOT}) + set(romfs_temp_dir ${CMAKE_BINARY_DIR}/tmp/${ROOT}) + set(romfs_dest_dir ${CMAKE_BINARY_DIR}/${ROOT}) set(romfs_src_dir ${CMAKE_SOURCE_DIR}/${ROOT}) - set(romfs_autostart ${CMAKE_SOURCE_DIR}/Tools/px_process_airframes.py) set(romfs_pruner ${CMAKE_SOURCE_DIR}/Tools/px_romfs_pruner.py) set(bin_to_obj ${CMAKE_SOURCE_DIR}/cmake/nuttx/bin_to_obj.py) - #message(STATUS "temp_dir: ${romfs_temp_dir}") - #message(STATUS "src_dir: ${romfs_src_dir}") + file(GLOB_RECURSE romfs_src_files ${romfs_src_dir} ${romfs_src_dir}/*) - add_custom_command(OUTPUT rc.autostart - COMMAND ${PYTHON_EXECUTABLE} ${romfs_autostart} - -a ${romfs_src_dir}/init.d - -s rc.autostart + px4_copy_tracked(OUT romfs_files + FILES ${romfs_src_files} + DEST ${romfs_dest_dir} + RELATIVE ${romfs_src_dir} ) + if (EXTRAS) + px4_copy_tracked(OUT extra_files + FILES ${EXTRAS} + DEST ${romfs_dest_dir}/extras + RELATIVE ${romfs_src_dir} + ) + list(APPEND romfs_files ${extra_files}) + endif() - set(io_bin_image - ${CMAKE_BINARY_DIR}/src/modules/px4iofirmware/${config_io_board}_${LABEL}.bin) + add_custom_command(OUTPUT ${romfs_dest_dir}/init.d/rc.autostart + COMMAND ${PYTHON_EXECUTABLE} ${romfs_autostart} + -a ${romfs_src_dir}/init.d + -s ${romfs_dest_dir}/init.d/rc.autostart + ) + list(APPEND romfs_files ${romfs_dest_dir}/init.d/rc.autostart) add_custom_command(OUTPUT romfs.bin COMMAND cmake -E remove_directory ${romfs_temp_dir} - COMMAND cmake -E copy_directory ${romfs_src_dir} ${romfs_temp_dir} - COMMAND cmake -E copy rc.autostart ${romfs_temp_dir}/init.d - COMMAND cmake -E make_directory ${romfs_temp_dir}/extras - COMMAND cmake -E copy ${io_bin_image} ${romfs_temp_dir}/extras - #TODO add romfs cleanup of temp file .~, .swp etc + COMMAND cmake -E copy_directory ${romfs_dest_dir} ${romfs_temp_dir} COMMAND ${PYTHON_EXECUTABLE} ${romfs_pruner} --folder ${romfs_temp_dir} COMMAND ${GENROMFS} -f ${CMAKE_CURRENT_BINARY_DIR}/romfs.bin -d ${romfs_temp_dir} -V "NSHInitVol" - DEPENDS ${romfs_files} rc.autostart ${io_bin_image} + COMMAND cmake -E remove_directory ${romfs_temp_dir} + DEPENDS ${romfs_files} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) diff --git a/src/modules/px4iofirmware/CMakeLists.txt b/src/modules/px4iofirmware/CMakeLists.txt index 06313da061..9feed84674 100644 --- a/src/modules/px4iofirmware/CMakeLists.txt +++ b/src/modules/px4iofirmware/CMakeLists.txt @@ -123,18 +123,14 @@ set(main_link_flags px4_join(OUT main_link_flags LIST ${main_link_flags} GLUE " ") set_target_properties(${fw_io_name} PROPERTIES LINK_FLAGS ${main_link_flags}) -set(io_fw_file ${CMAKE_CURRENT_BINARY_DIR}/${fw-io_name}.px4) - target_link_libraries(${fw_io_name} -Wl,--start-group apps nuttx nosys m gcc ${config_io_extra_libs} -Wl,--end-group) -px4_nuttx_add_firmware(OUT ${io_fw_file} - BOARD ${config_io_board} - EXE ${CMAKE_CURRENT_BINARY_DIR}/${fw_io_name} - ${config_firmware_options} +px4_nuttx_create_bin(OUT ${fw_io_name}.bin + EXE ${fw_io_name} ) # vim: set noet ft=cmake fenc=utf-8 ff=unix :