# Template file for 'pinebookpro-uboot'
pkgname=pinebookpro-uboot
reverts="20200212_1 20200212_2"
version=0.0.20200212
revision=3
_commit_uboot=365495a329c8e92ca4c134562d091df71b75845e
_commit_atf=22d12c4148c373932a7a81e5d1c59a767e143ac2
archs="aarch64*"
hostmakedepends="git flex cross-arm-none-eabi dtc python3 bc"
depends="u-boot-tools"
short_desc="U-Boot for Pinebook Pro"
maintainer="Renato Aguiar <renato@renatoaguiar.net>"
license="GPL-2.0-only, BSD-3-Clause"
homepage="https://git.eno.space/pbp-uboot"

do_fetch() {
	mkdir -p "${wrksrc}"

	cd "${wrksrc}"
	git clone https://git.eno.space/pbp-uboot.git
	cd pbp-uboot
	git reset --hard ${_commit_uboot}

	cd "${wrksrc}"
	git clone https://github.com/ARM-software/arm-trusted-firmware.git
	cd arm-trusted-firmware
	git reset --hard ${_commit_atf}
}

do_configure() {
	unset CFLAGS CXXFLAGS CPPFLAGS LDFLAGS

	cd pbp-uboot
	patch -Np1 -i ${FILESDIR}/fcommon-Makefile.patch
	make ${makejobs} pinebook_pro-rk3399_defconfig
	echo 'CONFIG_IDENT_STRING=" Voidlinux"' >> .config
}

do_build() {
	unset CFLAGS CXXFLAGS CPPFLAGS LDFLAGS
	if [ "$CROSS_BUILD" ]; then
		export CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-
	fi

	cd arm-trusted-firmware
	make ${makejobs} PLAT=rk3399

	cd ../pbp-uboot
	make ${makejobs} EXTRAVERSION=-${revision} \
	     BL31=../arm-trusted-firmware/build/rk3399/release/bl31/bl31.elf
}

do_install() {
	cd pbp-uboot
	vmkdir boot
	vinstall idbloader.img 0644 boot
	vinstall u-boot.itb 0644 boot
	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
}
