Build a B3 Kernel on your crossdev PC - sakaki-/gentoo-on-b3 GitHub Wiki

Build a kernel for your B3 in minutes, using your crossdev PC!

Prerequisites

This guide assumes that you have already set up crossdev and the gentoo-b3 overlay on your PC, per these instructions. So, if you haven't yet, please do this first, before proceeding.

Building a B3-Compatible Kernel

First, we need to download some kernel sources; you can use any that you like, but for simplicity, in this guide we'll use the standard gentoo-sources package (which contains the kernel.org sources, with Gentoo's standard patchset applied).

So, let's say you wanted 4.1.6, the version used in the current live USB image. You should issue the following to pull down the sources (note we use --nodeps here; we don't actually want to cross-emerge the perl etc. tools that'll be used to patch the sources, as you already have them in your native architecture (amd64 or whatever) and they'll be called from there):

gentoo_pc ~ # armv5tel-softfloat-linux-gnueabi-emerge --ask --verbose --nodeps ~sys-kernel/gentoo-sources-4.1.6

This may take some time to complete, depending on the speed of your network connection.

Note also that while this particular kernel version's ebuild (4.1.6) was in the Gentoo repository at the time of writing, it may have been purged by the time you read this (Gentoo only keeps a subset of all available kernel versions as ebuilds at any point in time). In that case, simply use a more modern version. You can use a tool like eix to show all the currently available ebuild versions for a given package (such as gentoo-sources).

Now, go into the source directory (crossdev automatically keeps things separate from your normal sysroot, to avoid pollution):

gentoo_pc ~ #  cd /usr/armv5tel-softfloat-linux-gnueabi/usr/src/linux-4.1.6-gentoo

Grab a suitable starter config from somewhere, such as the one used in this project ^-^, save it to .config, and then run the buildkernel-b3 script to build the kernel (see its manpage for options - in particular, add --usb, if you want to build a kernel that is bootable from USB, rather than the B3's hard drive; --menuconfig if you'd like to change the configuration using the editor, at the start of the build; and --custom-dts=<path_to_dts_file> if you would like to specify a custom device tree source file, such as the one used on the live USB (which turns the purple LED on during early boot)):

gentoo_pc linux-4.1.6-gentoo # cp <your config file> .config
gentoo_pc linux-4.1.6-gentoo # buildkernel-b3 --zimage

This does a parallel make, so on a modern PC, it shoudn't take long (5-15 mins).

NB: these instructions assume you are using version >= 2.0.0 of the live-USB, which has an interstitial ("bootloader") kernel in place to patch and chainload "vanilla" zImage files. Please refer to the buildkernel-b3 manpage for instructions on building directly-bootable kernels for earlier versions of the live-USB.

When done, you'll have a deploy_root directory, which will contain:

  • a lib directory, with the modules and firmware for the kernel; and
  • a boot directory, which will contain the files zImage, System.map, config and kirkwood-b3.dtb.

You can now simply copy these files over to the real root (on the B3's hard drive, or the live-USB, as appropriate), and you can try booting with your new kernel!

The next time you invoke buildkernel-b3 in the same directory (perhaps with a slightly altered configuration) it should be significantly faster, since most of the required components will be already compiled.

Next Steps

Now that you have a functioning cross-compilation environment on your PC, why not hook it up to distcc? This will allow your B3 to leverage the power of your PC when performing local builds (for C and C++ compilation and header pre-processing), and makes it possible to use a source-based distribution like Gentoo without huge update times. See these instructions for details on how to proceed.