mainmenu "ATF SDK configuration"
#
# ============================    MENU    ==============================
#
menu "Platform"
	choice CHIP
		bool "Target Platforms"
		config PLAT_MT7622
			bool "MT7622"
		config PLAT_MT7629
			bool "MT7629"
		config PLAT_MT7981
			bool "MT7981"
		config PLAT_MT7986
			bool "MT7986"
		config PLAT_MT7988
			bool "MT7988"
	endchoice
	config FPGA
		bool "Build for FPGA emulation"
		default n
endmenu

menu "Target"
	choice
		bool "Target Images"
		default TARGET_BL2 if !NEED_SBC
		default TARGET_ALL_HAS_SEC_BOOT if NEED_SBC
		config TARGET_BL2
			bool "BL2"
			depends on !NEED_SBC
		config TARGET_BL31
			bool "BL31"
			depends on !NEED_SBC
		config TARGET_FIP_NO_SEC_BOOT
			bool "BL31 + FIP image without secure boot"
			depends on !NEED_SBC
		config TARGET_ALL_NO_SEC_BOOT
			bool "BL2 + FIP image without secure boot"
			depends on !NEED_SBC
		config TARGET_ALL_HAS_SEC_BOOT
			bool "BL2 + FIP image with secure boot"
			depends on NEED_SBC
	endchoice
	config NEED_SBC
		bool "Enable Secure Boot"
		default n
	choice FLASH_DEVICE
		bool "Target Flash Devices"
		default FLASH_DEVICE_SNFI_SNAND
		config FLASH_DEVICE_SNFI_SNAND
			bool "snfi-snand"
			depends on MTK_SNFI_SUPPORT
			help
			  spi-nand flash with snfi controller
		config FLASH_DEVICE_SNOR
			bool "snor"
			depends on MTK_SNOR_SUPPORT
			help
			  spi-nor flash with snor controller
		config FLASH_DEVICE_SPIM_NAND
			bool "spim-snand"
			depends on MTK_SPIM_SUPPORT
			help
			  spi-nand flash with spim controller
		config FLASH_DEVICE_SPIM_NOR
			bool "spim-snor"
			depends on MTK_SPIM_SUPPORT
			help
			  spi-nor flash with spim controller
		config FLASH_DEVICE_EMMC
			bool "emmc"
			depends on MTK_SDMMC_SUPPORT
			help
			  emmc device
		config FLASH_DEVICE_SDMMC
			bool "sdcard"
			depends on MTK_SDMMC_SUPPORT
			help
			  sd card device
		config FLASH_DEVICE_RAM
			bool "ram"
			help
			  ram device
	endchoice
	config SNFI_SNAND_TYPE
		string "nand flash type"
		depends on FLASH_DEVICE_SNFI_SNAND
		default 'hsm:2k+64'
	config NMBM
		bool "Enable NAND mapping block management"
		depends on FLASH_DEVICE_SNFI_SNAND || FLASH_DEVICE_SPIM_NAND
		default y if PLAT_MT7622 || PLAT_MT7629 || \
			     PLAT_MT7981 || PLAT_MT7986
	config SPIM_NAND_TYPE
		string "nand flash type"
		depends on FLASH_DEVICE_SPIM_NAND
		default 'spim:2k+64'
endmenu

menu "DRAM"
	depends on !FPGA
	choice DDR_TYPE
		bool "DRAM type"
		config DRAM_DDR3
			bool "DDR3"
			depends on PLAT_MT7622 || \
				   PLAT_MT7629 || \
				   PLAT_MT7981 || \
				   PLAT_MT7986
		config DRAM_DDR4
			bool "DDR4"
			depends on PLAT_MT7981 || \
				   PLAT_MT7986
	endchoice
	choice BOARD_TYPE
		bool "BOARD type"
		config QFN
			bool "QFN"
			depends on PLAT_MT7981 && DRAM_DDR3
		config BGA
			bool "BGA"
			depends on PLAT_MT7981
	endchoice
	config DRAM_DDR3_FLYBY
		bool "Enable Fly-by topology (Uses 2x DDR3 chips)"
		default n
		depends on PLAT_MT7622
	choice DDR_SIZE
		bool "DRAM size limitation"
		default DRAM_SIZE_AUTO
		depends on PLAT_MT7981 || \
			   PLAT_MT7986
		config DRAM_SIZE_AUTO
			bool "Auto detect"
			depends on PLAT_MT7981 || \
				   PLAT_MT7986
		config DRAM_SIZE_256
			bool "256MB"
			depends on (PLAT_MT7981 && DRAM_DDR3) || \
				   (PLAT_MT7986 && DRAM_DDR3)
		config DRAM_SIZE_512
			bool "512MB"
			depends on (PLAT_MT7981 && DRAM_DDR3) || \
				   (PLAT_MT7986 && DRAM_DDR3) || \
				   (PLAT_MT7981 && DRAM_DDR4) || \
				   (PLAT_MT7986 && DRAM_DDR4)
		config DRAM_SIZE_1024
			bool "1GB"
			depends on (PLAT_MT7981 && DRAM_DDR4) || \
				   (PLAT_MT7986 && DRAM_DDR4)
		config DRAM_SIZE_2048
			bool "2GB"
			depends on (PLAT_MT7986 && DRAM_DDR4)
	endchoice
	choice DDR3_FREQUENCY
	bool "DDR3 frequency"
	default DDR3_FREQ_2133
	depends on PLAT_MT7981 && DRAM_DDR3
	config DDR3_FREQ_2133
		bool "DDR3 2133MHz"
	depends on PLAT_MT7981 && DRAM_DDR3
	config DDR3_FREQ_1866
		bool "DDR3 1866MHz"
		depends on PLAT_MT7981 && DRAM_DDR3
	endchoice

	choice DDR4_FREQUENCY
	bool "DDR4 frequency"
	default DDR4_FREQ_3200
	depends on PLAT_MT7986 && DRAM_DDR4
	config DDR4_FREQ_3200
		bool "DDR4 3200MHz"
		depends on PLAT_MT7986 && DRAM_DDR4
	config DDR4_FREQ_2666
		bool "DDR4 2666MHz"
		depends on PLAT_MT7986 && DRAM_DDR4
	endchoice


endmenu

menu "Log"
	choice LOG_LEVEL
		bool "Log level"
		default LOG_LEVEL_NOTICE
		config LOG_LEVEL_NONE
			bool "NONE"
		config LOG_LEVEL_ERROR
			bool "ERROR"
		config LOG_LEVEL_NOTICE
			bool "NOTICE"
		config LOG_LEVEL_WARNING
			bool "WARNING"
		config LOG_LEVEL_INFO
			bool "INFO"
		config LOG_LEVEL_VERBOSE
			bool "VERBOSE"
	endchoice
	config DRAM_DEBUG_LOG
		bool "Enable DRAM debug log"
		default n
endmenu


#
# ============================  PLATFORM  ==============================
#

config PLAT
	def_string "mt7622" if PLAT_MT7622
	def_string "mt7629" if PLAT_MT7629
	def_string "mt7981" if PLAT_MT7981
	def_string "mt7986" if PLAT_MT7986
	def_string "mt7988" if PLAT_MT7988

config AARCH64
	def_bool y if PLAT_MT7622
	def_bool n if PLAT_MT7629
	def_bool y if PLAT_MT7981
	def_bool y if PLAT_MT7986
	def_bool y if PLAT_MT7988

config AARCH32
	def_bool y if !AARCH64
	def_bool n if AARCH64

#
# ============================  TARGET   ==============================
#

config NEED_BL2
	def_bool y if TARGET_BL2
	def_bool y if TARGET_ALL_NO_SEC_BOOT
	def_bool y if TARGET_ALL_HAS_SEC_BOOT

config NEED_BL31
	def_bool y if TARGET_BL31
	def_bool y if TARGET_ALL_NO_SEC_BOOT
	def_bool y if TARGET_ALL_HAS_SEC_BOOT
	def_bool y if TARGET_FIP_NO_SEC_BOOT

config NEED_BL33
	def_bool y if TARGET_ALL_NO_SEC_BOOT
	def_bool y if TARGET_ALL_HAS_SEC_BOOT
	def_bool y if TARGET_FIP_NO_SEC_BOOT

config NEED_FIP
	def_bool y if TARGET_ALL_NO_SEC_BOOT
	def_bool y if TARGET_ALL_HAS_SEC_BOOT
	def_bool y if TARGET_FIP_NO_SEC_BOOT

config NEED_MBEDTLS
	def_bool y if TARGET_ALL_HAS_SEC_BOOT

if NEED_BL33
	config BL33
	string "Path to BL33 image"
	default "./u-boot.bin"
endif

MBEDTLS_FOUND :=  $(shell, ls | grep mbedtls-mbedtls- && echo -n "" || echo "0")
MBEDTLS_DEFAULT := $(shell, echo $(MBEDTLS_FOUND) | awk '{ print $NF }')

if NEED_MBEDTLS
	config MBEDTLS_DIR
	string "Path to mbedtls library"
	default $(MBEDTLS_DEFAULT) if $(MBEDTLS_FOUND)!=0
endif

if NEED_SBC
	config ROT_KEY
	string "Path to ROT_KEY"
	default "fip_private_key.pem"

	config BROM_SIGN_KEY
	string "Path to BROM_SIGN_KEY"
	default "bl2_private_key.pem"
endif

#
# ============================ TOOLCHAIN ==============================
#

CC_1 := "/mtkoss/aarch64/7.5.0/x86_64/bin/aarch64-linux-gnu-gcc"
TEST_1 := $(shell, test -e $(CC_1) && echo "1" || echo "0")
CC_2 := "/usr/bin/aarch64-linux-gnu-gcc"
TEST_2 := $(shell, test -e $(CC_2) && echo "1" || echo "0")
CC_3 := "/usr/bin/arm-linux-gnueabi-gcc"
TEST_3 := $(shell, test -e $(CC_3) && echo "1" || echo "0")

config CROSS_COMPILER
	string "cross compile prefix"
	default $(shell, echo $(CC_1) | sed 's/-gcc/-/g') if $(TEST_1)="1" && AARCH64
	default $(shell, echo $(CC_2) | sed 's/-gcc/-/g') if $(TEST_2)="1" && AARCH64
	default $(shell, echo $(CC_3) | sed 's/-gcc/-/g') if $(TEST_3)="1" && AARCH32

#
# ============================   FLASH   ==============================
#

config MTK_SPIM_SUPPORT
	def_bool y if PLAT_MT7981
	def_bool y if PLAT_MT7986
	def_bool y if PLAT_MT7988

config MTK_SNOR_SUPPORT
	def_bool y if PLAT_MT7622
	def_bool y if PLAT_MT7629

config MTK_SNFI_SUPPORT
	def_bool y if PLAT_MT7622
	def_bool y if PLAT_MT7629
	def_bool y if PLAT_MT7981
	def_bool y if PLAT_MT7986
	def_bool y if PLAT_MT7988

config MTK_SDMMC_SUPPORT
	def_bool y if PLAT_MT7622
	def_bool y if PLAT_MT7981
	def_bool y if PLAT_MT7986
	def_bool y if PLAT_MT7988

config BOOT_DEVICE
	def_string "nor" if FLASH_DEVICE_SNOR
	def_string "nor" if FLASH_DEVICE_SPIM_NOR
	def_string "snand" if FLASH_DEVICE_SNFI_SNAND
	def_string "spim-nand" if FLASH_DEVICE_SPIM_NAND
	def_string "emmc" if FLASH_DEVICE_EMMC
	def_string "sdmmc" if FLASH_DEVICE_SDMMC
	def_string "ram" if FLASH_DEVICE_RAM
