pax_global_header00006660000000000000000000000064147467045540014532gustar00rootroot0000000000000052 comment=4b6a19efc81c6bc7c7dfa3237ae87262dd405c87 AsahiLinux-asahi-scripts-5093f09/000077500000000000000000000000001474670455400166305ustar00rootroot00000000000000AsahiLinux-asahi-scripts-5093f09/.editorconfig000066400000000000000000000002611474670455400213040ustar00rootroot00000000000000root = true # Defaults [*] indent_style = space indent_size = 4 tab_width = 4 charset = utf-8 insert_final_newline = true trim_trailing_whitespace = true max_line_length = 100 AsahiLinux-asahi-scripts-5093f09/.gitignore000066400000000000000000000000061474670455400206140ustar00rootroot00000000000000build AsahiLinux-asahi-scripts-5093f09/LICENSE000066400000000000000000000020641474670455400176370ustar00rootroot00000000000000MIT License Copyright The Asahi Linux Contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. AsahiLinux-asahi-scripts-5093f09/Makefile000066400000000000000000000105431474670455400202730ustar00rootroot00000000000000PREFIX=/usr/local SYS_PREFIX=$(PREFIX) CONFIG_DIR=/etc/default BIN_DIR=$(PREFIX)/bin SCRIPTS=asahi-diagnose asahi-fwupdate update-m1n1 ARCH_SCRIPTS=update-grub first-boot UNITS=first-boot.service MULTI_USER_WANTS=first-boot.service DRACUT_CONF_DIR=$(PREFIX)/lib/dracut/dracut.conf.d DRACUT_MODULES_DIR=$(PREFIX)/lib/dracut/modules.d SYSTEMD_UNIT_DIR=$(PREFIX)/lib/systemd/system UDEV_RULES_DIR=$(PREFIX)/lib/udev/rules.d BUILD_SCRIPTS=$(addprefix build/,$(SCRIPTS)) BUILD_ARCH_SCRIPTS=$(addprefix build/,$(ARCH_SCRIPTS)) all: $(BUILD_SCRIPTS) $(BUILD_ARCH_SCRIPTS) build/%: % @[ ! -e build ] && mkdir -p build || true sed -e s,/etc/default,$(CONFIG_DIR),g "$<" > "$@" chmod +x "$@" clean: rm -rf build install: all install -d $(DESTDIR)$(BIN_DIR)/ install -m0755 -t $(DESTDIR)$(BIN_DIR)/ $(BUILD_SCRIPTS) install -dD $(DESTDIR)/etc install -dD $(DESTDIR)$(PREFIX)/share/asahi-scripts install -m0644 -t $(DESTDIR)$(PREFIX)/share/asahi-scripts functions.sh install -dD $(DESTDIR)/$(SYS_PREFIX)/lib/firmware/vendor install-mkinitcpio: install install -dD $(DESTDIR)$(PREFIX)/lib/initcpio/install install -m0644 -t $(DESTDIR)$(PREFIX)/lib/initcpio/install initcpio/install/asahi install -dD $(DESTDIR)$(PREFIX)/lib/initcpio/hooks install -m0644 -t $(DESTDIR)$(PREFIX)/lib/initcpio/hooks initcpio/hooks/asahi install-dracut: install install -dD $(DESTDIR)$(DRACUT_CONF_DIR) install -m0644 -t $(DESTDIR)$(DRACUT_CONF_DIR) dracut/dracut.conf.d/10-asahi.conf install -dD $(DESTDIR)$(DRACUT_MODULES_DIR)/91kernel-modules-asahi install -m0755 -t $(DESTDIR)$(DRACUT_MODULES_DIR)/91kernel-modules-asahi dracut/modules.d/91kernel-modules-asahi/module-setup.sh install -dD $(DESTDIR)$(DRACUT_MODULES_DIR)/99asahi-firmware install -m0755 -t $(DESTDIR)$(DRACUT_MODULES_DIR)/99asahi-firmware dracut/modules.d/99asahi-firmware/install-asahi-firmware.sh install -m0755 -t $(DESTDIR)$(DRACUT_MODULES_DIR)/99asahi-firmware dracut/modules.d/99asahi-firmware/load-asahi-firmware.sh install -m0755 -t $(DESTDIR)$(DRACUT_MODULES_DIR)/99asahi-firmware dracut/modules.d/99asahi-firmware/module-setup.sh install-macsmc-battery: install install -dD $(DESTDIR)$(SYSTEMD_UNIT_DIR) install -dD $(DESTDIR)$(UDEV_RULES_DIR) install -m0755 -t $(DESTDIR)$(SYSTEMD_UNIT_DIR) macsmc-battery/systemd/macsmc-battery-charge-control-end-threshold.path install -m0755 -t $(DESTDIR)$(SYSTEMD_UNIT_DIR) macsmc-battery/systemd/macsmc-battery-charge-control-end-threshold.service install -m0644 -t $(DESTDIR)$(UDEV_RULES_DIR) macsmc-battery/udev/93-macsmc-battery-charge-control.rules install-arch: install install-mkinitcpio install-macsmc-battery install -m0755 -t $(DESTDIR)$(BIN_DIR)/ $(BUILD_ARCH_SCRIPTS) install -dD $(DESTDIR)$(PREFIX)/lib/systemd/system install -dD $(DESTDIR)$(PREFIX)/lib/systemd/system/{multi-user,sysinit}.target.wants install -m0644 -t $(DESTDIR)$(PREFIX)/lib/systemd/system $(addprefix systemd/,$(UNITS)) ln -sf $(addprefix $(PREFIX)/lib/systemd/system/,$(MULTI_USER_WANTS)) \ $(DESTDIR)$(PREFIX)/lib/systemd/system/multi-user.target.wants/ install -dD $(DESTDIR)$(PREFIX)/share/libalpm/hooks install -m0644 -t $(DESTDIR)$(PREFIX)/share/libalpm/hooks libalpm/hooks/95-m1n1-install.hook install-fedora: install install-dracut install-macsmc-battery uninstall: rm -f $(addprefix $(DESTDIR)$(BIN_DIR)/,$(SCRIPTS)) rm -rf $(DESTDIR)$(PREFIX)/share/asahi-scripts uninstall-mkinitcpio: rm -f $(DESTDIR)$(PREFIX)/lib/initcpio/install/asahi rm -f $(DESTDIR)$(PREFIX)/lib/initcpio/hooks/asahi uninstall-dracut: rm -f $(DESTDIR)$(DRACUT_CONF_DIR)/10-asahi.conf uninstall-macsmc-battery: rm -f $(DESTDIR)$(SYSTEMD_UNIT_DIR)/macsmc-battery-charge-control-end-threshold.path rm -f $(DESTDIR)$(SYSTEMD_UNIT_DIR)/macsmc-battery-charge-control-end-threshold.service rm -f $(DESTDIR)$(UDEV_RULES_DIR)/93-macsmc-battery-charge-control.rules uninstall-arch: uninstall-mkinitcpio uninstall-macsmc-battery rm -f $(addprefix $(DESTDIR)$(BIN_DIR)/,$(ARCH_SCRIPTS)) rm -f $(addprefix $(DESTDIR)$(PREFIX)/lib/systemd/system/,$(UNITS)) rm -f $(addprefix $(DESTDIR)$(PREFIX)/lib/systemd/system/multi-user.target.wants/,$(MULTI_USER_WANTS)) rm -f $(DESTDIR)$(PREFIX)/share/libalpm/hooks/95-m1n1-install.hook uninstall-fedora: uninstall-dracut uninstall-macsmc-battery .PHONY: clean install install-mkinitcpio install-dracut install-arch install-fedora uninstall uninstall-mkinitcpio uninstall-dracut uninstall-arch uninstall-fedora AsahiLinux-asahi-scripts-5093f09/asahi-diagnose000077500000000000000000000234461474670455400214430ustar00rootroot00000000000000#!/bin/sh log() { echo "$@" } dt() { p=/proc/device-tree/"$1" if [ ! -e "$p" ]; then echo "(missing)" else cat "$p" | tr "\0" " " | sed -e 's/ $//g'; echo fi } banner() { cat < /dev/null \ && echo "yes" \ || echo "no" } pro_audio=$(check_proaudio) # Check for Configs in /etc/ (installed before mid 2023) check_audio_oldconfs() { [ -e /etc/pipewire/pipewire.conf.d/*asahi* ] \ || [ -e /etc/wireplumber/policy.lua.d/99-asahi-policy.lua ] \ && echo "yes" \ || echo "no" } old_conf=$(check_audio_oldconfs) # Check for the racy 99-asahi* build (installed before ~Oct 2023) check_audio_oldbuild() { [ -e /usr/share/wireplumber/policy.lua.d/99-asahi-policy.lua ] \ && echo "yes" \ || echo "no" } racy_build=$(check_audio_oldbuild) # Check if snd-soc-macaudio.please_blow_up_my_speakers was requested check_audio_macaudio() { grep "0" /sys/module/snd_soc_macaudio/parameters/please_blow_up_my_speakers > /dev/null \ && echo "no" \ || echo "yes" } bad_macaudio_params=$(check_audio_macaudio) # Check that snd-soc-tas2764.apple_quirks=0x3f is being applied check_audio_tas2764() { [ -e /sys/module/snd_soc_tas2764/ ] && ( grep "63" /sys/module/snd_soc_tas2764/parameters/apple_quirks > /dev/null \ && echo "yes" \ || echo "no" ) || echo "N/A" } tas2764_quirks=$(check_audio_tas2764) audio_config() { cat </dev/null | sort -u) \`\`\` EOF } module_parameters() { echo "## Module parameters" for mod in asahi hid_apple hid_magicmouse; do [ ! -e /sys/module/$mod/parameters/ ] && continue echo " $mod" for param in /sys/module/$mod/parameters/*; do echo " $(basename "$param")=$(cat "$param" | tr -d '\0')" done echo done echo } logfile() { f="$1" lines="$2" [ -e "$1" ] || return echo "## Log file: \`$f\`" echo '```' if [ -z "$lines" ]; then cat "$f" else tail -n "$lines" "$f" fi echo '```' echo } environment() { echo "## Environment" set | grep -E 'MESA|AGX|ASAHI|XDG_SESSION_TYPE|DISPLAY|TERM|LANG|LOCALE|LC_' | sed 's/^/ /' echo } diagnose() { f="$1" >$f log "Collecting system diagnostic information..." log ( exec >"$f" 2>&1 banner device_info firmware_versions boot_config system_info audio_config environment getfile /proc/mounts "Mounts" package_versions cmd lsblk "Block devices" cmd lspci "PCI devices" getfile /proc/bus/input/devices "Input devices" cmd lsmod "Loaded modules" module_parameters cmd 'journalctl -b 0 -tkernel' "Kernel log" cmd 'journalctl -b -1 -tkernel' "Kernel log (last boot)" logfile /var/log/Xorg.0.log logfile /var/log/pacman.log 500 ) log "Saved diagnostic information to $f" if [ "$macaudio_profile" != "HiFi" -a "$macaudio_profile" != "Default" ]; then echo echo "Pipewire macaudio profile is \"${macaudio_profile}\"." echo "Headphones and speakers will not work. Select the \"Default\" or \"HiFi\" profile." fi if [ "$pro_audio" = "yes" ] || \ [ "$old_conf" = "yes" ] || \ [ "$racy_build" = "yes" ] || \ [ "$bad_macaudio_params" = "yes" ] || \ [ "$tas2764_quirks" = "no" ]; then echo echo "!! IMPORTANT !!" echo "Your audio configuration is in an invalid state. It is likely that you tried to" echo "enable speakers early, despite numerous and very explicit warnings not to do so." echo "Potential reason(s) you are seeing this message: " ( [ "$pro_audio" = "yes" ] && echo " - The Pro Audio profile is/was enabled for the internal speakers." [ "$old_conf" = "yes" ] && echo " - You have files in /etc/ from a prerelease version of asahi-audio." [ "$racy_build" = "yes" ] && echo " - You have files in /usr/share/ from a prerelease version of asahi-audio." [ "$bad_macaudio_params" = "yes" ] && echo " - You have tried to manually circumvent our kernel-level safety controls." [ "$tas2764_quirks" = "no" ] && echo " - Required speaker codec settings are not being applied." ) echo "Please go to https://github.com/AsahiLinux/docs/wiki/Undoing-early-speaker-support-hacks for fixes." echo "Do NOT file audio-related bugs until you have tried ALL fixes suggested at the page above." echo "Your bugs will be ignored and you will not be assisted." fi plat="$(cat /proc/device-tree/compatible | sed -re 's/.*apple,(t....).*/\1/g')" ver="$(tr -d '\0' /dev/null 2>&1; then echo echo "** WARNING! **" echo "The asahi-platform-metapackage package is not installed, you may be missing" echo "required platform dependencies. See https://discussion.fedoraproject.org/t/95301" echo "for how to fix it." fi fi } if [ -z "$1" ]; then diagnose "$HOME/asahi-diagnose-$(date +%Y%m%d-%H%M%S).txt" elif [ "$1" = "-" ]; then diagnose /dev/stdout else diagnose "$1" fi AsahiLinux-asahi-scripts-5093f09/asahi-fwupdate000077500000000000000000000021131474670455400214550ustar00rootroot00000000000000#!/bin/sh # SPDX-License-Identifier: MIT set -eu unset PYTHON [ -e /etc/default/asahi-fwupdate ] && . /etc/default/asahi-fwupdate : "${ASAHIFW:=}" : "${VENDORFW:=}" : "${VENDORFWTMP:=/run/.vendorfw-tmp}" : "${PYTHON:=/usr/bin/python3}" if [ -e "$(dirname "$0")"/functions.sh ]; then . "$(dirname "$0")"/functions.sh else . /usr/share/asahi-scripts/functions.sh fi umount=false if [ -z "$ASAHIFW" ] && [ -z "$VENDORFW" ]; then mount_sys_esp /run/.system-efi ASAHIFW="/run/.system-efi/asahi/" VENDORFW="/run/.system-efi/vendorfw" umount=true fi if [ ! -e "${ASAHIFW}/all_firmware.tar.gz" ]; then echo "No firmware tarball found, skipping extraction" exit 0 fi if [ ! -d "$VENDORFW" ]; then mkdir -p "$VENDORFW" fi if [ ! -d "$VENDORFWTMP" ]; then mkdir -p "$VENDORFWTMP" fi echo "Upgrading vendor firmware package" asahi-fwextract "$ASAHIFW" "$VENDORFWTMP" rm -rf "$VENDORFW".new mv "${VENDORFWTMP}" "$VENDORFW".new rm -rf "$VENDORFW" mv "$VENDORFW".new "$VENDORFW" rm -rf "$VENDORFWTMP" echo "Firmware upgraded" $umount && umount /run/.system-efi true AsahiLinux-asahi-scripts-5093f09/dracut/000077500000000000000000000000001474670455400201125ustar00rootroot00000000000000AsahiLinux-asahi-scripts-5093f09/dracut/dracut.conf.d/000077500000000000000000000000001474670455400225425ustar00rootroot00000000000000AsahiLinux-asahi-scripts-5093f09/dracut/dracut.conf.d/10-asahi-noextgpu.conf000066400000000000000000000010011474670455400265530ustar00rootroot00000000000000# dracut config fragment to omit external PCIe GPUs # as of June 2024 PCIe tunneling over USB4/TB is not supported so it is # pointless to include those. Even when PCIe tunneling works PCIe GPUs are # probably not suppported and using them as primary display will not be a # supported configuration. # # This saves over 60 MB of firmware files in the initramfs on # Fedora-Asahi-Remix (Fedora 40, Kernel 6.9). # TODO: omit Xe drivers once their build is enabled on arm64. omit_drivers+=" amdgpu nouveau radeon " AsahiLinux-asahi-scripts-5093f09/dracut/dracut.conf.d/10-asahi.conf000066400000000000000000000006241474670455400247160ustar00rootroot00000000000000# Modules necessary for using Linux on Apple Silicon Macs # are handled in the module kernel-modules-asahi since add_drivers can't # handle missing modules # dwc3 instantiates xHCI asynchronously. To make things like init=/bin/sh work where udev is no longer running, force load this one. force_drivers+=" xhci-plat-hcd " # For Apple firmware add_dracutmodules+=" asahi-firmware kernel-modules-asahi " AsahiLinux-asahi-scripts-5093f09/dracut/modules.d/000077500000000000000000000000001474670455400220045ustar00rootroot00000000000000AsahiLinux-asahi-scripts-5093f09/dracut/modules.d/91kernel-modules-asahi/000077500000000000000000000000001474670455400261675ustar00rootroot00000000000000AsahiLinux-asahi-scripts-5093f09/dracut/modules.d/91kernel-modules-asahi/module-setup.sh000066400000000000000000000020261474670455400311460ustar00rootroot00000000000000#!/bin/bash # called by dracut installkernel() { # For NVMe & SMC hostonly='' instmods apple-mailbox # For NVMe hostonly='' instmods nvme_apple # For USB and HID hostonly='' instmods pinctrl-apple-gpio # SMC core hostonly='' instmods macsmc macsmc-rtkit # For USB hostonly='' instmods \ i2c-apple \ i2c-pasemi-platform \ tps6598x \ apple-dart \ dwc3 \ dwc3-of-simple \ nvmem-apple-efuses \ phy-apple-atc \ xhci-plat-hcd \ xhci-pci \ pcie-apple \ gpio_macsmc # For RTC hostonly='' instmods rtc-macsmc simple-mfd-spmi spmi-apple-controller nvmem_spmi_mfd # For HID hostonly='' instmods spi-apple spi-hid-apple spi-hid-apple-of # For MTP HID hostonly='' instmods apple-dockchannel dockchannel-hid apple-rtkit-helper # For DP / HDMI audio hostonly='' instmods apple-sio # For DPTX and HDMI displays hostonly='' instmods mux-apple-display-crossbar phy-apple-dptx } AsahiLinux-asahi-scripts-5093f09/dracut/modules.d/99asahi-dev-modules/000077500000000000000000000000001474670455400254755ustar00rootroot00000000000000AsahiLinux-asahi-scripts-5093f09/dracut/modules.d/99asahi-dev-modules/install-asahi-dev-modules.sh000077500000000000000000000010021474670455400330000ustar00rootroot00000000000000#!/bin/sh # SPDX-License-Identifier: MIT type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh if [ ! -d /$(uname -r) ]; then return 0 fi DESTDIR="/sysroot/lib/modules/$(uname -r)" info ":: Asahi: Installing dev kernel modules to root filesystem..." if [ ! -e ${DESTDIR} ]; then if [ ! -w /sysroot ]; then error ":: Asahi: root fs not writable!" return 0 fi mkdir -p ${DESTDIR} fi mount -t tmpfs -o mode=0755,size=192m dev-modules /${DESTDIR} cp -pr /$(uname -r)/* ${DESTDIR}/ AsahiLinux-asahi-scripts-5093f09/dracut/modules.d/99asahi-dev-modules/link-asahi-dev-modules.sh000066400000000000000000000003451474670455400322750ustar00rootroot00000000000000#!/bin/sh # SPDX-License-Identifier: MIT type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh if [ -d /$(uname -r) ]; then info ":: Asahi: dev modules present, link them into system" ln -s /$(uname -r) /lib/modules/ fi AsahiLinux-asahi-scripts-5093f09/dracut/modules.d/99asahi-dev-modules/module-setup.sh000077500000000000000000000010271474670455400304570ustar00rootroot00000000000000#!/bin/sh # SPDX-License-Identifier: MIT # called by dracut check() { if [ -n "$hostonly" ] && [ ! -e /proc/device-tree/chosen/asahi,efi-system-partition ]; then return 0 elif [ -z "$hostonly" ]; then return 0 else return 255 fi } # called by dracut depends() { echo fs-lib return 0 } # called by dracut install() { inst_multiple cp ln mkdir mount inst_hook pre-udev 99 "${moddir}/link-asahi-dev-modules.sh" inst_hook pre-pivot 99 "${moddir}/install-asahi-dev-modules.sh" } AsahiLinux-asahi-scripts-5093f09/dracut/modules.d/99asahi-firmware/000077500000000000000000000000001474670455400250655ustar00rootroot00000000000000AsahiLinux-asahi-scripts-5093f09/dracut/modules.d/99asahi-firmware/install-asahi-firmware.sh000077500000000000000000000006761474670455400320000ustar00rootroot00000000000000#!/bin/sh # SPDX-License-Identifier: MIT type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh info ":: Asahi: Installing vendor firmware to root filesystem..." if [ ! -d /sysroot/lib/firmware/vendor ]; then warn ":: Asahi: Vendor firmware directory missing on the root filesystem!" return 1 fi mount -t tmpfs -o mode=0755 vendorfw /sysroot/lib/firmware/vendor cp -a /vendorfw/* /vendorfw/.vendorfw.manifest /sysroot/lib/firmware/vendor AsahiLinux-asahi-scripts-5093f09/dracut/modules.d/99asahi-firmware/load-asahi-firmware.sh000077500000000000000000000024251474670455400312430ustar00rootroot00000000000000#!/bin/sh # SPDX-License-Identifier: MIT type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh if [ -e /vendorfw ]; then info ":: Asahi: Vendor firmware was loaded by the bootloader" return 0 fi if [ ! -e /proc/device-tree/chosen/asahi,efi-system-partition ]; then info ":: Asahi: Missing asahi,efi-system-partition variable, firmware will not be loaded!" return 0 fi info ":: Asahi: Triggering early load of NVMe modules..." modprobe apple-mailbox modprobe nvme-apple for i in $(seq 0 50); do [ -e /sys/bus/platform/drivers/nvme-apple/*.nvme/nvme/nvme*/nvme*n1/ ] && break sleep 0.1 done if [ ! -e /sys/bus/platform/drivers/nvme-apple/*.nvme/nvme/nvme*/nvme*n1/ ]; then warn ":: Asahi: Timed out waiting for NVMe device" return 1 fi # If the above exists, hopefully the /dev device exists and this will work info ":: Asahi: Unpacking vendor firmware into initramfs..." VENDORFW="/run/.system-efi/vendorfw/" ( . /usr/share/asahi-scripts/functions.sh mount_sys_esp /run/.system-efi ) if [ ! -e "$VENDORFW/firmware.cpio" ]; then warn ":: Asahi: Vendor firmware not found in ESP." umount /run/.system-efi return 1 fi ( cd /; cpio --quiet -i < "$VENDORFW/firmware.cpio" ) info ":: Asahi firmware unpacked successfully" umount /run/.system-efi AsahiLinux-asahi-scripts-5093f09/dracut/modules.d/99asahi-firmware/module-setup.sh000077500000000000000000000016041474670455400300500ustar00rootroot00000000000000#!/bin/sh # SPDX-License-Identifier: MIT # called by dracut check() { if [ -n "$hostonly" ] && [ ! -e /proc/device-tree/chosen/asahi,efi-system-partition ]; then return 0 elif [ -z "$hostonly" ]; then return 0 else return 255 fi } # called by dracut depends() { echo fs-lib return 0 } # called by dracut installkernel() { instmods apple-mailbox nvme-apple vfat } # called by dracut install() { inst_dir "/lib/firmware" ln_r "/vendorfw" "/lib/firmware/vendor" asahiscriptsdir="/usr/share/asahi-scripts" inst_dir $asahiscriptsdir $DRACUT_CP -R -L -t "${initdir}/${asahiscriptsdir}" "${dracutsysrootdir}${asahiscriptsdir}"/* inst_multiple cpio cut dirname grep mkdir modprobe mount seq sleep umount inst_hook pre-udev 10 "${moddir}/load-asahi-firmware.sh" inst_hook cleanup 99 "${moddir}/install-asahi-firmware.sh" } AsahiLinux-asahi-scripts-5093f09/first-boot000077500000000000000000000024511474670455400206500ustar00rootroot00000000000000#!/bin/sh # SPDX-License-Identifier: MIT set -e root_dev=$(findmnt -n -o SOURCE /) efi_dev=$(findmnt -n -o SOURCE /boot/efi) if [ -e "$root_dev" ]; then echo "Randomizing root filesystem UUID..." tune2fs -U random "$root_dev" root_uuid="$(blkid -c /dev/null "$root_dev" -o export | grep '^UUID=')" echo "Root filesystem: $root_uuid" echo fi if [ -e "$efi_dev" ] && \ blkid "$efi_dev" | grep -q 'TYPE="vfat"'; then echo "Randomizing EFI system partition UUID..." # Ugly... why isn't there a command to do this? ssize="$(blockdev --getss "$efi_dev")" dd bs=1 seek=67 count=4 conv=notrunc if=/dev/urandom of="$efi_dev" dd bs=1 skip=67 seek=$((67+6*$ssize)) count=4 conv=notrunc if="$efi_dev" of="$efi_dev" efi_uuid="$(blkid -c /dev/null "$efi_dev" -o export | grep '^UUID=')" echo "EFI partition: $efi_uuid" echo fi if [ ! -z "$root_uuid" ] && [ ! -z "$efi_uuid" ]; then echo "Regenerating /etc/fstab..." tee /etc/fstab <&2 } warn() { echo "$@" 1>&2 } mount_sys_esp() { set -e mountpoint="$1" mkdir -p "$mountpoint" while grep -q " $mountpoint " /proc/mounts; do umount "$mountpoint" done esp_uuid="$(cat /proc/device-tree/chosen/asahi,efi-system-partition 2>/dev/null | sed 's/\x00//')" if [ -e /boot/efi/.builder ] || [ -e /boot/.builder ] || [ -z "$esp_uuid" ]; then if [ -e "/boot/efi/m1n1" ]; then bootmnt="/boot/efi" elif [ -e "/boot/m1n1" ]; then bootmnt="/boot" else warn "ESP not found and cannot determine ESP PARTUUID." warn "Make sure that your m1n1 has the right asahi,efi-system-partition configuration," warn "or that your ESP is mounted at /boot/efi or /boot." return 1 fi mount --bind "$bootmnt" "$mountpoint" warn "System ESP not identified in device tree, using $bootmnt" else mount "PARTUUID=$esp_uuid" "$mountpoint" fi dev="$(grep "$mountpoint" /proc/mounts | cut -d" " -f1)" info "Mounted System ESP $dev at $mountpoint" } mount_boot_esp() { set -e mountpoint="$1" mkdir -p "$mountpoint" while grep -q " $mountpoint " /proc/mounts; do umount "$mountpoint" done if [ -e "/boot/efi/efi/boot" ]; then mount --bind "/boot/efi" "$mountpoint" elif [ -e "/boot/efi/boot" ]; then mount --bind "/boot" "$mountpoint" else esp_uuid="$(cat /proc/device-tree/chosen/asahi,efi-system-partition | sed 's/\x00//')" if [ -z "$esp_uuid" ]; then echo "Boot ESP not found and cannot determine ESP PARTUUID." echo "Make sure your ESP is mounted at /boot/efi or /boot," echo "or that your m1n1 has the right asahi,efi-system-partition configuration." return 1 fi mount "PARTUUID=$esp_uuid" "$mountpoint" fi info "Mounted Boot ESP at $mountpoint" } AsahiLinux-asahi-scripts-5093f09/initcpio/000077500000000000000000000000001474670455400204465ustar00rootroot00000000000000AsahiLinux-asahi-scripts-5093f09/initcpio/hooks/000077500000000000000000000000001474670455400215715ustar00rootroot00000000000000AsahiLinux-asahi-scripts-5093f09/initcpio/hooks/asahi000066400000000000000000000033241474670455400226030ustar00rootroot00000000000000#!/usr/bin/ash # SPDX-License-Identifier: MIT run_earlyhook() { if [ -e /vendorfw ]; then msg ":: Asahi: Vendor firmware was loaded by the bootloader" return 0 fi if [ ! -e /proc/device-tree/chosen/asahi,efi-system-partition ]; then msg ":: Asahi: Missing asahi,efi-system-partition variable, firmware will not be loaded!" return 1 fi msg ":: Asahi: Triggering early load of NVMe modules..." modprobe apple-mailbox modprobe nvme-apple modprobe xhci-plat-hcd for i in $(seq 0 50); do [ -e /sys/bus/platform/drivers/nvme-apple/*.nvme/nvme/nvme*/nvme*n1/ ] && break sleep 0.1 done if [ ! -e /sys/bus/platform/drivers/nvme-apple/*.nvme/nvme/nvme*/nvme*n1/ ]; then err "Timed out waiting for NVMe device" return 1 fi # If the above exists, hopefully the /dev device exists and this will work msg ":: Asahi: Unpacking vendor firmware into initramfs..." VENDORFW="/run/.system-efi/vendorfw/" ( . /usr/share/asahi-scripts/functions.sh mount_sys_esp /run/.system-efi ) if [ ! -e "$VENDORFW/firmware.cpio" ]; then msg ":: Asahi: Vendor firmware not available in ESP!" umount /run/.system-efi return 1 fi ( cd /; cpio -i < "$VENDORFW/firmware.cpio" ) umount /run/.system-efi msg ":: Asahi: Vendor firmware unpacked successfully" } run_latehook() { [ -e /vendorfw ] || return msg ":: Asahi: Copying vendor firmware to tmpfs under root filesystem..." mkdir -p /new_root/lib/firmware/vendor mount -t tmpfs -o mode=0755 vendorfw /new_root/lib/firmware/vendor cp -r /vendorfw/* /vendorfw/.vendorfw.manifest /new_root/lib/firmware/vendor } AsahiLinux-asahi-scripts-5093f09/initcpio/install/000077500000000000000000000000001474670455400221145ustar00rootroot00000000000000AsahiLinux-asahi-scripts-5093f09/initcpio/install/asahi000066400000000000000000000022261474670455400231260ustar00rootroot00000000000000#!/bin/bash # SPDX-License-Identifier: MIT build() { local filter # For NVMe & SMC add_module apple-mailbox? # For NVMe add_module nvme-apple? # For USB and HID add_module pinctrl-apple-gpio? # SMC core map add_module macsmc? macsmc-rtkit? # For USB map add_module i2c-pasemi-platform? tps6598x? apple-dart? dwc3? dwc3-of-simple? \ nvmem-apple-efuses? phy-apple-atc? xhci-plat-hcd? xhci-pci? pcie-apple? gpio_macsmc? # For HID map add_module spi-apple? spi-hid-apple? spi-hid-apple-of? # For RTC map add_module rtc-macsmc? simple-mfd-spmi? spmi-apple-controller? \ nvmem_spmi_mfd? # For MTP HID map add_module apple-dockchannel? dockchannel-hid? apple-rtkit-helper? # Hook dependencies add_full_dir /usr/share/asahi-scripts # Firmware update script add_runscript add_dir /lib/firmware add_symlink /lib/firmware/vendor /vendorfw } help() { cat < /tmp/grub-core.cfg <"$m1n1config" if [ -e "$CONFIG" ]; then info "Reading m1n1 config from $CONFIG:" while read line; do case "$line" in "") ;; \#*) ;; chosen.*=*|display=*) echo "$line" >> "$m1n1config" info " Option: $line" ;; *) warn " Ignoring unknown option: $line" ;; esac done <$CONFIG fi if [ -z "$TARGET" ]; then mount_sys_esp /run/.system-efi TARGET="/run/.system-efi/m1n1/boot.bin" umount=true fi cat "$M1N1" $DTBS >"${TARGET}.new" gzip -c "$U_BOOT" >>"${TARGET}.new" cat "$m1n1config" >>"${TARGET}.new" [ -e "$TARGET" ] && mv -f "$TARGET" "${TARGET}.old" mv -f "${TARGET}.new" "$TARGET" echo "m1n1 updated at ${TARGET}" $umount && umount /run/.system-efi true