2016-05-11 12:39:28 +00:00
|
|
|
.PHONY: vendor
|
|
|
|
|
2017-04-19 19:39:44 +00:00
|
|
|
JOBS = 4
|
|
|
|
MAKE = make -j $(JOBS)
|
2017-08-07 10:04:11 +00:00
|
|
|
SCONS = scons -Q -j $(JOBS)
|
2017-04-19 19:39:44 +00:00
|
|
|
|
2017-11-06 15:44:34 +00:00
|
|
|
BUILD_DIR = build
|
|
|
|
BOARDLOADER_BUILD_DIR = $(BUILD_DIR)/boardloader
|
|
|
|
BOOTLOADER_BUILD_DIR = $(BUILD_DIR)/bootloader
|
|
|
|
PRODTEST_BUILD_DIR = $(BUILD_DIR)/prodtest
|
2017-11-06 14:46:27 +00:00
|
|
|
REFLASH_BUILD_DIR = $(BUILD_DIR)/reflash
|
2017-11-06 15:44:34 +00:00
|
|
|
FIRMWARE_BUILD_DIR = $(BUILD_DIR)/firmware
|
|
|
|
UNIX_BUILD_DIR = $(BUILD_DIR)/unix
|
2016-10-12 16:29:01 +00:00
|
|
|
|
2017-08-08 12:23:34 +00:00
|
|
|
UNAME_S := $(shell uname -s)
|
2018-06-05 21:30:43 +00:00
|
|
|
UNIX_PORT_OPTS ?=
|
2018-01-05 00:07:05 +00:00
|
|
|
CROSS_PORT_OPTS ?=
|
2017-08-08 12:23:34 +00:00
|
|
|
|
2017-09-07 20:19:27 +00:00
|
|
|
ifeq ($(DISPLAY_ILI9341V), 1)
|
|
|
|
CFLAGS += -DDISPLAY_ILI9341V=1
|
|
|
|
CFLAGS += -DDISPLAY_ST7789V=0
|
|
|
|
endif
|
|
|
|
|
2017-10-12 10:17:04 +00:00
|
|
|
PRODUCTION ?= 0
|
|
|
|
|
2017-10-09 18:46:54 +00:00
|
|
|
STLINK_VER ?= v2
|
|
|
|
OPENOCD = openocd -f interface/stlink-$(STLINK_VER).cfg -c "transport select hla_swd" -f target/stm32f4x.cfg
|
2017-09-26 13:10:56 +00:00
|
|
|
|
2017-10-11 19:15:22 +00:00
|
|
|
BOARDLOADER_START = 0x08000000
|
|
|
|
BOOTLOADER_START = 0x08020000
|
2018-07-05 11:49:28 +00:00
|
|
|
FIRMWARE_P1_START = 0x08040000
|
|
|
|
FIRMWARE_P2_START = 0x08120000
|
2017-10-27 04:01:22 +00:00
|
|
|
PRODTEST_START = 0x08040000
|
2017-10-11 19:15:22 +00:00
|
|
|
|
|
|
|
BOARDLOADER_MAXSIZE = 49152
|
|
|
|
BOOTLOADER_MAXSIZE = 131072
|
2018-06-20 12:55:30 +00:00
|
|
|
FIRMWARE_P1_MAXSIZE = 786432
|
|
|
|
FIRMWARE_P2_MAXSIZE = 917504
|
|
|
|
FIRMWARE_MAXSIZE = 1703936
|
2017-10-11 19:15:22 +00:00
|
|
|
|
2017-10-12 14:09:45 +00:00
|
|
|
GITREV=$(shell git describe --always --dirty)
|
2017-10-12 14:02:40 +00:00
|
|
|
CFLAGS += -DGITREV=$(GITREV)
|
|
|
|
|
2017-03-25 13:46:38 +00:00
|
|
|
## help commands:
|
|
|
|
|
2016-03-30 14:36:39 +00:00
|
|
|
help: ## show this help
|
2017-03-25 13:46:38 +00:00
|
|
|
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9_-]+:.*?## / {printf "\033[36m make %-20s\033[0m %s\n", $$1, $$2} /^##(.*)/ {printf "\033[33m%s\n", substr($$0, 4)}' $(MAKEFILE_LIST)
|
|
|
|
|
|
|
|
## dependencies commands:
|
2016-03-30 14:36:39 +00:00
|
|
|
|
2016-05-11 12:39:28 +00:00
|
|
|
vendor: ## update git submodules
|
2017-10-11 14:17:17 +00:00
|
|
|
git submodule update --init --recursive --force
|
2016-04-01 18:04:59 +00:00
|
|
|
|
2016-09-29 11:35:00 +00:00
|
|
|
res: ## update resources
|
2017-02-08 15:36:19 +00:00
|
|
|
./tools/res_collect
|
2016-09-29 11:35:00 +00:00
|
|
|
|
2017-03-25 13:46:38 +00:00
|
|
|
## emulator commands:
|
|
|
|
|
2017-03-20 16:45:40 +00:00
|
|
|
run: ## run unix port
|
2017-11-06 15:44:34 +00:00
|
|
|
cd src ; ../$(UNIX_BUILD_DIR)/micropython
|
2017-03-20 16:45:40 +00:00
|
|
|
|
|
|
|
emu: ## run emulator
|
|
|
|
./emu.sh
|
|
|
|
|
2017-03-25 13:46:38 +00:00
|
|
|
## test commands:
|
|
|
|
|
2017-03-20 16:45:40 +00:00
|
|
|
test: ## run unit tests
|
2018-03-09 13:56:18 +00:00
|
|
|
cd tests ; ./run_tests.sh $(TESTOPTS)
|
2017-03-20 16:45:40 +00:00
|
|
|
|
2017-10-30 17:52:10 +00:00
|
|
|
test_emu: ## run selected device tests from python-trezor
|
2018-03-09 13:56:18 +00:00
|
|
|
cd tests ; ./run_tests_device_emu.sh $(TESTOPTS)
|
2017-03-20 16:45:40 +00:00
|
|
|
|
2017-12-16 01:11:26 +00:00
|
|
|
pylint: ## run pylint on application sources and tests
|
2017-06-14 10:58:20 +00:00
|
|
|
pylint -E $(shell find src -name *.py)
|
2017-12-16 01:11:26 +00:00
|
|
|
pylint -E $(shell find tests -name *.py)
|
2017-06-07 17:06:26 +00:00
|
|
|
|
2017-12-16 01:11:26 +00:00
|
|
|
style: ## run code style check on application sources and tests
|
2017-06-14 10:58:20 +00:00
|
|
|
flake8 $(shell find src -name *.py)
|
2017-12-16 01:11:26 +00:00
|
|
|
flake8 $(shell find tests -name *.py)
|
2017-06-13 17:35:14 +00:00
|
|
|
|
2018-07-03 12:26:27 +00:00
|
|
|
isort:
|
|
|
|
isort $(shell find src -name *.py ! -path 'src/trezor/messages/*')
|
|
|
|
|
|
|
|
black:
|
|
|
|
black $(shell find src -name *.py ! -path 'src/trezor/messages/*')
|
|
|
|
|
2017-03-25 13:46:38 +00:00
|
|
|
## build commands:
|
|
|
|
|
2018-02-02 19:06:25 +00:00
|
|
|
build: build_boardloader build_bootloader build_firmware build_prodtest build_unix ## build all
|
2017-02-20 10:36:07 +00:00
|
|
|
|
2017-04-10 17:11:44 +00:00
|
|
|
build_boardloader: ## build boardloader
|
2017-11-06 15:44:34 +00:00
|
|
|
$(SCONS) CFLAGS="$(CFLAGS)" PRODUCTION="$(PRODUCTION)" $(BOARDLOADER_BUILD_DIR)/boardloader.bin
|
2017-03-18 11:02:39 +00:00
|
|
|
|
2017-04-10 17:24:21 +00:00
|
|
|
build_bootloader: ## build bootloader
|
2017-11-06 15:44:34 +00:00
|
|
|
$(SCONS) CFLAGS="$(CFLAGS)" PRODUCTION="$(PRODUCTION)" $(BOOTLOADER_BUILD_DIR)/bootloader.bin
|
2017-03-20 14:41:21 +00:00
|
|
|
|
2017-10-24 16:16:36 +00:00
|
|
|
build_prodtest: ## build production test firmware
|
2018-01-30 14:32:53 +00:00
|
|
|
$(SCONS) CFLAGS="$(CFLAGS)" PRODUCTION="$(PRODUCTION)" $(PRODTEST_BUILD_DIR)/prodtest.bin
|
2017-10-24 16:16:36 +00:00
|
|
|
|
2017-11-06 14:46:27 +00:00
|
|
|
build_reflash: ## build reflash firmware + reflash image
|
2018-01-30 14:32:53 +00:00
|
|
|
$(SCONS) CFLAGS="$(CFLAGS)" PRODUCTION="$(PRODUCTION)" $(REFLASH_BUILD_DIR)/reflash.bin
|
2017-11-06 14:46:27 +00:00
|
|
|
dd if=build/boardloader/boardloader.bin of=$(REFLASH_BUILD_DIR)/sdimage.bin bs=1 seek=0
|
|
|
|
dd if=build/bootloader/bootloader.bin of=$(REFLASH_BUILD_DIR)/sdimage.bin bs=1 seek=49152
|
|
|
|
|
2017-03-30 14:47:02 +00:00
|
|
|
build_firmware: res build_cross ## build firmware with frozen modules
|
2018-01-30 14:32:53 +00:00
|
|
|
$(SCONS) CFLAGS="$(CFLAGS)" PRODUCTION="$(PRODUCTION)" $(FIRMWARE_BUILD_DIR)/firmware.bin
|
2017-03-29 20:00:17 +00:00
|
|
|
|
2018-01-02 18:59:40 +00:00
|
|
|
build_unix: res ## build unix port
|
2017-11-06 15:44:34 +00:00
|
|
|
$(SCONS) CFLAGS="$(CFLAGS)" $(UNIX_BUILD_DIR)/micropython $(UNIX_PORT_OPTS)
|
2016-04-29 14:02:18 +00:00
|
|
|
|
2018-01-02 18:59:40 +00:00
|
|
|
build_unix_noui: res ## build unix port without UI support
|
2017-11-06 15:44:34 +00:00
|
|
|
$(SCONS) CFLAGS="$(CFLAGS)" $(UNIX_BUILD_DIR)/micropython $(UNIX_PORT_OPTS) TREZOR_NOUI=1
|
2017-08-07 10:31:42 +00:00
|
|
|
|
2017-03-30 14:47:02 +00:00
|
|
|
build_cross: ## build mpy-cross port
|
2017-02-24 12:19:00 +00:00
|
|
|
$(MAKE) -C vendor/micropython/mpy-cross $(CROSS_PORT_OPTS)
|
2016-05-17 15:17:23 +00:00
|
|
|
|
2017-03-25 13:46:38 +00:00
|
|
|
## clean commands:
|
|
|
|
|
2017-10-24 16:16:36 +00:00
|
|
|
clean: clean_boardloader clean_bootloader clean_prodtest clean_firmware clean_unix clean_cross ## clean all
|
2017-01-23 09:21:48 +00:00
|
|
|
|
2017-04-10 17:11:44 +00:00
|
|
|
clean_boardloader: ## clean boardloader build
|
2017-11-06 15:44:34 +00:00
|
|
|
rm -rf $(BOARDLOADER_BUILD_DIR)
|
2017-03-20 16:45:40 +00:00
|
|
|
|
2017-04-10 17:24:21 +00:00
|
|
|
clean_bootloader: ## clean bootloader build
|
2017-11-06 15:44:34 +00:00
|
|
|
rm -rf $(BOOTLOADER_BUILD_DIR)
|
2017-03-20 16:45:40 +00:00
|
|
|
|
2017-10-24 16:16:36 +00:00
|
|
|
clean_prodtest: ## clean prodtest build
|
2017-11-06 15:44:34 +00:00
|
|
|
rm -rf $(PRODTEST_BUILD_DIR)
|
2017-10-24 16:16:36 +00:00
|
|
|
|
2017-11-06 14:46:27 +00:00
|
|
|
clean_reflash: ## clean reflash build
|
|
|
|
rm -rf $(REFLASH_BUILD_DIR)
|
|
|
|
|
2017-03-29 20:00:17 +00:00
|
|
|
clean_firmware: ## clean firmware build
|
2017-11-06 15:44:34 +00:00
|
|
|
rm -rf $(FIRMWARE_BUILD_DIR)
|
2017-03-29 20:00:17 +00:00
|
|
|
|
2016-04-11 15:55:10 +00:00
|
|
|
clean_unix: ## clean unix build
|
2017-11-06 15:44:34 +00:00
|
|
|
rm -rf $(UNIX_BUILD_DIR)
|
2016-04-11 15:55:10 +00:00
|
|
|
|
2016-09-19 15:08:41 +00:00
|
|
|
clean_cross: ## clean mpy-cross build
|
2017-02-24 12:19:00 +00:00
|
|
|
$(MAKE) -C vendor/micropython/mpy-cross clean $(CROSS_PORT_OPTS)
|
2016-11-24 13:27:30 +00:00
|
|
|
|
2017-03-25 13:46:38 +00:00
|
|
|
## flash commands:
|
|
|
|
|
2017-09-26 13:10:56 +00:00
|
|
|
flash: flash_boardloader flash_bootloader flash_firmware ## flash everything using OpenOCD
|
|
|
|
|
|
|
|
flash_boardloader: $(BOARDLOADER_BUILD_DIR)/boardloader.bin ## flash boardloader using OpenOCD
|
2017-10-11 19:15:22 +00:00
|
|
|
$(OPENOCD) -c "init; reset halt; flash write_image erase $< $(BOARDLOADER_START); exit"
|
2016-09-28 16:15:06 +00:00
|
|
|
|
2017-09-26 13:10:56 +00:00
|
|
|
flash_bootloader: $(BOOTLOADER_BUILD_DIR)/bootloader.bin ## flash bootloader using OpenOCD
|
2017-10-11 19:15:22 +00:00
|
|
|
$(OPENOCD) -c "init; reset halt; flash write_image erase $< $(BOOTLOADER_START); exit"
|
2017-03-19 14:29:48 +00:00
|
|
|
|
2017-10-26 22:41:22 +00:00
|
|
|
flash_prodtest: $(PRODTEST_BUILD_DIR)/prodtest.bin ## flash prodtest using OpenOCD
|
2018-07-05 11:49:28 +00:00
|
|
|
$(OPENOCD) -c "init; reset halt; flash write_image erase $< $(PRODTEST_START); exit"
|
2017-10-26 22:41:22 +00:00
|
|
|
|
2017-09-26 13:10:56 +00:00
|
|
|
flash_firmware: $(FIRMWARE_BUILD_DIR)/firmware.bin ## flash firmware using OpenOCD
|
2018-07-05 11:49:28 +00:00
|
|
|
$(OPENOCD) -c "init; reset halt; flash write_image erase $<.p1 $(FIRMWARE_P1_START); flash write_image erase $<.p2 $(FIRMWARE_P2_START); exit"
|
2017-03-29 20:00:17 +00:00
|
|
|
|
2017-10-27 04:01:22 +00:00
|
|
|
flash_combine: $(PRODTEST_BUILD_DIR)/combined.bin ## flash combined using OpenOCD
|
2017-10-11 19:15:22 +00:00
|
|
|
$(OPENOCD) -c "init; reset halt; flash write_image erase $< $(BOARDLOADER_START); exit"
|
2017-09-25 13:49:42 +00:00
|
|
|
|
2017-09-26 13:10:56 +00:00
|
|
|
flash_erase: ## erase all sectors in flash bank 0
|
|
|
|
$(OPENOCD) -c "init; reset halt; flash info 0; flash erase_sector 0 0 last; flash erase_check 0; exit"
|
2017-05-30 15:48:19 +00:00
|
|
|
|
2017-03-25 13:46:38 +00:00
|
|
|
## openocd debug commands:
|
|
|
|
|
2016-03-30 14:36:39 +00:00
|
|
|
openocd: ## start openocd which connects to the device
|
2017-09-26 13:10:56 +00:00
|
|
|
$(OPENOCD)
|
2016-03-30 14:36:39 +00:00
|
|
|
|
2017-11-10 19:02:35 +00:00
|
|
|
openocd_reset: ## cause a system reset using OpenOCD
|
|
|
|
$(OPENOCD) -c "init; reset; exit"
|
|
|
|
|
2017-09-28 22:04:11 +00:00
|
|
|
GDB = arm-none-eabi-gdb --nx -ex 'set remotetimeout unlimited' -ex 'set confirm off' -ex 'target remote 127.0.0.1:3333' -ex 'monitor reset halt'
|
|
|
|
|
|
|
|
gdb_boardloader: $(BOARDLOADER_BUILD_DIR)/boardloader.elf ## start remote gdb session to openocd with boardloader symbols
|
|
|
|
$(GDB) $<
|
|
|
|
|
|
|
|
gdb_bootloader: $(BOOTLOADER_BUILD_DIR)/bootloader.elf ## start remote gdb session to openocd with bootloader symbols
|
|
|
|
$(GDB) $<
|
|
|
|
|
2017-10-29 14:45:23 +00:00
|
|
|
gdb_prodtest: $(PRODTEST_BUILD_DIR)/prodtest.elf ## start remote gdb session to openocd with prodtest symbols
|
|
|
|
$(GDB) $<
|
|
|
|
|
2017-09-28 22:04:11 +00:00
|
|
|
gdb_firmware: $(FIRMWARE_BUILD_DIR)/firmware.elf ## start remote gdb session to openocd with firmware symbols
|
|
|
|
$(GDB) $<
|
2017-04-10 14:40:41 +00:00
|
|
|
|
|
|
|
## misc commands:
|
|
|
|
|
|
|
|
binctl: ## print info about binary files
|
2017-04-28 13:39:22 +00:00
|
|
|
./tools/binctl $(BOOTLOADER_BUILD_DIR)/bootloader.bin
|
|
|
|
./tools/binctl $(FIRMWARE_BUILD_DIR)/firmware.bin
|
2017-04-10 14:40:41 +00:00
|
|
|
|
|
|
|
bloaty: ## run bloaty size profiler
|
2017-04-28 13:39:22 +00:00
|
|
|
bloaty -d symbols -n 0 -s file $(FIRMWARE_BUILD_DIR)/firmware.elf | less
|
|
|
|
bloaty -d compileunits -n 0 -s file $(FIRMWARE_BUILD_DIR)/firmware.elf | less
|
|
|
|
|
|
|
|
sizecheck: ## check sizes of binary files
|
2017-10-30 13:07:52 +00:00
|
|
|
test $(BOARDLOADER_MAXSIZE) -ge $(shell wc -c < $(BOARDLOADER_BUILD_DIR)/boardloader.bin)
|
|
|
|
test $(BOOTLOADER_MAXSIZE) -ge $(shell wc -c < $(BOOTLOADER_BUILD_DIR)/bootloader.bin)
|
2018-06-20 12:55:30 +00:00
|
|
|
test $(FIRMWARE_P1_MAXSIZE) -ge $(shell wc -c < $(FIRMWARE_BUILD_DIR)/firmware.bin.p1)
|
|
|
|
test $(FIRMWARE_P2_MAXSIZE) -ge $(shell wc -c < $(FIRMWARE_BUILD_DIR)/firmware.bin.p2)
|
2017-10-30 13:07:52 +00:00
|
|
|
test $(FIRMWARE_MAXSIZE) -ge $(shell wc -c < $(FIRMWARE_BUILD_DIR)/firmware.bin)
|
2017-05-30 15:48:19 +00:00
|
|
|
|
2017-10-27 04:01:22 +00:00
|
|
|
combine: ## combine boardloader + bootloader + prodtest into one combined image
|
2017-05-30 15:48:19 +00:00
|
|
|
./tools/combine_firmware \
|
2017-10-11 19:15:22 +00:00
|
|
|
$(BOARDLOADER_START) $(BOARDLOADER_BUILD_DIR)/boardloader.bin \
|
|
|
|
$(BOOTLOADER_START) $(BOOTLOADER_BUILD_DIR)/bootloader.bin \
|
2017-10-27 04:01:22 +00:00
|
|
|
$(PRODTEST_START) $(PRODTEST_BUILD_DIR)/prodtest.bin \
|
|
|
|
> $(PRODTEST_BUILD_DIR)/combined.bin \
|
2017-10-16 16:03:04 +00:00
|
|
|
|
|
|
|
upload: ## upload firmware using trezorctl
|
|
|
|
trezorctl firmware_update -f $(FIRMWARE_BUILD_DIR)/firmware.bin
|
2017-10-26 22:41:22 +00:00
|
|
|
|
|
|
|
upload_prodtest: ## upload prodtest using trezorctl
|
|
|
|
trezorctl firmware_update -f $(PRODTEST_BUILD_DIR)/prodtest.bin
|