#@TYPE: Machine
#@NAME: Toradex Verdin iMX8M Mini
#@SOC: i.MX8MM
#@DESCRIPTION: Machine configuration for Toradex Verdin iMX8M Mini SoM
#@MAINTAINER: Max Krummenacher <max.krummenacher@toradex.com>

MACHINE_NAME = "Verdin-iMX8MM"

MACHINEOVERRIDES =. "mx8:mx8m:mx8mm:"

MACHINE_EXTRA_RRECOMMENDS:append = " mwifiexconf"

IMX_DEFAULT_BSP = "nxp"
IMX_DEFAULT_BSP:upstream = "mainline"

require conf/machine/include/imx-base.inc
# override imx-base.inc which sets this to cortexa53-crypto
DEFAULTTUNE:mx8mm-generic-bsp = "armv8a-crypto"
require conf/machine/include/arm/armv8a/tune-cortexa53.inc

# Don't include kernels in standard images
RRECOMMENDS:${KERNEL_PACKAGE_NAME}-base = ""

KERNEL_DTB_PREFIX = "freescale/"
KERNEL_DEVICETREE = " \
    ${KERNEL_DTB_PREFIX}imx8mm-verdin-nonwifi-dahlia.dtb \
    ${KERNEL_DTB_PREFIX}imx8mm-verdin-nonwifi-dev.dtb \
    ${KERNEL_DTB_PREFIX}imx8mm-verdin-nonwifi-mallow.dtb \
    ${KERNEL_DTB_PREFIX}imx8mm-verdin-nonwifi-yavia.dtb \
    ${KERNEL_DTB_PREFIX}imx8mm-verdin-wifi-dahlia.dtb \
    ${KERNEL_DTB_PREFIX}imx8mm-verdin-wifi-dev.dtb \
    ${KERNEL_DTB_PREFIX}imx8mm-verdin-wifi-mallow.dtb \
    ${KERNEL_DTB_PREFIX}imx8mm-verdin-wifi-yavia.dtb \
"
KERNEL_IMAGETYPE:aarch64 = "Image.gz"

UBOOT_CONFIG ??= "sd"
UBOOT_CONFIG[sd] = "verdin-imx8mm_defconfig,sdcard"
SPL_BINARY = "spl/u-boot-spl.bin"

UBOOT_DTB_LOADADDRESS:mx8mm-generic-bsp = "0x50200000"
UBOOT_DTBO_LOADADDRESS:mx8mm-generic-bsp = "0x50240000"
UBOOT_ENTRYPOINT:mx8mm-generic-bsp  = "0x48200000"
UBOOT_RD_LOADADDRESS = "0x52300000"

# Set u-boot DTB
UBOOT_DTB_NAME = "imx8mm-verdin.dtb"

# Set DDR FIRMWARE
DDR_FIRMWARE_NAME = " \
    lpddr4_pmu_train_1d_imem.bin \
    lpddr4_pmu_train_1d_dmem.bin \
    lpddr4_pmu_train_2d_imem.bin \
    lpddr4_pmu_train_2d_dmem.bin \
"

ATF_PLATFORM = "imx8mm"
SOC_ATF_BOOT_UART_BASE:verdin-imx8mm = "0x30860000"

BOOT_SPACE = "65536"

# Set imx-mkimage boot target
IMXBOOT_TARGETS = "flash_evk_emmc_fastboot"
IMX_BOOT_SOC_TARGET = "iMX8MM"

IMAGE_BOOT_FILES:append = " boot.scr-${MACHINE};boot.scr"
WKS_FILE_DEPENDS:append = " u-boot-default-script"
PREFERRED_PROVIDER_u-boot-default-script = "u-boot-distro-boot"

LOADADDR = ""
UBOOT_SUFFIX = "bin"
UBOOT_MAKE_TARGET = ""
IMX_BOOT_SEEK = "33"

SERIAL_CONSOLES = "115200;ttymxc0"

MACHINE_FEATURES += "3g bluetooth alsa ext2 pci screen touchscreen tpm2 usbgadget usbhost vfat wifi"

PREFERRED_PROVIDER_virtual/kernel = "linux-toradex"
PREFERRED_PROVIDER_virtual/kernel:preempt-rt = "linux-toradex"
PREFERRED_PROVIDER_virtual/kernel:use-mainline-bsp = "linux-toradex-mainline"
PREFERRED_PROVIDER_virtual/kernel:use-mainline-bsp:preempt-rt = "linux-toradex-mainline-rt"
PREFERRED_PROVIDER_virtual/dtb:use-mainline-bsp = "device-tree-overlays-mainline"
MACHINE_EXTRA_RRECOMMENDS:append:use-mainline-bsp = " modprobe-conf"

IMX_DEFAULT_BOOTLOADER = "u-boot-toradex"
# Currently we use the nxp 2022.04 downstream for mx8
PREFERRED_VERSION_u-boot-toradex = "2022.04%"

# handle machine firmware
MACHINE_FIRMWARE:append = " linux-firmware-ath10k linux-firmware-imx-sdma-imx7d"
MACHINE_FIRMWARE:append = " linux-firmware-sd8997"
MACHINE_FIRMWARE:append = " firmware-imx-vpu-imx8"

BOARD_TYPE = "verdin"

IMAGE_CLASSES:append = " image_type_tezi"
IMAGE_FSTYPES += "teziimg"

UBOOT_BINARY_TEZI_EMMC = "imx-boot"
OFFSET_BOOTROM_PAYLOAD = "2"

TEZI_EXTERNAL_KERNEL_DEVICETREE_BOOT = "verdin-imx8mm_dsi-to-hdmi_overlay.dtbo verdin-imx8mm_spidev_overlay.dtbo"
TEZI_EXTERNAL_KERNEL_DEVICETREE_BOOT:use-mainline-bsp = "verdin-imx8mm_spidev_overlay.dtbo"

TORADEX_PRODUCT_IDS = "0055 0057 0059 0060 0068 0086 0087 0090"
TORADEX_PRODUCT_IDS[0055] = "imx8mm-verdin-wifi-v1.1-dev.dtb"
TORADEX_PRODUCT_IDS[0057] = "imx8mm-verdin-nonwifi-v1.1-dev.dtb"
TORADEX_PRODUCT_IDS[0059] = "imx8mm-verdin-nonwifi-v1.1-dev.dtb"
TORADEX_PRODUCT_IDS[0060] = "imx8mm-verdin-wifi-v1.1-dev.dtb"
TORADEX_PRODUCT_IDS[0068] = "imx8mm-verdin-wifi-v1.1-dev.dtb"
TORADEX_PRODUCT_IDS[0086] = "imx8mm-verdin-nonwifi-v1.1-dev.dtb"
TORADEX_PRODUCT_IDS[0087] = "imx8mm-verdin-nonwifi-v1.1-dev.dtb"
TORADEX_PRODUCT_IDS[0090] = "imx8mm-verdin-wifi-v1.1-dev.dtb"
