pkgname=firmware-fairphone-fp4
pkgver=20230215
pkgrel=1
pkgdesc="Firmware for Fairphone 4"
subpackages="
	$pkgname-adreno
	$pkgname-adsp
	$pkgname-bluetooth
	$pkgname-cdsp
	$pkgname-ipa
	$pkgname-modem
	$pkgname-venus
	$pkgname-wlan
	"
url="https://github.com/FairBlobs/FP4-firmware"
arch="aarch64"
license="proprietary"
options="!check !strip !archcheck !tracedeps pmb:cross-native"
_commit="7b95dc9cabee71fd2444cf1c99216bbc0421c111"
source="https://github.com/FairBlobs/FP4-firmware/archive/$_commit/FP4-firmware-$_commit.tar.gz"
builddir="$srcdir/FP4-firmware-$_commit"

package() {
	# parent package is empty
	mkdir -p "$pkgdir"
}

adreno() {
	pkgdesc="Fairphone 4 adreno firmware"

	install -Dm644 "$builddir"/a6* -t \
		"$subpkgdir/lib/firmware/qcom/"
}

adsp() {
	pkgdesc="Fairphone 4 adsp firmware"

	install -Dm644 "$builddir"/adsp* -t \
		"$subpkgdir/lib/firmware/qcom/sm7225/fairphone4/"
}

bluetooth() {
	pkgdesc="Fairphone 4 bluetooth firmware"

	install -Dm644 "$builddir"/apbtfw11.tlv -t \
		"$subpkgdir/lib/firmware/qca/"
	install -Dm644 "$builddir"/apnv11.bin -t \
		"$subpkgdir/lib/firmware/qca/"
}

cdsp() {
	pkgdesc="Fairphone 4 cdsp firmware"

	install -Dm644 "$builddir"/cdsp* -t \
		"$subpkgdir/lib/firmware/qcom/sm7225/fairphone4/"
}

ipa() {
	pkgdesc="Fairphone 4 ipa firmware"

	cd "$builddir"
	for i in lagoon_ipa_fws.*; do
		install -Dm644 $i \
			"$subpkgdir/lib/firmware/qcom/sm7225/fairphone4/${i/lagoon_/}"
	done
}

modem() {
	pkgdesc="Fairphone 4 modem firmware"

	# cp because of the modem_pr directory
	mkdir -p "$subpkgdir/lib/firmware/qcom/sm7225/fairphone4/"
	cp -r "$builddir"/modem* \
		"$subpkgdir/lib/firmware/qcom/sm7225/fairphone4/"
	find "$subpkgdir/lib/firmware/qcom/sm7225/fairphone4/" \
		-type f -exec chmod 0644 {} \;
}

venus() {
	pkgdesc="Fairphone 4 venus firmware"

	install -Dm644 "$builddir"/venus.* -t \
		"$subpkgdir/lib/firmware/qcom/sm7225/fairphone4/"
}

wlan() {
	pkgdesc="Fairphone 4 wlan firmware"

	install -Dm644 "$builddir"/wlanmdsp.mbn -t \
		"$subpkgdir/lib/firmware/qcom/sm7225/fairphone4/"
}

sha512sums="
5e64b2146250227ab70d605c586c516c2337d5a1f23db539603ac6709be6683cb09677caf7ee4880e9cc5ec9f3b5f6cc0b2e88184b1ebe859d0166353a3d1ae3  FP4-firmware-7b95dc9cabee71fd2444cf1c99216bbc0421c111.tar.gz
"
