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

MACHINE_NAME = "Verdin-iMX8MP"

MACHINEOVERRIDES =. "mx8:mx8m:mx8mp:"

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:mx8mp-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}imx8mp-verdin-nonwifi-dahlia.dtb \
    ${KERNEL_DTB_PREFIX}imx8mp-verdin-nonwifi-dev.dtb \
    ${KERNEL_DTB_PREFIX}imx8mp-verdin-nonwifi-mallow.dtb \
    ${KERNEL_DTB_PREFIX}imx8mp-verdin-nonwifi-yavia.dtb \
    ${KERNEL_DTB_PREFIX}imx8mp-verdin-wifi-dahlia.dtb \
    ${KERNEL_DTB_PREFIX}imx8mp-verdin-wifi-dev.dtb \
    ${KERNEL_DTB_PREFIX}imx8mp-verdin-wifi-mallow.dtb \
    ${KERNEL_DTB_PREFIX}imx8mp-verdin-wifi-yavia.dtb \
"
KERNEL_IMAGETYPE:aarch64 = "Image.gz"

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

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

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

# Set DDR FIRMWARE
LPDDR_FW_VERSION = "_202006"
DDR_FIRMWARE_NAME = " \
    lpddr4_pmu_train_1d_dmem${LPDDR_FW_VERSION}.bin \
    lpddr4_pmu_train_1d_imem${LPDDR_FW_VERSION}.bin \
    lpddr4_pmu_train_2d_dmem${LPDDR_FW_VERSION}.bin \
    lpddr4_pmu_train_2d_imem${LPDDR_FW_VERSION}.bin \
"

ATF_PLATFORM = "imx8mp"
SOC_ATF_BOOT_UART_BASE:verdin-imx8mp = "0x30880000"

BOOT_SPACE = "65536"

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

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 = "32"

SERIAL_CONSOLES = "115200;ttymxc2"

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"

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-sd8997 linux-firmware-nxp89xx"
MACHINE_FIRMWARE:remove = "firmware-sof-imx"

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

UBOOT_BINARY_TEZI_EMMC = "imx-boot"
OFFSET_BOOTROM_PAYLOAD = "0"

TEZI_EXTERNAL_KERNEL_DEVICETREE_BOOT = "verdin-imx8mp_hdmi_overlay.dtbo verdin-imx8mp_dsi-to-hdmi_overlay.dtbo verdin-imx8mp_spidev_overlay.dtbo"
TEZI_EXTERNAL_KERNEL_DEVICETREE_BOOT:use-mainline-bsp = "verdin-imx8mp_spidev_overlay.dtbo"

TORADEX_PRODUCT_IDS = "0058 0061 0063 0064 0065 0066 0070"
TORADEX_PRODUCT_IDS[0058] = "imx8mp-verdin-wifi-dev.dtb"
TORADEX_PRODUCT_IDS[0061] = "imx8mp-verdin-nonwifi-dev.dtb"
TORADEX_PRODUCT_IDS[0063] = "imx8mp-verdin-nonwifi-dev.dtb"
TORADEX_PRODUCT_IDS[0064] = "imx8mp-verdin-wifi-dev.dtb"
TORADEX_PRODUCT_IDS[0065] = "imx8mp-verdin-nonwifi-dev.dtb"
TORADEX_PRODUCT_IDS[0066] = "imx8mp-verdin-wifi-dev.dtb"
TORADEX_PRODUCT_IDS[0070] = "imx8mp-verdin-wifi-dev.dtb"
