Adding Nuttx Build infrastructure

This commit is contained in:
David Sidrane
2016-12-21 08:34:20 +01:00
committed by Lorenz Meier
parent cb9517486d
commit d6098c8226
7 changed files with 360 additions and 96 deletions
+42 -4
View File
@@ -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 <relative path> ARGS <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
+188 -53
View File
@@ -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 <board>
# BIN <input bin file>)
# HWNAME <uavcan name>
# HW_MAJOR <number>
# HW_MINOR <number>
# SW_MAJOR <number>
# SW_MINOR <number>)
#
# 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 <m3|m4>
# CONFIG <nsh|bootloader
# [ROMFS <y|n>
# ROMFSROOT <root>]
# )
#
# 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:
+2
View File
@@ -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)