#@TYPE: Machine
#@NAME: zynq-generic
#@DESCRIPTION: Machine configuration for the zynq-generic devices

#### Preamble
MACHINEOVERRIDES =. "${@['', 'zynq-generic:']['zynq-generic' != '${MACHINE}']}"
#### Regular settings follow

# Variables that changes based on hw design or board specific requirement must be
# defined before calling the required inclusion file else pre-expansion value
# defined in local.conf without machine override will not be reflected.

# Yocto Zynq-7000 device-tree variables
YAML_CONSOLE_DEVICE_CONFIG:pn-device-tree ?= "ps7_uart_1"
YAML_MAIN_MEMORY_CONFIG:pn-device-tree ?= "PS7_DDR_0"
DT_PADDING_SIZE:pn-device-tree ?= "0x1000"
DTC_FLAGS:pn-device-tree = "-@"
YAML_DT_BOARD_FLAGS ?= "{BOARD zc702}"

# Yocto Zynq-7000 u-boot-xlnx variables
UBOOT_MACHINE ?= "xilinx_zynq_virt_defconfig"
BOOTMODE ?= "generic.root"

# Yocto Zynq-7000 FSBL variables
YAML_SERIAL_CONSOLE_STDIN:pn-fsbl-firmware ?= "ps7_uart_1"
YAML_SERIAL_CONSOLE_STDOUT:pn-fsbl-firmware ?= "ps7_uart_1"

# Yocto KERNEL Variables
UBOOT_ENTRYPOINT  ?= "0x200000"
UBOOT_LOADADDRESS ?= "0x200000"
KERNEL_EXTRA_ARGS += "UIMAGE_LOADADDR=${UBOOT_ENTRYPOINT}"

# Zynq-7000 Serial Console settings
SERIAL_CONSOLES ?= "115200;ttyPS0"
YAML_SERIAL_CONSOLE_BAUDRATE ?= "115200"

require conf/machine/include/soc-zynq.inc
require conf/machine/include/machine-xilinx-default.inc
require conf/machine/include/machine-xilinx-qemu.inc

# zynq-generic.conf uses zc702-zynq7 xsa as reference input.
# User can override with custom xsa using HDF_BASE and HDF_PATH variables from
# local.conf.
HDF_MACHINE = "zc702-zynq7"

MACHINE_FEATURES += "rtc ext2 ext3 vfat usbhost usbgadget"

MACHINE_ESSENTIAL_EXTRA_RDEPENDS += "${PREFERRED_PROVIDER_virtual/dtb}"

EXTRA_IMAGEDEPENDS += " \
    libyaml-native \
    python3-cython-native \
    python3-pyyaml-native \
    virtual/fsbl \
    virtual/boot-bin \
    virtual/bootloader \
    u-boot-xlnx-scr \
    "

IMAGE_BOOT_FILES += " \
    boot.bin \
    ${@bb.utils.contains('PREFERRED_PROVIDER_virtual/dtb', 'device-tree', 'system.dtb', '', d)} \
    boot.scr \
    uImage \
    "

IMAGE_CLASSES += "image-types-xilinx-qemu"
# Add wic.qemu-sd only if initramfs_image not set due to circular dependecies
IMAGE_FSTYPES += "${@'wic.qemu-sd' if (d.getVar('INITRAMFS_IMAGE') or '') == '' else 'cpio.gz'}"

# Zynq-7000 QEMU Configurations
# This machine has a QEMU model, runqemu setup:
QB_MEM = "-m 1024"
QB_NETWORK_DEVICE = "-net nic,netdev=net0,macaddr=@MAC@"

QB_KERNEL_ROOT = "/dev/mmcblk0p2"

# Replicate BootROM like behaviour, having loaded SPL and PMU(ROM+FW)
QB_OPT_APPEND = " \
	-serial null \
	-gdb tcp::9000 \
	-device loader,addr=0xf8000008,data=0xDF0D,data-len=4 \
	-device loader,addr=0xf8000140,data=0x00500801,data-len=4 \
	-device loader,addr=0xf800012c,data=0x1ed044d,data-len=4 \
	-device loader,addr=0xf8000108,data=0x0001e008,data-len=4 \
	-device loader,addr=0xF8000910,data=0xF,data-len=0x4 \
	-machine linux=on \
	"

#### No additional settings should be after the Postamble
#### Postamble
PACKAGE_EXTRA_ARCHS:append = "${@['', ' zynq_generic']['zynq-generic' != "${MACHINE}"]}"
