Building BBB Kernel

From eLinux.org
Jump to: navigation, search

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:

Name

Description

toolchain

this will contain the cross compiler

uboot

this will be used to build the mkimage program

kbuild

this will be used to build the kernel


Installing the build tools (toolchain)

3. 1 Compile tools

A suitable compiler can be obtained by issuing the following command

yum install gcc-arm-linux-gnu

Download and install the cross compiler

On non-RHEL platforms, you may wish to try

apt-get install gcc-arm-linux-gnueabi

Debian type platforms


''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:

yum install lzop

Installs the compression program


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

yum install sudo

Installs sudo

visudo

This is all one word, no space


Look for the line

ROOT ALL=(ALL) ALL

Add a new line after that:

xxx ALL=(ALL) ALL

where xxx 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:

cd /home/username/develop/uboot
wget ftp://ftp.denx.de/pub/u-boot/u-boot-latest.bz2 Downloads u-boot
tar -xjf u-boot-latest.bz2 Extract it
cd u-boot-<version>
Building <= v1014.07: make tools-only Builds the tools
Building >= v1014.10: make sandbox_defconfig tools-only Builds the tools
sudo install tools/mkimage /usr/local/bin Installs the mkimage program

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:

git clone git://github.com/beagleboard/kernel.git

This downloads the kernel source

cd kernel


git checkout 3.8

The head of 3.8 release was checked out. For further study how to check out a release tag that matches pre-built published images

./patch.sh

This step may take 10 minutes or longer


Some further preparations before the kernel is built:

cp configs/beaglebone kernel/arch/arm/configs/beaglebone_defconfig

We wish to build beaglebone series kernels

wget http://arago-project.org/git/projects/?p=am33x-cm3.git\;a=blob_plain\;f=bin/am335x-pm-firmware.bin\;hb=HEAD -O kernel/firmware/am335x-pm-firmware.bin

Pre-compiled power management firmware

cd kernel



These steps will compile the kernel and some kernel modules:

make ARCH=arm CROSS_COMPILE=arm-linux-gnu- beaglebone_defconfig


make ARCH=arm CROSS_COMPILE=arm-linux-gnu- uImage dtbs

This step builds the kernel and may take 15-20 minutes or longer

make ARCH=arm CROSS_COMPILE=arm-linux-gnu- uImage-dtb.am335x-boneblack

This step builds the kernel for the BBB

make ARCH=arm CROSS_COMPILE=arm-linux-gnu- modules

This builds the kernel modules and may take 20 minutes or longer


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 /home/username/develop/kbuild/kernel/kernel/arch/arm/boot folder, there will be a uImage-dtb.am335x-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.cmd

-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.cmd

-rw-rw-r--. 1 user user 4277954 Jun 16 14:43 uImage-dtb.am335x-bone

-rw-rw-r--. 1 user user 4278377 Jun 16 14:43 uImage-dtb.am335x-boneblack

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

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

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

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

[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:

mkimage -l uImage-BBB

Similar to the ‘file’ command; it examines the file and displays some information


[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:

setenv autoload no


dhcp

Obtain IP config via DHCP


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

setenv serverip 192.168.1.76

Replace with the IP address of your Linux server

tftp 0x80200000 uImage-BBB

This was the file that was called uImage-dtb.am335x-boneblack. Notice that the address needs to be 0x80200000 and not the address that the mkimage –l command reported

setenv bootargs console=ttyO0,115200n8 quiet root=/dev/mmcblk0p2 ro rootfstype=ext4 rootwait

The file system (that will be on top of the Linux kernel) is the one on the eMMC card for now

bootm 0x80200000

The parameter passed here is the addresses of where the kernel image was dumped


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

Here is some example output:

U-Boot SPL 2013.04-dirty (May 20 2013 - 14:30:06)

musb-hdrc: ConfigData=0xde (UTMI-8, dyn FIFOs, HB-ISO Rx, HB-ISO Tx, SoftConn)

musb-hdrc: MHDRC RTL version 2.0

musb-hdrc: setup fifo_mode 4

musb-hdrc: 28/31 max ep, 16384/16384 memory

USB Peripheral mode controller at 47401000 using PIO, IRQ 0

musb-hdrc: ConfigData=0xde (UTMI-8, dyn FIFOs, HB-ISO Rx, HB-ISO Tx, SoftConn)

musb-hdrc: MHDRC RTL version 2.0

musb-hdrc: setup fifo_mode 4

musb-hdrc: 28/31 max ep, 16384/16384 memory

USB Host mode controller at 47401800 using PIO, IRQ 0

OMAP SD/MMC: 0

mmc_send_cmd : timeout: No status update

reading u-boot.img

reading u-boot.img



U-Boot 2013.04-dirty (May 20 2013 - 14:30:06)


I2C: ready

DRAM: 512 MiB

WARNING: Caches not enabled

NAND: No NAND device found!!!

0 MiB

MMC: OMAP SD/MMC: 0, OMAP SD/MMC: 1

*** Warning - readenv() failed, using default environment


musb-hdrc: ConfigData=0xde (UTMI-8, dyn FIFOs, HB-ISO Rx, HB-ISO Tx, SoftConn)

musb-hdrc: MHDRC RTL version 2.0

musb-hdrc: setup fifo_mode 4

musb-hdrc: 28/31 max ep, 16384/16384 memory

USB Peripheral mode controller at 47401000 using PIO, IRQ 0

musb-hdrc: ConfigData=0xde (UTMI-8, dyn FIFOs, HB-ISO Rx, HB-ISO Tx, SoftConn)

musb-hdrc: MHDRC RTL version 2.0

musb-hdrc: setup fifo_mode 4

musb-hdrc: 28/31 max ep, 16384/16384 memory

USB Host mode controller at 47401800 using PIO, IRQ 0

Net: <ethaddr> not set. Validating first E-fuse MAC

cpsw, usb_ether

Hit any key to stop autoboot: 0

U-Boot#

U-Boot#

U-Boot# setenv autoload no

U-Boot# dhcp

link up on port 0, speed 100, full duplex

BOOTP broadcast 1

DHCP client bound to address 192.168.1.70

U-Boot# setenv serverip 192.168.1.76

U-Boot# tftp 0x80200000 uImage-BBB

link up on port 0, speed 100, full duplex

Using cpsw device

TFTP from server 192.168.1.76; our IP address is 192.168.1.70

Filename 'uImage-BBB'.

Load address: 0x80200000

Loading: #################################################################

        #################################################################         
        #################################################################         
        #################################################################         
        ################################                                          
        392.6 KiB/s                                                               

done

Bytes transferred = 4280457 (415089 hex)

U-Boot# setenv bootargs console=ttyO0,115200n8 quiet root=/dev/mmcblk0p2 ro rootfstype=ext4 rootwait

U-Boot# bootm 0x80200000

## Booting kernel from Legacy Image at 80200000 ...

  Image Name:   Linux-3.8.13-00650-gb0f8aff                                       
  Image Type:   ARM Linux Kernel Image (uncompressed)                             
  Data Size:    4280393 Bytes = 4.1 MiB                                           
  Load Address: 80008000                                                          
  Entry Point:  80008000                                                          
  Verifying Checksum ... OK                                                       
  Loading Kernel Image ... OK                                                     

OK


Starting kernel ...


Uncompressing Linux... done, booting the kernel.

[ 0.192647] omap2_mbox_probe: platform not supported

[ 0.203312] tps65217-bl tps65217-bl: no platform data provided

[ 0.280007] bone-capemgr bone_capemgr.8: slot #0: No cape found

[ 0.317116] bone-capemgr bone_capemgr.8: slot #1: No cape found

[ 0.354223] bone-capemgr bone_capemgr.8: slot #2: No cape found

[ 0.391333] bone-capemgr bone_capemgr.8: slot #3: No cape found

[ 0.411269] bone-capemgr bone_capemgr.8: slot #6: BB-BONELT-HDMIN conflict P8.4)

[ 0.420889] bone-capemgr bone_capemgr.8: slot #6: Failed verification

[ 0.427668] bone-capemgr bone_capemgr.8: loader: failed to load slot-6 BB-BONEL)

[ 0.450198] omap_hsmmc mmc.4: of_parse_phandle_with_args of 'reset' failed

[ 0.514871] pinctrl-single 44e10800.pinmux: pin 44e10854 already requested by 47

[ 0.526614] pinctrl-single 44e10800.pinmux: pin-21 (gpio-leds.7) status -22

[ 0.533928] pinctrl-single 44e10800.pinmux: could not request pin 21 on device e

[ 1.245582] systemd[1]: Failed to insert module 'autofs4'

[ 1.504995] systemd[1]: Failed to open /dev/autofs: No such file or directory

[ 1.512556] systemd[1]: Failed to initialize automounter: No such file or direcy

[ 1.520702] systemd[1]: Failed to set up automount Arbitrary Executable File Fo.

[ 6.637581] libphy: PHY 4a101000.mdio:01 not found

[ 6.642639] net eth0: phy 4a101000.mdio:01 not found on slave 1

systemd-fsck[84]: Angstrom: clean, 50555/112672 files, 291538/449820 blocks


.---O---.

| | .-. o o

| | |-----.-----.-----.| | .----..-----.-----.

| | | __ | ---'| '--.| .-'| | |

| | | | | |--- || --'| | | ' | | | |

'---'---'--'--'--. |-----''----''--' '-----'-'-'-'

               -'  |                                                              
               '---'                                                              


The Angstrom Distribution beaglebone ttyO0


Angstrom v2012.12 - Kernel 3.8.13-00650-gb0f8aff


beaglebone login:

Appendix: Installing and configuring the TFTP server

First, get the software installed; here, the TFTP client was installed too although it was not used.

yum install tftp-server

Install server

yum install tftp

Install client


Then, go to System->Administration->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

chmod 666 /tftpboot

Allow any user to place and access software in this folder


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

service tftp

{

disable = no

protocol = udp

port = 69

socket_type = dgram

wait = yes

user = root

server = /usr/sbin/in.tftpd

server_args = -s -c /tftpboot

per_source = 11

cps = 100 2

flags = IPv4

}

Then do:

/etc/init.d/xinetd stop

Stop the service

/etc/init.d/xinetd start

Start the service


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:

setenforce 0

or edit /etc/selinux/config and set

SELINUX=enforcing

to

SELINUX=disabled

Appendix: Installing and using Minicom

Install the software:

yum install minicom

Downloads and installs minicom


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

pu port /dev/ttyUSB0

pu baudrate 115200

pu bits 8

pu parity N

pu stopbits 1

pu minit

pu mreset

pu mdialpre

pu mdialsuf

pu mdialpre2

pu mdialsuf2

pu mdialpre3

pu mdialsuf3

pu mconnect

pu mnocon1 NO CARRIER

pu mnocon2 BUSY

pu mnocon3 NO DIALTONE

pu mnocon4 VOICE

pu rtscts No


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

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

Type ls -ltr /dev 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.dfl 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 minicom and you will be connected to the BBB

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