diff --git a/mac-manual/content/10-boot.md b/mac-manual/content/10-boot.md index 125be92c..45621da4 100644 --- a/mac-manual/content/10-boot.md +++ b/mac-manual/content/10-boot.md @@ -37,6 +37,7 @@ There is one kernel, `linux-aurora`, built in omarchy-pkgs from a pinned commit The initramfs is systemd-based. Omarchy sets the platform's baseline of mkinitcpio hooks, and `omarchy-mac-boot` adds Apple fragments on top, in order, rather than overwriting it. The fragments only apply on an Apple Silicon Mac: - `MODULES` entries for the Apple keyboard and trackpad drivers, added only when the running kernel really has them as modules, so a kernel that builds a driver in does not break a later `mkinitcpio -P`; +- `apple_pmp`, the power management coprocessor's driver, on the same terms, so an encrypted root does not wait 20 seconds for it before the passphrase prompt; - a vendor firmware service that copies Apple firmware onto the root, and a second copy before `cryptsetup-pre.target` on encrypted Macs, so Wi-Fi and input work at the passphrase prompt; - a Plymouth drop-in, so the passphrase prompt is graphical; - the `kmod-static-nodes` ordering fix that btrfs roots need on Apple hardware. diff --git a/mac-manual/content/12-hardware.md b/mac-manual/content/12-hardware.md index 5715cf80..70eb45a3 100644 --- a/mac-manual/content/12-hardware.md +++ b/mac-manual/content/12-hardware.md @@ -59,6 +59,18 @@ Everything below the desktop is the Asahi Linux project's work, and the authorit - [M2 feature support](https://asahilinux.org/docs/platform/feature-support/m2/) - [Overview across chips](https://asahilinux.org/docs/platform/feature-support/overview/) +### M3 MacBook Air (edge testers) + +M3 Macs are not part of the first release. On an M3 MacBook Air installed from an edge image, the native display needs the line `chosen.asahi,t8122-dcp=1` in `/etc/m1n1.conf`, and a fresh install writes it when its `m1n1-aurora` is 1.6.1.aurora20-4 or newer. An M3 Air installed before that keeps its old boot setup. Once `pacman -Q m1n1-aurora` reports 1.6.1.aurora20-4 or newer, add the line yourself, unless `/etc/m1n1.conf` already has one, and rebuild m1n1's boot image, then reboot: + +```bash +grep -Eq '^[[:space:]]*chosen\.asahi,t8122-dcp=' /etc/m1n1.conf 2>/dev/null || + printf '\nchosen.asahi,t8122-dcp=1\n' | sudo tee -a /etc/m1n1.conf +sudo update-m1n1 +``` + +USB-C and DisplayPort external displays stay off on an M3 Air for now, since the line hands over only the built-in one. With an older `m1n1-aurora`, 1.6.1.aurora20-3 included, the line black-screens the Mac at boot. If that happens, remove it from `/etc/m1n1.conf` and run `sudo update-m1n1` again from a shell on this install that doesn't need the display, such as SSH if you set it up beforehand. + Anything marked work in progress there, Thunderbolt device support among them, is work in progress here too. The Aurora kernel adds the display, camera and USB4 work described above. ## Reporting a problem diff --git a/omarchy-mac-boot/README.md b/omarchy-mac-boot/README.md index 052e1995..3d512c8d 100644 --- a/omarchy-mac-boot/README.md +++ b/omarchy-mac-boot/README.md @@ -10,7 +10,11 @@ While first boot keeps the splash up, a laptop with its lid open shows it on the The Limine menu is Omarchy's, timeout and quiet mode included: `setup/limine-boot.sh` keeps the template's, and `/usr/lib/omarchy/mac-boot/limine-menu-defaults` gives a menu that still carries the `timeout: 3` earlier Mac activations wrote the template's timeout and `quiet:` line, leaving any other menu to Omarchy's migrations. U-Boot keeps EFI variables the OS sets at runtime in RAM (`EFI_RT_VOLATILE_STORE`): `omarchy-mac-efi-vars.service` writes them to the variable file U-Boot names (`RTStorageVolatile`, from `VarToFile`) as the Mac shuts down, so `systemctl reboot --boot-loader-menu`, `bootctl` and `efibootmgr` changes reach the next boot as on x86. It does nothing where U-Boot names no file. multi-user.target pulls it in only from the next boot, so the recipe's scriptlet starts it on install and upgrade, and on upgrade also runs `limine-menu-defaults` on the live menu, since activation does not run again. -The implementation was moved from runtime integration `e82fe3c8850b184dfa22eefd571646ad85446122`, preserving Marcelo's provenance recorded in the runtime source-port ledger. The payload in `files/` comes from the boot recipe paired with #503 (omarchy-mac/omarchy-pkgs-aarch64#65 at `617a907f99a1`) with maralcbr/omarchy-pkgs#202 applied (omarchy-mac-boot 20260921-10: the owner's keyboard layout and dock keyboards at the disk prompt). The owner wizard, recovery-slot operations, journal/retry handling and shared Limine menu/hash operations remain core code. Hardware setup reaches its setup leaves through `omarchy-lifecycle-dispatch setup-boot [image-first-boot]` (`entrypoints/setup-boot`: `setup/grub-console.sh`, then `setup/limine-boot.sh`, which on an image's first boot keys the image's identity-less Limine entry to the Mac's machine-id and asks for the deferred rebuild instead of building the UKI); the image builder sources them directly. `entrypoints/update-takeover ...` answers an update that wants to move aside files no package owns (the step 6 seam asks before it moves anything): read-only, it refuses the whole takeover when any path is the Mac's boot chain, `/usr/lib/initcpio` or pacman configuration, which its image and this package write, or an mkinitcpio file whose own `HOOKS` carry the `asahi` or busybox `encrypt` hook (a legacy Mac's unlock), and lets anything else go, including the memory, USB and mkinitcpio drop-ins omarchy-settings ships on aarch64 too. Owner provisioning, factory reset and `omarchy-drive-password` reach this package only through `omarchy-lifecycle-dispatch`, which runs the `entrypoints/` staged in `/usr/lib/omarchy/mac-boot` and fails on Apple Silicon when they are missing. +The implementation was moved from runtime integration `e82fe3c8850b184dfa22eefd571646ad85446122`, preserving Marcelo's provenance recorded in the runtime source-port ledger. The payload in `files/` comes from the boot recipe paired with #503 (omarchy-mac/omarchy-pkgs-aarch64#65 at `617a907f99a1`) with maralcbr/omarchy-pkgs#202 applied (omarchy-mac-boot 20260921-10: the owner's keyboard layout and dock keyboards at the disk prompt). The owner wizard, recovery-slot operations, journal/retry handling and shared Limine menu/hash operations remain core code. Hardware setup reaches its setup leaves through `omarchy-lifecycle-dispatch setup-boot [image-first-boot]` (`entrypoints/setup-boot`: `setup/grub-console.sh`, then `setup/limine-boot.sh`, which on an image's first boot keys the image's identity-less Limine entry to the Mac's machine-id and asks for the deferred rebuild instead of building the UKI, then `setup/m1n1-display.sh`); the image builder sources them directly. `entrypoints/update-takeover ...` answers an update that wants to move aside files no package owns (the step 6 seam asks before it moves anything): read-only, it refuses the whole takeover when any path is the Mac's boot chain, `/usr/lib/initcpio` or pacman configuration, which its image and this package write, or an mkinitcpio file whose own `HOOKS` carry the `asahi` or busybox `encrypt` hook (a legacy Mac's unlock), and lets anything else go, including the memory, USB and mkinitcpio drop-ins omarchy-settings ships on aarch64 too. Owner provisioning, factory reset and `omarchy-drive-password` reach this package only through `omarchy-lifecycle-dispatch`, which runs the `entrypoints/` staged in `/usr/lib/omarchy/mac-boot` and fails on Apple Silicon when they are missing. + +On an M3 MacBook Air (`apple,t8122` with `apple,j613` or `apple,j615`), `setup/m1n1-display.sh` turns the native display on: it appends `chosen.asahi,t8122-dcp=1` to `/etc/m1n1.conf`, which update-m1n1 copies into `boot.bin`, and runs `update-m1n1` so the next boot has it. Only an `m1n1-aurora` at or above the leaf's `m1n1_t8122_dcp_minimum`, 1.6.1.aurora20-4 (omacom/m1n1#14, which reserves the external DCP firmware only on its own opt-in), hands the display over on that line; 1.6.1.aurora20-3 and older black-screen the Mac with it, so with an older `m1n1-aurora` the leaf writes nothing. The pkgrel is part of the minimum. An owner's own `chosen.asahi,t8122-dcp=` line, for either value, is kept, as are their other lines. If writing `m1n1.conf` or `update-m1n1` fails, `m1n1.conf` is put back byte for byte and the leaf warns without failing the setup. That keeps `boot.bin` matching unless `update-m1n1` failed after it had already moved the new `boot.bin` into place; the next update's boot check reports that. It runs only on a booted Mac (`/run/systemd/system`): setup-boot clears the environment, so `OMARCHY_MAC_IMAGE_BUILD` never reaches it, and a chroot (an image build's or an installer's) has no booted systemd. The other T8122 Macs are left alone. `setup-boot` runs at install and on a hardware rerun only, so an M3 Air installed before this does not get it on update (see the manual's hardware page). + +`92-omarchy-mac-pmp.conf` adds `apple_pmp`, the power management coprocessor's driver, to the initramfs when the target kernel has it as a module. Without it an encrypted root waits out "PMP driver did not bind within 20000 ms" before unlock, since the module is still on that root. ## Device tree overlays diff --git a/omarchy-mac-boot/entrypoints/setup-boot b/omarchy-mac-boot/entrypoints/setup-boot index 5602b6d4..f8881211 100755 --- a/omarchy-mac-boot/entrypoints/setup-boot +++ b/omarchy-mac-boot/entrypoints/setup-boot @@ -3,9 +3,10 @@ # omarchy-lifecycle-dispatch setup-boot [image-first-boot]. The platform setup # leaf runs this at the end of hardware setup, before omarchy-mac's # setup-system: the GRUB console settings, then the Limine activation on a Mac -# that opted in. On an image's first boot the Limine leaf asks for the boot -# rebuild the deferred setup does once after its last step, rather than -# building the UKI itself. Both leaves re-check the platform. +# that opted in, then the M3 Air display default in m1n1.conf. On an image's +# first boot the Limine leaf asks for the boot rebuild the deferred setup does +# once after its last step, rather than building the UKI itself. Every leaf +# re-checks the platform. set -euo pipefail @@ -18,7 +19,7 @@ if (( EUID == 0 )); then # Root takes nothing from its caller's environment. exec /usr/bin/env -i PATH=/usr/local/sbin:/usr/local/bin:/usr/bin OMARCHY_PATH=/usr/share/omarchy \ ${1:+OMARCHY_IMAGE_BOOT_REBUILD=/var/lib/omarchy/image/boot-rebuild} \ - /bin/bash -euo pipefail -c 'source "$1/grub-console.sh" || exit 1; source "$1/limine-boot.sh" || exit 1' setup-boot "$setup" + /bin/bash -euo pipefail -c 'source "$1/grub-console.sh" || exit 1; source "$1/limine-boot.sh" || exit 1; source "$1/m1n1-display.sh" || exit 1' setup-boot "$setup" else # Unprivileged tests stage the package under a fixture root. root=${OMARCHY_MAC_BOOT_ROOT:-} @@ -28,4 +29,5 @@ else fi source "$root$setup/grub-console.sh" || exit 1 source "$root$setup/limine-boot.sh" || exit 1 + source "$root$setup/m1n1-display.sh" || exit 1 fi diff --git a/omarchy-mac-boot/files/etc/mkinitcpio.conf.d/92-omarchy-mac-pmp.conf b/omarchy-mac-boot/files/etc/mkinitcpio.conf.d/92-omarchy-mac-pmp.conf new file mode 100644 index 00000000..78c1dab5 --- /dev/null +++ b/omarchy-mac-boot/files/etc/mkinitcpio.conf.d/92-omarchy-mac-pmp.conf @@ -0,0 +1,6 @@ +# The power management coprocessor's driver, before the root is unlocked: an +# encrypted root otherwise waits out "PMP driver did not bind within 20000 ms" +# with apple-pmp.ko still on that root. Added only when modinfo names a module. +_omarchy_mac_pmp_path=$(modinfo -k "${KERNELVERSION:-$(uname -r)}" -F filename apple_pmp 2>/dev/null) && + [[ $_omarchy_mac_pmp_path == /* ]] && MODULES+=(apple_pmp) +unset _omarchy_mac_pmp_path diff --git a/omarchy-mac-boot/files/usr/share/libalpm/hooks/91-omarchy-mac-boot-initramfs.hook b/omarchy-mac-boot/files/usr/share/libalpm/hooks/91-omarchy-mac-boot-initramfs.hook index 7bb3894a..bb878f35 100644 --- a/omarchy-mac-boot/files/usr/share/libalpm/hooks/91-omarchy-mac-boot-initramfs.hook +++ b/omarchy-mac-boot/files/usr/share/libalpm/hooks/91-omarchy-mac-boot-initramfs.hook @@ -5,6 +5,7 @@ Operation = Upgrade Target = etc/mkinitcpio.conf.d/90-omarchy-mac.conf Target = etc/mkinitcpio.conf.d/91-omarchy-mac-encrypt.conf Target = etc/mkinitcpio.conf.d/92-omarchy-mac-hid.conf +Target = etc/mkinitcpio.conf.d/92-omarchy-mac-pmp.conf Target = etc/mkinitcpio.conf.d/93-omarchy-mac-plymouth.conf Target = etc/mkinitcpio.conf.d/94-omarchy-mac-vconsole.conf Target = etc/initcpio/install/* diff --git a/omarchy-mac-boot/setup/m1n1-display.sh b/omarchy-mac-boot/setup/m1n1-display.sh new file mode 100644 index 00000000..f933107e --- /dev/null +++ b/omarchy-mac-boot/setup/m1n1-display.sh @@ -0,0 +1,83 @@ +# The M3 Airs' native display: m1n1 hands the display coprocessor to Linux only +# when /etc/m1n1.conf sets chosen.asahi,t8122-dcp=1, which update-m1n1 copies +# into boot.bin. An m1n1 without its opt-in gate black-screens these Macs with it. +omarchy-hw-apple-silicon || return 0 +[[ ${OMARCHY_MAC_IMAGE_BUILD:-} != "1" ]] || return 0 +# setup-boot clears the environment, so only a booted systemd tells the leaf it +# is not in a chroot (an image build's or an installer's). +[[ -d ${OMARCHY_SYSTEMD_RUN:-/run/systemd/system} ]] || return 0 + +( + set -uo pipefail + # The first m1n1-aurora that reserves the external DCP firmware only on its + # own opt-in (omacom/m1n1#14, omarchy-pkgs#1564); 20-3 black-screens. Keep the pkgrel. + m1n1_t8122_dcp_minimum=1.6.1.aurora20-4 + minimum_m1n1=${OMARCHY_M1N1_T8122_DCP_MINIMUM-$m1n1_t8122_dcp_minimum} + compatible=${OMARCHY_DEVICE_TREE_COMPATIBLE:-/proc/device-tree/compatible} + config=${OMARCHY_M1N1_CONF:-/etc/m1n1.conf} + key=chosen.asahi,t8122-dcp + + machine= + [[ ! -r $compatible ]] || machine=$(tr '\0' '\n' <"$compatible") + m1n1_display_has() { [[ $'\n'$machine$'\n' == *$'\n'"$1"$'\n'* ]]; } + + m1n1_display_has apple,t8122 || exit 0 + # The M3 Airs (J613, J615); the other T8122 Macs' displays are untested. + m1n1_display_has apple,j613 || m1n1_display_has apple,j615 || exit 0 + if [[ -z $minimum_m1n1 ]]; then + echo "m1n1-display: no m1n1-aurora with the T8122 display opt-in is known yet; leaving $config alone" + exit 0 + fi + # pacman -Q also answers for a package that only provides the name. + name= installed= + read -r name installed < <(pacman -Q m1n1-aurora 2>/dev/null) || true + if [[ $name != "m1n1-aurora" || -z $installed ]]; then + echo "m1n1-display: m1n1-aurora is not installed; leaving $config alone" + exit 0 + fi + # Fail closed: a comparison that cannot be made writes nothing. + if ! order=$(vercmp "$installed" "$minimum_m1n1" 2>/dev/null) || [[ ! $order =~ ^-?[0-9]+$ ]]; then + echo "m1n1-display: cannot compare m1n1-aurora $installed with $minimum_m1n1; leaving $config alone" + exit 0 + fi + if (( order < 0 )); then + echo "m1n1-display: m1n1-aurora $installed predates the T8122 display opt-in ($minimum_m1n1); leaving $config alone" + exit 0 + fi + # A line the owner wrote, for either value, is theirs to keep. + if [[ -r $config ]] && grep -Eq "^[[:space:]]*${key//./\\.}=" "$config"; then + exit 0 + fi + + staged=$(mktemp -d) || { echo "m1n1-display: could not stage $config; leaving it alone" >&2; exit 0; } + trap 'rm -rf "$staged"' EXIT + : >"$staged/new" + if [[ -e $config ]]; then + cp "$config" "$staged/original" && cp "$config" "$staged/new" || + { echo "m1n1-display: could not stage $config; leaving it alone" >&2; exit 0; } + # Keep a last line without its newline from swallowing ours. + [[ ! -s $staged/new || $(tail -c 1 "$staged/new" | od -An -c | tr -d ' ') == '\n' ]] || printf '\n' >>"$staged/new" + fi + printf '# omarchy-mac-boot: the M3 Air native display. Set it to 0 to keep m1n1 from handing it over.\n%s=1\n' "$key" >>"$staged/new" + + # Put the original bytes back (install can unlink the file before copying). + m1n1_display_restore() { + if [[ -e $staged/original ]]; then + sudo install -m 0644 "$staged/original" "$config" + else + sudo rm -f "$config" + fi + } + m1n1_display_failed() { + if m1n1_display_restore; then + echo "m1n1-display: $1; $config is back as it was, and the native display stays off" >&2 + else + echo "m1n1-display: $1, and $config could not be put back; the next update-m1n1 takes its $key line" >&2 + fi + exit 0 + } + sudo install -D -m 0644 "$staged/new" "$config" || m1n1_display_failed "could not write $config" + # boot.bin only takes m1n1.conf when update-m1n1 builds it. + sudo update-m1n1 || m1n1_display_failed "update-m1n1 failed" + echo "m1n1-display: enabled the native display in $config" +) diff --git a/omarchy-mac-boot/test/m1n1-display-test.sh b/omarchy-mac-boot/test/m1n1-display-test.sh new file mode 100644 index 00000000..889be367 --- /dev/null +++ b/omarchy-mac-boot/test/m1n1-display-test.sh @@ -0,0 +1,139 @@ +#!/bin/bash +set -euo pipefail +source "$(dirname "$0")/base-test.sh" + +# setup/m1n1-display.sh writes the M3 Air display opt-in into m1n1.conf and +# rebuilds boot.bin, only on a J613 or J615 whose m1n1-aurora has the gate. +command -v vercmp >/dev/null || { printf 'skip - m1n1 display default: vercmp is not installed\n'; exit 0; } +work=$(mktemp -d) +trap 'rm -rf "$work"' EXIT +stub=$work/bin +mkdir -p "$stub" +printf '#!/bin/bash\n[[ ${NOT_APPLE:-} != 1 ]]\n' >"$stub/omarchy-hw-apple-silicon" +# A vercmp that fails after printing a number, prints text with a number in it, or prints nothing. +fake_vercmp=$work/fake-vercmp +mkdir -p "$fake_vercmp" +cat >"$fake_vercmp/vercmp" <<'SH' +#!/bin/bash +case $VERCMP in + fails) echo 1; exit 1 ;; + garbage) echo 'error: 2 is not a version' ;; + empty) ;; +esac +SH +chmod +x "$fake_vercmp/vercmp" +cat >"$stub/pacman" <<'SH' +#!/bin/bash +[[ $1 == -Q && $2 == m1n1-aurora && -n ${M1N1_VERSION:-} ]] || exit 1 +echo "${M1N1_PACKAGE:-m1n1-aurora} $M1N1_VERSION" +SH +cat >"$stub/sudo" <<'SH' +#!/bin/bash +[[ ${WRITE_FAILS:-} == 1 && $1 == install && $2 == -D ]] && { rm -f "${@: -1}"; exit 1; } +exec "$@" +SH +cat >"$stub/update-m1n1" <<'SH' +#!/bin/bash +echo update-m1n1 >>"$CALLS" +[[ ${UPDATE_FAILS:-} != 1 ]] +SH +chmod +x "$stub"/* +export CALLS=$work/calls +mkdir -p "$work/run-systemd" + +# machine COMPATIBLE...: a device tree root compatible list. +machine() { printf '%s\0' "$@" >"$work/compatible"; } +run() { + : >"$CALLS" + PATH="${VERCMP:+$fake_vercmp:}$stub:$PATH" OMARCHY_DEVICE_TREE_COMPATIBLE=$work/compatible OMARCHY_M1N1_CONF=$work/etc/m1n1.conf \ + OMARCHY_SYSTEMD_RUN=${SYSTEMD_RUN-$work/run-systemd} \ + OMARCHY_M1N1_T8122_DCP_MINIMUM=${MINIMUM-1.6.1.aurora21-1} M1N1_VERSION=${VERSION-1.6.1.aurora21-1} \ + bash -c '[[ -z ${PACKAGED:-} ]] || unset OMARCHY_M1N1_T8122_DCP_MINIMUM; source "$1"' _ "$ROOT/setup/m1n1-display.sh" >"$work/out" 2>&1 +} +conf() { cat "$work/etc/m1n1.conf" 2>/dev/null || echo absent; } + +machine apple,j613 apple,t8122 apple,arm-platform +run || fail 'a fresh M3 Air takes the display default' "$(cat "$work/out")" +grep -Fxq 'chosen.asahi,t8122-dcp=1' "$work/etc/m1n1.conf" && [[ $(<"$CALLS") == update-m1n1 ]] || + fail 'the opt-in is written and boot.bin rebuilt' "$(conf) / $(cat "$CALLS")" +[[ $(stat -c %a "$work/etc/m1n1.conf") == 644 ]] || fail 'm1n1.conf is world-readable, as update-m1n1 reads it' +before=$(conf) +run && [[ $(conf) == "$before" && ! -s $CALLS ]] || fail 'a rerun changes nothing and rebuilds nothing' +machine apple,j615 apple,t8122 apple,arm-platform +rm -rf "$work/etc" +run && grep -Fxq 'chosen.asahi,t8122-dcp=1' "$work/etc/m1n1.conf" || fail 'the 15-inch M3 Air takes it too' +pass 'an M3 Air gets the native display in m1n1.conf and boot.bin, once' + +# The owner's own m1n1.conf lines stay, and their own choice for the display wins. +mkdir -p "$work/etc" +printf 'display=1920x1080\nchosen.asahi,other=1' >"$work/etc/m1n1.conf" +run || fail 'an M3 Air with its own m1n1.conf takes the default' +[[ $(head -n 2 "$work/etc/m1n1.conf") == $'display=1920x1080\nchosen.asahi,other=1' ]] && + grep -Fxq 'chosen.asahi,t8122-dcp=1' "$work/etc/m1n1.conf" || fail 'the owner lines stay, and a last line without a newline is not joined' "$(conf)" +printf 'chosen.asahi,t8122-dcp=0\n' >"$work/etc/m1n1.conf" +run && [[ $(conf) == 'chosen.asahi,t8122-dcp=0' && ! -s $CALLS ]] || fail "the owner's own choice is never overwritten" "$(conf)" +printf 'chosenXasahi,t8122-dcp=0\n' >"$work/etc/m1n1.conf" +run && grep -Fxq 'chosen.asahi,t8122-dcp=1' "$work/etc/m1n1.conf" || fail 'only the exact key counts as the owner line, not a near miss' "$(conf)" +pass "the owner's m1n1.conf lines and choice are kept" + +# The hard gate: an m1n1 without the opt-in gate black-screens with the line. +check_untouched() { + rm -rf "$work/etc" + run || fail "$1: still succeeds" + [[ $(conf) == absent && ! -s $CALLS ]] || fail "$1" "$(conf) $(cat "$CALLS")" +} +machine apple,j613 apple,t8122 apple,arm-platform +VERSION=1.6.1.aurora20-3 check_untouched 'an older m1n1-aurora gets nothing written' +grep -q predates "$work/out" || fail 'an older m1n1-aurora is named as older, not as uncomparable' "$(cat "$work/out")" +VERSION= check_untouched 'without m1n1-aurora nothing is written' +MINIMUM= check_untouched 'until the minimum is known nothing is written' +M1N1_PACKAGE=m1n1-other check_untouched 'a package that only provides m1n1-aurora is not taken for it' +SYSTEMD_RUN=$work/no-such-run check_untouched "an image build's chroot, with no booted systemd, gets nothing written" +for result in fails garbage empty; do + VERCMP=$result check_untouched "a vercmp that $result writes nothing: the gate fails closed" +done +NOT_APPLE=1 check_untouched 'off Apple Silicon nothing is written' +OMARCHY_MAC_IMAGE_BUILD=1 check_untouched 'an image build writes nothing' +machine apple,j613 apple,t8112 apple,arm-platform +check_untouched 'a J613 board name on another SoC is left alone' +machine apple,j504 apple,t8122 apple,arm-platform +check_untouched 'another T8122 Mac is left alone' +machine apple,j414c apple,t6021 apple,arm-platform +check_untouched 'an M2 Max is left alone' +grep -Fxq ' m1n1_t8122_dcp_minimum=1.6.1.aurora20-4' "$ROOT/setup/m1n1-display.sh" || + fail 'the packaged minimum is the first m1n1-aurora with the dcpext opt-in, pkgrel included' +# The packaged minimum: 20-3 black-screens an M3 Air with the line, 20-4 does not. +machine apple,j613 apple,t8122 apple,arm-platform +PACKAGED=1 VERSION=1.6.1.aurora20-3 check_untouched 'm1n1-aurora 1.6.1.aurora20-3, the black-screen build, gets nothing written' +rm -rf "$work/etc" +PACKAGED=1 VERSION=1.6.1.aurora20-4 run && grep -Fxq 'chosen.asahi,t8122-dcp=1' "$work/etc/m1n1.conf" || + fail 'm1n1-aurora 1.6.1.aurora20-4 gets the display line' "$(conf) $(cat "$work/out")" +for newer in 1.6.1.aurora20-10 1.6.1.aurora21-1; do + rm -rf "$work/etc" + PACKAGED=1 VERSION=$newer run && grep -Fxq 'chosen.asahi,t8122-dcp=1' "$work/etc/m1n1.conf" || + fail "m1n1-aurora $newer, newer than the packaged minimum, gets the display line" "$(conf) $(cat "$work/out")" +done +pass 'only an m1n1-aurora at or above the packaged minimum gets the line on an M3 Air' + +# A failed rebuild leaves m1n1.conf as it was, so the boot check stays consistent. +machine apple,j613 apple,t8122 apple,arm-platform +rm -rf "$work/etc" +UPDATE_FAILS=1 run || fail 'a failed update-m1n1 warns but never fails the setup' +[[ $(conf) == absent ]] && grep -q 'stays off' "$work/out" || fail 'a new m1n1.conf is removed again after a failed rebuild, and it says so' "$(conf)" +mkdir -p "$work/etc" && printf 'display=1920x1080' >"$work/etc/m1n1.conf" +cp "$work/etc/m1n1.conf" "$work/original" +UPDATE_FAILS=1 run || fail 'a failed update-m1n1 warns but never fails the setup' +cmp -s "$work/etc/m1n1.conf" "$work/original" || fail "the owner's m1n1.conf is back byte for byte, a last line without a newline included" "$(od -c "$work/etc/m1n1.conf" | head -2)" +mkdir -p "$work/etc" && printf 'display=1920x1080\n' >"$work/etc/m1n1.conf" +cp "$work/etc/m1n1.conf" "$work/original" +WRITE_FAILS=1 run || fail 'a failed first write never fails the setup' +cmp -s "$work/etc/m1n1.conf" "$work/original" && [[ ! -s $CALLS ]] || + fail "a failed first write puts the owner's m1n1.conf back and rebuilds nothing" "$(conf)" +cat >"$stub/sudo" <<'SH' +#!/bin/bash +[[ ${RESTORE_FAILS:-} == 1 && $1 == install && $2 == -m ]] && exit 1 +exec "$@" +SH +UPDATE_FAILS=1 RESTORE_FAILS=1 run || fail 'a failed restore still never fails the setup' +grep -q 'could not be put back' "$work/out" || fail 'a failed restore says so instead of claiming m1n1.conf is back' "$(cat "$work/out")" +pass 'a failed rebuild puts m1n1.conf back exactly, and the setup carries on' diff --git a/omarchy-mac-boot/test/mac-pmp-initramfs-test.sh b/omarchy-mac-boot/test/mac-pmp-initramfs-test.sh new file mode 100644 index 00000000..207ce104 --- /dev/null +++ b/omarchy-mac-boot/test/mac-pmp-initramfs-test.sh @@ -0,0 +1,33 @@ +#!/bin/bash +set -euo pipefail +source "$(dirname "$0")/base-test.sh" + +# 92-omarchy-mac-pmp.conf adds apple_pmp to the initramfs only where the +# target kernel has it as a module, so a built-in or missing driver never +# fails mkinitcpio, and never anything else. +work=$(mktemp -d) +trap 'rm -rf "$work"' EXIT +dropin=$ROOT/files/etc/mkinitcpio.conf.d/92-omarchy-mac-pmp.conf +mkdir -p "$work/bin" +cat >"$work/bin/modinfo" <<'SH' +#!/bin/sh +[ "$2" = "$EXPECTED_KERNEL" ] && [ "$5" = apple_pmp ] || exit 64 +case $MODINFO in + module) echo /lib/modules/k/kernel/drivers/soc/apple/apple-pmp.ko ;; + builtin) echo '(builtin)' ;; + *) exit 1 ;; +esac +SH +chmod +x "$work/bin/modinfo" +modules() { + MODINFO=$1 EXPECTED_KERNEL=target-kernel PATH="$work/bin:$PATH" bash -c ' + MODULES=(btrfs) + KERNELVERSION=target-kernel + source "$1" + printf "%s|%s|%s\n" "$?" "${MODULES[*]}" "${_omarchy_mac_pmp_path-unset}" + ' _ "$dropin" +} +[[ $(modules module) == '0|btrfs apple_pmp|unset' ]] || fail 'a module apple_pmp joins the initramfs' "$(modules module)" +[[ $(modules builtin) == '0|btrfs|unset' ]] || fail 'a built-in apple_pmp is left out' "$(modules builtin)" +[[ $(modules none) == '0|btrfs|unset' ]] || fail 'a kernel without apple_pmp is left out' "$(modules none)" +pass 'apple_pmp joins the initramfs only as a module of the target kernel' diff --git a/omarchy-mac-boot/test/mac-setup-boot-test.sh b/omarchy-mac-boot/test/mac-setup-boot-test.sh index 8a050c32..f9055be7 100755 --- a/omarchy-mac-boot/test/mac-setup-boot-test.sh +++ b/omarchy-mac-boot/test/mac-setup-boot-test.sh @@ -12,7 +12,7 @@ root=$work/root "$ROOT/install" "$root" entry=$root/usr/lib/omarchy/mac-boot/setup-boot [[ -x $entry && $(stat -c %a "$entry") == 755 ]] || fail 'the setup-boot entrypoint is staged for omarchy-lifecycle-dispatch' -for leaf in grub-console limine-boot; do +for leaf in grub-console limine-boot m1n1-display; do cat >"$root/usr/lib/omarchy-mac/boot/setup/$leaf.sh" <>"$work/ran" [[ ! -e $work/$leaf-fail ]] || return 1 @@ -21,11 +21,11 @@ done run() { rm -f "$work/ran"; OMARCHY_MAC_BOOT_ROOT=$root "$entry" "$@"; } run -[[ $(<"$work/ran") == $'grub-console rebuild=none\nlimine-boot rebuild=none' ]] || fail 'the console leaf runs, then the Limine leaf' "$(cat "$work/ran")" +[[ $(<"$work/ran") == $'grub-console rebuild=none\nlimine-boot rebuild=none\nm1n1-display rebuild=none' ]] || fail 'the console leaf runs, then the Limine leaf, then the display default' "$(cat "$work/ran")" run image-first-boot -[[ $(<"$work/ran") == $'grub-console rebuild='"$root"$'/var/lib/omarchy/image/boot-rebuild\nlimine-boot rebuild='"$root"'/var/lib/omarchy/image/boot-rebuild' ]] || +[[ $(<"$work/ran") == $'grub-console rebuild='"$root"$'/var/lib/omarchy/image/boot-rebuild\nlimine-boot rebuild='"$root"$'/var/lib/omarchy/image/boot-rebuild\nm1n1-display rebuild='"$root"'/var/lib/omarchy/image/boot-rebuild' ]] || fail "an image's first boot asks for the deferred rebuild" "$(cat "$work/ran")" -pass 'setup-boot runs the console leaf, then the Limine leaf, asking for the rebuild on an image first boot' +pass 'setup-boot runs the console leaf, the Limine leaf, then the display default, asking for the rebuild on an image first boot' touch "$work/grub-console-fail" if run 2>/dev/null; then fail 'a failed console leaf fails setup-boot'; fi @@ -34,6 +34,9 @@ rm "$work/grub-console-fail" touch "$work/limine-boot-fail" if run 2>/dev/null; then fail 'a failed Limine leaf fails setup-boot'; fi rm "$work/limine-boot-fail" +touch "$work/m1n1-display-fail" +if run 2>/dev/null; then fail 'a failed display leaf fails setup-boot'; fi +rm "$work/m1n1-display-fail" for arguments in first-boot 'image-first-boot extra'; do status=0 # shellcheck disable=SC2086