From b6954d59e89fe3b3097be61def1b6c4ff9bda5fd Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Sun, 15 Jun 2025 23:01:13 -0400 Subject: [PATCH] device-pine64-pinenote: add waveform management initd Previously, waveform information was provided by maintainer. Since every device panel is slightly different, waveform information is actually available on the device in a specific partition (partlabel=waveform). We thus use the device waveform information instead of the less appropriate generic binary. We do this by having an initd script extract and prepare the binary from the partition using hrdl's scripts. The rockchip_ebc module expects both ebc.wbf and custom_wf.bin under /lib/firmware/rockchip. Thus, if those files are not detected, the initd runs the necessary operations, regenerates with mkinitfs, and reloads rockchip_ebc. gpio_rockchip is also added to modules-initfs as the kernel now compiles it as a module Part-of: https://gitlab.postmarketos.org/postmarketOS/pmaports/-/merge_requests/6667 [ci:skip-build]: already built successfully in CI --- .../30-eink-waveform.files | 2 + .../testing/device-pine64-pinenote/APKBUILD | 62 ++++++++++++++++--- ...enote-nonfree-firmware-openrc.post-install | 3 + ...enote-nonfree-firmware-openrc.post-upgrade | 1 + .../device-pine64-pinenote/modules-initfs | 1 + .../pinenote-init-waveform.initd | 34 ++++++++++ .../waveform-extract-use-lib.patch | 15 +++++ 7 files changed, 108 insertions(+), 10 deletions(-) create mode 100644 device/testing/device-pine64-pinenote/30-eink-waveform.files create mode 100644 device/testing/device-pine64-pinenote/device-pine64-pinenote-nonfree-firmware-openrc.post-install create mode 120000 device/testing/device-pine64-pinenote/device-pine64-pinenote-nonfree-firmware-openrc.post-upgrade create mode 100644 device/testing/device-pine64-pinenote/pinenote-init-waveform.initd create mode 100644 device/testing/device-pine64-pinenote/waveform-extract-use-lib.patch diff --git a/device/testing/device-pine64-pinenote/30-eink-waveform.files b/device/testing/device-pine64-pinenote/30-eink-waveform.files new file mode 100644 index 000000000..ea81da107 --- /dev/null +++ b/device/testing/device-pine64-pinenote/30-eink-waveform.files @@ -0,0 +1,2 @@ +/lib/firmware/rockchip/ebc.wbf +/lib/firmware/rockchip/custom_wf.bin diff --git a/device/testing/device-pine64-pinenote/APKBUILD b/device/testing/device-pine64-pinenote/APKBUILD index da8e59ae5..67ded4a03 100644 --- a/device/testing/device-pine64-pinenote/APKBUILD +++ b/device/testing/device-pine64-pinenote/APKBUILD @@ -1,34 +1,45 @@ # Maintainer: Antoine Martin (ayakael) pkgname=device-pine64-pinenote pkgdesc="Pine64 PineNote" -pkgver=3 +pkgver=4 pkgrel=0 +_commit="28d2c05ab4e80a7972611cd3188f3e8be4197f6a" url="https://postmarketos.org" -license="MIT" +license="GPL-3.0-only" arch="aarch64" options="!check !archcheck" depends=" linux-pine64-pinenote - pinenote-dbus-service<20221207 + pinenote-dbus-service postmarketos-base u-boot-pine64-pinenote " makedepends="devicepkg-dev" +# pinenote-dist repo provides some management scripts for pinenote and sway +# although for now we only source waveform scripts source=" + pinenote-dist-$_commit.tar.gz::https://git.sr.ht/~hrdl/pinenote-dist/archive/$_commit.tar.gz + waveform-extract-use-lib.patch + + deviceinfo + modules-initfs + + pinenote-init-waveform.initd + 30-eink-waveform.files 50-touchscreen.conf 81-libinput-pinenote.rules 82-ebc-rockchip.rules - deviceinfo local-overrides.quirks - modules-initfs panfrost.conf phoc.ini rockchip_ebc.conf " subpackages=" $pkgname-nonfree-firmware:nonfree_firmware + $pkgname-nonfree-firmware-openrc:nonfree_firmware_openrc $pkgname-phosh " +builddir="$srcdir"/pinenote-dist-$_commit build() { devicepkg_build $startdir $pkgname @@ -61,18 +72,49 @@ phosh() { nonfree_firmware() { pkgdesc="WiFi, Bluetooth and display firmware" - depends="firmware-pine64-pinenote linux-firmware" - mkdir "$subpkgdir" + depends="linux-firmware py3-numpy" + replaces="firmware-pine64-pinenote" + + # waveform firmware is provided locally via /dev/disk/by-label/waveform + # and then adapted to kernel using hrdl's script + # and initd script executes it at first boot of device + install -Dm644 "$srcdir"/30-eink-waveform.files \ + "$subpkgdir"/usr/share/mkinitfs/files/30-eink-waveform.files + install -Dm755 "$builddir"/bin/wbf_to_custom.py \ + -t "$subpkgdir"/usr/libexec/pinenote + install -Dm755 "$builddir"/bin/read_file.py \ + -t "$subpkgdir"/usr/libexec/pinenote + install -Dm755 "$builddir"/bin/waveform_extract.sh \ + -t "$subpkgdir"/usr/libexec/pinenote + + # create empty waveform firmware so that initial mkinitfs doesn't fail + mkdir -p "$subpkgdir"/lib/firmware/rockchip + touch "$subpkgdir"/lib/firmware/rockchip/ebc.wbf + touch "$subpkgdir"/lib/firmware/rockchip/custom_wf.bin } +nonfree_firmware_openrc() { + install_if="$pkgname-nonfree-firmware=$pkgver-r$pkgrel openrc" + install="$subpkgname.post-install $subpkgname.post-upgrade" + depends="openrc" + + install -Dm755 "$srcdir"/pinenote-init-waveform.initd \ + "$subpkgdir"/etc/init.d/pinenote-init-waveform +} + + sha512sums=" +4b6548a05dcdbe1ddda97dba58d625407fb553f90817e8e678b97e28603f64aab9a31fa18bda654c06638f3be21d7a6936786197f93f715e7d03a07e380873c5 pinenote-dist-28d2c05ab4e80a7972611cd3188f3e8be4197f6a.tar.gz +6dc70339d220a560e684e0a28679ab932455cc05d6fb83b9dadd696b54f7987f4ebaadeb8d6287ca3357cd20087e9e1294cd5e0147f9cfb2f74b7cb58a30f6e0 waveform-extract-use-lib.patch 5829b9b52206a7520066e4bb3c08c2535d98002a3940664a0239344f5e7522fe7b6a9cb0c0074f9846c7e42c40746f2991f6aeeefeba8efa9140c16630b2893e deviceinfo -473accb3497244742dd9fd15f8a02957a13e08fa4d4393fec185ecbb27f1f17726e4b5ece22da861151f9d358d3266206c647def8aa75adb672b6f1f1904c66f modules-initfs -4bf5158fbd53274a7429e825bb66225001f2403a4851e2d6803323b77d9095738ee3e5340ac85baf3e86bb4f47d38af8cbd78d8a5055c59a62f5b06e722e19cb phoc.ini -1123720962c9c8fec3c50302ca6a3dd56e2907dc9eea361a7b8eb4201b042476633d41a0ee4f6ab61d9c60eeccc894f83491ba9fa309a9bce2f1db0b0341d79d local-overrides.quirks +e0d3ac808e7a4f05df327a824e30dc54864908e31f4a643f6e85f054ab812eeb28fef647eb52ae85bfad7d40c9cd81c43c1cdc575de5dbc04304d74862d9772c modules-initfs +29710d80112f8797adf7e3dfd54771d8752d29cb265532e235fe406e380056ac846929568ddbe5110bbd74da337e2f8cd905e4092c14bc94aea07dc83f39aa6e pinenote-init-waveform.initd +8f7a5ad2f407de8c474d54dfdb9cc099c96e8918fc123f8b2a8ff911d7e1c7ca6fe30f9cea8ee2f0c1ba5f3e53359193d0683ca912f0b66e79a12814ce38dd98 30-eink-waveform.files ac433eebbc35a48561837495997aee4e55510b979bc0d8e3bafb761bc1be5b4bdeed2f456369dcbc582688aefd07c63966b0d72b6ffa99e84cfd868e677f02c8 50-touchscreen.conf 2bc51f200baefc37abfaaad368a911244999e906bdca4b728ac233f49a8fb3ae7206ee3c95cdb20d7dceae2a31d25a57f4e1da4fd67057fd64724b8232e42aed 81-libinput-pinenote.rules 19e922eec89dba419798c4e1dc9b39c040db33986d0969a39a8220c642fa081763f15ff2418115d5a748af4054a1be0784927d1712ea79942c2b237ebab47728 82-ebc-rockchip.rules +1123720962c9c8fec3c50302ca6a3dd56e2907dc9eea361a7b8eb4201b042476633d41a0ee4f6ab61d9c60eeccc894f83491ba9fa309a9bce2f1db0b0341d79d local-overrides.quirks 6ba6638754e00908243de2f73ed6898dac03638a200dcf7b7cd9684757355ee1eb0ac874af0f971ad2e054c1a8c471867bdaea4d9aaf7eea6d3cf81ac7dd73a2 panfrost.conf +4bf5158fbd53274a7429e825bb66225001f2403a4851e2d6803323b77d9095738ee3e5340ac85baf3e86bb4f47d38af8cbd78d8a5055c59a62f5b06e722e19cb phoc.ini b52d2e7f0c62d7c313b6db9aeb706cdb2596b6aa637aeddb862abf1e256103377fb6267e38cd4285e25d32112acf8d03bbf32ecff7be3dfbb9176209ea7ae283 rockchip_ebc.conf " diff --git a/device/testing/device-pine64-pinenote/device-pine64-pinenote-nonfree-firmware-openrc.post-install b/device/testing/device-pine64-pinenote/device-pine64-pinenote-nonfree-firmware-openrc.post-install new file mode 100644 index 000000000..ea28c9830 --- /dev/null +++ b/device/testing/device-pine64-pinenote/device-pine64-pinenote-nonfree-firmware-openrc.post-install @@ -0,0 +1,3 @@ +#!/bin/sh + +rc-update add pinenote-init-waveform boot diff --git a/device/testing/device-pine64-pinenote/device-pine64-pinenote-nonfree-firmware-openrc.post-upgrade b/device/testing/device-pine64-pinenote/device-pine64-pinenote-nonfree-firmware-openrc.post-upgrade new file mode 120000 index 000000000..40974131f --- /dev/null +++ b/device/testing/device-pine64-pinenote/device-pine64-pinenote-nonfree-firmware-openrc.post-upgrade @@ -0,0 +1 @@ +device-pine64-pinenote-nonfree-firmware-openrc.post-install \ No newline at end of file diff --git a/device/testing/device-pine64-pinenote/modules-initfs b/device/testing/device-pine64-pinenote/modules-initfs index 1b49e53d1..6e87d4147 100644 --- a/device/testing/device-pine64-pinenote/modules-initfs +++ b/device/testing/device-pine64-pinenote/modules-initfs @@ -1,3 +1,4 @@ +gpio_rockchip tps65185-regulator rockchip_ebc drm_kms_helper diff --git a/device/testing/device-pine64-pinenote/pinenote-init-waveform.initd b/device/testing/device-pine64-pinenote/pinenote-init-waveform.initd new file mode 100644 index 000000000..f7ffd4f52 --- /dev/null +++ b/device/testing/device-pine64-pinenote/pinenote-init-waveform.initd @@ -0,0 +1,34 @@ +#!/sbin/openrc-run + +name=$RC_SVCNAME +description="Sets up rockchip_ebc ebc.wbf waveform from waveform partition" +error_log=/var/log/pinenote/$RC_SVCNAME.log + +start() { + # Check for the file existence + if [ -s "/lib/firmware/rockchip/ebc.wbf" ] && [ -s "/lib/firmware/rockchip/custom_wf.bin" ]; then + einfo "No need to init waveform" + unset -f start + return 0 + fi + + ebegin "Extracting waveform" + cd /tmp + /usr/libexec/pinenote/waveform_extract.sh 2>&1 | tee -a "$error_log" + /usr/libexec/pinenote/wbf_to_custom.py /lib/firmware/rockchip/ebc.wbf 2>&1 | tee -a "$error_log" + mv custom_wf.bin /lib/firmware/rockchip/. + + einfo "Regenerating initramfs" + /usr/sbin/mkinitfs 2>&1 | tee -a "$error_log" + + einfo "Reloading rockchip_ebc" + modprobe -r rockchip_ebc + modprobe rockchip_ebc + eend $? +} + +start_pre() { + checkpath --directory --owner root:root --mode 0775 \ + /lib/firmware/rockchip \ + /var/log/pinenote +} diff --git a/device/testing/device-pine64-pinenote/waveform-extract-use-lib.patch b/device/testing/device-pine64-pinenote/waveform-extract-use-lib.patch new file mode 100644 index 000000000..a9b84b5ce --- /dev/null +++ b/device/testing/device-pine64-pinenote/waveform-extract-use-lib.patch @@ -0,0 +1,15 @@ +diff --git a/bin/waveform_extract.sh.orig b/bin/waveform_extract.sh +index e00be1c4ad..8e97749555 100755 +--- a/bin/waveform_extract.sh.orig ++++ b/bin/waveform_extract.sh +@@ -3,8 +3,8 @@ + set -e + + IN=/dev/disk/by-partlabel/waveform +-OUT=/usr/lib/firmware/rockchip/ebc.wbf ++OUT=/lib/firmware/rockchip/ebc.wbf + +-mkdir -p /usr/lib/firmware/rockchip ++mkdir -p /lib/firmware/rockchip + size=$(hexdump --skip 4 --length 4 "${IN}" --format '"%u"') + head -c "${size}" "${IN}" > "${OUT}"