Getting MacBook Pro 2018 T2 to work with ArchLinux (dualboot)

There was a lot of hype about the fact that due to the new T2 chip, it is impossible to install linux on the new 2018 MacBook with a touchbar. As time went on, and by the end of 2019, third-party developers implemented a number of drivers and kernel patches for interacting with the T2 chip. The main driver for MacBook models 2018 and newer implements VHCI (operation of the touch / keyboard / etc.), as well as the functioning of sound.



The mbp2018-bridge-drv project is divided into 3 main components:





The second project is called macbook12-spi-driver , and it implements the possibility of the input driver for the keyboard, SPI trackpad, touchbar for MacBook Pro late 2016 and later. Some drivers for the keyboard / trackpad are now included in the kernel, starting with version 5.3.



Support was also implemented for devices such as wi-fi, touchpad, etc, using kernel patches. Currently the kernel version is 5.3.5-1



What works at the moment



  1. NVMe
  2. Keyboard
  3. USB-C (Thunderbolt was not tested, when the module loads automatically, it suspends the system tightly)
  4. Touchbar (with the ability to turn on the Fn keys, backlight, ESC, etc.)
  5. Sound (built-in speakers only)
  6. Wi-Fi module (via brcmfmac and only through iw)
  7. DisplayPort via USB-C
  8. Sensors
  9. Suspend / Resume (partially)
  10. etc ..


This tutorial is applicable for macbookpro15.1 and macbookpro15.2. The article was taken from the github in English from here . Not all of this article worked, so I had to look for a solution on my own.



What you need to install





1. Disable the ban on loading from external media



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 30GB to the disk, formatting it to exfat in Disk Utility itself. Partitioning a physical disk into Disk Utility partitions .



3. Form an iso image



Options:



  1. You can go the simple way and download the finished image with the kernel 5.3.5-1 and the patches from aunali1 link to the finished image
  2. Create an image yourself through archlive (you need a system with archa distribution)



    Install 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, at the end we add the linux-mbp and linux-mbp-headers kernel



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





    Change 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!" }
          
          





    We form an image:



     sudo ./build.sh -v
          
          





    Press Y to skip the 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 inserted flash drive and keyboard. Press options when the apple appears, select EFI BOOT.



Next, you need to press the β€œe” key and enter module_blacklist = thunderbolt at the end of the command line. If this is not done, then the system may not boot, and the Thunderbolt ICM Error will crash.



Using fdisk / cfdisk we find our section (I have it nvme0n1p4), format and install the arch. You can use the official instructions or third-party .



We do not create the boot partition, we will write the bootloader in / dev / nvme0n1p1

After the environment in / mnt is fully formed and before switching to 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
      
      





Put thunderbolt and applesmc in /etc/modprobe.d/blacklist.conf



 blacklist thunderbolt blacklist applesmc
      
      





Keyboard, touchbar, etc



Install yay:



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





Install the modules for the touchbar:



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





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



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





Install the kernel modules for the keyboard. The repository anuali1 has a ready-made package, it is called apple-bce-dkms-git . To install it, write in the console:



 pacman -S apple-bce-dkms-git
      
      





In this case, the kernel module will be called apple-bce . In the case of self-assembly, it is called bce . Accordingly, if you want to register the module in the MODULES section in the mkinicpio.conf file, then do not forget which module you installed.



Manual assembly:



 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 buttons by default, then in the /etc/modprobe.d/apple-tb.conf file we write:



 options apple-ib-tb fnmode=2
      
      





Updating the kernel and initramfs.



 mkinitcpio -p linux-mbp
      
      





Install iwd:



 sudo pacman -S networkmanager iwd
      
      





5. Bootloader



Once inside the chroot all the main packages are installed, you can proceed to install the bootloader.



I never managed to get grub to work. From an external usb drive, grub boots, but when you try to register it in nvme via
grub-install --target = x86_64-efi --efi-directory = / boot --bootloader-id = grub
the system crashed into kernel panic, and after rebooting a new item through options did not appear. I did not find any intelligible solution to this problem and therefore decided to try to implement the boot using systemd-boot.



  1. We launch



     bootctl --path=/boot install
          
          





    and fly off to kernel panic. Turn off the MacBook, turn it on again, click options (do not turn off the usb-c hub with the keyboard)
  2. Check that a new EFI BOOT record has appeared in addition to the external device
  3. We select the download from an external usb-drive, as during the first installation (do not forget to write module_blacklist = thunderbolt)
  4. We mount our disk and go into the environment through arch-chroot


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





If it is necessary for the keyboard to work until the system is fully loaded (this is necessary if luks / dm-crypt encryption is used), then we write it in the /etc/mkinicpio.conf file in the MODULES section:



 MODULES=(ext4 applespi intel_lpss_pci spi_pxa2xx_platform bce)
      
      





Updating the kernel and initramfs.



 mkinicpio -p linux-mbp
      
      





Configure systemd-boot



We edit the file /boot/loader/loader.conf, delete everything inside it, 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 on MacOS.



6. Wi-fi setup



As it turned out, MacOS stores the firmware files for the wi-fi adapter in the / usr / share / firmware / wifi folder, and you can take them from there in the form of blobs and feed them to the brcmfmac kernel module. In order to find out exactly which files your adapter uses, open the terminal in MacOS and write:



 ioreg -l | grep C-4364
      
      





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



 "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 / usr / share / firmware / wifi folder to the USB flash drive and rename it to the following view:



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





In this case, the last text file contains the model name, if your model is not macbookpro15,2, then you need to rename this file in accordance with your macbook model.



Reboot into arch.



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



 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 health of the module:



 rmmod brcmfmac modprobe brcmfmac
      
      





We make sure that the network interface appeared through ifconfig / ip.

Configure wifi via iwctl



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



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



 [device] wifi.backend=iwd
      
      





Starting the NetworkManager service



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





7. Sound



In order to make sound, you must 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



At the moment, 10/16/2019 you have to choose either sound or suspend / resume. We are waiting for the author of the bce module to finish the functionality.



To build a module with support for susped / resume, you must 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 collect and install the bce module with support for suspend mode.



Also, you need to add the applesmc module to the blacklist (if you haven’t done this before) and make sure that the pcie_ports = compat parameter is added to /boot/loader/entries/arch.conf in the options line at the end.



At the moment, the touchbar driver crashes when you enter suspend mode, and the thunderbolt driver sometimes suspends the system for more than 30 seconds, and when you resume it, for several minutes. This can be fixed by automatically downloading problem modules.



Create the script /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
      
      





Make it executable:



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





That's all for now. The result is a fully functional system, with the exception of some nuances with suspend / resume. No crashes and kernel panic has been observed for several days uptime. I hope that in the near future the author of the bce module will finish it, and we will get full support for suspend / resume and sound.



All Articles