From 6877d75e875aa272e7544d406163e5adc9f255ae Mon Sep 17 00:00:00 2001 From: Scott Jones Date: Mon, 14 Sep 2026 21:57:39 -0400 Subject: [PATCH] Package Apple Video Decoder firmware and the VA-API driver --- pkgbuilds/avd-fw/.omarchy/package.json | 9 +++ pkgbuilds/avd-fw/PKGBUILD | 51 +++++++++++++++++ .../.omarchy/package.json | 12 ++++ pkgbuilds/libva-v4l2_request-avd/PKGBUILD | 55 +++++++++++++++++++ .../libva-v4l2_request-avd.install | 21 +++++++ 5 files changed, 148 insertions(+) create mode 100644 pkgbuilds/avd-fw/.omarchy/package.json create mode 100644 pkgbuilds/avd-fw/PKGBUILD create mode 100644 pkgbuilds/libva-v4l2_request-avd/.omarchy/package.json create mode 100644 pkgbuilds/libva-v4l2_request-avd/PKGBUILD create mode 100644 pkgbuilds/libva-v4l2_request-avd/libva-v4l2_request-avd.install diff --git a/pkgbuilds/avd-fw/.omarchy/package.json b/pkgbuilds/avd-fw/.omarchy/package.json new file mode 100644 index 0000000..2d609e6 --- /dev/null +++ b/pkgbuilds/avd-fw/.omarchy/package.json @@ -0,0 +1,9 @@ +{ + "source": "local", + "upstream": { + "watch": { + "pattern": "v(?P[0-9]+(?:\\.[0-9]+)*)", + "git_tags": "https://github.com/AsahiLinux/avd-fw.git" + } + } +} diff --git a/pkgbuilds/avd-fw/PKGBUILD b/pkgbuilds/avd-fw/PKGBUILD new file mode 100644 index 0000000..b24e65e --- /dev/null +++ b/pkgbuilds/avd-fw/PKGBUILD @@ -0,0 +1,51 @@ +# Open replacement firmware for the Apple Video Decoder. +# Built from AsahiLinux sources, without extracting proprietary firmware. + +pkgname=avd-fw +pkgver=0.1 +pkgrel=1 +pkgdesc='Open replacement firmware for the Apple Video Decoder (AVD) on Apple Silicon' +# The images are raw Cortex-M3 firmware, identical whatever host builds them, +# so this is an 'any' package (as linux-firmware is) rather than an aarch64 one. +arch=('any') +url='https://github.com/AsahiLinux/avd-fw' +license=('MIT') +# clang cross-compiles to arm-none-eabi out of the box, so no arm-none-eabi +# toolchain is required; llvm supplies llvm-objcopy, which meson.build looks +# up by name to turn each linked ELF into a padded raw image. +makedepends=('meson' 'clang' 'llvm') +# !buildflags is load-bearing: makepkg's CFLAGS/LDFLAGS target the aarch64 host +# and would be injected into a bare-metal Cortex-M3 build. !strip keeps makepkg +# from running the host strip over raw firmware images. +options=('!strip' '!debug' '!buildflags' '!lto') +source=("$pkgname-$pkgver.tar.gz::$url/archive/refs/tags/v$pkgver.tar.gz") +sha256sums=('2e131244275cb15c94243e41eec8a2a665ec895cfe3a818181549db991e62c67') + +build() { + # The cross file selects clang, pins the host machine to cortex-m3 and sets + # libdir=lib, which lands the images in /usr/lib/firmware/apple. + # + # Optimization is pinned to match upstream's Makefile (-O2). Meson's default + # buildtype is "debug" (-O0 -g), which would ship unoptimized firmware; the + # MMIO accessors in src/util.c go through a volatile typedef, so -O2 cannot + # elide register reads or writes. + meson setup \ + --cross-file "$pkgname-$pkgver/llvm.ini" \ + --prefix=/usr \ + -Doptimization=2 \ + -Ddebug=false \ + "$pkgname-$pkgver" build + + meson compile -C build +} + +package() { + meson install -C build --destdir "$pkgdir" + + # meson installs custom_target outputs 0755; these are firmware blobs, not + # programs, and every other firmware file on the system is 0644. + chmod 644 "$pkgdir"/usr/lib/firmware/apple/*.bin + + install -Dm644 "$pkgname-$pkgver/LICENSE" \ + "$pkgdir/usr/share/licenses/$pkgname/LICENSE" +} diff --git a/pkgbuilds/libva-v4l2_request-avd/.omarchy/package.json b/pkgbuilds/libva-v4l2_request-avd/.omarchy/package.json new file mode 100644 index 0000000..5dc4867 --- /dev/null +++ b/pkgbuilds/libva-v4l2_request-avd/.omarchy/package.json @@ -0,0 +1,12 @@ +{ + "source": "local", + "upstream": { + "watch": { + "git_tags": "https://github.com/sofus13/libva-v4l2_request.git", + "pattern": "(?P[0-9]+(?:\\.[0-9]+)*)" + } + }, + "rebuild_on": [ + "libva" + ] +} diff --git a/pkgbuilds/libva-v4l2_request-avd/PKGBUILD b/pkgbuilds/libva-v4l2_request-avd/PKGBUILD new file mode 100644 index 0000000..255f542 --- /dev/null +++ b/pkgbuilds/libva-v4l2_request-avd/PKGBUILD @@ -0,0 +1,55 @@ +# VA-API driver with Apple Video Decoder fixes from the sofus13 fork. +# The asahi alias lets libva discover it on Apple Silicon. + +_fork=sofus13 +pkgname=libva-v4l2_request-avd +pkgver=1.3 +pkgrel=1 +pkgdesc='VA-API driver for V4L2 stateless decoders, with Apple Video Decoder (AVD) support' +arch=('aarch64') +url="https://github.com/$_fork/libva-v4l2_request" +license=('GPL-3.0-or-later') +# The driver is a dlopen()ed plugin: it links only libc and exports the VA +# backend entry point (__vaDriverInit_1_24), so libva is a runtime rather than +# a link-time dependency -- and that symbol is versioned, so this needs a +# rebuild whenever libva's driver ABI is bumped. libdrm is only used for +# drm_fourcc.h constants at compile time. +depends=('glibc' 'libva') +makedepends=('meson' 'libdrm') +provides=('libva-v4l2_request') +conflicts=('libva-v4l2_request') +install="$pkgname.install" +source=("$pkgname-$pkgver.tar.gz::$url/archive/refs/tags/$pkgver.tar.gz") +sha256sums=('3670a1712f9f0a5a61bd44a781eba81dd9b2e0fd8271417ca8a9fbbed9dccfe9') + +build() { + # driverdir is left unset so meson takes it from libva's pkg-config + # (/usr/lib/dri); the codec set is decided by configure-time checks against + # the kernel uapi headers, so linux-api-headers governs what gets built in. + # Plain meson rather than arch-meson: the latter lives in devtools, which is + # not a safe assumption outside a clean chroot. buildtype=plain hands the + # compiler makepkg's own CFLAGS/LDFLAGS, which is what arch-meson does too. + meson setup \ + --prefix=/usr \ + --buildtype=plain \ + --wrap-mode=nodownload \ + "libva-v4l2_request-$pkgver" build + meson compile -C build +} + +package() { + meson install -C build --destdir "$pkgdir" + + # libva picks its driver from the DRM driver name of the render node, which + # on Apple Silicon is "asahi", so it looks for asahi_drv_video.so. Nothing + # else ships that name (mesa provides no VA driver for asahi), so aliasing it + # here makes every VA-API application find the decoder with no environment + # variable at all. If mesa ever ships its own asahi_drv_video.so this will + # collide and pacman will say so at install time. + ln -sf v4l2_request_drv_video.so "$pkgdir/usr/lib/dri/asahi_drv_video.so" + + install -Dm644 "libva-v4l2_request-$pkgver/COPYING" \ + "$pkgdir/usr/share/licenses/$pkgname/COPYING" + install -Dm644 "libva-v4l2_request-$pkgver/README" \ + "$pkgdir/usr/share/doc/$pkgname/README" +} diff --git a/pkgbuilds/libva-v4l2_request-avd/libva-v4l2_request-avd.install b/pkgbuilds/libva-v4l2_request-avd/libva-v4l2_request-avd.install new file mode 100644 index 0000000..e56488b --- /dev/null +++ b/pkgbuilds/libva-v4l2_request-avd/libva-v4l2_request-avd.install @@ -0,0 +1,21 @@ +post_install() { + cat <<'MSG' +==> This package installs itself as asahi_drv_video.so as well, which is the + name libva looks for on Apple Silicon, so VA-API applications should pick + the decoder up with no configuration. + + If something does not, select it explicitly for the session: + + LIBVA_DRIVER_NAME=v4l2_request + +==> Check with: vainfo +==> mpv: mpv --hwdec=vaapi video.mp4 +==> Firefox: additionally needs MOZ_DISABLE_RDD_SANDBOX=1, because the RDD + sandbox blocks the /dev/video* and /dev/media* access this + driver requires. That weakens Firefox's media sandbox. +MSG +} + +post_upgrade() { + post_install +}