Cross Compilation and Booting of Linux kernel for Raspberry Pi3 – Manual Compilation

For this post, we assume that you already have a working root filesystem as we did in “Building kernel and filesystem using Yocto for Raspberry Pi / Creating Embedded Linux for RPi using Yocto” since we just want to showcase how to manually compile kernel for RPi.

Download Linux kernel source code from raspberry pi git

 $ mkdir -p /home/myuser/rpi 
 $ cd /home/myuser/rpi 
 $ git clone git:// --depth=1 

This will download the default HEAD branch from the remote repository.

$ cd linux 
$ git branch
      * rpi-4.9.y

downloading toolchain

$ cd /home/myuser/rpi 
 $ git clone --depth 1 
 $ cd tools
$ git branch
* master

export toolchain path

 $ export PATH=$PATH:/home/myuser/rpi/tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/bin 

Configuring Linux Kernel

 $ cd linux 

default configuration file for RPi3 is arch/arm/configs/bcm2709_defconfig

 $ make ARCH=arm CROSS_COMPILE=arm-bcm2708-linux-gnueabi- bcm2709_defconfig 

Above command will do the default configuration of kernel for compilation for RPi

Now, we will compile the kernel to create kernel binary using below command,

 $ make ARCH=arm CROSS_COMPILE=arm-bcm2708-linux-gnueabi- zImage modules dtbs 

This command will create, kernel zImage at arch/arm/boot/zImage

$ file arch/arm/boot/zImage
arch/arm/boot/zImage: Linux kernel ARM boot executable zImage (little-endian)

Now, we have to copy this image into first partition of the SD card by using standard name as “kernel7.img” as,

 $ sudo cp -r arch/arm/boot/zImage /media/myuser/raspberrypi/kernel7.img 

Assuming that first partition of sdcard is mounted at /media/myuser/raspberrypi/ ( you can check same using df -h command )

Related :   How Linux Kernel Module Loading works ?

Now, put unmount this SD card and put to RPi and power ON RPi,

You can check now the booted kernel is what we manually compiled as,

root@raspberrypi3:~# cat /proc/version 
Linux version 4.9.45-v7+ (myuser@myhost) (gcc version 4.7.1 20120402 (prerelease) (crosstool-NG 1.15.2) ) 
#1 SMP Mon Aug 28 19:52:58 IST 2017


Subscribe with Valid Email Id to receive updates in Inbox. ( Secured by Google FeedBurner )


1 thought on “Cross Compilation and Booting of Linux kernel for Raspberry Pi3 – Manual Compilation”

Leave a Comment

Android Android Applications Android Build system Android Commands Application Libraries Application Stack / User Interface Bash / Shell Scripts Bluetooth driver Cloud Technologies Commands and Packages Compilation Content Management System Core Kernel C Programs Development & Build Development, Debugging and Performance Tools Development Environment Setup Django & REST Api Errors & Failures Git Hardware Platforms HTML JAVA Programs Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Multimedia Audio, Video, Images NDK / Middleware / HAL OS Concepts PHP Programming Languages Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Source Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Web design and development Website Hosting Wordpress Yocto / Bitbake / Openembedded