From e470e1d709c1bec6baa8859adb651cc98a8af02a Mon Sep 17 00:00:00 2001 From: Marcelo Alcantara Date: Sun, 4 Oct 2026 12:03:09 +1000 Subject: [PATCH] Include Apple USB controllers before root unlock SN201202x negotiates the USB data role on M3, and dwc3_apple binds the Apple USB controller. The initramfs now carries both, where the kernel has them, so a USB keyboard types at the disk password prompt without waiting for root-filesystem coldplug. Ported from omacom/omarchy-mac#604 (this commit only) with paths mapped to this repository. Its MacBook display scale seeding wrote into the user's monitors.lua, which the packages no longer do, and its migration fixture change went with the migration engine. Co-authored-by: Scott Jones <444693+scottjones@users.noreply.github.com> --- omarchy-mac-boot/README.md | 2 + .../mkinitcpio.conf.d/92-omarchy-mac-hid.conf | 7 +++- .../test/mac-hid-initramfs-test.sh | 39 +++++++++++++++++-- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/omarchy-mac-boot/README.md b/omarchy-mac-boot/README.md index 8376f9bd..fd2ceaad 100644 --- a/omarchy-mac-boot/README.md +++ b/omarchy-mac-boot/README.md @@ -10,6 +10,8 @@ While first boot keeps the splash up, a laptop with its lid open shows it on the 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 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 package-owned `92-omarchy-mac-hid.conf` also includes the `sn201202x` USB-PD and `dwc3_apple` controller modules for USB input before root unlock. It selects loadable modules from mkinitcpio's target kernel, leaves absent or built-in drivers alone for other kernel configurations, and lets mkinitcpio resolve module dependencies. It appends to `MODULES` without replacing `HOOKS`. This does not enable a driver omitted from the kernel configuration: M3 candidates must separately verify SN201202x support and inspect both the generated initramfs and UKI for its dependency closure. USB storage after login does not qualify a keyboard at the encrypted-root prompt. + ## Temporary adaptations - Deploy ARM64 Limine to U-Boot's `EFI/BOOT/BOOTAA64.EFI` slot until the shared Limine installer supports that target. diff --git a/omarchy-mac-boot/files/etc/mkinitcpio.conf.d/92-omarchy-mac-hid.conf b/omarchy-mac-boot/files/etc/mkinitcpio.conf.d/92-omarchy-mac-hid.conf index b75e8a55..3741d017 100644 --- a/omarchy-mac-boot/files/etc/mkinitcpio.conf.d/92-omarchy-mac-hid.conf +++ b/omarchy-mac-boot/files/etc/mkinitcpio.conf.d/92-omarchy-mac-hid.conf @@ -8,6 +8,10 @@ # thunderbolt_apple, the Apple Silicon USB4 host router (CONFIG_USB4_APPLE_SOC=m # on linux-aurora), bring up the USB4/Thunderbolt tunnels, so a keyboard behind # a USB-C or Thunderbolt dock types at the prompt too (omarchy-mx-mac#86). +# SN201202x negotiates the USB data role on M3; dwc3_apple binds the Apple +# USB controller. Include both before root unlock so USB keyboards do not +# depend on root-filesystem coldplug. mkinitcpio includes their dependencies +# from the selected kernel, including the shared TPS6598x core and DWC3. # # mkinitcpio fails the whole image over a MODULES entry it cannot find, or a # built-in it reports as "(builtin)". Each name is added only when modinfo @@ -16,7 +20,8 @@ for _omarchy_mac_hid_module in \ hid_apple hid_magicmouse dockchannel-hid usbhid \ spi-apple spi-hid-apple spi-hid-apple-of \ - apple-dockchannel apple-rtkit-helper thunderbolt thunderbolt_apple; do + apple-dockchannel apple-rtkit-helper thunderbolt thunderbolt_apple \ + sn201202x dwc3_apple; do _omarchy_mac_hid_path=$(modinfo -k "${KERNELVERSION:-$(uname -r)}" -F filename \ "$_omarchy_mac_hid_module" 2>/dev/null) || continue [[ $_omarchy_mac_hid_path == /* ]] || continue diff --git a/omarchy-mac-boot/test/mac-hid-initramfs-test.sh b/omarchy-mac-boot/test/mac-hid-initramfs-test.sh index 7ae0dde0..43c33005 100644 --- a/omarchy-mac-boot/test/mac-hid-initramfs-test.sh +++ b/omarchy-mac-boot/test/mac-hid-initramfs-test.sh @@ -109,7 +109,10 @@ while [ $# -gt 0 ]; do [ "$2" = filename ] && want_filename=1 shift 2 ;; - -k) shift 2 ;; + -k) + [ "$2" = "$EXPECTED_KERNEL" ] || exit 64 + shift 2 + ;; *) module=$1; shift ;; esac done @@ -136,13 +139,15 @@ write_modinfo() { source_hid() { write_modinfo "$@" - export MODINFO_DIR=$tmp/modinfo + export MODINFO_DIR=$tmp/modinfo EXPECTED_KERNEL=fixture-target-kernel PATH="$stub:$PATH" bash -c ' MODULES=(btrfs) FILES=() + HOOKS=(base systemd custom-hook sd-encrypt filesystems) + KERNELVERSION=$EXPECTED_KERNEL source "$1" status=$? - printf "%s\n" "$status" "${MODULES[*]}" "$(declare -p _omarchy_mac_hid_module 2>/dev/null || echo unset)" + printf "%s\n" "$status" "${MODULES[*]}" "$(declare -p _omarchy_mac_hid_module 2>/dev/null || echo unset)" "${HOOKS[*]}" ' bash "$hid_conf" } @@ -166,6 +171,30 @@ mapfile -t sourced < <(source_hid hid_apple=/lib/modules/x/hid-apple.ko) fail "a driver the kernel does not build is left out" "MODULES=(${sourced[1]})" echo 'ok - a driver the kernel does not build is left out' +# M3 modules must be selected from the target kernel even on a different +# build host. Keep the existing M1/M2 input and user-provided hook/module lists. +mapfile -t sourced < <(source_hid \ + hid_apple=/lib/modules/x/hid-apple.ko \ + sn201202x=/lib/modules/x/sn201202x.ko.zst \ + dwc3_apple=/lib/modules/x/dwc3-apple.ko.zst) +[[ ${sourced[0]} == 0 ]] || fail "M3 USB modules source cleanly" +[[ ${sourced[1]} == "btrfs hid_apple sn201202x dwc3_apple" ]] || + fail "target-kernel USB controllers are early-loaded alongside existing modules" "MODULES=(${sourced[1]})" +[[ ${sourced[3]} == "base systemd custom-hook sd-encrypt filesystems" ]] || + fail "USB inclusion must not change HOOKS" "HOOKS=(${sourced[3]})" +echo 'ok - M3 USB controllers use the target kernel and preserve existing MODULES and HOOKS' + +mapfile -t sourced < <(source_hid sn201202x='(builtin)' dwc3_apple='(builtin)') +[[ ${sourced[0]} == 0 && ${sourced[1]} == btrfs ]] || + fail "built-in USB controllers must not become MODULES entries" "MODULES=(${sourced[1]})" +mapfile -t sourced < <(source_hid sn201202x=/lib/modules/x/sn201202x.ko dwc3_apple='(builtin)') +[[ ${sourced[0]} == 0 && ${sourced[1]} == "btrfs sn201202x" ]] || + fail "mixed built-in/modular USB controllers are handled independently" "MODULES=(${sourced[1]})" +mapfile -t sourced < <(source_hid) +[[ ${sourced[0]} == 0 && ${sourced[1]} == btrfs ]] || + fail "kernels without Apple modules keep their configuration" "MODULES=(${sourced[1]})" +echo 'ok - built-in, mixed and absent USB controller configurations are accepted' + if [[ ${OMARCHY_DISPOSABLE_BOOT_TESTS:-0} != "1" && ${IN_OMARCHY_MAC_HID_TEST:-0} != "1" ]]; then echo 'ok - source checks passed; disposable initramfs/block tests not run (OMARCHY_DISPOSABLE_BOOT_TESTS=1 opts in)' exit 0 @@ -253,7 +282,7 @@ mint_ko() { } for module in hid-apple hid-magicmouse dockchannel-hid usbhid thunderbolt thunderbolt_apple \ - crypto_lzo crypto_lz4 dm_crypt dm_integrity; do + sn201202x dwc3_apple crypto_lzo crypto_lz4 dm_crypt dm_integrity; do mint_ko "$module" done # HID drop-in looks under drivers/hid as well as extra/. @@ -314,6 +343,8 @@ grep -Eq 'dockchannel-hid|dockchannel_hid' "$list" || fail "lsinitcpio lists doc grep -Eq 'usbhid' "$list" || fail "lsinitcpio lists usbhid" "$(cat "$list")" grep -Eq '(^|/)thunderbolt\.ko' "$list" || fail "lsinitcpio lists thunderbolt (dock keyboards, omarchy-mx-mac#86)" "$(cat "$list")" grep -Eq '(^|/)thunderbolt[-_]apple\.ko' "$list" || fail "lsinitcpio lists thunderbolt_apple, the Apple Silicon USB4 host router" "$(cat "$list")" +grep -Eq '(^|/)sn201202x\.ko' "$list" || fail "lsinitcpio lists sn201202x" "$(cat "$list")" +grep -Eq '(^|/)dwc3[-_]apple\.ko' "$list" || fail "lsinitcpio lists dwc3_apple" "$(cat "$list")" grep -Fq 'omarchy-vendorfw.sh' "$list" || fail "lsinitcpio lists the late vendorfw script" grep -Fq 'omarchy-vendorfw-initrd.sh' "$list" || fail "lsinitcpio lists the early vendorfw helper" grep -Fq 'omarchy-vendorfw.service' "$list" || fail "lsinitcpio lists the late vendorfw unit"