I originally wrote an article on cross-compiling for ARM systems, some time ago – before I got my first Raspberry Pi – and this is a more up-to-date version.
This is how I cross-compile ARM kernels, on x86_64. There are – of course – other ways of doing this, but this works, for me..
The following info assumes that you are already familiar with compiling your own Linux kernels..
For the cross-compiler and associated system files, I found the set for Mandriva works fine, and installed OK on my Fedora x86_64 systems, and is suitable for producing kernels for armv5 (DreamPlug) and armv6 (Raspberry Pi) systems, as well as armv7..:
I run Fedora (and – now – Pidora) on all my Linux systems, but – of course – there are similar cross-compiler toolchains available for Debian, Arch Linux, Gentoo, and other distros..
I – personally – don’t use the # make…. ARCH=ARM… method, but instead I modify the top-level Makefile, as I wanted the kernel and modules etc. to all be resident in a local directory.. One point to mention is that – assuming this is all somewhere in your ~/home directory – the compilation can be run as a normal user..
This example is for the Raspberry Pi, but the compilation stage is the same for other arm systems, with UBoot etc. For arm systems which can use the standard mainstream kernel, such as the DreamPlug, boot image creation has recently changed to use the ‘device tree’, dtbs, mkimage etc. but that is outside the scope of this particular article!
First, unpack the kernel source (from github..) in its own directory (raspberrypi-312 in the example below..). Remember not to use the ‘download zip’ option (see previous article)..
Then create a ‘lib’ (sub)directory there.
Then edit the top-level Makefile, as follows (changing the armvxx……. description to suite your particular cross-compiler installation, if different..)
around line 195: change: ARCH ?= $(SUBARCH) CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:"%"=%) to: ARCH ?= arm CROSS_COMPILE ?= armv7l-mandriva-linux-gnueabi- -------------------------------------------------^ Don't forget the dash at the end, so the compile process will find the correct version of gcc..
To install modules etc. locally – under the ../lib directory,
around line 695: change: export INSTALL_PATH ?= /boot to: export INSTALL_PATH ?= ../boot and add: export INSTALL_MOD_PATH ?= ../ - then run # make xconfig (or whatever you prefer...) # make and.. # make modules_install Do not run # make install!
The Pi uses a kernel.img file, along with some binary ‘firmware’ files (for the GPU) and config files, residing in the fat partition.
So, the whole kernel (compiled) source / lib / kernel.img package directory structure looks like:
raspberrypi-312 | | | | | tools (containing kernel.img file) | | | linux (containing compiled kernel source) | lib (containing modules and firmware directories created by the kernel compilation)
Then copy the kernel.img file to the boot (FAT) partition, to be accessed by the bootloader, and copy the directories/files from the ../lib/modules and ../lib/firmware directories to the corresponding directories on the root (EXT3 or 4) directory on the SD Card.
Usual disclaimer – This works on my system (Currently Fedora 20, Kernel 3.12) It may not on yours.
Robert Gadsdon.. November 16, 2013.