1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-09 17:10:17 +00:00
trezor-firmware/Makefile.include
2017-12-18 20:09:59 +01:00

203 lines
4.5 KiB
Makefile

TOP_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
TOOLCHAIN_DIR ?= $(TOP_DIR)vendor/libopencm3
ifeq ($(EMULATOR),1)
CC = gcc
LD = gcc
OBJCOPY = objcopy
OBJDUMP = objdump
AR = ar
AS = as
OPTFLAGS ?= -O3
DBGFLAGS ?= -g3
CPUFLAGS ?= -m32
else
PREFIX ?= arm-none-eabi-
CC = $(PREFIX)gcc
LD = $(PREFIX)gcc
OBJCOPY = $(PREFIX)objcopy
OBJDUMP = $(PREFIX)objdump
AR = $(PREFIX)ar
AS = $(PREFIX)as
FLASH = st-flash
OPENOCD = openocd
OPTFLAGS ?= -O3
DBGFLAGS ?= -g -DNDEBUG
CPUFLAGS ?= -mcpu=cortex-m3 -mthumb
FPUFLAGS ?= -msoft-float
endif
CFLAGS += $(OPTFLAGS) \
$(DBGFLAGS) \
-std=gnu99 \
-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 \
-ffunction-sections \
-fdata-sections \
-fstack-protector-all \
$(CPUFLAGS) \
$(FPUFLAGS) \
-DSTM32F2 \
-DCONFIDENTIAL='__attribute__((section("confidential")))' \
-I$(TOOLCHAIN_DIR)/include \
-I$(TOP_DIR) \
-I$(TOP_DIR)gen \
-I$(TOP_DIR)vendor/trezor-crypto \
-I$(TOP_DIR)vendor/trezor-crypto/aes \
-I$(TOP_DIR)vendor/trezor-crypto/ed25519-donna \
-I$(TOP_DIR)vendor/trezor-qrenc
ifeq ($(EMULATOR),1)
CFLAGS += -DEMULATOR=1
ifeq ($(HEADLESS),1)
CFLAGS += -DHEADLESS=1
else
CFLAGS += -DHEADLESS=0
CFLAGS += $(shell pkg-config --cflags sdl2)
LDLIBS += $(shell pkg-config --libs sdl2)
endif
CFLAGS += -include $(TOP_DIR)emulator/emulator.h
CFLAGS += -include stdio.h
LDFLAGS += -L$(TOP_DIR) \
-L$(TOP_DIR)emulator \
$(CPUFLAGS)
LDLIBS += -ltrezor -lemulator
LIBDEPS += $(TOP_DIR)/libtrezor.a $(TOP_DIR)emulator/libemulator.a
else
ifdef APPVER
CFLAGS += -DAPPVER=$(APPVER)
LDSCRIPT = $(TOP_DIR)/memory_app_$(APPVER).ld
else
LDSCRIPT = $(TOP_DIR)/memory.ld
endif
CFLAGS += -DEMULATOR=0
LDFLAGS += --static \
-Wl,--start-group \
-lc \
-lgcc \
-lnosys \
-Wl,--end-group \
-L$(TOP_DIR) \
-L$(TOOLCHAIN_DIR)/lib \
-T$(LDSCRIPT) \
-nostartfiles \
-Wl,--gc-sections \
$(CPUFLAGS) \
$(FPUFLAGS)
LDLIBS += -ltrezor
LIBDEPS += $(TOP_DIR)/libtrezor.a
LDLIBS += -lopencm3_stm32f2
LIBDEPS += $(TOOLCHAIN_DIR)/lib/libopencm3_stm32f2.a
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
all: $(NAME).bin
flash: $(NAME).bin
$(FLASH) write $(NAME).bin 0x8000000
flash2: $(NAME).hex
$(OPENOCD) -f board/stm32f4discovery.cfg \
-c "init" \
-c "reset init" \
-c "stm32f2x mass_erase 0" \
-c "flash write_image $(NAME).hex" \
-c "reset" \
-c "shutdown"
upload: sign
trezorctl firmware_update -f $(NAME).bin
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
$(NAME).elf: $(OBJS) $(LDSCRIPT) $(LIBDEPS)
$(LD) -o $(NAME).elf $(OBJS) $(LDLIBS) $(LDFLAGS)
%.o: %.s Makefile
$(AS) $(CPUFLAGS) -o $@ $<
%.o: %.c Makefile
$(CC) $(CFLAGS) -MMD -MP -o $@ -c $<
%.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 $@ $<
clean::
rm -f $(OBJS)
rm -f *.a
rm -f *.bin
rm -f *.d
rm -f *.elf
rm -f *.hex
rm -f *.list
rm -f *.log
rm -f *.srec
-include $(OBJS:.o=.d)