Wednesday, August 14, 2013

New kernel for Rasberry Pi


Last year, December, 2012 I received my Raspberry Pi board from RS Elements. Honestly it takes a long time, about 5 month. My order for the board was sent from July 2012. Actually I received several message from RS Elements that the order would take several months.

Anyway, this week I already finish my setup for raspberry, below picture represents my current setup.

My setup consists of below items:

  • Raspberry Pi board Rev 2.0

  • FTDI RS232 TTL, this devices for serial logging

  • Raspberry PI GPIO cable, this cable to avoid direct connection to Raspberry Pi GPIO pins

  • Female to male jumper cables to connect FTDI RS232 TTL to Raspberry GPIO pins

  • Class 10, 8 GB micro SD card with SD card housing

  • Micro usb power adapter, 5v, 700mA. (Raspberry Pi needs at least 700mA)

[Serial output configuration ]

Since I don't have TV / Monitor for raspberry pi specific use, I decide to debug and checking via serial log. To get serial log from raspberry pi you need to have FTDI RS232 TTL, and by connecting the devices' UART pin to raspberry pi UART pin.

Serial log is not always enabled by any images, anyhow Raspbian images that I used is already enable serial this serial log. But to make sure serial log is enable or not, you can check it on /boot/cmdline.txt files, the contents of that file should be like below:

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

The line “console=ttyAMA0,115200 kgdboc=ttyAMA0,115200” enables serial log for kernel debug output.

In other hand, you also need to make sure that serial console is activated as well after Linux is completely boot. You can check on /etc/inittab files and make sure below line is not commented or missing

T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

[Linux Kernel Compilation Preparation]

Before we go further, I would inform that we will use git extensively to download toolchains and Linux code for raspberry pi. So, it's highly recommended to install git in your Linux system.

In this post, I will reports my trial cross compiling Linux kernel for Raspberry Pi using my Slackware box. Before we go compiling, we need toolchains and as you know raspberry is on arm architecture so we need arm compiler to do this trial. You can download the toolchains from below path.

git clone

That command will create tools-master directory which contains toolchains.

Now we have the toolchains and next we need to download Linux source for Raspberry pi, you also can download it from github using below command.

git clone

You will find out new “linux” directory which contains Linux source code.

[Build New Kernel]

Clean Linux code using below command:

$ cd <linux code path> $ make mrproper

In this case I want to use “.config” from Raspbian image. The way I retrieve the “.config” file is like below:

  • Boot up your Raspberry using Raspbian image
  • Insert USB drive and mount it using below command

    # mount /dev/sda1 /mnt/

  • Copy Raspbian “.config” to usb, in my case I'll copy “.config” file as raspbian_config in usb drive

    # zcat /proc/config.gz > /mnt/raspbian_config

  • Also you can use <linux code path>/arch/arm/configs/bcmrpi-defconfig as your .config file
    But I have not try this one.

Copy Raspbian “.config” and use it as our linux “.config”. Insert your usb drive which contains Raspbian “.config” into you Linux system and copy it into Linux code directory as “.config”.

$sudo mount /dev/sda1 /mnt $cp /mnt/raspbian_config <linux code path>/.config

After that we need to set prefix compiler of our toolchain for compiling.

$ export CCPREFIX=<your tool-master directory>/arm-bcm2708/arm-bcm2708-linux-gnueabi/bin/arm-bcm2708-linux-gnueabi-

Our “.config” file can be from older version of our kernel code, so we need to sync it with our kernel by using below command. After executing the command some questions regarding new feature of new kernel will come out and need to be answered.

$ make ARCH=arm CROSS_COMPILE=${CCPREFIX} oldconfig

And after synchronization of “.config” is done, we can go to build kernel and modules using below command.


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

If building process is successfully done, we need to gather all modules in one directory to make easier to control by using below command.

$ export MODULES_TEMP=~/modules


Then, we can find our new kernel in: “<linux_code_path>/arch/boot/Image” and modules in “<linux_code_path>/modules/”. The next step is copying kernel and new modules into current raspberry rootfs in SD Card by using below command.

$ sudo mount /dev/sda1 /mnt (in assumption your sd card is on /dev/sda1)

$ cp <linux code path>/arch/boot/Image /mnt/boot/kernel.img

$ cp $MODULES_TEMP/* /mnt/lib/*

After that insert your SD Card into your Rasberry and reboot, if booting process is done successfully it means new kernel and modules is no problem.