Skip to content

Instantly share code, notes, and snippets.

@almas
Forked from rob-hills/ubuntu-22.04-mbp-a1707.md
Last active July 27, 2024 13:11
Show Gist options
  • Save almas/5f75adb61bccf604b6572f763ce63e3e to your computer and use it in GitHub Desktop.
Save almas/5f75adb61bccf604b6572f763ce63e3e to your computer and use it in GitHub Desktop.
Ubuntu 22.04 on MacBook Pro 2017 (A1707, MBP 14,3)

Summary

Notes to install Ubuntu 22.04.4LTS (Upgraded to 24.04LTS) up and running on my 2017 MacBook Pro 15 inch (MacBookPro14,3).

Now everything except the TouchID (Fingerprint), Suspend and Hibernation seems to work for me.

About Ubuntu 24.04LTS: I tried to install Ubuntu 24.04 and didn't have success. There was a crash issue during installation. https://bugs.launchpad.net/subiquity/+bug/2065310 But I installed 22.04 and upgraded it to the 24.04LTS later and it working same as 22.04.4.

Useful References (not mentioned in the 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 a1707, 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 SSK USB-C multi-port adapter, provides important infrastructure such as LAN connection, external monitor, and external storage;
  • Bluetooth. Connected external Bluetooth keyboard and Apple mouse 2.

What didn't work

  • Wifi: It was partly functional, but was not fully usable. Only 2.4Ghz access points shown with poor level and can be connected;
  • Touchbar;
  • Sound;
  • Camera;

What still doesn't work

The following notes mostly document what worked to get Wifi, Touchbar, Camera, and Sound working.

Pre-requirement

The Macbook's EFI partition seems to need to be kept. Please see the following comment for more information.

https://gist.github.com/roadrunner2/1289542a748d9a104e7baec6a92f9cd7?permalink_comment_id=4937505#gistcomment-4937505

Resolution

WiFi

Just creating the configuration file /usr/lib/firmware/brcm/brcmfmac43602-pcie.txt was enough for my hardware.

Andy Holst's example configuration file final iteration here was 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=00:90:4c:0d:f5:30
ccode=ALL
  • macaddr - set to the mac address of my WiFi card (I got it with the command ip addr)
  • ccode - I just simply set it to ALL, (ALL (Channel 1-14), US, EU etc.)

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

Build and install drivers from the source code.

apt install dkms

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

Test the drivers by loading them and their dependencies

modprobe intel_lpss_pci spi_pxa2xx_platform applespi apple-ib-tb

An empty 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 (Optional)

Personally, I don't like this. But, if you want the Function keys to appear by default (instead of the brightness and sound keys), then you need 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 the Touchbar after 60 seconds.
EOF

After reloading the module with the following command, the Function keys will be shown by default.

sudo modprobe -r apple_ib_tb
sudo modprobe apple_ib_tb

Sound

I found the resolution from the Rade0nFighter's answer from the following QA: https://askubuntu.com/questions/1475091/sound-macbook-pro-ubuntu-22-04

sudo su

apt install wget make gcc linux-headers-generic
git clone https://github.com/davidjo/snd_hda_macbookpro.git
cd snd_hda_macbookpro/
./install.cirrus.driver.sh

# It will give you instructions to install package linux-source-XXXXX. Install it.
apt install linux-source-XXXXX

# Then re-run install script.
./install.cirrus.driver.sh

reboot

Now the sound should work.

Camera

Execute the following command and reboot.

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

Now the camera should work too.

References

@100lvlmaster
Copy link

will this work with ubuntu 24?

@almas
Copy link
Author

almas commented May 11, 2024

will this work with ubuntu 24?

As I mentioned in the note, I tried to install Ubuntu 24.04 and didn't have success. There was a crash issue during installation.
Basically, it should work if you upgrade from the 22.04 as my understanding. But, you can try it on your own.

@almas
Copy link
Author

almas commented May 16, 2024

Update: I upgraded to Ubuntu 24.04LTS from 22.04, and it works the same as 22.04.
Update: Not recommend to upgrade...

@samrostaq
Copy link

Getting this error on A1707 MBP:
#dkms install applespi/0.1

Kernel preparation unnecessary for this kernel. Skipping...

Building module:
cleaning build area...
make -j8 KERNELRELEASE=6.5.0-41-generic...(bad exit status: 2)
ERROR (dkms apport): binary package for applespi: 0.1 not found
Error! Bad return status for module build on kernel: 6.5.0-41-generic (x86_64)
Consult /var/lib/dkms/applespi/0.1/build/make.log for more information.

@gioriv
Copy link

gioriv commented Jun 23, 2024

I'm absolutely new to all of linux, everything that I would hare I did just from others suggestion and reading all type of forums regarding this information.

I was having the same issue until I updated the kernel to 6.5 ( I'm using Linux Mint ). The driver are already in the kernel, so there was no need to install them. So I made sure the module was set to load during boot with the following steps.

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

After that I did the following steps except git checkout touchbar-driver-hid-driver because is already running.

git clone https://github.com/roadrunner2/macbook12-spi-driver.git
pushd macbook12-spi-driver
git checkout touchbar-driver-hid-driver
sudo ln -s `pwd` /usr/src/applespi-0.1
sudo dkms install applespi/0.1
popd

After reboot I follow this steps and it worked:

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

On boot it would have to do the same again, so these steps I found here:
https://www.collegesidekick.com/study-docs/13850638

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

systemctl enable macbook-quirks.service

Also here you would find the cause of it:
roadrunner2/macbook12-spi-driver#42

After all that it did worked fine, for some reason after shut down the Laptop next day after boot it wasn't working. I re-install everything fro 0 again to see. It worked again, but this time I create a system backup with time-shift. I actually did it again with installing, update or making any changes whatsoever. I restored with the time-shift and it worked again. Let the PC overnight not fully shutdown and connected to the power and is still working. Will se what happens in the next few hours without being connected to the power and not fully shutdown to see.

I posted I picture of the touch-bar working on reddit:
https://www.reddit.com/r/linuxmint/comments/1dlm01u/finally_got_my_macbook_143_2017_pro_touch_bar/

@almas
Copy link
Author

almas commented Jun 30, 2024

@samrostaq

It is still working for me. You might did something wrong.

@HappyZ
Copy link

HappyZ commented Jul 6, 2024

was the crash issue installing 24.04 due to swap? I had the issue and manually did gparted first so it properly recognizes swap during installation. Otherwise it fails at formatting the swap partition.

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