Break up the firmware build into a 'make export' phase for NuttX on a per-board basis, and then a separate per-config phase that allows us to avoid re-building NuttX all the time, and ship more than one firmware config for a given board.

This is a first cut; it builds one firmware for each of FMU and IO.
This commit is contained in:
px4dev 2013-01-05 21:46:50 -08:00
parent 085d08ce6c
commit b80575fcff
7 changed files with 285 additions and 0 deletions

71
makefiles/firmware.mk Normal file
View File

@ -0,0 +1,71 @@
#
# Generic Makefile for PX4 firmware.
#
# Currently this assumes that we're just compiling SRCS
# and then linking the whole thing together.
#
#
# Work out where this file is, so we can find other makefiles in the
# same directory.
#
export PX4_MK_INCLUDE ?= $(dir $(lastword $(MAKEFILE_LIST)))
#
# Use the linker script from the NuttX export
#
LDSCRIPT = $(WORK_DIR)/nuttx-export/build/ld.script
#
# Add directories from the NuttX export to the relevant search paths
#
INCLUDE_DIRS += $(WORK_DIR)/nuttx-export/include
LIB_DIRS += $(WORK_DIR)/nuttx-export/libs
LIBS += -lapps -lnuttx
#
# Things that, if they change, might affect everything
#
GLOBAL_DEPS += $(MAKEFILE_LIST)
#
# Include the platform configuration
#
include $(PX4_MK_INCLUDE)/$(PLATFORM).mk
#
# What we're going to build
#
PRODUCT_BIN = $(WORK_DIR)/firmware.bin
PRODUCT_SYM = $(WORK_DIR)/firmware.sym
PRODUCTS = $(PRODUCT_BIN) $(PRODUCT_SYM)
.PHONY: all
all: $(PRODUCTS)
#
# Rules for building objects
#
OBJS = $(foreach src,$(SRCS),$(WORK_DIR)/$(src).o)
$(filter %.c.o,$(OBJS)): $(WORK_DIR)/%.c.o: %.c
@echo compile $<
@mkdir -p $(dir $@)
$(call COMPILE,$<,$@)
$(filter %.cpp.o,$(OBJS)): $(WORK_DIR)/%.cpp.o: %.cpp
@mkdir -p $(dir $@)
$(call COMPILEXX,$<,$@)
$(filter %.S.o,$(OBJS)): $(WORK_DIR)/%.S.o: %.S
@mkdir -p $(dir $@)
$(call ASSEMBLE,$<,$@)
-include $(DEP_INCLUDES)
$(PRODUCT_BIN): $(PRODUCT_SYM)
$(call SYM_TO_BIN,$<,$@)
$(PRODUCT_SYM): $(OBJS) $(GLOBAL_DEPS) $(LINK_DEPS)
$(call LINK,$@,$(OBJS))

177
makefiles/gnu-arm-eabi.mk Normal file
View File

@ -0,0 +1,177 @@
#
# Definitions for a generic GNU ARM-EABI toolchain
#
CROSSDEV = arm-none-eabi-
CC = $(CROSSDEV)gcc
CXX = $(CROSSDEV)g++
CPP = $(CROSSDEV)gcc -E
LD = $(CROSSDEV)ld
AR = $(CROSSDEV)ar rcs
NM = $(CROSSDEV)nm
OBJCOPY = $(CROSSDEV)objcopy
OBJDUMP = $(CROSSDEV)objdump
# XXX this is pulled pretty directly from the fmu Make.defs - needs cleanup
MAXOPTIMIZATION = -O3
# base CPU flags
ARCHCPUFLAGS_CORTEXM4F = -mcpu=cortex-m4 \
-mthumb \
-march=armv7e-m \
-mfpu=fpv4-sp-d16 \
-mfloat-abi=hard
ARCHCPUFLAGS_CORTEXM4 = -mcpu=cortex-m4 \
-mthumb \
-march=armv7e-m \
-mfloat-abi=soft
ARCHCPUFLAGS_CORTEXM3 = -mcpu=cortex-m3 \
-mthumb \
-march=armv6-m \
-mfloat-abi=soft
ARCHCPUFLAGS = $(ARCHCPUFLAGS_$(CONFIG_ARCH))
# optimisation flags
ARCHOPTIMIZATION = $(MAXOPTIMIZATION) \
-fno-strict-aliasing \
-fno-strength-reduce \
-fomit-frame-pointer \
-funsafe-math-optimizations \
-fno-builtin-printf \
-ffunction-sections \
-fdata-sections
ifeq ("${CONFIG_DEBUG_SYMBOLS}","y")
ARCHOPTIMIZATION += -g
endif
# enable precise stack overflow tracking
# note - requires corresponding support in NuttX
INSTRUMENTATIONDEFINES = -finstrument-functions \
-ffixed-r10
ARCHCFLAGS = -std=gnu99
ARCHCXXFLAGS = -fno-exceptions -fno-rtti -std=gnu++0x
ARCHWARNINGS = -Wall \
-Wextra \
-Wdouble-promotion \
-Wshadow \
-Wfloat-equal \
-Wframe-larger-than=1024 \
-Wpointer-arith \
-Wlogical-op \
-Wmissing-declarations \
-Wpacked \
-Wno-unused-parameter
# -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
ARCHCWARNINGS = $(ARCHWARNINGS) \
-Wbad-function-cast \
-Wstrict-prototypes \
-Wold-style-declaration \
-Wmissing-parameter-type \
-Wmissing-prototypes \
-Wnested-externs \
-Wunsuffixed-float-constants
ARCHWARNINGSXX = $(ARCHWARNINGS)
# pull in *just* libm from the toolchain ... this is grody
LIBM = $(shell $(CC) $(ARCHCPUFLAGS) -print-file-name=libm.a)
EXTRA_LIBS += $(LIBM)
CFLAGS = $(ARCHCFLAGS) \
$(ARCHCWARNINGS) \
$(ARCHOPTIMIZATION) \
$(ARCHCPUFLAGS) \
$(ARCHINCLUDES) \
$(INSTRUMENTATIONDEFINES) \
$(ARCHDEFINES) \
$(EXTRADEFINES) \
-fno-common
CXXFLAGS = $(ARCHCXXFLAGS) \
$(ARCHWARNINGSXX) \
$(ARCHOPTIMIZATION) \
$(ARCHCPUFLAGS) \
$(ARCHXXINCLUDES) \
$(INSTRUMENTATIONDEFINES) \
$(ARCHDEFINES) \
$(EXTRADEFINES)
CPPFLAGS = $(ARCHINCLUDES) \
$(INSTRUMENTATIONDEFINES) \
$(ARCHDEFINES) \
$(EXTRADEFINES)
AFLAGS = $(CFLAGS) -D__ASSEMBLY__
LDFLAGS += --warn-common \
--gc-sections \
-T $(LDSCRIPT) \
$(addprefix -L,$(LIB_DIRS))
LIBGCC := $(shell $(CC) $(ARCHCPUFLAGS) -print-libgcc-file-name)
# files that the final link depends on
# XXX add libraries that we know about here...
LINK_DEPS += $(LDSCRIPT)
# files to include to get automated dependencies
DEP_INCLUDES = $(subst .o,.d,$(OBJS))
ifeq ($(V),)
Q = @
else
Q =
endif
# compile C source $1 to object $2
# as a side-effect, generate a dependency file
define COMPILE
@echo "CC: $1"
$(Q) $(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"
$(Q) $(CXX) -MD -c $(CXXFLAGS) $(abspath $1) -o $2
endef
# assemble $1 into $2
define ASSEMBLE
@echo "AS: $1"
$(Q) $(CC) -c $(AFLAGS) $(abspath $1) -o $2
endef
# produce partially-linked $1 from files in $2
define PRELINK
@echo "PRELINK: $1"
$(Q) $(LD) -Ur -o $1 $2 && $(OBJCOPY) --localize-hidden $1
endef
# update the archive $1 with the files in $2
define ARCHIVE
@echo "AR: $2"
$(Q) $(AR) $1 $2
endef
# Link the objects in $2 into the binary $1
define LINK
@echo "LINK: $1"
$(Q) $(LD) $(LDFLAGS) -o $1 --start-group $(LIBS) $(EXTRA_LIBS) $(LIBGCC) --end-group
endef
# convert $1 from a linked object to a raw binary
define SYM_TO_BIN
@echo "BIN: $2"
$(Q) $(OBJCOPY) -O binary $1 $2
endef

10
makefiles/px4fmu.mk Normal file
View File

@ -0,0 +1,10 @@
#
# Platform-specific definitions for the PX4FMU
#
#
# Configure the toolchain
#
CONFIG_ARCH = CORTEXM4F
include $(PX4_MK_INCLUDE)/gnu-arm-eabi.mk

View File

@ -0,0 +1,7 @@
#
# Makefile for the px4fmu_default configuration
#
SRCS = $(PX4BASE)/platforms/empty.c
include $(PX4BASE)/makefiles/firmware.mk

10
makefiles/px4io.mk Normal file
View File

@ -0,0 +1,10 @@
#
# Platform-specific definitions for the PX4IO
#
#
# Configure the toolchain
#
CONFIG_ARCH = CORTEXM3
include $(PX4_MK_INCLUDE)/gnu-arm-eabi.mk

View File

@ -0,0 +1,7 @@
#
# Makefile for the px4io_default configuration
#
SRCS = $(PX4BASE)/platforms/empty.c
include $(PX4BASE)/makefiles/firmware.mk

3
platforms/empty.c Normal file
View File

@ -0,0 +1,3 @@
/*
* This is an empty C source file, used when building default firmware configurations.
*/