diff options
Diffstat (limited to 'Makefile')
-rw-r--r-- | Makefile | 121 |
1 files changed, 62 insertions, 59 deletions
@@ -1,35 +1,57 @@ +# Copyright (c) 2015, SUNET +# +# 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. +# +# 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. + +# "stm32-native" projects SELF-TESTS = fmc-test led-test short-test uart-test fmc-perf +vpath %.c self-test -LIBHAL-TESTS = cores test-bus test-hash test-aes-key-wrap test-pbkdf2 test-ecdsa #test-rsa +# apps originally written for unix-like environment +LIBHAL-TESTS = cores test-bus test-hash test-aes-key-wrap test-pbkdf2 #test-ecdsa #test-rsa +vpath %.c libhal/tests libhal/utils -# put your *.o targets here, make should handle the rest! -SRCS = stm32f4xx_hal_msp.c stm32f4xx_it.c stm-fmc.c stm-init.c stm-uart.c - -TOPLEVEL=. +# absolute path, because we're going to be passing -I cflags to sub-makes +TOPLEVEL = $(shell pwd) # Location of the Libraries folder from the STM32F0xx Standard Peripheral Library -STD_PERIPH_LIB ?= $(TOPLEVEL)/Drivers +STD_PERIPH_LIB = $(TOPLEVEL)/Drivers -# Location of the linker scripts -LDSCRIPT_INC ?= $(TOPLEVEL)/Device/ldscripts +# linker script +LDSCRIPT = $(TOPLEVEL)/Device/ldscripts/stm32f429bitx.ld -# MCU selection parameters -# -STDPERIPH_SETTINGS ?= -DUSE_STDPERIPH_DRIVER -DSTM32F4XX -DSTM32F429xx -# -# For the dev-bridge rev01 board, use stm32f429bitx.ld. -MCU_LINKSCRIPT ?= stm32f429bitx.ld +# board-specific objects, to link into every project +BOARD_OBJS = stm32f4xx_hal_msp.o stm32f4xx_it.o stm-fmc.o stm-init.o stm-uart.o \ + Device/startup_stm32f429xx.o Device/system_stm32f4xx.o -# add startup file to build -# -# For the dev-bridge rev01 board, use startup_stm32f429xx.s. -SRCS += $(TOPLEVEL)/Device/startup_stm32f429xx.s -SRCS += $(TOPLEVEL)/Device/system_stm32f4xx.c - -# that's it, no need to change anything below this line! +# a few objects for libhal/test projects +LIBC_OBJS = syscalls.o printf.o gettimeofday.o -################################################### +LIBS = $(STD_PERIPH_LIB)/libstmf4.a libhal/libhal.a thirdparty/libtfm/libtfm.a +# cross-building tools PREFIX=arm-none-eabi- export CC=$(PREFIX)gcc export AS=$(PREFIX)as @@ -38,33 +60,20 @@ export OBJCOPY=$(PREFIX)objcopy export OBJDUMP=$(PREFIX)objdump export SIZE=$(PREFIX)size -#CFLAGS = -ggdb -O2 -Wall -Wextra -Warray-bounds -CFLAGS = -ggdb -O2 -Wall -Warray-bounds +# whew, that's a lot of cflags +CFLAGS = -ggdb -O2 -Wall -Warray-bounds #-Wextra CFLAGS += -mcpu=cortex-m4 -mthumb -mlittle-endian -mthumb-interwork CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 -CFLAGS += $(STDPERIPH_SETTINGS) +CFLAGS += -DUSE_STDPERIPH_DRIVER -DSTM32F4XX -DSTM32F429xx CFLAGS += -ffunction-sections -fdata-sections CFLAGS += -Wl,--gc-sections CFLAGS += -std=c99 - -################################################### - -vpath %.c src self-test -vpath %.a $(STD_PERIPH_LIB) - -IFLAGS += -I include -I $(STD_PERIPH_LIB) -I $(STD_PERIPH_LIB)/CMSIS/Device/ST/STM32F4xx/Include -IFLAGS += -I $(STD_PERIPH_LIB)/CMSIS/Include -I $(STD_PERIPH_LIB)/STM32F4xx_HAL_Driver/Inc - -%.o: %.c - $(CC) -c $(CFLAGS) $(IFLAGS) -o $@ $< - -OBJS = $(patsubst %.s,%.o, $(patsubst %.c,%.o, $(SRCS))) - -################################################### - -.PHONY: lib self-test - -LIBS = $(STD_PERIPH_LIB)/libstmf4.a libhal/libhal.a thirdparty/libtfm/libtfm.a +CFLAGS += -I $(TOPLEVEL) -I $(STD_PERIPH_LIB) +CFLAGS += -I $(STD_PERIPH_LIB)/CMSIS/Device/ST/STM32F4xx/Include +CFLAGS += -I $(STD_PERIPH_LIB)/CMSIS/Include +CFLAGS += -I $(STD_PERIPH_LIB)/STM32F4xx_HAL_Driver/Inc +CFLAGS += -I libhal +export CFLAGS all: lib self-test libhal-tests @@ -73,10 +82,8 @@ init: lib: $(LIBS) -export CFLAGS - $(STD_PERIPH_LIB)/libstmf4.a: - $(MAKE) -C $(STD_PERIPH_LIB) STDPERIPH_SETTINGS="$(STDPERIPH_SETTINGS) -I $(PWD)/include" + $(MAKE) -C $(STD_PERIPH_LIB) thirdparty/libtfm/libtfm.a: $(MAKE) -C thirdparty/libtfm PREFIX=$(PREFIX) @@ -86,8 +93,8 @@ libhal/libhal.a: hal_io_fmc.o thirdparty/libtfm/libtfm.a self-test: $(SELF-TESTS:=.elf) -%.elf: %.o $(OBJS) $(STD_PERIPH_LIB)/libstmf4.a - $(CC) $(CFLAGS) $^ -o $@ -L$(LDSCRIPT_INC) -T$(MCU_LINKSCRIPT) -g -Wl,-Map=$*.map +%.elf: %.o $(BOARD_OBJS) $(STD_PERIPH_LIB)/libstmf4.a + $(CC) $(CFLAGS) $^ -o $@ -T$(LDSCRIPT) -g -Wl,-Map=$*.map $(OBJCOPY) -O ihex $*.elf $*.hex $(OBJCOPY) -O binary $*.elf $*.bin $(OBJDUMP) -St $*.elf >$*.lst @@ -95,26 +102,23 @@ self-test: $(SELF-TESTS:=.elf) libhal-tests: $(LIBHAL-TESTS:=.bin) -vpath %.c libhal/tests -CFLAGS += -I libhal - # .mo extension for files with main() that need to be wrapped as __main() %.mo: %.c - $(CC) -c $(CFLAGS) $(IFLAGS) -Dmain=__main -o $@ $< + $(CC) -c $(CFLAGS) -Dmain=__main -o $@ $< -vpath %.c libc libhal/utils -%.bin: %.mo main.o syscalls.o printf.o gettimeofday.o $(OBJS) $(LIBS) - $(CC) $(CFLAGS) $^ -o $*.elf -L$(LDSCRIPT_INC) -T$(MCU_LINKSCRIPT) -g -Wl,-Map=$*.map +%.bin: %.mo main.o $(BOARD_OBJS) $(LIBC_OBJS) $(LIBS) + $(CC) $(CFLAGS) $^ -o $*.elf -T$(LDSCRIPT) -g -Wl,-Map=$*.map $(OBJCOPY) -O ihex $*.elf $*.hex $(OBJCOPY) -O binary $*.elf $*.bin $(OBJDUMP) -St $*.elf >$*.lst $(SIZE) $*.elf -.SECONDARY: $(OBJS) *.mo main.o syscalls.o printf.o gettimeofday.o +# don't automatically delete objects, to avoid a lot of unnecessary rebuilding +.SECONDARY: $(BOARD_OBJS) $(LIBC_OBJS) clean: find ./ -name '*~' | xargs rm -f - rm -f $(OBJS) *.o *.mo + rm -f $(BOARD_OBJS) $(LIBC_OBJS) *.o *.mo rm -f *.elf rm -f *.hex rm -f *.bin @@ -125,4 +129,3 @@ distclean: clean $(MAKE) -C $(STD_PERIPH_LIB) clean $(MAKE) -C thirdparty/libtfm clean $(MAKE) -C libhal clean - $(MAKE) -C libc clean |