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.
We download the cross-toolchain for ARM:
vi /etc/make.conf
PORTDIR_OVERLAY="/usr/local/portage/overlay/"
crossdev -S -v -t arm-unknown-linux-gnueabi
We download the ARM compiler:
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
revdep-rebuild
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:
We take the config to the server where we will compile:
We configure the kernel:
make ARCH=arm CROSS_COMPILE=${CCPREFIX} menuconfig
We compile:
We compile modules:
We install the modules:
mkdir
export MODULES_TEMP=
make ARCH=arm CROSS_COMPILE=${CCPREFIX} INSTALL_MOD_PATH=${MODULES_TEMP} modules_install
cd ~
tar czvf modules.tar.gz modules
We copy the image and modules to the Rasp:
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:
git clone git://github.com/raspberrypi/firmware.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:
rm -rf /opt/vc/ 2>/dev/null
For Hard:
For Soft:
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 ;)