#@TYPE: Machine
#@NAME: Toradex Apalis iMX8
#@DESCRIPTION: Toradex Apalis iMX8 powered by a i.MX 8QuadMax SoC
#@MAINTAINER: Stefan Agner <stefan.agner@toradex.com>

MACHINE_NAME = "Apalis-iMX8"

SOC_SILICON_REV ?= ""

MACHINEOVERRIDES =. "mx8:mx8qm:"

MACHINE_EXTRA_RRECOMMENDS:append = " mwifiexconf"

IMX_DEFAULT_BSP = "nxp"

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

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

LOADADDR = ""

# we do not want to have getty running on tty1 as we run
# auto-serial-console there
USE_VT = "0"

KERNEL_DTB_PREFIX = "freescale/"
KERNEL_DEVICETREE = " \
    ${KERNEL_DTB_PREFIX}imx8qm-apalis-eval.dtb \
    ${KERNEL_DTB_PREFIX}imx8qm-apalis-eval-v1.2.dtb \
    ${KERNEL_DTB_PREFIX}imx8qm-apalis-ixora-v1.1.dtb \
    ${KERNEL_DTB_PREFIX}imx8qm-apalis-v1.1-eval.dtb \
    ${KERNEL_DTB_PREFIX}imx8qm-apalis-v1.1-eval-v1.2.dtb \
    ${KERNEL_DTB_PREFIX}imx8qm-apalis-v1.1-ixora-v1.1.dtb \
    ${KERNEL_DTB_PREFIX}imx8qm-apalis-v1.1-ixora-v1.2.dtb \
    ${KERNEL_DTB_PREFIX}imx8qp-apalis-v1.1-eval.dtb \
    ${KERNEL_DTB_PREFIX}imx8qp-apalis-v1.1-eval-v1.2.dtb \
    ${KERNEL_DTB_PREFIX}imx8qp-apalis-v1.1-ixora-v1.1.dtb	\
    ${KERNEL_DTB_PREFIX}imx8qp-apalis-v1.1-ixora-v1.2.dtb \
"

KERNEL_IMAGETYPE:aarch64 = "Image.gz"

UBOOT_SUFFIX = "bin"
UBOOT_CONFIG ??= "sd"
UBOOT_CONFIG[sd] = "apalis-imx8_defconfig,sdcard"

UBOOT_ENTRYPOINT = "0x96000000"
UBOOT_DTB_LOADADDRESS = "0x83000000"
UBOOT_DTBO_LOADADDRESS = "0x83100000"
UBOOT_RD_LOADADDRESS = "0xA0000000"

ATF_PLATFORM = "imx8qm"

BOOT_SPACE = "65536"
IMX_BOOT_SEEK = "32"

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

PREFERRED_PROVIDER_virtual/kernel = "linux-toradex"
PREFERRED_PROVIDER_virtual/kernel:preempt-rt = "linux-toradex"
PREFERRED_PROVIDER_virtual/bootloader = "u-boot-toradex"
PREFERRED_PROVIDER_u-boot = "u-boot-toradex"
# Currently we use the nxp 2022.04 downstream for mx8
PREFERRED_VERSION_u-boot-toradex = "2022.04%"

MACHINE_FIRMWARE:append = " linux-firmware-pcie8997 firmware-imx-hdmi"

IMXBOOT_TARGETS = "flash_b0"
IMX_BOOT_SOC_TARGET = "iMX8QM"

PREFERRED_PROVIDER_imx-sc-firmware = "imx-sc-firmware-toradex"
BOARD_TYPE = "apalis"

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

# The imx-boot container takes care for the i.MX 8 offset, so the container
# has to be flashed at offset 0 directly
UBOOT_BINARY_TEZI_EMMC = "imx-boot"
OFFSET_BOOTROM_PAYLOAD = "0"

TEZI_EXTERNAL_KERNEL_DEVICETREE_BOOT = " \
    apalis-imx8_hdmi_overlay.dtbo \
    apalis-imx8_spi1_spidev_overlay.dtbo \
    apalis-imx8_spi2_spidev_overlay.dtbo \
"

TORADEX_PRODUCT_IDS = "0037 0047 0048 0049 0067 0091 0092 0093 0094 0095"
TORADEX_PRODUCT_IDS[0037] = "imx8qm-apalis-v1.1-eval.dtb"
TORADEX_PRODUCT_IDS[0047] = "imx8qm-apalis-v1.1-eval.dtb"
TORADEX_PRODUCT_IDS[0048] = "imx8qp-apalis-v1.1-eval.dtb"
TORADEX_PRODUCT_IDS[0049] = "imx8qp-apalis-v1.1-eval.dtb"
TORADEX_PRODUCT_IDS[0067] = "imx8qm-apalis-v1.1-eval.dtb"
TORADEX_PRODUCT_IDS[0091] = "imx8qm-apalis-v1.1-eval.dtb"
TORADEX_PRODUCT_IDS[0092] = "imx8qm-apalis-v1.1-eval.dtb"
TORADEX_PRODUCT_IDS[0093] = "imx8qp-apalis-v1.1-eval.dtb"
TORADEX_PRODUCT_IDS[0094] = "imx8qp-apalis-v1.1-eval.dtb"
TORADEX_PRODUCT_IDS[0095] = "imx8qm-apalis-v1.1-eval.dtb"

