|
| 1 | +# SPDX-License-Identifier: MIT |
| 2 | +import subprocess, json, datetime, logging, sys |
| 3 | +from util import * |
| 4 | + |
| 5 | +BUGGY_SFR_MIN = "14.0" |
| 6 | + |
| 7 | +ALLOWED_MACOS_MIN = "14.1.1" |
| 8 | + |
| 9 | +PROMOTION_DEVICES = { |
| 10 | + "j314cap", |
| 11 | + "j314sap", |
| 12 | + "j316cap", |
| 13 | + "j316sap", |
| 14 | + "j414cap", |
| 15 | + "j414sap", |
| 16 | + "j416cap", |
| 17 | + "j416sap", |
| 18 | + "j514cap", |
| 19 | + "j514sap", |
| 20 | + "j516cap", |
| 21 | + "j516sap", |
| 22 | +} |
| 23 | + |
| 24 | +def get_boottime(): |
| 25 | + p = subprocess.run(["sysctl", "-n", "kern.boottime"], capture_output=True, check=True) |
| 26 | + ts = int(p.stdout.split(b"sec = ")[1].split(b",")[0]) |
| 27 | + dt = datetime.datetime.fromtimestamp(ts, datetime.timezone.utc) |
| 28 | + logging.info(f"System boot time: {dt}") |
| 29 | + return dt |
| 30 | + |
| 31 | +def get_logs(start, process): |
| 32 | + logging.info(f"Getting {process} system logs") |
| 33 | + start_ts = int(start.timestamp()) |
| 34 | + p = subprocess.run(["log", "show", "-p", process, |
| 35 | + "--start", f"@{start_ts}", "--style", "json", |
| 36 | + "--timezone", "utc"], |
| 37 | + capture_output=True, check=True) |
| 38 | + l = json.loads(p.stdout) |
| 39 | + for entry in json.loads(p.stdout): |
| 40 | + ts = entry["timestamp"].replace("+0000", "+00:00") |
| 41 | + dt = datetime.datetime.fromisoformat(ts) |
| 42 | + yield (dt, entry["eventMessage"]) |
| 43 | + |
| 44 | +def get_startup_display_mode(): |
| 45 | + logging.info("get_startup_display_mode()") |
| 46 | + boot_time = get_boottime() |
| 47 | + startup = False |
| 48 | + for ts, message in get_logs(boot_time, "WindowServer"): |
| 49 | + logging.info(f"Log: {ts} {message}") |
| 50 | + delta = ts - boot_time |
| 51 | + if delta > datetime.timedelta(seconds=10): |
| 52 | + logging.warning("Failed to find startup/mode logs for WindowServer") |
| 53 | + break |
| 54 | + if "Server is starting up" in message: |
| 55 | + assert not startup |
| 56 | + startup = True |
| 57 | + if startup and "Display 1 current mode" in message: |
| 58 | + mode = int(message.split("[")[1].split(" ")[0]) |
| 59 | + logging.info(f"Internal panel boot mode: {mode}") |
| 60 | + return mode |
| 61 | + |
| 62 | + return None |
| 63 | + |
| 64 | +def request_upgrade(): |
| 65 | + p_error("Mismatched System Firmware / System Recovery detected!") |
| 66 | + print() |
| 67 | + p_warning("You have a machine with a ProMotion display, with a System Firmware version") |
| 68 | + p_warning("newer than 14.0 and a System Recovery version older than 14.0. Due to a") |
| 69 | + p_warning("critical macOS bug, this combination can lead to an unbootable system under") |
| 70 | + p_warning("certain conditions.") |
| 71 | + print() |
| 72 | + p_plain("Your machine is not currently in imminent danger, but will be safer if you") |
| 73 | + p_plain("upgrade to macOS Sonoma 14.1.1 or later. With this version, Apple added a") |
| 74 | + p_plain("temporary workaround that will make it harder to hit the bug in practice.") |
| 75 | + print() |
| 76 | + p_message("Please upgrade your system to macOS 14.1.1 or later and run this installer") |
| 77 | + p_message("again to continue. Do NOT change your display configuration until the upgrade") |
| 78 | + p_message("is complete.") |
| 79 | + print() |
| 80 | + |
| 81 | +def sadness(sysinfo): |
| 82 | + p_error("Your machine is affected by a critical macOS bug!") |
| 83 | + print() |
| 84 | + p_warning("You have a machine with a ProMotion display, with a System Firmware version") |
| 85 | + p_warning("newer than 14.0 and a System Recovery version older than 14.0. Due to a") |
| 86 | + p_warning("critical Apple bug, this combination can lead to an unbootable system under") |
| 87 | + p_warning("certain conditions.") |
| 88 | + print() |
| 89 | + if split_ver(sysinfo.sros_ver) < split_ver(BUGGY_SFR_MIN): |
| 90 | + p_error("We have determined that your machine is affected and currently has an") |
| 91 | + p_error("inoperable System Recovery. This is a dangerous condition that can make it") |
| 92 | + p_error("impossible to recover from certain situations. Installing Asahi Linux is also") |
| 93 | + p_error("not possible in this state.") |
| 94 | + else: |
| 95 | + p_error("We have determined that your machine is affected and would not be able to") |
| 96 | + p_error("successfully complete an Asahi Linux installation, as it cannot boot older") |
| 97 | + p_error("versions of macOS Recovery in this state.") |
| 98 | + print() |
| 99 | + p_error("We cannot continue with the install. Sorry. You will have to wait for Apple") |
| 100 | + p_error("to fix this properly in a future update. This bug is entirely outside of our") |
| 101 | + p_error("control and there is no easy workaround at this time.") |
| 102 | + print() |
| 103 | + p_plain("More information:") |
| 104 | + print() |
| 105 | + p_plain( f" {col(BLUE, BRIGHT)}https://github.com/AsahiLinux/docs/wiki/macOS-Sonoma-Boot-Failures{col()}") |
| 106 | + |
| 107 | +def you_are_safe(main): |
| 108 | + p_plain("Good news! Your machine should be unaffected by the critical ProMotion") |
| 109 | + p_plain("boot failure bug at this time. If you have any other versions of macOS") |
| 110 | + p_plain("installed side-by-side, we strongly recommend not booting them until") |
| 111 | + p_plain("Apple properly and fully fixes this bug, as that could cause the issue") |
| 112 | + p_plain("to trigger and your machine to become unbootable. Asahi Linux installs") |
| 113 | + p_plain("are safe and will not cause any danger to your system.") |
| 114 | + print() |
| 115 | + p_message("Press enter to continue.") |
| 116 | + main.input() |
| 117 | + |
| 118 | +def run_checks(main): |
| 119 | + if main.sysinfo.device_class not in PROMOTION_DEVICES: |
| 120 | + return |
| 121 | + |
| 122 | + if split_ver(main.sysinfo.sfr_ver) < split_ver(BUGGY_SFR_MIN): |
| 123 | + return |
| 124 | + |
| 125 | + p_progress("Checking whether your machine is affected by critical Apple bugs...") |
| 126 | + print() |
| 127 | + |
| 128 | + hz = main.sysinfo.get_refresh_rate() |
| 129 | + if hz is None: |
| 130 | + p_warning("Could not check ProMotion display status") |
| 131 | + p_plain("This probably means your laptop lid is closed. Please open it and try again.") |
| 132 | + p_plain("(You're going to have to use the power button soon anyway!)") |
| 133 | + print() |
| 134 | + sys.exit(1) |
| 135 | + |
| 136 | + p_info(f" Current display refresh rate: {col()}{hz} Hz") |
| 137 | + print() |
| 138 | + if hz != 120.0: |
| 139 | + p_error("Your display is not set to ProMotion mode (120 Hz). Please change your") |
| 140 | + p_error("display refresh rate to ProMotion mode in System Settings, then reboot") |
| 141 | + p_error("your machine with the lid open and try again.") |
| 142 | + print() |
| 143 | + p_error("Due to a critical Apple bug, it is not safe to install multiple operating") |
| 144 | + p_error("systems on your Mac with a non-ProMotion refresh rate configured.") |
| 145 | + print() |
| 146 | + sys.exit(1) |
| 147 | + |
| 148 | + mode = get_startup_display_mode() |
| 149 | + if mode is None: |
| 150 | + p_warning("Could not check boot-time display configuration") |
| 151 | + p_plain("This can happen if you have not rebooted your machine in several days.") |
| 152 | + p_plain("Please reboot your machine with the laptop lid open, then try again.") |
| 153 | + print() |
| 154 | + sys.exit(1) |
| 155 | + |
| 156 | + if split_ver(main.sysinfo.macos_ver) < split_ver(ALLOWED_MACOS_MIN): |
| 157 | + if mode != 2: |
| 158 | + p_warning("Mismatch between screen boot mode and current screen mode detected.") |
| 159 | + print() |
| 160 | + p_plain("Please reboot your machine and try again.") |
| 161 | + print() |
| 162 | + else: |
| 163 | + request_upgrade() |
| 164 | + sys.exit(1) |
| 165 | + |
| 166 | + if mode == 2: |
| 167 | + you_are_safe(main) |
| 168 | + else: |
| 169 | + sadness(main.sysinfo) |
| 170 | + sys.exit(1) |
0 commit comments