# (c) Copyright 2021 by Coinkite Inc. This file is covered by license found in COPYING-CC.
#
# Build micropython for stm32 (an ARM processor). Also handles signing of resulting firmware images.
#
# MARK 4 with different chip and layout
#
include version.mk

BOARD = COLDCARD_MK4
FIRMWARE_BASE   = 0x08020000
BOOTLOADER_BASE = 0x08000000
MK_NUM = 4

# This is release of the bootloader that will be built into the release firmware.
BOOTLOADER_VERSION = 3.1.4
BOOTLOADER_DIR = mk4-bootloader

LATEST_RELEASE = $(shell ls -t1 ../releases/*-mk4-*.dfu | head -1)

# keep near top, because defined default target (all)
include shared.mk

# This is fast for Coinkite devs, but no DFU support in the wild.
dfu-up: dev.dfu
	echo 'dfu' | nc localhost 4444
	$(PYTHON_DO_DFU) -u dev.dfu

dfu-up2: dev.dfu
	$(PYTHON_DO_DFU) -u dev.dfu

# Super fast, assumes Coldcard already attached and unlock on this Mac.
up: dev.dfu
	cp dev.dfu /Volumes/COLDCARD/.
	diskutil eject /Volumes/COLDCARD

# Fairly fast, assumes openocd already running, and its current directory is here.
ocp-up: dev.dfu
	echo 'load_image dev.dfu 0x08010000 bin; reset run' | nc localhost 4444

# In another window: 
#
#		openocd -f openocd-mk4.cfg
#
# Can do:
# - "load" which writes the flash (medium speed, lots of output on st-util)
# - "cont" starts/continues system
# - "br main" sets breakpoints
# - "mon reset" to reset micro
# - and so on
#
debug:
	arm-none-eabi-gdb $(BUILD_DIR)/firmware.elf -x gogo-mk4.gdb

# EOF
