# Maintainer: Jenneron <jenneron@protonmail.com>
pkgname=u-boot-snow
pkgver=2022.01
pkgrel=0
pkgdesc="u-boot for Google Snow 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
	cve-2017-5715.patch
	fix-sd-card-detection.patch
"
builddir="$srcdir"/u-boot-${pkgver//_/-}

prepare() {
	default_prepare
}

build() {
	make snow_defconfig
	make

	mkimage -A arm -O linux -T kernel -C none -e 0x43E00000 -a 0x43E00000 -d u-boot-dtb.bin 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-snow/u-boot-dtb.img.kpart
}

sha512sums="
d83c62bd8f0f51664d2aca329a3ce1379cfd1dfff439dccd6cfc2cb33cfef89a2b01855c97716f591b5550bfdf99e2f3aef7efa33f2e7834c820648f9eef3825  u-boot-2022.01.tar.bz2
29378f89edc367f8ea2316ed04d0515398442f74bb29cda85f7cd9edc494707e6e27f1a0dd7cc3aa590fd683710b158da92a596b1b94ee4356d26a9a6c0bf27c  cve-2017-5715.patch
af1095d82c905aab244845419e9b7bf009a043f3c223bb72c9748edea6093d7bd272dfc0eaf9b6b3882fad2e0cdf3652f6b1d81126f0e9f5fa73f13983577ead  fix-sd-card-detection.patch
"
