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

MACHINE_NAME = "Aquila-AM69"
MACHINE_FEATURES:remove = "efi"
MACHINE_FEATURES:append = " tpm2"

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

TFA_K3_USART = "0x8"
OPTEE_K3_USART = "0x8"

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

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

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

PREFERRED_PROVIDER_virtual/kernel = "linux-toradex-ti"
PREFERRED_PROVIDER_virtual/kernel:preempt-rt = "linux-toradex-ti"
PREFERRED_PROVIDER_virtual/dtb = "device-tree-overlays-ti"
PREFERRED_PROVIDER_virtual/bootloader = "u-boot-toradex-ti"
PREFERRED_PROVIDER_u-boot = "u-boot-toradex-ti"

KERNEL_DTB_PREFIX = "ti/"
# TODO remove am69-sk dtb
KERNEL_DEVICETREE = " \
    ${KERNEL_DTB_PREFIX}k3-am69-aquila-dev.dtb \
    ${KERNEL_DTB_PREFIX}k3-am69-sk.dtb \
"

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

# overlays applied by generated overlays.txt
TEZI_EXTERNAL_KERNEL_DEVICETREE_BOOT = "aquila-am69_spi1_spidev_overlay.dtbo aquila-am69_spi2_spidev_overlay.dtbo"

UBOOT_CONFIG ??= "sd"
UBOOT_CONFIG[sd] = "aquila-am69_a72_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"

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[0088] = "tiboot3-am69-hs-fs-aquila.bin"
# tispl.bin
OFFSET_FW_PAYLOAD = "2048"
# u-boot.img
OFFSET_SPL_PAYLOAD = "6144"
UBOOT_BINARY = "u-boot.img"

TORADEX_PRODUCT_IDS = "0088"
