pkgname=firmware-xiaomi-wt88047
pkgver=9.2.5.0
pkgrel=0
pkgdesc="Firmware for Xiaomi Redmi 2"
url="https://androidfilehost.com/?w=files&flid=303434"
subpackages="$pkgname-modem $pkgname-wcnss-nv:wcnss_nv"
arch="aarch64"
license="proprietary"
options="!check !strip !archcheck !tracedeps pmb:cross-native"
makedepends="mtools"
source="
	wt88047-WCNSS_qcom_wlan_nv.bin.base64::https://pastebin.com/raw/bntm8Z7m
	https://archive.org/download/lineage-15.1-20200223-nightly-wt88047-signed_202004/wt88047-firmware_V9.2.5.0.LHJMIEK.zip
"

_fwdir="/lib/firmware/postmarketos"

unpack() {
	default_unpack
	base64 -d wt88047-WCNSS_qcom_wlan_nv.bin.base64 > WCNSS_qcom_wlan_nv.bin

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

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

modem() {
	pkgdesc="Xiaomi Redmi 2 (wt88047) modem firmware"
	install -Dm644 "$srcdir"/mba.mbn -t "$subpkgdir/$_fwdir"
	install -Dm644 "$srcdir"/modem.* -t "$subpkgdir/$_fwdir"
}

wcnss_nv() {
	pkgdesc="Xiaomi Redmi 2 WiFi/BT firmware configuration"
	install -Dm644 "$srcdir"/WCNSS_qcom_wlan_nv.bin -t "$subpkgdir/$_fwdir"/wlan/prima
}

sha512sums="cab8578bf8b20ff83035a10598ebb673619e5409683799a5d6d04496b7f4b4e0f54a635b29efe2007137adf089d24134339c69214fdfa06a9d2ff052c39b9e59  wt88047-WCNSS_qcom_wlan_nv.bin.base64
45b0926f1694dc2f71d26b1408922345e2340bb84a73597ea00bd5025e31f5bafcf910395a6b021686043e041b8f2cd4ca448e891341fe4eca7382b6ee5b2186  wt88047-firmware_V9.2.5.0.LHJMIEK.zip"
