Build the Kernel

Now that you have connected to the virtual machine, we can start the build process. First let's look at some of the build options included with the build kernel build helper.

You can view the build options by entering sudo ./build -h and pressing return.

$ sudo ./build -h
usage: build [options]
 This will build the Raspberry Pi Kernel.
 OPTIONS:
    -h        Show this message
    -r        The remote github repo to clone
              Default: raspberrypi/linux
    -b        The git branch to use
              Default: Default git branch of repo
    -1        The config file to use when compiling for Raspi v1
              Default: arch/arm/configs/bcmrpi_defconfig
    -2        The config file to use when compiling for Raspi v2
              Default: arch/arm/configs/bcm2709_defconfig

Let's look at the config options in more detail:

  • -h shows you the usage instructions shown above.
  • -r allows you to pass a GitHub repo in username/repo format that will be used instead of the official Raspberry Pi linux repo found here: https://github.com/raspberrypi/linux
  • -b specifies the name of the git branch on the repo to use when compiling. If you do not supply a branch, the default branch of the selected git repo will be used.
  • -1 allows you to point to a custom config file for the Raspberry Pi v1 build. This can be an absolute path to a file on the virtual machine, or a relative path from the root of the selected git repo. By default the config file selected is arch/arm/configs/bcmpri_defconfig.
  • -2 allows you to point to a custom config file for the Raspberry Pi v2 build. This can be an absolute path to a file on the virtual machine, or a relative path from the root of the selected git repo. By default the config file selected is arch/arm/configs/bcm2709_defconfig.

Now that you know what your options are, let's start a simple build of the latest version of the official Raspberry Pi kernel using the default build settings. To do that, we need to run sudo build.

After build finishes cloning a the required repos for building the kernel, you will be presented with a menu. This is the menu configuration for the kernel, where you can add or remove modules and capabilities. Tweak any options you want here; if you would like to use the defaults in the config file, it is safe to exit and save. Hit TAB and RETURN to exit, and RETURN again to confirm that you want to save.

Now comes the part where you sit and watch a kernel compile. It takes about 15 minutes on a 2Ghz Intel i7 with 8 cores working to finish the kernel for the Raspberry Pi v1, but the compile time will vary depending on your machine.

Once the kernel for v1 has finished, you will be presented with the same menu again to configure the options for the Raspberry Pi v2 kernel build. Configure, exit and save the configuration to start building the kernel for the Raspberry Pi v2.

Once both builds have finished, build will create a tar.gz archive that you can transfer to your Raspberry Pi. The archive will be available in the Kernel-o-Matic folder on your host computer.

If you would like to build something other than the current official kernel, you can use the options we went over earlier to change the git repo, git branch, and config files the compiler uses. Let's say you wanted to compile the rpi-3.15.y branch of the Adafruit fork of the Raspberry Pi kernel, and use the adafruit_defconfig configuration file found in the repo for the Raspberry Pi v1 build. The build command would look like this:

$ sudo build -r https://github.com/adafruit/adafruit-raspberrypi-linux -b rpi-3.15.y -1 arch/arm/configs/adafruit_defconfig

Custom PiTFT Builds

If you would like to build a custom kernel with our PiTFT additions included, you should use the pitft branch of the Kernel-o-Matic repo. First, switch to the pitft branch in the cloned Kernel-o-Matic folder on your host machine.

git fetch && git checkout pitft

SSH back into the Kernel-o-Matic VM.

vagrant ssh

Then, run build with no arguments. The pitft branch is pointed to the proper linux repo, branch, device tree overlays, and custom defconfigs for the PiTFT hardware.

sudo build

The rest of the build process will look the same as using the default settings described earlier, and you can use both instances of menuconfig to make any changes you would like to the kernel for both versions of the Raspberry Pi. A custom pitft tar.gz archive will be available in the Kernel-o-Matic folder on the host machine when the build has finished. In the next section, we'll show you how to install the custom kernel on your Raspberry Pi.

Last updated on 2016-09-25 at 12.06.30 AM Published on 2015-01-30 at 06.49.17 PM