Installing Ubuntu on Surface pro 4

I have a fairly nice Surface Pro 4 kernel running on my Ubuntu installation.

The Rundown

What works:

  • wifi/bluetooth
  • multi-touch
  • pen
  • trackpad on the typing cover

What works somewhat:

  • hibernate - after resume there is no touch or pen

What doesn't:

  • suspend (see the note on power saving below)
  • freeze (the more battery draining version of suspend/sleep that doesn't reliably work)
  • the typing cover

What I haven't tried:

  • the cameras

General idea

The general idea behind this kernel is to take the changes done by Hyungwoo Yang at https://github.com/ipts-linux-org/ipts-linux-new/wiki and apply them to the Ubuntu 4.9rc3 kernel. Here are the steps to get the kernel in order. The compilation process takes about 45 minutes using all the cores of the Surface 4. Cloning the kernel repositories requires about 1.5 gigs of disk space.


Steps to produce the kernel

  1. install Ubuntu 16.10 yakkety. to accomplish this you will need a USB hub that can handle both the ubuntu live-USB and the keyboard/mouse.

  2. boot linux with a USB keyboard.

  3. prepare the Ubuntu 4.9rc3 kernel.

    • clone the Ubuntu 4.9rc3 kernel (requires ~1.5gig of space):

      git clone git://git.launchpad.net/~ubuntu-kernel-test/ubuntu/+source/linux/+git/mainline-crack v4.9-rc3

    • download 6 patches: Patch1 Patch2 Patch3 Patch4 Patch5 Patch6

    • apply the patches to the kernel in order: do

      git am /path/to/THEPATCH.patch

      for each of the patches.

  4. create a patch with touch/pen support from the ipts-linux-new kernel.

    • clone the kernel (requires ~1.5gig of space) in another directory:

      git clone https://github.com/ipts-linux-org/ipts-linux-new.git

    • create the patch:

      git diff 0c183d92b20b5c84ca655b45ef57b3318b83eb9e > /path/to/ipts-linux-new_patch.txt

  5. apply the ipts-linux-new patch to v4.9rc3

    `cd /path/to/v4.9rc3`
    `patch -p1 < /path/to/ipts-linux-new_patch.txt`
    `git add .`
    `git commit -m 'Patch for Surface Pro 4 taken from ipts-linux-new.'`
    
  6. compile the kernel and make ubuntu .deb packages (copied from Ubuntu Kernel Compilation)

    cd /path/to/v4.9rc3

    • initialize the debian files:

      fakeroot debian/rules clean

    • configure the kernel you will build:

      fakeroot debian/rules editconfigs

      • Say yes only to the amd64 question. This will show the "menuconfig" curses interface. activate the following two options:
        • Device Drivers -> NVM express lock device (y)
        • Device Drivers -> Misc devices -> Intel Precise Touch & Stylus (m)
    • comment or remove "do_zfs = true" in "/path/to/v4.9rc3/debian.master/rules.d/amd64.mk"

    • rename the kernel by editing "/path/to/v4.9rc3/debian.master/changelog"

  7. compile the kernel (use more threads than processors to make it faster)

    `fakeroot debian/rules clean` #necessary, but I don't know why
    `DEB_BUILD_OPTIONS=parallel=5 fakeroot debian/rules binary-headers binary-generic binary-perarch`
    
  8. four new .debs should be created in the directory next to v4.9rc3. Install the .debs with the following command:

    `sudo dpkg -i linux-image-* linux-headers-4.9.0-040900rc3*`
    
  9. copy driver files from windows to linux:

    • copy driver files from "\Windows\INF\PreciseTouch\Intel" to the linux directory "/lib/firmware/intel/ipts". There should be at least 4 files with names similar to these:

      • iaPreciseTouchDescriptor.bin
      • SurfaceTouchServicingSFTConfigMSHW0078.bin
      • SurfaceTouchServicingDescriptorMSHW0078.bin
      • SurfaceTouchServicingKernelSKLMSHW0078.bin
    • Make symbolic links to these files:

      cd /lib/firmware/intel/ipts

      ln -s iaPreciseTouchDescriptor.bin intel_desc.bin

      ln -s SurfaceTouchServicingSFTConfigMSHW0078.bin config.bin

      ln -s SurfaceTouchServicingDescriptorMSHW0078.bin vendor_desc.bin

      ln -s SurfaceTouchServicingKernelSKLMSHW0078.bin vendor_kernel.bin

You should be able to boot the new kernel now. If the links are in the right place then touch and pen will work nicely.


Note on power saving

The missing suspend functionality is a major drawback. This is a due to the Microsoft "connected standby" fiasco: https://lwn.net/Articles/580451/. Freeze uses more battery (drains the battery maybe half as fast as if you had left the computer on), and doesn't seem to be reliable. With hibernate the state is successfully kept, but unfortunately, the touch and stylus functionalities do not work after resume.


I used this guide on Reddit

Had issues with fridgecow's kernel freezing up and could never restart or shut down properly, would just freeze with Ubuntu logo doing nothing.

I used cantenna's (6a and 7a) and works fine other than doesn't wake from sleep and volume buttons don't work.

Download this file (the patched kernel)

cd to the directory where it went (eg cd Downloads) and install the packages

sudo dpkg -i './linux-headers-4.4.0-rc8touchkernel+_1_amd64.deb'
sudo dpkg -i './linux-image-4.4.0-rc8touchkernel+_1_amd64.deb'

Mount your Windows partition (you can download the files from here if you deleted your Windows partition or can't find them) and copy the files to your Ubuntu root directory (you may need to adjust the path depending on the mountpoint of your Windows partition:

sudo mkdir /itouch
cp /media/$USER/Windows/Windows/INF/PreciseTouch/Intel/* /itouch

Now make symlinks to the files so that the driver can find them

sudo ln -sf /itouch/SurfaceTouchServicingKernelSKLMSHW0078.bin /itouch/vendor_kernel_skl.bin
sudo ln -sf /itouch/SurfaceTouchServicingSFTConfigMSHW0078.bin /itouch/integ_sft_cfg_skl.bin
sudo ln -sf /itouch/SurfaceTouchServicingDescriptorMSHW0078.bin /itouch/vendor_descriptor.bin
sudo ln -sf /itouch/iaPreciseTouchDescriptor.bin /itouch/integ_descriptor.bin

You'll then need to make sure you have the option to boot this kernel or set it to boot by default by configuring GRUB.