Jump to content

The Mainline Kernel

From postmarketOS Wiki
Revision as of 03:42, 13 March 2018 by Alive4ever (talk | contribs) (Links: added link to Device Tree Reference)

Introduction

We want to get as many devices working with one shared kernel package (based on upstream). Making a device boot with the upstream kernel is commonly referred to as mainlining.

Why bother?

Carrying around forks of the kernel is not sustainable as it becomes impossible to provide security patches after a short time. The only way to truly fix this for a device is mainlining it.

Kernel packaging

That package is linux-postmarketos-stable. For devices, which are in the kernel's mainline release, but not yet in stable (see kernel releases), we also have linux-postmarketos-mainline. It is even allowed to carry temporary patches around on top of these kernels, as long as work is being done to get them upstreamed properly. The kernel packages based on the official one are in aports/main/postmarketos-linux*, while the device-specific forks are in aports/device/linux-*.

To make the kernel work with multiple devices, it no longer appends the dtb file to the kernel image. Instead, it puts all dtb files for the current architecture in /usr/share/dtb. The postmarketos-mkinitfs package appends the dtb file defined in the deviceinfo to the linux image in the boot partition.

Device tree source (ARM architecture)

To make your device boot, you will need a device tree source (dts) file (which will get compiled to a dtb mentioned above). Check the arch/arm/boot/dts (replace arm with your architecture) folder in the kernel source code for relevant files (browse online) with your device's codename. The general file naming is $chipset_vendor-$chipset-$vendor-$codename.dts.

Examples:

  • qcom-msm8974-lge-nexus5-hammerhead.dts
  • qcom-msm8974-sony-xperia-honami.dts
  • qcom-apq8064-sony-xperia-yuga.dts
  • qcom-apq8064-asus-nexus7-flo.dts

When you don't have a result, try to find a dts file with the same chipset as your device (e.g. msm8974). Try to create a new one for your device based on that by creating a patch for linux-postmarketos-stable. If there is not even a dts file for the same chipset, you need to create one from scratch (no idea how to do that, good luck and please extend the wiki).

Enable the mainline kernel for a new device

Before proceeding, make sure that you know that your device is supported by the mainline kernel. Otherwise use the source code of a vendor's fork of the kernel, which is known to work as described in the porting guide.

  1. run pmbootstrap.py menuconfig linux-postmarketos and adjust the kernel config to add the drivers for the device if they are not enabled yet. Set as much drivers to build as external module as possible so the main vmlinuz filesize doesn't increase too much.
  2. Set the kernel dependency to linux-postmarketos in the APKBUILD for the device package if you want to make it the default kernel (more information).
  3. Add the name of the generated dtb file (without path or extension) to the deviceinfo_dtb file in the deviceinfo file.

A good example of a device using a mainline kernel is the device-nokia-rx51 package.

Porting drivers from a Linux fork to the mainline kernel

This is a massive amount of work, and you will need C knowledge, as well as knowledge about how to contribute to the kernel. It is probably a very frustrating path, so make sure that you are either up to that or consider contributing in pmOS in another, from a developers point of view, more enjoyable way. Documentation from our side is also pretty thin on this, so if you actually work on this, please expand it. Thanks!

If you never worked on kernel before, you may want to help with some simple driver on already-working device. Nokia N900 should be easy, Nokia N9, N950 and Motorola Droid 4 are a bit harder. You might also try to revive support for something older, Nokia N770, N800 or N810 may not be too hard. Next in difficulty is unsupported phone based on supported SoC. TI OMAPs have pretty good support, so Samsung i9100g might be good target... Preparing mainline support for new SoC may be too much work for individual developer.

Preparation

  • Select a device where support is doable. Get a suitable one if necessary.
  • Get a working serial cable
  • Find out hardware details about your device, such as CPU, GPU, display, ...
  • Find out which drivers are missing from mainline.
  • Configure bootloader

Boot with serial output and shell

You probably need to copy over the device tree source, from which the dtb file gets generated, to the mainline kernel. Please expand this.

Links