# "The Vector table must be naturally aligned to a power of two whose alignment
# value is greater than or equal to number of Exceptions supported x 4"
# CPU_IRQ_NUMOF for KWxD and KxF boards is < 102+16 so (81*4 bytes = 472 bytes ~= 0x200)
# RIOTBOOT_HDR_LEN can be set to 0x200
ifneq (,$(filter FK DW,$(KINETIS_CORE)$(KINETIS_SERIES)))
  RIOTBOOT_HDR_LEN ?= 0x200
endif

# Slot size is determined by "((total_flash_size - RIOTBOOT_LEN) / 2)".
# If RIOTBOOT_LEN uses an uneven number of flashpages, the remainder of the
# flash cannot be divided by two slots while staying FLASHPAGE_SIZE aligned.
ifeq (K, $(KINETIS_SERIES))
  RIOTBOOT_LEN ?= 0x2000
endif

# Add search path for linker scripts
LINKFLAGS += -L$(RIOTCPU)/$(CPU)/ldscripts

# Use generic linker script for all Kinetis based CPUs
LINKER_SCRIPT = kinetis.ld

ROM_START_ADDR = 0x00000000
RAM_BASE_ADDR  = 0x20000000
RAM_START_ADDR := $(shell printf "0x%08x" $$(($(RAM_BASE_ADDR)-($(KINETIS_SRAM_L_SIZE) * 1024))))

# Define ROM_LEN with a non arithmetic value as it must be
# evaluated in `cortexm_common` without a shell context
# The `K` is correctly handled by both the linker and `cortexm_common`.
ROM_LEN = $(KINETIS_ROMSIZE)K
RAM_LEN = $$(($(KINETIS_RAMSIZE) * 1024))

CFLAGS += \
  -DKINETIS_CORE_$(KINETIS_CORE) \
  -DKINETIS_SERIES_$(KINETIS_SERIES) \
  -DKINETIS_FAMILY=$(KINETIS_FAMILY) \
  -DKINETIS_SUBFAMILY=$(KINETIS_SUBFAMILY) \
  -DKINETIS_ROMSIZE=$(KINETIS_ROMSIZE) \
  #

include $(RIOTMAKE)/arch/cortexm.inc.mk