summaryrefslogtreecommitdiff
path: root/controller/fw/Makefile
diff options
context:
space:
mode:
authorjaseg <git-bigdata-wsl-arch@jaseg.de>2020-02-27 14:39:18 +0100
committerjaseg <git-bigdata-wsl-arch@jaseg.de>2020-02-27 14:39:18 +0100
commitb489a1b12f2f574ed24237601b3797b58d302196 (patch)
treefe9bbd687c6ea9d3fe4f453f3419810f3c7e9ad4 /controller/fw/Makefile
parentfcbdab4ab27e83acf0ed721583db4ddbf6222341 (diff)
downloadmaster-thesis-b489a1b12f2f574ed24237601b3797b58d302196.tar.gz
master-thesis-b489a1b12f2f574ed24237601b3797b58d302196.tar.bz2
master-thesis-b489a1b12f2f574ed24237601b3797b58d302196.zip
Add a bunch of deps
Diffstat (limited to 'controller/fw/Makefile')
-rw-r--r--controller/fw/Makefile108
1 files changed, 62 insertions, 46 deletions
diff --git a/controller/fw/Makefile b/controller/fw/Makefile
index 52951b1..9895c87 100644
--- a/controller/fw/Makefile
+++ b/controller/fw/Makefile
@@ -1,13 +1,23 @@
-SOURCES := main.c mspdebug_wrapper.c spi_flash.c
-SOURCES += mspdebug/drivers/jtaglib.c
+OPENCM3_DIR ?= libopencm3
+CMSIS_DIR ?= cmsis
+MSPDEBUG_DIR ?= mspdebug
+LIBSODIUM_DIR ?= libsodium
+TINYAES_DIR ?= tinyaes
+MUSL_DIR ?= musl
+
+C_SOURCES := src/main.c src/mspdebug_wrapper.c src/spi_flash.c
+C_SOURCES += $(MSPDEBUG_DIR)/drivers/jtaglib.c
+C_SOURCES += $(CMSIS_DIR)/CMSIS/DSP/Source/TransformFunctions/arm_rfft_f32.c
+C_SOURCES += $(CMSIS_DIR)/CMSIS/DSP/Source/TransformFunctions/arm_bitreversal.c
+C_SOURCES += $(CMSIS_DIR)/CMSIS/DSP/Source/TransformFunctions/arm_cfft_radix4_f32.c
+
+CXX_SOURCES += src/ldpc_wrapper.cpp
BUILDDIR ?= build
BINARY := safetyreset
LDSCRIPT := stm32f407.ld
-LIBNAME := opencm3_stm32f4
-
-OPENCM3_DIR ?= libopencm3
+OPENCM3_LIB := opencm3_stm32f4
PREFIX ?= arm-none-eabi-
@@ -21,73 +31,79 @@ OBJCOPY := $(PREFIX)objcopy
OBJDUMP := $(PREFIX)objdump
GDB := $(PREFIX)gdb
+OPENCM3_DIR := $(abspath $(OPENCM3_DIR))
+CMSIS_DIR := $(abspath $(CMSIS_DIR))
+MSPDEBUG_DIR := $(abspath $(MSPDEBUG_DIR))
+LIBSODIUM_DIR := $(abspath $(LIBSODIUM_DIR))
+TINYAES_DIR := $(abspath $(TINYAES_DIR))
+MUSL_DIR := $(abspath $(MUSL_DIR))
CFLAGS += -I$(OPENCM3_DIR)/include -Imspdebug/util -Imspdebug/drivers
+CFLAGS += -I$(CMSIS_DIR)/CMSIS/DSP/Include -I$(CMSIS_DIR)/CMSIS/Core/Include
CFLAGS += -Os -std=gnu11 -g -DSTM32F4
# Note: libopencm3 requires some standard libc definitions from stdint.h and stdbool.h, so we don't pass -nostdinc here.
CFLAGS += -nostdlib -ffreestanding
-CFLAGS += -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -g
-CFLAGS += -Wextra -Wshadow -Wimplicit-function-declaration -Wundef
-CFLAGS += -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes
+CFLAGS += -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16
CFLAGS += -fno-common -ffunction-sections -fdata-sections
+INT_CFLAGS += -Wextra -Wshadow -Wimplicit-function-declaration -Wundef
+INT_CFLAGS += -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes
+
+CXXFLAGS += -Os -g
+CXXFLAGS += -nostdlib -ffreestanding
+CXXFLAGS += -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16
+CXXFLAGS += -fno-common -ffunction-sections -fdata-sections
+CXXFLAGS += -Wextra -Wshadow -Wundef -Wredundant-decls
+CXXFLAGS += -I.
+
LDFLAGS += --static -nostartfiles
LDFLAGS += -T$(LDSCRIPT)
LDFLAGS += -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -g
LDFLAGS += -Wl,--cre
#LDFLAGS += -Wl,--gc-sections
LDFLAGS += -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group
-LDFLAGS += -L$(OPENCM3_DIR)/lib
-LDFLAGS += -l$(LIBNAME) $(shell $(CC) -print-libgcc-file-name)
+LDFLAGS += -L$(OPENCM3_DIR)/lib -l$(OPENCM3_LIB) $(shell $(CC) -print-libgcc-file-name)
-all: elf
+all: $(BUILDDIR)/$(BINARY).elf
-elf: $(BUILDDIR)/$(BINARY).elf
-bin: $(BUILDDIR)/$(BINARY).bin
-hex: $(BUILDDIR)/$(BINARY).hex
-srec: $(BUILDDIR)/$(BINARY).srec
-list: $(BUILDDIR)/$(BINARY).list
+OBJS := $(addprefix $(BUILDDIR)/,$(C_SOURCES:.c=.o) $(CXX_SOURCES:.cpp=.o))
-images: $(BUILDDIR)/$(BINARY).images
-$(OPENCM3_DIR)/lib/lib$(LIBNAME).a:
- echo "Warning, $@ not found, attempting to rebuild in $(OPENCM3_DIR)"
- $(MAKE) -C $(OPENCM3_DIR)
+$(BUILDDIR)/%.elf: $(OBJS) $(LDSCRIPT) $(OPENCM3_DIR)/lib/lib$(OPENCM3_LIB).a $(BUILDDIR)/libsodium/src/libsodium/.libs/libsodium.a $(BUILDDIR)/tinyaes/aes.o $(BUILDDIR)/musl/lib/libc.a
+ $(LD) $(OBJS) $(LDFLAGS) -o $@ -Wl,-Map=$(BUILDDIR)/src/$*.map $(BUILDDIR)/libsodium/src/libsodium/.libs/libsodium.a $(BUILDDIR)/tinyaes/aes.o
-OBJS := $(addprefix $(BUILDDIR)/,$(SOURCES:%.c=%.o))
+$(BUILDDIR)/src/%.o: src/%.c
+ mkdir -p $(@D)
+ $(CC) $(CFLAGS) $(INT_CFLAGS) -o $@ -c $<
-# Define a helper macro for debugging make errors online
-# you can type "make print-OPENCM3_DIR" and it will show you
-# how that ended up being resolved by all of the included
-# makefiles.
-print-%:
- @echo $*=$($*)
+$(BUILDDIR)/src/%.o: src/%.cpp
+ mkdir -p $(@D)
+ $(CXX) $(CXXFLAGS) -o $@ -c $<
-$(BUILDDIR)/%.images: $(BUILDDIR)/%.bin $(BUILDDIR)/%.hex $(BUILDDIR)/%.srec $(BUILDDIR)/%.list $(BUILDDIR)/%.map
-
-$(BUILDDIR)/%.bin: $(BUILDDIR)/%.elf
- $(OBJCOPY) -Obinary $< $@
-
-$(BUILDDIR)/%.hex: $(BUILDDIR)/%.elf
- $(OBJCOPY) -Oihex $< $@
-
-$(BUILDDIR)/%.srec: $(BUILDDIR)/%.elf
- $(OBJCOPY) -Osrec $< $@
+$(BUILDDIR)/%.o: %.c
+ mkdir -p $(@D)
+ $(CC) $(CFLAGS) $(EXT_CFLAGS) -o $@ -c $<
-$(BUILDDIR)/%.list: $(BUILDDIR)/%.elf
- $(OBJDUMP) -S $< > $@
+$(OPENCM3_DIR)/lib/lib$(OPENCM3_LIB).a:
+ $(MAKE) -C $(OPENCM3_DIR) -j $(shell nproc)
-$(BUILDDIR)/%.elf: $(OBJS) $(LDSCRIPT) $(OPENCM3_DIR)/lib/lib$(LIBNAME).a
- $(LD) $(OBJS) $(LDFLAGS) -o $@ -Wl,-Map=$*.map
+$(BUILDDIR)/libsodium/src/libsodium/.libs/libsodium.a:
+ mkdir -p build/libsodium
+ cd build/libsodium && CFLAGS="$(CFLAGS) -DDEV_MODE=1" $(LIBSODIUM_DIR)/configure --host=arm-none-eabi && $(MAKE) -j $(shell nproc)
-$(BUILDDIR)/%.o: %.c
- mkdir -p $(dir $@)
- $(CC) $(CFLAGS) -o $@ -c $<
+$(BUILDDIR)/tinyaes/aes.o:
+ mkdir -p $(@D)
+ make -C $(@D) -f $(TINYAES_DIR)/Makefile VPATH=$(TINYAES_DIR) CFLAGS="$(CFLAGS) -c" CC=$(CC) LD=$(LD) AR=$(AR) aes.o
clean:
- -rm -r $(BUILDDIR)
+ -rm -r $(BUILDDIR)/src
+ -rm $(BUILDDIR)/$(BINARY).elf
+
+mrproper: clean
+ -rm -r build
+ -$(MAKE) -C $(OPENCM3_DIR) clean
-.PHONY: images clean elf bin hex srec list
+.PHONY: clean mrproper
-include $(OBJS:.o=.d)