Building BBB Kernel

=Beaglebone Black – Building Images=

Introduction
The Beaglebone Black is still a very young board, and new software images are being created every few weeks or more often. The supplied image on the built-in eMMC is no longer recent, and so one of the first steps is to update the image to a more recent version at this link http://beagleboard.org/latest-images (eMMC flasher image).

However, some people may want to explore the source and be able to compile a custom image if desired, and perhaps contribute to the source. I think (not sure) that exploring the 3D graphics processor currently will also require the capability to compile up kernel modules.

Many people are doing Beaglebone Black activities, so thankfully there is lots of information on how to create an image. There are other links too, but some of them are missing bits of information that probably some people are already familiar with. The information here documents an entire process. Special thanks to Vlad Ungureanu for helping in the debugging.

Hopefully over time people can also document the process for mounting the file system over NFS, and for building against a specific release.

Is it difficult?
No, but definitely be prepared to google for information if an error occurs.

What is required?

 * A Linux server with perhaps 20Gbytes of free disk space (A VM was used here). Note that the steps here used a variant of Red Hat Enterprise Linux (RHEL), Scientific Linux in this case; the steps may also work on (say) Centos.
 * A USB to 3.3V serial cable
 * A 5V power supply
 * An Ethernet cable and connection (e.g. into a switch port on a home router)

What steps are involved?
Some build tools (also known as a toolchain) are required to be installed; the tools include the cross-compiler and other utilities.

Once the toolchain is installed on the Linux server, the kernel software is downloaded and then compiled. This part of the process may take an hour or more depending on the speed of the server.

After compilation, the built image can be downloaded to the BBB via TFTP; the remainder file system can be mounted using NFS.

Note that the transfer via TFTP, and testing the image, requires the TFTP service to be installed and configured on the Linux server, and optionally minicom to be installed (if you don’t have any terminal software). If your server does not have TFTP service already installed, or you need minicom, see the steps listed at the end.

Getting started - Folders
Create a development folder at a suitable location, such as off your home directory, e.g. called develop (e.g. /home/username/develop, this entire path is referred to in places below). In that folder, create these three folders:

3. 1 Compile tools
A suitable compiler can be obtained by issuing the following command

On non-RHEL platforms, you may wish to try

Note: on RHEL, the current toolchains from the Angstrom site and from TI’s SDK both had issues building the kernel.''

Once installed, on RHEL, the path to the compiler is /usr/bin, which should already be part of the PATH environment variable, so no need to change it. If you type ls /usr/bin/arm* then you will see that the executables are named arm-linux-gnu-gcc for example.

3.2 Some miscellaneous items
Install lzop (a file compression program) because that will get used. As root user:

You may as well install and configure sudo if you don’t already have it, because some scripts in the SDK use sudo:

as root user, type

Look for the line

Add a new line after that:

where  is your username and then save the file.

3.3 U-boot
U-boot also needs to be installed so that a mkimage program can be used which is part of the software.

The instructions at this site http://wiki.beyondlogic.org/index.php/BeagleBoneBlack_Building_Kernel were used to install u-boot:

Downloading and building the Linux Kernel
In the /home/username/develop/kbuild folder, the instructions at the beagleboard.org site http://beagleboard.org/linux were followed, with the make commands slightly altered to reflect the toolchain executable naming.

First, the source code was downloaded, checked-out and patched:

Some further preparations before the kernel is built:

These steps will compile the kernel and some kernel modules:

This whole process took around an hour on a VM running on a i5 2.5GHz laptop. On an i7 1.6GHz, it took twice as long, so if you have a choice then it makes sense to spend some time examining which server you really wish to develop on.

In the  folder, there will be a  uImage-dtb.am 335x-boneblack file.

[user@sl61 boot]$ pwd

/home/user/dev/kbuild/kernel/kernel/arch/arm/boot

[user@sl61 boot]$ ls -al

total 23372

drwxrwxr-x. 5 user user   4096 Jun 16 14:43.

drwxrwxr-x. 87 user user   4096 Jun 16 13:49 ..

drwxrwxr-x. 2 user user   4096 Jun 16 13:45 bootp

drwxrwxr-x. 2 user user   4096 Jun 16 14:43 compressed

drwxrwxr-x. 3 user user  20480 Jun 16 14:43 dts

-rw-rw-r--. 1 user user     46 Jun 16 13:45 .gitignore

-rwxrwxr-x. 1 user user 6790368 Jun 16 14:24 Image

-rw-rw-r--. 1 user user    112 Jun 16 14:24. Image.cm d

-rw-rw-r--. 1 user user   1274 Jun 16 13:45 install.sh

-rw-rw-r--. 1 user user   3404 Jun 16 13:48 Makefile

-rw-rw-r--. 1 user user 4254248 Jun 16 14:24 uImage

-rw-rw-r--. 1 user user    235 Jun 16 14:24. uImage.cm d

-rw-rw-r--. 1 user user 4277954 Jun 16 14:43 uImage-dtb.am 335x-bone

-rw-rw-r--. 1 user user 4278377 Jun 16 14:43 uImage-dtb.am 335x-boneblack

-rw-rw-r--. 1 user user    298 Jun 16 14:43. uImage-dtb.am335x-boneblack.cm d

-rw-rw-r--. 1 user user    283 Jun 16 14:43. uImage-dtb.am335x-bone.cm d

-rwxrwxr-x. 1 user user 4254184 Jun 16 14:43 zImage

-rw-rw-r--. 1 user user    139 Jun 16 14:43. zImage.cm d

[user@sl61 boot]$

Copy the file to /tftpboot (rename it to something shorter like uImage-BBB in the /tftpboot folder for convenience).

You can inspect the image by typing:

[user@sl61 tftpboot]$ mkimage -l uImage-BBB

Image Name:  Linux-3.8.13-00650-g5506bfa

Created:     Sun Jun 16 14:43:36 2013

Image Type:  ARM Linux Kernel Image (uncompressed)

Data Size:   4278313 Bytes = 4178.04 kB = 4.08 MB

Load Address: 80008000

Entry Point: 80008000

[user@sl61 tftpboot]$

You should see that the location and entry point addresses of the image are 0x80008000.

Transferring the image to the BBB via TFTP
Start up minicom, and power up the BBB; quickly press space repeatedly to stop it at the u-boot prompt.

Then, type the following at the u-boot prompt:

An IP address should be acquired now – assume it is 192.168.1.70 for now.

With the final command listed above, you should see the kernel begin execution.

Here is some example output:

Appendix: Installing and configuring the TFTP server
First, get the software installed; here, the TFTP client was installed too although it was not used.

Then, go to System-&gt;Administration-&gt;Firewall and make sure tftp and tftp client are checked.

As root user, create a /tftpboot folder if it doesn’t exist, and then do

Also, change the /etc/xinetd.d/tftp file so that this is the contents:

Then do:

Note that if you are running Linux on a VM, then you probably most likely will need to change the network adapter settings from the default NAT, to Bridged. With Bridged, your server will use DHCP to get its own IP address from the router’s DHCP server.

Note that if you still have difficulty getting TFTP functioning (you could test it from a different server) then try temporarily disabling the firewall entirely, and disabling selinux. If that works, then that narrows down the problem. To disable selinux type:

or edit /etc/selinux/config and set

to

Appendix: Installing and using Minicom
Install the software:

Create a file called  minirc.df l in the /etc folder and populate it with this content:

Note that the first line (containing  ) may need adjustment. This is now explained.

type  in a window; then, plug in a USB to serial port adapter into the server.

Type  in another separate window, and you should see a difference; A file called ttyUSB0 may be created (along with some other files), or a slightly different name. Place that name as part of the first line in the minirc.df l file.

Time to test minicom: For some reason, despite being a member of the ‘dialout’ group, using the USB port seems to only work as root user, or if you issue chmod 666 /dev/ttyUSB0 as root user.

As root (or issue the chmod command mentioned above first), type just  and you will be connected to the BBB

Type CTRL-A and then 'h' for help, or CTRL-A and then 'x' to exit.