How I Ended Up Adding Deep Sleep to the M4 MacBook Air
In April I bought a MacBook Neo as a fun project. In November a patch series of mine taught the M4 MacBook Air to sleep properly under Linux.
This is how one led to the other.
Looking for a laptop
I’d been hunting for a new laptop since the start of the year. I love Apple’s build quality, but I wanted Linux.
I looked at a Framework 13, then bought an HP ZBook Ultra 14 G1a after watching geohot put one through his Laptop Olympics stream (where even an older M1 Max MacBook Pro still held its own) and reading his post about trying to replace his MacBook with it. He was running Omarchy on the ZBook, got its lid-closed sleep down to 0.2 W, and still concluded that “there’s no better laptop hardware than a MacBook”. He wrote off Linux on Apple Silicon anyway, since Asahi didn’t support M3 and newer and even on M1 couldn’t drive an external USB-C monitor, before tossing off an aside that aged well: “Btw, LLMs are super helpful at reverse engineering – it’s almost becoming fun again.”
My ZBook didn’t even get that far. On cold boots it hung at the “HP powered by Experiences” splash screen with the fan roaring, until a 90-second hard reset. It did that on a clean Windows install too, and a BIOS update didn’t fix it. It’s a known embedded-controller bug on that model, and it ruled out the NixOS dual boot I’d planned. I had it for about a week before sending it back.
On March 10 I posted:
Asahi linux + opencode + grok + opus RE, at least Mac is classier than HP G1A. What G1A? Yeah…
Eryk’s Neo
In early April my friend Eryk, a developer and a long-time Linux user, told me he’d bought a MacBook Neo. macOS was “passable”, and he expected Asahi Linux to take years to support the Neo’s A18 Pro. He chose it partly because it was cheap, and partly because he wanted a new chip to have fun with: Asahi had already done M1 and M2.
He wanted Linux on it. At the time I said I wanted someone to sponsor my AI tokens so I could help with Asahi.
There wasn’t much to go on. The earliest public attempt I found, asahi_neo, was a feasibility study for booting Linux through a shim inside Apple’s own kernel, and its README said “Nothing runs yet”. Eryk later sent me a Reddit thread where someone had taken first steps with m1n1, the Asahi bootloader, on the Neo. He still couldn’t get m1n1 to boot on his.
The camera came first
Meanwhile I was busy taking back a cheap security camera. On April 19 I had Thingino running on a TP-Link Tapo C210 and streaming video. I joked to Eryk that I was having the same fun for a thirtieth of the price of a Neo.
A couple of days later I bought one anyway. The Neo was cheap, it had the build quality I wanted, and getting Linux working on it looked like a fun project. The camera had just reminded me how good it feels to make a device my own.
A keyboard first
At first the Neo was just another host in my Nix configuration, running nix-darwin.
Bringing up a machine means a lot of rebooting, and a lot of that happens before any operating system can help. Boot pickers, recovery screens and firmware menus need a keyboard.
So the first thing I built for the Neo wasn’t kernel code.
It was a keyboard for before the operating system boots: a small board that looks like an ordinary USB keyboard to the Mac and takes commands over Bluetooth from another computer.
Its README from April 29 already asks whether the Neo accepts it as a real Apple Fn key in every boot stage.
A descendant of that keyboard still types into my test machines today.
Finding Aurora
By the end of the summer Eryk had found a group that wanted the same thing we did: Linux on the newest Macs, the Neo included. He joined Aurora before I did, working on the M3 and M4, and at the end of August he told me about it. A few days later I joined their Discord.
It has some extremely talented people. Bootloaders, kernel drivers, GPU drivers, firmware reverse engineering: for every layer of a Mac there’s someone who knows it deeply, and things move fast.
At the end of September I asked Eryk what I could do on the Neo. The Neo code wasn’t his, and he wasn’t going to hand me anything behind the team’s back, so I’d have to talk to them myself. I told him what I actually wanted: a Linux laptop whose battery lasts.
For me that’s mostly about sleep. My desktop never sleeps: I always have a bunch of ongoing projects open on it, and I hate losing that context and having to recreate my session after a reboot. I like being able to jump in and out. On a laptop, you only get that if closing the lid actually puts it to sleep, so you can open it back up later and pick up right where you left off instead of coming back to a dead battery or a fresh boot.
If someone else made that happen, great. It turned out that someone would partly be me.
NixOS on the Neo
By October, Aurora had Linux running on the Neo.
I started nixos-neo: composable NixOS support for the Neo, with an installer, EFI boot selection and the Wi-Fi kernel.
My first kernel patch fixed timekeeping in s2idle, the shallow sleep state, on the Neo. It was small, and it was merged the same day.
A panel that wouldn’t wake up
Then Erik (erikwb) posted good power numbers from the M4 MacBook Air. His patches power the display down while the panel is blanked, while it’s static, and for system sleep. I wanted the same saving on the Neo.
It didn’t translate. On the Neo the display domains went down and came back up cleanly, but the display itself never came back. To find out why, I had to understand the whole power cycle of the display coprocessor (DCP): the firmware that drives the panel, its mailboxes, its IOMMU and the power domains underneath. That was the rabbit hole.
Iterating in Aura
Rebooting into Linux for every experiment would have taken forever. Aura, Aurora’s bootloader, has a proxy mode: the Mac sits in the bootloader and another computer drives it over USB, reading and writing registers from Python.
So most of the DCP work happened there. Each experiment was a small script against a live machine: bring the firmware up, idle it, stop it, try one more register write, read back what happened. A watchdog brought the Neo back to a healthy Linux boot after each trial.
It was also where I spent most of my agent budget. Getting DCP to work burned through three of ChatGPT Astra’s usage-limit resets.
The write that faulted with no error
In early November I was trying to power the Neo’s display coprocessor down and up again. It’s also a prerequisite for real sleep: the display hardware has to be off before the SoC can go down.
After the firmware was idle and the coprocessor stopped, the very first write to its CPU power register faulted.
The exception said almost nothing: ESR 0xbe000000, FAR 0.
Apple’s error registers are locked, so there was nothing more to read.
The obvious question was whether the write itself was wrong. A capture under macOS showed macOS making the identical write successfully. So the write was right, and something macOS did beforehand was missing.
The device tree had the first clue: the display’s DART (Apple’s IOMMU) is assigned a clock-protection slice tied to the display CPU domain. It turned out the hardware expects a strict power-down order before that domain can go off:
- disable the DART’s streams;
- run the power-down flush and wait for it;
- clear the clock-protection bit for that slice (
0x12to0x2); - only then touch the CPU power register.
Four register writes from the Aura proxy, and the fault was gone. The CPU register read back the same value as in the macOS capture.
From the first fault to the working sequence took about two hours and forty minutes, with the Neo in the loop the whole time and a coding agent doing much of the digging. None of it was visible at the fault itself. Every piece was wired into the device tree and the platform’s power-down sequence, but you had to know where to look.
While I was in there, I also found that the display coprocessor has a second mailbox with its own sleep handshake, which macOS completes before the main firmware goes to sleep.
Sharing it
dj, one of Aurora’s maintainers, was working on deep sleep for the Neo at the same time and had hit the same fault. I posted the clock-protection sequence on Aurora’s Discord in the middle of the night. Eight minutes later dj replied that it got past the fault. I sent the second mailbox’s handshake in between, and a few minutes later powering DCP off was working without errors.
That’s my favourite part of working on this project. Findings move from one machine to another, and from one person to another, in minutes.
Moving to the M4 Air
By then I had an M4 MacBook Air as well. After the Neo, I’d started to believe an Air could be a usable Linux laptop for my girlfriend, and I knew that working on it would give me more to contribute to Aurora. She uses Ubuntu on her old laptop, so I’ve started an Ubuntu setup for the Air too. It boots to a desktop, and it’s still a work in progress.
dj was making fast progress on deep sleep for the Neo, and I didn’t want to race them on the same machine. So I took the DCP work to the Air, where Erik’s panel work had started.
The same clock-protection trick, on a different slice, let me power the Air’s display coprocessor fully down while the panel was blanked. That became my first display patch for the Air.
With DCP working on the Air, and dj getting the Neo to sleep, the next step was obvious. I tried to make the whole Air sleep.
macOS under a hypervisor
The best reference for how a Mac sleeps is macOS itself. dj had written a hypervisor in Aura that boots stock macOS as a guest on the Neo, so every register access it makes can be watched. I ported it to the M4 Air. It booted macOS to a working desktop on the first run, and the port was merged into Aura.
With it I could trace macOS’s own path into and out of sleep: the 88 register writes it makes on the way back up, and the steps it takes with the power-management chip after the commit. That trace answered questions I would otherwise have had to guess at, and the M4 sleep work leaned on it throughout.
Deep sleep on these machines isn’t a single switch. iBoot leaves “reconfig programs” in always-on SRAM, and a small engine runs them to take the SoC down and bring it back. Every program arms a five-second watchdog as its first step.
My first attempts reset about five seconds in. Decoding iBoot’s programs out of SRAM showed why: none of them had started. The boot core’s power-gate bit was clear, because the Air’s device tree had no description of the cluster power gates that the Neo’s had. With that node added, the watchdog stopped firing, and the Air went somewhere it hadn’t been before.
The first full resume needed more than that:
- the system-level cache had to be off, until a hypervisor trace showed how macOS drains it;
- the radio host had to be off, until Erik’s radio patches taught it to sleep;
- the alarm that wakes the machine lives in the power-management chip, and its interrupt had to be wired up before it could wake anything.
By then it was a matter of making each subsystem survive the trip: USB, Wi-Fi, Bluetooth, the GPU. Eventually Wi-Fi, Bluetooth and the GPU all came back together, and the Air drew about 0.09 W asleep.
The series ended up as 52 commits. It built on dj’s sleep work for the Neo, and it folded in Erik’s radio and dock patches. dj reviewed it, Ryan’s rework of the per-SoC sleep code landed underneath it, and it was merged on November 13.
Along the way I wrote up what I’d found for axxzy, who was bringing deep sleep up on an M4 Max stuck in a similar place. Their M4 Max series merged too.
After that, Aurora added me to the organisation and its developer channel.
Since then
Sleep doesn’t stay finished.
Since my series landed, the shared sleep code was reworked for newer chips and Aurora moved the Air to the macOS 27.2 firmware, where Ryan had to re-wire deep sleep for both the internal and external display processors to get it sleeping again on main.
Sleep also shook out a lot of other things, all of them merged since:
- external displays report their EDID and keep working across a deep sleep;
- the headphone jack works again after waking;
- the Neural Engine gives memory and address space back after a program closes, parks itself when idle, and recovers cleanly if a program hangs it, at runtime or across sleep.
I have history with the first of those. The monitors on my desktop used to hang the whole machine when they woke up, and back then my only fix was a smart socket that cut their power.
The Neural Engine turned into a project of its own.
On these machines a bad Neural Engine program doesn’t just compute the wrong answer: it can hang the whole laptop.
So I started vane, an open compiler and safety verifier for it under Aurora Silicon, written in Lean 4 with proofs.
It is still in progress: it already has an ONNX and SafeTensors frontend and compiles multi-task graphs into Neural Engine programs verified directly on Linux hardware through accel/ane.
Nothing is emitted unless it passes static safety checks on bitfield bounds, tiling, L2 SRAM footprints and multi-task memory hazards, backed by Lean 4 soundness proofs.
More on that when it’s further along.
Making this kind of progress is addictive. Soon after, I bought an M5 MacBook Air so I could keep contributing to Aurora. It booted NixOS the day it arrived, and I had it sleeping before the day was out, though not on the first try. The first real sleep reset the machine seconds after it went down, and every wake after that reset before a single core came back. I put progress markers into the boot chain to see how far each wake got, and tried another tester’s setup, which wouldn’t even boot on mine. The fix turned out to be an Aura change by m0d16l14n1 that takes over the external display processors iBoot leaves running. I tested it against Aura without it, wired deep sleep into my NixOS support for the M5 as a single option, and ran it through 50 wakes in a row, with Wi-Fi back every time.
It’s about the loop
Nearly all of this was done with coding agents. I’ve written a series about what that’s like.
The biggest lesson is one Andrej Karpathy made in an interview this March: to get the most out of these tools, remove yourself as the bottleneck. His autoresearch project is the extreme version, an agent left to run training experiments on its own overnight. A clanker is only as fast as the loop it runs in. If every experiment needs me to press a button, look at a screen or reboot a machine, the clanker spends most of its time waiting for me.
So most of my effort went into building loops the clanker could close on its own.
For DCP on the Neo, that loop was the Aura proxy. The clanker wrote an experiment, ran it against the live machine over USB, read the registers back, and a watchdog returned the Neo to a healthy Linux boot afterwards. I didn’t have to touch the laptop between trials.
For the Air’s sleep work, the loop needed more parts, because a machine that fails to wake can’t report anything:
- the Air sets its own wake alarm before each sleep, so a good sleep ends by itself;
- when a wake hangs, the Neo restarts the Air over the USB-C cable between them, with a vendor message that needs no cooperation from the Air;
- the Neo’s camera faces the Air’s screen, so the clanker can see what the Air shows;
- the scriptable keyboard types into the Air when there’s no network;
- progress markers written to the power-management chip survive a reset, so after each failure the clanker reads how far the last attempt got.
With that in place, one sleep attempt was a single command, and a failed attempt cost a minute instead of my attention. The M5’s 50-wake stress test ran unattended too.
My job moved from running experiments to deciding which ones were worth running, and what their results meant. Karpathy makes that point too: as long as models stay jagged, you need to be in the loop. The clanker reads device trees, decodes traces and keeps a dozen experiments straight. I decide what is true, and the hardware has the last word.