Repository navigation
Force SPI PIO on MacBook8,1 so the built-in keyboard works #9735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jeissonneira
wants to merge
5
commits into
omacom:quattro
Choose a base branch
from
jeissonneira:fix/macbook81-spi-pio
base: quattro
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+66
−1
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
abba2c4
Force SPI PIO on MacBook8,1 so the built-in keyboard works
jeissonneira adf055d
Keep the MacBook8,1 migration pending when a kernel is not rebuilt
omarchybot 98386bd
Merge quattro into fix/macbook81-spi-pio
omarchybot cd66d1d
Expect the MacBook8,1 PIO drop-in in the hardware quirks table
omarchybot 1c3be3c
Drop the MacBook8,1 test file in favour of the hardware quirks table
omarchybot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| echo "Force SPI PIO on MacBook8,1 so the built-in keyboard works" | ||
|
|
||
| # The install-time leaf already loads applespi for this model, but that is not | ||
| # enough: DesignWare DMA on 00:15.0 never completes GSPI transfers, so the | ||
| # keyboard and trackpad time out until the controller is forced into PIO. | ||
| # See install/hardware/apple/fix-spi-keyboard.sh. | ||
| product="${OMARCHY_MACBOOK81_DMI_PRODUCT:-/sys/class/dmi/id/product_name}" | ||
| limine_conf="${OMARCHY_MACBOOK81_LIMINE_CONF:-/etc/limine-entry-tool.d/macbook81-spi-pio.conf}" | ||
| repair_marker="${OMARCHY_MACBOOK81_REPAIR_MARKER:-/var/lib/omarchy/migrations/1788318101}" | ||
| running_cmdline="${OMARCHY_MACBOOK81_RUNNING_CMDLINE:-/proc/cmdline}" | ||
|
|
||
| product_name="$(cat "$product" 2>/dev/null || true)" | ||
| if [[ $product_name != "MacBook8,1" ]]; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| needs_limine_rebuild=0 | ||
|
|
||
| if [[ ! -f $limine_conf ]] || ! grep -q 'initcall_blacklist=dw_pci_driver_init' "$limine_conf"; then | ||
| sudo mkdir -p "$(dirname "$limine_conf")" | ||
| sudo tee "$limine_conf" >/dev/null <<'EOF' | ||
| # MacBook8,1: DesignWare DMA never completes GSPI transfers. | ||
| KERNEL_CMDLINE[default]+=" initcall_blacklist=dw_pci_driver_init mem_sleep_default=s2idle" | ||
| EOF | ||
| needs_limine_rebuild=1 | ||
| fi | ||
|
|
||
| # The current kernel keeps its old command line until reboot. Record a | ||
| # successful machine-wide rebuild so another user's migration does not repeat | ||
| # it before then, while a missing marker still retries an interrupted rebuild. | ||
| if [[ -f $limine_conf ]] && | ||
| [[ ! -e $repair_marker ]] && | ||
| grep -q 'initcall_blacklist=dw_pci_driver_init' "$limine_conf" && | ||
| { [[ ! -r $running_cmdline ]] || | ||
| ! grep -Eq '(^| )initcall_blacklist=dw_pci_driver_init( |$)' "$running_cmdline"; }; then | ||
| needs_limine_rebuild=1 | ||
| fi | ||
|
|
||
| if (( needs_limine_rebuild )); 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. | ||
| # Without the marker, this migration stays pending and retries. | ||
| if grep -q 'mkinitcpio failed for kernel' "$rebuild_log"; then | ||
| echo "Could not rebuild the boot image; this migration stays pending." >&2 | ||
| exit 1 | ||
| fi | ||
| sudo install -Dm644 /dev/null "$repair_marker" | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" | ||
|
|
||
| leaf="$ROOT/install/hardware/apple/fix-spi-keyboard.sh" | ||
| all="$ROOT/install/hardware/all.sh" | ||
| migration="$ROOT/migrations/1788318101.sh" | ||
|
|
||
| grep -q 'apple/fix-spi-keyboard.sh' "$all" || | ||
| fail "the SPI keyboard leaf runs during hardware setup" | ||
| grep -q 'initcall_blacklist=dw_pci_driver_init' "$leaf" || | ||
| fail "MacBook8,1 setup forces SPI PIO" | ||
| grep -q 'mem_sleep_default=s2idle' "$leaf" || | ||
| fail "MacBook8,1 setup defaults sleep to s2idle" | ||
| pass "MacBook8,1 SPI PIO is part of hardware setup" | ||
|
|
||
| test_tmp=$(mktemp -d) | ||
| trap 'rm -rf "$test_tmp"' EXIT | ||
|
|
||
| stub_bin="$test_tmp/bin" | ||
| calls="$test_tmp/calls.log" | ||
| mkdir -p "$stub_bin" "$test_tmp/dmi" | ||
| : >"$calls" | ||
|
|
||
| cat >"$stub_bin/omarchy-pkg-add" <<'SH' | ||
| #!/bin/bash | ||
|
|
||
| printf 'omarchy-pkg-add' >>"$TEST_LOG" | ||
| printf '\t%s' "$@" >>"$TEST_LOG" | ||
| printf '\n' >>"$TEST_LOG" | ||
| SH | ||
|
|
||
| cat >"$stub_bin/sudo" <<'SH' | ||
| #!/bin/bash | ||
|
|
||
| printf 'sudo' >>"$TEST_LOG" | ||
| printf '\t%s' "$@" >>"$TEST_LOG" | ||
| printf '\n' >>"$TEST_LOG" | ||
| "$@" | ||
| SH | ||
|
|
||
| cat >"$stub_bin/limine-mkinitcpio" <<'SH' | ||
| #!/bin/bash | ||
|
|
||
| echo 'limine-mkinitcpio' >>"$TEST_LOG" | ||
| [[ -z ${REBUILD_FAILS:-} ]] || echo "==> ERROR: mkinitcpio failed for kernel linux-omarchy, skipping." | ||
| SH | ||
|
|
||
| chmod +x "$stub_bin"/* | ||
|
|
||
| run_leaf() { | ||
| local product="$1" | ||
| rm -rf "$test_tmp/etc" | ||
| mkdir -p "$test_tmp/etc" | ||
| printf '%s' "$product" >"$test_tmp/dmi/product_name" | ||
| : >"$calls" | ||
|
|
||
| local script="$test_tmp/leaf.sh" | ||
| sed -e "s|/sys/class/dmi/id/product_name|$test_tmp/dmi/product_name|g" \ | ||
| -e "s|/etc/mkinitcpio.conf.d|$test_tmp/etc/mkinitcpio.conf.d|g" \ | ||
| -e "s|/etc/limine-entry-tool.d|$test_tmp/etc/limine-entry-tool.d|g" \ | ||
| "$leaf" >"$script" | ||
|
|
||
| PATH="$stub_bin:$PATH" TEST_LOG="$calls" \ | ||
| bash -eE -o pipefail -c 'source "$1"' bash "$script" </dev/null | ||
| } | ||
|
|
||
| run_leaf "MacBook8,1" >/dev/null | ||
| modules="$test_tmp/etc/mkinitcpio.conf.d/macbook_spi_modules.conf" | ||
| pio="$test_tmp/etc/limine-entry-tool.d/macbook81-spi-pio.conf" | ||
| grep -Fq 'MODULES=(applespi spi_pxa2xx_platform spi_pxa2xx_pci)' "$modules" || | ||
| fail "MacBook8,1 still gets the SPI initramfs modules" "$(cat "$modules" 2>/dev/null)" | ||
| grep -Fq 'initcall_blacklist=dw_pci_driver_init' "$pio" || | ||
| fail "MacBook8,1 gets the PIO kernel parameter" "$(cat "$pio" 2>/dev/null)" | ||
| grep -Fq 'mem_sleep_default=s2idle' "$pio" || | ||
| fail "MacBook8,1 gets s2idle" "$(cat "$pio" 2>/dev/null)" | ||
| grep -Fq $'omarchy-pkg-add\tmacbook12-spi-driver-dkms' "$calls" || | ||
| fail "MacBook8,1 still installs the SPI DKMS package" "$(cat "$calls")" | ||
| pass "MacBook8,1 setup writes SPI modules and the PIO drop-in" | ||
|
|
||
| run_leaf "MacBook10,1" >/dev/null | ||
| [[ -f $modules ]] || fail "MacBook10,1 still gets SPI modules" | ||
| [[ ! -e $pio ]] || fail "later 12-inch MacBooks do not get the 8,1 PIO quirk" "$(cat "$pio")" | ||
| pass "later SPI MacBooks are left on DMA" | ||
|
|
||
| run_leaf "MacBookPro14,1" >/dev/null | ||
| [[ ! -e $pio ]] || fail "MacBookPro models do not get the 8,1 PIO quirk" | ||
| pass "MacBookPro SPI models are left on DMA" | ||
|
|
||
| run_leaf "ThinkPad X1 Carbon" >/dev/null | ||
| [[ ! -e $modules ]] || fail "non-Apple hardware is left alone" | ||
| [[ ! -e $pio ]] || fail "non-Apple hardware is left alone" | ||
| [[ ! -s $calls ]] || fail "non-Apple hardware escalates nothing" "$(cat "$calls")" | ||
| pass "non-Apple hardware is left alone" | ||
|
|
||
| run_migration() { | ||
| local product="$1" | ||
| printf '%s' "$product" >"$test_tmp/dmi/product_name" | ||
| : >"$calls" | ||
|
|
||
| PATH="$stub_bin:$PATH" TEST_LOG="$calls" \ | ||
| OMARCHY_MACBOOK81_DMI_PRODUCT="$test_tmp/dmi/product_name" \ | ||
| OMARCHY_MACBOOK81_LIMINE_CONF="$pio" \ | ||
| OMARCHY_MACBOOK81_REPAIR_MARKER="$test_tmp/repair-complete" \ | ||
| OMARCHY_MACBOOK81_RUNNING_CMDLINE="$test_tmp/cmdline" \ | ||
| bash -euo pipefail "$migration" >/dev/null | ||
|
greptile-apps[bot] marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| rm -rf "$test_tmp/etc" "$test_tmp/repair-complete" | ||
| mkdir -p "$test_tmp/etc" | ||
| echo 'quiet splash' >"$test_tmp/cmdline" | ||
| ! REBUILD_FAILS=1 run_migration "MacBook8,1" 2>/dev/null || | ||
| fail "a boot image rebuild that skipped a kernel fails the migration" | ||
| [[ ! -e $test_tmp/repair-complete ]] || | ||
| fail "a boot image rebuild that skipped a kernel leaves the repair pending" | ||
| pass "the migration stays pending when a kernel is not rebuilt" | ||
|
|
||
| rm -rf "$test_tmp/etc" | ||
| mkdir -p "$test_tmp/etc" | ||
| run_migration "MacBook8,1" | ||
| grep -Fq 'initcall_blacklist=dw_pci_driver_init' "$pio" || | ||
| fail "the migration writes the PIO drop-in" "$(cat "$pio" 2>/dev/null)" | ||
| grep -Fq 'mem_sleep_default=s2idle' "$pio" || | ||
| fail "the migration writes s2idle" "$(cat "$pio" 2>/dev/null)" | ||
| grep -Fxq 'limine-mkinitcpio' "$calls" || | ||
| fail "the migration rebuilds the boot image" "$(cat "$calls")" | ||
| [[ -f $test_tmp/repair-complete ]] || fail "the migration records the machine-wide repair" | ||
| pass "the migration repairs an existing MacBook8,1" | ||
|
|
||
| : >"$calls" | ||
| run_migration "MacBook8,1" | ||
| [[ ! -s $calls ]] || fail "an already repaired MacBook8,1 is left unchanged" "$(cat "$calls")" | ||
| pass "the migration is machine-idempotent before reboot" | ||
|
|
||
| rm -f "$test_tmp/repair-complete" | ||
| : >"$calls" | ||
| run_migration "MacBook8,1" | ||
| grep -Fxq 'limine-mkinitcpio' "$calls" || | ||
| fail "the migration retries an interrupted boot image rebuild" | ||
| [[ -f $test_tmp/repair-complete ]] || fail "a retried repair records completion" | ||
| ! grep -Eq $'^(sudo\t)?tee(\t|$)' "$calls" || | ||
| fail "rebuild retry leaves a complete drop-in alone" "$(cat "$calls")" | ||
| pass "the migration retries an interrupted boot image rebuild" | ||
|
|
||
| rm -rf "$test_tmp/etc" "$test_tmp/repair-complete" | ||
| mkdir -p "$test_tmp/etc" | ||
| : >"$calls" | ||
| run_migration "MacBook10,1" | ||
| [[ ! -e $pio ]] || fail "the migration skips later 12-inch MacBooks" | ||
| [[ ! -s $calls ]] || fail "the migration escalates nothing on unrelated Macs" "$(cat "$calls")" | ||
| pass "the migration skips unrelated hardware" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.