I would like to understand more about how the kernel works. Part of this is to compile it myself. How do I cross-compile the Kernel on a Ubuntu host?
3 Answers
Preparation
First, we need to install the required prerequisites. I assume you have sudo
access.
sudo apt-get install git ncurses-dev make gcc-arm-linux-gnueabi
git
is the version control system used by the Linux kernel team.ncurses
is a library for build console menus. It is necessary formenuconfig
.make
runs the compilation for us.gcc-arm-linux-gnueabi
is the cross-compiler.
Next, we need to retrieve the source, run:
git clone https://github.com/raspberrypi/linux raspberrypi-linux
cd raspberrypi-linux
This will clone the source code to a directory called raspberrypi-linux
and change to it.
Compilation
We first need to move the config file by running
cp arch/arm/configs/bcmrpi_cutdown_defconfig .config
Then configure the kernel build
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- oldconfig
Optional: Customise the build using menuconfig
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- menuconfig
Then run the compilation
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- -k
References
-
1Thank you very much for providing an alternative to using crosstool-ng. Commented Jul 14, 2012 at 21:38
-
In my case CROSS_COMPILE is just a prefix, so the follow should be enough (without gcc at the end):
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- -k
Commented Jun 28, 2014 at 14:21
I think Alex is right but the gcc-arm-linux-gnueabi is compiled for arm cpus without hardware floating point unit. You can find a cross-compiler with armhf support on: https://github.com/raspberrypi/tools and a good tutorial to start with here: http://hertaville.com/2012/09/28/development-environment-raspberry-pi-cross-compiler/
Official documentation
https://www.raspberrypi.org/documentation/linux/kernel/building.md (GitHub)
I would recommend that you just follow the steps there, or send a pull request if something becomes outdated or is not clear enough: those instructions are the most likely ones to be correct and up to date since they are part of the official documentation of the project.