Getting the MacBook Pro 2018 T2 to Work with ArchLinux (Dualboot)

There was quite a bit of noise about the fact that due to the new T2 chip, it was impossible to install Linux on the new MacBook 2018 models with the Touch Bar. As time went on, by the end of 2019, third-party developers implemented a number of drivers and kernel patches for interfacing with the T2 chip. The main driver for MacBook models 2018 and later supports the functioning of VHCI (Touch/keyboard operation, etc.) as well as audio functionality.

Project mbp2018-bridge-drv divided into 3 main components:

  • BCE (Buffer Copy Engine) — establishes the main communication channel with the T2. VHCI and Audio require this component.
  • VHCI is a virtual USB host controller; the keyboard, mouse, and other system components are provided by this component (other drivers use this host controller for enhanced functionality).
  • Audio — driver for the T2 audio interface, currently supports only audio output through the built-in speakers of the MacBook.


The second project is called macbook12-spi-driver, and it implements the input driver for the keyboard, trackpad SPI, and Touch Bar for MacBook Pro models from late 2016 and newer. Parts of the keyboard/trackpad drivers are now included in the kernel, starting from version 5.3.

Support for devices like Wi-Fi, touchpad, etc., has also been implemented via kernel patches. Currently, the kernel version is 5.3.5-1

What Works Currently

  1. NVMe
  2. Keyboard
  3. USB-C (Thunderbolt has not been tested, automatically loading the module hangs the system completely)
  4. Touch Bar (with the ability to enable Fn keys, backlight, ESC, etc.)
  5. Sound (only through built-in speakers)
  6. Wi-Fi module (via brcmfmac and only through iw)
  7. DisplayPort over USB-C
  8. Sensors
  9. Suspend/Resume (partially)
  10. etc.

This tutorial applies to macbookpro15,1 and macbookpro15,2. It is based on an article from GitHub in English from here. Not everything in this article worked, so I had to find a solution myself.

What You Will Need for Installation

  • USB-C dock adapter to USB (at least three USB ports to connect a mouse, keyboard, USB modem, or phone in tethering mode). This is only necessary in the early stages of installation.
  • USB keyboard
  • USB/USB-C flash drive of at least 4 GB

1. Disable boot restrictions from external drives.

https://support.apple.com/en-us/HT208330
https://www.ninjastik.com/support/2018-macbook-pro-boot-from-usb/

2. Allocate free space using Disk Utility.

For convenience, I immediately allocated 30 GB to the disk, formatting it in exFAT in Disk Utility. Partitioning the Physical Disk with Disk Utility.

3. Creating the ISO Image

Options:

  1. You can take the easy route and download a pre-built image with kernel 5.3.5-1 and patches from aunali1 link to the pre-built image
  2. Create the image yourself via archlive (a system with the Arch distribution is required)

    Installing archiso

    pacman -S archiso

    
    cp -r /usr/share/archiso/configs/releng/ archlive
    cd archlive
    

    Add the repository to pacman.conf:

    
    [mbp]
    Server = https://packages.aunali1.com/archlinux/$repo/$arch
    

    Ignore the original kernel in pacman.conf:

    IgnorePkg   = linux linux-headers
    

    Add the necessary packages, finally adding the linux-mbp and linux-mbp-headers kernels

    ...
    wvdial
    xl2tpd
    linux-mbp
    linux-mbp-headers
    

    Modify the script to work in interactive mode (replace pacstrap -C with pacstrap -i -C):

    sudo nano /usr/bin/mkarchiso

    # Install desired packages to airootfs
    _pacman ()
    {
        _msg_info "Installing packages to '${work_dir}/airootfs/'..."
    
        if [[ "${quiet}" = "y" ]]; then
            pacstrap -i -C "${pacman_conf}" -c -G -M "${work_dir}/airootfs" $* &> /dev/null
        else
            pacstrap -i -C "${pacman_conf}" -c -G -M "${work_dir}/airootfs" $*
        fi
    
        _msg_info "Packages installed successfully!"
    }

    Create the image:

    sudo ./build.sh -v

    Press Y to skip ignored packages, then write the ISO image to the USB flash drive:

    sudo dd if=out/archlinux*.iso of=/dev/sdb bs=1M

4. First Boot

Reboot with the USB drive inserted and keyboard connected. Press options when the Apple logo appears, select EFI BOOT.

Next, you need to press the "e" key and type at the end of the command line module_blacklist=thunderbolt. If this is not done, the system may not boot, and you will get a Thunderbolt ICM Error.

Using fdisk/cfdisk, find your partition (for me it's nvme0n1p4), format it and proceed with the installation of Arch. You can refer to the official instructions or third-party.

Do not create a boot partition; we will write the bootloader to /dev/nvme0n1p1
Once the environment in /mnt is fully set up and before entering arch-chroot, we write:

mount /dev/nvme0n1p1 /mnt/boot
arch-chroot /mnt /bin/bash

Add to /etc/pacman.conf:


[mbp]
Server = https://packages.aunali1.com/archlinux/$repo/$arch

Install the kernel:


sudo pacman -S linux-mbp linux-mbp-headers
sudo mkinitcpio -p linux-mbp

Add thunderbolt and applesmc to /etc/modprobe.d/blacklist.conf

blacklist thunderbolt
blacklist applesmc

Keyboard, touch bar, etc.

Install yay:


sudo pacman -S git gcc make fakeroot binutils
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si

Install modules for touch bar functionality:


git clone --branch mbp15 https://github.com/roadrunner2/macbook12-spi-driver.git
cd macbook12-spi-driver
make install

Add the modules to autoload: /etc/modules-load.d/apple.conf

industrialio_triggered_buffer
apple-ibridge
apple-ib-tb
apple-ib-als

Install kernel modules for keyboard functionality. In the repository aunali1 there is a pre-made package called apple-bce-dkms-git. To install it, enter in the console:

pacman -S apple-bce-dkms-git

In this case, the kernel module will be called apple-bce. In the case of a manual build, it is called bceAccordingly, if you want to include a module in the MODULES section of the mkinicpio.conf file, don’t forget which module you installed.

Manual build:


git clone https://github.com/MCMrARM/mbp2018-bridge-drv.git
cd mbp2018-bridge-drv
make
cp bce.ko /usr/lib/modules/extramodules-mbp/bce.ko

Add the bce or apple-bce module to autoload: /etc/modules-load.d/bce.conf

bce

If you want to use the Fn keys by default, add the following to the /etc/modprobe.d/apple-tb.conf file:

options apple-ib-tb fnmode=2

Update the kernel and initramfs.


mkinitcpio -p linux-mbp

Let’s install iwd:

sudo pacman -S networkmanager iwd

5. Bootloader

After all the essential packages are installed inside chroot, you can proceed to install the bootloader.

I couldn’t get grub to work. Grub boots from an external USB drive, but when trying to install it on nvme via

grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=grub

the system went into kernel panic, and after rebooting, the new entry didn’t appear through options. I couldn’t find a clear solution to this issue, so I decided to try booting with systemd-boot.

  1. Launch
    bootctl --path=/boot install

    and we go into kernel panic. Turn off the MacBook, turn it back on, hold options (don't disconnect the usb-c hub with the keyboard)

  2. Check that a new EFI BOOT entry appears along with the external device.
  3. Select booting from the external USB drive, just as during the first installation (remember to add module_blacklist=thunderbolt)
  4. Mount our disk and enter the environment via arch-chroot


mount /dev/nvme0n1p4 /mnt
mount /dev/nvme0n1p1 /mnt/boot
arch-chroot /mnt

If you need the keyboard to work before the full system boots (which is necessary when using luks/dm-crypt encryption), add to the /etc/mkinicpio.conf file in the MODULES section:

MODULES=(ext4 applespi intel_lpss_pci spi_pxa2xx_platform bce)

Update the kernel and initramfs.


mkinicpio -p linux-mbp

Configure systemd-boot

Edit the /boot/loader/loader.conf file, remove everything inside, and add the following:

default arch
timeout 5
editor 1

Go to the /boot/loader/entries folder, create the arch.conf file and write:

title arch
linux /vmlinuz-linux-mbp
initrd /initramfs-linux-mbp.img
options root=/dev/<b>nvme0n1p4</b> rw pcie_ports=compat

If you used luks and lvm, then

options cryptdevice=/dev/<b>nvme0n1p4</b>:luks root=/dev/mapper/vz0-root rw pcie_ports=compat

Reboot into MacOS.

6. Wi-Fi Setup

As it turned out, the firmware files for the wi-fi adapter are stored in the folder /usr/share/firmware/wifi , and they can be taken from there in the form of blobs and fed to the brcmfmac kernel module. To find out which files your adapter uses, open the terminal in MacOS and type:

ioreg -l | grep C-4364

You will get a long list. We only need files from the section RequestedFiles:

"RequestedFiles" = ({"Firmware"="<b>C-4364__s-B2/maui.trx</b>","TxCap"="C-4364__s-B2/maui-X3.txcb","Regulatory"="C-4364__s-B2/<b>maui-X3.clmb</b>","NVRAM"="C-4364__s-B2/<b>P-maui-X3_M-HRPN_V-m__m-7.7.txt</b>"})

In your case, the file names may differ. Copy them from the folder /usr/share/firmware/wifi to the flash drive and rename them as follows:

    maui.trx -&gt; brcmfmac4364-pcie.bin
    maui-X3.clmb -&gt; brcmfmac4364-pcie.clm_blob
    P-maui-X3_M-HRPN_V-m__m-7.7.txt -&gt; brcmfmac4364-pcie.Apple Inc.-<b>MacBookPro15,2.txt</b>

In this case, the last text file contains the model names; if your model is not macbookpro15,2, you need to rename this file according to your MacBook model.

We reboot into Arch.

Copy the files from the flash drive to the folder /lib/firmware/brcm/


sudo cp brcmfmac4364-pcie.bin /lib/firmware/brcm/
sudo cp brcmfmac4364-pcie.clm_blob /lib/firmware/brcm/
sudo cp 'brcmfmac4364-pcie.Apple Inc.-<b>MacBookPro15,2.txt' /lib/firmware/brcm/

Check the module's functionality:


rmmod brcmfmac
modprobe brcmfmac

Ensure the network interface appears via ifconfig/ip.
Configure wifi via iwctl

Attention. The interface does not work through netctl, nmcli, etc., only through iwd.

Force NetworkManager to use iwd. To do this, create the file /etc/NetworkManager/NetworkManager.conf and write:

[device]
wifi.backend=iwd

Start the NetworkManager service


sudo systemctl start NetworkManager.service
sudo systemctl enable NetworkManager.service

7. Sound

To enable sound, you need to install pulseaudio:


sudo pacman -S pulseaudio

Download three files:

Move them:

    /usr/share/alsa/cards/AppleT2.conf
    /usr/share/pulseaudio/alsa-mixer/profile-sets/apple-t2.conf
    /usr/lib/udev/rules.d/91-pulseaudio-custom.rules

8. Suspend/Resume

Currently, you have to choose either sound or suspend/resume. We are waiting for the author of the bce module to finalize the functionality. 16.10.2019 To build the module with suspend/resume support, you need to do the following:

git clone https://github.com/MCMrARM/mbp2018-bridge-drv.git cd mbp2018-bridge-drv git checkout suspend make cp bce.ko /usr/lib/modules/extramodules-mbp/bce.ko modprobe bce


If you installed the ready-made apple-bce module from the anuali1 repository, you must first remove it and only then build and install the bce module with suspend mode support.

Additionally, you need to add the applesmc module to the blacklist (if you haven't done it before) and ensure that the parameter is added at the end of the options line in /boot/loader/entries/arch.conf:

pcie_ports=compat Currently, the touch bar driver crashes when entering suspend mode, and the thunderbolt driver sometimes freezes the system for more than 30 seconds, and upon resuming—for several minutes. This can be fixed by automatically unloading problematic modules..

Create a script

Make it executable: /lib/systemd/system-sleep/rmmod.sh:

#!/bin/sh
if [ "${1}" == "pre" ]; then
        rmmod thunderbolt
        rmmod apple_ib_tb
elif [ "${1}" == "post" ]; then
        modprobe apple_ib_tb
        modprobe thunderbolt
fi

sudo chmod +x /lib/systemd/system-sleep/rmmod.sh

That’s all for now. In the end, you will have a quite functional system, aside from some nuances with suspend/resume. No crashes or kernel panic has been observed for several days of uptime. I hope that soon the author of the bce module will finalize it, and we will get full support for suspend/resume and sound.

That's all for now. In the end, we have a fully functional system, with the exception of some nuances regarding suspend/resume. There have been no crashes or kernel panics observed over several days of uptime. I hope that the module's author will refine it soon, and we will gain full support for suspend/resume and sound.

Source: habr.com

Buy reliable website hosting with DDoS protection, VPS VDS servers šŸ”„ Buy reliable website hosting with DDoS protection, VPS VDS servers | ProHoster