Ubuntu kernel build alternatives

This page gathers several options for building an Ubuntu kernel, either as a binary package or directly using the standard kernel make command, both natively (on an ARM board) or cross-compiled.

Several ways for generating an Ubuntu kernel are described here. Prefered way is described here Ubuntu kernel for OMAP4:
 * kernel packaging using debuild
 * kernel packaging using dpkg-build-package
 * kernel packaging using debian/rules
 * standard kernel building (kernel Makefile)

= A note on required tools / packages = If you need to generate kernel packages, you will have to install additional tools. Most of the tools can be installed by running: sudo apt-get build-dep linux-image-$(uname -r)

Here is a non-exhaustive list of the packages that are usually required for packaging: git-core debhelper build-essential fakeroot kernel-wedge libelf-dev debhelper xmlto docbook-utils gs transfig sharutils pbuilder binutils-dev libdw-dev asciidoc

= Native compilation =

debuild
debuild is a wrapper on top of dpkg-buildpackage. It is installed with the devscript package: sudo apt-get install devscript

debuild -b -uc -us

dpkg-buildpackage
fakeroot debian/rules clean dpkg-buildpackage -B

debian/rules
fakeroot debian/rules clean export $(dpkg-architecture -aarmel) do_tools=false fakeroot debian/rules binary-arch

kernel Makefile
cp debian.ti-omap4/config/config.common.ubuntu .config make make uImage

= Cross-compilation = Here, you will need a cross toolchain. The cross-toolchains usually used are: Linaro toolchain is prefered as more up to date, and in line with the gcc shipping with Ubuntu.
 * Linaro one: https://wiki.linaro.org/MarcinJuszkiewicz/Projects/UbuntuCrossToolchains (https://wiki.linaro.org/WorkingGroups/ToolChain/CrossCompilerOnLucid)
 * CodeSourcery one (2010q1 link): http://www.codesourcery.com/sgpp/lite/arm/portal/release1293

The examples below assume you are using the CodeSourcery 2010q1 toolchain. If you want to use Linaro instead, just replace arm-none-linux-gnueabi- by arm-linux-gnueabi-.

Note: the do_tools=false option is required with CodeSourcery 2010q1. It will prevent the generation of the tools binary package (including perf) that would fail with CodeSourcery 2010q1 toolchain (to be checked with Linaro or more recent CodeSourcery).

debuild
debuild -eCROSS_COMPILE=arm-none-linux-gnueabi- --prepend-path= -edo_tools=false -aarmel -uc -us -b (replace  with the correct path)

dpkg-buildpackage
fakeroot debian/rules clean CROSS_COMPILE=arm-none-linux-gnueabi- do_tools=false dpkg-buildpackage -B -aarmel -uc -us

debian/rules
fakeroot debian/rules clean export $(dpkg-architecture -aarmel) CROSS_COMPILE=arm-none-linux-gnueabi- do_tools=false fakeroot debian/rules binary-arch

kernel Makefile
cp debian.ti-omap4/config/config.common.ubuntu .config ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- make uImage

= ABI and modules change verification = The kernel packaging tools will fail package creation if the kernel ABI or modules-list changed since the last packaged version. This test can be skipped to complete the package creation in spite of ABI or modules list change. Add the following option depending on your build method:
 * debuild: add '-eskipabi=true -eskipmodule=true' to your command line
 * dpkg-buildpackage and debian/rules: add 'skipabi=true skipmodule=true' to your command line

= kernel source package =

The kernel source package contains the kernel sources. Here is an easy way to generate it: git clean -fdx fakeroot debian/rules clean time debuild -S -sa -uc -us -I.git -I.gitignore -i'\.git.*'

= Links =