# Template file for 'pinebookpro-uboot'
pkgname=pinebookpro-uboot
reverts="20200212_1 20200212_2"
version=2022.04
revision=2
archs="aarch64*"
hostmakedepends="flex bc dtc python3 openssl-devel"
makedepends="atf-rk3399-bl31"
depends="u-boot-tools"
short_desc="U-Boot for Pinebook Pro"
maintainer="Cameron Nemo <cam@nohom.org>"
license="GPL-2.0-only, BSD-3-Clause"
homepage="https://www.denx.de/wiki/U-Boot/"
distfiles="https://ftp.denx.de/pub/u-boot/u-boot-${version}.tar.bz2"
checksum=68e065413926778e276ec3abd28bb32fa82abaa4a6898d570c1f48fbdb08bcd0

do_configure() {
	unset CFLAGS CXXFLAGS CPPFLAGS LDFLAGS
	make ${makejobs} pinebook-pro-rk3399_defconfig
}

do_build() {
	unset CFLAGS CXXFLAGS CPPFLAGS LDFLAGS
	if [ "$CROSS_BUILD" ]; then
		export CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-
	fi
	make ${makejobs} EXTRAVERSION=-${revision} \
	     BL31="${XBPS_CROSS_BASE}/usr/lib/trusted-firmware-a/rk3399/bl31.elf"
}

do_install() {
	vinstall idbloader.img 0644 usr/lib/pinebookpro-uboot
	vinstall u-boot.itb 0644 usr/lib/pinebookpro-uboot
	# FWIW this file is not at all specific to the PBP and will overwrite any custom
	# u-boot boot.scr files that a user installs into /boot.
	# I would like to remove it, but it could cause breakage for existing setups.
	# It would also require some changes to void-mklive to configure u-boot suitably.
	vinstall "${FILESDIR}/kernel.d/uboot" 750 \
		etc/kernel.d/post-install 60-uboot

	vlicense Licenses/Exceptions
	vlicense Licenses/OFL.txt
	vlicense Licenses/README
	vlicense Licenses/bsd-2-clause.txt
	vlicense Licenses/bsd-3-clause.txt
	vlicense Licenses/eCos-2.0.txt
	vlicense Licenses/gpl-2.0.txt
	vlicense Licenses/ibm-pibs.txt
	vlicense Licenses/isc.txt
	vlicense Licenses/lgpl-2.0.txt
	vlicense Licenses/lgpl-2.1.txt
	vlicense Licenses/r8a779x_usb3.txt
	vlicense Licenses/x11.txt
}
