Raspberry Pi Kernel Compile

  

This tutorial will demonstrate how to cross compile the kernel for the Raspberry Pi on Ubuntu 12.04 LTS. The kernel is functional with both the Debian and Arch Linux Raspberry Pi images.  First, install the package dependencies, git and the cross-compilation toolchain:

sudo apt-get install git-core gcc-4.6-arm-linux-gnueabi

Create a symlink for the cross compiler:

sudo ln -s /usr/bin/arm-linux-gnueabi-gcc-4.6 /usr/bin/arm-linux-gnueabi-gcc

Make a directory for the sources and tools, then clone them with git:

mkdir raspberrypi
cd raspberrypi
git clone https://github.com/raspberrypi/tools.git
git clone https://github.com/raspberrypi/linux.git
cd linux

Generate the .config file from the pre-packaged raspberry pi one:

make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- bcmrpi_cutdown_defconfig

If you want to make changes to the configuration, run make menuconfig (optional):

make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- menuconfig

Once you have made the desired changes, save and exit the menuconfig screen. Now we are ready to start the build. You can speed up the compilation process by enabling parallel make with the -j flag. The recommended use is ‘processor cores + 1′, e.g. 5 if you have a quad core processor:

make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- -k -j5

Assuming the compilation was sucessful, create a directory for the modules:

mkdir ../modules

Then compile and ‘install’ the loadable modules to the temp directory:

make modules_install ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- INSTALL_MOD_PATH=../modules/

Now we need to use imagetool-uncompressed.py from the tools repo to get the kernel ready for the Pi.

cd ../tools/mkimage/
./imagetool-uncompressed.py ../../linux/arch/arm/boot/Image

This creates a kernel.img in the current directory. Plug in the SD card of the existing Debian image that you wish to install the new kernel on. Delete the existing kernel.img and replace it with the new one, substituting “boot-partition-uuid” with the identifier of the partion as it is mounted in Ubuntu.

sudo rm /media/boot-partition-uuid/kernel.img
sudo mv kernel.img /media/boot-partition-uuid/

Next, remove the existing /lib/modules and lib/firmware directories, substituting “rootfs-partition-uuid” with the identifier of the root filesystem partion mounted in Ubuntu.

sudo rm -rf /media/rootfs-partition-uuid/lib/modules/
sudo rm -rf /media/rootfs-partition-uuid/lib/firmware/

Go to the destination directory of the previous make modules_install, and copy the new modules and firmware in their place:

cd ../../modules/
sudo cp -a lib/modules/ /media/rootfs-partition-uuid/lib/
sudo cp -a lib/firmware/ /media/rootfs-partition-uuid/lib/
sync

That’s it! Exject the SD card, and boot the new kernel on the Raspberry Pi!

 

25 Comments

  1. if you copt the boot directory from the firmware github onto the sdcard boot partition, you can just copy the kernel image arch/arm/boot/bzImage to sdcard/boot_partitiion/kernel.img – it will work straight away.

  2. sokkaaj

    What is the modification you’re talking about on the external USB rootfs page?

    • The modification allows you to move the root filesystem (ie ‘/’) from the SD card to a USB drive. I have several USB drives in excess of 16GB, but only a 4GB SD card. Moving ‘/’ to the USB drive gives me much more space.

  3. iqzer0++

    is there any way to change the root password ?

  4. Moin dear Michel and interrogators!
    Thank You for detailed instruction which I was looking for since I found no direct ADSL connection over PPPoE provided for on RP.
    Perhaps some more advice available in this direction?
    Greetings from Hamburg, North Germany!
    Ludolf

    • Hi Ludolf,
      It looks like PPP is supported by default, but PPPoE is not. For kernel support, you will need to enable the PPPoE module. In the .config file, change:
      # CONFIG_PPPOE is not set
      to
      CONFIG_PPPOE=m
      Then you should be able to follow the official Debian instructions to configure PPPoE here:
      http://wiki.debian.org/PPPoE

  5. hey, i’ve followed all the steps above and the new kernel runs, but a can’t load modules and getting Exec format error after modprobe

  6. Hey ,

    All steps are very clear to me. I successfully built the kernel and run on the board. but it fails to load any module as even mouse and keyboard attached to board stop responding. Please guide me through this…Thanks.

    Zia

  7. make modules_install ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- INSTALL_MOD_PATH=../modules/

    should be

    make modules_install ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi-gcc-4.6 INSTALL_MOD_PATH=../modules/

  8. Thank you very much for this tutorial please help me I cannot locate xorg.conf file.
    I’m using raspbmc and compiling went well but I’m missing xorg.conf.
    Touch is now working but I cannot do anything until edit this file.

  9. Very nice tutorial!

  10. 110202820

    Whenever I try to move the kernel to the sd card, it tells me that kernel.img doesnt exist. Help?

  11. When I type in the first line it says “could not locate package” please help

  12. Ramesh

    I followed the above steps and It worked fine for me..Thanks a lot

  13. Worked for me; thanks very much!

  14. Thank you very much for the tutorial, it the easiest out there to follow. Maybe you can add how to calibrate it in the end. http://engineering-diy.blogspot.dk/2013/01/adding-7inch-display-with-touchscreen.html This tutorial dose almost as you do (You do it better) but in the end there are some calibration instructions.

    Ok. to my question :) I have followed your tutorial and the touch screen is working perfectly. But my WiFi USB dongle is stop working… Is it some thing in the configuration file that is missing or some bad communication between the injected kernel.img and the drivers? have suggestions?

    Thanks.

    Noam

  15. I also got the failed message on the first step. Has the version number been updated since 12.04ls?

  16. Snake Hi, I have not had luck with the instructions. I am trying to use a AOC usb monitor with my Pi. Can you provide instruction for copying the kernel.
    Thanks
    Ken

Trackbacks/Pingbacks

  1. Raspberry Pi Root FS on USB Drive | MitchTech - [...] This tutorial will demonstrate how to install the Debian root filestem (ie. ‘/’) on a USB drive instead of …
  2. Compile Kernel on CentOS/RHEL for Raspberry Pi at 爱折腾 - [...] http://mitchtech.net/raspberry-pi-kernel-compile/ [...]
  3. Raspberry PI and AOC e1649Fwu USB powered LED monitor « imkiyoung - [...] Follow instructions in http://mitchtech.net/raspberry-pi-kernel-compile/ [...]
  4. Recompiler le kernel du Raspi avec les outils Linaro | Le blog d'Androme - [...] Sources : http://elinux.org/RPi_Kernel_Compilation http://mitchtech.net/raspberry-pi-kernel-compile/ [...]
  5. How to fully encrypt your Raspberry Pi (CryptoPi) : ROAB/sec - [...] http://mitchtech.net/raspberry-pi-kernel-compile/ [...]
  6. Raspberry piにDisplayLinkのUSBディスプレイを接続する | tetro - [...] Mimo USB Monitor and Raspberry Pi – anuk nurkhede Raspberry Pi Kernel Compile – MitchTech これでダメなら諦めた方が良い程度にRasberry [...]
  7. วิธีการคอมไพล์ kernel ของ raspberry pi | Ayarafun Factory - [...] เพิ่มเติม http://elinux.org/RPi_Kernel_Compilation http://mitchtech.net/raspberry-pi-kernel-compile/ [...]
  8. RaspberryPiでdisplaylink | ITでGameなMusic! - […] 【ココと ココと ココと ココと ココと ココと ココ 参照】 […]
  9. eGalax Touch (Cross compiling Pi) - 李小华的博客 - […] first step in getting this done is to compile the raspbian kernel with necessary kernel module. Here is a nice …

Leave a Reply