BBB Embedded Linux Systems 6
BBB Embedded Linux Systems 6
de Telemática y Electrónica
Universidad Politécnica de Madrid
Embedded Linux
Systems
Mariano Ruiz
Francisco Javier Jiménez
2016
Page 2 of 38
Table of figures
Fig. 1: Main screen of VMware player with some VM available to be executed. _______________ 6
Fig. 2: Ubuntu Virtual Machine login screen. ___________________________________________ 7
Fig. 3 Buildroot home page. ________________________________________________________ 7
Fig. 4: Downloading buildroot source code. ____________________________________________ 8
Fig. 5: Buildroot folder (the folder name depends on the version downloaded). ______________ 8
Fig. 6: Dash home, Terminal application _______________________________________________ 9
Fig. 7: Buildroot setup screen (make xconfig). The content of this windows depends on the
parameter selected._________________________________________________ 10
Fig. 8: Successful compilation and installation of Buildroot ______________________________ 15
Fig. 9: Schematic representation of the Buildroot tool. Buildroot generates the root file system,
the kernel image, the booloader and the toolchain. Figure copied from “Free
Electrons” training materials (http://free-electrons.com/training/) __________ 15
Fig. 10: images folder contains the binary files for our embedded system. __________________ 16
Fig. 11: Main window for configuring the Linux kernel. __________________________________ 17
Fig. 12: BBB. 18
Fig. 13: BeagleBone Black block diagram _____________________________________________ 18
Fig. 14: Powering BBB with USB ____________________________________________________ 19
Fig. 15: BBB serial line header terminal identification. __________________________________ 19
Fig. 16: Identification of the terminals in the USB-RS232 adapter _________________________ 19
Fig. 17: Booting process for BBB.____________________________________________________ 20
Fig. 18: BeagleBone. S2 push button _________________________________________________ 21
Fig. 19: Putty program main window. ________________________________________________ 21
Fig. 20: Running Linux. ____________________________________________________________ 22
Fig. 21: AM335x Processor’s memory map. ___________________________________________ 23
Fig. 22: Summary of the different configurations for developing applications for embedded
systems. Figure copied from “Free Electrons” training materials (http://free-
electrons.com/training/) _____________________________________________ 26
Fig. 23: Cross compiling tools installed in the host computer _____________________________ 27
Fig. 24: Selection of the workspace for Eclipse. Use a folder in your account. ________________ 27
Fig. 25: Eclipse welcome window. ___________________________________________________ 28
Fig. 26: Eclipse main window. ______________________________________________________ 28
Fig. 27: Basic C project creation in Eclipse ____________________________________________ 29
Fig. 28: Cross-compiler prefix and path window. _______________________________________ 29
Fig. 29: Hello world example. ______________________________________________________ 30
Fig. 30: Tool Chain Editor should be configured to use Cross GCC. _________________________ 30
Fig. 31: Cross tools locate on (path).The path shown in this figure is an example.Use always the
path of your toolchain. ______________________________________________ 31
Fig. 32: Include search path. _______________________________________________________ 31
Fig. 33: Libraries search path. ______________________________________________________ 32
Fig. 34: Eclipse project compiled (Binaries has been generated). __________________________ 33
Fig. 35: Run test program in Raspberry PI _____________________________________________ 34
Fig. 36: Creating a Debug Configuration ______________________________________________ 34
Fig. 37: Debug configuration including the path to locate the cross gdb tool. ________________ 35
Fig. 38: Synaptic program from Dash ________________________________________________ 37
Fig. 39: Synaptic windows _________________________________________________________ 38
Page 3 of 38
1 SCOPE
T
Document Overview
This document describes the basic steps to develop and embedded Linux-based system using the
BeagleBone Black (BBB). The document has been specifically written to use a BBB development
system based on the AM335x Texas Instruments Sitara processor. All the software elements used to
build the Linux distribution have a GPL license.
[Time to complete the tutorial]: The time necessary to complete all the steps in this
tutorial is approximately 8 hours.
Read carefully all the instructions before executing the practical part otherwise you will find errors and
probably unpredicted errors. In parallel you need to review the slides available at Moodle site or at [RD1]
Acronyms
BBB BeagleBone Black
CPU Central Processing Unit
EABI Extended Application Binary Interface
EHCI Enhanced Host Controller Interface
I/O Input and Output
MMC Multimedia card
NAND Flash memory type for fast sequential read and write
PCI Peripheral Component Interconnect – computer bus standard
PCI Express Peripheral Component Interconnect Express
OS Operating system
UART Universal Asynchronous Receiver Transmitter
USB Universal Serial Bus
Page 4 of 38
2 REFERENCED DOCUMENTS
References
[RD1] Embedded Linux system development.
Slides at https://moodle.upm.es/titulaciones/oficiales/course/<your course>
[RD2] Hallinan, C. Embedded Linux Primer. Second Edition. Prentice Hall. 2011.
[RD3] getting-started-with-ubuntu
[RD4] http://free-electrons.com/training/embedded-linux/
[RD5] http://elinux.org/Beagleboard:BeagleBone#Rev_A6A User Guide. Reference Manual.
[RD6] http://www.uclibc.org/ uclib web site.
[RD7] http://www.gnu.org/software/binutils/ Binutils web site.
[RD8] http://elinux.org/BeagleBoardBeginners#Formatting_the_SD_card_via_fdisk_.22Expert_m
ode.22
Page 5 of 38
3 LAB1: BUILDING LINUX USING BUILDROOT
Elements needed for the execution of these LABS.
In order to execute properly this lab you need the following elements:
1. VMware WorkStation player version 12.0 or above. Available at www.wmware.com (free download
and use). This software is already installed in the laboratory desktop computer.
2. A VMWare virtual machine with Ubuntu 14.04 and all the software packages installed is already
available in the Desktop. This virtual machine is available for your personal use at the Department
assistance office (preferred method). If you want to setup your virtual machine by yourself follow
the instructions provided in the Annex I.
3. A BBB, the accessories and USB cable are available at the laboratory.
4. Basic knowledge of Linux commands. Available at http://www.ee.surrey.ac.uk/Teaching/Unix/ UNIX
tutorial for beginners.
Page 6 of 38
Fig. 2: Ubuntu Virtual Machine login screen.
Open the Firefox web browser and download from https://buildroot.org/ the version identified as
buidlroot2016-05 (use the download link, see Fig. 3, and navigate searching for a specific release,
https://buildroot.org/downloads/ ). Save the file to the Documents folder in your account (Fig. 4).
Page 7 of 38
Fig. 4: Downloading buildroot source code.
Copy the file to the “Documents” folder and decompress the file (Fig. 5).
Fig. 5: Buildroot folder (the folder name depends on the version downloaded).
Right click in the window and execute “Open in Terminal” or execute from Dash home the Terminal
application as is shown in the Fig. 6 (if “Open in Terminal” is not available, search how to install it in Ubuntu).
Page 8 of 38
Fig. 6: Dash home, Terminal application
xxx@ubuntu:~/Documents$ cd buildroot-2016.05
xxx@ubuntu:~/Documents/buildroot-2016.05$ make xconfig {or make menuconfig}
[Help]: You can use either “make xconfig” or “make menuconfig”. If “make xconfig”
returns an error try “make menuconfig”
[Help]: In Linux “TAB” key helps you to autocomplete de commands, folders and files
names. You can find a description of “make” application in this link
https://www.gnu.org/software/make/manual/make.pdf
In some seconds you will see a new window with a content similar to Fig. 7.
Page 9 of 38
Fig. 7: Buildroot setup screen (make xconfig). The content of this windows depends on the parameter selected.
Configuring Buildroot.
Once Buildroot configuration is started, it is necessary to configure the different items. You need to navigate
through the different menus and select the elements to install. Table I contains the specific configuration of
Buildroot for installing it in the BeagleBone Black. Depending on the version downloaded the organization
and the items displayed can be different.
Page 10 of 38
Main Item Subitem Value Comments
Build options Default values How Buildroot will built the
code. Leave default values.
Toolchain Cross Compiler, linker,
libraries to be built to compile
our embedded application
Toolchain Type Buildroot toolchain Embedded system will be
compiled with tools
integrated in Buildroot
Kernel Headers Same as kernel Source header files of the
Linux Kernel. Navigate to
kernel option and select it.
The option is now displayed.
Custom kernel 3.12.x
headers series
C library uClibc
uClib configuration package/uclibc/uClibc-ng.config
file to use?
Enable WCHAR Yes Support for extender set of
support chars.
Page 11 of 38
Main Item Subitem Value Comments
Passwords encoding md5
Init System BusyBox
/dev management Dynamic using devtmpfs only
Path to permissions system/device_table.txt Text files with permissions for
table /dev files
Page 13 of 38
Main Item Subitem Value Comments
Text editors and Default
viewers
Filesystem
Images
ext2/3/4 root ext2 (rev0)
filesystem Compression method no compression
Bootloaders
U-Boot Build system: Legacy You need to provide in the “U-
U-Boot board name: am335x_evm boot SPL binary image name”
U-Boot Version: 2016.03 the name of the file to be
U-Boot binary format: u-boot.img generated. In this case is
Install U-Boot SPL binary image name: “MLO”
“MLO”
Host utilities
host u-boot tools ?? Yes
host omap-ti-boot-
utils??
Once you have configured all the menus you need to exit saving the values (File->Quit).
[Help]: The Buildroot configuration is stored in a file named as “.config”. You should
have a backup of this file.
Compiling buildroot.
In the Terminal Window executes the following command:
xxx@ubuntu:~/Documents/buildroot-2016.05$ make
If everything is correct you will see a final window similar to the represented in Fig. 8.
[Time for this step]: In this step buildroot is going to connect, using the internet, to
different repositories. After downloading the code, Buildroot is going to compile the
applications and generates a lot files and folders. Depending of your internet speed
access and the configuration chosen this step could take up to two hour and half. The
download of kernel source code from TI is very slowly.
Warning. If you have errors in the configuration of buildroot you could obtain errors in
this compilation phase. Check correctly your configuration. Use “make clean” to clean
up your partial compilation.
Page 14 of 38
Warning. dl subfolder in your buildroot folder contains all the packages download for
the internet. If you want to move your buildroot configuration from one computer to
another avoiding the copy of the virtual machine you can copy this folder.
Buildroot Output.
The main output files of the execution of the previous steps can be located at the folder “./output/images”.
Fig. 9 summarizes the use of Buildroot. Buildroot generates a boot loader, a kernel image, and a file system.
Fig. 9: Schematic representation of the Buildroot tool. Buildroot generates the root file system, the kernel image,
the booloader and the toolchain. Figure copied from “Free Electrons” training materials (http://free-
electrons.com/training/)
In our specific case the folder content is shown in Fig. 10
Page 15 of 38
Fig. 10: images folder contains the binary files for our embedded system.
The file MLO is the X-Loader. The u-boot.img file contains the u-boot binary for booting your Linux. Linux
image is zImage. The files with dtb extension are the device tree in binary form used by Linux in the booting
phase to discover the hardware available in the BeagleBone. The file rootfs.ext2 contains all the files of the
file system of your embedded Linux. In order to boot the BBB from a SD card firstly you need to format it
adequately, follow the instructions included in [RD8]. All files (Fig. 10) with the exception of the rootfs.ext2
must be copied to the SD card FAT32 partition for booting BBB. It is mandatory to copy first the MLO file.
Copy the content of rootfs.ext2 to Linux partition using the dd command as follow:
xxx@ubuntu:~/Documents$ cd buildroot-2016.05/output/images
xxx@ubuntu:~/Documents/output/images $ sudo dd if=rootfs.ext2 of=/dev/sd<n>2
Please use “dmesg” Linux command to find out the device assigned to your SD card. Use “eject” of Ubuntu (
) to unmount the SD Card, this is similar to eject an USB disk in Windows. Insert again the SD card in the
computer and verify that the files are correctly copied.
Page 16 of 38
You can navigate in this application using the arrows. Inspect the configuration of the kernel. If you add or
remove features, save them and compile again buildroot using make command. This will generate new
images that must be copied to SD card.
[Info]: We do not need to apply changes in the default kernel configuration for BBB. This
step has been included here in order to understand how to proceed whether you need
to tune your kernel
[Connecting the USB serial interface in the VM]: In order to connect the serial interface
in your virtual machine you need to connect it selecting un VMWare Player the option
Player->Removable Devices->Future Devices TTL 232R 3V3->Connect
b) To connect the power supply provided to the jack identified as 5v or using a USB cable.
Page 17 of 38
Fig. 12: BBB.
Page 18 of 38
Fig. 14: Powering BBB with USB
Page 19 of 38
The booting process of the BBB with its AM335x processor is depicted in Fig. 17. By default, the ROM in the
Sitara AM335x will boot from the MMC1 interface first (the onboard eMMC), followed by MMC0 (MicroSD),
UART0 and USB0. If the boot switch (S2) is held down during power-up, the processor starts running the ROM
code and boots from the SPI0 Interface first, followed by MMC0, USB0 and UART0. This allows the
BeagleBone Black to bypass the on-board eMMC and boot from the removable uSD (provided no valid boot
device is found on SPI0).
Open the putty application in the Linux host (execute “sudo putty” in a Linux terminal) and open a session to
the serial line (use /dev/ttyUSB0 with 115200 baud rate). Apply the power supply pressing S2 button (Fig. 18)
and releasing it after (for instance) one second, the BeagleBone will boot from SD card.
FIRST STAGE
AM335x ROM code
Basic peripheral
POWER ON configuration
Searches for booting
devices
Load x-loader into SRAM
SECOND STAGE
Secondary Program Loader
X-loader
Setup pin mux
Clock initialization. Memory configuration
Loads u-boot inti SDRAM
THIRD STAGE
U-boot Additional Platform
intialization
Boot arguments
Load kernel image and boot
FOUR STAGE
Linux Kernel boot
Page 20 of 38
Fig. 18: BeagleBone. S2 push button
Page 21 of 38
[Serial interface identification in Linux]: In Linux the serial devices are identified
typically with the names /dev/ttyS0, /dev/ttyS1, etc. In the figure the example has been
checked with a serial port implemented with an USB-RS232 converter. This is the reason
of why the name is /dev/ttyUSB0. In your computer you need to find the identification
of your serial port. Use Linux dmesg command to do this.
After some seconds you will see a lot messages displaying in the terminal. Linux kernel is booting and the
operating system is running their configuration and initial daemons. If the system boots correctly you will see
an output like the represented in Fig. 20. Introduce the user name root and the Linux shell will be available
for you.
$dmesg
….
$uname –r
….
$ifconfig
….
$ps –ax
The Texas Instruments am335x processor (based on an ARM cortex-A8) has a memory area for SDRAM
available in the range 0x80000000-0xC0000000. In this memory area we are going to load using u-boot two
basic elements: the kernel and the device-tree. The starting address for the kernel is 0x80200000 and for the
device tree 0x80F80000.
[Info] u-boot source code can be found in different internet repositories. In this
tutorial we are using the official repository of DENX Software Engineering
(git://git.denx.de/u-boot.git). You can also find u-boot in other internet sites. In
particular Texas Instruments, the manufacture of the AM335x processor provides
Page 23 of 38
a site with the u-boot code for the TI processors. This link is “git://git.ti.com/ti-u-
boot/ti-u-boot.git”. For sure that if you compare the code you will see small
differences between them. Be aware of this.
The embedded Linux system developed in this tutorial uses the content of “uEnv.txt” file in the boot process.
This file has been copied to FAT32 partition in the SD card. Remove it and power on the BBB pressing the S2
button and releasing it after some seconds. During u-boot boot process you will see a message inviting you
to press a key to interrupt the u-boot sequence. Press a key to get the u-boot prompt and execute the
following commands (Explain the meaning of the different u-boot commands). The bootz command will
launch the execution of the zImage loaded in the BBB DRAM memory.
mmc rescan
setenv bootargs console=ttyO0,115200n8 root=/dev/mmcblk0p2 rw rootfstype=ext2 rootwait
fatload mmc 0 0x80F80000 am335x-boneblack.dtb
fatload mmc 0 0x80007fc0 zImage
bootz 0x80007fc0 - 0x80F80000
Of course booting in this way, manually, is not very interesting for functional embedded system. In the next
point we are going to develop a script automating this boot process.
Table 2: Main files in u-boot with the configuration for BBB hardware based on Am335x processor.
File Objective
<u-boot>/include/configs/am335x_evm.h Definition of the different constants
and environment variables of u-boot
for AM335x-based hardware. In this file
the default addresses to store kernel,
device tree and filesystem are defined.
<u-boot>/board/ti/am335x Folder with source files containing the
code to initialize and manage the
AM335x processor and the board
resources.
<uboot>/configs/am335x_evm_defconfig Default u-boot configuration for BBB
Page 24 of 38
Configuring the network interface in the BBB.
The configuration generated by buildroot for the BBB’s network interface (eth0) is DHCP. This means that in
Linux initialization the “init” process is launching an application working as DHCP client. Execute the
commands ifconfig and ps to see the network configuration and the processes running in the BBB. You can
test if the network is working using the ping command. Use the ping command with a known address. For
instance, the address of one computer in the lab.
[Help]: If you execute the ping command in the BBB trying to connect with a computer
in the laboratory probably you obtain a connection timeout. Consider that computers
running windows could have the firewall activated. You can also try to run the ping in a
windows computer or in Linux virtual machine. In this case the BBB doesn’t have a
firewall running and the connection should be ok.
[DHCP Server]: The DHCP server providing the IP address to the BBB should be active in
your network. In the UPM ETSIST labs the IP is assigned using the BBB’s MAC address.
Check with your instructor the IP assigned to your RPI. If you are using the RPI at home,
the DNS server is running in your router. The method used by this should be different
from one manufactures to others. If you want to know the IP address assigned you have
two options: use a serial cable connected to the RPI or check the router status web page
and display the table of the DHCP clients connected. Looking for the MAC in the list you
will obtain the IP.
Page 25 of 38
4 LAB2: USING INTEGRATED DEVELOPMENT
ENVIRONMENT: ECLIPSE/CDT
Adding cross-compiling tools to PATH variable.
Using a text editor, edit the .profile file (available at your home directory). Add a line at the end of the file
containing: PATH="<your buildroot installation>/output/host/usr/bin:$PATH". This add to the PATH
environment variable the location of the cross-compiling tools. You must logout and login again.
Fig. 22: Summary of the different configurations for developing applications for embedded systems. Figure
copied from “Free Electrons” training materials (http://free-electrons.com/training/)
The first question is where the cross-compiler is located. The answer is this: in the folder “buildroot-
2016.05/output/host/usr/bin”. If you inspect the content of this folder you can see the entire compiling,
linking and debugging tool (see Fig. 23). These programs are executed in your x86 computer but they
generate code for ARM processor.
Page 26 of 38
Fig. 23: Cross compiling tools installed in the host computer
In a Terminal window start Eclipse with the following command:
xxxx@ubuntu:~$ eclipse
The popup window invites you to enter the workspace (see Fig. 24). The workspace is the folder that will
contain all the eclipse projects created by the user. You can have as many workspaces as you want. Please
specify a folder in your account.
[Help]: The figures displayed in the following paragraphs can be different depending on
the Eclipse version installed.
Fig. 24: Selection of the workspace for Eclipse. Use a folder in your account.
Page 27 of 38
Select Ok and the welcome window of Eclipse will be shown (Fig. 25). Next, close the welcome window and
the main eclipse window will be displayed (Fig. 26).
Page 28 of 38
Fig. 27: Basic C project creation in Eclipse
There is a window (Fig. 28) requesting the Cross Compiler prefix and path, leave both inputs blank and click
on the Finish button. You will obtain your first project created with eclipse.
Page 29 of 38
Fig. 29: Hello world example.
The next step (mandatory) is the Eclipse project configuration for managing the Cross-tools. In Project ->
Properties configure the C/C++ Build Setting as the Fig. 30 and Fig. 31 shown. Pay attention that Prefix
requires a string ending in a hyphen.
Fig. 30: Tool Chain Editor should be configured to use Cross GCC.
Page 30 of 38
Fig. 31: Cross tools locate on (path).The path shown in this figure is an example.Use always the path of your
toolchain.
The next step is to configure the search paths for the compiler and linker, and the different tools to use.
Complete the different fields with the information included in Fig. 32 and Fig. 33. Please consider the paths.
The figures are showing examples for an specific user account.
Page 31 of 38
Fig. 33: Libraries search path.
Once you have configured the cross chain in Eclipse you can build your project using Project->Build Project.
If everything is correct you will see the eclipse project as represented in Fig. 35.
[Console in Eclipse]: Have a look to the messages displayed in the Console. You will see
how eclipse is calling the cross compiler with different parameters.
In order to copy the executalbe to the target you have different options. You can use the linux application
called “scp” or other similar applications. In our case we are going to use “Connect to Server….” utility
included in ubuntu (under Places menu). Specify in Server Address ssh://<ip address>
Page 32 of 38
Fig. 34: Pop up window when executing “Connect to Server”
Page 33 of 38
Fig. 36: Run test program in Raspberry PI
Warning. If you experiment problems using ssh, delete the .ssh folder in
your home directory.
In the debugger window (main tab) you need to configure the path of your gdb application. Remember that
we are working with a cross-compiler, cross debugging, therefore, you need to provide here the correct path
of your gdb. The GDB command file must be specified, providing a path with an empty file. In the Gdbserver
settings tab you need to provide path to the gdbserver in the target and the port used (by default 2345).
Page 34 of 38
Fig. 38: Debug configuration including the path to locate the cross gdb tool.
Now, press Debug in Eclipse window and you can debug remotely your application.
Page 35 of 38
5 PREPARING THE LINUX VIRTUAL MACHINE.
Download VMware Workstation Player.
The link https://www.vmware.com/support/pubs/player_pubs.html contains documentation describing the
installation and basic use of VMware Workstation Player. Follow the instructions to setup the application in
your computer.
[Ubuntu version]: It is mandatory to install Ubuntu 14.04 version. 16.04 version will
generate compatibility problems.
The first step is to download Ubuntu 14.04 (32 bit PC-i386) from Ubuntu web site using this link:
http://releases.ubuntu.com/14.04/ . You will download an ISO image with this Linux operating System.
Run WMware player and install Ubuntu using the VMWare player instructions. Consider the following when
creating the virtual machine: you need at least 80Gbytes of hard disk space (in multiple files) and 1GByte of
RAM. The installation time will be half an hour more or less depending of your computer. Moving a virtual
machine form one computer to another is a time consuming task, therefore, take this into account to
minimize the development time.
Page 36 of 38
6 ANNEX I: UBUNTU 14.04 LTS PACKAGES INSTALLED.
List of packages used by Buidlroot .
Using buildroot requires some software packages that have to be installed in the VM. These are listed in this
link http://buildroot.uclibc.org/downloads/manual/manual.html#requirement. If you need to install
software packages you can do it using the command apt-get. Another alternative process is the use of
synaptic utility. In order to use it you need to install it using this command:
Once installed you can search and execute the synaptic program. When you click two times over the package
it will show all the dependent packages than would be installed.
Page 37 of 38
Fig. 40: Synaptic windows
Page 38 of 38