From 838e9fc76943eabd78064a8f18effd3dcd0fd1bf Mon Sep 17 00:00:00 2001 From: Mark Charlebois Date: Tue, 10 Mar 2015 15:13:22 -0700 Subject: [PATCH] Refactoring for multiplatform support Moved the NuttX specific board files to makefiles/nuttx and added a makfiles/linux directory with sample config and board files. Created a makefiles/toolchain_native.mk file for building for Linux with the native system compiler. GCC or clang can be used by setting a flag in the file. The Linux build creates an archive file and will build the tasks as threads. Other code changes are required to support both task based and thread based builds. The NuttX source should not be required for the Linux build. The target OS (NuttX or Linux) is selected by commenting out the desired line in setup.mk Signed-off-by: Mark Charlebois --- Makefile | 143 +------- makefiles/README.txt | 31 +- makefiles/firmware.mk | 192 +---------- makefiles/firmware_linux.mk | 56 ++++ makefiles/firmware_nuttx.mk | 160 +++++++++ makefiles/library.mk | 2 +- makefiles/linux.mk | 38 +++ makefiles/linux/board_linux.mk | 11 + makefiles/linux/config_linux_default.mk | 64 ++++ makefiles/linux_elf.mk | 69 ++++ makefiles/nuttx.mk | 2 + makefiles/{ => nuttx}/board_aerocore.mk | 0 makefiles/{ => nuttx}/board_px4fmu-v1.mk | 0 makefiles/{ => nuttx}/board_px4fmu-v2.mk | 0 makefiles/{ => nuttx}/board_px4io-v1.mk | 0 makefiles/{ => nuttx}/board_px4io-v2.mk | 0 .../{ => nuttx}/config_aerocore_default.mk | 0 .../{ => nuttx}/config_px4fmu-v1_default.mk | 0 .../{ => nuttx}/config_px4fmu-v2_default.mk | 0 .../config_px4fmu-v2_multiplatform.mk | 0 .../{ => nuttx}/config_px4fmu-v2_test.mk | 0 .../{ => nuttx}/config_px4io-v1_default.mk | 0 .../{ => nuttx}/config_px4io-v2_default.mk | 0 makefiles/nuttx_romfs.mk | 219 +++++++++++++ makefiles/setup.mk | 3 + makefiles/toolchain_gnu-arm-eabi.mk | 2 +- makefiles/toolchain_native.mk | 306 ++++++++++++++++++ 27 files changed, 979 insertions(+), 319 deletions(-) create mode 100644 makefiles/firmware_linux.mk create mode 100644 makefiles/firmware_nuttx.mk create mode 100644 makefiles/linux.mk create mode 100644 makefiles/linux/board_linux.mk create mode 100644 makefiles/linux/config_linux_default.mk create mode 100644 makefiles/linux_elf.mk rename makefiles/{ => nuttx}/board_aerocore.mk (100%) rename makefiles/{ => nuttx}/board_px4fmu-v1.mk (100%) rename makefiles/{ => nuttx}/board_px4fmu-v2.mk (100%) rename makefiles/{ => nuttx}/board_px4io-v1.mk (100%) rename makefiles/{ => nuttx}/board_px4io-v2.mk (100%) rename makefiles/{ => nuttx}/config_aerocore_default.mk (100%) rename makefiles/{ => nuttx}/config_px4fmu-v1_default.mk (100%) rename makefiles/{ => nuttx}/config_px4fmu-v2_default.mk (100%) rename makefiles/{ => nuttx}/config_px4fmu-v2_multiplatform.mk (100%) rename makefiles/{ => nuttx}/config_px4fmu-v2_test.mk (100%) rename makefiles/{ => nuttx}/config_px4io-v1_default.mk (100%) rename makefiles/{ => nuttx}/config_px4io-v2_default.mk (100%) create mode 100644 makefiles/nuttx_romfs.mk create mode 100644 makefiles/toolchain_native.mk diff --git a/Makefile b/Makefile index 201187e021..65eabf9832 100644 --- a/Makefile +++ b/Makefile @@ -53,13 +53,13 @@ export GIT_DESC # # Canned firmware configurations that we (know how to) build. # -KNOWN_CONFIGS := $(subst config_,,$(basename $(notdir $(wildcard $(PX4_MK_DIR)config_*.mk)))) +KNOWN_CONFIGS := $(subst config_,,$(basename $(notdir $(wildcard $(PX4_MK_DIR)/$(PX4_TARGET_OS)/config_*.mk)))) CONFIGS ?= $(KNOWN_CONFIGS) # # Boards that we (know how to) build NuttX export kits for. # -KNOWN_BOARDS := $(subst board_,,$(basename $(notdir $(wildcard $(PX4_MK_DIR)board_*.mk)))) +KNOWN_BOARDS := $(subst board_,,$(basename $(notdir $(wildcard $(PX4_MK_DIR)/$(PX4_TARGET_OS)/board_*.mk)))) BOARDS ?= $(KNOWN_BOARDS) # @@ -97,146 +97,31 @@ upload: endif endif -# -# Built products -# -DESIRED_FIRMWARES = $(foreach config,$(CONFIGS),$(IMAGE_DIR)$(config).px4) -STAGED_FIRMWARES = $(foreach config,$(KNOWN_CONFIGS),$(IMAGE_DIR)$(config).px4) -FIRMWARES = $(foreach config,$(KNOWN_CONFIGS),$(BUILD_DIR)$(config).build/firmware.px4) - -all: $(DESIRED_FIRMWARES) - -# -# Copy FIRMWARES into the image directory. -# -# XXX copying the .bin files is a hack to work around the PX4IO uploader -# not supporting .px4 files, and it should be deprecated onced that -# is taken care of. -# -$(STAGED_FIRMWARES): $(IMAGE_DIR)%.px4: $(BUILD_DIR)%.build/firmware.px4 - @$(ECHO) %% Copying $@ - $(Q) $(COPY) $< $@ - $(Q) $(COPY) $(patsubst %.px4,%.bin,$<) $(patsubst %.px4,%.bin,$@) - -# -# Generate FIRMWARES. -# -.PHONY: $(FIRMWARES) -$(BUILD_DIR)%.build/firmware.px4: config = $(patsubst $(BUILD_DIR)%.build/firmware.px4,%,$@) -$(BUILD_DIR)%.build/firmware.px4: work_dir = $(BUILD_DIR)$(config).build/ -$(FIRMWARES): $(BUILD_DIR)%.build/firmware.px4: generateuorbtopicheaders checksubmodules - @$(ECHO) %%%% - @$(ECHO) %%%% Building $(config) in $(work_dir) - @$(ECHO) %%%% - $(Q) $(MKDIR) -p $(work_dir) - $(Q) $(MAKE) -r -C $(work_dir) \ - -f $(PX4_MK_DIR)firmware.mk \ - CONFIG=$(config) \ - WORK_DIR=$(work_dir) \ - $(FIRMWARE_GOAL) - -# -# Make FMU firmwares depend on the corresponding IO firmware. -# -# This is a pretty vile hack, since it hard-codes knowledge of the FMU->IO dependency -# and forces the _default config in all cases. There has to be a better way to do this... -# -FMU_VERSION = $(patsubst px4fmu-%,%,$(word 1, $(subst _, ,$(1)))) -define FMU_DEP -$(BUILD_DIR)$(1).build/firmware.px4: $(IMAGE_DIR)px4io-$(call FMU_VERSION,$(1))_default.px4 -endef -FMU_CONFIGS := $(filter px4fmu%,$(CONFIGS)) -$(foreach config,$(FMU_CONFIGS),$(eval $(call FMU_DEP,$(config)))) - -# -# Build the NuttX export archives. -# -# Note that there are no explicit dependencies extended from these -# archives. If NuttX is updated, the user is expected to rebuild the -# archives/build area manually. Likewise, when the 'archives' target is -# invoked, all archives are always rebuilt. -# -# XXX Should support fetching/unpacking from a separate directory to permit -# downloads of the prebuilt archives as well... -# -NUTTX_ARCHIVES = $(foreach board,$(BOARDS),$(ARCHIVE_DIR)$(board).export) -.PHONY: archives -archives: checksubmodules $(NUTTX_ARCHIVES) - -# We cannot build these parallel; note that we also force -j1 for the -# sub-make invocations. -ifneq ($(filter archives,$(MAKECMDGOALS)),) -.NOTPARALLEL: +ifeq ($(PX4_TARGET_OS),nuttx) +include $(PX4_BASE)makefiles/firmware_nuttx.mk endif - -J?=1 - -$(ARCHIVE_DIR)%.export: board = $(notdir $(basename $@)) -$(ARCHIVE_DIR)%.export: configuration = nsh -$(NUTTX_ARCHIVES): $(ARCHIVE_DIR)%.export: $(NUTTX_SRC) - @$(ECHO) %% Configuring NuttX for $(board) - $(Q) (cd $(NUTTX_SRC) && $(RMDIR) nuttx-export) - $(Q) $(MAKE) -r -j$(J) -C $(NUTTX_SRC) -r $(MQUIET) distclean - $(Q) (cd $(NUTTX_SRC)/configs && $(COPYDIR) $(PX4_BASE)nuttx-configs/$(board) .) - $(Q) (cd $(NUTTX_SRC)tools && ./configure.sh $(board)/$(configuration)) - @$(ECHO) %% Exporting NuttX for $(board) - $(Q) $(MAKE) -r -j$(J) -C $(NUTTX_SRC) -r $(MQUIET) CONFIG_ARCH_BOARD=$(board) export - $(Q) $(MKDIR) -p $(dir $@) - $(Q) $(COPY) $(NUTTX_SRC)nuttx-export.zip $@ - $(Q) (cd $(NUTTX_SRC)/configs && $(RMDIR) $(board)) - -# -# The user can run the NuttX 'menuconfig' tool for a single board configuration with -# make BOARDS= menuconfig -# -ifeq ($(MAKECMDGOALS),menuconfig) -ifneq ($(words $(BOARDS)),1) -$(error BOARDS must specify exactly one board for the menuconfig goal) +ifeq ($(PX4_TARGET_OS),linux) +include $(PX4_BASE)makefiles/firmware_linux.mk endif -BOARD = $(BOARDS) -menuconfig: $(NUTTX_SRC) - @$(ECHO) %% Configuring NuttX for $(BOARD) - $(Q) (cd $(NUTTX_SRC) && $(RMDIR) nuttx-export) - $(Q) $(MAKE) -r -j$(J) -C $(NUTTX_SRC) -r $(MQUIET) distclean - $(Q) (cd $(NUTTX_SRC)/configs && $(COPYDIR) $(PX4_BASE)nuttx-configs/$(BOARD) .) - $(Q) (cd $(NUTTX_SRC)tools && ./configure.sh $(BOARD)/nsh) - @$(ECHO) %% Running menuconfig for $(BOARD) - $(Q) $(MAKE) -r -j$(J) -C $(NUTTX_SRC) -r $(MQUIET) menuconfig - @$(ECHO) %% Saving configuration file - $(Q)$(COPY) $(NUTTX_SRC).config $(PX4_BASE)nuttx-configs/$(BOARD)/nsh/defconfig -else -menuconfig: - @$(ECHO) "" - @$(ECHO) "The menuconfig goal must be invoked without any other goal being specified" - @$(ECHO) "" -endif - -$(NUTTX_SRC): checksubmodules - -$(UAVCAN_DIR): - $(Q) (./Tools/check_submodules.sh) - -.PHONY: checksubmodules -checksubmodules: - $(Q) ($(PX4_BASE)/Tools/check_submodules.sh) - -.PHONY: updatesubmodules -updatesubmodules: - $(Q) (git submodule init) - $(Q) (git submodule update) MSG_DIR = $(PX4_BASE)msg UORB_TEMPLATE_DIR = $(PX4_BASE)msg/templates/uorb MULTIPLATFORM_TEMPLATE_DIR = $(PX4_BASE)msg/templates/px4/uorb TOPICS_DIR = $(PX4_BASE)src/modules/uORB/topics -MULTIPLATFORM_HEADER_DIR = $(PX4_BASE)src/platforms/nuttx/px4_messages +MULTIPLATFORM_HEADER_DIR = $(PX4_BASE)src/platforms/$(PX4_TARGET_OS)/px4_messages MULTIPLATFORM_PREFIX = px4_ TOPICHEADER_TEMP_DIR = $(BUILD_DIR)topics_temporary GENMSG_PYTHONPATH = $(PX4_BASE)Tools/genmsg/src GENCPP_PYTHONPATH = $(PX4_BASE)Tools/gencpp/src +ifeq ($(PX4_TARGET_OS),nuttx) +OS_DEPS = checksubmodules +else +OS_DEPS = +endif + .PHONY: generateuorbtopicheaders -generateuorbtopicheaders: checksubmodules +generateuorbtopicheaders: $(OS_DEPS) @$(ECHO) "Generating uORB topic headers" $(Q) (PYTHONPATH=$(GENMSG_PYTHONPATH):$(GENCPP_PYTHONPATH):$(PYTHONPATH) $(PYTHON) \ $(PX4_BASE)Tools/px_generate_uorb_topic_headers.py \ diff --git a/makefiles/README.txt b/makefiles/README.txt index 8b84e4c40d..36edf6a47b 100644 --- a/makefiles/README.txt +++ b/makefiles/README.txt @@ -7,8 +7,9 @@ with Makefile in the parent directory. ../Makefile - Top-level makefile for the PX4 build system. This makefile supports - building NuttX archives, as well as supervising the building of all + Top-level makefile for the PX4 build system. + This makefile supports building NuttX archives for the NuttX based + configurations, as well as supervising the building of all of the defined PX4 firmware configurations. Try 'make help' in the parent directory for documentation. @@ -25,6 +26,14 @@ firmware.mk source tree. When used in this mode, at least BOARD, MODULES and CONFIG_FILE must be set. +firmware_nuttx.mk + + Called by firmware.mk to build NuttX based firmware. + +firmware_linux.mk + + Called by firmware.mk to build Linux (non-ROS) based firmware. + module.mk Called by firmware.mk to build individual modules. @@ -34,22 +43,28 @@ module.mk nuttx.mk - Called by ../Makefile to build or download the NuttX archives. + Called by ../Makefile to build or download the NuttX archives if + PX4_TARGET_OS is set to "nuttx". + +linux.mk + + Called by ../Makefile to set Linux specific parameters if + PX4_TARGET_OS is set to "linux". upload.mk Called by ../Makefile to upload files to a target board. Can be used - by external build systems as well. + by external build systems as well. (NuttX targets only) setup.mk - Provides common path and tool definitions. Implements host system-specific - compatibility hacks. + Provides common path and tool definitions. Implements host + system-specific compatibility hacks. Sets PX4_TARGET_OS. board_.mk - Board-specific configuration for . Typically sets CONFIG_ARCH - and then includes the toolchain definition for the board. + Board-specific configuration for . Typically sets + CONFIG_ARCH and then includes the toolchain definition for the board. config__.mk diff --git a/makefiles/firmware.mk b/makefiles/firmware.mk index 4c10de931c..814bf8b8d6 100644 --- a/makefiles/firmware.mk +++ b/makefiles/firmware.mk @@ -132,7 +132,7 @@ include $(MK_DIR)/setup.mk ifneq ($(CONFIG_FILE),) CONFIG := $(subst config_,,$(basename $(notdir $(CONFIG_FILE)))) else -CONFIG_FILE := $(wildcard $(PX4_MK_DIR)/config_$(CONFIG).mk) +CONFIG_FILE := $(wildcard $(PX4_MK_DIR)/$(PX4_TARGET_OS)/config_$(CONFIG).mk) endif ifeq ($(CONFIG),) $(error Missing configuration name or file (specify with CONFIG=)) @@ -150,7 +150,7 @@ $(info % CONFIG = $(CONFIG)) ifeq ($(BOARD),) BOARD := $(firstword $(subst _, ,$(CONFIG))) endif -BOARD_FILE := $(wildcard $(PX4_MK_DIR)/board_$(BOARD).mk) +BOARD_FILE := $(wildcard $(PX4_MK_DIR)/$(PX4_TARGET_OS)/board_$(BOARD).mk) ifeq ($(BOARD_FILE),) $(error Config $(CONFIG) references board $(BOARD), but no board definition file found) endif @@ -186,10 +186,10 @@ EXTRA_CLEANS = INCLUDE_DIRS += $(PX4_MODULE_SRC)drivers/boards/$(BOARD) ################################################################################ -# NuttX libraries and paths +# OS specific libraries and paths ################################################################################ -include $(PX4_MK_DIR)/nuttx.mk +include $(PX4_MK_DIR)/$(PX4_TARGET_OS).mk ################################################################################ # Modules @@ -311,130 +311,6 @@ $(LIBRARY_CLEANS): LIBRARY_MK=$(mkfile) \ clean -################################################################################ -# ROMFS generation -################################################################################ - -ifneq ($(ROMFS_ROOT),) -ifeq ($(wildcard $(ROMFS_ROOT)),) -$(error ROMFS_ROOT specifies a directory that does not exist) -endif - -# -# Note that there is no support for more than one root directory or constructing -# a root from several templates. That would be a nice feature. -# - -# Add dependencies on anything in the ROMFS root directory -ROMFS_FILES += $(wildcard \ - $(ROMFS_ROOT)/* \ - $(ROMFS_ROOT)/*/* \ - $(ROMFS_ROOT)/*/*/* \ - $(ROMFS_ROOT)/*/*/*/* \ - $(ROMFS_ROOT)/*/*/*/*/* \ - $(ROMFS_ROOT)/*/*/*/*/*/*) -ifeq ($(ROMFS_FILES),) -$(error ROMFS_ROOT $(ROMFS_ROOT) specifies a directory containing no files) -endif -ROMFS_DEPS += $(ROMFS_FILES) - -# Extra files that may be copied into the ROMFS /extras directory -# ROMFS_EXTRA_FILES are required, ROMFS_OPTIONAL_FILES are optional -ROMFS_EXTRA_FILES += $(wildcard $(ROMFS_OPTIONAL_FILES)) -ROMFS_DEPS += $(ROMFS_EXTRA_FILES) - -ROMFS_IMG = romfs.img -ROMFS_SCRATCH = romfs_scratch -ROMFS_CSRC = $(ROMFS_IMG:.img=.c) -ROMFS_OBJ = $(ROMFS_CSRC:.c=.o) -LIBS += $(ROMFS_OBJ) -LINK_DEPS += $(ROMFS_OBJ) - -# Remove all comments from startup and mixer files -ROMFS_PRUNER = $(PX4_BASE)/Tools/px_romfs_pruner.py - -# Turn the ROMFS image into an object file -$(ROMFS_OBJ): $(ROMFS_IMG) $(GLOBAL_DEPS) - $(call BIN_TO_OBJ,$<,$@,romfs_img) - -# Generate the ROMFS image from the root -$(ROMFS_IMG): $(ROMFS_SCRATCH) $(ROMFS_DEPS) $(GLOBAL_DEPS) - @$(ECHO) "ROMFS: $@" - $(Q) $(GENROMFS) -f $@ -d $(ROMFS_SCRATCH) -V "NSHInitVol" - -# Construct the ROMFS scratch root from the canonical root -$(ROMFS_SCRATCH): $(ROMFS_DEPS) $(GLOBAL_DEPS) - $(Q) $(MKDIR) -p $(ROMFS_SCRATCH) - $(Q) $(COPYDIR) $(ROMFS_ROOT)/* $(ROMFS_SCRATCH) -# delete all files in ROMFS_SCRATCH which start with a . or end with a ~ - $(Q) $(RM) $(ROMFS_SCRATCH)/*/.[!.]* $(ROMFS_SCRATCH)/*/*~ -ifneq ($(ROMFS_EXTRA_FILES),) - $(Q) $(MKDIR) -p $(ROMFS_SCRATCH)/extras - $(Q) $(COPY) $(ROMFS_EXTRA_FILES) $(ROMFS_SCRATCH)/extras -endif - $(Q) $(PYTHON) -u $(ROMFS_PRUNER) --folder $(ROMFS_SCRATCH) - -EXTRA_CLEANS += $(ROMGS_OBJ) $(ROMFS_IMG) - -endif - -################################################################################ -# Builtin command list generation -################################################################################ - -# -# Builtin commands can be generated by the configuration, in which case they -# must refer to commands that already exist, or indirectly generated by modules -# when they are built. -# -# The configuration supplies builtin command information in the BUILTIN_COMMANDS -# variable. Applications make empty files in $(WORK_DIR)/builtin_commands whose -# filename contains the same information. -# -# In each case, the command information consists of four fields separated with a -# period. These fields are the command's name, its thread priority, its stack size -# and the name of the function to call when starting the thread. -# -BUILTIN_CSRC = $(WORK_DIR)builtin_commands.c - -# command definitions from modules (may be empty at Makefile parsing time...) -MODULE_COMMANDS = $(subst COMMAND.,,$(notdir $(wildcard $(WORK_DIR)builtin_commands/COMMAND.*))) - -# We must have at least one pre-defined builtin command in order to generate -# any of this. -# -ifneq ($(BUILTIN_COMMANDS),) - -# (BUILTIN_PROTO,,) -define BUILTIN_PROTO - $(ECHO) 'extern int $(word 4,$1)(int argc, char *argv[]);' >> $2; -endef - -# (BUILTIN_DEF,,) -define BUILTIN_DEF - $(ECHO) ' {"$(word 1,$1)", $(word 2,$1), $(word 3,$1), $(word 4,$1)},' >> $2; -endef - -# Don't generate until modules have updated their command files -$(BUILTIN_CSRC): $(GLOBAL_DEPS) $(MODULE_OBJS) $(MODULE_MKFILES) $(BUILTIN_COMMAND_FILES) - @$(ECHO) "CMDS: $@" - $(Q) $(ECHO) '/* builtin command list - automatically generated, do not edit */' > $@ - $(Q) $(ECHO) '#include ' >> $@ - $(Q) $(ECHO) '#include ' >> $@ - $(Q) $(foreach spec,$(BUILTIN_COMMANDS),$(call BUILTIN_PROTO,$(subst ., ,$(spec)),$@)) - $(Q) $(foreach spec,$(MODULE_COMMANDS),$(call BUILTIN_PROTO,$(subst ., ,$(spec)),$@)) - $(Q) $(ECHO) 'const struct builtin_s g_builtins[] = {' >> $@ - $(Q) $(foreach spec,$(BUILTIN_COMMANDS),$(call BUILTIN_DEF,$(subst ., ,$(spec)),$@)) - $(Q) $(foreach spec,$(MODULE_COMMANDS),$(call BUILTIN_DEF,$(subst ., ,$(spec)),$@)) - $(Q) $(ECHO) ' {NULL, 0, 0, NULL}' >> $@ - $(Q) $(ECHO) '};' >> $@ - $(Q) $(ECHO) 'const int g_builtin_count = $(words $(BUILTIN_COMMANDS) $(MODULE_COMMANDS));' >> $@ - -SRCS += $(BUILTIN_CSRC) - -EXTRA_CLEANS += $(BUILTIN_CSRC) - -endif ################################################################################ # Default SRCS generation @@ -453,20 +329,9 @@ SRCS += $(EMPTY_SRC) endif ################################################################################ -# Build rules +# Generic Build rules ################################################################################ -# -# What we're going to build. -# -PRODUCT_BUNDLE = $(WORK_DIR)firmware.px4 -PRODUCT_BIN = $(WORK_DIR)firmware.bin -PRODUCT_ELF = $(WORK_DIR)firmware.elf -PRODUCT_PARAMXML = $(WORK_DIR)/parameters.xml - -.PHONY: firmware -firmware: $(PRODUCT_BUNDLE) - # # Object files we will generate from sources # @@ -488,49 +353,16 @@ $(filter %.S.o,$(OBJS)): $(WORK_DIR)%.S.o: %.S $(GLOBAL_DEPS) $(call ASSEMBLE,$<,$@) # -# Built product rules +# Include the OS specific build rules +# The rules must define the "firmware" make target # -$(PRODUCT_BUNDLE): $(PRODUCT_BIN) - @$(ECHO) %% Generating $@ -ifdef GEN_PARAM_XML - python $(PX4_BASE)/Tools/px_process_params.py --src-path $(PX4_BASE)/src --xml - $(Q) $(MKFW) --prototype $(IMAGE_DIR)/$(BOARD).prototype \ - --git_identity $(PX4_BASE) \ - --parameter_xml $(PRODUCT_PARAMXML) \ - --image $< > $@ -else - $(Q) $(MKFW) --prototype $(IMAGE_DIR)/$(BOARD).prototype \ - --git_identity $(PX4_BASE) \ - --image $< > $@ +ifeq ($(PX4_TARGET_OS),nuttx) +include $(MK_DIR)/nuttx_romfs.mk +endif +ifeq ($(PX4_TARGET_OS),linux) +include $(MK_DIR)/linux_elf.mk endif - -$(PRODUCT_BIN): $(PRODUCT_ELF) - $(call SYM_TO_BIN,$<,$@) - -$(PRODUCT_ELF): $(OBJS) $(MODULE_OBJS) $(LIBRARY_LIBS) $(GLOBAL_DEPS) $(LINK_DEPS) $(MODULE_MKFILES) - $(call LINK,$@,$(OBJS) $(MODULE_OBJS) $(LIBRARY_LIBS)) - -# -# Utility rules -# - -.PHONY: upload -upload: $(PRODUCT_BUNDLE) $(PRODUCT_BIN) - $(Q) $(MAKE) -f $(PX4_MK_DIR)/upload.mk \ - METHOD=serial \ - CONFIG=$(CONFIG) \ - BOARD=$(BOARD) \ - BUNDLE=$(PRODUCT_BUNDLE) \ - BIN=$(PRODUCT_BIN) - -.PHONY: clean -clean: $(MODULE_CLEANS) - @$(ECHO) %% cleaning - $(Q) $(REMOVE) $(PRODUCT_BUNDLE) $(PRODUCT_BIN) $(PRODUCT_ELF) - $(Q) $(REMOVE) $(OBJS) $(DEP_INCLUDES) $(EXTRA_CLEANS) - $(Q) $(RMDIR) $(NUTTX_EXPORT_DIR) - # # DEP_INCLUDES is defined by the toolchain include in terms of $(OBJS) diff --git a/makefiles/firmware_linux.mk b/makefiles/firmware_linux.mk new file mode 100644 index 0000000000..6acec4e733 --- /dev/null +++ b/makefiles/firmware_linux.mk @@ -0,0 +1,56 @@ +# +# Copyright (c) 2012-2015 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. +# + +# +# Built products +# +FIRMWARES = $(foreach config,$(KNOWN_CONFIGS),$(BUILD_DIR)$(config).build/firmware.a) + +all: $(FIRMWARES) + +# +# Generate FIRMWARES. +# +.PHONY: $(FIRMWARES) +$(BUILD_DIR)%.build/firmware.a: config = $(patsubst $(BUILD_DIR)%.build/firmware.a,%,$@) +$(BUILD_DIR)%.build/firmware.a: work_dir = $(BUILD_DIR)$(config).build/ +$(FIRMWARES): $(BUILD_DIR)%.build/firmware.a: generateuorbtopicheaders + @$(ECHO) %%%% + @$(ECHO) %%%% Building $(config) in $(work_dir) + @$(ECHO) %%%% + $(Q) $(MKDIR) -p $(work_dir) + $(Q) $(MAKE) -r -C $(work_dir) \ + -f $(PX4_MK_DIR)firmware.mk \ + CONFIG=$(config) \ + WORK_DIR=$(work_dir) \ + $(FIRMWARE_GOAL) + + diff --git a/makefiles/firmware_nuttx.mk b/makefiles/firmware_nuttx.mk new file mode 100644 index 0000000000..fb97ca4217 --- /dev/null +++ b/makefiles/firmware_nuttx.mk @@ -0,0 +1,160 @@ +# +# Copyright (c) 2012-2015 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. +# + +# +# Built products +# + +DESIRED_FIRMWARES = $(foreach config,$(CONFIGS),$(IMAGE_DIR)$(config).px4) +STAGED_FIRMWARES = $(foreach config,$(KNOWN_CONFIGS),$(IMAGE_DIR)$(config).px4) +FIRMWARES = $(foreach config,$(KNOWN_CONFIGS),$(BUILD_DIR)$(config).build/firmware.px4) + +all: $(DESIRED_FIRMWARES) + +# +# Copy FIRMWARES into the image directory. +# +# XXX copying the .bin files is a hack to work around the PX4IO uploader +# not supporting .px4 files, and it should be deprecated onced that +# is taken care of. +# +$(STAGED_FIRMWARES): $(IMAGE_DIR)%.px4: $(BUILD_DIR)%.build/firmware.px4 + @$(ECHO) %% Copying $@ + $(Q) $(COPY) $< $@ + $(Q) $(COPY) $(patsubst %.px4,%.bin,$<) $(patsubst %.px4,%.bin,$@) + +# +# Generate FIRMWARES. +# +.PHONY: $(FIRMWARES) +$(BUILD_DIR)%.build/firmware.px4: config = $(patsubst $(BUILD_DIR)%.build/firmware.px4,%,$@) +$(BUILD_DIR)%.build/firmware.px4: work_dir = $(BUILD_DIR)$(config).build/ +$(FIRMWARES): $(BUILD_DIR)%.build/firmware.px4: generateuorbtopicheaders checksubmodules + @$(ECHO) %%%% + @$(ECHO) %%%% Building $(config) in $(work_dir) + @$(ECHO) %%%% + $(Q) $(MKDIR) -p $(work_dir) + $(Q) $(MAKE) -r -C $(work_dir) \ + -f $(PX4_MK_DIR)firmware.mk \ + CONFIG=$(config) \ + WORK_DIR=$(work_dir) \ + $(FIRMWARE_GOAL) + +# +# Make FMU firmwares depend on the corresponding IO firmware. +# +# This is a pretty vile hack, since it hard-codes knowledge of the FMU->IO dependency +# and forces the _default config in all cases. There has to be a better way to do this... +# +FMU_VERSION = $(patsubst px4fmu-%,%,$(word 1, $(subst _, ,$(1)))) +define FMU_DEP +$(BUILD_DIR)$(1).build/firmware.px4: $(IMAGE_DIR)px4io-$(call FMU_VERSION,$(1))_default.px4 +endef +FMU_CONFIGS := $(filter px4fmu%,$(CONFIGS)) +$(foreach config,$(FMU_CONFIGS),$(eval $(call FMU_DEP,$(config)))) + +# +# Build the NuttX export archives. +# +# Note that there are no explicit dependencies extended from these +# archives. If NuttX is updated, the user is expected to rebuild the +# archives/build area manually. Likewise, when the 'archives' target is +# invoked, all archives are always rebuilt. +# +# XXX Should support fetching/unpacking from a separate directory to permit +# downloads of the prebuilt archives as well... +# +NUTTX_ARCHIVES = $(foreach board,$(BOARDS),$(ARCHIVE_DIR)$(board).export) +.PHONY: archives +archives: checksubmodules $(NUTTX_ARCHIVES) + +# We cannot build these parallel; note that we also force -j1 for the +# sub-make invocations. +ifneq ($(filter archives,$(MAKECMDGOALS)),) +.NOTPARALLEL: +endif + +J?=1 + +$(ARCHIVE_DIR)%.export: board = $(notdir $(basename $@)) +$(ARCHIVE_DIR)%.export: configuration = nsh +$(NUTTX_ARCHIVES): $(ARCHIVE_DIR)%.export: $(NUTTX_SRC) + @$(ECHO) %% Configuring NuttX for $(board) + $(Q) (cd $(NUTTX_SRC) && $(RMDIR) nuttx-export) + $(Q) $(MAKE) -r -j$(J) -C $(NUTTX_SRC) -r $(MQUIET) distclean + $(Q) (cd $(NUTTX_SRC)/configs && $(COPYDIR) $(PX4_BASE)nuttx-configs/$(board) .) + $(Q) (cd $(NUTTX_SRC)tools && ./configure.sh $(board)/$(configuration)) + @$(ECHO) %% Exporting NuttX for $(board) + $(Q) $(MAKE) -r -j$(J) -C $(NUTTX_SRC) -r $(MQUIET) CONFIG_ARCH_BOARD=$(board) export + $(Q) $(MKDIR) -p $(dir $@) + $(Q) $(COPY) $(NUTTX_SRC)nuttx-export.zip $@ + $(Q) (cd $(NUTTX_SRC)/configs && $(RMDIR) $(board)) + +# +# The user can run the NuttX 'menuconfig' tool for a single board configuration with +# make BOARDS= menuconfig +# +ifeq ($(MAKECMDGOALS),menuconfig) +ifneq ($(words $(BOARDS)),1) +$(error BOARDS must specify exactly one board for the menuconfig goal) +endif +BOARD = $(BOARDS) +menuconfig: $(NUTTX_SRC) + @$(ECHO) %% Configuring NuttX for $(BOARD) + $(Q) (cd $(NUTTX_SRC) && $(RMDIR) nuttx-export) + $(Q) $(MAKE) -r -j$(J) -C $(NUTTX_SRC) -r $(MQUIET) distclean + $(Q) (cd $(NUTTX_SRC)/configs && $(COPYDIR) $(PX4_BASE)nuttx-configs/$(BOARD) .) + $(Q) (cd $(NUTTX_SRC)tools && ./configure.sh $(BOARD)/nsh) + @$(ECHO) %% Running menuconfig for $(BOARD) + $(Q) $(MAKE) -r -j$(J) -C $(NUTTX_SRC) -r $(MQUIET) menuconfig + @$(ECHO) %% Saving configuration file + $(Q)$(COPY) $(NUTTX_SRC).config $(PX4_BASE)nuttx-configs/$(BOARD)/nsh/defconfig +else +menuconfig: + @$(ECHO) "" + @$(ECHO) "The menuconfig goal must be invoked without any other goal being specified" + @$(ECHO) "" +endif + +$(NUTTX_SRC): checksubmodules + +$(UAVCAN_DIR): + $(Q) (./Tools/check_submodules.sh) + +.PHONY: checksubmodules +checksubmodules: + $(Q) ($(PX4_BASE)/Tools/check_submodules.sh) + +.PHONY: updatesubmodules +updatesubmodules: + $(Q) (git submodule init) + $(Q) (git submodule update) + diff --git a/makefiles/library.mk b/makefiles/library.mk index 28a421fe0e..e20fcce941 100644 --- a/makefiles/library.mk +++ b/makefiles/library.mk @@ -93,7 +93,7 @@ $(info %% LIBRARY_MK = $(LIBRARY_MK)) # # Get the board/toolchain config # -include $(PX4_MK_DIR)/board_$(BOARD).mk +include $(PX4_MK_DIR)/$(PX4_TARGET_OS)/board_$(BOARD).mk # # Get the library's config diff --git a/makefiles/linux.mk b/makefiles/linux.mk new file mode 100644 index 0000000000..b424521a4b --- /dev/null +++ b/makefiles/linux.mk @@ -0,0 +1,38 @@ +# +# Copyright (C) 2012 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. +# + +# +# Rules and definitions related to handling the Linux specific impl when +# building firmware. +# + +MODULES += platforms/linux/px4_layer + diff --git a/makefiles/linux/board_linux.mk b/makefiles/linux/board_linux.mk new file mode 100644 index 0000000000..ffdfd036a5 --- /dev/null +++ b/makefiles/linux/board_linux.mk @@ -0,0 +1,11 @@ +# +# Board-specific definitions for the Linux port of PX4 +# + +# +# Configure the toolchain +# +CONFIG_ARCH = NATIVE +CONFIG_BOARD = FOO + +include $(PX4_MK_DIR)/toolchain_native.mk diff --git a/makefiles/linux/config_linux_default.mk b/makefiles/linux/config_linux_default.mk new file mode 100644 index 0000000000..57721c0db4 --- /dev/null +++ b/makefiles/linux/config_linux_default.mk @@ -0,0 +1,64 @@ +# +# Makefile for the Foo *default* configuration +# + +# +# Use the configuration's ROMFS. +# +ROMFS_ROOT = $(PX4_BASE)/ROMFS/px4fmu_common + +# +# Board support modules +# +#MODULES += drivers/dxl +#MODULES += drivers/i2c_pwm +#MODULES += drivers/lemonrx +#MODULES += drivers/mpu9x50 +#MODULES += drivers/um7 +MODULES += drivers/device +MODULES += modules/sensors + +# +# System commands +# +#MODULES += systemcmds/boardinfo + +# +# General system control +# +#MODULES += modules/mavlink +MODULES += modules/mavlink + +# +# Estimation modules (EKF/ SO3 / other filters) +# +MODULES += modules/attitude_estimator_ekf + +# +# Vehicle Control +# +MODULES += modules/mc_att_control + +# +# Library modules +# +MODULES += modules/systemlib +MODULES += modules/systemlib/mixer +MODULES += modules/uORB +MODULES += modules/dataman + +# +# Libraries +# +MODULES += lib/mathlib +MODULES += lib/geo +MODULES += lib/geo_lookup +MODULES += lib/conversion +#MODULES += lib/utils + +# +# Linux port +# +MODULES += platforms/linux/px4_layer +MODULES += platforms/linux/publisher + diff --git a/makefiles/linux_elf.mk b/makefiles/linux_elf.mk new file mode 100644 index 0000000000..18578a55c1 --- /dev/null +++ b/makefiles/linux_elf.mk @@ -0,0 +1,69 @@ +# +# Copyright (C) 2012 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. +# + +# +# Makefile for PX4 Linux based firmware images. +# + +################################################################################ +# Build rules +################################################################################ + +# +# What we're going to build. +# +PRODUCT_SHARED_LIB = $(WORK_DIR)firmware.a + +.PHONY: firmware +firmware: $(PRODUCT_SHARED_LIB) $(WORK_DIR)mainapp + +# +# Built product rules +# + +$(PRODUCT_SHARED_LIB): $(OBJS) $(MODULE_OBJS) $(LIBRARY_LIBS) $(GLOBAL_DEPS) $(LINK_DEPS) $(MODULE_MKFILES) + $(call LINK_A,$@,$(OBJS) $(MODULE_OBJS) $(LIBRARY_LIBS)) + +MAIN = $(PX4_BASE)/src/platforms/linux/main.cpp +$(WORK_DIR)mainapp: $(PRODUCT_SHARED_LIB) + $(PX4_BASE)/Tools/linux_apps.py > apps.h + $(call LINK,$@, -I. $(MAIN) $(PRODUCT_SHARED_LIB)) + +# +# Utility rules +# + +.PHONY: clean +clean: $(MODULE_CLEANS) + @$(ECHO) %% cleaning + $(Q) $(REMOVE) $(PRODUCT_ELF) + $(Q) $(REMOVE) $(OBJS) $(DEP_INCLUDES) $(EXTRA_CLEANS) + diff --git a/makefiles/nuttx.mk b/makefiles/nuttx.mk index bf07441408..a151e7d917 100644 --- a/makefiles/nuttx.mk +++ b/makefiles/nuttx.mk @@ -34,6 +34,8 @@ # building firmware. # +#MODULES += platforms/nuttx/px4_layer + # # Check that the NuttX archive for the selected board is available. # diff --git a/makefiles/board_aerocore.mk b/makefiles/nuttx/board_aerocore.mk similarity index 100% rename from makefiles/board_aerocore.mk rename to makefiles/nuttx/board_aerocore.mk diff --git a/makefiles/board_px4fmu-v1.mk b/makefiles/nuttx/board_px4fmu-v1.mk similarity index 100% rename from makefiles/board_px4fmu-v1.mk rename to makefiles/nuttx/board_px4fmu-v1.mk diff --git a/makefiles/board_px4fmu-v2.mk b/makefiles/nuttx/board_px4fmu-v2.mk similarity index 100% rename from makefiles/board_px4fmu-v2.mk rename to makefiles/nuttx/board_px4fmu-v2.mk diff --git a/makefiles/board_px4io-v1.mk b/makefiles/nuttx/board_px4io-v1.mk similarity index 100% rename from makefiles/board_px4io-v1.mk rename to makefiles/nuttx/board_px4io-v1.mk diff --git a/makefiles/board_px4io-v2.mk b/makefiles/nuttx/board_px4io-v2.mk similarity index 100% rename from makefiles/board_px4io-v2.mk rename to makefiles/nuttx/board_px4io-v2.mk diff --git a/makefiles/config_aerocore_default.mk b/makefiles/nuttx/config_aerocore_default.mk similarity index 100% rename from makefiles/config_aerocore_default.mk rename to makefiles/nuttx/config_aerocore_default.mk diff --git a/makefiles/config_px4fmu-v1_default.mk b/makefiles/nuttx/config_px4fmu-v1_default.mk similarity index 100% rename from makefiles/config_px4fmu-v1_default.mk rename to makefiles/nuttx/config_px4fmu-v1_default.mk diff --git a/makefiles/config_px4fmu-v2_default.mk b/makefiles/nuttx/config_px4fmu-v2_default.mk similarity index 100% rename from makefiles/config_px4fmu-v2_default.mk rename to makefiles/nuttx/config_px4fmu-v2_default.mk diff --git a/makefiles/config_px4fmu-v2_multiplatform.mk b/makefiles/nuttx/config_px4fmu-v2_multiplatform.mk similarity index 100% rename from makefiles/config_px4fmu-v2_multiplatform.mk rename to makefiles/nuttx/config_px4fmu-v2_multiplatform.mk diff --git a/makefiles/config_px4fmu-v2_test.mk b/makefiles/nuttx/config_px4fmu-v2_test.mk similarity index 100% rename from makefiles/config_px4fmu-v2_test.mk rename to makefiles/nuttx/config_px4fmu-v2_test.mk diff --git a/makefiles/config_px4io-v1_default.mk b/makefiles/nuttx/config_px4io-v1_default.mk similarity index 100% rename from makefiles/config_px4io-v1_default.mk rename to makefiles/nuttx/config_px4io-v1_default.mk diff --git a/makefiles/config_px4io-v2_default.mk b/makefiles/nuttx/config_px4io-v2_default.mk similarity index 100% rename from makefiles/config_px4io-v2_default.mk rename to makefiles/nuttx/config_px4io-v2_default.mk diff --git a/makefiles/nuttx_romfs.mk b/makefiles/nuttx_romfs.mk new file mode 100644 index 0000000000..ca6fefe29e --- /dev/null +++ b/makefiles/nuttx_romfs.mk @@ -0,0 +1,219 @@ +# +# Copyright (C) 2012 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. +# + +# +# Makefile for PX4 Nuttx based firmware images. +# + +################################################################################ +# ROMFS generation +################################################################################ + +ifneq ($(ROMFS_ROOT),) +ifeq ($(wildcard $(ROMFS_ROOT)),) +$(error ROMFS_ROOT specifies a directory that does not exist) +endif + +# +# Note that there is no support for more than one root directory or constructing +# a root from several templates. That would be a nice feature. +# + +# Add dependencies on anything in the ROMFS root directory +ROMFS_FILES += $(wildcard \ + $(ROMFS_ROOT)/* \ + $(ROMFS_ROOT)/*/* \ + $(ROMFS_ROOT)/*/*/* \ + $(ROMFS_ROOT)/*/*/*/* \ + $(ROMFS_ROOT)/*/*/*/*/* \ + $(ROMFS_ROOT)/*/*/*/*/*/*) +ifeq ($(ROMFS_FILES),) +$(error ROMFS_ROOT $(ROMFS_ROOT) specifies a directory containing no files) +endif +ROMFS_DEPS += $(ROMFS_FILES) + +# Extra files that may be copied into the ROMFS /extras directory +# ROMFS_EXTRA_FILES are required, ROMFS_OPTIONAL_FILES are optional +ROMFS_EXTRA_FILES += $(wildcard $(ROMFS_OPTIONAL_FILES)) +ROMFS_DEPS += $(ROMFS_EXTRA_FILES) + +ROMFS_IMG = romfs.img +ROMFS_SCRATCH = romfs_scratch +ROMFS_CSRC = $(ROMFS_IMG:.img=.c) +ROMFS_OBJ = $(ROMFS_CSRC:.c=.o) +LIBS += $(ROMFS_OBJ) +LINK_DEPS += $(ROMFS_OBJ) + +# Remove all comments from startup and mixer files +ROMFS_PRUNER = $(PX4_BASE)/Tools/px_romfs_pruner.py + +# Turn the ROMFS image into an object file +$(ROMFS_OBJ): $(ROMFS_IMG) $(GLOBAL_DEPS) + $(call BIN_TO_OBJ,$<,$@,romfs_img) + +# Generate the ROMFS image from the root +$(ROMFS_IMG): $(ROMFS_SCRATCH) $(ROMFS_DEPS) $(GLOBAL_DEPS) + @$(ECHO) "ROMFS: $@" + $(Q) $(GENROMFS) -f $@ -d $(ROMFS_SCRATCH) -V "NSHInitVol" + +# Construct the ROMFS scratch root from the canonical root +$(ROMFS_SCRATCH): $(ROMFS_DEPS) $(GLOBAL_DEPS) + $(Q) $(MKDIR) -p $(ROMFS_SCRATCH) + $(Q) $(COPYDIR) $(ROMFS_ROOT)/* $(ROMFS_SCRATCH) +# delete all files in ROMFS_SCRATCH which start with a . or end with a ~ + $(Q) $(RM) $(ROMFS_SCRATCH)/*/.[!.]* $(ROMFS_SCRATCH)/*/*~ +ifneq ($(ROMFS_EXTRA_FILES),) + $(Q) $(MKDIR) -p $(ROMFS_SCRATCH)/extras + $(Q) $(COPY) $(ROMFS_EXTRA_FILES) $(ROMFS_SCRATCH)/extras +endif + $(Q) $(PYTHON) -u $(ROMFS_PRUNER) --folder $(ROMFS_SCRATCH) + +EXTRA_CLEANS += $(ROMGS_OBJ) $(ROMFS_IMG) + +endif + +################################################################################ +# Builtin command list generation +################################################################################ + +# +# Builtin commands can be generated by the configuration, in which case they +# must refer to commands that already exist, or indirectly generated by modules +# when they are built. +# +# The configuration supplies builtin command information in the BUILTIN_COMMANDS +# variable. Applications make empty files in $(WORK_DIR)/builtin_commands whose +# filename contains the same information. +# +# In each case, the command information consists of four fields separated with a +# period. These fields are the command's name, its thread priority, its stack size +# and the name of the function to call when starting the thread. +# +BUILTIN_CSRC = $(WORK_DIR)builtin_commands.c + +# command definitions from modules (may be empty at Makefile parsing time...) +MODULE_COMMANDS = $(subst COMMAND.,,$(notdir $(wildcard $(WORK_DIR)builtin_commands/COMMAND.*))) + +# We must have at least one pre-defined builtin command in order to generate +# any of this. +# +ifneq ($(BUILTIN_COMMANDS),) + +# (BUILTIN_PROTO,,) +define BUILTIN_PROTO + $(ECHO) 'extern int $(word 4,$1)(int argc, char *argv[]);' >> $2; +endef + +# (BUILTIN_DEF,,) +define BUILTIN_DEF + $(ECHO) ' {"$(word 1,$1)", $(word 2,$1), $(word 3,$1), $(word 4,$1)},' >> $2; +endef + +# Don't generate until modules have updated their command files +$(BUILTIN_CSRC): $(GLOBAL_DEPS) $(MODULE_OBJS) $(MODULE_MKFILES) $(BUILTIN_COMMAND_FILES) + @$(ECHO) "CMDS: $@" + $(Q) $(ECHO) '/* builtin command list - automatically generated, do not edit */' > $@ + $(Q) $(ECHO) '#include ' >> $@ + $(Q) $(ECHO) '#include ' >> $@ + $(Q) $(foreach spec,$(BUILTIN_COMMANDS),$(call BUILTIN_PROTO,$(subst ., ,$(spec)),$@)) + $(Q) $(foreach spec,$(MODULE_COMMANDS),$(call BUILTIN_PROTO,$(subst ., ,$(spec)),$@)) + $(Q) $(ECHO) 'const struct builtin_s g_builtins[] = {' >> $@ + $(Q) $(foreach spec,$(BUILTIN_COMMANDS),$(call BUILTIN_DEF,$(subst ., ,$(spec)),$@)) + $(Q) $(foreach spec,$(MODULE_COMMANDS),$(call BUILTIN_DEF,$(subst ., ,$(spec)),$@)) + $(Q) $(ECHO) ' {NULL, 0, 0, NULL}' >> $@ + $(Q) $(ECHO) '};' >> $@ + $(Q) $(ECHO) 'const int g_builtin_count = $(words $(BUILTIN_COMMANDS) $(MODULE_COMMANDS));' >> $@ + +SRCS += $(BUILTIN_CSRC) + +EXTRA_CLEANS += $(BUILTIN_CSRC) + +endif + +################################################################################ +# Build rules +################################################################################ + +# +# What we're going to build. +# +PRODUCT_BUNDLE = $(WORK_DIR)firmware.px4 +PRODUCT_BIN = $(WORK_DIR)firmware.bin +PRODUCT_ELF = $(WORK_DIR)firmware.elf +PRODUCT_PARAMXML = $(WORK_DIR)/parameters.xml + +.PHONY: firmware +firmware: $(PRODUCT_BUNDLE) + +# +# Built product rules +# + +$(PRODUCT_BUNDLE): $(PRODUCT_BIN) + @$(ECHO) %% Generating $@ +ifdef GEN_PARAM_XML + python $(PX4_BASE)/Tools/px_process_params.py --src-path $(PX4_BASE)/src --xml + $(Q) $(MKFW) --prototype $(IMAGE_DIR)/$(BOARD).prototype \ + --git_identity $(PX4_BASE) \ + --parameter_xml $(PRODUCT_PARAMXML) \ + --image $< > $@ +else + $(Q) $(MKFW) --prototype $(IMAGE_DIR)/$(BOARD).prototype \ + --git_identity $(PX4_BASE) \ + --image $< > $@ +endif + +$(PRODUCT_BIN): $(PRODUCT_ELF) + $(call SYM_TO_BIN,$<,$@) + +$(PRODUCT_ELF): $(OBJS) $(MODULE_OBJS) $(LIBRARY_LIBS) $(GLOBAL_DEPS) $(LINK_DEPS) $(MODULE_MKFILES) + $(call LINK,$@,$(OBJS) $(MODULE_OBJS) $(LIBRARY_LIBS)) + +# +# Utility rules +# + +.PHONY: upload +upload: $(PRODUCT_BUNDLE) $(PRODUCT_BIN) + $(Q) $(MAKE) -f $(PX4_MK_DIR)/upload.mk \ + METHOD=serial \ + CONFIG=$(CONFIG) \ + BOARD=$(BOARD) \ + BUNDLE=$(PRODUCT_BUNDLE) \ + BIN=$(PRODUCT_BIN) + +.PHONY: clean +clean: $(MODULE_CLEANS) + @$(ECHO) %% cleaning + $(Q) $(REMOVE) $(PRODUCT_BUNDLE) $(PRODUCT_BIN) $(PRODUCT_ELF) + $(Q) $(REMOVE) $(OBJS) $(DEP_INCLUDES) $(EXTRA_CLEANS) + $(Q) $(RMDIR) $(NUTTX_EXPORT_DIR) + diff --git a/makefiles/setup.mk b/makefiles/setup.mk index 351b9f1b71..1c6e5c3a2e 100644 --- a/makefiles/setup.mk +++ b/makefiles/setup.mk @@ -33,6 +33,9 @@ # Path and tool setup # +export PX4_TARGET_OS = nuttx +#export PX4_TARGET_OS = linux + # # Some useful paths. # diff --git a/makefiles/toolchain_gnu-arm-eabi.mk b/makefiles/toolchain_gnu-arm-eabi.mk index 3b9fefb3ef..7cf72bdad8 100644 --- a/makefiles/toolchain_gnu-arm-eabi.mk +++ b/makefiles/toolchain_gnu-arm-eabi.mk @@ -107,7 +107,7 @@ endif ifeq ($(CONFIG_BOARD),) $(error Board config does not define CONFIG_BOARD) endif -ARCHDEFINES += -DCONFIG_ARCH_BOARD_$(CONFIG_BOARD) +ARCHDEFINES += -DCONFIG_ARCH_BOARD_$(CONFIG_BOARD) -D__PX4_NUTTX # optimisation flags # diff --git a/makefiles/toolchain_native.mk b/makefiles/toolchain_native.mk new file mode 100644 index 0000000000..37e5dbed51 --- /dev/null +++ b/makefiles/toolchain_native.mk @@ -0,0 +1,306 @@ +# +# Copyright (C) 2012-2014 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. +# + +# +# Definitions for a native GCC toolchain +# + +#$(info TOOLCHAIN native) + +# Toolchain commands. Normally only used inside this file. +# + +# Set to 1 for GCC-4.8.2 and to 0 for Clang-3.5 (Ubuntu 14.04) +USE_GCC=0 + +ifeq ($(USE_GCC),1) +# GCC Options: +CC = gcc +CXX = g++ +CPP = gcc -E + +# GCC Version +DEV_VER_SUPPORTED = 4.8.2 + +else +# Clang options +CC = clang-3.5 +CXX = clang++-3.5 +CPP = clang-3.5 -E + +# Clang GCC reported version +DEV_VER_SUPPORTED = 4.2.1 +endif + +LD = ld +AR = ar rcs +NM = nm +OBJCOPY = objcopy +OBJDUMP = objdump + +# Check if the right version of the toolchain is available +# +DEV_VER_FOUND = $(shell $(CC) -dumpversion) + +ifeq (,$(findstring $(DEV_VER_FOUND), $(DEV_VER_SUPPORTED))) +$(error Unsupported version of $(CC), found: $(DEV_VER_FOUND) instead of one in: $(DEV_VER_SUPPORTED)) +endif + + +# XXX this is pulled pretty directly from the fmu Make.defs - needs cleanup + +MAXOPTIMIZATION ?= -O3 + +# Enabling stack checks if OS was build with them +# + +# Set the board flags +# +ifeq ($(CONFIG_BOARD),) +$(error Board config does not define CONFIG_BOARD) +endif +ARCHDEFINES += -DCONFIG_ARCH_BOARD_$(CONFIG_BOARD) \ + -D__PX4_LINUX \ + -Dnoreturn_function= \ + -I/usr/include/eigen3 \ + -I$(PX4_BASE)/src/platforms/linux/include \ + -Wno-error=shadow + +# optimisation flags +# +ARCHOPTIMIZATION = $(MAXOPTIMIZATION) \ + -g3 \ + -fno-strict-aliasing \ + -fomit-frame-pointer \ + -funsafe-math-optimizations \ + -fno-builtin-printf \ + -ffunction-sections \ + -fdata-sections + +# Language-specific flags +# +ARCHCFLAGS = -std=gnu99 -g +ARCHCXXFLAGS = -fno-exceptions -fno-rtti -std=c++11 -fno-threadsafe-statics -D__CUSTOM_FILE_IO__ -g + +# Generic warnings +# +# Disabled +# -Wshadow - Breaks for the libeigen package headers +# -Wframe-larger-than=1024 - Only needed for embedded + +ARCHWARNINGS = -Wall \ + -Wextra \ + -Werror \ + -Wfloat-equal \ + -Wpointer-arith \ + -Wmissing-declarations \ + -Wpacked \ + -Wno-unused-parameter \ + -Werror=format-security \ + -Werror=array-bounds \ + -Wfatal-errors \ + -Werror=unused-variable \ + -Werror=reorder \ + -Werror=uninitialized \ + -Werror=init-self + +# Add compiler specific options +ifeq ($(USE_GCC),1) +ARCHDEFINES += -Wno-error=logical-op +ARCHWARNINGS += -Wdouble-promotion \ + -Wlogical-op \ + -Wformat=1 \ + -Werror=unused-but-set-variable \ + -Werror=double-promotion +ARCHOPTIMIZATION += -fno-strength-reduce +endif + +# -Werror=float-conversion - works, just needs to be phased in with some effort and needs GCC 4.9+ +# -Wcast-qual - generates spurious noreturn attribute warnings, try again later +# -Wconversion - would be nice, but too many "risky-but-safe" conversions in the code +# -Wcast-align - would help catch bad casts in some cases, but generates too many false positives + +# C-specific warnings +# +ARCHCWARNINGS = $(ARCHWARNINGS) \ + -Wbad-function-cast \ + -Wstrict-prototypes \ + -Wmissing-prototypes \ + -Wnested-externs + +# Add compiler specific options +ifeq ($(USE_GCC),1) +ARCHCWARNINGS += -Wold-style-declaration \ + -Wmissing-parameter-type +endif + +# C++-specific warnings +# +ARCHWARNINGSXX = $(ARCHWARNINGS) \ + -Wno-missing-field-initializers + +# pull in *just* libm from the toolchain ... this is grody +LIBM := $(shell $(CC) $(ARCHCPUFLAGS) -print-file-name=libm.a) +#EXTRA_LIBS += $(LIBM) +EXTRA_LIBS += -pthread -lm + +# Flags we pass to the C compiler +# +CFLAGS = $(ARCHCFLAGS) \ + $(ARCHCWARNINGS) \ + $(ARCHOPTIMIZATION) \ + $(ARCHCPUFLAGS) \ + $(ARCHINCLUDES) \ + $(INSTRUMENTATIONDEFINES) \ + $(ARCHDEFINES) \ + $(EXTRADEFINES) \ + $(EXTRACFLAGS) \ + -fno-common \ + $(addprefix -I,$(INCLUDE_DIRS)) + +# Flags we pass to the C++ compiler +# +CXXFLAGS = $(ARCHCXXFLAGS) \ + $(ARCHWARNINGSXX) \ + $(ARCHOPTIMIZATION) \ + $(ARCHCPUFLAGS) \ + $(ARCHXXINCLUDES) \ + $(INSTRUMENTATIONDEFINES) \ + $(ARCHDEFINES) \ + -DCONFIG_WCHAR_BUILTIN \ + $(EXTRADEFINES) \ + $(EXTRACXXFLAGS) \ + -Wno-effc++ \ + $(addprefix -I,$(INCLUDE_DIRS)) + +ifeq ($(USE_GCC),0) +CXXFLAGS += -Wno-deprecated-register \ + -Wno-tautological-constant-out-of-range-compare \ + -Wno-unused-private-field \ + -Wno-unused-const-variable +endif + +# Flags we pass to the assembler +# +AFLAGS = $(CFLAGS) -D__ASSEMBLY__ \ + $(EXTRADEFINES) \ + $(EXTRAAFLAGS) + +# Flags we pass to the linker +# +LDFLAGS += $(EXTRALDFLAGS) \ + $(addprefix -L,$(LIB_DIRS)) + +# Compiler support library +# +LIBGCC := $(shell $(CC) $(ARCHCPUFLAGS) -print-libgcc-file-name) + +# Files that the final link depends on +# +#LINK_DEPS += $(LDSCRIPT) +LINK_DEPS += + +# Files to include to get automated dependencies +# +DEP_INCLUDES = $(subst .o,.d,$(OBJS)) + +# Compile C source $1 to object $2 +# as a side-effect, generate a dependency file +# +define COMPILE + @$(ECHO) "CC: $1" + @$(MKDIR) -p $(dir $2) + $(Q) $(CCACHE) $(CC) -MD -c $(CFLAGS) $(abspath $1) -o $2 +endef + +# Compile C++ source $1 to $2 +# as a side-effect, generate a dependency file +# +define COMPILEXX + @$(ECHO) "CXX: $1" + @$(MKDIR) -p $(dir $2) + @echo $(Q) $(CCACHE) $(CXX) -MD -c $(CXXFLAGS) $(abspath $1) -o $2 + $(Q) $(CCACHE) $(CXX) -MD -c $(CXXFLAGS) $(abspath $1) -o $2 +endef + +# Assemble $1 into $2 +# +define ASSEMBLE + @$(ECHO) "AS: $1" + @$(MKDIR) -p $(dir $2) + $(Q) $(CC) -c $(AFLAGS) $(abspath $1) -o $2 +endef + +# Produce partially-linked $1 from files in $2 +# +define PRELINK + @$(ECHO) "PRELINK: $1" + @$(MKDIR) -p $(dir $1) + $(Q) $(LD) -Ur -o $1 $2 + +endef +# $(Q) $(LD) -Ur -o $1 $2 && $(OBJCOPY) --localize-hidden $1 + +# Update the archive $1 with the files in $2 +# +define ARCHIVE + @$(ECHO) "AR: $2" + @$(MKDIR) -p $(dir $1) + $(Q) $(AR) $1 $2 +endef + +# Link the objects in $2 into the shared library $1 +# +define LINK_A + @$(ECHO) "LINK_A: $1" + @$(MKDIR) -p $(dir $1) + echo "$(Q) $(AR) $1 $2" + $(Q) $(AR) $1 $2 +endef + +# Link the objects in $2 into the shared library $1 +# +define LINK_SO + @$(ECHO) "LINK_SO: $1" + @$(MKDIR) -p $(dir $1) + echo "$(Q) $(CXX) $(LDFLAGS) -shared -Wl,-soname,`basename $1`.1 -o $1 $2 $(LIBS) $(EXTRA_LIBS)" + $(Q) $(CXX) $(LDFLAGS) -shared -Wl,-soname,`basename $1`.1 -o $1 $2 $(LIBS) -pthread -lc +endef + +# Link the objects in $2 into the application $1 +# +define LINK + @$(ECHO) "LINK: $1" + @$(MKDIR) -p $(dir $1) + echo "$(Q) $(CXX) $(LDFLAGS) -o $1 $2 $(LIBS) $(EXTRA_LIBS)" + $(Q) $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $1 $2 $(LIBS) $(EXTRA_LIBS) $(LIBGCC) +endef +