2014-06-18 09:54:54 +00:00
|
|
|
TOP_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
|
2015-12-15 22:01:54 +00:00
|
|
|
TOOLCHAIN_DIR ?= $(TOP_DIR)vendor/libopencm3
|
2014-06-18 09:54:54 +00:00
|
|
|
|
2018-06-25 19:29:18 +00:00
|
|
|
ifneq ($(V),1)
|
|
|
|
Q := @
|
|
|
|
endif
|
|
|
|
|
2017-12-18 21:48:52 +00:00
|
|
|
PYTHON ?= python
|
2021-11-01 13:52:48 +00:00
|
|
|
CC_FOR_BUILD ?= gcc
|
2017-12-18 21:48:52 +00:00
|
|
|
|
2017-12-13 18:38:51 +00:00
|
|
|
ifeq ($(EMULATOR),1)
|
2017-12-20 13:46:17 +00:00
|
|
|
CC ?= gcc
|
|
|
|
LD := $(CC)
|
2021-01-22 18:07:35 +00:00
|
|
|
OBJCOPY := true
|
|
|
|
OBJDUMP := true
|
2017-12-20 13:46:17 +00:00
|
|
|
AR := ar
|
|
|
|
AS := as
|
2017-12-13 18:38:51 +00:00
|
|
|
|
2021-01-22 18:07:35 +00:00
|
|
|
CONFFLAG ?= -DCONFIDENTIAL=''
|
2017-12-13 18:38:51 +00:00
|
|
|
OPTFLAGS ?= -O3
|
2017-12-20 13:46:17 +00:00
|
|
|
DBGFLAGS ?= -g3 -ggdb3
|
2018-03-15 18:00:54 +00:00
|
|
|
CPUFLAGS ?=
|
2017-12-20 13:46:17 +00:00
|
|
|
FPUFLAGS ?=
|
2022-01-05 16:11:19 +00:00
|
|
|
ifeq ($(ADDRESS_SANITIZER),1)
|
|
|
|
SANFLAGS += -fsanitize=address
|
|
|
|
endif
|
2017-12-13 18:38:51 +00:00
|
|
|
else
|
2017-12-20 13:46:17 +00:00
|
|
|
PREFIX ?= arm-none-eabi-
|
|
|
|
CC := $(PREFIX)gcc
|
|
|
|
LD := $(PREFIX)gcc
|
|
|
|
OBJCOPY := $(PREFIX)objcopy
|
|
|
|
OBJDUMP := $(PREFIX)objdump
|
|
|
|
AR := $(PREFIX)ar
|
|
|
|
AS := $(PREFIX)as
|
2018-07-04 19:21:01 +00:00
|
|
|
OPENOCD := openocd -f interface/stlink.cfg -c "transport select hla_swd" -f target/stm32f2x.cfg
|
|
|
|
|
2019-01-27 13:28:21 +00:00
|
|
|
GDB := $(PREFIX)gdb --nx -ex 'set remotetimeout unlimited' -ex 'set confirm off' -ex 'target remote 127.0.0.1:3333' -ex 'monitor reset halt'
|
2014-04-29 12:26:51 +00:00
|
|
|
|
2021-12-07 17:17:53 +00:00
|
|
|
CONFFLAG ?= -DCONFIDENTIAL='__attribute__((section("confidential")))' -fstack-protector-all
|
2016-02-18 23:21:09 +00:00
|
|
|
OPTFLAGS ?= -O3
|
|
|
|
DBGFLAGS ?= -g -DNDEBUG
|
2017-08-08 10:59:39 +00:00
|
|
|
CPUFLAGS ?= -mcpu=cortex-m3 -mthumb
|
|
|
|
FPUFLAGS ?= -msoft-float
|
2017-12-13 18:38:51 +00:00
|
|
|
endif
|
2014-04-29 12:26:51 +00:00
|
|
|
|
|
|
|
CFLAGS += $(OPTFLAGS) \
|
2016-02-18 23:21:09 +00:00
|
|
|
$(DBGFLAGS) \
|
2022-01-05 16:11:19 +00:00
|
|
|
$(SANFLAGS) \
|
2018-09-12 13:58:11 +00:00
|
|
|
-std=gnu11 \
|
2014-04-29 12:26:51 +00: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 \
|
2019-10-11 07:59:32 +00:00
|
|
|
-Wno-missing-braces \
|
2014-04-29 12:26:51 +00:00
|
|
|
-Werror \
|
|
|
|
-fno-common \
|
|
|
|
-fno-exceptions \
|
|
|
|
-fvisibility=internal \
|
2014-06-19 00:16:28 +00:00
|
|
|
-ffunction-sections \
|
|
|
|
-fdata-sections \
|
2017-08-08 10:59:39 +00:00
|
|
|
$(CPUFLAGS) \
|
|
|
|
$(FPUFLAGS) \
|
2021-01-22 18:07:35 +00:00
|
|
|
$(CONFFLAG) \
|
2014-04-29 12:26:51 +00:00
|
|
|
-DSTM32F2 \
|
2018-01-13 14:20:10 +00:00
|
|
|
-DRAND_PLATFORM_INDEPENDENT=1 \
|
2014-04-29 12:26:51 +00:00
|
|
|
-I$(TOOLCHAIN_DIR)/include \
|
|
|
|
-I$(TOP_DIR) \
|
2015-12-14 23:20:34 +00:00
|
|
|
-I$(TOP_DIR)gen \
|
2015-12-15 22:01:54 +00:00
|
|
|
-I$(TOP_DIR)vendor/trezor-crypto \
|
2019-02-16 16:21:35 +00:00
|
|
|
-I$(TOP_DIR)vendor/QR-Code-generator/c \
|
2019-01-25 10:58:23 +00:00
|
|
|
-I$(TOP_DIR)vendor/trezor-storage
|
2014-04-29 12:26:51 +00:00
|
|
|
|
2017-12-20 13:46:17 +00:00
|
|
|
LDFLAGS += -L$(TOP_DIR) \
|
|
|
|
$(DBGFLAGS) \
|
2022-01-05 16:11:19 +00:00
|
|
|
$(SANFLAGS) \
|
2017-12-20 13:46:17 +00:00
|
|
|
$(CPUFLAGS) \
|
|
|
|
$(FPUFLAGS)
|
|
|
|
|
2021-11-01 13:52:48 +00:00
|
|
|
ZKP_PATH = $(TOP_DIR)vendor/secp256k1-zkp
|
|
|
|
|
2017-12-13 18:38:51 +00:00
|
|
|
ifeq ($(EMULATOR),1)
|
|
|
|
CFLAGS += -DEMULATOR=1
|
|
|
|
|
2018-02-18 17:44:36 +00: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
|
|
|
|
|
2020-07-10 14:31:50 +00:00
|
|
|
CFLAGS += $(shell pkg-config --cflags sdl2 SDL2_image)
|
|
|
|
LDLIBS += $(shell pkg-config --libs sdl2 SDL2_image)
|
2017-12-13 18:38:51 +00:00
|
|
|
|
2018-08-10 13:40:08 +00:00
|
|
|
ifdef RANDOM_DEV_FILE
|
|
|
|
CFLAGS += -DRANDOM_DEV_FILE=\"$(RANDOM_DEV_FILE)\"
|
|
|
|
endif
|
|
|
|
|
2017-12-13 18:38:51 +00:00
|
|
|
else
|
2014-04-29 12:26:51 +00:00
|
|
|
ifdef APPVER
|
|
|
|
CFLAGS += -DAPPVER=$(APPVER)
|
|
|
|
LDSCRIPT = $(TOP_DIR)/memory_app_$(APPVER).ld
|
|
|
|
else
|
|
|
|
LDSCRIPT = $(TOP_DIR)/memory.ld
|
|
|
|
endif
|
|
|
|
|
2017-12-13 18:38:51 +00:00
|
|
|
CFLAGS += -DEMULATOR=0
|
2017-07-19 09:54:26 +00:00
|
|
|
|
2014-04-29 12:26:51 +00:00
|
|
|
LDFLAGS += --static \
|
|
|
|
-Wl,--start-group \
|
|
|
|
-lc \
|
|
|
|
-lgcc \
|
|
|
|
-lnosys \
|
|
|
|
-Wl,--end-group \
|
|
|
|
-L$(TOOLCHAIN_DIR)/lib \
|
|
|
|
-T$(LDSCRIPT) \
|
|
|
|
-nostartfiles \
|
2017-12-20 13:46:17 +00:00
|
|
|
-Wl,--gc-sections
|
2014-04-29 12:26:51 +00:00
|
|
|
|
2017-12-11 19:42:51 +00:00
|
|
|
LDLIBS += -ltrezor
|
|
|
|
LIBDEPS += $(TOP_DIR)/libtrezor.a
|
|
|
|
|
|
|
|
LDLIBS += -lopencm3_stm32f2
|
|
|
|
LIBDEPS += $(TOOLCHAIN_DIR)/lib/libopencm3_stm32f2.a
|
2017-12-13 18:38:51 +00:00
|
|
|
endif
|
|
|
|
|
2019-04-27 14:15:35 +00:00
|
|
|
ifeq ($(BITCOIN_ONLY), 1)
|
|
|
|
CFLAGS += -DBITCOIN_ONLY=1
|
|
|
|
CFLAGS += -DU2F_ENABLED=0
|
|
|
|
else
|
|
|
|
CFLAGS += -DBITCOIN_ONLY=0
|
|
|
|
CFLAGS += -DU2F_ENABLED=1
|
|
|
|
endif
|
|
|
|
|
2021-12-12 14:45:10 +00:00
|
|
|
ifeq ($(PRODUCTION), 0)
|
|
|
|
CFLAGS += -DPRODUCTION=0
|
|
|
|
CPUFLAGS += -DPRODUCTION=0
|
|
|
|
$(info PRODUCTION=0)
|
2017-12-13 18:38:51 +00:00
|
|
|
else
|
2021-12-12 14:45:10 +00:00
|
|
|
CFLAGS += -DPRODUCTION=1
|
|
|
|
CPUFLAGS += -DPRODUCTION=1
|
|
|
|
$(info PRODUCTION=1)
|
2017-12-13 18:38:51 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(DEBUG_RNG), 1)
|
|
|
|
CFLAGS += -DDEBUG_RNG=1
|
|
|
|
else
|
|
|
|
CFLAGS += -DDEBUG_RNG=0
|
|
|
|
endif
|
2017-12-11 19:42:51 +00:00
|
|
|
|
2014-04-29 12:26:51 +00:00
|
|
|
all: $(NAME).bin
|
|
|
|
|
2019-01-27 13:28:21 +00:00
|
|
|
openocd:
|
|
|
|
$(OPENOCD)
|
|
|
|
|
|
|
|
gdb_bootloader: bootloader/bootloader.elf
|
|
|
|
$(GDB) $<
|
|
|
|
|
|
|
|
gdb_firmware: firmware/trezor.elf
|
|
|
|
$(GDB) $<
|
|
|
|
|
2014-04-29 12:26:51 +00:00
|
|
|
flash: $(NAME).bin
|
2018-02-13 14:15:52 +00:00
|
|
|
$(OPENOCD) -c "init; reset halt; flash write_image erase $(NAME).bin 0x8000000; exit"
|
2014-04-29 12:26:51 +00:00
|
|
|
|
2017-01-13 18:04:59 +00:00
|
|
|
upload: sign
|
2019-01-27 10:58:30 +00:00
|
|
|
trezorctl firmware_update -f $(NAME).bin -s
|
2014-04-29 12:26:51 +00:00
|
|
|
|
|
|
|
sign: $(NAME).bin
|
2018-06-07 12:48:15 +00:00
|
|
|
$(PYTHON) ../bootloader/firmware_sign.py -f $(NAME).bin
|
2014-04-29 12:26:51 +00:00
|
|
|
|
|
|
|
release: $(NAME).bin
|
2018-06-07 12:48:15 +00:00
|
|
|
$(PYTHON) ../bootloader/firmware_sign.py -f $(NAME).bin
|
2014-04-29 12:26:51 +00:00
|
|
|
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
|
2018-06-25 19:29:18 +00:00
|
|
|
@printf " OBJCOPY $@\n"
|
|
|
|
$(Q)$(OBJCOPY) -Obinary $(NAME).elf $(NAME).bin
|
2014-04-29 12:26:51 +00:00
|
|
|
|
|
|
|
$(NAME).hex: $(NAME).elf
|
2018-06-25 19:29:18 +00:00
|
|
|
@printf " OBJCOPY $@\n"
|
|
|
|
$(Q)$(OBJCOPY) -Oihex $(NAME).elf $(NAME).hex
|
2014-04-29 12:26:51 +00:00
|
|
|
|
|
|
|
$(NAME).srec: $(NAME).elf
|
2018-06-25 19:29:18 +00:00
|
|
|
@printf " OBJCOPY $@\n"
|
|
|
|
$(Q)$(OBJCOPY) -Osrec $(NAME).elf $(NAME).srec
|
2014-04-29 12:26:51 +00:00
|
|
|
|
|
|
|
$(NAME).list: $(NAME).elf
|
2018-06-25 19:29:18 +00:00
|
|
|
@printf " OBJDUMP $@\n"
|
|
|
|
$(Q)$(OBJDUMP) -S $(NAME).elf > $(NAME).list
|
2014-04-29 12:26:51 +00:00
|
|
|
|
2017-12-11 19:42:51 +00:00
|
|
|
$(NAME).elf: $(OBJS) $(LDSCRIPT) $(LIBDEPS)
|
2018-06-25 19:29:18 +00:00
|
|
|
@printf " LD $@\n"
|
|
|
|
$(Q)$(LD) -o $(NAME).elf $(OBJS) $(LDLIBS) $(LDFLAGS)
|
2014-04-29 12:26:51 +00:00
|
|
|
|
2021-11-01 13:52:48 +00:00
|
|
|
$(ZKP_PATH)/src/ecmult_static_context.h: $(ZKP_PATH)/src/gen_context.c
|
|
|
|
@printf " GEN $@\n"
|
|
|
|
$(Q)$(CC_FOR_BUILD) $(ZKP_CFLAGS) $(ZKP_PATH)/src/gen_context.c -o $(ZKP_PATH)/gen_context
|
|
|
|
$(Q)cd $(ZKP_PATH) && ./gen_context
|
|
|
|
|
|
|
|
secp256k1-zkp.o: $(ZKP_PATH)/src/ecmult_static_context.h
|
|
|
|
@printf " CC $@\n"
|
|
|
|
$(Q)$(CC) $(CFLAGS) -Wno-unused-function $(ZKP_CFLAGS) -I$(ZKP_PATH) -I$(ZKP_PATH)/src -c $(ZKP_PATH)/src/secp256k1.c -o secp256k1-zkp.o
|
|
|
|
|
|
|
|
field_10x26_arm.o:
|
|
|
|
@printf " AS $@\n"
|
|
|
|
$(Q)$(CC) $(CFLAGS) $(ZKP_CFLAGS) -c $(ZKP_PATH)/src/asm/field_10x26_arm.s -o field_10x26_arm.o
|
|
|
|
|
2019-08-28 13:51:27 +00:00
|
|
|
%.o: %.S Makefile
|
2018-06-25 19:29:18 +00:00
|
|
|
@printf " AS $@\n"
|
2019-08-28 13:51:27 +00:00
|
|
|
$(Q)$(CC) $(CPUFLAGS) -o $@ -c $<
|
2017-08-08 10:59:39 +00:00
|
|
|
|
2014-04-29 12:26:51 +00:00
|
|
|
%.o: %.c Makefile
|
2018-06-25 19:29:18 +00:00
|
|
|
@printf " CC $@\n"
|
|
|
|
$(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -c $<
|
2014-04-29 12:26:51 +00:00
|
|
|
|
|
|
|
%.small.o: %.c Makefile
|
2018-06-25 19:29:18 +00:00
|
|
|
@printf " CC $@\n"
|
|
|
|
$(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -c $<
|
2017-10-10 18:54:21 +00:00
|
|
|
|
|
|
|
%.d: %.c Makefile
|
2018-06-25 19:29:18 +00:00
|
|
|
@printf " DEP $@\n"
|
|
|
|
$(Q)$(CC) $(CFLAGS) -MM -MP -MG -o $@ $<
|
2017-10-10 18:54:21 +00:00
|
|
|
|
|
|
|
%.small.d: %.c Makefile
|
2018-06-25 19:29:18 +00:00
|
|
|
@printf " DEP $@\n"
|
|
|
|
$(Q)$(CC) $(CFLAGS) -MM -MP -MG -o $@ $<
|
2014-04-29 12:26:51 +00:00
|
|
|
|
2017-09-30 09:09:11 +00:00
|
|
|
clean::
|
2014-04-29 12:26:51 +00:00
|
|
|
rm -f $(OBJS)
|
|
|
|
rm -f *.a
|
2014-06-19 00:28:22 +00:00
|
|
|
rm -f *.bin
|
2014-04-29 12:26:51 +00:00
|
|
|
rm -f *.d
|
|
|
|
rm -f *.elf
|
|
|
|
rm -f *.hex
|
|
|
|
rm -f *.list
|
2014-07-01 18:29:44 +00:00
|
|
|
rm -f *.log
|
2014-06-19 00:28:22 +00:00
|
|
|
rm -f *.srec
|
2017-01-15 13:49:36 +00:00
|
|
|
|
|
|
|
-include $(OBJS:.o=.d)
|