Tinkering

Microsoft Surface Pro 4 & Fedora 28

published on
Microsoft

I decided to take Fedora 28 for a spin in my Microsoft Surface Pro 4. I'd used Ubuntu before but updates there were problematic, resulting on Gnome crashes, among other mysterious occasional reboots and lockups. I'm happy to report that Fedora works wonderfully. Here are the instructions I followed to compile and install the latest kernel on Fedora 28 so you get most of the hardware working (battery status and the integrated cameras don't work, yet).

Getting kernel sources: linux-surface + linux-stable

Jake Day has done all the hard work for us: here. We'll start by creating a folder to host the source code we will need, one for Jake's patches, one for Linux kernel source. If any of the commands do not work, you may be missing some packages installed on your machine.

$ cd ~
$ mkdir kernel-sources
$ cd kernel-sources
$ git clone https://github.com/jakeday/linux-surface.git

This will download the list of patches from Jake Day's GitHub repository to make changes to the official Linux kernel. Now we'll use Jake's script to install a few libraries and drivers that will be needed for the kernel compilation to suceed.

$ cd linux-surface
$ sudo sh setup.sh
$ [enter your sudo password]
$ Running fedora version 28 (Workstation Edition) on a Surface Pro.\n
Press enter if this is correct, or CTRL-C to cancel - enter
-- it will complain about a missing folder, ignore it --
$ Do you want to replace suspend with hibernate (type yes or no) - no
$ Do you want use the patched libwacom packages? (type yes or no) - no
-- it will now install IPTS firmware (this will give us touch and pen input!) --
-- it will install motherboard firmware (i915) --
-- it will install wifi Marvell firmware (to fix a buggy WiFi connection) --
$ Do you want to set your clock to local time instead of UTC? This fixes issues when dual booting with Windows. (type yes or no) - no (I'm getting rid of it)
$ Do you want this script to download and install the latest kernel for you? (type yes or no) - no (because this one is meant for Ubuntu and won't work in Fedora)

Now we have the firmware in place. Let's now prepare the Linux source to use Jake Day's patches. Check here what is the current supported version of the kernel for which Jake Day has made his patches. At this time it's 4.18.11-1. Remember this version number 4.18.11. Let's now get Linux kernel source code:

$ cd ~/kernel-sources
$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
$ cd linux-stable
$ git checkout v4.18.11

Installing packages needed for source code compilation

Before we get compiling everything, we need to make sure we have all the libraries we'll ever need to compile drivers and kernel from source.

$ sudo dnf groupinstall "Development Tools" "C Development Tools and Libraries"
$ sudo dnf install elfutils-devel openssl-devel perl-devel perl-generators pesign ncurses-devel

Adding support for battery status monitoring

To add support to battery events, you'll need to apply the patches from qzed which add battery monitoring to your desktop. You'll need to do:

$ cd ~/kernel-sources/linux-surface
$ git remote add upstream https://github.com/qzed/linux-surface.git
$ git fetch upstream
$ git checkout master
$ git merge upstream/master

Apply patches from linux-surface into linux-stable

We'll now apply the changes Jake Day has prepared into linux-stable (official Linux kernel). Then we'll load Fedora's configuration file so we have the same support as officially was bundled.

$ cd ~/kernel-sources/linux-stable
$ for i in ../linux-surface/patches/4.18/*.patch; do patch -p1 < $i; done
$ cp /boot/config-`uname -r` .config

We need to make sure these lines exist in .config file:
CONFIG_SERIAL_DEV_BUS=y
CONFIG_SERIAL_DEV_CTRL_TTYPORT=y

In the following step "Compiling kernel and modules", make sure to select "m" in the CONFIG_INTEL_IPTS otherwise you'll have errors creating the bzImage. The "m" stands for module, so that's fine!

Compiling kernel and modules

This will take some time to complete (bzImage about 20 minutes) + (all modules about 45 minutes). Be patient. It will ask you to accept the new modules from Surface Pro 4, shown as (NEW). Press m to have them added as modules for your kernel.

$ make -j `getconf _NPROCESSORS_ONLN` bzImage; make -j `getconf _NPROCESSORS_ONLN` modules

Installing kernel and modules

Assuming compilation went without errors, you can now install them both.

$ sudo make -j `getconf _NPROCESSORS_ONLN` modules_install
$ sudo make -j `getconf _NPROCESSORS_ONLN` install

Install battery ACPI module

Install DKMS in Fedora:

$ sudo dnf install dkms

We'll now download and compile the extra ACPI module (thanks to qzed):
$ cd ~/kernel-sources/linux-stable/drivers
$ git clone https://github.com/qzed/linux-surfacegen5-acpi-notify.git surfacegen5-acpi-notify
$ cd surfacegen5-acpi-notify
$ make
$ sudo make dkms-install

And there you have it. Reboot your computer and you'll have the option to choose this kernel at boot and you should have better support for your Surface Pro 4.