DESCRIPTION = "U-Boot port for pinephone"

require recipes-bsp/u-boot/u-boot.inc

LICENSE = "GPL-2.0-only"
LIC_FILES_CHKSUM = "file://Licenses/gpl-2.0.txt;md5=b234ee4d69f5fce4486a80fdaf4a4263"

FILESEXTRAPATHS:prepend := "${THISDIR}/files:"

DEPENDS:append = " bc-native dtc-native swig-native python3-native flex-native bison-native python3-setuptools-native "
DEPENDS:append = " atf-50i-a64 "

# No patches for other machines yet
PROVIDES += " u-boot virtual/bootloader "

COMPATIBLE_MACHINE = "(sun50i|sun50i-a64|pinephone)"
DEFAULT_PREFERENCE:sun50i = "1"
DEFAULT_PREFERENCE:pinephone="1"

UBOOT_MACHINE = "pinephonefb_defconfig"

SRC_URI = " \
	git://git.iohub.dev/dany/u-boot-megous.git;protocol=https;branch=megi-v2025.01 \
	file://boot.cmd \
	file://pinephonefb_defconfig \
	"

PE = "1"

PV = "v2025.01+git${SRCPV}"

SRCREV = "${AUTOREV}"

S = "${UNPACKDIR}/git"

PACKAGE_ARCH = "${MACHINE_ARCH}"

SPL_BINARY="u-boot-sunxi-with-spl.bin"
UBOOT_ENV_SUFFIX = "scr"
UBOOT_ENV = "boot"

EXTRA_OEMAKE:append = ' HOSTLDSHARED="${BUILD_CC} -shared ${BUILD_LDFLAGS} ${BUILD_CFLAGS}" '
EXTRA_OEMAKE:append = " BL31=${DEPLOY_DIR_IMAGE}/bl31.bin SCP=/dev/null"


do_compile[depends] += "atf-50i-a64:do_install"

do_configure:prepend() {
    cp ${UNPACKDIR}/pinephonefb_defconfig ${S}/configs/pinephonefb_defconfig
}

do_configure() {
	oe_runmake  ${UBOOT_MACHINE}
#   oe_runmake -C ${S} O=${B} ${UBOOT_MACHINE} mrproper
}

do_compile() {
	oe_runmake
	oe_runmake u-boot-initial-env
    ${B}/tools/mkimage -C none -A arm -T script -d ${UNPACKDIR}/boot.cmd ${S}/${UBOOT_ENV_BINARY}
}

