maintainer="Jianhua Lu <lujianhua000@gmail.com>"
pkgname=firmware-xiaomi-elish
pkgver=20240917
pkgrel=3
pkgdesc="Firmware for Xiaomi Mi Pad 5 Pro"
subpackages="
	$pkgname-adreno
	$pkgname-adsp
	$pkgname-cdsp
	$pkgname-cirrus
	$pkgname-hexagonfs
	$pkgname-initramfs
	$pkgname-slpi
	$pkgname-touchscreen
	$pkgname-venus
	"
url="https://github.com/lujianhua/xiaomi-elish-firmware"
arch="aarch64"
license="proprietary"
options="!check !strip !archcheck !tracedeps pmb:cross-native"
_commit="51e9ac8cd91d88de43fb016530b9421a2713467a"
source="
	https://github.com/lujianhua/xiaomi-elish-firmware/archive/$_commit/xiaomi-elish-firmware-$_commit.tar.gz
	30-dsp-firmware.files
"
builddir="$srcdir/xiaomi-elish-firmware-$_commit"

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

# Xiaomi elish boots with secure boot, it can only load signed firmwares.
adreno() {
	pkgdesc="Xiaomi elish adreno firmware"
	depends="firmware-qcom-adreno-a650"

	install -Dm644 "$builddir"/sm8250/a650_zap.mbn -t \
		"$subpkgdir/usr/lib/firmware/qcom/sm8250/xiaomi/elish/"
}

adsp() {
	pkgdesc="Xiaomi elish adsp firmware"

	install -Dm644 "$builddir"/sm8250/adsp* -t \
		"$subpkgdir/usr/lib/firmware/qcom/sm8250/xiaomi/elish/"
}

cdsp() {
	pkgdesc="Xiaomi elish cdsp firmware"

	install -Dm644 "$builddir"/sm8250/cdsp* -t \
		"$subpkgdir/usr/lib/firmware/qcom/sm8250/xiaomi/elish/"
}

cirrus() {
	pkgdesc="Xiaomi elish cirrus firmware"

	install -Dm644 "$builddir"/cirrus/cs35l41* -t \
		"$subpkgdir/usr/lib/firmware/cirrus/"
}

hexagonfs() {
	pkgdesc="Xiaomi elish hexagonfs files"

	mkdir -p "$subpkgdir"/usr/share/qcom/sm8250/Xiaomi
	cp -r "$builddir"/hexagonfs/ \
		"$subpkgdir"/usr/share/qcom/sm8250/Xiaomi/elish

	# Remove files that we don't need - for now
	rm -r "$subpkgdir"/usr/share/qcom/sm8250/Xiaomi/elish/acdb/
	rm -r "$subpkgdir"/usr/share/qcom/sm8250/Xiaomi/elish/dsp/
}

initramfs() {
	pkgdesc="Xiaomi elish firmware to be included in the initramfs"

	install -Dm644 "$srcdir/30-dsp-firmware.files" \
		"$subpkgdir/usr/share/mkinitfs/files/30-dsp-firmware.files"
}

slpi() {
	pkgdesc="Xiaomi elish slpi firmware"

	install -Dm644 "$builddir"/sm8250/slpi* -t \
		"$subpkgdir/usr/lib/firmware/qcom/sm8250/xiaomi/elish/"
}

touchscreen() {
	pkgdesc="Xiaomi elish touchscreen firmware"

	install -Dm644 "$builddir"/novatek/nt36523* -t \
		"$subpkgdir/usr/lib/firmware/novatek/"
}

venus() {
	pkgdesc="Xiaomi elish venus firmware"

	install -Dm644 "$builddir"/sm8250/venus.mbn -t \
		"$subpkgdir/usr/lib/firmware/qcom/sm8250/xiaomi/elish/"
}

sha512sums="
c1ebaf280313a00a64c9bc9ebf820574f0bffe26cdf0652a9897068d46e251ae03853e684bf7b26591d557d218c56eb10c36e50358778bcffb36caea948466b5  xiaomi-elish-firmware-51e9ac8cd91d88de43fb016530b9421a2713467a.tar.gz
498ca1e76de8a7cb6d7141b8537fe9cb32e7dae8ccb4d68b9e0e92863f5ac03b6f0cde1fe71f8d9e0248f3ffcf4e0d1fbaf027e6c7d6df2ad78786173594433e  30-dsp-firmware.files
"
