How to Cross compile kernel for BeagleBone Black ?

By | May 16, 2016

Here comes another stage of embedded Linux development, that is kernel compilation for beaglebone black. In this post, we will see the procedure to fetch the kernel source, apply beaglebone kernel configuration and compile the kernel.

As you know, a simple Embedded Linux system consist of 3 major components, that is bootloader, kernel, root filesystem. In the previous post, we have seen the procedure to compile the bootloader for beagle board. So, first stage of beaglebone embedded Linux development is completed.

In this post we will only discuss about kernel compilation. In the upcoming posts, we will see the procedure to boot kernel from different mediums such as TFTP, MMC/SD card, eMMC, and from other flash memories.

Kernel is my heart

BeagleBone Development Environment :

Nothing much required for kernel building.

  • Software
    • Ubuntu 14.04
  • Others
    • Internet (to download kernel source)

Required Ubuntu Tools :

Few common tools required for kernel fetching and for compilation.

$ sudo apt-get install minicom git ncurses-dev 

Download cross compiler :

If you have a cross compiler, you can skip this step. Else run the below command to download a ARM based Linaro cross compiler.

$ sudo apt-get install gcc-arm-linux-gnueabi

Download kernel Source :

Beagle board kernel source repository is available in this link. To clone the this GitHub kernel repository run the below command.

$ git clone git://github.com/beagleboard/linux.git

Download will take sometime and consumes arround 1 GB of your Internet data. Download log will be as shown below.

minion@ubuntu:~/minion/bbb$ git clone git://github.com/beagleboard/linux.git
 Cloning into 'linux'...
 remote: Counting objects: 4786537, done.
 remote: Compressing objects: 100% (1590/1590), done.
 remote: Total 4786537 (delta 1144), reused 19 (delta 19), pack-reused 4784924
 Receiving objects: 100% (4786537/4786537), 1.03 GiB | 384.00 KiB/s, done.
 Resolving deltas: 100% (4003068/4003068), done.
 Checking connectivity... done.
 Checking out files: 100% (52709/52709), done.
 minion@ubuntu:~/minion/bbb$

After successful download, you can enter into the kernel source root directory.

$ cd linux/

Choose desired Kernel branch :

At present, kernel source is pointed to “4.4” branch by default. If you want a particular branch for your development, you can follow below procedure.

  • To know about the list of available branches, run the below command.
git branch -r

Log will be as shown below.

minion@ubuntu:~/minion/bbb/linux$ git branch -r
  origin/3.12
  origin/3.13
  origin/3.14
  origin/3.8
  origin/3.8-green
  origin/3.8.13-bone67-pruspeak
  origin/3.8.13-bone69-bb-view-7
  origin/3.8.13-bone71-input-polldev
  origin/3.8.13-bone71-lsm303
  origin/4.1
  origin/4.1-abbbi
  origin/4.1-bbbw
  origin/4.1-i2c-speed
  origin/4.4
  origin/4.4-capemgr-eeprom-disable-hack
  origin/4.4-ev3dev
  origin/HEAD -> origin/4.4
  origin/beaglebone-3.2
  origin/master
minion@ubuntu:~/minion/bbb/linux$
  • Checkout the desired kernel branch by running below command. I want to use 4.1 kernel for my development.
usage : git checkout <git-branch> -b <local-branch-name>
$ git checkout origin/4.1 -b 4.1

You will get similar log as shown below

minion@ubuntu:~/minion/bbb/linux$ git checkout origin/4.1 -b 4.1
Checking out files: 100% (4478/4478), done.
Branch 4.1 set up to track remote branch 4.1 from origin.
Switched to a new branch '4.1'

Configuration of build environment :

By default, kernel build system uses x86 architecture and native gcc compiler. This is not correct of ARM based systems.

So, It is mandatory to specify the ARCH and CROSS_COMPILE to compile the kernel.

Based on these definitions, kernel build system understands which architecture and cross compile to be used. So export them, ‘make’ command automatically fetches these definitions during compilation.

$ export ARCH=arm
$ export CROSS_COMPILE=arm-linux-gnueabi-

Apply beaglebone kernel configuration :

Kernel configurations for ARM based SOC are available in the below folder.

ls arch/arm/configs/*

Kernel configuration for beaglebone black is bb.org_defconfig

To apply this configuration, run below command.

$ make bb.org_defconfig

This command write it configurations to the .config file available in the kernel source root directory. You will get below log.

minion@ubuntu:~/minion/bbb/linux$ make bb.org_defconfig
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/kconfig/conf.o
  SHIPPED scripts/kconfig/zconf.tab.c
  SHIPPED scripts/kconfig/zconf.lex.c
  SHIPPED scripts/kconfig/zconf.hash.c
  HOSTCC  scripts/kconfig/zconf.tab.o
  HOSTLD  scripts/kconfig/conf
#
# configuration written to .config
#
minion@ubuntu:~/minion/bbb/linux$

Build/Compile the kernel:

Finally issue make command to compile the kernel. Kernel build system allows you specify the CPU utilization during the build process. This can be done by using -jX option.

To get more throughput, X value can be calculated using below formula. In my case, No of processors: 4.

make -j(1.5 x No.processors)
$ make -j6

Make command compiles all drivers, modules, device trees, that are specified in the configuration file.

Generate uImage by running below command

make uImage LOADADDR=0x80008000 -j6

After a successful compilation, kernel binaries zImage, uImage generates under arch/arm/boot/ folder.

ls arch/arm/boot/zImage

OK, kernel compilation is done. In the up coming post, we will see the procedure to customize the kernel and device trees also as mentioned above kernel booting.

Embedded Rocks !!

Good day.

 

4 thoughts on “How to Cross compile kernel for BeagleBone Black ?

  1. Pingback: Beaglebone Black Embedded Linux Development with Buildroot : part-1 - EmbeddedForU

  2. Satyanarayana G

    Hi….am new to working with Beagelebone Black Rev C .Because of some reasons I could not start my BBB ooard.I would like to make new bootable SD card .as the part I found your article and followed your instructions.Its fine I successfully did compilation, kernel binaries zImage, uImage generates under arch/arm/boot/ folder.
    what to do next to wake up means to boot my BBB.Please give suggest me sir.

    Thanks and Regards,
    Satya,
    India.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *