# Reference: <https://postmarketos.org/devicepkg>
maintainer="Hugo Osvaldo Barrera <hugo@whynothugo.nl>"
pkgname=device-pine64-pinebookpro
pkgdesc="PINE64 Pinebook Pro"
pkgver=23
pkgrel=0
url="https://postmarketos.org"
license="MIT"
arch="aarch64"
options="!check !archcheck"
depends="
	alsa-ucm-conf>=1.2.7
	iw
	linux-firmware-brcm
	linux-firmware-rockchip
	linux-postmarketos-rockchip>=5.14
	nvme-cli
	postmarketos-base>=25-r1
	soc-rockchip-rk3399
	u-boot-pinebookpro
	"
makedepends="devicepkg-dev"
install="
	$pkgname-elogind.post-install
	$pkgname-elogind.post-upgrade
	$pkgname-openrc.post-install
	$pkgname-openrc.post-upgrade
	"
subpackages="
	$pkgname-elogind
	$pkgname-openrc
	"
replaces="device-pine64-pinebookpro-nonfree-firmware"
source="
	deviceinfo
	kernel-cmdline.conf
	modules-initfs
	nvme-powersave.initd
	wlan-powersave-off.initd
	enable-s2idle.conf
"

build() {
	devicepkg_build $startdir $pkgname
}

package() {
	devicepkg_package $startdir $pkgname

	install -D -m755 "$srcdir"/nvme-powersave.initd \
		"$pkgdir"/etc/init.d/nvme-powersave

	install -D -m755 "$srcdir"/wlan-powersave-off.initd \
		"$pkgdir"/etc/init.d/wlan-powersave-off

	# Workaround for kernel load brcm43455 firmware bug
	# details: https://gitlab.postmarketos.org/postmarketOS/pmaports/-/issues/4285
	mkdir -p "$pkgdir"/usr/lib/firmware/brcm
	ln -s brcmfmac43455-sdio.AW-CM256SM.txt.zst \
		"$pkgdir"/usr/lib/firmware/brcm/brcmfmac43456-sdio.pine64,pinebook-pro.txt.zst
}

elogind() {
	install_if="$pkgname=$pkgver-r$pkgrel elogind"
	install -D -m644 "$srcdir"/enable-s2idle.conf \
		"$subpkgdir"/usr/lib/elogind/sleep.conf.d/enable-s2idle.conf
}

openrc() {
	default_openrc
	depends="eudev-hwids openrc"
}

sha512sums="
1d35423407898d56f23520ee41e37191257cc5ecad7c62d990f143dbd7a5c410f4826706c868f86c734c285e25c0e8d0b161422e1529533608fc07953c436691  deviceinfo
84df486ec8fb3c5a0c032fe42e210a6fbfa9c5a1a8cdf548fb70bb023815dc625a08ded0fc6e2ea9f6aad28d2b7a3bf40659c3d417bbbce9ee67d8d225210be6  kernel-cmdline.conf
c162d99b77e6e8a22aa2991d99a330f488af7707e3bbf0c96efd98a4d99a022bf2703fb991a590a5bea79adc7c90d6a455666cb1dfe9144cb467ded53fc38b4c  modules-initfs
2abfa31fa56028339efc6d2b6cb838f310990d7110ac4dd996bc4cfcf90f0a8770e70f28f77f7b6929d110e494bc33731302f16b9717729f991c2732be0731d5  nvme-powersave.initd
2d40d75d47bf42b37b4f99abba43a2c7dbdbe7e722f7e323be5c5781f5ca938bc4681ba0d303c1e68ce301a93f1c2f38a1b2670dd401ec0c1fe6ce226ccf5f00  wlan-powersave-off.initd
811af9c79151f41e25916c0f0bb130e82ebfb7d4d5b63413a3fed6700f829c1c017a12e85da230ed2f47a6bd49ed2bf5da19bbc4576ce485a48a2d3808a3a691  enable-s2idle.conf
"
