From 542673fa2943f317142770f8b894f7731456c99c Mon Sep 17 00:00:00 2001 From: podhrmic Date: Tue, 15 Oct 2013 15:43:11 -0600 Subject: [PATCH] Makefile and linker update 1) Custom linker script in case we are using luftboot (8kb memory offset) 2) Custom makefiles rules for chibios (no .dep/ folder) --- conf/Makefile.chibios | 124 +++++++++--- conf/boards/lia_1.1_chibios.makefile | 1 - conf/chibios_rules.mk | 244 ++++++++++++++++++++++++ sw/airborne/arch/chibios/STM32F107xC.ld | 163 ++++++++++++++++ 4 files changed, 506 insertions(+), 26 deletions(-) create mode 100644 conf/chibios_rules.mk create mode 100644 sw/airborne/arch/chibios/STM32F107xC.ld diff --git a/conf/Makefile.chibios b/conf/Makefile.chibios index ef3ab8ca465..6aaced8d218 100644 --- a/conf/Makefile.chibios +++ b/conf/Makefile.chibios @@ -30,6 +30,7 @@ # CHIBIOS = $(PAPARAZZI_SRC)/sw/ext/chibios CHIBIOS_SPECIFIC_DIR = $(PAPARAZZI_SRC)/sw/airborne/boards/$(BOARD)/chibios +CHIBIOS_ARCH_DIR = $(PAPARAZZI_SRC)/sw/airborne/arch/chibios # Launch with "make Q=''" to get full command display Q=@ @@ -108,13 +109,14 @@ include $(CHIBIOS)/os/hal/platforms/$(CHIBIOS_BOARD_PLATFORM) include $(CHIBIOS)/os/hal/hal.mk include $(CHIBIOS)/os/ports/GCC/$(CHIBIOS_BOARD_PORT) include $(CHIBIOS)/os/kernel/kernel.mk -#include $(CHIBIOS)/test/test.mk # Define linker script file here +ifdef NO_LUFTBOOT LDSCRIPT= $(PORTLD)/$(CHIBIOS_BOARD_LINKER) -# Define linker script file here -#LDSCRIPT= $($(TARGET).LDSCRIPT) +else +LDSCRIPT= $(CHIBIOS_ARCH_DIR)/$(CHIBIOS_BOARD_LINKER) +endif # C sources that can be compiled in ARM or THUMB mode depending on the global # setting. @@ -251,29 +253,11 @@ ULIBS = # End of user defines ############################################################################## -# TODO: remove these... -# Info messages -#$(info CHIBIOS = $(CHIBIOS)) -#$(info PORTSRC = $(PORTSRC)) -#$(info KERNSRC = $(KERNSRC)) -#$(info TESTSRC = $(TESTSRC)) -#$(info HALSRC = $(HALSRC)) -#$(info PLATFORMSRC = $(PLATFORMSRC)) -#$(info BOARDSRC = $(BOARDSRC)) -$(info INCDIR = $(INCDIR)) -$(info UINCDIR = $(UINCDIR)) -$(info CSRC = $(CSRC)) -$(info UDEFS = $(UDEFS)) - # # Include upload rules ############################################################################## -# Default upload using black magic probe -#ifndef FLASH_MODE -#FLASH_MODE = JTAG -#endif - -# for now, no luftboot +# default: assume the luftboot bootloader is used +# if luftboot is not used define NO_LUFTBOOT to a value != 0 ASSUMING_LUFTBOOT = "yes" # Settings for GDB @@ -294,8 +278,98 @@ OOCD_BOARD = $($(TARGET).OOCD_BOARD) endif ############################################################################### # Upload makefile -include $(PAPARAZZI_HOME)/conf/Makefile.stm32-upload +#include $(PAPARAZZI_HOME)/conf/Makefile.stm32-upload +# +# check which flash mode is configured +# +ifeq ($(FLASH_MODE),DFU) +ifeq ($(DFU_UTIL),y) +# +# DFU flash mode using dfu-util +DFU_ADDR ?= 0x08000000 +upload: $(OBJDIR)/$(TARGET).bin + @echo "Using dfu-util at $(DFU_ADDR)" + $(Q)dfu-util -d 0483:df11 -c 1 -i 0 -a 0 -s $(DFU_ADDR) -D $^ +else +# +# DFU flash mode paparazzi stm32_mem +ifdef DFU_ADDR +DFU_ADDR_CMD = --addr=$(DFU_ADDR) +endif +ifdef DFU_PRODUCT +DFU_PRODUCT_CMD = --product=$(DFU_PRODUCT) +endif +upload: $(OBJDIR)/$(TARGET).bin + @echo "Using stm32 mem dfu loader" + $(PYTHON) $(PAPARAZZI_SRC)/sw/tools/dfu/stm32_mem.py $(DFU_PRODUCT_CMD) $(DFU_ADDR_CMD) $^ +endif +# +# serial flash mode +else ifeq ($(FLASH_MODE),SERIAL) +upload: $(OBJDIR)/$(TARGET).bin + $(LOADER) -p /dev/ttyUSB0 -b 115200 -e -w -v $^ +# +# JTAG flash mode +else ifeq ($(FLASH_MODE),JTAG) +# either via normal jtag or BlackMagicProbe +ifeq ($(BMP_PORT),) +# normal jtag via OpenOCD +upload: $(OBJDIR)/$(TARGET).hex + @echo "Assuming luftboot bootloader: $(ASSUMING_LUFTBOOT)" + @echo "Using OOCD = $(OOCD)" + @echo " OOCD\t$<" + $(Q)$(OOCD) -f interface/$(OOCD_INTERFACE).cfg \ + -f board/$(OOCD_BOARD).cfg $(OOCD_OPTIONS) \ + -c init \ + -c "reset halt" \ + -c "reset init" \ + -c "flash erase_sector 0 $(OOCD_START_SECTOR) last" \ + -c "flash write_image $<" \ + -c reset \ + -c shutdown +else +# jtag via BMP +BMP_UPLOAD_SCRIPT ?= $(PAPARAZZI_SRC)/sw/tools/flash_scripts/bmp_jtag_flash.scr + +upload: $(OBJDIR)/$(TARGET).elf + @echo "Assuming luftboot bootloader: $(ASSUMING_LUFTBOOT)" + @echo "Using Black Magic Probe with JTAG on BMP_PORT $(BMP_PORT)" + @echo "Using GDB = $(GDB)" + @echo " BMP\t$<" + $(Q)$(GDB) --batch \ + -ex 'target extended-remote $(BMP_PORT)' \ + -x $(BMP_UPLOAD_SCRIPT) \ + $< +endif +# +# SWD flash mode +else ifeq ($(FLASH_MODE),SWD) +# only works if BMP_PORT is defined +ifeq ($(STLINK),y) +STLINK_ADDR ?= 0x08000000 +upload: $(OBJDIR)/$(TARGET).bin + @echo "Using ST-LINK with SWD at $(STLINK_ADDR)" + $(Q)st-flash write $^ $(STLINK_ADDR) +else +BMP_PORT ?= /dev/ttyACM0 +BMP_UPLOAD_SCRIPT ?= $(PAPARAZZI_SRC)/sw/tools/flash_scripts/bmp_swd_flash.scr +upload: $(OBJDIR)/$(TARGET).elf + @echo "Assuming luftboot bootloader: $(ASSUMING_LUFTBOOT)" + @echo "Using Black Magic Probe with SWD on BMP_PORT $(BMP_PORT)" + @echo "Using GDB = $(GDB)" + @echo " BMP\t$<" + $(Q)$(GDB) --batch \ + -ex 'target extended-remote $(BMP_PORT)' \ + -x $(BMP_UPLOAD_SCRIPT) \ + $< +endif +# +# no known flash mode +else +upload: + @echo unknown flash_mode $(FLASH_MODE) +endif ############################################################################### ifeq ($(USE_FPU),yes) @@ -306,4 +380,4 @@ else endif # Compile -include $(CHIBIOS)/os/ports/GCC/ARMCMx/rules.mk +include $(PAPARAZZI_HOME)/conf/chibios_rules.mk diff --git a/conf/boards/lia_1.1_chibios.makefile b/conf/boards/lia_1.1_chibios.makefile index acea2b860c9..b87917f36d3 100644 --- a/conf/boards/lia_1.1_chibios.makefile +++ b/conf/boards/lia_1.1_chibios.makefile @@ -65,7 +65,6 @@ DFU_UTIL ?= n ifndef NO_LUFTBOOT $(TARGET).CFLAGS+=-DLUFTBOOT -$(TARGET).LDFLAGS+=-Wl,-Ttext=0x8002000 endif ############################################################################## diff --git a/conf/chibios_rules.mk b/conf/chibios_rules.mk new file mode 100644 index 00000000000..56e6eef90c0 --- /dev/null +++ b/conf/chibios_rules.mk @@ -0,0 +1,244 @@ +# +# Copyright (C) 2013 AggieAir, A Remote Sensing Unmanned Aerial System for Scientific Applications +# Utah State University, http://aggieair.usu.edu/ +# +# Michal Podhradsky (michal.podhradsky@aggiemail.usu.edu) +# Calvin Coopmans (c.r.coopmans@ieee.org) +# +# credits to ENAC team for initial work on ChibiOs and Paparazzi integration +# +# This file is part of paparazzi. +# +# paparazzi is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# paparazzi is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with paparazzi; see the file COPYING. If not, write to +# the Free Software Foundation, 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. +# + +# +# This makefile rules are copied from ChibiOS/RT +# see sw/ext/chibios/os/ports/GCC/ARMCMx/rules.mk +# and modified +# +# ARM Cortex-Mx common makefile scripts and rules. + +# Output directory and files +ifeq ($(BUILDDIR),) + BUILDDIR = build +endif +ifeq ($(BUILDDIR),.) + BUILDDIR = build +endif +OUTFILES = $(BUILDDIR)/$(PROJECT).elf $(BUILDDIR)/$(PROJECT).hex \ + $(BUILDDIR)/$(PROJECT).bin $(BUILDDIR)/$(PROJECT).dmp + +# Automatic compiler options +OPT = $(USE_OPT) +COPT = $(USE_COPT) +CPPOPT = $(USE_CPPOPT) +ifeq ($(USE_LINK_GC),yes) + OPT += -ffunction-sections -fdata-sections -fno-common +endif + +# Source files groups and paths +ifeq ($(USE_THUMB),yes) + TCSRC += $(CSRC) + TCPPSRC += $(CPPSRC) +else + ACSRC += $(CSRC) + ACPPSRC += $(CPPSRC) +endif +ASRC = $(ACSRC)$(ACPPSRC) +TSRC = $(TCSRC)$(TCPPSRC) +SRCPATHS = $(sort $(dir $(ASMXSRC)) $(dir $(ASMSRC)) $(dir $(ASRC)) $(dir $(TSRC))) + +# Various directories +OBJDIR = $(BUILDDIR)/obj +LSTDIR = $(BUILDDIR)/lst + +# Object files groups +ACOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ACSRC:.c=.o))) +ACPPOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ACPPSRC:.cpp=.o))) +TCOBJS = $(addprefix $(OBJDIR)/, $(notdir $(TCSRC:.c=.o))) +TCPPOBJS = $(addprefix $(OBJDIR)/, $(notdir $(TCPPSRC:.cpp=.o))) +ASMOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ASMSRC:.s=.o))) +ASMXOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ASMXSRC:.S=.o))) +OBJS = $(ASMXOBJS) $(ASMOBJS) $(ACOBJS) $(TCOBJS) $(ACPPOBJS) $(TCPPOBJS) + +# Paths +IINCDIR = $(patsubst %,-I%,$(INCDIR) $(DINCDIR) $(UINCDIR)) +LLIBDIR = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR)) + +# Macros +DEFS = $(DDEFS) $(UDEFS) +ADEFS = $(DADEFS) $(UADEFS) + +# Libs +LIBS = $(DLIBS) $(ULIBS) + +# Various settings +MCFLAGS = -mcpu=$(MCU) +ODFLAGS = -x --syms +ASFLAGS = $(MCFLAGS) -Wa,-amhls=$(LSTDIR)/$(notdir $(<:.s=.lst)) $(ADEFS) +ASXFLAGS = $(MCFLAGS) -Wa,-amhls=$(LSTDIR)/$(notdir $(<:.S=.lst)) $(ADEFS) +CFLAGS = $(MCFLAGS) $(OPT) $(COPT) $(CWARN) -Wa,-alms=$(LSTDIR)/$(notdir $(<:.c=.lst)) $(DEFS) +CPPFLAGS = $(MCFLAGS) $(OPT) $(CPPOPT) $(CPPWARN) -Wa,-alms=$(LSTDIR)/$(notdir $(<:.cpp=.lst)) $(DEFS) +ifeq ($(USE_LINK_GC),yes) + LDFLAGS = $(MCFLAGS) -nostartfiles -T$(LDSCRIPT) -Wl,-Map=$(BUILDDIR)/$(PROJECT).map,--cref,--no-warn-mismatch,--gc-sections $(LLIBDIR) +else + LDFLAGS = $(MCFLAGS) -nostartfiles -T$(LDSCRIPT) -Wl,-Map=$(BUILDDIR)/$(PROJECT).map,--cref,--no-warn-mismatch $(LLIBDIR) +endif + +# Thumb interwork enabled only if needed because it kills performance. +ifneq ($(TSRC),) + CFLAGS += -DTHUMB_PRESENT + CPPFLAGS += -DTHUMB_PRESENT + ASFLAGS += -DTHUMB_PRESENT + ifneq ($(ASRC),) + # Mixed ARM and THUMB mode. + CFLAGS += -mthumb-interwork + CPPFLAGS += -mthumb-interwork + ASFLAGS += -mthumb-interwork + LDFLAGS += -mthumb-interwork + else + # Pure THUMB mode, THUMB C code cannot be called by ARM asm code directly. + CFLAGS += -mno-thumb-interwork -DTHUMB_NO_INTERWORKING + CPPFLAGS += -mno-thumb-interwork -DTHUMB_NO_INTERWORKING + ASFLAGS += -mno-thumb-interwork -DTHUMB_NO_INTERWORKING -mthumb + LDFLAGS += -mno-thumb-interwork -mthumb + endif +else + # Pure ARM mode + CFLAGS += -mno-thumb-interwork + CPPFLAGS += -mno-thumb-interwork + ASFLAGS += -mno-thumb-interwork + LDFLAGS += -mno-thumb-interwork +endif + +# Paths where to search for sources +VPATH = $(SRCPATHS) + +# +# Include user extra rules if any +# +ifneq ($(EXTRA_RULES_INCLUDE_PATH),) +include $(EXTRA_RULES_INCLUDE_PATH) +endif + +# +# Makefile rules +# +all: $(OBJS) $(OUTFILES) MAKE_ALL_RULE_HOOK + +MAKE_ALL_RULE_HOOK: + +$(OBJS): | $(BUILDDIR) + +$(BUILDDIR) $(OBJDIR) $(LSTDIR): +ifneq ($(USE_VERBOSE_COMPILE),yes) + @echo Compiler Options + @echo $(CC) -c $(CFLAGS) -I. $(IINCDIR) main.c -o main.o + @echo +endif + mkdir -p $(OBJDIR) + mkdir -p $(LSTDIR) + +$(ACPPOBJS) : $(OBJDIR)/%.o : %.cpp Makefile +ifeq ($(USE_VERBOSE_COMPILE),yes) + @echo + $(CPPC) -c $(CPPFLAGS) $(AOPT) -I. $(IINCDIR) $< -o $@ +else + @echo Compiling $( $@ +else + @echo Creating $@ + @$(OD) $(ODFLAGS) $< > $@ + @echo Done +endif + +# *** EOF *** diff --git a/sw/airborne/arch/chibios/STM32F107xC.ld b/sw/airborne/arch/chibios/STM32F107xC.ld new file mode 100644 index 00000000000..b982850e577 --- /dev/null +++ b/sw/airborne/arch/chibios/STM32F107xC.ld @@ -0,0 +1,163 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011,2012,2013 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + --- + + A special exception to the GPL can be applied should you wish to distribute + a combined work that includes ChibiOS/RT, without being obliged to provide + the source code for any proprietary components. See the file exception.txt + for full details of how and when the exception can be applied. +*/ + +/* + * ST32F107xC memory setup. + * Modified by Michal Podhradsky, 2013 + * Flash addr is shifted by 8kb (luftboot) + * Note: probably not the cleanest solution, but it works + */ +__main_stack_size__ = 0x0400; +__process_stack_size__ = 0x0400; + +MEMORY +{ + flash : org = 0x08002000, len = 248k + ram : org = 0x20000000, len = 64k +} + +__ram_start__ = ORIGIN(ram); +__ram_size__ = LENGTH(ram); +__ram_end__ = __ram_start__ + __ram_size__; + +ENTRY(ResetHandler) + +SECTIONS +{ + . = 0; + _text = .; + + startup : ALIGN(16) SUBALIGN(16) + { + KEEP(*(vectors)) + } > flash + + constructors : ALIGN(4) SUBALIGN(4) + { + PROVIDE(__init_array_start = .); + KEEP(*(SORT(.init_array.*))) + KEEP(*(.init_array)) + PROVIDE(__init_array_end = .); + } > flash + + destructors : ALIGN(4) SUBALIGN(4) + { + PROVIDE(__fini_array_start = .); + KEEP(*(.fini_array)) + KEEP(*(SORT(.fini_array.*))) + PROVIDE(__fini_array_end = .); + } > flash + + .text : ALIGN(16) SUBALIGN(16) + { + *(.text.startup.*) + *(.text) + *(.text.*) + *(.rodata) + *(.rodata.*) + *(.glue_7t) + *(.glue_7) + *(.gcc*) + } > flash + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > flash + + .ARM.exidx : { + PROVIDE(__exidx_start = .); + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + PROVIDE(__exidx_end = .); + } > flash + + .eh_frame_hdr : + { + *(.eh_frame_hdr) + } > flash + + .eh_frame : ONLY_IF_RO + { + *(.eh_frame) + } > flash + + .textalign : ONLY_IF_RO + { + . = ALIGN(8); + } > flash + + . = ALIGN(4); + _etext = .; + _textdata = _etext; + + .stacks : + { + . = ALIGN(8); + __main_stack_base__ = .; + . += __main_stack_size__; + . = ALIGN(8); + __main_stack_end__ = .; + __process_stack_base__ = .; + __main_thread_stack_base__ = .; + . += __process_stack_size__; + . = ALIGN(8); + __process_stack_end__ = .; + __main_thread_stack_end__ = .; + } > ram + + .data : + { + . = ALIGN(4); + PROVIDE(_data = .); + *(.data) + . = ALIGN(4); + *(.data.*) + . = ALIGN(4); + *(.ramtext) + . = ALIGN(4); + PROVIDE(_edata = .); + } > ram AT > flash + + .bss : + { + . = ALIGN(4); + PROVIDE(_bss_start = .); + *(.bss) + . = ALIGN(4); + *(.bss.*) + . = ALIGN(4); + *(COMMON) + . = ALIGN(4); + PROVIDE(_bss_end = .); + } > ram +} + +PROVIDE(end = .); +_end = .; + +__heap_base__ = _end; +__heap_end__ = __ram_end__;