How to cross compile a Raspberry Pi kernel Debian (Raspbian) package from source
Published 17 September 2013 under raspberry, pi, kernel, debian, raspbian, cross compile
Compiling a new kernel on a Raspberry Pi itself takes a long time. This is how to cross-compile a kernel package. An Intel i7 laptop does the job in 11 minutes.
I am assuming that you are using an Ubuntu/Mint Linux distribution.
System set-up
Install the kernel-package package:
sudo apt-get install kernel-package
This contains make-kpkg which will build the .deb file.
Install an appropriate cross compiler.
sudo apt-get install gcc-arm-linux-gnueabihf
This should provide /usr/bin/arm-linux-gnueabihf-gcc (among other things).
Get kernel source
Download the linux kernel source (this example is the Afterthought Software version to support the RasClock RTC, however, any linux kernel source should work)
git clone https://github.com/afterthoughtsoftware/linux.git
Simple build
The following will use 5 parallel jobs and this seems fine on my Intel i7 laptop. Adjust this number if you don't have 4 threads on your machine.
cd linux
make ARCH=arm bcmrpi_defconfig
DEB_HOST_ARCH=armhf nohup make-kpkg --rootcmd fakeroot --arch arm --cross-compile arm-linux-gnueabihf- --revision=1.0 --jobs 5 kernel_image &
The DEB_HOST_ARCH is required due to a bug in make-kpkg (http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=664854). armhf can't be specified as the --arch.
Note that the following warnings will probably occur:
dpkg-architecture: warning: specified GNU system type arm-linux-gnu does not match gcc system type x86_64-linux-gnu, try setting a correct CC environment variable
Using nohup will create a nohup.out file which can be viewed to watch progress of the build. e.g. using
tail -f nohup.out
Removing installation warnings
In order to get rid of annoying warnings when installing the kernel on your RaspberryPi, a post-install script is required.
#!/usr/bin/env bash
echo "Running post-install"
# This gets run multiple times during the build process, so must be careful
# when the operations are actually performed!
# Remove these links as they produce warnings when the package is unpacked
if [ "$IMAGE_TOP" != "" ]; then
if [ "$version" != "" ]; then
rm -f $IMAGE_TOP/lib/modules/$version/build
rm -f $IMAGE_TOP/lib/modules/$version/source
fi
fi
Put this script in a file called post-install, make sure it's executable, in a directory somewhere, e.g. ~/overlay-dir
Then add --overlay-dir ~/overlay-dir to make-kpkg command line. This will remove the dangling links created as part of the build.
make ARCH=arm bcmrpi_defconfig
DEB_HOST_ARCH=armhf nohup make-kpkg --rootcmd fakeroot --arch arm --cross-compile /usr/bin/arm-linux-gnueabihf- --revision=1.0 --jobs 5 --overlay-dir ~/overlay-dir kernel_image &
Comments
blog comments powered by Disqus