diff --git a/install/hardware/all.sh b/install/hardware/all.sh index 5f6b67c84f57..9463d42e5b5a 100644 --- a/install/hardware/all.sh +++ b/install/hardware/all.sh @@ -73,6 +73,7 @@ run_logged "$OMARCHY_INSTALL/hardware/lenovo/fix-yoga-pro7-bass-speakers.sh" run_logged "$OMARCHY_INSTALL/hardware/lenovo/yoga-slim7x.sh" run_logged "$OMARCHY_INSTALL/hardware/lenovo/thinkpad-t14s-camera.sh" run_logged "$OMARCHY_INSTALL/hardware/microsoft/surface-pro-11.sh" +run_logged "$OMARCHY_INSTALL/hardware/microsoft/surface-laptop-7.sh" run_logged "$OMARCHY_INSTALL/hardware/microsoft/surface-laptop8.sh" run_logged "$OMARCHY_INSTALL/hardware/fix-bcm43xx.sh" diff --git a/install/hardware/microsoft/surface-laptop-7.sh b/install/hardware/microsoft/surface-laptop-7.sh new file mode 100644 index 000000000000..84cc9308996a --- /dev/null +++ b/install/hardware/microsoft/surface-laptop-7.sh @@ -0,0 +1,48 @@ +# Microsoft Surface Laptop 7 15" (Snapdragon X Elite) board-specific setup. +# The 13.8" model runs another device tree and has not been tested. + +mkinitcpio_dir=${OMARCHY_SURFACE_LAPTOP7_MKINITCPIO_DIR:-/etc/mkinitcpio.conf.d} + +if omarchy-hw-aarch64-qualcomm && omarchy-hw-match-device-tree microsoft,romulus15; then + echo "Detected Microsoft Surface Laptop 7 15\", applying board-specific support..." + + # Bring up the panel and the keyboard before disk unlock. Without this the + # unlock prompt is black and takes no keys from the built-in keyboard. As in + # qualcomm/initramfs.sh, the ? skips a module a kernel does not have, so its + # image still builds. + # - The display driver waits for the USB-C DisplayPort chain, so that loads + # early too, with the IPC router and PD mapper pmic_glink needs. + # - The panel is a generic eDP one lit by a PWM backlight, whose PWM comes + # from the PMIC's LPG block. + # - The keyboard is a HID device behind the Surface Aggregator Module. + mkdir -p "$mkinitcpio_dir" + cat >"$mkinitcpio_dir/surface-laptop-7-initramfs.conf" <<'CONF' +MODULES+=(msm? dispcc_x1e80100? gpucc_x1e80100? phy_qcom_edp? panel_edp? + pwm_bl? leds_qcom_lpg? phy_qcom_qmp_combo? ps883x? qrtr? qcom_pd_mapper? + pmic_glink? pmic_glink_altmode? surface_aggregator? + surface_aggregator_registry? surface_hid_core? surface_hid?) + +# The Adreno X1's microcode, requested once when the display driver loads +# early. The board-signed zap shader is included by qcom-firmware-extract. +# Search like the kernel does: each suffix in every directory, then the next. +for firmware in qcom/gen70500_sqe.fw qcom/gen70500_gmu.bin; do + for suffix in '' .zst .xz; do + for directory in "${OMARCHY_SURFACE_LAPTOP7_FIRMWARE_ROOT:-/usr/lib/firmware}/updates" \ + "${OMARCHY_SURFACE_LAPTOP7_FIRMWARE_ROOT:-/usr/lib/firmware}"; do + if [[ -f $directory/$firmware$suffix ]]; then + FILES+=("$directory/$firmware$suffix") + break 2 + fi + done + done +done +unset firmware directory suffix +CONF + + # microsoft-surface-snapdragon-addresses gives Wi-Fi and Bluetooth the + # laptop's own addresses: without it Wi-Fi takes a new placeholder address on + # every boot and Bluetooth has no controller. iptsd gives the touchpad + # two-finger scroll, pinch and two-finger tap, which the kernel alone, running + # the pad as a mouse, does not; pressing the pad stops registering as a click. + omarchy-pkg-add microsoft-surface-snapdragon-addresses iptsd +fi diff --git a/install/omarchy-other.packages b/install/omarchy-other.packages index 89a3d80d266b..a92c648a85e0 100644 --- a/install/omarchy-other.packages +++ b/install/omarchy-other.packages @@ -64,6 +64,9 @@ iptsd microsoft-surface-pro-11-sensors microsoft-surface-pro-11-support +# Surface Laptop 7 15" (Snapdragon) support packages; iptsd is listed above +microsoft-surface-snapdragon-addresses + # Surface Laptop 8 (Snapdragon) support packages microsoft-surface-laptop-8-support diff --git a/migrations/1794718518.sh b/migrations/1794718518.sh new file mode 100644 index 000000000000..caafdf54f3dc --- /dev/null +++ b/migrations/1794718518.sh @@ -0,0 +1,33 @@ +echo "Set up the Surface Laptop 7 15\" on installs made before its board setup" + +# See install/hardware/microsoft/surface-laptop-7.sh. It loads the panel and +# keyboard drivers early and installs microsoft-surface-snapdragon-addresses +# and iptsd, then the boot image is rebuilt to pick up the drivers. Rerunning +# the setup rewrites the same file and skips what is installed. +rebuild_marker=/var/lib/omarchy/migrations/1794718518 + +if ! omarchy-hw-aarch64-qualcomm || ! omarchy-hw-match-device-tree microsoft,romulus15; then + exit 0 +fi + +sudo env PATH="$PATH" OMARCHY_PATH="$OMARCHY_PATH" bash -euo pipefail -c ' + source "$OMARCHY_PATH/install/hardware/microsoft/surface-laptop-7.sh" +' + +# A marker records the machine-wide rebuild: another user's run must not repeat +# it, while a missing marker still retries an interrupted rebuild. +if [[ ! -e $rebuild_marker ]]; then + rebuild_log=$(mktemp) + trap 'rm -f "$rebuild_log"' EXIT + sudo limine-mkinitcpio 2>&1 | tee "$rebuild_log" + + # limine-mkinitcpio reports a kernel it could not rebuild and still exits 0. + # That image lacks the early drivers, so the migration stays pending. + if grep -q 'mkinitcpio failed for kernel' "$rebuild_log"; then + echo "A boot image was not rebuilt. Fix the error above, then run omarchy-migrate again before rebooting." >&2 + exit 1 + fi + + sudo install -Dm644 /dev/null "$rebuild_marker" + omarchy-state set reboot-required +fi diff --git a/test/shell.d/surface-laptop-7-hardware-test.sh b/test/shell.d/surface-laptop-7-hardware-test.sh new file mode 100755 index 000000000000..b5b859b73ed0 --- /dev/null +++ b/test/shell.d/surface-laptop-7-hardware-test.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +set -euo pipefail + +source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" + +setup="$ROOT/install/hardware/microsoft/surface-laptop-7.sh" +scratch=$(mktemp -d) +trap 'rm -rf "$scratch"' EXIT + +bash -n "$setup" || fail "Surface Laptop 7 hardware script has valid syntax" + +require_platform_fixtures "the Surface Laptop 7 setup" + +run_setup() ( + set -eE + local dir=$1 + PATH="$ROOT/bin:$PATH" + omarchy-hw-aarch64-qualcomm() { return 0; } + omarchy-pkg-add() { printf 'add %s\n' "$*" >>"$dir/packages.log"; } + + OMARCHY_PROC_ROOT="$dir/proc" \ + OMARCHY_SURFACE_LAPTOP7_MKINITCPIO_DIR="$dir/mkinitcpio.conf.d" \ + source "$setup" +) + +compatible() { + mkdir -p "$1/proc/device-tree" + printf '%b' "$2" >"$1/proc/device-tree/compatible" +} + +matching="$scratch/matching" +compatible "$matching" 'microsoft,romulus15\0qcom,x1e80100\0' +run_setup "$matching" >/dev/null +[[ $(<"$matching/packages.log") == 'add microsoft-surface-snapdragon-addresses iptsd' ]] || + fail "Surface Laptop 7 15\" setup adds its Wi-Fi and Bluetooth addresses and iptsd" + +( + firmware_root="$scratch/firmware" + mkdir -p "$firmware_root/qcom" "$firmware_root/updates/qcom" + touch "$firmware_root/qcom/gen70500_sqe.fw.zst" "$firmware_root/updates/qcom/gen70500_sqe.fw" + MODULES=() FILES=() + OMARCHY_SURFACE_LAPTOP7_FIRMWARE_ROOT="$firmware_root" \ + source "$matching/mkinitcpio.conf.d/surface-laptop-7-initramfs.conf" + + for module in "${MODULES[@]}"; do + [[ $module == *\? ]] || fail "$module is optional, so a kernel without it still builds its image" + done + + for module in pwm_bl leds_qcom_lpg surface_aggregator surface_aggregator_registry surface_hid; do + [[ " ${MODULES[*]} " == *" $module? "* ]] || + fail "$module loads early, for the backlight and the keyboard at disk unlock" + done + + [[ ${FILES[*]} == "$firmware_root/updates/qcom/gen70500_sqe.fw" ]] || + fail "early firmware prefers extracted copies and skips what is missing" +) + +for other in 'microsoft,romulus13\0qcom,x1e80100\0' 'lenovo,yoga-slim7x\0qcom,x1e80100\0'; do + dir="$scratch/other-${other%%\\0*}" + compatible "$dir" "$other" + run_setup "$dir" >/dev/null + [[ ! -e $dir/packages.log && ! -e $dir/mkinitcpio.conf.d ]] || + fail "${other%%\\0*} is left alone" +done + +pass "Surface Laptop 7 setup configures only the 15\" model"