# Template file for 'odroid-u2-uboot'
_githash=89f2ab95e7304fe02e5267f1282fbc178550d528
pkgname=odroid-u2-uboot
version=v2010.12
revision=2
wrksrc="u-boot-${_githash}"
hostmakedepends="uboot-mkimage"
short_desc="Odroid U2 U-Boot files for SD booting"
maintainer="Enno Boland <gottox@voidlinux.eu>"
license="GPL-2"
homepage="https://github.com/hardkernel/u-boot"
distfiles="https://github.com/hardkernel/u-boot/archive/${_githash}.tar.gz"
checksum="29593e636a0d908230910522aab74c09a35b92fee71b165d088f561e85ba3e1d"

only_for_archs="armv7l"

_default_scr="boot-auto_edid.scr"

do_configure() {
	make mrproper
	patch -p1 < ${FILESDIR}/config.patch
	make smdk4412_config
}

do_build() {
	${BUILD_CC} ${BUILD_CFLAGS} -o mkbl2 ${FILESDIR}/mkbl2.c

	unset CFLAGS CXXFLAGS LDFLAGS

	if [ "$CROSS_BUILD" ]; then
		make ARCH=arm CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-
	else
		make ARCH=arm
	fi

	# Building uboot scr's
	for source in ${FILESDIR}/*.ini; do
		name=$(basename ${source%.ini})
		mkimage -A arm -T script -C none -n "${name}" -d $source ${name}.scr
	done

	cp ${_default_scr} boot.scr
}

do_install() {
	vinstall u-boot.bin 600 boot

	# Install uboot scr's
	for scr in *.scr; do
		echo $scr
		vinstall $scr 600 boot
	done
}
