#@TYPE: Machine
#@NAME: freedom-u540
#@SOC: Freedom U540
#@DESCRIPTION: Machine configuration for the HiFive Unleashed development board

require conf/machine/include/riscv/tune-riscv.inc

MACHINE_FEATURES = "screen keyboard ext2 ext3 serial"

KERNEL_CLASSES = "kernel-fitimage"
KERNEL_IMAGETYPE = "fitImage"

PREFERRED_PROVIDER_virtual/kernel ?= "linux-mainline"
PREFERRED_PROVIDER_virtual/bootloader ?= "u-boot"

PREFERRED_VERSION_openocd-native = "riscv"
PREFERRED_VERSION_openocd = "riscv"

RISCV_SBI_PLAT = "generic"

## This sets u-boot as the default OpenSBI payload
#RISCV_SBI_PAYLOAD ?= "u-boot.bin"
## This will set the kernel as the OpenSBI payload. This is not recommended,
##  you can use U-Boot's MMC loading instead.
# RISCV_SBI_PAYLOAD ?= "${KERNEL_IMAGETYPE}-${MACHINE}.bin"

RISCV_SBI_FDT ?= "hifive-unleashed-a00.dtb"
## Use this to add Microsemi Expansion board support
# RISCV_SBI_FDT ?=  "hifive-unleashed-a00-microsemi.dtb"

SERIAL_CONSOLES = "115200;ttySIF0"

MACHINE_EXTRA_RRECOMMENDS += " kernel-modules"

IMAGE_FSTYPES += "wic.gz ext4"
KERNEL_DEVICETREE ?= "sifive/${RISCV_SBI_FDT}"

## Do not update fstab file when using wic images
WIC_CREATE_EXTRA_ARGS ?= "--no-fstab-update"

EXTRA_IMAGEDEPENDS += "u-boot"
UBOOT_MACHINE = "sifive_unleashed_defconfig"
SPL_BINARY ?= "spl/u-boot-spl.bin"
UBOOT_SUFFIX ?= "itb"

UBOOT_ENTRYPOINT = "0x80200000"
UBOOT_DTB_LOADADDRESS = "0x82200000"

## Set this to "mmc-boot" to generate a boot.scr file which should be included
##  in the boot partition. It will try to load a kernel image by TFTP and if that
##  fails it will fall back to local images in the boot partition.
UBOOT_ENV ?= "tftp-mmc-boot"

## wic default support
WKS_FILE_DEPENDS ?= " \
    opensbi \
    e2fsprogs-native \
    bmap-tools-native \
"

IMAGE_BOOT_FILES ?= " \
    fw_payload.bin \
    fitImage \
    boot.scr.uimg \
"

WKS_FILE ?= "freedom-u540-opensbi.wks"
