Monday , January 23 2017
Home / Linux / Compiling and Deploying BeagleBone Black Kernel
bbb

Compiling and Deploying BeagleBone Black Kernel

It’s been a while since I my first article and though I need to come up with something a little more advanced this time. Something which will be perfect for the die hard Linux users and those who await to get hands dirty with some kernel grease.

For the sake of this discussion, it is assumed that you have some working knowledge of the Linux operating systems (at least as a user). Needless to say you should have a working bone to follow this tutorial.

BeagleBone Black

BeagleBone Black aka BBB, is a popular Single Board Computer (SBC). We already have a tech review of BeagleBone White you might want to check that out as well.

So the BBB is nothing but the successor of BeagleBone White. If you don’t have it, just order one to dive into the world of Embedded Linux. I’m sure that BBB will occupy a special place in your electronics hardware inventory :-).

Why custom kernel deploying?

Well, I know that this question will be itching your mind. Instead of using the pre-built image, why should we use this method of building our own image and RFS? The answer for this question is, you have to do this in order to get some fun out of BeagleBone. Electronics is a fun when you start doing things of your own and also you will learn lot of things while doing.

For starters, I would strongly recommend to use the pre-built image for working with BeagleBone. But, as I already stated, this post is for the intermediate level users of BBB. This will be cool when you do this and I’m sure this will guide you into the real world of Embedded Linux.

Tools needed to get started

For building linux kernel you will need several tools other than BeagleBone. The tools which are required is listed below:

  • A PC/Laptop with a flavor of Linux (Preferably Ubuntu 14.04)
  • Linux kernel source for BeagleBone Black
  • ARM cross compiler
  • U-Boot(optional)
  • mkimage

1. Installing ARM cross compiler

First and foremost thing in compiling kernel is installing ARM gcc cross compiler. Since, BeagleBone Black is based on AM335x Sitara Processor, we need to compile the kernel for that environment. There are numerous compilers available online for free but it is important to install a stable one for proper compilation. For instance gcc-arm-linux-gnueabihf compiler available in standard Ubuntu package is an unstable one. So, download a stable compiler. The preferred one is Linaro cross compiler.

You can download the compiler here

After downloading, extract the compiler using the following command.

The compiler will be extracted to /opt/ directory. opt is nothing but the optional directory. Next, step is to add the compiler to the PATH variable, in order to direct the shell to find our compiler.

Go to /opt/ directory and change the directory name for adaptivity. Then, add the compiler to PATH variable.

After installing the compiler you can verify it using the following command,

 

2. Cloning the Kernel

After installing the compiler, clone the kernel source for BeagleBone Black from GitHub using

Go to the  linux directory and ensure that you have cloned the correct repo by executing the following command

3. Cloning and Compiling U-boot(Optional)

U-boot is an open source universal bootloader for Linux systems. It supports features like TFTP, DHCP, NFS etc… In order to boot the kernel, a valid kernel image (uImage) is required. It is not possible to explain u-boot here, which is beyond the scope of this post. So, we will see how to produce a bootable image using U-boot.

Clone u-boot using the following command

Before, compiling U-Boot we need to configure it. Thanks to the availability of configuration files in the configs/ directory under u-boot. We can configure using the am332x_boneblack_defconfig file. All the configuration will be written to .config file located in u-boot/ directory. By default you will not be able to view the .config file. To view give ls -a command.

After configuring, u-boot can be cross compiled using the following command.

It will take around 10 to 15 minutes depending on the system configuration. Mine is Pentium dual core processor and it took 10 minutes for compilation. After successful compilation, several files will be produced in u-boot/ directory. Our prime concern is MLO and u-boot.img files.

For now, we will not use the above mentioned files for booting. But, during later stages those will be needed.

4. Formatting SD card

For deploying kernel from sd card, we need to format it and place the files accordingly. For this process, “Gparted” tool is needed. Install Gparted by the following command.

Insert your sd card by means of card reader and open Gparted. Select your sd card from the top right corner. it will be something like this, “/dev/sdb”

Note: Always use sd card of size greater than 2 GB. Although, 500 MB is more than enough for our task, having large free space will come handy at times.

Right click on the rectangular area showing your sd card name and select unmount as we need to unmount the existing partitions. Then, delete the existing partitions by again right clicking and selecting “delete”. This will delete all your files in sd card, so make sure you backed off any important files. We need two partitions in order to boot the kernel, one is for storing the bootable images and another one is for storing the minimal RFS(Root File System). Select new option by right clicking the partitions and provide the following details:

  • New size: 50MBembed journal
  • File System: FAT32
  • Label: BOOT

Click Add button. Then, create another partition for storing RFS by entering the options below

  • New Size: 1000MB
  • File System: EXT3
  • Label: RFS

Finally, click the green tick mark at the menu bar. The partition will be created and you can see two partitions created as BOOT and RFS.

5. Compiling kernel

Before compiling the kernel we need to configure it. It will be hard for the newbies. Once again, thanks to the kernel developers for providing all configurations in a single file. Go to the kernel directory and issue the following command.

This will write the configurations in file bb.org_defconfig to .config file.

Then compile the kernel.

The above command will compile the kernel using the arm cross compiler having the load address as 80008000. “j4” corresponds to the number of process to be run during the compilation. Give the value as twice that of your cpu core. Mine is dual core, so I it gave as 4.

After compiling you can find the image files in “arch/arm/boot/” directory. Copy “uImage” file from this directory and also “am335x-boneblack.dtb” file from “arch/arm/boot/dts/” directory to the BOOT partition.

Then, create a file named as “uEnv.txt” in BOOT partition and copy the following code to it.

This will be the file in which uboot will look upon while booting. The instructions in this file will make the uboot to boot from our kernel.

After completing the above steps you can find the following files in BOOT partition of sd card.

  • uImage
  • am335x-boneblack.dtb
  • uEnv.txt

Note: Make sure you have installed mkimage tool and mounted the sd card.

6. RFS

Download RFS here.

Instead of downloading RFS, we can create own own custom RFS using BusyBox, which will be covered in a separate post. So, as of now download and de-compress the RFS.

The above command will de-compress the tar file and will place it in the RFS partition of sd card. Just replace “mani” with your username in the above command.

7. Install Kernel Modules

We need modules for proper working of the kernel. So, install the kernel modules by the following command.

That’s it. After completing the above steps, remove the sd card and place it in your BeagleBone. Connect the Bone to your PC via USB to serial converter and open the serial console using minicom in PC. (Give baud rate as 115200). After ensuring all things are found correct, power on your BBB while holding the Boot switch (SW2). It will boot from your own custom kernel. Now you can cherish that you have created your own kernel image and deployed it in BeagleBone Black!!!

In my next post I will show you how to create custom RFS using BusyBox. Subscribe to our posts to get the article delivered to your inbox!

As always, if you encountered any troubles on the way, just throw it in the comments, we will try to figure it out.

About Mani

Mani is an Embedded Linux hobbyist having perennial interest towards Electronics and Agriculture. You can reach him by the following social channels.

Check Also

gmail

How to use gmail form terminal (Linux)

Great news gmail our favorite mail service can be accessed form command line!! Now you …

  • Mehmet Aydogan

    This article is very practical and applicable easily to BBB.
    I made sd card with my compiled kernel and run it on BBB. Thanks.

    • Mani Sadhasivam

      Thanks Mehmet,

      Keep visiting Embed Journal for more stuffs…:-)

  • Ivan

    i’ve got trouble with installing kernel modules. Make command saying that no rule to make target “modules”

    • Mani Sadhasivam

      Hi Ivan,

      Seems like your kernel source is not properly installed. Try the steps from the beginning. Also, make sure you were in the source directory while executing the make command.

    • Nikam Yuvraj

      Hi Ivan, You need to give ARM cross compiler PATH

  • Rajesh D

    All above process done successfully. but board was not boot?

  • Rajesh D

    uEnv.txt file didn’t boot kernel. please provide a valid environmental
    file

    • Mani

      Hi Rajesh,

      Can you provide more info? so that I can help you!

    • Mani Sadhasivam

      Hi Rajesh,

      Could you please elaborate? The above mentioned uEnv.txt is valid and it can boot linux kernel from Uboot

  • AndyM

    Was the follow up article on creating a customized RFS written?
    Thanks

    • Mani

      Hi Andy,

      The follow-up article for Custom RFS is on the way… Keep visiting Embed journal

    • Mani Sadhasivam

      Hi Andy,

      Yes, the follow-up article on Custom RFS is on the way… Keep visiting embed journal

    • Yasir Awais Butt

      I had the same problem. Solved it. In the uEnv.txt add these lines at the top:
      loadaddr=0x82000000
      fdtaddr=0x88000000

      You see that the we are specifying that ${loadaddr} uImage but the environment variable loadaddr is not defined. Same for fdtaddr. Still better make the simplest uEnv.txt as fol:
      console=tty0,115200n8
      mmcroot=/dev/mmcblk0p2
      mmcargs=setenv bootargs console=${console} ${optargs} root=${mmcroot} rootfstype=ext4}

      This will boot the device.

      • Uboot will load environment variable from Flash memory to RAM while booting. If it is unable to find valid env from flash, it will load its default environment. For checking the env variables, interrupt uboot by pressing SPACE button and type printenv. This will print all environment variables loaded into the memory.

        If you are specifying loadaddr in uEnv.txt file, it will override the default value. Here, it should be defined by default so only I’ve referenced as ${loadaddr}. The same case applies for fdtaddr also.

        • Yasir Awais Butt

          Thanks bro for explanation. However, I did try to boot with the default values and the kernel booting stopped at Starting Kernel…
          All LEDs became solid. Initially I thought it was a problem with specifying the serial port, but, after some experimentation I got to this solution. I however agree that default values should have worked. Other than that, the tutorial is perfect.

        • Khadar Basha Shaik

          Thanks Yasir and Mani. For me also kernel booting stopped at Starting Kernel.. it started working after adding loadaddr=0x82000000
          fdtaddr=0x88000000 at the top of uEnv.txt file.

          How can we transfer dmesg log to local host ubuntu?

  • Microprocessor

    I completed all steps successfully but the board does not boot the kernel.

    • Mani

      You need to hold the boot switch (S2) while powering up BBB. Hope it helps.

    • Mani Sadhasivam

      You need to hold the Boot Switch (SW2) while powering up BBB.

  • Yasir Awais Butt

    Hi there,
    I am new to linux world and might sound ignorant.
    I have completed all steps and have booted the board. I now want to install native gcc on BBB by compiling it on a ubuntu machine and then putting it on the custom kernel compiled using this tutorial just as an exercise. Is this possible? Also I want to add a package manager. Can someone please provide link to a similar tutorial. I am new to linux world and have been unable to find a resource.

  • Abhilash

    Hi Mani , your article is great .Thanks for the article.
    Where to place the u-boot files i.e MLO and u-boot.bin. Should that be placed in BOOT partition?

    • Hi Abhilash,

      In this article, Uboot binaries were not taken into account. I just showed how to build Uboot for BBB. We’re using existing Uboot to boot our custom kernel. However, if you wanna use your compiled Uboot you can place MLO and uboot.bin in BOOT partition

      • Abhilash

        Hi Mani,
        Thnaks for the quick reply.
        I was able to boot into kernel with the old u-boot present in the beaglebone black.Then i wiped eMMC content . Then i copied MLO and u-boot.bin to BOOT partition of sd card. But the board is not booting. Only ‘C’ appears on terminal.Are you sure we need to copy MLO and u-boot.bin to BOOT directory.

        • Yes… MLO and boot.bin should be in BOOT partition of sd card. BBB’s boot ROM code will try to fetch first stage bootloader aka. MLO from any of the available options. ‘ccccc’ mentions that it is trying to boot from UART. If you have formatted the sd card correctly and placed the MLO in FAT32 partition (BOOT), it should have found it.

          Also, you need to press boot switch(sw2) while powering up BBB. Make sure you are setting ‘boot’ flag for the BOOT partition in Gparted.

        • Abhilash

          Hi Mani,
          I am now able to boot from the sd card. But u-boot.bin did not work.
          Instead if we use u-boot.img then it would work.
          I will just tell what i did so that it will help others.

          In FAT32 partition i.e BOOT copy this files. Remember to mark this partition as boot.

          MLO
          u-boot.img

          uImage
          am335x-boneblack.dtb
          uEnv.txt
          In RFS its same as mentioned in this post.

        • Yeah… That’s a typo which I didn’t catch, it should be u-boot.img

          Thanks,
          Mani.

  • Khadar Basha Shaik

    Hi Mani,

    Thanks for the article.
    After establishing serial connection and logging in as root@beaglebone, How can we transfer dmesg log to local host ubuntu?

    Thanks,
    Khadar

    • Hi Khadar,

      I personally recommend rsync to transfer any files. First create a static ip for BBB-usb and then use ssh to transfer files over rsync. It is more reliable.

      In a simple way, you can mount sd card and then copy the file.

Keep in touch with the current trends!
Did you like this article? Sign up and get our latest posts delivered to your inbox!
  We hate spam and never share your details.