# Contributor: Milan P. Stanić <mps@arvanta.net>
# Maintainer: Milan P. Stanić <mps@arvanta.net>
pkgname=u-boot-spacemit
_basever=2022.10
_realver=2.0.4
pkgver=${_basever}.${_realver}
pkgrel=0
pkgdesc="u-boot bootloader for spacemit"
url="https://gitee.com/bianbu-linux/uboot-2022.10"
arch="riscv64"
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

makedepends="$depends_dev
	bash
	bc
	bison
	dtc
	flex
	gnutls-dev
	linux-headers
	opensbi-spacemit
	openssl-dev
	py3-elftools
	py3-setuptools
	python3-dev
	swig
	util-linux-dev
	"
source="$pkgname-v$_realver.tar.gz::https://gitee.com/bianbu-linux/uboot-2022.10/repository/archive/v$_realver.tar.gz
	020-mbr-support.patch
	022-syslinux-and-script-support.patch
	"
builddir=$srcdir/uboot-$_basever-v$_realver

prepare() {
	rm -f rm board/spacemit/k1-x/k1-x.env
	default_prepare
	make k1_defconfig
	scripts/config --file .config --disable PRINT_TIMESTAMP
	scripts/config --file .config --set-val BOOTDELAY 2
	scripts/config --file .config --disable AUTOBOOT_KEYED
	scripts/config --file .config --disable AUTOBOOT_USE_MENUKEY
	scripts/config --file .config --disable LOCALVERSION_AUTO
	scripts/config --file .config --disable AUTOBOOT_DELAY_STR
	scripts/config --file .config --disable AUTOBOOT_STOP_STR
	scripts/config --file .config --set-str LOCALVERSION " $_realver"
}

build() {
	export OPENSBI="/usr/share/opensbi-spacemit/fw_dynamic.itb"
	make
}

package() {
	mkdir -p "$pkgdir"/usr/share/$pkgname
	install -m644 "$builddir"/u-boot.itb "$pkgdir"/usr/share/$pkgname/
	install -m644 "$builddir"/FSBL.bin "$pkgdir"/usr/share/$pkgname/
	install -m644 "$builddir"/bootinfo_emmc.bin "$pkgdir"/usr/share/$pkgname/
}

sha512sums="
69e5a13bebae37d3cc67d56be1057753d6ced351001729135b552d73ae704431ee2674d0673a7fa20189cd8323a26e4af0e5e433a5963acd36d5fb73196d7151  u-boot-spacemit-v2.0.4.tar.gz
a495f25797013d23a262b7bccd124315927b50febdb4a1a5564116dd82ef164514acec920cfba021eb4f48686f478a0f0a8a498115709715890c6c5236204b09  020-mbr-support.patch
87ee8313dbe4f1e23b4e11ad728d17f5b63492ed1e5c6f00f2e3f6a286697c32305595a877517f924416adc9ad88d35e79f20e813a2375ee9b7a33d71b8ca25e  022-syslinux-and-script-support.patch
"
