trezor-mcu/Makefile.include

196 lines
4.3 KiB
Makefile
Raw Permalink Normal View History

TOP_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
2015-12-15 14:01:54 -08:00
TOOLCHAIN_DIR ?= $(TOP_DIR)vendor/libopencm3
2017-12-18 13:48:52 -08:00
PYTHON ?= python
2017-12-13 10:38:51 -08:00
ifeq ($(EMULATOR),1)
CC ?= gcc
LD := $(CC)
OBJCOPY := objcopy
OBJDUMP := objdump
AR := ar
AS := as
2017-12-13 10:38:51 -08:00
OPTFLAGS ?= -O3
DBGFLAGS ?= -g3 -ggdb3
2017-12-13 10:38:51 -08:00
CPUFLAGS ?= -m32
FPUFLAGS ?=
2017-12-13 10:38:51 -08:00
else
PREFIX ?= arm-none-eabi-
CC := $(PREFIX)gcc
LD := $(PREFIX)gcc
OBJCOPY := $(PREFIX)objcopy
OBJDUMP := $(PREFIX)objdump
AR := $(PREFIX)ar
AS := $(PREFIX)as
OPENOCD := openocd -f interface/stlink-v2.cfg -c "transport select hla_swd" -f target/stm32f2x.cfg
2014-04-29 05:26:51 -07:00
OPTFLAGS ?= -O3
DBGFLAGS ?= -g -DNDEBUG
CPUFLAGS ?= -mcpu=cortex-m3 -mthumb
FPUFLAGS ?= -msoft-float
2017-12-13 10:38:51 -08:00
endif
2014-04-29 05:26:51 -07:00
CFLAGS += $(OPTFLAGS) \
$(DBGFLAGS) \
2016-04-29 08:06:21 -07:00
-std=gnu99 \
2014-04-29 05:26:51 -07:00
-W \
-Wall \
-Wextra \
-Wimplicit-function-declaration \
-Wredundant-decls \
-Wstrict-prototypes \
-Wundef \
-Wshadow \
-Wpointer-arith \
-Wformat \
-Wreturn-type \
-Wsign-compare \
-Wmultichar \
-Wformat-nonliteral \
-Winit-self \
-Wuninitialized \
-Wformat-security \
-Werror \
-fno-common \
-fno-exceptions \
-fvisibility=internal \
2014-06-18 17:16:28 -07:00
-ffunction-sections \
-fdata-sections \
2014-07-30 11:34:28 -07:00
-fstack-protector-all \
$(CPUFLAGS) \
$(FPUFLAGS) \
2014-04-29 05:26:51 -07:00
-DSTM32F2 \
-DCONFIDENTIAL='__attribute__((section("confidential")))' \
-DRAND_PLATFORM_INDEPENDENT=1 \
2014-04-29 05:26:51 -07:00
-I$(TOOLCHAIN_DIR)/include \
-I$(TOP_DIR) \
2015-12-14 15:20:34 -08:00
-I$(TOP_DIR)gen \
2015-12-15 14:01:54 -08:00
-I$(TOP_DIR)vendor/trezor-crypto \
-I$(TOP_DIR)vendor/trezor-qrenc
2014-04-29 05:26:51 -07:00
LDFLAGS += -L$(TOP_DIR) \
$(DBGFLAGS) \
$(CPUFLAGS) \
$(FPUFLAGS)
2017-12-13 10:38:51 -08:00
ifeq ($(EMULATOR),1)
CFLAGS += -DEMULATOR=1
2018-02-18 09:44:36 -08:00
CFLAGS += -include $(TOP_DIR)emulator/emulator.h
CFLAGS += -include stdio.h
LDFLAGS += -L$(TOP_DIR)emulator
LDLIBS += -ltrezor -lemulator
LIBDEPS += $(TOP_DIR)/libtrezor.a $(TOP_DIR)emulator/libemulator.a
2017-12-13 10:38:51 -08:00
ifeq ($(HEADLESS),1)
CFLAGS += -DHEADLESS=1
else
CFLAGS += -DHEADLESS=0
2018-02-18 11:00:40 -08:00
CFLAGS += -I/usr/include/SDL2 -D_REENTRANT
LDLIBS += -lSDL2
2017-12-13 10:38:51 -08:00
endif
else
2014-04-29 05:26:51 -07:00
ifdef APPVER
CFLAGS += -DAPPVER=$(APPVER)
LDSCRIPT = $(TOP_DIR)/memory_app_$(APPVER).ld
else
LDSCRIPT = $(TOP_DIR)/memory.ld
endif
2017-12-13 10:38:51 -08:00
CFLAGS += -DEMULATOR=0
2014-04-29 05:26:51 -07:00
LDFLAGS += --static \
-Wl,--start-group \
-lc \
-lgcc \
-lnosys \
-Wl,--end-group \
-L$(TOOLCHAIN_DIR)/lib \
-T$(LDSCRIPT) \
-nostartfiles \
-Wl,--gc-sections
2014-04-29 05:26:51 -07:00
2017-12-11 11:42:51 -08:00
LDLIBS += -ltrezor
LIBDEPS += $(TOP_DIR)/libtrezor.a
LDLIBS += -lopencm3_stm32f2
LIBDEPS += $(TOOLCHAIN_DIR)/lib/libopencm3_stm32f2.a
2017-12-13 10:38:51 -08:00
endif
ifeq ($(MEMORY_PROTECT), 0)
CFLAGS += -DMEMORY_PROTECT=0
else
CFLAGS += -DMEMORY_PROTECT=1
endif
ifeq ($(DEBUG_RNG), 1)
CFLAGS += -DDEBUG_RNG=1
else
CFLAGS += -DDEBUG_RNG=0
endif
2017-12-11 11:42:51 -08:00
2014-04-29 05:26:51 -07:00
all: $(NAME).bin
flash: $(NAME).bin
$(OPENOCD) -c "init; reset halt; flash write_image erase $(NAME).bin 0x8000000; exit"
2014-04-29 05:26:51 -07:00
upload: sign
2017-01-10 05:58:28 -08:00
trezorctl firmware_update -f $(NAME).bin
2014-04-29 05:26:51 -07:00
sign: $(NAME).bin
../bootloader/firmware_sign.py -f $(NAME).bin
release: $(NAME).bin
../bootloader/firmware_sign.py -f $(NAME).bin
cp $(NAME).bin $(NAME)-$(APPVER).bin
chmod -x $(NAME)-$(APPVER).bin
xxd -p $(NAME)-$(APPVER).bin | tr -d '\n' > $(NAME)-$(APPVER).bin.hex
$(NAME).bin: $(NAME).elf
$(OBJCOPY) -Obinary $(NAME).elf $(NAME).bin
$(NAME).hex: $(NAME).elf
$(OBJCOPY) -Oihex $(NAME).elf $(NAME).hex
$(NAME).srec: $(NAME).elf
$(OBJCOPY) -Osrec $(NAME).elf $(NAME).srec
$(NAME).list: $(NAME).elf
$(OBJDUMP) -S $(NAME).elf > $(NAME).list
2017-12-11 11:42:51 -08:00
$(NAME).elf: $(OBJS) $(LDSCRIPT) $(LIBDEPS)
$(LD) -o $(NAME).elf $(OBJS) $(LDLIBS) $(LDFLAGS)
2014-04-29 05:26:51 -07:00
%.o: %.s Makefile
$(AS) $(CPUFLAGS) -o $@ $<
2014-04-29 05:26:51 -07:00
%.o: %.c Makefile
$(CC) $(CFLAGS) -MMD -MP -o $@ -c $<
2014-04-29 05:26:51 -07:00
%.small.o: %.c Makefile
$(CC) $(CFLAGS) -MMD -MP -o $@ -c $<
%.d: %.c Makefile
@$(CC) $(CFLAGS) -MM -MP -MG -o $@ $<
%.small.d: %.c Makefile
@$(CC) $(CFLAGS) -MM -MP -MG -o $@ $<
2014-04-29 05:26:51 -07:00
clean::
2014-04-29 05:26:51 -07:00
rm -f $(OBJS)
rm -f *.a
rm -f *.bin
2014-04-29 05:26:51 -07:00
rm -f *.d
rm -f *.elf
rm -f *.hex
rm -f *.list
2014-07-01 11:29:44 -07:00
rm -f *.log
rm -f *.srec
-include $(OBJS:.o=.d)