#@TYPE: Machine
#@NAME: Toradex Verdin AM62
#@DESCRIPTION: Machine configuration for Toradex Verdin AM62 SoM
#@MAINTAINER: Max Krummenacher <max.krummenacher@toradex.com>

MACHINE_NAME = "Verdin-AM62"
MACHINE_FEATURES:remove = "efi"
MACHINE_FEATURES:append = " tpm2"

MACHINE_EXTRA_RRECOMMENDS:append = " btnxpuartconf mwifiexconf"

require conf/machine/tdx-utilities.inc
require conf/machine/include/am62xx.inc

do_image[mcdepends] = "mc::k3r5:virtual/bootloader:do_deploy"

# cope with our changed tiboot3 file names vs. the hardcoded TI AM625 SK-EVM  ones
IMAGE_BOOT_FILES:remove = "tiboot3-am62x-gp-evm.bin tiboot3-am62x-hs-evm.bin tiboot3-am62x-hs-fs-evm.bin"

IMAGE_BOOT_FILES:remove = "ti_logo_414x97_32bpp.bmp.gz"

# Don't include kernels in standard images
RRECOMMENDS:${KERNEL_PACKAGE_NAME}-base = ""
# Install kernel modules by default
MACHINE_EXTRA_RRECOMMENDS:append:am62xx = " kernel-modules"

PREFERRED_PROVIDER_virtual/kernel = "linux-toradex-ti"
PREFERRED_PROVIDER_virtual/kernel:preempt-rt = "linux-toradex-ti"
PREFERRED_PROVIDER_virtual/kernel:upstream = "linux-toradex-mainline"
PREFERRED_PROVIDER_virtual/kernel:upstream:preempt-rt = "linux-toradex-mainline-rt"
PREFERRED_PROVIDER_virtual/gpudriver:upstream = ""
PREFERRED_PROVIDER_virtual/dtb = "device-tree-overlays-ti"
PREFERRED_PROVIDER_virtual/dtb:upstream = "device-tree-overlays-mainline"
PREFERRED_PROVIDER_virtual/bootloader = "u-boot-toradex-ti"
PREFERRED_PROVIDER_u-boot = "u-boot-toradex-ti"
PREFERRED_PROVIDER_virtual/bootloader:upstream:use-head-next = "u-boot-toradex"
PREFERRED_PROVIDER_u-boot:upstream:use-head-next = "u-boot-toradex"

KERNEL_DTB_PREFIX = "ti/"
KERNEL_DEVICETREE = " \
    ${KERNEL_DTB_PREFIX}k3-am625-verdin-nonwifi-dahlia.dtb \
    ${KERNEL_DTB_PREFIX}k3-am625-verdin-nonwifi-dev.dtb \
    ${KERNEL_DTB_PREFIX}k3-am625-verdin-nonwifi-mallow.dtb \
    ${KERNEL_DTB_PREFIX}k3-am625-verdin-nonwifi-yavia.dtb \
    ${KERNEL_DTB_PREFIX}k3-am625-verdin-wifi-dahlia.dtb \
    ${KERNEL_DTB_PREFIX}k3-am625-verdin-wifi-dev.dtb \
    ${KERNEL_DTB_PREFIX}k3-am625-verdin-wifi-mallow.dtb \
    ${KERNEL_DTB_PREFIX}k3-am625-verdin-wifi-yavia.dtb \
"

KERNEL_IMAGETYPE = "Image.gz"
KERNEL_IMAGETYPES = "fitImage Image Image.gz"

# overlays applied by generated overlays.txt
TEZI_EXTERNAL_KERNEL_DEVICETREE_BOOT = "verdin-am62_dsi-to-hdmi_overlay.dtbo verdin-am62_spidev_overlay.dtbo"
TEZI_EXTERNAL_KERNEL_DEVICETREE_BOOT:upstream = ""

UBOOT_CONFIG ??= "sd"
UBOOT_CONFIG[sd] = "verdin-am62_a53_defconfig,sdcard"
UBOOT_ENTRYPOINT = "0x80200000"
UBOOT_LOADADDRESS = "0x80200000"

IMAGE_BOOT_FILES = " \
    boot.scr-${MACHINE};boot.scr \
    ${KERNEL_IMAGETYPE} \
    ${@make_dtb_boot_files(d)} \
"

# meta-ti-bsp/conf/machine/include/k3.inc
# With "sdimage-2part-efi.wks" my builds do not boot, no serial output at
# all
WKS_FILE:k3 = "sdimage-2part.wks"
WKS_FILE_DEPENDS:append = " u-boot-distro-boot"
WIC_CREATE_EXTRA_ARGS:append = " --no-fstab-update"

# handle machine firmware
MACHINE_EXTRA_RRECOMMENDS:append = " linux-firmware-iw416"

IMAGE_CLASSES:append = " image_type_tezi"
IMAGE_FSTYPES:append = " teziimg"
# The payload offsets are given in number of 512 byte blocks.
# tiboot3.bin
OFFSET_BOOTROM_PAYLOAD = "0"
FIRMWARE_BINARY[0069] = "tiboot3-am62x-gp-verdin.bin"
FIRMWARE_BINARY[0071] = "tiboot3-am62x-hs-fs-verdin.bin"
FIRMWARE_BINARY[0072] = "tiboot3-am62x-hs-fs-verdin.bin"
FIRMWARE_BINARY[0073] = "tiboot3-am62x-hs-fs-verdin.bin"
FIRMWARE_BINARY[0074] = "tiboot3-am62x-hs-fs-verdin.bin"
FIRMWARE_BINARY[0075] = "tiboot3-am62x-hs-fs-verdin.bin"
FIRMWARE_BINARY[0076] = "tiboot3-am62x-hs-fs-verdin.bin"
# tispl.bin
OFFSET_FW_PAYLOAD = "1024"
# u-boot.img
OFFSET_SPL_PAYLOAD = "5120"
UBOOT_BINARY = "u-boot.img"

TORADEX_PRODUCT_IDS = "0069 0071 0072 0073 0074 0075 0076"
