maintainer="Antoine Martin (ayakael) <dev@ayakael.net>"
pkgname=u-boot-clockworkpi-uconsole-radxa-cm5
pkgver=2017.09
pkgrel=1
_ddr_ver=1.19
pkgdesc="U-Boot fork for the Radxa CM5 for uConsole"
arch="aarch64"
_carch="arm"
license="GPL-2.0"
url="https://github.com/radxa/u-boot"
makedepends="
	arm-trusted-firmware
	bash
	bc
	bison
	coreutils
	dtc
	flex
	gnutls-dev
	openssl-dev
	python3
	py3-setuptools
	python3-dev
	swig
	u-boot-tools
"
options="!check !tracedeps"
_repository="u-boot"
_commit="575d1a114c66ad09e0d9d9f478c993fc243f5aec"
_rkbin_commit="efaf8526fe85521ac86f4e88b0a6a6c6cf2563a1"
source="
	$pkgname-$_commit.tar.gz::https://github.com/radxa/$_repository/archive/$_commit.tar.gz
	https://ayakael.net/api/packages/forge/generic/spl_loader_rk3588/1.19.113/rk3588_spl_loader_v1.19.113.bin
	https://github.com/radxa/rkbin/raw/$_rkbin_commit/bin/rk35/rk3588_ddr_lp4_2112MHz_lp5_2400MHz_v$_ddr_ver.bin

	0001-menu-fix-timeout-duration.patch
	0002-rockchip-move-crypto-functions-to-rk3588s.patch
	0003-rk3588-support-compressed-kernel.patch

	disable-spl-spi-load.patch
	use-python3.patch
	update-u-boot
"
replaces="u-boot-radxa-cm5=$pkgver-r$pkgrel"
builddir="$srcdir/$_repository-$_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

	export ROCKCHIP_TPL="$srcdir"/rk3588_ddr_lp4_2112MHz_lp5_2400MHz_v$_ddr_ver.bin
	export UBOOTVERSION=rk2410-2017.09-1
	export BL31="/usr/share/arm-trusted-firmware/rk3588/bl31.elf"

	make radxa-cm5-rpi-cm4-io-rk3588s_defconfig
	make all u-boot.itb

	# make idbloader.img
	mkimage -n rk3588 -T rksd -d "$ROCKCHIP_TPL:$builddir"/spl/u-boot-spl.bin "$builddir"/idbloader.img
}

package() {
	install -D -m755 "$srcdir"/update-u-boot "$pkgdir"/usr/sbin/update-u-boot
	install -Dm644 \
		"$builddir"/idbloader.img \
		"$builddir"/u-boot.itb \
		"$srcdir"/rk3588_spl_loader_v1.19.113.bin \
		-t "$pkgdir"/usr/share/u-boot/clockworkpi-uconsole-radxa-cm5
}

sha512sums="
4805d0224b8c4ffecdaf560cf493ea06df9e195b7009aa7c30457cb33ecaeea92a64e7b2004ec1903d20fecc0e711905c710bca53072eefececd41a46b4176a2  u-boot-clockworkpi-uconsole-radxa-cm5-575d1a114c66ad09e0d9d9f478c993fc243f5aec.tar.gz
ec2bcf5d5574759ba4bfa71a1880aa76a6647b73a104cac01c17666beab44bf864cc25407435bd2bdc2f9bb88f4bee12ee980cd824044179549e895daba8eff9  rk3588_spl_loader_v1.19.113.bin
0b529e57a7206471a66dcdb98dab3f8deeff333d587c2ebdd08febb40ab9b44e2d51de364d2383ed80dd2b38764ccb552a48f9e34da43607f1e08d385af3f161  rk3588_ddr_lp4_2112MHz_lp5_2400MHz_v1.19.bin
36baf3b8618928e8927229353157ccecb5477e6ed868b9425a04acc2b297026084bd5ed96785292ab2ccb74b9f6328fe032b55505749b103cd68e25777dc3334  0001-menu-fix-timeout-duration.patch
364a8701898e34f6235d2de486316413b5beec95578ee450e504e9a6f5c9feec773642a8129a91eef264e9466206c082950d0793a6a3e97f638edac42e4a70bf  0002-rockchip-move-crypto-functions-to-rk3588s.patch
d80fbde984311b97b0dbd3d1bf7e740350f7c85f3bc8c22fdac93f9200c5b7c722c956dbcc3ec0f4422a72fe5c46b14c0770433efa0f6faf01520ad2ac5f9eca  0003-rk3588-support-compressed-kernel.patch
11a1e30ad0002148f32314dc60c95120d45ffe462755e0bbc7d52ee4001e3283ffb87ba6f58d41feb0c40d456ef42c03857f98f8921c9a7bb810bbf404abedb3  disable-spl-spi-load.patch
1164247343518c9820ce2bf1302f18079b9af81f6ef164e5b9d2c5cbad00ac20e1943bb44d48862c0d4a2f0b7448f9fa35d02d2f66e90c34033d999b3a968443  use-python3.patch
c38b421d48f399ab30707cb244460d9dfc9050592dbafd13f09be11aeda2a19d325f2599cf2650e6855034999a1daf54324e9a65979f9a5d5dc55fe012421384  update-u-boot
"
