mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-27 14:53:35 +08:00
boards organization
This commit is contained in:
committed by
David Sidrane
parent
c1f851a600
commit
f692ad04d0
@@ -3,17 +3,11 @@ cmake_minimum_required(VERSION 3.2)
|
||||
px4_add_git_submodule(TARGET git_nuttx PATH "nuttx")
|
||||
px4_add_git_submodule(TARGET git_nuttx_apps PATH "apps")
|
||||
|
||||
if(NOT BOARD)
|
||||
message(FATAL_ERROR "BOARD must be set (eg px4fmu-v2)")
|
||||
if(NOT PX4_BOARD)
|
||||
message(FATAL_ERROR "PX4_BOARD must be set (eg px4fmu-v2)")
|
||||
endif()
|
||||
|
||||
if(NOT nuttx_config_type)
|
||||
# default to nsh if not specified
|
||||
set(nuttx_config_type "nsh")
|
||||
endif()
|
||||
|
||||
project(NuttX_${BOARD} LANGUAGES ASM C CXX)
|
||||
message(STATUS "NuttX: " ${BOARD} " " ${nuttx_config_type} " " ${CMAKE_SYSTEM_PROCESSOR})
|
||||
project(NuttX_${PX4_BOARD} LANGUAGES ASM C CXX)
|
||||
|
||||
if (CMAKE_HOST_APPLE OR CMAKE_HOST_WIN32)
|
||||
# copy with rsync and create file dependencies
|
||||
@@ -39,8 +33,10 @@ file(GLOB_RECURSE copy_apps_files
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/apps/*)
|
||||
|
||||
set(NUTTX_DIR ${CMAKE_CURRENT_BINARY_DIR}/nuttx)
|
||||
set(NUTTX_CONFIG_DIR ${PX4_SOURCE_DIR}/platforms/nuttx/nuttx-configs)
|
||||
configure_file(${NUTTX_CONFIG_DIR}/Make.defs.in ${NUTTX_DIR}/Make.defs)
|
||||
set(NUTTX_CONFIG_DIR ${PX4_BOARD_DIR}/nuttx-config)
|
||||
|
||||
set(NUTTX_CONFIGS_DIR ${PX4_SOURCE_DIR}/platforms/nuttx/nuttx-configs)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Make.defs.in ${NUTTX_DIR}/Make.defs)
|
||||
|
||||
# copy nuttx to build directory
|
||||
file(RELATIVE_PATH CP_SRC ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/nuttx)
|
||||
@@ -66,24 +62,23 @@ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/apps_copy.stamp
|
||||
set(APPS_DIR ${CMAKE_CURRENT_BINARY_DIR}/apps)
|
||||
|
||||
# copy PX4 board config into nuttx
|
||||
file(GLOB_RECURSE board_config_files ${NUTTX_CONFIG_DIR}/${BOARD})
|
||||
file(RELATIVE_PATH CP_SRC ${CMAKE_SOURCE_DIR} ${NUTTX_CONFIG_DIR}/${BOARD})
|
||||
file(RELATIVE_PATH CP_DST ${CMAKE_SOURCE_DIR} ${NUTTX_DIR}/configs)
|
||||
add_custom_command(
|
||||
OUTPUT ${NUTTX_DIR}/.config
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${NUTTX_CONFIG_DIR}/${BOARD}/${nuttx_config_type}/defconfig ${NUTTX_DIR}/.config
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${NUTTX_CONFIG_DIR}/${NUTTX_CONFIG}/defconfig ${NUTTX_DIR}/.config
|
||||
COMMAND ${CMAKE_COMMAND} -E remove -f ${NUTTX_DIR}/include/nuttx/config.h
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${NUTTX_DIR}/configs/${BOARD}/src
|
||||
COMMAND cd ${CMAKE_SOURCE_DIR} && ${cp_cmd} ${cp_opts} ${CP_SRC} ${CP_DST}
|
||||
COMMAND ${CMAKE_COMMAND} -E remove_directory ${NUTTX_DIR}/configs/${PX4_BOARD}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory ${NUTTX_CONFIG_DIR}/ ${NUTTX_DIR}/configs/${PX4_BOARD}/
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${NUTTX_DIR}/configs/${PX4_BOARD}/src
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/nsh_romfsimg.h ${NUTTX_DIR}/configs/${PX4_BOARD}/include
|
||||
DEPENDS
|
||||
${NUTTX_CONFIG_DIR}/${BOARD}/${nuttx_config_type}/defconfig
|
||||
${board_config_files}
|
||||
${NUTTX_CONFIG_DIR}/${NUTTX_CONFIG}/defconfig
|
||||
${NUTTX_CONFIG_DIR}/include/board.h
|
||||
${NUTTX_CONFIG_DIR}/scripts/ld.script
|
||||
${CMAKE_CURRENT_BINARY_DIR}/nuttx_copy.stamp
|
||||
${CMAKE_CURRENT_BINARY_DIR}/apps_copy.stamp
|
||||
WORKING_DIRECTORY ${NUTTX_DIR}/tools
|
||||
COMMENT "Copying NuttX config ${BOARD} and configuring"
|
||||
COMMENT "Copying NuttX config ${NUTTX_CONFIG} and configuring"
|
||||
)
|
||||
add_custom_target(nuttx_configure DEPENDS ${NUTTX_DIR}/.config)
|
||||
|
||||
# verbose build settings (V=1 or VERBOSE=1)
|
||||
option(PX4_NUTTX_VERBOSE "PX4 NuttX verbose build" off)
|
||||
@@ -106,11 +101,11 @@ endif()
|
||||
# context
|
||||
add_custom_command(OUTPUT ${NUTTX_DIR}/include/nuttx/version.h ${NUTTX_DIR}/include/nuttx/config.h
|
||||
COMMAND make ${nuttx_build_options} --no-print-directory context ${nuttx_build_output}
|
||||
DEPENDS nuttx_configure ${NUTTX_DIR}/.config
|
||||
DEPENDS ${NUTTX_DIR}/.config
|
||||
WORKING_DIRECTORY ${NUTTX_DIR}
|
||||
${nuttx_build_uses_terminal}
|
||||
)
|
||||
add_custom_target(nuttx_context DEPENDS ${NUTTX_DIR}/include/nuttx/version.h)
|
||||
add_custom_target(nuttx_context DEPENDS ${NUTTX_DIR}/include/nuttx/version.h ${NUTTX_DIR}/include/nuttx/config.h)
|
||||
|
||||
# library of NuttX libraries
|
||||
add_library(nuttx_build INTERFACE)
|
||||
@@ -126,9 +121,10 @@ if (CONFIG_NSH_LIBRARY)
|
||||
COMMAND rm -f ${APPS_DIR}/builtin/builtin_list.h
|
||||
COMMAND ${CMAKE_COMMAND} -E touch builtins_clean.stamp
|
||||
DEPENDS
|
||||
nuttx_configure
|
||||
nuttx_context
|
||||
${PX4_SOURCE_DIR}/cmake/configs/${CONFIG}.cmake
|
||||
${NUTTX_DIR}/.config
|
||||
${NUTTX_DIR}/include/nuttx/version.h
|
||||
${NUTTX_DIR}/include/nuttx/config.h
|
||||
${PX4_CONFIG_FILE}
|
||||
)
|
||||
|
||||
foreach(module ${module_libraries})
|
||||
@@ -140,7 +136,7 @@ if (CONFIG_NSH_LIBRARY)
|
||||
add_custom_command(OUTPUT ${APPS_DIR}/builtin/registry/px4_${MAIN}_main.bdat
|
||||
COMMAND echo "{ \"${MAIN}\", ${PRIORITY}, ${STACK_MAIN}, ${MAIN}_main }," > ${APPS_DIR}/builtin/registry/px4_${MAIN}_main.bdat
|
||||
COMMAND ${CMAKE_COMMAND} -E touch ${APPS_DIR}/builtin/registry/.updated
|
||||
DEPENDS nuttx_context builtins_clean.stamp
|
||||
DEPENDS builtins_clean.stamp ${NUTTX_DIR}/include/nuttx/version.h ${NUTTX_DIR}/include/nuttx/config.h
|
||||
VERBATIM
|
||||
)
|
||||
list(APPEND nuttx_builtin_list ${APPS_DIR}/builtin/registry/px4_${MAIN}_main.bdat)
|
||||
@@ -148,7 +144,7 @@ if (CONFIG_NSH_LIBRARY)
|
||||
add_custom_command(OUTPUT ${APPS_DIR}/builtin/registry/px4_${MAIN}_main.pdat
|
||||
COMMAND echo "int ${MAIN}_main(int argc, char *argv[]);" > ${APPS_DIR}/builtin/registry/px4_${MAIN}_main.pdat
|
||||
COMMAND ${CMAKE_COMMAND} -E touch ${APPS_DIR}/builtin/registry/.updated
|
||||
DEPENDS nuttx_context builtins_clean.stamp
|
||||
DEPENDS builtins_clean.stamp ${NUTTX_DIR}/include/nuttx/version.h ${NUTTX_DIR}/include/nuttx/config.h
|
||||
VERBATIM
|
||||
)
|
||||
list(APPEND nuttx_builtin_list ${APPS_DIR}/builtin/registry/px4_${MAIN}_main.pdat)
|
||||
@@ -163,7 +159,7 @@ endif()
|
||||
add_custom_command(OUTPUT ${APPS_DIR}/libapps.a ${APPS_DIR}/platform/.built
|
||||
COMMAND find ${APPS_DIR} -name \*.o -delete
|
||||
COMMAND make ${nuttx_build_options} --no-print-directory -C ../apps TOPDIR="${NUTTX_DIR}" libapps.a ${nuttx_build_output}
|
||||
DEPENDS nuttx_context ${nuttx_builtin_list}
|
||||
DEPENDS ${nuttx_builtin_list} ${NUTTX_DIR}/include/nuttx/version.h ${NUTTX_DIR}/include/nuttx/config.h
|
||||
WORKING_DIRECTORY ${NUTTX_DIR}
|
||||
${nuttx_build_uses_terminal}
|
||||
)
|
||||
@@ -182,7 +178,7 @@ function(add_nuttx_dir nuttx_lib nuttx_lib_dir kernel extra)
|
||||
add_custom_command(OUTPUT ${NUTTX_DIR}/${nuttx_lib_dir}/lib${nuttx_lib}.a
|
||||
COMMAND find ${nuttx_lib_dir} -type f -name *.o -delete
|
||||
COMMAND make -C ${nuttx_lib_dir} ${nuttx_build_options} --no-print-directory all TOPDIR=${NUTTX_DIR} KERNEL=${kernel} EXTRADEFINES=${extra} ${nuttx_build_output}
|
||||
DEPENDS ${nuttx_lib_files} nuttx_context
|
||||
DEPENDS ${nuttx_lib_files} ${NUTTX_DIR}/include/nuttx/version.h ${NUTTX_DIR}/include/nuttx/config.h
|
||||
WORKING_DIRECTORY ${NUTTX_DIR}
|
||||
${nuttx_build_uses_terminal}
|
||||
)
|
||||
@@ -210,32 +206,32 @@ endif()
|
||||
|
||||
# oldconfig helper
|
||||
add_custom_target(oldconfig
|
||||
COMMAND make --no-print-directory --silent -C ${NUTTX_DIR} CONFIG_ARCH_BOARD=${BOARD} oldconfig
|
||||
COMMAND cp ${NUTTX_DIR}/.config ${NUTTX_CONFIG_DIR}/${BOARD}/${nuttx_config_type}/defconfig
|
||||
COMMAND ${PX4_SOURCE_DIR}/platforms/nuttx/NuttX/tools/nuttx_defconf_tool.sh ${NUTTX_CONFIG_DIR}/${BOARD}/${nuttx_config_type}/defconfig
|
||||
DEPENDS nuttx_configure
|
||||
COMMAND make --no-print-directory --silent -C ${NUTTX_DIR} CONFIG_ARCH_BOARD=${PX4_BOARD} oldconfig
|
||||
COMMAND cp ${NUTTX_DIR}/.config ${NUTTX_CONFIG_DIR}/${NUTTX_CONFIG}/defconfig
|
||||
COMMAND ${PX4_SOURCE_DIR}/platforms/nuttx/NuttX/tools/nuttx_defconf_tool.sh ${NUTTX_CONFIG_DIR}/${NUTTX_CONFIG}/defconfig
|
||||
DEPENDS ${NUTTX_DIR}/.config
|
||||
WORKING_DIRECTORY ${NUTTX_DIR}
|
||||
COMMENT "Running NuttX make oldconfig for ${BOARD} with ${nuttx_config_type}"
|
||||
COMMENT "Running NuttX make oldconfig for ${NUTTX_CONFIG}"
|
||||
USES_TERMINAL
|
||||
)
|
||||
|
||||
# menuconfig helper
|
||||
add_custom_target(menuconfig
|
||||
COMMAND make --no-print-directory --silent -C ${NUTTX_DIR} CONFIG_ARCH_BOARD=${BOARD} menuconfig
|
||||
COMMAND cp ${NUTTX_DIR}/.config ${NUTTX_CONFIG_DIR}/${BOARD}/${nuttx_config_type}/defconfig
|
||||
COMMAND cd ${PX4_SOURCE_DIR} && platforms/nuttx/NuttX/tools/nuttx_defconf_tool.sh ${NUTTX_CONFIG_DIR}/${BOARD}/${nuttx_config_type}/defconfig
|
||||
DEPENDS nuttx_configure
|
||||
COMMAND make --no-print-directory --silent -C ${NUTTX_DIR} CONFIG_ARCH_BOARD=${PX4_BOARD} menuconfig
|
||||
COMMAND cp ${NUTTX_DIR}/.config ${NUTTX_CONFIG_DIR}/${NUTTX_CONFIG}/defconfig
|
||||
COMMAND cd ${PX4_SOURCE_DIR} && platforms/nuttx/NuttX/tools/nuttx_defconf_tool.sh ${NUTTX_CONFIG_DIR}/${NUTTX_CONFIG}/defconfig
|
||||
DEPENDS ${NUTTX_DIR}/.config
|
||||
WORKING_DIRECTORY ${NUTTX_DIR}
|
||||
COMMENT "Running NuttX make menuconfig for ${BOARD} with ${nuttx_config_type}"
|
||||
COMMENT "Running NuttX make menuconfig for ${NUTTX_CONFIG}"
|
||||
USES_TERMINAL
|
||||
)
|
||||
|
||||
# qconfig helper
|
||||
add_custom_target(qconfig
|
||||
COMMAND make --no-print-directory --silent -C ${NUTTX_DIR} CONFIG_ARCH_BOARD=${BOARD} qconfig
|
||||
COMMAND cp .config ${NUTTX_CONFIG_DIR}/${BOARD}/${nuttx_config_type}/defconfig
|
||||
DEPENDS nuttx_configure
|
||||
COMMAND make --no-print-directory --silent -C ${NUTTX_DIR} CONFIG_ARCH_BOARD=${PX4_BOARD} qconfig
|
||||
COMMAND cp .config ${NUTTX_CONFIG_DIR}/${NUTTX_CONFIG}/defconfig
|
||||
DEPENDS ${NUTTX_DIR}/.config
|
||||
WORKING_DIRECTORY ${NUTTX_DIR}
|
||||
COMMENT "Running NuttX make qconfig for ${BOARD} with ${nuttx_config_type}"
|
||||
COMMENT "Running NuttX make qconfig for ${NUTTX_CONFIG}"
|
||||
USES_TERMINAL
|
||||
)
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
############################################################################
|
||||
# nuttx-configs/Make.defs
|
||||
#
|
||||
# Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# 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 NuttX 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
include $(TOPDIR)/.config
|
||||
include $(TOPDIR)/tools/Config.mk
|
||||
|
||||
CC = ${CMAKE_C_COMPILER}
|
||||
CXX = ${CMAKE_CXX_COMPILER}
|
||||
CPP = ${CMAKE_C_COMPILER} -E
|
||||
LD = ${CMAKE_LD}
|
||||
AR = ${CMAKE_AR} rcs
|
||||
NM = ${CMAKE_NM}
|
||||
OBJCOPY = ${CMAKE_OBJCOPY}
|
||||
OBJDUMP = ${CMAKE_OBJDUMP}
|
||||
|
||||
# Include paths with Cygwin path conversion
|
||||
ifneq (, $(findstring CYGWIN, $(shell uname)))
|
||||
WINTOOL = y
|
||||
ARCHINCLUDES = -I. -isystem "$(shell cygpath -w $(TOPDIR)/include)"
|
||||
ARCHXXINCLUDES = $(ARCHINCLUDES) -isystem "$(shell cygpath -w $(TOPDIR)/include/cxx)"
|
||||
else
|
||||
ARCHINCLUDES = -I. -isystem $(TOPDIR)/include
|
||||
ARCHXXINCLUDES = $(ARCHINCLUDES) -isystem $(TOPDIR)/include/cxx
|
||||
endif
|
||||
|
||||
# Windows toolchain (MSYS & Cygwin) symbolic link handling
|
||||
ifeq ($(WINTOOL),y)
|
||||
DIRLINK = $(TOPDIR)/tools/copydir.sh
|
||||
DIRUNLINK = $(TOPDIR)/tools/unlink.sh
|
||||
MKDEP = $(TOPDIR)/tools/mknulldeps.sh
|
||||
endif
|
||||
|
||||
FLAGS = -Os -g2 \
|
||||
-fdata-sections \
|
||||
-ffunction-sections \
|
||||
-fno-builtin-printf \
|
||||
-fno-common \
|
||||
-fno-strength-reduce \
|
||||
-fno-strict-aliasing \
|
||||
-fomit-frame-pointer \
|
||||
-Wall \
|
||||
-Werror \
|
||||
-Wextra \
|
||||
-Wlogical-op \
|
||||
-Wno-cpp \
|
||||
-Wno-format-truncation \
|
||||
-Wno-maybe-uninitialized \
|
||||
-Wno-missing-field-initializers \
|
||||
-Wno-sign-compare \
|
||||
-Wno-type-limits \
|
||||
-Wno-unused-parameter \
|
||||
-Wpointer-arith
|
||||
|
||||
# enable precise stack overflow tracking
|
||||
ifeq ($(CONFIG_ARMV7M_STACKCHECK),y)
|
||||
FLAGS += -finstrument-functions -ffixed-r10
|
||||
endif
|
||||
|
||||
CFLAGS = $(ARCHINCLUDES) \
|
||||
-std=gnu99 \
|
||||
${CMAKE_C_FLAGS} \
|
||||
$(FLAGS) \
|
||||
-Wno-bad-function-cast \
|
||||
-Wno-float-equal \
|
||||
-Wno-implicit-fallthrough \
|
||||
-Wno-implicit-function-declaration \
|
||||
-Wno-logical-op \
|
||||
-Wno-missing-declarations \
|
||||
-Wno-missing-field-initializers \
|
||||
-Wno-missing-prototypes \
|
||||
-Wno-nested-externs \
|
||||
-Wno-nonnull-compare \
|
||||
-Wno-old-style-declaration \
|
||||
-Wno-sign-compare \
|
||||
-Wno-type-limits
|
||||
|
||||
CXXFLAGS = $(ARCHXXINCLUDES) \
|
||||
-std=gnu++11 \
|
||||
${CMAKE_CXX_FLAGS} \
|
||||
$(FLAGS) \
|
||||
-fcheck-new \
|
||||
-fno-builtin \
|
||||
-fno-exceptions \
|
||||
-fno-rtti \
|
||||
-Wno-double-promotion \
|
||||
-Wno-missing-declarations
|
||||
|
||||
AFLAGS = $(CFLAGS) -D__ASSEMBLY__
|
||||
@@ -0,0 +1,42 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (C) 2013 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* nsh_romfsetc.h
|
||||
*
|
||||
* This file is a stub for 'make export' purposes; the actual ROMFS
|
||||
* must be supplied by the library client.
|
||||
*/
|
||||
|
||||
extern unsigned char romfs_img[];
|
||||
extern unsigned int romfs_img_len;
|
||||
@@ -1,173 +0,0 @@
|
||||
#! /bin/bash
|
||||
|
||||
function fatal
|
||||
{
|
||||
echo "$0: ERROR: $*"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Find out what the base directory is.
|
||||
BASEDIR="$(dirname $(dirname $(readlink -en "$0")))"
|
||||
echo "BASEDIR=\"$BASEDIR\""
|
||||
striplen=$((${#BASEDIR} + 2))
|
||||
|
||||
# BASEDIR may not contain a space, that's just too hard to get to work.
|
||||
expr index "$BASEDIR" " " >/dev/null && fatal "it is not supported that BASEDIR contains a space."
|
||||
|
||||
# Make sure that worked.
|
||||
test -f $BASEDIR/cmake/posix/px4_impl_posix.cmake || fatal "Failed to determine BASEDIR: '\$BASEDIR/cmake/posix/px4_impl_posix.cmake' is not a regular file."
|
||||
|
||||
# Did we get two arguments?
|
||||
if [[ $# -lt 2 ]]; then
|
||||
echo "Usage:"
|
||||
echo " $0 PROTOTYPE NEWNAME"
|
||||
echo
|
||||
echo "For example: $0 px4fmu-v4 awesome_new_board-v2"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Parse command line parameters.
|
||||
oldname=
|
||||
newname=
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
case $1 in
|
||||
-*)
|
||||
fatal "Unknown option $1"
|
||||
;;
|
||||
*)
|
||||
if [ -z "$oldname" ]; then
|
||||
oldname="$1"
|
||||
elif [ -z "$newname" ]; then
|
||||
newname="$1"
|
||||
else
|
||||
fatal "Too many arguments."
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
echo "PROTOTYPE = \"$oldname\""
|
||||
|
||||
# Does that look like an existing old name?
|
||||
if [ ! -f $BASEDIR/platforms/nuttx/Images/$oldname.prototype ]; then
|
||||
fatal "\"$oldname\" doesn't look like an existing board name (there is no $BASEDIR/platforms/nuttx/Images/$oldname.prototype)"
|
||||
fi
|
||||
if [ ! -d $BASEDIR/src/drivers/boards/$oldname ]; then
|
||||
fatal "\"$oldname\" doesn't look like an existing board name (no such directory $BASEDIR/src/drivers/boards/$oldname)"
|
||||
fi
|
||||
if [ ! -f $BASEDIR/cmake/configs/nuttx_"$oldname"_default.cmake -a ! -f $BASEDIR/cmake/configs/nuttx_"$oldname"_bootloader.cmake ]; then
|
||||
fatal "\"$oldname\" doesn't look like an existing board name (there is neither a $BASEDIR/cmake/configs/nuttx_"$oldname"_default.cmake nor a $BASEDIR/cmake/configs/nuttx_"$oldname"_bootloader.cmake)"
|
||||
fi
|
||||
if [ ! -d $BASEDIR/platforms/nuttx/nuttx-configs/$oldname ]; then
|
||||
fatal "\"$oldname\" doesn't look like an existing board name (no such directory $BASEDIR/platforms/nuttx/nuttx-configs/$oldname)"
|
||||
fi
|
||||
|
||||
# Does the new name look like a new name?
|
||||
if [[ $newname =~ ^[[:alnum:]_-]+$ ]]; then
|
||||
echo "NEWNAME = \"$newname\""
|
||||
else
|
||||
fatal "NEWNAME may only contain alpha numeric characters, a dash or an underscore."
|
||||
fi
|
||||
|
||||
# Change directory to BASEDIR.
|
||||
cd "$BASEDIR" || fatal "Could not change directory to $BASEDIR"
|
||||
|
||||
# Make sure we don't accidently overwrite stuff.
|
||||
if [ -f platforms/nuttx/Images/$newname.prototype -o \
|
||||
-f cmake/configs/nuttx_"$newname"_default.cmake -o \
|
||||
-f cmake/configs/nuttx_"$newname"_bootloader.cmake -o \
|
||||
-d src/drivers/boards/$newname -o \
|
||||
-d nuttx-configs/$newname ]; then
|
||||
echo "\"$newname\" already exists! Please first delete it with the following command (in $BASEDIR):"
|
||||
echo "rm -rf platforms/nuttx/Images/$newname.prototype cmake/configs/nuttx_"$newname"_default.cmake cmake/configs/nuttx_"$newname"_bootloader.cmake src/drivers/boards/$newname nuttx-configs/$newname"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Capitalize names.
|
||||
oldboard=$(echo "$oldname" | tr '[:lower:]-' '[:upper:]_')
|
||||
newboard=$(echo "$newname" | tr '[:lower:]-' '[:upper:]_')
|
||||
|
||||
# Do we have a default and/or bootloader?
|
||||
[ ! -e cmake/configs/nuttx_"$oldname"_default.cmake ]; have_default=$?
|
||||
[ ! -e cmake/configs/nuttx_"$oldname"_bootloader.cmake ]; have_bootloader=$?
|
||||
|
||||
function insertAfter # file line newText
|
||||
{
|
||||
local file="$1" line="$2" newText="$3"
|
||||
sed -i -e "/$line/a"$'\\\n'"$newText" "$file"
|
||||
}
|
||||
|
||||
for k in default bootloader; do
|
||||
eval needit=\$have_$k;
|
||||
if [[ $needit -eq 1 ]]; then
|
||||
# Copy cmake/configs/file(s).
|
||||
cp "cmake/configs/nuttx_${oldname}_${k}.cmake" "cmake/configs/nuttx_${newname}_${k}.cmake"
|
||||
git add "cmake/configs/nuttx_${newname}_${k}.cmake"
|
||||
sed -i -e "s%drivers/boards/${oldname}%drivers/boards/${newname}%" "cmake/configs/nuttx_${newname}_${k}.cmake"
|
||||
# If Makefile does not already have it, add 'check_$newname_[default|bootloader]'
|
||||
# to targets checks_[default|bootloader]s respectivily.
|
||||
if ! grep '^'$'\t'"check_${newname}_${k}"' \\$' Makefile >/dev/null; then
|
||||
insertAfter Makefile "^checks_${k}s:" $'\t'"check_${newname}_${k}"' \\'
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# Copy remaining files.
|
||||
cp platforms/nuttx/Images/${oldname}.prototype platforms/nuttx/Images/${newname}.prototype
|
||||
git add platforms/nuttx/Images/${newname}.prototype
|
||||
cp -r nuttx-configs/${oldname} nuttx-configs/${newname}
|
||||
git add nuttx-configs/${newname}
|
||||
cp -r src/drivers/boards/${oldname} src/drivers/boards/${newname}
|
||||
git add src/drivers/boards/${newname}
|
||||
if [[ $have_bootloader -eq 1 ]]; then
|
||||
cp cmake/configs/uavcan_board_ident/${oldname}.cmake cmake/configs/uavcan_board_ident/${newname}.cmake
|
||||
git add cmake/configs/uavcan_board_ident/${newname}.cmake
|
||||
sed -i -r -e 's%\\"([^\\]*)\\"%\\"FIXME (was: \1)\\"%' cmake/configs/uavcan_board_ident/${newname}.cmake
|
||||
fi
|
||||
|
||||
# Rename certain files.
|
||||
|
||||
TYPE_RE='(buttons|can|timer_config|i2c|init|led|pwr|sdio|spi|usb)'
|
||||
oldstem=$(find "src/drivers/boards/$oldname" -type f -name '*.c' -o -name '*.cpp' | grep -E "_$TYPE_RE.[cp]*$" | sed -r -e 's%.*/%%;s%_'"$TYPE_RE"'\.[cp]*$%%' | sort -u | head -n 1)
|
||||
newstem=$(echo "$newname" | sed -e 's/-v[0-9]*$//' | tr '[:upper:]-' '[:lower:]_')
|
||||
|
||||
echo "oldstem=\"$oldstem\""
|
||||
echo "newstem=\"$newstem\""
|
||||
|
||||
FILES=$(find src/drivers/boards/${newname} -regextype egrep -regex ".*/$oldstem[0-9]*_$TYPE_RE\.[cp]*")
|
||||
for f in $FILES; do
|
||||
nf=$(echo $f | sed -r -e 's%^(.*/)'"$oldstem"'([0-9]*_'"$TYPE_RE"'\.[cp]*)$%\1'"$newstem"'\2%')
|
||||
if [[ "$f" != "$nf" ]]; then
|
||||
git mv "$f" "$nf"
|
||||
fi
|
||||
git add "$nf"
|
||||
bf=$(basename "$f")
|
||||
bnf=$(basename "$nf")
|
||||
sed -i -e "s%$bf%$bnf%" "$nf"
|
||||
done
|
||||
|
||||
oldconfig=CONFIG_ARCH_BOARD_$oldboard
|
||||
newconfig=CONFIG_ARCH_BOARD_$newboard
|
||||
|
||||
# Fixup copied files.
|
||||
sed -i -r -e 's%(MODULE[[:space:]]+.*)'"$oldname"'%\1'"$newname"'%;s%^([[:space:]]+)'"$oldstem"'([0-9]*_'"$TYPE_RE"'\.)%\1'"$newstem"'\2%' "src/drivers/boards/${newname}/CMakeLists.txt"
|
||||
sed -i -r -e 's%"'"$oldboard"'"%"'"$newboard"'"%' "src/drivers/boards/${newname}/board_config.h"
|
||||
sed -i -r -e 's%'"$oldname"'%'"$newname"'%' "nuttx-configs/${newname}/nsh/Make.defs"
|
||||
sed -i -r -e 's%'"$oldname"'%'"$newname"'%;s%'"$oldconfig"'%'"$newconfig"'%;s%(CONFIG_CDCACM_PRODUCTSTR=)"([^"]*)"%\1"FIXME (was: \2)"%' "nuttx-configs/${newname}/nsh/defconfig"
|
||||
|
||||
# If src/modules/gpio_led/gpio_led.c does not already contain it,
|
||||
# add defined($newconfig) where defined($oldconfig) exists.
|
||||
if ! grep 'defined('"${newconfig}"')' 'src/modules/gpio_led/gpio_led.c' >/dev/null; then
|
||||
insertAfter src/modules/gpio_led/gpio_led.c "defined(${oldconfig})"' || \\$' $'\t'"defined(${newconfig})"' || \\'
|
||||
sed -i -e 's/\(defined('"${oldconfig}"')$\)/\1 || \\'$'\\n\\t'"defined(${newconfig})/" 'src/modules/gpio_led/gpio_led.c'
|
||||
fi
|
||||
|
||||
# Make some changes to platforms/nuttx/Images/$(newname).prototype
|
||||
sed -i -r -e 's%("(magic|description|summary)": ")([^"]*)(",).*%\1FIXME (was: \3)\4%' "platforms/nuttx/Images/${newname}.prototype"
|
||||
|
||||
echo "*** The following files contain a reference to $oldconfig (this might take a while):"
|
||||
find . -path './build/*' -o -path './.git' -o -name 'defconfig' -prune -o -type f -exec grep -l -- "$oldconfig" {} \;
|
||||
echo "*** Run 'git diff' to check the changes that this script already made relative to the copied prototype files."
|
||||
echo "*** Use 'git status' to see other (added) files, that likely need fixing."
|
||||
Reference in New Issue
Block a user