2017-03-20 17:26:23 +00:00
|
|
|
# source directories
|
|
|
|
SRCDIR_MP = vendor/micropython
|
|
|
|
SRCDIR_FW = micropython
|
|
|
|
|
2017-03-18 11:02:39 +00:00
|
|
|
# target directory
|
2017-04-21 14:45:15 +00:00
|
|
|
PROJECT ?= boardloader
|
|
|
|
BUILD ?= micropython/$(PROJECT)/build
|
2017-03-18 11:02:39 +00:00
|
|
|
|
|
|
|
# include py core make definitions
|
2017-03-20 17:26:23 +00:00
|
|
|
include $(SRCDIR_MP)/py/mkenv.mk
|
2017-03-18 11:02:39 +00:00
|
|
|
|
|
|
|
# sources
|
|
|
|
# =====================================
|
|
|
|
|
|
|
|
BUILD_MP = $(BUILD)/$(SRCDIR_MP)
|
|
|
|
BUILD_FW = $(BUILD)/$(SRCDIR_FW)
|
2017-03-20 16:27:00 +00:00
|
|
|
BUILD_HDR = $(BUILD)/genhdr
|
2017-03-18 11:02:39 +00:00
|
|
|
|
2017-04-19 21:11:31 +00:00
|
|
|
CFLAGS_MOD += \
|
|
|
|
-I$(SRCDIR_FW)/extmod/modtrezorcrypto/trezor-crypto \
|
|
|
|
-I$(SRCDIR_FW)/extmod/modtrezorcrypto/trezor-crypto/ed25519-donna \
|
|
|
|
-DAES_128 \
|
|
|
|
-DAES_192 \
|
|
|
|
-DUSE_KECCAK=1 \
|
|
|
|
-DED25519_NO_PRECOMP=1 \
|
|
|
|
-Wno-sequence-point
|
|
|
|
|
2017-03-18 11:02:39 +00:00
|
|
|
# OBJ vendor/micropython
|
2017-04-19 21:11:31 +00:00
|
|
|
OBJ_MICROPYTHON += $(addprefix $(BUILD_MP)/,\
|
2017-03-18 11:02:39 +00:00
|
|
|
lib/libc/string0.o \
|
2017-03-23 16:27:32 +00:00
|
|
|
stmhal/startup_stm32.o \
|
|
|
|
)
|
|
|
|
|
|
|
|
# OBJ vendor/micropython
|
2017-04-19 21:11:31 +00:00
|
|
|
OBJ_STMHAL += $(addprefix $(BUILD_MP)/,\
|
2017-03-18 11:02:39 +00:00
|
|
|
stmhal/hal/f4/src/stm32f4xx_hal_adc_ex.o \
|
|
|
|
stmhal/hal/f4/src/stm32f4xx_hal_adc.o \
|
|
|
|
stmhal/hal/f4/src/stm32f4xx_hal_can.o \
|
|
|
|
stmhal/hal/f4/src/stm32f4xx_hal_cortex.o \
|
|
|
|
stmhal/hal/f4/src/stm32f4xx_hal_dac_ex.o \
|
|
|
|
stmhal/hal/f4/src/stm32f4xx_hal_dac.o \
|
|
|
|
stmhal/hal/f4/src/stm32f4xx_hal_dma.o \
|
|
|
|
stmhal/hal/f4/src/stm32f4xx_hal_flash_ex.o \
|
|
|
|
stmhal/hal/f4/src/stm32f4xx_hal_flash.o \
|
|
|
|
stmhal/hal/f4/src/stm32f4xx_hal_gpio.o \
|
|
|
|
stmhal/hal/f4/src/stm32f4xx_hal_i2c.o \
|
|
|
|
stmhal/hal/f4/src/stm32f4xx_hal_pcd_ex.o \
|
|
|
|
stmhal/hal/f4/src/stm32f4xx_hal_pcd.o \
|
|
|
|
stmhal/hal/f4/src/stm32f4xx_hal_pwr_ex.o \
|
|
|
|
stmhal/hal/f4/src/stm32f4xx_hal_pwr.o \
|
|
|
|
stmhal/hal/f4/src/stm32f4xx_hal_rcc_ex.o \
|
|
|
|
stmhal/hal/f4/src/stm32f4xx_hal_rcc.o \
|
|
|
|
stmhal/hal/f4/src/stm32f4xx_hal_rng.o \
|
|
|
|
stmhal/hal/f4/src/stm32f4xx_hal_rtc_ex.o \
|
|
|
|
stmhal/hal/f4/src/stm32f4xx_hal_rtc.o \
|
|
|
|
stmhal/hal/f4/src/stm32f4xx_hal_sd.o \
|
|
|
|
stmhal/hal/f4/src/stm32f4xx_hal_spi.o \
|
|
|
|
stmhal/hal/f4/src/stm32f4xx_hal_tim_ex.o \
|
|
|
|
stmhal/hal/f4/src/stm32f4xx_hal_tim.o \
|
|
|
|
stmhal/hal/f4/src/stm32f4xx_hal_uart.o \
|
|
|
|
stmhal/hal/f4/src/stm32f4xx_hal.o \
|
|
|
|
stmhal/hal/f4/src/stm32f4xx_ll_sdmmc.o \
|
|
|
|
stmhal/hal/f4/src/stm32f4xx_ll_usb.o \
|
|
|
|
)
|
|
|
|
|
|
|
|
# OBJ micropython/
|
2017-04-19 20:40:15 +00:00
|
|
|
OBJ_BOARDLOADER += $(addprefix $(BUILD_FW)/, \
|
2017-04-10 17:11:44 +00:00
|
|
|
boardloader/main.o \
|
2017-04-19 21:11:31 +00:00
|
|
|
extmod/modtrezorcrypto/trezor-crypto/ed25519-donna/ed25519.o \
|
|
|
|
extmod/modtrezorcrypto/trezor-crypto/blake2s.o \
|
|
|
|
extmod/modtrezorcrypto/trezor-crypto/sha2.o \
|
2017-03-18 11:02:39 +00:00
|
|
|
extmod/modtrezorui/display.o \
|
|
|
|
extmod/modtrezorui/font_bitmap.o \
|
2017-04-19 20:40:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
OBJ_TREZORHAL += $(addprefix $(BUILD_FW)/, \
|
2017-03-21 00:41:49 +00:00
|
|
|
trezorhal/common.o \
|
2017-04-01 10:57:14 +00:00
|
|
|
trezorhal/image.o \
|
2017-03-28 11:04:54 +00:00
|
|
|
trezorhal/flash.o \
|
2017-03-18 11:02:39 +00:00
|
|
|
trezorhal/sdcard.o \
|
|
|
|
trezorhal/stm32_it.o \
|
|
|
|
trezorhal/stm32_system.o \
|
|
|
|
trezorhal/hal/stm32f4xx_hal_sram.o \
|
|
|
|
trezorhal/hal/stm32f4xx_ll_fsmc.o \
|
|
|
|
)
|
|
|
|
|
2017-04-19 21:11:31 +00:00
|
|
|
OBJ = $(OBJ_MICROPYTHON) $(OBJ_STMHAL) $(OBJ_TREZORHAL)
|
2017-04-19 20:40:15 +00:00
|
|
|
OBJ += $(OBJ_BOARDLOADER)
|
2017-03-18 11:02:39 +00:00
|
|
|
|
|
|
|
# comp flags
|
|
|
|
# =====================================
|
|
|
|
|
|
|
|
CROSS_COMPILE = arm-none-eabi-
|
|
|
|
|
|
|
|
INC += -I.
|
2017-04-21 14:45:15 +00:00
|
|
|
INC += -I$(SRCDIR_FW)/$(PROJECT)
|
2017-03-20 17:26:23 +00:00
|
|
|
INC += -I$(SRCDIR_FW)/extmod/modtrezorui
|
|
|
|
INC += -I$(SRCDIR_FW)/trezorhal
|
|
|
|
INC += -I$(SRCDIR_FW)/trezorhal/hal
|
|
|
|
INC += -I$(SRCDIR_MP)
|
|
|
|
INC += -I$(SRCDIR_MP)/stmhal
|
|
|
|
INC += -I$(SRCDIR_MP)/stmhal/cmsis
|
|
|
|
INC += -I$(SRCDIR_MP)/stmhal/hal/f4/inc
|
|
|
|
INC += -I$(SRCDIR_MP)/lib/cmsis/inc
|
2017-03-18 11:02:39 +00:00
|
|
|
INC += -I$(BUILD)
|
|
|
|
|
|
|
|
ifeq ($(DEBUG), 1)
|
2017-03-28 13:19:54 +00:00
|
|
|
CFLAGS += -Os -ggdb
|
2017-03-18 11:02:39 +00:00
|
|
|
else
|
|
|
|
CFLAGS += -Os -DNDEBUG
|
|
|
|
endif
|
|
|
|
|
|
|
|
CFLAGS += $(INC) $(CFLAGS_MOD) $(CFLAGS_EXTRA)
|
|
|
|
CFLAGS += -std=gnu99 -nostdlib -Wall -Werror -Wdouble-promotion -Wpointer-arith
|
|
|
|
CFLAGS += -mthumb -mtune=cortex-m4 -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fsingle-precision-constant
|
|
|
|
CFLAGS += -DSTM32F405xx -DMCU_SERIES_F4
|
|
|
|
CFLAGS += -DSTM32_HAL_H='<stm32f4xx_hal.h>'
|
2017-04-17 15:57:42 +00:00
|
|
|
CFLAGS += -DTREZOR_STM32
|
2017-03-18 11:02:39 +00:00
|
|
|
|
|
|
|
LIBS = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
|
|
|
|
|
2017-04-21 14:45:15 +00:00
|
|
|
LDFLAGS = -nostdlib -T $(SRCDIR_FW)/$(PROJECT)/memory.ld -Map=$@.map --cref
|
2017-03-18 11:02:39 +00:00
|
|
|
|
|
|
|
# remove uncalled code from the final image
|
|
|
|
CFLAGS += -fdata-sections -ffunction-sections
|
|
|
|
LDFLAGS += --gc-sections
|
|
|
|
|
|
|
|
# comp rules
|
|
|
|
# =====================================
|
|
|
|
|
2017-04-21 14:45:15 +00:00
|
|
|
all: $(BUILD)/$(PROJECT).bin
|
2017-03-18 11:02:39 +00:00
|
|
|
|
2017-04-21 14:45:15 +00:00
|
|
|
$(BUILD)/$(PROJECT).elf: $(OBJ)
|
2017-03-18 11:02:39 +00:00
|
|
|
$(ECHO) "LINK $@"
|
|
|
|
$(Q)$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
|
|
|
|
$(Q)$(SIZE) $@
|
|
|
|
|
2017-04-21 14:45:15 +00:00
|
|
|
$(BUILD)/$(PROJECT).bin: $(BUILD)/$(PROJECT).elf
|
|
|
|
$(Q)$(OBJCOPY) -O binary -j .header -j .flash -j .data $^ $(BUILD)/$(PROJECT).bin
|
2017-03-18 11:02:39 +00:00
|
|
|
|
|
|
|
$(BUILD)/%.o: %.S
|
|
|
|
$(ECHO) "CC $<"
|
|
|
|
$(Q)$(CC) $(CFLAGS) -c -o $@ $<
|
|
|
|
|
|
|
|
$(BUILD)/%.o: %.s
|
|
|
|
$(ECHO) "AS $<"
|
|
|
|
$(Q)$(AS) -o $@ $<
|
|
|
|
|
|
|
|
$(BUILD)/%.o: %.c
|
|
|
|
$(ECHO) "CC $<"
|
|
|
|
$(Q)$(CC) $(CFLAGS) -c -MD -o $@ $<
|
|
|
|
|
|
|
|
OBJ_DIRS = $(sort $(dir $(OBJ)))
|
|
|
|
$(OBJ): | $(OBJ_DIRS)
|
2017-03-20 16:45:40 +00:00
|
|
|
$(OBJ_DIRS) $(BUILD_HDR):
|
2017-03-18 11:02:39 +00:00
|
|
|
$(MKDIR) -p $@
|
|
|
|
|
2017-03-20 16:27:00 +00:00
|
|
|
$(OBJ): | $(BUILD_HDR)/qstrdefs.generated.h
|
|
|
|
|
2017-03-20 16:45:40 +00:00
|
|
|
$(BUILD_HDR)/qstrdefs.generated.h: | $(BUILD_HDR)
|
2017-03-20 16:27:00 +00:00
|
|
|
touch $(BUILD_HDR)/qstrdefs.generated.h
|
|
|
|
|
2017-03-18 11:02:39 +00:00
|
|
|
clean:
|
|
|
|
$(RM) -rf $(BUILD)
|
|
|
|
|
|
|
|
.PHONY: all clean
|