Daily driving DragonflyBSD on a 2017 Macbook Air
Dragonfly BSD mostly works on a Macbook Air (2017), provided you can source a very specific shim to allow replacing the (proprietary) broadcom wifi card, and can tolerate trackpad issues.
The 2017 macbook air is awful, but better than more contemporary macbooks in that the wireless card and SSD are user-replacable (although both really require adapters). I've ran Xubuntu on my laptop for a long while, and while it works, it always bothered me that I had to build a module for the broadcom wifi every time the kernel updated. Sure, DKMS does it for me - I still don't like it.
When I took the macbook apart to see what type of connector it used for the troublesome wifi card, I was bemused to see it was entirely proprietary.
Worse than propritary, it isn't even well documented. Most places will refer to it as "12+6 Pin", given the location of the gap in the edge connector of the wifi board. So trying to find an Atheros card, or an Intel card with that pinout is a lost cause. Interestingly, however, there's a derth of 12+6 Pin to M.2 A+E boards. This seems to be down to people using discarded 12+6 cards in hackintosh builds, as the card is naturally well supported in MacOS.
The existence of these apple-to-rest-of-the-world adapter cards led me to believe that the only thing different was the pinout, meaning that a largely trivial to design passive adapter would work in the other direction. Unfortunately, people using not MacOS on Macbooks is uncommon. People using not MacOS and in need of a different wifi card are even more so. This is a niche product.
fter an hour or so plugging in variations on 'airport to m2', '12+6 to a+e' and 'macbook air ngff', I finally found what I was looking for. Given the low price, I purchased the appropriate shape and began working out what M.2 A+E card was best supported on Dragonfly BSD.
The best supported wifi cards are, without a doubt, any card that is covered by Linux's ath9k driver. ath9k is completely free and open, and requires no microcode to operate. Unfortunately, ath9k cards don't cover 802.11ac, and they're typically mini-pci-e, rather than m.2. ath10k does support 802.11ac, and cards do come in the right form factor - but doesn't have a Dragonfly driver. There is (as far as I can gather) an ongoing project to bring support to FreeBSD, which will likely benefit Dragonfly. But this is far from being merged.
I combed through the manpages for a while, until I eventually found the iwm driver manpage. This would have been faster had the driver been listed on the Wikipedia page. I've since added it. The iwm driver covers the 9260 chipset - which is an M.2 A+E card readily available on Amazon UK. The card and the adapter match the form-factor of the original card, and work on Dragonfly with no issues (so far).
Audio support is unsurprisingly well-handled by loading sndhda on boot, however requires some tweaking to make the speakers (pcm2) work. The manpage specifically recommends playing with GPIO configuration, and a little trial and error will lead you to setting GPIO 0.
sysctl dev.hdaa.1.gpio_config=0=set
The only issue I haven't managed to work through is the trackpad, which insists on firing off right click and middle click events of its own accord.
Update : Sascha Wildner has been kind enough to get wsp merged into master, so the Macbook Air 2017 trackpad should now work by default on later releases of DragonflyBSD.
I ended up putting Xubuntu back on my macbook, just to give me something I could continue using while looking at the trackpad problem.
If you found this page looking for "trackpad" "dragonfly bsd" "macbook" - the problem I had was this: on random occasions, random button presses would fire. This was true both in X11 and on the console.
Debug output from moused showed that it was seeing these button press events from the device.
A helpful person on the mailing list recommended I try FreeBSD to see if the issue persisted there. Trying -CURRENT, which will become 13 at the time of writing, I observed the issue in X11, but not on the console. FreeBSD, unlike Dragonfly BSD, provides two drivers for Macbook touchpads - [[][wsp]] and [[][atp]].
The former for contemporary devices, the latter for older devices.
FreeBSD and Dragonfly BSD are two distinct operating systems, but given Dragonfly BSD originally diverged from FreeBSD, there's plenty shared code and co-operation between the two.
With that, I expected someone had attempted to port the wsp driver, and went about looking for mention of it on mailing lists or blogs. My search eventually brought me to this patch, bringing in both atp and wsp.
I'd built Dragonfly BSD from source before, but only to upgrade. I was also thrown off when the patch failed to apply, although I shouldn't have been given the patch was ~3 years old. Flicking through the wiki, and figuring out how to write a new kernel module, I yanked the wsp code from the patch and introduced it to my tree by hand. There's probably a better way to do that, and I'll learn it at some point I'm sure.
Having built the kernel and restarted, I was cautiously happy to find /dev/wsp0. Starting moused to provide /dev/sysmouse from /dev/wsp0, I was cautiously ecstatic to not see ghost clicks.
Starting xfce, I was relieved to find that not only did the cursor work, not send arbitrary clicks - it also had two-finger-right-click and two-finger-scrolling.
There's still some outstanding niggles. Keyboard backlight doesn't work, although I don't use it. Function keys also don't report themselves as anything other than F1-F12, so I've had to script around the keys I care about using intelbacklight and mixer.
I'd also like to see wsp upstreamed, but I don't have the knowledge to do that, and my impression from the mailing list is that not all Macbooks have this problem, so I don't know how specificly useful this patch it.
Power management is better than it used to be when it comes to Linux and BSDs - but there are still steps you can take to improve battery life. Here are some tweaks I've made to increase battery life on DragonflyBSD.
One glaring omission you may notice coming from FreeBSD or Linux is keyboard backlight support, fan speed control, and access to the various macbook-specific temperature sensors. On FreeBSD, support for these things is implemented by asmc(4).
This module has not been ported to DragonflyBSD. I'm considering putting up a bounty to encourage movement on this, but as I don't really use these things, I also may not.
Although we may not have asmc(4), we do have a lot of other things we can prod, owing to how much of the macbook is produced by Intel:
intel_backlight(1) provides command-line control of the display backlight. The lower the backlight, the less power used.
powerd(8) provides automatic CPU scaling based on CPU temperature (more on that below) and presence of an external power supply. In my experience, powerd is less extreme than MacOS's throttling with its default settings. However you can configure the thresholds and minimum/maximum clockrates as you like.
sysctl(8) can be used to tweak the C-states (power modes) your processor will drop into. Details on these C-states are available in a few places. State C2 is generally safe, and available everywhere. C3 can apparently cause issues with SMP scheduling, however I haven't observed this:
machdep.mwait.CX.idle=AUTODEEP
hw.acpi.cpu.cx_lowest=C3
iwm(4) provides a tunable to set the power management scheme. I leave this set to the default (balanced), however it can be set to low-power mode with the hw.iwm.power_scheme tunable.
usbconfig(8) can be used to force power states for USB devices. I very rarely use the SD card reader, so I typically turn it off. A trivial savings, but one I have little reason not to make.
[root@oolong /]# usbconfig
ugen0.1: 0x8086 XHCI root HUB at usbus0, cfg=0 md=HOST spd=SUPER (5.0Gbps) pwr=SAVE (0mA)
ugen0.2: vendor 0x8087 product 0x0025 at usbus0, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON (100mA)
ugen0.3: Apple Inc. Apple Internal Keyboard at usbus0, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON (500mA)
ugen0.4: Apple Card Reader at usbus0, cfg=0 md=HOST spd=SUPER (5.0Gbps) pwr=ON (224mA)
[root@oolong /]# usbconfig -d 0.4 power_off
[root@oolong /]# usbconfig
ugen0.1: 0x8086 XHCI root HUB at usbus0, cfg=0 md=HOST spd=SUPER (5.0Gbps) pwr=SAVE (0mA)
ugen0.2: vendor 0x8087 product 0x0025 at usbus0, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON (100mA)
ugen0.3: Apple Inc. Apple Internal Keyboard at usbus0, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON (500mA)
I made these changes a long time ago, so I don't have hard data to back up the impact this made to battery life. However, you yourself can gather some of that information using the corepower(4) driver to expose (at the very least) CPU package power usage:
[root@oolong /]# sysctl hw.sensors
hw.sensors.cpu0.temp0: 62.00 degC (node0 core0 temp), OK
hw.sensors.cpu1.temp0: 62.00 degC (node0 core1 temp), OK
hw.sensors.cpu2.temp0: 62.00 degC (node0 core0 temp), OK
hw.sensors.cpu3.temp0: 62.00 degC (node0 core1 temp), OK
hw.sensors.cpu_node0.temp0: 62.00 degC (node0 temp), OK
hw.sensors.cpu_node0.power0: 5.76 W (node0 Package Power)
hw.sensors.cpu_node0.power1: 0.54 W (node0 DRAM Power)
hw.sensors.cpu_node0.power2: 0.63 W (node0 Cores Power)
hw.sensors.cpu_node0.power3: 1.86 W (node0 Graphics Power)
hw.sensors.dev_idmax: 6