# Template file for 'cubieboard2-uboot'
pkgname=cubieboard2-uboot
version=2016.11
revision=1
wrksrc="u-boot-${version}"
hostmakedepends="dtc bc git sunxi-tools uboot-mkimage"
short_desc="U-Boot for cubieboard2"
maintainer="Orphaned <orphan@voidlinux.org>"
license="GPL-2"
homepage="http://www.denx.de/wiki/U-Boot/WebHome"
distfiles="ftp://ftp.denx.de/pub/u-boot/u-boot-${version}.tar.bz2"
checksum=45813e6565dcc0436abe6752624324cdbf5f3ac106570d76d32b46ec529bcdc8

archs="armv7l*"

do_configure() {
	git clone https://github.com/linux-sunxi/sunxi-boards
}
do_build() {
	local _boards="Cubieboard2 Cubietruck"

	unset CFLAGS CXXFLAGS LDFLAGS

	for f in ${_boards}; do
		mkdir bin_${f}
		make distclean
		if [ -n "$CROSS_BUILD" ]; then
			make CROSS_COMPILE=${XBPS_CROSS_TRIPLET}- ${f}_config
			make CROSS_COMPILE=${XBPS_CROSS_TRIPLET}- ${makejobs}
		else
			make ${f}_config
			make ${makejobs}
		fi
		mv u-boot-sunxi-with-spl.bin bin_${f}
	done

	mkimage -A arm -O linux -T script -C none -n "U-Boot boot script" -d ${FILESDIR}/boot.txt boot.scr
}
do_install() {
	vmkdir boot
	vinstall bin_Cubieboard2/u-boot-sunxi-with-spl.bin 644 boot
	fex2bin sunxi-boards/sys_config/a20/cubieboard2.fex ${DESTDIR}/boot/script.bin
	vinstall ${FILESDIR}/boot.txt 644 boot
	vinstall boot.scr 644 boot
}

cubietruck-uboot_package() {
	short_desc="${short_desc/cubieboard2/cubietruck}"
	pkg_install() {
		vmkdir boot
		vinstall bin_Cubietruck/u-boot-sunxi-with-spl.bin 644 boot
		fex2bin sunxi-boards/sys_config/a20/cubietruck.fex ${DESTDIR}/boot/script.bin
		vinstall ${FILESDIR}/boot.txt 644 boot
		vinstall boot.scr 644 boot
	}
}