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

# Deprecated board config
USE_BOARD = "${@"conf/machine/include/xilinx-board-pre.inc" if d.getVar("BOARD") or d.getVar("BOARD_VARIANT") else ""}"
require ${USE_BOARD}
unset USE_BOARD

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

# Set the default for a modern full feature microblaze...
TUNE_FEATURES:tune-microblaze ?= "microblaze v11.0 pattern-compare barrel-shift divide-hard multiply-high fpu-hard reorder"
DEFAULTTUNE ?= "microblaze"

# 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 Microblaze device-tree variables
YAML_CONSOLE_DEVICE_CONFIG:pn-device-tree ?= "axi_uartlite_0"
YAML_MAIN_MEMORY_CONFIG:pn-device-tree ?= "DDR4_0"
DT_PADDING_SIZE:pn-device-tree ?= "0x1000"
DTC_FLAGS:pn-device-tree ?= ""
XSCTH_PROC:pn-device-tree ?= "microblaze_0"
YAML_DT_BOARD_FLAGS ?= "{BOARD kcu105}"

# Yocto Microblaze FS-Boot variables
YAML_SERIAL_CONSOLE_STDIN:pn-fs-boot ?= "axi_uartlite_0"
YAML_SERIAL_CONSOLE_STDOUT:pn-fs-boot ?= "axi_uartlite_0"
YAML_MAIN_MEMORY_CONFIG:pn-fs-boot ?= "DDR4_0"
YAML_FLASH_MEMORY_CONFIG:pn-fs-boot ?= "axi_quad_spi_0"
XSCTH_PROC:pn-fs-boot ?= "microblaze_0"

# Yocto Microblaze u-boot-xlnx variables
UBOOT_MACHINE ?= "microblaze-generic_defconfig"
UBOOT_INITIAL_ENV = ""
BOOTMODE ?= "generic.root"

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

# Microblaze Serial Console settings
SERIAL_CONSOLES ?= "115200;ttyUL0"
YAML_SERIAL_CONSOLE_BAUDRATE ?= "115200"

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

# The default MACHINE_ARCH is dynmic for microblaze, since the architecture is not fixed
# Based on core bitbake.conf
DEF_MACHINE_ARCH = "${@[d.getVar('TUNE_PKGARCH'), d.getVar('MACHINE')][bool(d.getVar('MACHINE'))].replace('-', '_')}"
# Enable a dynamic machine_arch
MB_MACHINE_ARCH = "${@[d.getVar('TUNE_PKGARCH'), d.getVar('TUNE_PKGARCH') + '-generic'][bool(d.getVar('MACHINE'))].replace('-', '_')}"

MACHINE_ARCH = "${@['${MB_MACHINE_ARCH}', '${DEF_MACHINE_ARCH}']['microblaze-generic' != "${MACHINE}"]}"

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

MACHINE_FEATURES = ""

KERNEL_IMAGETYPE ?= "linux.bin.ub"
KERNEL_IMAGETYPES = ""

MACHINE_ESSENTIAL_EXTRA_RDEPENDS += "${PREFERRED_PROVIDER_virtual/dtb}"

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

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

IMAGE_FSTYPES += "cpio.gz"

# Microblaze QEMU Configurations
QB_MEM = "-m 2G"
QB_KERNEL_CMDLINE_APPEND = "console=ttyUL0,115200 root=/dev/ram0 rw"
QB_OPT_APPEND = ""
QB_NETWORK_DEVICE = "-net nic,netdev=net0,macaddr=@MAC@"

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

# Deprecated board config
USE_BOARD = "${@"conf/machine/include/xilinx-board-post.inc" if d.getVar("BOARD") or d.getVar("BOARD_VARIANT") else ""}"
require ${USE_BOARD}
unset USE_BOARD
