maintainer="Luca Weiss <luca@lucaweiss.eu>"
pkgname=firmware-fairphone-fp3
pkgver=20210805
_commit="ee529820bb874ab1b52873f0b144c3786f01ee4c"
pkgrel=3
pkgdesc="Firmware for Fairphone 3"
url="https://github.com/FairBlobs/FP3-firmware"
arch="aarch64"
license="proprietary"
makedepends="pil-squasher"
subpackages="
	$pkgname-adreno
	$pkgname-adsp
	$pkgname-audio
	$pkgname-modem
	$pkgname-venus
	$pkgname-wcnss
	"
options="!check !strip !archcheck !tracedeps pmb:cross-native"
source="https://github.com/FairBlobs/FP3-firmware/archive/$_commit/FP3-firmware-$_commit.tar.gz"
builddir="$srcdir/FP3-firmware-$_commit"

build() {
	for i in *.mdt; do
		pil-squasher "$(basename "$i" .mdt)".mbn "$i"
	done
}

package() {
	mkdir -p "$pkgdir"
}

adreno() {
	pkgdesc="Fairphone 3 firmware for GPU"

	install -Dm644 "$builddir"/a506_zap.mbn -t \
		"$subpkgdir/lib/firmware/qcom/msm8953/fairphone/fp3"
}

adsp() {
	pkgdesc="Fairphone 3 firmware for the ADSP"

	install -Dm644 "$builddir"/adsp.mbn -t \
		"$subpkgdir/lib/firmware/qcom/msm8953/fairphone/fp3"
}

audio() {
	pkgdesc="Fairphone 3 firmware for the audio amplifier"

	# TODO: More generic path
	install -Dm644 "$builddir"/aw8898_cfg.bin -t \
		"$subpkgdir/lib/firmware/postmarketos"
}

modem() {
	pkgdesc="Fairphone 3 firmware for the modem"

	install -Dm644 "$builddir"/mba.mbn -t \
		"$subpkgdir/lib/firmware/qcom/msm8953/fairphone/fp3"
	install -Dm644 "$builddir"/modem.mbn -t \
		"$subpkgdir/lib/firmware/qcom/msm8953/fairphone/fp3"
}

venus() {
	pkgdesc="Fairphone 3 firmware for venus"

	install -Dm644 "$builddir"/venus.mbn -t \
		"$subpkgdir/lib/firmware/qcom/msm8953/fairphone/fp3"
}

wcnss() {
	pkgdesc="Fairphone 3 firmware for the Qualcomm Wireless Connectivity Subsystem (WCNSS)"

	install -Dm644 "$builddir"/wcnss.mbn -t \
		"$subpkgdir/lib/firmware/qcom/msm8953/fairphone/fp3"
	install -Dm644 "$builddir"/wlan/prima/WCNSS_qcom_wlan_nv.bin -t \
		"$subpkgdir/lib/firmware/qcom/msm8953/fairphone/fp3"
}

sha512sums="
efa827787814ff4a59a0a61ca66410e46ce0add29b1451b4962b2d8af1d52b7035a0550b188fd442358702252964e4b64b16f836c5dcb1f748102cd0550aff7b  FP3-firmware-ee529820bb874ab1b52873f0b144c3786f01ee4c.tar.gz
"
