Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save crazypenguincode/4af2de4da5ad41c5771f4114363e13d5 to your computer and use it in GitHub Desktop.
Save crazypenguincode/4af2de4da5ad41c5771f4114363e13d5 to your computer and use it in GitHub Desktop.
Linux on MacBook Pro Late 2016 (with Touchbar)

Introduction

This is about documenting getting Linux running on the late 2016 MPB's; the focus is mostly on the MacBookPro13,3 (15inch model), but I try to make it relevant and provide information for MacBookPro13,1 and MacBookPro13,2 (13inch models) too. I'm currently using Fedora 25, but most the things should be valid for other recent distros even if the details differ. The kernel version is 4.9.x (after latest update).

The state of linux on the MBP (with particular focus on MacBookPro13,2) is also being tracked on https://github.com/Dunedan/mbp-2016-linux .

Summary Of Current State

What works

  • Booting (i.e Grub etc)
  • Recognizes disk on MacBookPro13,3; MacBookPro13,2 and MacBookPro13,1 need kernel patch
  • Keyboard, touchpad, and basic touchbar functionality
  • HiDPI detection
  • Accelerated video
  • Screen brightness control
  • WiFi in a very limited fashion
  • USB
  • Sensors (install lm_sensors package)
  • Camera

What doesn't work

  • Suspend/Resume
  • Keyboard backlight (always off)
  • Audio (two cards show up, and intel driver is loaded, but no sound)

Untested

  • Thunderbolt
  • DisplayPort
  • Bluetooth

Details

Booting

One kernel param necessary to boot properly: intremap=nosid. E.g.

sudo sed -i 's/\(GRUB_CMDLINE_LINUX=.*\)"/\1 intremap=nosid"/' /etc/default/grub
sudo grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg

Also, MacBookPro13,1 and MacBookPro13,2 (13inch models) have the Apple NVMe controller and hence need the attached kernel patch (if running a kernel < 4.11) in order for the disk to be correctly recognized (MacBookPro13,3 uses a Samsung NVMe controller which is automatically detected correctly). Instead of patching you can also do the following (for distros using something other than dracut to create the initrd you'll need to adjust the 2nd and 3rd lines appropriately):

echo 'install nvme /sbin/modprobe --ignore-install nvme $CMDLINE_OPTS; echo 106b 2003 > /sys/bus/pci/drivers/nvme/new_id' | sudo tee /etc/modprobe.d/nvme.conf
echo 'force_drivers+="nvme"' | sudo tee /etc/dracut.conf.d/disk.conf
sudo dracut --force --kver <kernel-version>

If you are booting a live CD or similar with a kernel < 4.9 then you will also need to add the nomodeset kernel parameter to your kernel line; you will then not have proper HiDPI detection or accelerated graphics.

Keyboard/Touchpad/Touchbar

For this we need the drivers from https://github.com/roadrunner2/macbook12-spi-driver.git (a clone of https://github.com/cb22/macbook12-spi-driver which includes a preliminary touchbar driver and keyboard fixes). The following commands set this up.

First some extra packages:

sudo dnf install git kernel-devel acpica-tools patch

Get and build the driver:

git clone https://github.com/roadrunner2/macbook12-spi-driver.git
pushd macbook12-spi-driver
git checkout touchbar-driver-hid-driver
make
sudo mkdir /lib/modules/`uname -r`/custom/
sudo cp applespi.ko appletb.ko /lib/modules/`uname -r`/custom/
sudo depmod
popd

Patch up the DSDT:

mkdir dsdt
pushd dsdt

sudo cp /sys/firmware/acpi/tables/DSDT dsdt.orig
sudo cp /sys/firmware/acpi/tables/SSDT* .
sudo chown ${USER}:$GROUP *
iasl -e SSDT* -d dsdt.orig

mv ...the-attached-dsdt.dsl.patch... dsdt.dsl.patch
patch -b < dsdt.dsl.patch

iasl -tc dsdt.dsl
sudo mkdir -p /usr/local/lib/firmware/acpi/
sudo cp dsdt.aml /usr/local/lib/firmware/acpi/
popd

Now rebuild the initramfs:

sudo mv /boot/initramfs-`uname -r`.img{,.orig}
sudo mv ...the-attached-keyboard.conf... /etc/dracut.conf.d/keyboard.conf
sudo sed -i.orig 's/CONFIG_ACPI_INITRD_TABLE_OVERRIDE/CONFIG_ACPI_TABLE_UPGRADE/g' /usr/bin/dracut
sudo dracut

Next we need to set the proper dpi for the touchpad:

sudo cp ...the-attached-61-evdev-local.hwdb... /etc/udev/hwdb.d/61-evdev-local.hwdb

Finally, reboot to get the new DSDT and other changes:

sudo reboot

Note: on distros using mkinitramfs instead of dracut you'll want to do the following instead of using keyboard.conf

  • add the modules (listed in keyboard.conf) to /etc/initramfs-tools/modules
  • copy the dsdt.aml to /etc/initramfs-tools/DSDT.aml

Screen Brightness Control

Screen brightness control works out of the box on MacBookPro13,1 and MacBookPro13,2, but requires a kernel patch on MacBookPro13,3 (see also Dunedan/mbp-2016-linux#2). The following will create and install the patched apple-gmux:

mkdir apple-gmux
pushd apple-gmux

curl -o apple-gmux.patch 'https://bugzilla.kernel.org/attachment.cgi?id=192601'
curl -o apple-gmux.c 'https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/plain/drivers/platform/x86/apple-gmux.c?id=refs/tags/v4.9.11'

patch < apple-gmux.patch

echo -e '
obj-m += apple-gmux.o

all:
\tmake -C /lib/modules/`uname -r`/build M=`pwd` modules
' > Makefile
make

mod=$(ls /lib/modules/`uname -r`/kernel/drivers/platform/x86/apple-gmux.ko*)
sudo mv $mod{,.orig}
sudo cp apple-gmux.ko /lib/modules/`uname -r`/kernel/drivers/platform/x86/
sudo depmod

popd

sudo reboot

Other

The touchpad defaults to using the bottom-left corner for right-clicks - to get 2-finger right click, install the Gnome tweak tool and change it in there.

WiFi

The brcmfmac driver is automatically loaded. However, there are a number of issues with it:

  • it only does 2.4GHz - no 5GHz channels are visible
  • it has an extremely low sensitivity - you must be within a few feet of the base station, and even at 5 feet distance it shows a weak signal.
  • it stops working after 10 or 15 or so minutes; turning WiFi off, waiting a several minutes, and then turning it back on generally gets it working again. Maybe a thermal issue?

Bug report: https://bugzilla.kernel.org/show_bug.cgi?id=193121

Display

The amdgpu driver works well and is automatically loaded on MacBookPro13,3. On the 13 inch models the use of the intel needs to be forced (see first comment below).

Camera

For MacBookPro13,3 you need the following:

echo "options uvcvideo quirks=0x100" > /etc/modprobe.d/uvcvideo.conf

For MacBookPro13,[12] see Dunedan/mbp-2016-linux#15.

# MacBookPro13,* (Late 2016)
evdev:name:Apple SPI Touchpad:dmi:*:svnAppleInc.:pnMacBookPro13,1:*
evdev:name:Apple SPI Touchpad:dmi:*:svnAppleInc.:pnMacBookPro13,2:*
EVDEV_ABS_00=::96
EVDEV_ABS_01=::94
EVDEV_ABS_35=::96
EVDEV_ABS_36=::94
evdev:name:Apple SPI Touchpad:dmi:*:svnAppleInc.:pnMacBookPro13,3:*
EVDEV_ABS_00=::96
EVDEV_ABS_01=::95
EVDEV_ABS_35=::96
EVDEV_ABS_36=::95
--- dsdt.dsl.orig 2017-01-14 06:09:53.435098814 -0800
+++ dsdt.dsl 2017-01-14 23:15:53.020864710 -0800
@@ -18,7 +18,7 @@
* Compiler ID "INTL"
* Compiler Version 0x20140424 (538182692)
*/
-DefinitionBlock ("", "DSDT", 2, "APPLE ", "MacBookP", 0x00150001)
+DefinitionBlock ("", "DSDT", 2, "APPLE ", "MacBookP", 0x00150002)
{
/*
* iASL Warning: There were 8 external control methods found during
@@ -7232,7 +7232,7 @@
Name (ABUF, ResourceTemplate ()
{
})
- If (!OSDW ())
+ If (OSDW ())
{
Return (UBUF) /* \_SB_.PCI0.SPI1.SPIT._CRS.UBUF */
}
--- a/drivers/nvme/host/pci.c 2017-01-22 21:49:03.710949755 -0800
+++ b/drivers/nvme/host/pci.c 2017-01-22 21:49:23.490761505 -0800
@@ -2121,6 +2121,7 @@
.driver_data = NVME_QUIRK_DELAY_BEFORE_CHK_RDY, },
{ PCI_DEVICE_CLASS(PCI_CLASS_STORAGE_EXPRESS, 0xffffff) },
{ PCI_DEVICE(PCI_VENDOR_ID_APPLE, 0x2001) },
+ { PCI_DEVICE(PCI_VENDOR_ID_APPLE, 0x2003) },
{ 0, }
};
MODULE_DEVICE_TABLE(pci, nvme_id_table);
# override the acpi with our patched one
acpi_override="yes"
acpi_table_dir="/usr/local/lib/firmware/acpi"
# load all drivers needed for the keyboard+touchpad
add_drivers+="applespi intel_lpss_pci spi_pxa2xx_platform appletb"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment