#@TYPE: Machine
#@NAME: nezha-allwinner-d1
#@SOC: Allwinner D1
#@DESCRIPTION: Machine configuration for Nezha board

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

MACHINE_FEATURES = "screen keyboard ext2 ext3 serial"

KERNEL_CLASSES = "kernel-fitimage"
KERNEL_IMAGETYPE = "fitImage"
UBOOT_ENV ?= "boot"
UBOOT_ENV_SUFFIX = "scr.uimg"
PREFERRED_PROVIDER_virtual/kernel ?= "linux-nezha-dev"
PREFERRED_PROVIDER_virtual/bootloader ?= "u-boot-nezha"

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

EXTRA_IMAGEDEPENDS += "opensbi"
RISCV_SBI_PLAT = "generic"

## This sets u-boot as the default OpenSBI payload
### Nezha board uses TOC1 images loaded by SPL and containing U-Boot, DTB, and
### OpenSBI so 'RISCV_SBI_PAYLOAD' isn't used.
### 'RISCV_SBI_FDT' isn't used because the DTB is loaded from RAM at
### ${fdtcontroladdr}
#RISCV_SBI_PAYLOAD ?= "u-boot.bin"
#RISCV_SBI_FDT ?= "sun20i-d1-nezha.dtb"

SERIAL_CONSOLES = "115200;ttyS0"

MACHINE_EXTRA_RRECOMMENDS += " kernel-modules"

IMAGE_FSTYPES += "wic.gz wic.bmap ext4"

### 'KERNEL_DEVICETREE' isn't used because the DTB is loaded from RAM
### at address ${fdtcontroladdr}
#KERNEL_DEVICETREE ?= "allwinner/sun20i-d1-nezha.dtb"

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

EXTRA_IMAGEDEPENDS += "u-boot-nezha"
UBOOT_MACHINE = "nezha_defconfig"


UBOOT_ENTRYPOINT = "0x40200000"
UBOOT_DTB_LOADADDRESS = "0x4FA00000"
UBOOT_DTB = "1"
UBOOT_DTB_BINARY ?= "sun20i-d1-nezha.dtb"

# Deploy boot0 which is used as SPL
EXTRA_IMAGEDEPENDS += "boot0"

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

IMAGE_BOOT_FILES ?= " \
    ${KERNEL_IMAGETYPE} \
    boot.scr.uimg \
    uEnv.txt \
"

WKS_FILE ?= "nezha.wks"
