Linux

This guide will help you through the steps to build a Linux kernel for your desired platform.

Prerequisites

All of the common prerequisites apply.

Requirements

Suggestions

Branch Name-Scheme

The builserver can only build your images, if you follow the correct name-scheme for the branches.

The variables that are needed for your platform can be found in the User Documentation.

Variables

Variable Notes
Platform-String Specified and mapped to the target architecture by the Administrator. Found in the User Documentation
Major Kernel major version number (X.2.3)
Minor Kernel minor version number (1.X.3)
Subminor Kernel subminor version number (1.2.X)

Branches

To avoid unnecessary redundancy, which will naturally occur if you build multiple platforms for the same kernel version, following branch structure is necessary. The default build scripts (generic, platform) follow exactly this idea.

Branch Dependency Task
version_generic platform independent Provide Linux sources with Gentoo patches
version_platform platform dependent Store .config, user patches, call build script in version_generic branch

For each kernel version, there will be exactly one version_generic branch, where for each platform there will be one version_platform branch. Following name-scheme has to be followed.

Branch Scheme Example
version_generic < major >.< minor >.< subminor > 3.17.2
version_platform < major >.< minor >.< subminor >_< platform-string > 3.17.2_raspberry-pi

Example Linux
Repository

Step-by-Step Example

The following example will give you a detailed overview of the necessary steps to build kernel 3.18.7 for the raspberry pi. We assume that at this point the linux-specs repository is empty.

Add New Upstream Kernel

Before you can add a new platfom, for which you want to build a Linux kernel, you first need to add a version_generic branch to the linux-specs repository.

  1. Clone the linux-specs repository with the URL provided in the user documentation.

    $ git clone git@apu.in.htwg-konstanz.de:labworks-embEDUx/linux.git

  2. Add a version_generic branch to the linux-specs repository.

    $ git checkout master $ git branch 3.18.7 $ git checkout 3.18.7 $ touch README.md $ git add README.md $ git commit -m "inital commit" $ git push --set-upstream origin 3.18.7

  3. Add the default script as build to the branch and make it executable.

    $ ls -hl

    total 4.0K
    -rwxr-xr-x 1 user user 2.9K Mar  1 20:52 build
    -rw-r--r-- 1 user user    0 Mar  1 20:51 README
    
  4. Modify < kernel-url >, < kernel-file > in the build script, to match the desired kernel version. You also need to modify < patch-version >, which is the version of the Gentoo specific patches. Be careful as the version number of the Gentoo patches doesn't follow the version number of the Linux kernel. In this case Gentoo patches 3.18-9 result in Linux kernel 3.18.7.

    ...
    KERNEL_URL="http://www.kernel.org/pub/linux/kernel/v3.x"
    KERNEL_FILE="linux-3.18.tar.xz"
    ...
    PATCH_VERSION="3.18-9"
    ...
    
  5. Before you push your changes upstream, make sure the build script is running without any errors. If you need help, have a look at Local Testing

  6. Add your changes, commit and push them upstream.

    $ git add build $ git commit -m "new kernel" $ git push

  7. Now that you have a version_generic branch for your desired Linux kernel version within your linux-specs repository, the next step is to add a version_platform branch.

Add New Platform

This step requires an existing version_genereric branch for the Linux kernel version you want to add a platform.

  1. If not already done, clone the linux-specs repository with the URL provided in the user documentation.

    $ git clone git@apu.in.htwg-konstanz.de:labworks-embEDUx/linux.git

  2. Add a version_platform branch to the linux-specs repository. It is necessary that you push the branch at this point upstream, so the buildserver can find the new version_platform branch.

    $ git checkout master $ git branch 3.18.7_raspberry-pi $ git checkout 3.18.7_raspberry-pi $ touch README.md $ git add README.md $ git commit -m "inital commit" $ git push --set-upstream origin 3.18.7_raspberry-pi

  3. Add the default build script as build to the branch and make it executable.

    $ ls -hl

    total 4.0K
    -rwxr-xr-x 1 user user 2.9K Mar  1 21:20 build
    -rw-r--r-- 1 user user    0 Mar  1 21:19 README
    
  4. Modify < kernel-version > in build to the desired version_generic branch. Then modify < kernel-dtb > to the desired device tree blob. If your platforms device tree sources aren't in the Linux kernel sources yet, you have to add them with a patch, as described in a later step.

    ...
    KERNEL_VERSION="3.18.7"
    ...
    KERNEL_DTB="bcm2835-rpi-b.dtb"
    KERNEL_CONFIG=".config"
    ...
    
  5. Add a working kernel configuration .config to the branch. If you aren't sure weather your kernel configuration is working or not, you can run the build script locally with a proper toolchain.

    $ ls -hla

    total 76K
    drwxr-xr-x 1 user user  44 Mar  1 21:29 .
    drwxr-xr-x 1 user user 650 Mar  1 15:04 ..
    -rwxr-xr-x 1 user user 562 Mar  1 21:25 build
    -rw-r--r-- 1 user user 69K Mar  1 21:29 .config
    drwxr-xr-x 1 user user 188 Mar  1 21:29 .git
    -rw-r--r-- 1 user user   0 Mar  1 20:51 README
    
  6. Optional: Add needed patches to the root directory of your branch. The patch needs to be in the standard patch format, eg. created with diff -Naur.

    $ diff -Naur linux/.../smsc95xx.c.old linux/.../smsc95xxx.c > 9000-Smsc95xx_allow_mac_to_be_set.patch $ ls -hl

    total 8.0K
    -rw-r--r-- 1 user user 2.8K Mar  1 21:38 9000-Smsc95xx_allow_mac_to_be_set.patch
    -rwxr-xr-x 1 user user  562 Mar  1 21:25 build
    -rw-r--r-- 1 user user    0 Mar  1 20:51 README
    
  7. Before you push your changes upstream, make sure the build script is running without any errors. If you need help, have a look at Local Testing

  8. Add all changes, commit and push them upstream.

    $ git add build $ git add .config $ git add *.patch $ git commit -m "added raspberry-pi 3.18.7 kernel build" $ git push

  9. The buildserver should start building your kernel image now. For further informations on how to monitor the build check monitoring guide.

  10. Congratulations, you just built your first kernel for your first platform. If you have a uboot, a rootfs and the necessary misc files, you can flash everything with the Flashtool or deploy your files manually (see Hardware Deployment).