pkgname=firmware-qcom-db410c
pkgver=1034.2.1
pkgrel=1
pkgdesc="Firmware for DragonBoard 410c"
url="https://releases.linaro.org/96boards/dragonboard410c/qualcomm/firmware/"
subpackages="$pkgname-doc $pkgname-modem $pkgname-wcnss $pkgname-wcnss-nv:wcnss_nv"
arch="aarch64"
license="custom"
options="!check !strip !archcheck !tracedeps pmb:cross-native"
makedepends="mtools"
source="https://releases.linaro.org/96boards/dragonboard410c/qualcomm/firmware/linux-board-support-package-r$pkgver.zip"
builddir="$srcdir/linux-board-support-package-r$pkgver"

_fwdir="/lib/firmware/postmarketos"

unpack() {
	default_unpack

	# Extract firmware files from FAT file system image
	mcopy -i "$builddir"/bootloaders-linux/NON-HLOS.bin -p -m -v \
		::image/mba.mbn ::image/modem.* ::image/wcnss.* "$srcdir"
}

package() {
	install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
	install -Dm644 NOTICE.txt "$pkgdir"/usr/share/licenses/$pkgname/NOTICE
}

modem() {
	pkgdesc="DragonBoard 410c modem firmware"
	install -Dm644 "$srcdir"/mba.mbn -t "$subpkgdir/$_fwdir"
	install -Dm644 "$srcdir"/modem.* -t "$subpkgdir/$_fwdir"
}

wcnss() {
	pkgdesc="DragonBoard 410c WiFi/BT firmware"
	provides="firmware-qcom-msm8916-wcnss"
	provider_priority=100

	install -Dm644 "$srcdir"/wcnss.* -t "$subpkgdir/$_fwdir"
}

wcnss_nv() {
	pkgdesc="DragonBoard 410c WiFi/BT firmware configuration"
	install -Dm644 "$builddir"/proprietary-linux/wlan/prima/WCNSS_* \
		-t "$subpkgdir/$_fwdir"/wlan/prima
}

sha512sums="4b5d0250552ff3b0a55af9395e62064299a1240f22a5f50383de95723db964351412fa2b38f24fe73fdeb613366e0eb6b3c335600c238546db783ca84647e2d2  linux-board-support-package-r1034.2.1.zip"
