18

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?

Peter Mortensen
  • 2,004
  • 2
  • 15
  • 18
Alex Chamberlain
  • 15,530
  • 14
  • 67
  • 113

3 Answers3

25

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 for menuconfig.
  • 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
Alex Chamberlain
  • 15,530
  • 14
  • 67
  • 113
4

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/

aronadaal
  • 176
  • 2
  • 5
1

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.