Thursday, January 23, 2014

Cross compile Raspberry Pi kernel from source on Ubuntu

This post show how to build Raspberry Pi kernel on Ubuntu, then copy the kernel.img and other files to Raspbian installed SD Card.

Create our working directory, raspberrypi:
  • $ mkdir raspberrypi
  • cd raspberrypi
Before start our works, install the necessary tools and source code of Raspberry Pi linux:
  • $ git clone https://github.com/raspberrypi/tools.git
  • $ git clone https://github.com/raspberrypi/linux.git
Prepare the .config file from pre-packaged config, bcmrpi_cutdown_defconfig:
  • $ cd linux
  • $ make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- bcmrpi_cutdown_defconfig
Build kernel:
  • $ make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi-
  • $ mkdir ../modules
  • $ make modules_install ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- INSTALL_MOD_PATH=../modules/
  • $ cd ../tools/mkimage/
  • $ ./imagetool-uncompressed.py ../../linux/arch/arm/boot/Image
Now insert a Raspbian installed SD Card, and run the command:
  • $ sudo rm /media/<boot-partition>/kernel.img
  • $ sudo mv kernel.img /media/<boot-partition>/
  • $ sudo rm -rf /media/<rootfs-partition>/lib/modules/
  • $ sudo rm -rf /media/<rootfs-partition>/lib/firmware/
  • $ cd ../../modules/
  • $ sudo cp -a lib/modules/ /media/<rootfs-partition>/lib/
  • $ sudo cp -a lib/firmware/ /media/<rootfs-partition>/lib/
  • $ sync
Now you can remove the SD Card and use it to boot Raspberry Pi with the new kernel.

- The original kernel run 3.10.25+

- The new generated kernel run 3.10.27+

5 comments:

Gregir said...

Thanks for posting this. In Ubuntu 14.04, the following command just hangs: sudo cp -a lib/firmware/ /media//lib/

Or if it isn't hung, it's taking FOREVER to complete (hours, so far). Any idea why that would be?

Pranita Yeole said...

Thank you so much It really helped me without any failure.
Now my question is that as you took raspbian on sd card as a prerequisite but suppose I want to create .img for raspbian directly so how can I go for it?

Arun Gopal said...

Hi follow the same procedure..
but it is not working for me.my kernel is not initialsing..i have 3.12.22+ kernel.
i need to upgrade from 3.12.26+ kernel.i tried same on this kernels but kernel is not initialising..

Siva Jyothi said...

Hi follow the same procedure.., I got the result without any failure..,
Thanx for the good article.

Wayne Jude Bertumen said...

at present , can this procedure be applicable?