2011-02-23 05:18:53 +01:00
|
|
|
# Toolchain prefix (i.e arm-elf- -> arm-elf-gcc.exe)
|
|
|
|
TCHAIN_PREFIX ?= arm-none-eabi-
|
|
|
|
|
|
|
|
# Define toolchain component names.
|
|
|
|
CC = $(TCHAIN_PREFIX)gcc
|
|
|
|
CPP = $(TCHAIN_PREFIX)g++
|
|
|
|
AR = $(TCHAIN_PREFIX)ar
|
|
|
|
OBJCOPY = $(TCHAIN_PREFIX)objcopy
|
|
|
|
OBJDUMP = $(TCHAIN_PREFIX)objdump
|
|
|
|
SIZE = $(TCHAIN_PREFIX)size
|
|
|
|
NM = $(TCHAIN_PREFIX)nm
|
2011-04-11 03:34:00 +02:00
|
|
|
STRIP = $(TCHAIN_PREFIX)strip
|
2011-05-13 10:20:53 +02:00
|
|
|
INSTALL = install
|
2011-02-23 05:18:53 +01:00
|
|
|
|
|
|
|
THUMB = -mthumb
|
|
|
|
|
|
|
|
# Test if quotes are needed for the echo-command
|
|
|
|
result = ${shell echo "test"}
|
|
|
|
ifeq (${result}, test)
|
|
|
|
quote = '
|
|
|
|
# This line is just to clear out the single quote above '
|
|
|
|
else
|
|
|
|
quote =
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Define Messages
|
|
|
|
# English
|
|
|
|
MSG_FORMATERROR := ${quote} Can not handle output-format${quote}
|
|
|
|
MSG_MODINIT := ${quote} MODINIT ${quote}
|
|
|
|
MSG_SIZE := ${quote} SIZE ${quote}
|
|
|
|
MSG_LOAD_FILE := ${quote} BIN/HEX ${quote}
|
2011-03-26 13:37:44 +01:00
|
|
|
MSG_BIN_OBJ := ${quote} BINO ${quote}
|
2011-04-11 03:34:00 +02:00
|
|
|
MSG_STRIP_FILE := ${quote} STRIP ${quote}
|
2011-02-23 05:18:53 +01:00
|
|
|
MSG_EXTENDED_LISTING := ${quote} LIS ${quote}
|
|
|
|
MSG_SYMBOL_TABLE := ${quote} NM ${quote}
|
|
|
|
MSG_LINKING := ${quote} LD ${quote}
|
|
|
|
MSG_COMPILING := ${quote} CC ${quote}
|
|
|
|
MSG_COMPILING_ARM := ${quote} CC-ARM ${quote}
|
|
|
|
MSG_COMPILINGCPP := ${quote} CXX ${quote}
|
|
|
|
MSG_COMPILINGCPP_ARM := ${quote} CXX-ARM ${quote}
|
|
|
|
MSG_ASSEMBLING := ${quote} AS ${quote}
|
|
|
|
MSG_ASSEMBLING_ARM := ${quote} AS-ARM ${quote}
|
|
|
|
MSG_CLEANING := ${quote} CLEAN ${quote}
|
|
|
|
MSG_ASMFROMC := ${quote} AS(C) ${quote}
|
|
|
|
MSG_ASMFROMC_ARM := ${quote} AS(C)-ARM ${quote}
|
|
|
|
MSG_PYMITEINIT := ${quote} PY ${quote}
|
2011-05-13 10:20:53 +02:00
|
|
|
MSG_INSTALLING := ${quote} INSTALL ${quote}
|
2011-05-25 06:20:02 +02:00
|
|
|
MSG_OPFIRMWARE := ${quote} OPFW ${quote}
|
build: refactor fw, bl and bu rules
- New macros for fw, bl and bu rules in top-level make
- Per-board info factored into make/board/*/board-info.mk
- Per-board info now shared btw. fw, bl and blupd for each board
- BOARD_TYPE, BOARD_REVISION, BOOTLOADER_VERSION, HW_TYPE
- MCU, CHIP, BOARD, MODEL, MODEL_SUFFIX
- START_OF_BL_CODE, START_OF_FW_CODE
- blupd_* goals renamed to bu_*
- all_blupd goal renamed to all_bu
- firmware goals renamed to fw_*, board name goals are preserved
- bu_*_program now writes updater to correct address for all boards
- BL updater firmware builds now produce .opf format including
version info blob.
- BL updater firmware name now includes board name.
- INS makefile brought up to date w.r.t. linker scripts
2011-05-23 21:11:53 +02:00
|
|
|
MSG_FWINFO := ${quote} FWINFO ${quote}
|
2011-05-24 07:10:31 +02:00
|
|
|
MSG_JTAG_PROGRAM := ${quote} JTAG-PGM ${quote}
|
|
|
|
MSG_JTAG_WIPE := ${quote} JTAG-WIPE ${quote}
|
2011-02-23 05:18:53 +01:00
|
|
|
|
|
|
|
toprel = $(subst $(realpath $(TOP))/,,$(abspath $(1)))
|
|
|
|
|
|
|
|
# Display compiler version information.
|
|
|
|
.PHONY: gccversion
|
|
|
|
gccversion :
|
|
|
|
@$(CC) --version
|
|
|
|
|
|
|
|
# Create final output file (.hex) from ELF output file.
|
|
|
|
%.hex: %.elf
|
|
|
|
@echo $(MSG_LOAD_FILE) $(call toprel, $@)
|
|
|
|
$(V1) $(OBJCOPY) -O ihex $< $@
|
|
|
|
|
2011-04-11 03:34:00 +02:00
|
|
|
# Create stripped output file (.elf.stripped) from ELF output file.
|
|
|
|
%.elf.stripped: %.elf
|
|
|
|
@echo $(MSG_STRIP_FILE) $(call toprel, $@)
|
|
|
|
$(V1) $(STRIP) --strip-unneeded $< -o $@
|
|
|
|
|
2011-02-23 05:18:53 +01:00
|
|
|
# Create final output file (.bin) from ELF output file.
|
|
|
|
%.bin: %.elf
|
|
|
|
@echo $(MSG_LOAD_FILE) $(call toprel, $@)
|
|
|
|
$(V1) $(OBJCOPY) -O binary $< $@
|
|
|
|
|
2011-05-21 19:55:15 +02:00
|
|
|
%.bin: %.o
|
|
|
|
@echo $(MSG_LOAD_FILE) $(call toprel, $@)
|
|
|
|
$(V1) $(OBJCOPY) -O binary $< $@
|
|
|
|
|
2011-03-26 13:37:44 +01:00
|
|
|
%.bin.o: %.bin
|
|
|
|
@echo $(MSG_BIN_OBJ) $(call toprel, $@)
|
|
|
|
$(V1) $(OBJCOPY) -I binary -O elf32-littlearm --binary-architecture arm \
|
|
|
|
--rename-section .data=.rodata,alloc,load,readonly,data,contents \
|
|
|
|
--wildcard \
|
2011-05-08 23:36:04 +02:00
|
|
|
--redefine-sym _binary_$(subst :,_,$(subst -,_,$(subst .,_,$(subst /,_,$<))))_start=_binary_start \
|
|
|
|
--redefine-sym _binary_$(subst :,_,$(subst -,_,$(subst .,_,$(subst /,_,$<))))_end=_binary_end \
|
|
|
|
--redefine-sym _binary_$(subst :,_,$(subst -,_,$(subst .,_,$(subst /,_,$<))))_size=_binary_size \
|
2011-03-26 13:37:44 +01:00
|
|
|
$< $@
|
|
|
|
|
2011-02-23 05:18:53 +01:00
|
|
|
# Create extended listing file/disassambly from ELF output file.
|
|
|
|
# using objdump testing: option -C
|
|
|
|
%.lss: %.elf
|
|
|
|
@echo $(MSG_EXTENDED_LISTING) $(call toprel, $@)
|
|
|
|
$(V1) $(OBJDUMP) -h -S -C -r $< > $@
|
|
|
|
|
|
|
|
# Create a symbol table from ELF output file.
|
|
|
|
%.sym: %.elf
|
|
|
|
@echo $(MSG_SYMBOL_TABLE) $(call toprel, $@)
|
|
|
|
$(V1) $(NM) -n $< > $@
|
|
|
|
|
|
|
|
define SIZE_TEMPLATE
|
2011-05-24 07:10:31 +02:00
|
|
|
.PHONY: size
|
|
|
|
size: $(1)_size
|
|
|
|
|
2011-02-23 05:18:53 +01:00
|
|
|
.PHONY: $(1)_size
|
|
|
|
$(1)_size: $(1)
|
|
|
|
@echo $(MSG_SIZE) $$(call toprel, $$<)
|
|
|
|
$(V1) $(SIZE) -A $$<
|
|
|
|
endef
|
|
|
|
|
2011-05-21 19:55:15 +02:00
|
|
|
# OpenPilot firmware image template
|
|
|
|
# $(1) = path to bin file
|
|
|
|
# $(2) = boardtype in hex
|
|
|
|
# $(3) = board revision in hex
|
2011-05-25 06:20:02 +02:00
|
|
|
define OPFW_TEMPLATE
|
2011-05-25 06:27:16 +02:00
|
|
|
FORCE:
|
|
|
|
|
|
|
|
$(1).firmwareinfo.c: $(1) $(TOP)/make/templates/firmwareinfotemplate.c FORCE
|
build: refactor fw, bl and bu rules
- New macros for fw, bl and bu rules in top-level make
- Per-board info factored into make/board/*/board-info.mk
- Per-board info now shared btw. fw, bl and blupd for each board
- BOARD_TYPE, BOARD_REVISION, BOOTLOADER_VERSION, HW_TYPE
- MCU, CHIP, BOARD, MODEL, MODEL_SUFFIX
- START_OF_BL_CODE, START_OF_FW_CODE
- blupd_* goals renamed to bu_*
- all_blupd goal renamed to all_bu
- firmware goals renamed to fw_*, board name goals are preserved
- bu_*_program now writes updater to correct address for all boards
- BL updater firmware builds now produce .opf format including
version info blob.
- BL updater firmware name now includes board name.
- INS makefile brought up to date w.r.t. linker scripts
2011-05-23 21:11:53 +02:00
|
|
|
@echo $(MSG_FWINFO) $$(call toprel, $$@)
|
2012-04-08 04:12:49 +02:00
|
|
|
python $(TOP)/make/scripts/version-info.py \
|
2011-05-21 19:55:15 +02:00
|
|
|
--path=$(TOP) \
|
|
|
|
--template=$(TOP)/make/templates/firmwareinfotemplate.c \
|
|
|
|
--outfile=$$@ \
|
|
|
|
--image=$(1) \
|
|
|
|
--type=$(2) \
|
|
|
|
--revision=$(3)
|
|
|
|
|
|
|
|
$(eval $(call COMPILE_C_TEMPLATE, $(1).firmwareinfo.c))
|
|
|
|
|
2011-05-25 06:20:02 +02:00
|
|
|
$(OUTDIR)/$(notdir $(basename $(1))).opfw : $(1) $(1).firmwareinfo.bin
|
2011-05-21 19:55:15 +02:00
|
|
|
@echo $(MSG_OPFIRMWARE) $$(call toprel, $$@)
|
|
|
|
$(V1) cat $(1) $(1).firmwareinfo.bin > $$@
|
|
|
|
endef
|
|
|
|
|
2011-02-23 05:18:53 +01:00
|
|
|
# Assemble: create object files from assembler source files.
|
|
|
|
define ASSEMBLE_TEMPLATE
|
|
|
|
$(OUTDIR)/$(notdir $(basename $(1))).o : $(1)
|
|
|
|
@echo $(MSG_ASSEMBLING) $$(call toprel, $$<)
|
|
|
|
$(V1) $(CC) -c -mthumb $$(ASFLAGS) $$< -o $$@
|
|
|
|
endef
|
|
|
|
|
|
|
|
# Assemble: create object files from assembler source files. ARM-only
|
|
|
|
define ASSEMBLE_ARM_TEMPLATE
|
|
|
|
$(OUTDIR)/$(notdir $(basename $(1))).o : $(1)
|
|
|
|
@echo $(MSG_ASSEMBLING_ARM) $$(call toprel, $$<)
|
|
|
|
$(V1) $(CC) -c $$(ASFLAGS) $$< -o $$@
|
|
|
|
endef
|
|
|
|
|
|
|
|
# Compile: create object files from C source files.
|
|
|
|
define COMPILE_C_TEMPLATE
|
|
|
|
$(OUTDIR)/$(notdir $(basename $(1))).o : $(1)
|
|
|
|
@echo $(MSG_COMPILING) $$(call toprel, $$<)
|
|
|
|
$(V1) $(CC) -c -mthumb $$(CFLAGS) $$(CONLYFLAGS) $$< -o $$@
|
|
|
|
endef
|
|
|
|
|
|
|
|
# Compile: create object files from C source files. ARM-only
|
|
|
|
define COMPILE_C_ARM_TEMPLATE
|
|
|
|
$(OUTDIR)/$(notdir $(basename $(1))).o : $(1)
|
|
|
|
@echo $(MSG_COMPILING_ARM) $$(call toprel, $$<)
|
|
|
|
$(V1) $(CC) -c $$(CFLAGS) $$(CONLYFLAGS) $$< -o $$@
|
|
|
|
endef
|
|
|
|
|
|
|
|
# Compile: create object files from C++ source files.
|
|
|
|
define COMPILE_CPP_TEMPLATE
|
|
|
|
$(OUTDIR)/$(notdir $(basename $(1))).o : $(1)
|
|
|
|
@echo $(MSG_COMPILINGCPP) $$(call toprel, $$<)
|
|
|
|
$(V1) $(CC) -c -mthumb $$(CFLAGS) $$(CPPFLAGS) $$< -o $$@
|
|
|
|
endef
|
|
|
|
|
|
|
|
# Compile: create object files from C++ source files. ARM-only
|
|
|
|
define COMPILE_CPP_ARM_TEMPLATE
|
|
|
|
$(OUTDIR)/$(notdir $(basename $(1))).o : $(1)
|
|
|
|
@echo $(MSG_COMPILINGCPP_ARM) $$(call toprel, $$<)
|
|
|
|
$(V1) $(CC) -c $$(CFLAGS) $$(CPPFLAGS) $$< -o $$@
|
|
|
|
endef
|
|
|
|
|
|
|
|
# Link: create ELF output file from object files.
|
|
|
|
# $1 = elf file to produce
|
|
|
|
# $2 = list of object files that make up the elf file
|
|
|
|
define LINK_TEMPLATE
|
|
|
|
.SECONDARY : $(1)
|
|
|
|
.PRECIOUS : $(2)
|
|
|
|
$(1): $(2)
|
|
|
|
@echo $(MSG_LINKING) $$(call toprel, $$@)
|
|
|
|
$(V1) $(CC) -mthumb $$(CFLAGS) $(2) --output $$@ $$(LDFLAGS)
|
|
|
|
endef
|
|
|
|
|
|
|
|
# Compile: create assembler files from C source files. ARM/Thumb
|
|
|
|
define PARTIAL_COMPILE_TEMPLATE
|
|
|
|
$($(1):.c=.s) : %.s : %.c
|
|
|
|
@echo $(MSG_ASMFROMC) $$(call toprel, $$<)
|
|
|
|
$(V1) $(CC) -mthumb -S $$(CFLAGS) $$(CONLYFLAGS) $$< -o $$@
|
|
|
|
endef
|
|
|
|
|
|
|
|
# Compile: create assembler files from C source files. ARM only
|
|
|
|
define PARTIAL_COMPILE_ARM_TEMPLATE
|
|
|
|
$($(1):.c=.s) : %.s : %.c
|
|
|
|
@echo $(MSG_ASMFROMC_ARM) $$(call toprel, $$<)
|
|
|
|
$(V1) $(CC) -S $$(CFLAGS) $$(CONLYFLAGS) $$< -o $$@
|
|
|
|
endef
|
|
|
|
|
2011-05-24 07:10:31 +02:00
|
|
|
# $(1) = Name of binary image to write
|
|
|
|
# $(2) = Base of flash region to write/wipe
|
|
|
|
# $(3) = Size of flash region to write/wipe
|
|
|
|
define JTAG_TEMPLATE
|
2011-04-24 17:19:00 +02:00
|
|
|
# ---------------------------------------------------------------------------
|
2011-04-25 00:37:45 +02:00
|
|
|
# Options for OpenOCD flash-programming
|
2011-04-24 17:19:00 +02:00
|
|
|
# see openocd.pdf/openocd.texi for further information
|
2011-04-25 00:37:45 +02:00
|
|
|
|
2011-04-24 17:19:00 +02:00
|
|
|
# if OpenOCD is in the $PATH just set OPENOCDEXE=openocd
|
2011-05-24 07:10:31 +02:00
|
|
|
OOCD_EXE ?= openocd
|
|
|
|
|
2011-04-24 17:19:00 +02:00
|
|
|
# debug level
|
2011-05-24 07:10:31 +02:00
|
|
|
OOCD_JTAG_SETUP = -d0
|
2011-04-24 17:19:00 +02:00
|
|
|
# interface and board/target settings (using the OOCD target-library here)
|
2011-05-24 07:10:31 +02:00
|
|
|
OOCD_JTAG_SETUP += -s $(TOP)/flight/Project/OpenOCD
|
2012-04-08 04:12:49 +02:00
|
|
|
OOCD_JTAG_SETUP += -f flyswatter.cfg -f stm32f1x.cfg
|
2011-04-24 17:19:00 +02:00
|
|
|
|
|
|
|
# initialize
|
2011-05-24 07:10:31 +02:00
|
|
|
OOCD_BOARD_RESET = -c init
|
2011-04-24 17:19:00 +02:00
|
|
|
# show the targets
|
2011-05-24 07:10:31 +02:00
|
|
|
#OOCD_BOARD_RESET += -c targets
|
2011-04-24 17:19:00 +02:00
|
|
|
# commands to prepare flash-write
|
2011-05-24 07:10:31 +02:00
|
|
|
OOCD_BOARD_RESET += -c "reset halt"
|
|
|
|
|
|
|
|
.PHONY: program
|
|
|
|
program: $(1)
|
|
|
|
@echo $(MSG_JTAG_PROGRAM) $$(call toprel, $$<)
|
|
|
|
$(V1) $(OOCD_EXE) \
|
|
|
|
$$(OOCD_JTAG_SETUP) \
|
|
|
|
$$(OOCD_BOARD_RESET) \
|
2012-04-08 04:12:49 +02:00
|
|
|
-c "flash write_image erase $(subst c:,,$(1)) $(2) bin" \
|
|
|
|
-c "verify_image $(subst c:,,$(1)) $(2) bin" \
|
2011-05-24 07:10:31 +02:00
|
|
|
-c "reset run" \
|
|
|
|
-c "shutdown"
|
|
|
|
|
|
|
|
.PHONY: wipe
|
|
|
|
wipe:
|
|
|
|
@echo $(MSG_JTAG_WIPE) wiping $(3) bytes starting from $(2)
|
|
|
|
$(V1) $(OOCD_EXE) \
|
|
|
|
$$(OOCD_JTAG_SETUP) \
|
|
|
|
$$(OOCD_BOARD_RESET) \
|
|
|
|
-c "flash erase_address pad $(2) $(3)" \
|
|
|
|
-c "reset run" \
|
|
|
|
-c "shutdown"
|
2012-04-08 04:12:49 +02:00
|
|
|
endef
|