diff --git a/cmake/common/px4_base.cmake b/cmake/common/px4_base.cmake index 7ad8254d8a..b08565971c 100644 --- a/cmake/common/px4_base.cmake +++ b/cmake/common/px4_base.cmake @@ -101,9 +101,14 @@ include(CMakeParseArguments) function(px4_parse_function_args) cmake_parse_arguments(IN "" "NAME" "OPTIONS;ONE_VALUE;MULTI_VALUE;REQUIRED;ARGN" "${ARGN}") cmake_parse_arguments(OUT "${IN_OPTIONS}" "${IN_ONE_VALUE}" "${IN_MULTI_VALUE}" "${IN_ARGN}") + if (OUT_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "${IN_NAME}: unparsed ${OUT_UNPARSED_ARGUMENTS}") + endif() foreach(arg ${IN_REQUIRED}) if (NOT OUT_${arg}) - message(FATAL_ERROR "${IN_NAME} requires argument ${arg}\nARGN: ${IN_ARGN}") + if (NOT "${OUT_${arg}}" STREQUAL "0") + message(FATAL_ERROR "${IN_NAME} requires argument ${arg}\nARGN: ${IN_ARGN}") + endif() endif() endforeach() foreach(arg ${IN_OPTIONS} ${IN_ONE_VALUE} ${IN_MULTI_VALUE}) @@ -143,6 +148,9 @@ function(px4_add_git_submodule) ) add_custom_target(${TARGET} WORKING_DIRECTORY ${PX4_SOURCE_DIR} +# todo:Not have 2 list of submodues one (see the end of Tools/check_submodules.sh and Firmware/CMakeLists.txt) +# using the list of submodules from the CMake file to drive the test +# COMMAND Tools/check_submodules.sh ${PATH} DEPENDS ${PX4_BINARY_DIR}/git_init_${NAME}.stamp ) endfunction() @@ -240,7 +248,7 @@ endfunction() # STACK : deprecated use stack main instead # STACK_MAIN : size of stack for main function # STACK_MAX : maximum stack size of any frame -# COMPILE_FLAGS : compile flags +# COMPILE_FLAGS : compile flags # LINK_FLAGS : link flags # SRCS : source files # INCLUDES : include directories @@ -375,6 +383,8 @@ function(px4_generate_messages) MULTI_VALUE MSG_FILES DEPENDS INCLUDES REQUIRED MSG_FILES OS TARGET ARGN ${ARGN}) + if("${config_nuttx_config}" STREQUAL "bootloader") + else() set(QUIET) if(NOT VERBOSE) set(QUIET "-q") @@ -463,7 +473,7 @@ function(px4_generate_messages) ${msg_multi_files_out} ${msg_files_out} ) - + endif() endfunction() #============================================================================= @@ -1043,7 +1053,7 @@ function(px4_generate_airframes_xml) set(process_airframes ${PX4_SOURCE_DIR}/Tools/px_process_airframes.py) add_custom_command(OUTPUT ${OUT} COMMAND ${PYTHON_EXECUTABLE} ${process_airframes} - -a ${PX4_SOURCE_DIR}/ROMFS/px4fmu_common/init.d + -a ${PX4_SOURCE_DIR}/ROMFS/${config_romfs_root}/init.d --board CONFIG_ARCH_BOARD_${BOARD} --xml ) set(${OUT} ${${OUT}} PARENT_SCOPE) @@ -1098,6 +1108,34 @@ function(px4_copy_tracked) set(${OUT} ${_files_out} PARENT_SCOPE) endfunction() +#============================================================================= +# +# px4_share_subdirectory +# +# This function simplifes sharing a sub directory +# +# Usage: +# px4_share_subdirectory(RELDIR ARGS ) +# +# Input: +# RELDIR : The relitive path to share. +# ARGS : Any optional arguments to pass to add_subdirectory +# +# Output: +# : None +# +# Example: +# px4_share_subdirectory(RELDIR ../uavcan/libuavcan ARGS EXCLUDE_FROM_ALL) +# +function(px4_share_subdirectory) + px4_parse_function_args( + NAME px4_share_subdirectory + ONE_VALUE OUT RELDIR + MULTI_VALUE ARGS + REQUIRED RELDIR + ARGN ${ARGN}) + add_subdirectory(${RELDIR} ${RELDIR}/${RELDIR} ${ARGS}) +endfunction() #============================================================================= # # px4_strip_optimization diff --git a/cmake/nuttx/px4_impl_nuttx.cmake b/cmake/nuttx/px4_impl_nuttx.cmake index 562d97f982..16d4a9813b 100644 --- a/cmake/nuttx/px4_impl_nuttx.cmake +++ b/cmake/nuttx/px4_impl_nuttx.cmake @@ -38,6 +38,7 @@ # OS Specific Functions # # * px4_nuttx_add_firmware +# * px4_nuttx_make_uavcan_bootloadable # * px4_nuttx_generate_builtin_commands # * px4_nuttx_add_export # * px4_nuttx_add_romfs @@ -93,7 +94,7 @@ function(px4_nuttx_add_firmware) ) endif() - add_custom_command(OUTPUT ${OUT} + add_custom_command(OUTPUT ${OUT} ${EXE}.bin COMMAND ${OBJCOPY} -O binary ${EXE} ${EXE}.bin COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/px_mkfw.py --prototype ${PX4_SOURCE_DIR}/Images/${BOARD}.prototype @@ -105,6 +106,70 @@ function(px4_nuttx_add_firmware) add_custom_target(build_firmware_${BOARD} ALL DEPENDS ${OUT}) endfunction() +#============================================================================= +# +# px4_nuttx_make_uavcan_bootloadable +# +# This function adds a uavcan boot loadable target. +# +# Usage: +# px4_nuttx_make_uavcan_bootloadable( +# BOARD +# BIN ) +# HWNAME +# HW_MAJOR +# HW_MINOR +# SW_MAJOR +# SW_MINOR ) +# +# Input: +# BOARD : the board +# BIN : the bin file to generate the bootloadable image from +# HWNAME : the uavcan name +# HW_MAJOR : the major hardware revision +# HW_MINOR : the minor hardware revision +# SW_MAJOR : the major software revision +# SW_MINOR : the minor software revision +# +# Output: +# OUT : None +# +# Example: +# px4_nuttx_make_uavcan_bootloadable( +# BOARD ${BOARD} +# BIN ${CMAKE_CURRENT_BINARY_DIR}/firmware_nuttx +# HWNAME ${uavcanblid_name} +# HW_MAJOR ${uavcanblid_hw_version_major} +# HW_MINOR ${uavcanblid_hw_version_minor} +# SW_MAJOR ${uavcanblid_sw_version_major} +# SW_MINOR ${uavcanblid_sw_version_minor} +# ) +# +function(px4_nuttx_make_uavcan_bootloadable) + px4_parse_function_args( + NAME px4_nuttx_make_uavcan_bootloadable + ONE_VALUE BOARD BIN HWNAME HW_MAJOR HW_MINOR SW_MAJOR SW_MINOR + REQUIRED BOARD BIN HWNAME HW_MAJOR HW_MINOR SW_MAJOR SW_MINOR + ARGN ${ARGN}) + string(REPLACE "\"" "" HWNAME ${HWNAME}) + execute_process( + COMMAND git rev-list HEAD --max-count=1 --abbrev=8 --abbrev-commit + OUTPUT_VARIABLE uavcanbl_git_desc + OUTPUT_STRIP_TRAILING_WHITESPACE + WORKING_DIRECTORY ${PX4_SOURCE_DIR} + ) + if ("${uavcanbl_git_desc}" STREQUAL "") + set(uavcanbl_git_desc ffffffff) + endif() + set(uavcan_bl_imange_name ${HWNAME}-${HW_MAJOR}.${HW_MINOR}-${SW_MAJOR}.${SW_MINOR}.${uavcanbl_git_desc}.uavcan.bin) + message(STATUS "Generating UAVCAN Bootable as ${uavcan_bl_imange_name}") + add_custom_command(OUTPUT ${uavcan_bl_imange_name} + COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/make_can_boot_descriptor.py + -v --use-git-hash ${BIN} ${uavcan_bl_imange_name} + DEPENDS ${BIN}) + add_custom_target(build_uavcan_bl_${BOARD} ALL DEPENDS ${uavcan_bl_imange_name}) +endfunction() + #============================================================================= # # px4_nuttx_generate_builtin_commands @@ -185,60 +250,75 @@ function(px4_nuttx_add_export) set(nuttx_src ${PX4_BINARY_DIR}/${CONFIG}/NuttX) + # all patches + file(GLOB nuttx_patches ${PX4_SOURCE_DIR}/nuttx-patches/*.patch) + + # copy + file(GLOB_RECURSE nuttx_all_files ${PX4_SOURCE_DIR}/NuttX/*) + add_custom_command(OUTPUT nuttx_copy_${CONFIG}.stamp + COMMAND ${MKDIR} -p ${nuttx_src} + COMMAND rsync -a --delete --exclude=.git ${PX4_SOURCE_DIR}/NuttX/ ${nuttx_src}/ + COMMAND ${TOUCH} nuttx_copy_${CONFIG}.stamp + DEPENDS ${DEPENDS} ${nuttx_patches} ${nuttx_all_files} + COMMENT "Copying NuttX for ${CONFIG} with ${config_nuttx_config}") + # patch - add_custom_target(__nuttx_patch_${CONFIG}) - file(GLOB nuttx_patches RELATIVE ${PX4_SOURCE_DIR} - ${PX4_SOURCE_DIR}/nuttx-patches/*.patch) + add_custom_target(nuttx_patch_${CONFIG}) foreach(patch ${nuttx_patches}) - string(REPLACE "/" "_" patch_name "${patch}-${CONFIG}") - message(STATUS "nuttx-patch: ${patch}") - add_custom_command(OUTPUT nuttx_patch_${patch_name}.stamp - COMMAND ${PATCH} -p0 -N < ${PX4_SOURCE_DIR}/${patch} - COMMAND ${TOUCH} nuttx_patch_${patch_name}.stamp - DEPENDS ${DEPENDS} - ) - add_custom_target(nuttx_patch_${patch_name} - DEPENDS nuttx_patch_${patch_name}.stamp) - add_dependencies(nuttx_patch nuttx_patch_${patch_name}) + get_filename_component(patch_file_name ${patch} NAME) + message(STATUS "NuttX patch: nuttx-patches/${patch_file_name}") + string(REPLACE "/" "_" patch_name "nuttx_patch_${patch_file_name}-${CONFIG}") + set(patch_stamp ${nuttx_src}/${patch_name}.stamp) + + add_custom_command(OUTPUT ${patch_stamp} + COMMAND ${PATCH} -d ${nuttx_src} -s -p1 -N < ${patch} + COMMAND ${TOUCH} ${patch_stamp} + DEPENDS ${DEPENDS} nuttx_copy_${CONFIG}.stamp ${patch} + COMMENT "Applying ${patch}") + + add_custom_target(${patch_name} DEPENDS ${patch_stamp}) + add_dependencies(nuttx_patch_${CONFIG} ${patch_name}) endforeach() - # Read defconfig to see if CONFIG_ARMV7M_STACKCHECK is yes + # Read defconfig to see if CONFIG_ARMV7M_STACKCHECK is yes # note: CONFIG will be BOARD in the future evaluation of ${hw_stack_check_${CONFIG} - file(STRINGS "${PX4_SOURCE_DIR}/nuttx-configs/${CONFIG}/nsh/defconfig" + file(STRINGS "${PX4_SOURCE_DIR}/nuttx-configs/${CONFIG}/${config_nuttx_config}/defconfig" hw_stack_check_${CONFIG} REGEX "CONFIG_ARMV7M_STACKCHECK=y" ) if ("${hw_stack_check_${CONFIG}}" STREQUAL "CONFIG_ARMV7M_STACKCHECK=y") - set(config_nuttx_hw_stack_check_${CONFIG} y CACHE INTERNAL "") + set(config_nuttx_hw_stack_check_${CONFIG} y CACHE INTERNAL "" FORCE) endif() - # copy and export - file(RELATIVE_PATH nuttx_cp_src ${PX4_BINARY_DIR} ${PX4_SOURCE_DIR}/NuttX) + # configure file(GLOB_RECURSE config_files ${PX4_SOURCE_DIR}/nuttx-configs/${CONFIG}/*) - add_custom_command(OUTPUT ${PX4_BINARY_DIR}/${CONFIG}.export - COMMAND ${MKDIR} -p ${nuttx_src} - COMMAND rsync -a --delete --exclude=.git ${nuttx_cp_src}/ ${CONFIG}/NuttX/ - #COMMAND ${ECHO} Configuring NuttX for ${CONFIG} - COMMAND ${MAKE} --no-print-directory -C${nuttx_src}/nuttx -r --quiet distclean - COMMAND ${CP} -r ${PX4_SOURCE_DIR}/nuttx-configs/PX4_Warnings.mk ${nuttx_src}/nuttx/ - COMMAND ${CP} -r ${PX4_SOURCE_DIR}/nuttx-configs/${CONFIG} ${nuttx_src}/nuttx/configs - COMMAND cd ${nuttx_src}/nuttx/tools && ./configure.sh ${CONFIG}/nsh && cd .. - #COMMAND ${ECHO} Exporting NuttX for ${CONFIG} - COMMAND ${MAKE} --no-print-directory --quiet -C ${nuttx_src}/nuttx -j${THREADS} -r CONFIG_ARCH_BOARD=${CONFIG} export > nuttx_build.log - COMMAND ${CP} -r ${nuttx_src}/nuttx/nuttx-export.zip ${PX4_BINARY_DIR}/${CONFIG}.export - DEPENDS ${config_files} "${PX4_SOURCE_DIR}/nuttx-configs/${CONFIG}/nsh/defconfig" ${DEPENDS} + add_custom_command(OUTPUT ${nuttx_src}/nuttx/.config + COMMAND ${CP} -rp ${PX4_SOURCE_DIR}/nuttx-configs/*.mk ${nuttx_src}/nuttx/ + COMMAND ${CP} -rp ${PX4_SOURCE_DIR}/nuttx-configs/${CONFIG} ${nuttx_src}/nuttx/configs + COMMAND cd ${nuttx_src}/nuttx/tools && ./configure.sh ${CONFIG}/${config_nuttx_config} + DEPENDS ${DEPENDS} nuttx_patch_${CONFIG} ${config_files} WORKING_DIRECTORY ${PX4_BINARY_DIR} - COMMENT "Building NuttX for ${CONFIG}") + COMMENT "Configuring NuttX for ${CONFIG} with ${config_nuttx_config}") - # extract - add_custom_command(OUTPUT nuttx_export_${CONFIG}.stamp - COMMAND ${RM} -rf ${nuttx_src}/nuttx-export - COMMAND ${UNZIP} -q ${PX4_BINARY_DIR}/${CONFIG}.export -d ${nuttx_src} - COMMAND ${TOUCH} nuttx_export_${CONFIG}.stamp - DEPENDS ${DEPENDS} ${PX4_BINARY_DIR}/${CONFIG}.export) + # manual reconfigure helper + add_custom_target(reconfigure_nuttx_${CONFIG} + COMMAND cd ${nuttx_src}/nuttx + COMMAND ${MAKE} -C ${nuttx_src}/nuttx CONFIG_ARCH_BOARD=${CONFIG} oldconfig + COMMAND ${MAKE} -C ${nuttx_src}/nuttx CONFIG_ARCH_BOARD=${CONFIG} menuconfig + COMMAND ${CP} ${nuttx_src}/nuttx/.config ${PX4_SOURCE_DIR}/nuttx-configs/${CONFIG}/${config_nuttx_config}/defconfig + DEPENDS ${nuttx_src}/nuttx/.config + COMMENT "Reconfiguring NuttX for ${CONFIG} with ${config_nuttx_config}" + USES_TERMINAL) - add_custom_target(${OUT} - DEPENDS nuttx_export_${CONFIG}.stamp) + # build and export + add_custom_command(OUTPUT ${nuttx_src}/nuttx/nuttx-export/include/nuttx/config.h + COMMAND ${RM} -rf ${nuttx_src}/nuttx/nuttx-export + COMMAND ${MAKE} --no-print-directory --quiet -C ${nuttx_src}/nuttx -r CONFIG_ARCH_BOARD=${CONFIG} export > nuttx_build.log + DEPENDS ${DEPENDS} ${nuttx_src}/nuttx/.config + WORKING_DIRECTORY ${PX4_BINARY_DIR} + COMMENT "Building NuttX for ${CONFIG} with ${config_nuttx_config}") + + add_custom_target(${OUT} DEPENDS ${nuttx_src}/nuttx/nuttx-export/include/nuttx/config.h) endfunction() @@ -308,6 +388,7 @@ function(px4_nuttx_add_romfs) REQUIRED OUT ROOT ARGN ${ARGN}) + set(romfs_used y PARENT_SCOPE) set(romfs_temp_dir ${PX4_BINARY_DIR}/tmp/${ROOT}) set(romfs_src_dir ${PX4_SOURCE_DIR}/${ROOT}) set(romfs_autostart ${PX4_SOURCE_DIR}/Tools/px_process_airframes.py) @@ -422,20 +503,27 @@ function(px4_os_add_flags) LINK_DIRS ${LINK_DIRS} DEFINITIONS ${DEFINITIONS}) - set(nuttx_export_dir ${PX4_BINARY_DIR}/${BOARD}/NuttX/nuttx-export) + set(nuttx_export_root ${PX4_BINARY_DIR}/${BOARD}/NuttX) + set(nuttx_export_dir ${nuttx_export_root}/nuttx/nuttx-export) set(added_include_dirs ${nuttx_export_dir}/include ${nuttx_export_dir}/include/cxx ${nuttx_export_dir}/arch/chip ${nuttx_export_dir}/arch/common + ${nuttx_export_dir}/arch/armv7-m + ${nuttx_export_root}/apps/include ) set(added_link_dirs ${nuttx_export_dir}/libs ) set(added_definitions -D__PX4_NUTTX - -D__DF_NUTTX # Define for DriverFramework ) + + if(NOT "${config_nuttx_config}" STREQUAL "bootloader") + list(APPEND added_definitions -D__DF_NUTTX) + endif() + set(added_c_flags -nodefaultlibs -nostdlib @@ -458,27 +546,27 @@ function(px4_os_add_flags) endif() set(cpu_flags) - # Handle non-F4 boards specifically here - if (${BOARD} STREQUAL "px4io-v1") + if (${config_nuttx_hw} STREQUAL "m7") set(cpu_flags - -mcpu=cortex-m3 + -mcpu=cortex-m7 -mthumb - -march=armv7-m + -mfpu=fpv5-sp-d16 + -mfloat-abi=hard ) - elseif (${BOARD} STREQUAL "px4io-v2") + elseif (${config_nuttx_hw} STREQUAL "m4") set(cpu_flags - -mcpu=cortex-m3 - -mthumb - -march=armv7-m - ) - else () - set(cpu_flags -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard ) + elseif (${config_nuttx_hw} STREQUAL "m3") + set(cpu_flags + -mcpu=cortex-m3 + -mthumb + -march=armv7-m + ) endif() list(APPEND c_flags ${cpu_flags}) list(APPEND cxx_flags ${cpu_flags}) @@ -527,4 +615,51 @@ function(px4_os_prebuild_targets) add_custom_target(${OUT} DEPENDS nuttx_export_${BOARD}) endfunction() +#============================================================================= +# +# px4_nuttx_configure +# +# This function sets the nuttx configuration +# +# Usage: +# px4_nuttx_configure( +# HWCLASS +# CONFIG +# ROMFSROOT ] +# ) +# +# Input: +# HWCLASS : the class of hardware +# CONFIG : the nuttx condufiguration to use +# ROMFS : whether or not to use incllude theROMFS +# ROMFSROOT : If ROMFS used set the root the default is px4fmu_common +# +# Output: +# OUT : None +# +# Example: +# px4_nuttx_configure(HWCLASS m4 CONFIG nsh ROMFS y) +# +function(px4_nuttx_configure) + px4_parse_function_args( + NAME px4_nuttx_configure + ONE_VALUE HWCLASS CONFIG ROMFS ROMFSROOT + REQUIRED HWCLASS CONFIG + ARGN ${ARGN}) + set(config_nuttx_config ${CONFIG} PARENT_SCOPE) + set(config_nuttx_hw ${HWCLASS} PARENT_SCOPE) + if ("${ROMFS}" STREQUAL "y") + set(romfs_used ${ROMFS} PARENT_SCOPE) + if (NOT DEFINED ROMFSROOT) + set(config_romfs_root px4fmu_common) + else() + set(config_romfs_root ${ROMFSROOT}) + endif() + set(HASROMFS "with ROMFS on ${config_romfs_root}") + set(config_romfs_root ${config_romfs_root} PARENT_SCOPE) + endif() + message(STATUS "Nuttx build for ${BOARD} on ${HWCLASS} hardware, using ${CONFIG} ${HASROMFS}") +endfunction() + # vim: set noet fenc=utf-8 ff=unix nowrap: diff --git a/cmake/qurt/px4_impl_qurt.cmake b/cmake/qurt/px4_impl_qurt.cmake index d6ff56f97d..c783e38c18 100644 --- a/cmake/qurt/px4_impl_qurt.cmake +++ b/cmake/qurt/px4_impl_qurt.cmake @@ -189,6 +189,8 @@ function(px4_os_add_flags) set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") + set(DF_TARGET "qurt" PARENT_SCOPE) + # output foreach(var ${inout_vars}) string(TOLOWER ${var} lower_var) diff --git a/nuttx-configs/PX4_Config.mk b/nuttx-configs/PX4_Config.mk new file mode 100644 index 0000000000..4ec3002da1 --- /dev/null +++ b/nuttx-configs/PX4_Config.mk @@ -0,0 +1,45 @@ +############################################################################ +# nuttx-configs/PX4_Config.mk +# +# Copyright (c) 2016 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. +# +############################################################################ + +# Nuttx GNU builds now use GNU_EABI to set the toolchaine +# PX4 uses the host OS to decide if it is Linux, Darwin or Windows + +ifeq ($(OS),Windows_NT) + OS_DETECTED := Windows + HOST_OS_FIRST_LETTER:= W +else + OS_DETECTED := $(shell uname -s) + # Clump Dawin and Linux as L to set GNU_EABI + HOST_OS_FIRST_LETTER := L +endif diff --git a/nuttx-configs/PX4_Warnings.mk b/nuttx-configs/PX4_Warnings.mk index a2da41cae6..cca25b0df7 100644 --- a/nuttx-configs/PX4_Warnings.mk +++ b/nuttx-configs/PX4_Warnings.mk @@ -1,5 +1,5 @@ ############################################################################ -# configs/PX4_Warnings.mk +# nuttx-configs/PX4_Warnings.mk # # Copyright (C) 2011 Gregory Nutt. All rights reserved. # Author: Gregory Nutt diff --git a/src/firmware/nuttx/CMakeLists.txt b/src/firmware/nuttx/CMakeLists.txt index d0d16e5ee6..0167bc4329 100644 --- a/src/firmware/nuttx/CMakeLists.txt +++ b/src/firmware/nuttx/CMakeLists.txt @@ -10,16 +10,49 @@ add_executable(firmware_nuttx builtin_commands.c) -set(nuttx_export_dir ${PX4_BINARY_DIR}/${BOARD}/NuttX/nuttx-export) +set(nuttx_export_dir ${PX4_BINARY_DIR}/${BOARD}/NuttX/nuttx/nuttx-export) set(link_libs - romfs apps nuttx m gcc + apps nuttx m gcc ) +if("${romfs_used}" STREQUAL "y") + list(APPEND link_libs romfs) +endif() + +# +# Bootloaders use a different ld file, a seperate startup file +# and need to override the os version of sched_process_timer +# +set(startup_libs) + +if("${config_nuttx_config}" STREQUAL "bootloader") + set(nuttx_ld_prefix "bootloader") + set(nuttx_startup_files ${nuttx_export_dir}/startup/${nuttx_startup_files}) + set(nuttx_bootloader_wrapers "-Wl,-wrap,sched_process_timer") + + add_custom_command(OUTPUT + ${nuttx_startup_files} + DEPENDS nuttx_export_${BOARD}) + + set_source_files_properties( + ${nuttx_startup_files} + PROPERTIES + EXTERNAL_OBJECT true + GENERATED true) + + add_library(startup + ${nuttx_startup_files}) + set_target_properties(startup + PROPERTIES + LINKER_LANGUAGE C) + list(APPEND startup_libs startup) + +endif() + if(NOT ${BOARD} STREQUAL "sim") - list(APPEND link_libs nosys) set(main_link_flags - "-T${nuttx_export_dir}/build/ld.script" + "-T${nuttx_export_dir}/build/${nuttx_ld_prefix}ld.script" "-Wl,-Map=${PX4_BINARY_DIR}/${BOARD}/main.map" ) px4_join(OUT main_link_flags LIST ${main_link_flags} GLUE " ") @@ -27,10 +60,14 @@ if(NOT ${BOARD} STREQUAL "sim") endif() target_link_libraries(firmware_nuttx + -Wl,--warn-common + -Wl,--gc-sections -Wl,--start-group + ${startup_libs} ${module_libraries} ${df_driver_libs} ${config_extra_libs} + ${nuttx_bootloader_wrapers} ${link_libs} -Wl,--end-group) @@ -42,35 +79,36 @@ add_custom_target(check_weak if(NOT ${BOARD} STREQUAL "sim") - if (config_io_board) - set(extras "${PX4_BINARY_DIR}/src/modules/px4iofirmware/${config_io_board}.bin") + if ("${romfs_used}" STREQUAL "y") + + if (config_io_board) + set(extras "${CMAKE_BINARY_DIR}/src/modules/px4iofirmware/${config_io_board}.bin") + endif() + + message(STATUS "Adding ROMFS on ${BOARD}") + px4_nuttx_add_romfs(OUT romfs + ROOT ROMFS/${config_romfs_root} + EXTRAS ${extras} + ) + if (config_io_board) + add_dependencies(romfs fw_io) + endif() endif() - set(romfs_dir "ROMFS/px4fmu_common") - if (${BOARD} STREQUAL "tap-v1") - set(romfs_dir "ROMFS/tap_common") + set(fw_file + ${CMAKE_CURRENT_BINARY_DIR}/${OS}-${BOARD}-${LABEL}.px4) + +# +# Bootloaders do not need .px4 or xml +# + if(NOT "${config_nuttx_config}" STREQUAL "bootloader") + px4_nuttx_add_firmware(OUT ${fw_file} + BOARD ${BOARD} + EXE ${CMAKE_CURRENT_BINARY_DIR}/firmware_nuttx + PARAM_XML ${PX4_BINARY_DIR}/parameters.xml + AIRFRAMES_XML ${PX4_BINARY_DIR}/airframes.xml + ) endif() - if (${BOARD} STREQUAL "px4fmu-v2" AND ${LABEL} STREQUAL "test") - set(romfs_dir "ROMFS/px4fmu_test") - endif() - - - px4_nuttx_add_romfs(OUT romfs - ROOT ${romfs_dir} - EXTRAS ${extras} - ) - if (config_io_board) - add_dependencies(romfs fw_io) - endif() - - set(fw_file ${CMAKE_CURRENT_BINARY_DIR}/${OS}-${BOARD}-${LABEL}.px4) - - px4_nuttx_add_firmware(OUT ${fw_file} - BOARD ${BOARD} - EXE ${CMAKE_CURRENT_BINARY_DIR}/firmware_nuttx - PARAM_XML ${PX4_BINARY_DIR}/parameters.xml - AIRFRAMES_XML ${PX4_BINARY_DIR}/airframes.xml - ) configure_file(gdbinit.in .gdbinit) @@ -113,15 +151,19 @@ if(NOT ${BOARD} STREQUAL "sim") ${CMAKE_CURRENT_BINARY_DIR}/.gdbinit ) - if ("${BOARD}" STREQUAL "aerofc-v1") - px4_add_upload_aero(OUT upload OS ${OS} BOARD ${BOARD} - BUNDLE ${fw_file}) - else() - px4_add_upload(OUT upload OS ${OS} BOARD ${BOARD} - BUNDLE ${fw_file}) + if(NOT "${config_nuttx_config}" STREQUAL "bootloader") + if ("${BOARD}" STREQUAL "aerofc-v1") + px4_add_upload_aero(OUT upload OS ${OS} BOARD ${BOARD} + BUNDLE ${fw_file}) + else() + px4_add_upload(OUT upload OS ${OS} BOARD ${BOARD} + BUNDLE ${fw_file}) + endif() endif() endif() -install(FILES ${fw_file} DESTINATION .) +if(NOT "${config_nuttx_config}" STREQUAL "bootloader") + install(FILES ${fw_file} DESTINATION .) +endif() # vim: set noet ft=cmake fenc=utf-8 ff=unix : diff --git a/src/modules/px4iofirmware/CMakeLists.txt b/src/modules/px4iofirmware/CMakeLists.txt index 754bf715a3..bef1719312 100644 --- a/src/modules/px4iofirmware/CMakeLists.txt +++ b/src/modules/px4iofirmware/CMakeLists.txt @@ -45,6 +45,8 @@ set(include_dirs) set(link_dirs) set(definitions) +px4_nuttx_configure(HWCLASS m3 CONFIG nsh) + px4_os_prebuild_targets(OUT io_prebuild_targets BOARD ${config_io_board} THREADS ${THREADS}) @@ -120,7 +122,7 @@ add_dependencies(${fw_io_name} mixer_gen ) -set(nuttx_export_dir ${PX4_BINARY_DIR}/${config_io_board}/NuttX/nuttx-export) +set(nuttx_export_dir ${PX4_BINARY_DIR}/${config_io_board}/NuttX/nuttx/nuttx-export) set(main_link_flags "-T${nuttx_export_dir}/build/ld.script" "-Wl,-Map=${PX4_BINARY_DIR}/${config_io_board}/main.map"