# Maintainer: Jenneron <jenneron@protonmail.com>
# Co-Maintainer: Segfault <awarnecke002@hotmail.com>
pkgname=u-boot-nyan-2gb
pkgver=2022.04
pkgrel=0
pkgdesc="U-Boot for Nyan Chromebooks"
url="https://www.denx.de/wiki/U-Boot/"
arch="armv7"
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"
options="!check" # no tests in upstream
makedepends="$depends_dev bc dtc python3-dev swig bison flex openssl-dev
	py3-setuptools linux-headers u-boot-tools vboot-utils"
source="
	https://ftp.denx.de/pub/u-boot/u-boot-${pkgver//_/-}.tar.bz2
	fix-stdin.patch
	spectre-mitigation.patch
	chromebook_nyan.its
"

builddir="$srcdir"/u-boot-${pkgver//_/-}

prepare() {
	default_prepare
}

build() {
	make nyan-big_defconfig
	make

	cp "$srcdir"/chromebook_nyan.its ./
	mkimage -f chromebook_nyan.its u-boot-dtb.img

	echo -e "\n" > dummy_config
	echo -e "\n" > dummy_bootloader

	vbutil_kernel \
		--pack u-boot-dtb.img.kpart \
		--keyblock /usr/share/vboot/devkeys/kernel.keyblock \
		--signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \
		--version 1 \
		--arch arm \
		--config dummy_config \
		--bootloader dummy_bootloader \
		--vmlinuz u-boot-dtb.img
}

package() {
	install -D -m644 "$builddir"/u-boot-dtb.img.kpart \
		"$pkgdir"/usr/share/u-boot/google-nyan-big/u-boot-dtb.img.kpart
	ln -s google-nyan-big "$pkgdir"/usr/share/u-boot/google-nyan-blaze
}

sha512sums="
113056e542db049eea3b1d1ccbbe52c79539a2f9bb6129d284ec9200dcffec7bd5969821913a9899631575b80991c84ad01bc845b4bba614e42e54466d9f0d64  u-boot-2022.04.tar.bz2
188f0ac86e2b180c006e31860e1518fde61f393152d94923e9d9d96eeb826c0af0c95ebe9b3a832161181dc0f8d998e203e82317f938e205bfe006012221bfe4  fix-stdin.patch
4e9d167400b3821e9a5cbf189e96cbcb87a960ce8fe7e3f4ee66d764bcd863a626819ebdd4d368247b44d9d0360f8cf3facb194e31634ca3be188ab696e37229  spectre-mitigation.patch
814153b0a0d6c63bff52d5f8e632f7a6083e0aa486dbcbb0c15e4edd570381a7ab2b7ef501bc35c74fee738e60534a501c8e06047cf1ef52af1ad1f3cf2e2b46  chromebook_nyan.its
"
