2012-08-04 19:12:36 -03:00
|
|
|
#
|
|
|
|
# Top-level Makefile for building PX4 firmware images.
|
|
|
|
#
|
2013-01-16 22:23:49 -04:00
|
|
|
|
2012-08-04 19:12:36 -03:00
|
|
|
|
|
|
|
#
|
|
|
|
# Some useful paths.
|
|
|
|
#
|
2013-01-16 22:23:49 -04:00
|
|
|
export PX4_BASE = $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
|
|
|
|
export NUTTX_SRC = $(PX4_BASE)/nuttx
|
|
|
|
export NUTTX_APPS = $(PX4_BASE)/apps
|
|
|
|
export MAVLINK_SRC = $(PX4_BASE)/mavlink
|
|
|
|
export ROMFS_SRC = $(PX4_BASE)/ROMFS
|
|
|
|
export IMAGE_DIR = $(PX4_BASE)/Images
|
|
|
|
export BUILD_DIR = $(PX4_BASE)/Build
|
|
|
|
export ARCHIVE_DIR = $(PX4_BASE)/Archives
|
2012-08-04 19:12:36 -03:00
|
|
|
|
|
|
|
#
|
|
|
|
# Tools
|
|
|
|
#
|
2013-01-16 22:23:49 -04:00
|
|
|
MKFW = $(PX4_BASE)/Tools/px_mkfw.py
|
|
|
|
UPLOADER = $(PX4_BASE)/Tools/px_uploader.py
|
|
|
|
COPY = cp
|
|
|
|
REMOVE = rm -f
|
|
|
|
RMDIR = rm -rf
|
|
|
|
|
|
|
|
#
|
|
|
|
# Canned firmware configurations that we build.
|
|
|
|
#
|
|
|
|
CONFIGS ?= px4fmu_default px4io_default
|
2012-08-04 19:12:36 -03:00
|
|
|
|
|
|
|
#
|
2013-01-16 22:23:49 -04:00
|
|
|
# If the user has listed a config as a target, strip it out and override CONFIGS
|
2012-08-04 19:12:36 -03:00
|
|
|
#
|
2013-01-16 22:23:49 -04:00
|
|
|
EXPLICIT_CONFIGS := $(filter $(CONFIGS),$(MAKECMDGOALS))
|
|
|
|
ifneq ($(EXPLICIT_CONFIGS),)
|
|
|
|
CONFIGS := $(EXPLICIT_CONFIGS)
|
|
|
|
.PHONY: $(EXPLICIT_CONFIGS)
|
|
|
|
$(EXPLICIT_CONFIGS): all
|
2013-01-11 06:14:43 -04:00
|
|
|
endif
|
2012-08-04 19:12:36 -03:00
|
|
|
|
|
|
|
#
|
2013-01-16 22:23:49 -04:00
|
|
|
# Platforms (boards) that we build prelink kits for.
|
|
|
|
#
|
|
|
|
PLATFORMS = px4fmu px4io
|
|
|
|
|
|
|
|
#
|
|
|
|
# Some handy macros
|
|
|
|
#
|
|
|
|
PLATFORM_FROM_CONFIG = $(word 1,$(subst _, ,$1))
|
|
|
|
|
|
|
|
#
|
|
|
|
# Built products
|
2012-08-04 19:12:36 -03:00
|
|
|
#
|
2013-01-16 22:23:49 -04:00
|
|
|
FIRMWARES = $(foreach config,$(CONFIGS),$(IMAGE_DIR)/$(config).px4)
|
|
|
|
BINARIES = $(foreach config,$(CONFIGS),$(BUILD_DIR)/$(config).build/firmware.bin)
|
2012-08-04 19:12:36 -03:00
|
|
|
|
|
|
|
#
|
|
|
|
# Debugging
|
|
|
|
#
|
2013-01-11 06:31:30 -04:00
|
|
|
MQUIET = --no-print-directory
|
|
|
|
#MQUIET = --print-directory
|
2013-01-16 22:23:49 -04:00
|
|
|
ifeq ($(V),)
|
|
|
|
Q = @
|
|
|
|
else
|
|
|
|
Q =
|
|
|
|
endif
|
|
|
|
|
|
|
|
all: $(FIRMWARES)
|
|
|
|
#all: $(SYMBOLS)
|
2012-08-04 19:12:36 -03:00
|
|
|
|
|
|
|
|
|
|
|
#
|
2013-01-16 22:23:49 -04:00
|
|
|
# Generate FIRMWARES from BINARIES
|
2012-08-04 19:12:36 -03:00
|
|
|
#
|
2013-01-16 22:23:49 -04:00
|
|
|
$(IMAGE_DIR)/%.px4: basepath = $(basename $(@))
|
|
|
|
$(IMAGE_DIR)/%.px4: config = $(notdir $(basepath))
|
|
|
|
$(IMAGE_DIR)/%.px4: platform = $(call PLATFORM_FROM_CONFIG,$(config))
|
|
|
|
$(FIRMWARES): $(IMAGE_DIR)/%.px4: $(BUILD_DIR)/%.build/firmware.bin
|
|
|
|
@echo %% Generating $@ for $(config)
|
|
|
|
$(Q) $(MKFW) --prototype $(IMAGE_DIR)/$(platform).prototype \
|
|
|
|
--git_identity $(PX4_BASE) \
|
|
|
|
--image $< > $@
|
2013-01-03 02:13:30 -04:00
|
|
|
|
2012-08-04 19:12:36 -03:00
|
|
|
#
|
2013-01-16 22:23:49 -04:00
|
|
|
# Generate the firmware executable
|
2012-08-04 19:12:36 -03:00
|
|
|
#
|
2013-01-16 22:23:49 -04:00
|
|
|
# XXX pick the right build tool for the host OS - force it on the generation side too.
|
|
|
|
#
|
|
|
|
$(BUILD_DIR)/%.build/firmware.bin: config = $(patsubst $(BUILD_DIR)/%.build/firmware.bin,%,$@)
|
|
|
|
$(BUILD_DIR)/%.build/firmware.bin: work_dir = $(BUILD_DIR)/$(config).build
|
|
|
|
$(BINARIES): $(BUILD_DIR)/%.build/firmware.bin: $(BUILD_DIR)/$(word 1,$(subst _, ,%)).build
|
|
|
|
@echo %% Building $(config) in $(work_dir)
|
|
|
|
$(Q) make -C $(work_dir) \
|
|
|
|
-f $(PX4_BASE)/makefiles/$(config).mk \
|
|
|
|
CONFIG=$(config) \
|
|
|
|
PLATFORM=$(call PLATFORM_FROM_CONFIG,$(config)) \
|
|
|
|
WORK_DIR=$(work_dir)
|
2012-08-04 19:12:36 -03:00
|
|
|
|
|
|
|
#
|
2013-01-16 22:23:49 -04:00
|
|
|
# Generate the config build directory.
|
2012-08-04 19:12:36 -03:00
|
|
|
#
|
2013-01-16 22:23:49 -04:00
|
|
|
BUILDAREAS = $(foreach config,$(CONFIGS),$(BUILD_DIR)/$(config).build)
|
|
|
|
.PHONY: buildareas
|
|
|
|
buildareas: $(BUILDAREAS)
|
2012-08-04 19:12:36 -03:00
|
|
|
|
2013-01-16 22:23:49 -04:00
|
|
|
$(BUILD_DIR)/%.build: config = $(notdir $(basename $@))
|
|
|
|
$(BUILD_DIR)/%.build: platform = $(call PLATFORM_FROM_CONFIG,$(config))
|
|
|
|
$(BUILDAREAS): $(BUILD_DIR)/%.build:
|
|
|
|
@echo %% Setting up build environment for $(config)
|
|
|
|
$(Q) mkdir -p $@
|
|
|
|
$(Q) (cd $@ && $(RMDIR) nuttx-export && unzip -q $(ARCHIVE_DIR)/$(platform).export)
|
2013-01-03 02:13:30 -04:00
|
|
|
|
2012-08-04 19:12:36 -03:00
|
|
|
#
|
2013-01-16 22:23:49 -04:00
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# XXX Should support fetching/unpacking from a separate directory to permit
|
|
|
|
# downloads of the prebuilt archives as well...
|
2012-08-04 19:12:36 -03:00
|
|
|
#
|
2013-01-16 22:23:49 -04:00
|
|
|
# XXX PX4IO config name is bad - we should just call them all "px4"
|
|
|
|
#
|
|
|
|
NUTTX_ARCHIVES = $(foreach platform,$(PLATFORMS),$(ARCHIVE_DIR)/$(platform).export)
|
|
|
|
.PHONY: archives
|
|
|
|
archives: $(NUTTX_ARCHIVES)
|
2012-08-04 19:12:36 -03:00
|
|
|
|
2013-01-16 22:23:49 -04:00
|
|
|
$(ARCHIVE_DIR)/%.export: platform = $(notdir $(basename $@))
|
|
|
|
$(ARCHIVE_DIR)/%.export: config = $(if $(filter $(platform),px4io),io,nsh)
|
|
|
|
$(NUTTX_ARCHIVES): $(ARCHIVE_DIR)/%.export: $(NUTTX_SRC) $(NUTTX_APPS)
|
|
|
|
@echo %% Configuring NuttX for $(platform)
|
|
|
|
$(Q) (cd $(NUTTX_SRC) && $(RMDIR) nuttx-export)
|
|
|
|
$(Q) make -C $(NUTTX_SRC) -r $(MQUIET) distclean
|
|
|
|
$(Q) (cd $(NUTTX_SRC)/tools && ./configure.sh $(platform)/$(config))
|
|
|
|
@echo Generating ROMFS for $(platform) XXX move this!
|
|
|
|
$(Q) make -C $(ROMFS_SRC) all
|
|
|
|
@echo %% Exporting NuttX for $(platform)
|
|
|
|
$(Q) make -C $(NUTTX_SRC) -r $(MQUIET) export
|
|
|
|
$(Q) mkdir -p $(dir $@)
|
|
|
|
$(Q) $(COPY) $(NUTTX_SRC)/nuttx-export.zip $@
|
2012-08-04 19:12:36 -03:00
|
|
|
|
2013-01-16 22:23:49 -04:00
|
|
|
setup_px4io:
|
2013-01-03 02:13:30 -04:00
|
|
|
|
2012-08-04 19:12:36 -03:00
|
|
|
#
|
2013-01-16 22:23:49 -04:00
|
|
|
# Firmware upload.
|
2012-08-04 19:12:36 -03:00
|
|
|
#
|
|
|
|
|
|
|
|
# serial port defaults by operating system.
|
|
|
|
SYSTYPE = $(shell uname)
|
|
|
|
ifeq ($(SYSTYPE),Darwin)
|
2012-08-10 11:18:45 -03:00
|
|
|
SERIAL_PORTS ?= "/dev/tty.usbmodemPX1,/dev/tty.usbmodemPX2,/dev/tty.usbmodemPX3,/dev/tty.usbmodemPX4,/dev/tty.usbmodem1,/dev/tty.usbmodem2,/dev/tty.usbmodem3,/dev/tty.usbmodem4"
|
2012-08-04 19:12:36 -03:00
|
|
|
endif
|
|
|
|
ifeq ($(SYSTYPE),Linux)
|
|
|
|
SERIAL_PORTS ?= "/dev/ttyACM5,/dev/ttyACM4,/dev/ttyACM3,/dev/ttyACM2,/dev/ttyACM1,/dev/ttyACM0"
|
|
|
|
endif
|
|
|
|
ifeq ($(SERIAL_PORTS),)
|
2012-11-27 14:45:11 -04:00
|
|
|
SERIAL_PORTS = "\\\\.\\COM32,\\\\.\\COM31,\\\\.\\COM30,\\\\.\\COM29,\\\\.\\COM28,\\\\.\\COM27,\\\\.\\COM26,\\\\.\\COM25,\\\\.\\COM24,\\\\.\\COM23,\\\\.\\COM22,\\\\.\\COM21,\\\\.\\COM20,\\\\.\\COM19,\\\\.\\COM18,\\\\.\\COM17,\\\\.\\COM16,\\\\.\\COM15,\\\\.\\COM14,\\\\.\\COM13,\\\\.\\COM12,\\\\.\\COM11,\\\\.\\COM10,\\\\.\\COM9,\\\\.\\COM8,\\\\.\\COM7,\\\\.\\COM6,\\\\.\\COM5,\\\\.\\COM4,\\\\.\\COM3,\\\\.\\COM2,\\\\.\\COM1,\\\\.\\COM0"
|
2012-08-04 19:12:36 -03:00
|
|
|
endif
|
|
|
|
|
|
|
|
upload: $(FIRMWARE_BUNDLE) $(UPLOADER)
|
|
|
|
@python -u $(UPLOADER) --port $(SERIAL_PORTS) $(FIRMWARE_BUNDLE)
|
2012-11-30 05:42:27 -04:00
|
|
|
|
|
|
|
#
|
|
|
|
# JTAG firmware uploading with OpenOCD
|
|
|
|
#
|
|
|
|
ifeq ($(JTAGCONFIG),)
|
|
|
|
JTAGCONFIG=interface/olimex-jtag-tiny.cfg
|
|
|
|
endif
|
|
|
|
|
2013-01-16 22:23:49 -04:00
|
|
|
.PHONY: upload-jtag-px4fmu
|
|
|
|
upload-jtag-px4fmu: all
|
2012-09-24 13:23:00 -03:00
|
|
|
@echo Attempting to flash PX4FMU board via JTAG
|
2012-11-30 05:42:27 -04:00
|
|
|
@openocd -f $(JTAGCONFIG) -f ../Bootloader/stm32f4x.cfg -c init -c "reset halt" -c "flash write_image erase nuttx/nuttx" -c "flash write_image erase ../Bootloader/px4fmu_bl.elf" -c "reset run" -c shutdown
|
|
|
|
|
2013-01-16 22:23:49 -04:00
|
|
|
.PHONY: upload-jtag-px4io
|
2012-11-30 05:42:27 -04:00
|
|
|
upload-jtag-px4io: all
|
|
|
|
@echo Attempting to flash PX4IO board via JTAG
|
|
|
|
@openocd -f $(JTAGCONFIG) -f ../Bootloader/stm32f1x.cfg -c init -c "reset halt" -c "flash write_image erase nuttx/nuttx" -c "flash write_image erase ../Bootloader/px4io_bl.elf" -c "reset run" -c shutdown
|
2012-08-04 19:12:36 -03:00
|
|
|
|
|
|
|
#
|
|
|
|
# Hacks and fixups
|
|
|
|
#
|
|
|
|
|
|
|
|
ifeq ($(SYSTYPE),Darwin)
|
|
|
|
# PATH inherited by Eclipse may not include toolchain install location
|
|
|
|
export PATH := $(PATH):/usr/local/bin
|
|
|
|
endif
|
|
|
|
|
|
|
|
#
|
|
|
|
# Cleanup targets. 'clean' should remove all built products and force
|
|
|
|
# a complete re-compilation, 'distclean' should remove everything
|
|
|
|
# that's generated leaving only files that are in source control.
|
|
|
|
#
|
2013-01-16 22:23:49 -04:00
|
|
|
.PHONY: clean
|
2012-08-04 19:12:36 -03:00
|
|
|
clean:
|
2013-01-16 22:23:49 -04:00
|
|
|
$(Q) $(RMDIR) $(BUILD_DIR)/*.build
|
|
|
|
$(Q) $(REMOVE) -f $(IMAGE_DIR)/*.bin
|
|
|
|
$(Q) $(REMOVE) -f $(IMAGE_DIR)/*.sym
|
|
|
|
$(Q) $(REMOVE) -f $(IMAGE_DIR)/*.px4
|
|
|
|
$(Q) make -C $(ROMFS_SRC) -r $(MQUIET) clean
|
2012-08-04 19:12:36 -03:00
|
|
|
|
|
|
|
.PHONY: distclean
|
2013-01-16 22:23:49 -04:00
|
|
|
distclean: clean
|
|
|
|
$(Q) $(REMOVE) -f $(ARCHIVE_DIR)/*.export
|
|
|
|
$(Q) make -C $(NUTTX_SRC) -r $(MQUIET) distclean
|
|
|
|
$(Q) make -C $(ROMFS_SRC) -r $(MQUIET) distclean
|
2012-08-04 19:12:36 -03:00
|
|
|
|