# Seperate u-boot package for the pine64-pinebookpro because this includes
# a driver for the display and supports efi loading operating systems
maintainer="Hugo Osvaldo Barrera <hugo@whynothugo.nl>"
pkgname=u-boot-pinebookpro
pkgver=2026.04
pkgrel=0
pkgdesc="u-boot bootloader for the rk3399"
url="https://gitlab.denx.de/u-boot/u-boot"
arch="aarch64"
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"
makedepends="$depends_dev
	arm-trusted-firmware
	bash
	bc
	bison
	dtc
	flex
	gnutls-dev
	openssl-dev
	python3-dev
	py3-elftools
	py3-setuptools
	swig
	u-boot-tools
	"
options="!check"
source="
	ftp://ftp.denx.de/pub/u-boot/u-boot-${pkgver//_/-}.tar.bz2
	0001-pinebook-pro-ensure-USB-keyboards-are-available.patch
	0002-drivers-video-rockchip-rk_edp.c-Change-clock-rate.patch
	0003-vidconsole-uclass-Implement-ANSI_CURSOR_COLUMN.patch
	0004-Configure-boot-splash-logo.patch
	0005-cli-Clear-ctrl-c-before-running-a-command.patch
	0006-rockchip-move-usb0-after-mmc1-in-default-boot-order.patch
	0007-pinebook-pro-Fix-vcc_sdio-regulator-max-voltage.patch
	pine64.bmp
	"
builddir="$srcdir"/u-boot-${pkgver//_/-}

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 BL31="/usr/share/arm-trusted-firmware/rk3399/bl31.elf"
	export BUILD_DIR="$builddir"/build
	mkdir -p "$BUILD_DIR"
	make O="$BUILD_DIR" HOSTCC=gcc ARCH=arm LOGO_BMP=$srcdir/pine64.bmp pinebook-pro-rk3399_defconfig
	make O="$BUILD_DIR" HOSTCC=gcc ARCH=arm LOGO_BMP=$srcdir/pine64.bmp all

	mkimage -n rk3399 -T rkspi -d build/tpl/u-boot-tpl-dtb.bin:build/spl/u-boot-spl-dtb.bin spl.bin
	dd if=spl.bin bs=512K conv=sync of=u-boot.spiflash.bin
	cat u-boot.spiflash.bin build/u-boot.itb > build/u-boot.spiflash.bin
	# Make the image the exact size of the spi flash so flashrom does what it's supposed to
	truncate -s 16777216 build/u-boot.spiflash.bin

	truncate -s 50MB bootable.img
	dd if=build/idbloader.img of=bootable.img bs=512 seek=64 conv=notrunc
	dd if=build/u-boot.itb of=bootable.img bs=512 seek=16384 conv=notrunc
}

package() {
	install -D -m644 build/u-boot-rockchip.bin \
		"$pkgdir"/usr/share/u-boot/pine64-rockpro64/u-boot-rockchip.bin
	install -D -m644 build/u-boot.spiflash.bin \
		"$pkgdir"/usr/share/u-boot/pine64-rockpro64/u-boot.spiflash.bin
	install -D -m644 bootable.img \
		"$pkgdir"/usr/share/u-boot/pine64-rockpro64/bootable.img
}


sha512sums="
c5fca2abc533759985dfcc6d071d154007535787b0bbd569b61bda1fe2f3a31fba08481c8caf18cf5f2bc79609f50dee504977a8b65e8c4cc21f277268232e03  u-boot-2026.04.tar.bz2
572d24d70d96e84649b71a0a460ac9b9ae26d155d549bda1bc2534a54d102b158319caef24609fdbef6465a63d6c2624a42851bcad5b5cb60373abef62bd1850  0001-pinebook-pro-ensure-USB-keyboards-are-available.patch
3657612c577076c733637cf1b52ece1722369f3a7b821e6a08b7650e85692f5e69acc8f1d4a20d36b701a5bcc4a5bc306456ac371689fcc69ee4c4626ec78483  0002-drivers-video-rockchip-rk_edp.c-Change-clock-rate.patch
e1dc0553c3685ea1f52f067907b042f54f8244060f9ba865a81970bceba387fe1581d6ea05f6d1aa1ca81513a8e92580781ecb20f9d02d83c56033809ede4ccc  0003-vidconsole-uclass-Implement-ANSI_CURSOR_COLUMN.patch
da1b515afbbe2387f6fee1028277cb19f5536598ba3fe7cd940d11476f41f162d3d4c08d9ee0ff5554e16dd9cbb4fc70015b5cc5eed885e75267a9e82bf7209f  0004-Configure-boot-splash-logo.patch
11be09f9dc0bd2eefb645fcc3d5681ade90e104aa8e7c9de549b20393761074edd0e42828fb5147e186d995e11e1397bc94dd2cc521f307d8d26b6925fe22f1b  0005-cli-Clear-ctrl-c-before-running-a-command.patch
5fdf9a5b42b271414b1f07a8cd94b537562d4994b5cb21377dddc065754b3977a8a3af646c9db0736eeb9cb7e9be0da7838721c5c1bc58f6de00bc1cbed54604  0006-rockchip-move-usb0-after-mmc1-in-default-boot-order.patch
3537d81c0a839f2a35e28ef0dc9126e3d175950a0752b363839970c64db4c5aa6afceb8912a2e0a3a09d14fceb94704be2f752a0c002ace51676e736a58ba435  0007-pinebook-pro-Fix-vcc_sdio-regulator-max-voltage.patch
e317f8527dbb3b8a40a45d20da6c42f8cfd98b968060d6b4f1fa5453736441d36d1048bdc4359af47c2129fa86b6d43b3e263ef282f5c7b2e54f702d8b6bd8b1  pine64.bmp
"
