# name of your application
APPLICATION = boot2
DISABLE_UART_TRY_DOWNLOAD ?= 1
LOG_CONF_LEVEL_MAIN ?= LOG_LEVEL_INFO

# If no BOARD is found in the environment, use this default:
BOARD ?= crane

# If no AROM_VERSION is found in the environment, use this default:
AROM_VERSION ?= 20200730

# If no AROMVERSION is found in the environment, use this default:
export AROMVERSION ?= 2019.01.15

# This has to be the absolute path to the RIOT base directory:
RIOTBASE ?= $(realpath $(CURDIR)/../../)

BOARD_WHITELIST += crane cranew-mcu

#PZ1 test: boot2(add qspi freq to max for PZ1 xip run)-> pz1.bin:
QSPI_PROBE_IN_BOOT2_ENABLE ?= 0

# Include all submodules depending on
USEMODULE += libarom
USEMODULE += ptable
# The bin size can be reduced by 1KB by replace crc32 with crc32_syscall
USEMODULE += crc32_syscall
USEMODULE += property
USEMODULE += log
USEMODULE += bl2_arg
USEMODULE += fip

# Except for ram verson for compatibility: Watch1 CR5 and Lapwing.
# After the arom.bin are updated to the releasepack, this exclusion can be
# removed.
ifeq ($(findstring $(AROM_VERSION), 20220808, 20240430),)
USEMODULE += vsnprintf_syscall
endif

ifeq ($(AROM_VERSION),20200730)
# CraneG/CraneM A0
USEMODULE += patchlib
USEMODULE += secureboot_arom_patch
USEMODULE += arom_syscall
USEMODULE += decompress
USEMODULE += loadtable
endif

# Except for Watch1 CR5
ifeq ($(findstring $(AROM_VERSION), 20220808),)
USEMODULE += usb
endif

ifneq ($(findstring $(AROM_VERSION), 20200730, 20211016, 20220728, 20221106, 20221111, 20240430),)
USEMODULE += flasher_guard
CFLAGS += -DUSE_ARB
endif

ifeq ($(AROM_VERSION),20220728)
# Watchone
#USEMODULE += sealipay
endif

ifeq ($(QSPI_PROBE_IN_BOOT2_ENABLE), 1)
USEMODULE += flash
endif

CFLAGS += -DDISABLE_UART_TRY_DOWNLOAD=$(DISABLE_UART_TRY_DOWNLOAD)
CFLAGS += -Wno-int-conversion
CFLAGS += -DLOG_CONF_LEVEL_MAIN=$(LOG_CONF_LEVEL_MAIN)
CFLAGS += -DAROM_VERSION=$(AROM_VERSION)

ifeq ($(QSPI_PROBE_IN_BOOT2_ENABLE),1)
CFLAGS += -DUSE_QSPI_NOR_FLASH
CFLAGS += -DQSPI_PROBE_IN_BOOT2_ENABLE=1
CFLAGS += -DQSPI_DTR_MODE_IN_PZ1_ENABLE=1
endif

# Change this to 0 show compiler invocation lines by default:
QUIET ?= 1

OFLAGS = -O binary
HEXFILE = $(ELFFILE:.elf=.bin)

LINKER_SOURCE_SCRIPT := $(APPLICATION).lds

include $(RIOTBASE)/Makefile.include
