# Reference: <https://u-boot.readthedocs.io/en/latest/board/amlogic/radxa-zero.html>
# Maintainer:
pkgname=u-boot-beelink-gt1
pkgver=2023.04
pkgrel=1
pkgdesc="U-Boot bootloader for Beelink gt1"
url="https://source.denx.de/u-boot"
arch="aarch64"
_ubootver=2023.04-rc3
license="GPL-2.0-or-later OFL-1.1 BSD-2-Clause BSD-3-Clause eCos-2.0 IBM-pibs
	ISC LGPL-2.0-only LGPL-2.1-only X11 proprietary"
makedepends="$depends_dev
	bc
	bison
	dtc
	flex
	openssl-dev
	py3-setuptools
	python3-dev
	swig
	bash
	"
options="!check"
# https://u-boot.readthedocs.io/en/latest/board/amlogic/pre-generated-fip.html
_amlogicblob_commit="e96b6a694380ff07d5a9e4be644ffe254bd18512"
source="https://source.denx.de/u-boot/u-boot/-/archive/v$_ubootver/u-boot-v$_ubootver.tar.gz
	0001-add-basic-support-for-beelink-gt1.patch
	amlogicblob_beelink-gt1.tar.gz::https://github.com/LibreELEC/amlogic-boot-fip/archive/$_amlogicblob_commit.tar.gz
	"
builddir="$srcdir/u-boot-v$_ubootver"
_fipbuilddir="$srcdir/amlogic-boot-fip-$_amlogicblob_commit"

build() {
	touch include/config.h
	LC_ALL=C date +'#define U_BOOT_DATE "%b %d %C%y"' > include/timestamp_autogenerated.h
	LC_ALL=C date +'#define U_BOOT_TIME "%T"' >> include/timestamp_autogenerated.h

	make ARCH=arm beelink_gt1_ultimate_defconfig
	make ARCH=arm all
	cd $_fipbuilddir
	mkdir build
	./build-fip.sh beelink-gt1 $builddir/u-boot.bin ./build
	cd ./build
	dd if=u-boot.bin.sd.bin of=u-boot.bin.sd-stripped.bin conv=fsync,notrunc bs=512 skip=1
}

package() {
	_installdir="$pkgdir/usr/share/u-boot/beelink-gt1"
	install -Dm644 "$_fipbuilddir/build/u-boot.bin.sd-stripped.bin" -t "$_installdir"
	install -Dm644 "$_fipbuilddir/build/u-boot.bin.sd.bin" -t "$_installdir"
	install -Dm644 "$_fipbuilddir/build/u-boot.bin" -t "$_installdir"
	install -Dm644 "$_fipbuilddir/build/u-boot.bin.usb.bl2" -t "$_installdir"
	install -Dm644 "$_fipbuilddir/build/u-boot.bin.usb.tpl" -t "$_installdir"
}

sha512sums="
4d2afc652d1431f17694bb41493c699dd477c82b466282a24094c59fada558df7c8a79518c1804729a73dd901d2e24beb1643313cb2d93d348559410182bc67b  u-boot-v2023.04-rc3.tar.gz
d870e1ea53e70038600c9a9ac03a2493f511ebf27231ff899c6f2c6f3d9160d91882871553e48475b46a4ba80f9037f7fcb0243b26649f7f3753fa13d220e352  0001-add-basic-support-for-beelink-gt1.patch
98ecbbc56e8326ce11db4e316a7bb3812d713fbe630235825ddb657b28419eb406f7117208a5c0360653ebdccb9af1a48357d0c257cd61f11a8c3cdaa78548b5  amlogicblob_beelink-gt1.tar.gz
"
