Skip to content

Instantly share code, notes, and snippets.

@rob-hills
Last active November 16, 2024 22:55
Show Gist options
  • Save rob-hills/9134b7352ee7471c4d4f4fbd6454c4b9 to your computer and use it in GitHub Desktop.
Save rob-hills/9134b7352ee7471c4d4f4fbd6454c4b9 to your computer and use it in GitHub Desktop.
Ubuntu 22.04 on MacBook Pro 2017 (A1707, MBP 14,3)

Summary

Random set of notes and links that have helped me in the saga to get Ubuntu 22.04 up and running on my 2017 MacBook Pro These notes are mainly for myself in the event that I have to do this again some day. But if you find them helpful, that's great.

Important update

Unfortunately the MacBookPro that I bought second hand turned out to be a dud with some serious hardware flaws that didn't show up until a couple of months after I'd bought it.

I've since purhcased another laptop so I'm not going to be able to maintain this GIST.

I'll leave it here for now in case others want to contribute updates, or clone it. If you feel it's out of date or misleading or a waste of time, let me know in the comments and I'll remove it.

Details

My MacBook Pro:

root@rob-MacBookPro:~# sudo dmidecode | grep -i mac
	Product Name: MacBookPro14,3
	Family: MacBook Pro
	Product Name: Mac-551B86E5744E2388
	Version: MacBookPro14,3
	Version: Mac-551B86E5744E2388
		MCE (Machine check exception)
		MCA (Machine check architecture)

Hmmm, curious, it says MBP 15.4/3 on the box.

Useful References (not mentioned in text)

Out of the Box

What worked

A lot of online info about running Ubuntu on MBP indicated that you needed to build drivers and install them just to get the basics running. For Ubuntu 22.04LTS and my MBP 1707 this was not the case. Things that worked for me with the standard Ubuntu 22.04LTS Live USB and after initial installation included:

  • The basic keyboard (not the Touchbar with Esc and Function keys though);
  • The touchpad;
  • My ASUS USB-C docking station, providing important infrastructure such as full external keyboard with all keys functional, LAN connection, external monitor;
  • NVMe SSD

What didn't work

  • Wifi: Actually it was partly functional, but unusable. It would find my WLAN access point and would sometimes connect for brief periods, sometimes not. Usually the connection would be extremely slow and would drop out after brief intervals;
  • The Touchbar

The following notes mostly document what worked to get Wifi and the Touchbar working

WiFi

Extensive Googling indicated that the Broadcom driver installed with Ubuntu doesn't work properly on most newer MBPs. However, after installing the recommended driver, I experienced small improvements but was still not getting reliable WiFi.

Eventually I came across a Kernel Bugzilla discussion that led me to a solution. The discussion about this bug is long and technical, but well worth the time to read through from beginning to end.

In particular, Sontal.santan's comment explaining how to create a configuration file for the driver, where to put it and what parameters to tweak was the first step in getting my WiFi to work.

The configuration file needed for my hardware is: /usr/lib/firmware/brcm/brcmfmac43602-pcie.txt

Andy Holst's example configuration files, first one here and final iteration here were ideal and only required a little tweaking for my system.

WiFi Driver Configuration tweaks

I made the following changes to Andy Holst's /usr/lib/firmware/brcm/brcmfmac43602-pcie.txt

  • macaddr - set to the mac address of my WiFi card
  • ccode - set to your country code, in my case AU (for Australia)

Touchbar

Many thanks to RoadRunner2 for his Gist on getting Ubuntu running on the MBP and for all his work on drivers.

Unfortunately his drivers wouldn't compile against the current Linux kernel in Ubuntu 22.04. Eventually I found Patrick Verner's fork of the macbook12-spi-driver which did compile. But still my touchbar wasn't working.

Reading through the discussion on RoadRunner2's version, I came across others with the same issue and this pointed me towards this workaround which finally lit up my touchbar!

Step by Step touchbar

Become the superuser

sudo su

Ubuntu uses initramfs so add our new modules to the list to be loaded

cat <<EOF | tee -a /etc/initramfs-tools/modules
# drivers for keyboard+touchpad
applespi
apple-ib-tb
intel_lpss_pci
spi_pxa2xx_platform
EOF

Now, install prerequisites, download and build the drivers

apt install dkms

cd {your preferred source download folder}
git clone https://github.com/PatrickVerner/macbook12-spi-driver.git
pushd macbook12-spi-driver
git checkout touchbar-driver-hid-driver
ln -s `pwd` /usr/src/applespi-0.1
dkms install applespi/0.1
popd

Test the drivers by loading them and their dependencies

sudo modprobe intel_lpss_pci spi_pxa2xx_platform applespi apple-ib-tb

Null output indicates success

Reboot

At this point of the process, my touchbar was not working. More Googling led me to someone else logging this as [an issue on RoadRunner2's Driver repository[(roadrunner2/macbook12-spi-driver#42] and in the discussion I found a workaround. The following commands:

echo '1-3' | sudo tee /sys/bus/usb/drivers/usb/unbind
echo '1-3' | sudo tee /sys/bus/usb/drivers/usb/bind

caused my touchbar to light up!!

To save having to run these commands each time I start the computer, I needed to create a "macbook-quirks.service" and have it start up with the computer:

sudo su
cat <<EOF | tee /etc/systemd/system/macbook-quirks.service
[Unit]
Description=Re-enable MacBook 14,3 TouchBar
Before=display-manager.service

[Service]
Type=oneshot
ExecStartPre=/bin/sleep 2
ExecStart=/bin/sh -c "echo '1-3' > /sys/bus/usb/drivers/usb/unbind"
ExecStart=/bin/sh -c "echo '1-3' > /sys/bus/usb/drivers/usb/bind"
RemainAfterExit=yes
TimeoutSec=0

[Install]
WantedBy=multi-user.target
EOF

Now enable with systemctl enable macbook-quirks.service and reboot to check.

My MBP now boots up with the touchbar working!

From the discussion in the link above, it appears this may be due to a bug in Linux and the usbmuxd system so hopefully will be able to remove the workaround in the future, so keep an eye on the relevant issue discussion.

Touchbar Tweaking

I wanted the Function keys to appear by default (instead of the brightness and sound keys) so I needed to pass some parameters to the apple_ib_tb module. 'modinfo apple_ib_tb' lists the parameters and what they do.

sudo su
cat <<EOF | tee /etc/modprobe.d/apple_ib_tb.conf
options apple_ib_tb fnmode=2           # Default to Function Keys, Fn key toggles to "special"
options apple_ib_tb idle_timeout=60    # Turn off touchbar after 60 seconds.
EOF

After reloading the module with

sudo modprobe -r apple_ib_tb
sudo modprobe apple_ib_tb

now the Function keys show by default!

@ev4n32
Copy link

ev4n32 commented Mar 9, 2024

@rob-hills @MCMuser1 Do you have the Patrick Verner driver saved somewhere? The repo is dead.

@bennettforkner
Copy link

@rob-hills @MCMuser1 Do you have the Patrick Verner driver saved somewhere? The repo is dead.

Also wondering on this!

@almas
Copy link

almas commented May 10, 2024

Thank you guys.

I also noted my adventure, which might give a hint to someone later.
https://gist.github.com/almas/5f75adb61bccf604b6572f763ce63e3e

I edited the driver repository source to support kernels newer than >5.3.

@hamishfor
Copy link

Has anyone got 24.04 running on their 2017 A1707 MBP?

@almas
Copy link

almas commented Oct 31, 2024

@hamishfor
Didn't you see my gist?

@hamishfor
Copy link

Hi @almas - sorry I did not! Thank you for pointing me towards it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment