This page looks best with JavaScript enabled

Compiling Raspberrypi kernel for different architecture

 ·  🎃 kr0m

In this article, we will explain the necessary steps to compile a kernel for ARM from Amd64. The ultimate goal is to compile the kernel of our Raspberrypi without having to wait an eternity. To carry out our enterprise, we will need the following software:

  • Kernel sources
  • Cross-toolchain for ARM
  • ARM compiler

We download the kernel sources.

Note: These sources are NOT vanilla since they do not have the drivers for the Raspberrypi hardware, and we would have to patch them.

mkdir /usr/src/rpi_kernel
cd /usr/src/rpi_kernel
git clone

We download the cross-toolchain for ARM:

emerge -av sys-devel/crossdev
vi /etc/make.conf
mkdir -p PORTDIR_OVERLAY=“e --deep --with-bdeps=y @worldusr/local/portage/overlay/
crossdev -S -v -t arm-unknown-linux-gnueabi

We download the ARM compiler:

git clone git://

NOTE: It is compiled for 32 bits, so we must have emulation support enabled in the kernel:

Executable file formats / Emulations --->
[*] IA32 Emulation
<*> IA32 a.out support
[*] x32 ABI for 64-bit mode 
emerge emul-linux-x86-baselibs
export CCPREFIX=/usr/src/rpi_kernel/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-
cd linux
make mrproper

We extract the base config of the Rasp:

zcat /proc/config.gz > /root/punto_config

We take the config to the server where we will compile:

scp /root/punto_config root@IP:/usr/src/rpi_kernel/linux/.config

We configure the kernel:

make ARCH=arm CROSS_COMPILE=${CCPREFIX} oldconfig –> If there are options that are not in our config, it will ask us ;)
make ARCH=arm CROSS_COMPILE=${CCPREFIX} menuconfig

We compile:


We compile modules:

make -j2 ARCH=arm CROSS_COMPILE=${CCPREFIX} modules

We install the modules:

rm -rf ~/modules 2>/dev/null
mkdir ~/modules
export MODULES_TEMP=~/modules
cd ~
tar czvf modules.tar.gz modules

We copy the image and modules to the Rasp:

scp /root/modules.tar.gz IP_RASP:/root/
scp /usr/src/rpi_kernel/linux/arch/arm/boot/Image IP_RASP:/root/

We install the image and modules:

rm -rf modules 2>/dev/null
tar xvzf modules.tar.gz
cp -r /root/modules/lib/modules/* /lib/modules/
cp /boot/kernel.img /boot/kernel.img.ori
cp /root/Image /boot/kernel.img

There are occasions when changing the kernel requires changing the firmware since there are considerable changes:

emerge -av dev-vcs/git
git clone git://
cp firmware/boot/bootcode.bin firmware/boot/fixup.dat firmware/boot/start.elf /boot/

We will also copy the VC libraries, but we must know whether to copy the hard or soft ones:

${CCPREFIX}gcc -v 2>&1 | grep har
rm -rf /opt/vc/ 2>/dev/null

For Hard:

cp -r firmware/hardfp/opt/vc/ /opt/

For Soft:

cp -r firmware/opt/vc/ /opt/

For the laziest, I leave here my config and a compiled image .

NOTE: This image does not support modules, so we can skip the module installation part. It is also designed to act as a server or FW, audio drivers, wireless cards, and other fancy things have been removed, while everything related to encryption, iptables, and network protocols has been added ;)

If you liked the article, you can treat me to a RedBull here