Practical Labs: Yocto Project and Openembedded Training
Practical Labs: Yocto Project and Openembedded Training
Practical Labs: Yocto Project and Openembedded Training
Practical Labs
https://bootlin.com
Training setup
Download files and directories used in practical labs
Lab data are now available in an yocto-labs directory in your home directory. This directory
contains directories and files used in the various practical labs. It will also be used as working
space, in particular to keep generated files separate when needed.
More guidelines
Can be useful throughout any of the labs
• Read instructions and tips carefully. Lots of people make mistakes or waste time because
they missed an explanation or a guideline.
1 This tool from Microsoft is Open Source! To try it on Ubuntu: sudo snap install code --classic
• Always read error messages carefully, in particular the first one which is issued. Some
people stumble on very simple errors just because they specified a wrong file path and
didn’t pay enough attention to the corresponding error message.
• Never stay stuck with a strange problem more than 5 minutes. Show your problem to
your colleagues or to the instructor.
• You should only use the root user for operations that require super-user privileges, such
as: mounting a file system, loading a kernel module, changing file ownership, configuring
the network. Most regular tasks (such as downloading, extracting sources, compiling...)
can be done as a regular user.
• If you ran commands from a root shell by mistake, your regular user may no longer be
able to handle the corresponding generated files. In this case, use the chown -R command
to give the new files back to your regular user.
Example: $ chown -R myuser.myuser linux/
Setup
Before starting this lab, make sure your home directory is not encrypted. OpenEmbedded
cannot be used on top of an eCryptFS file system due to limitations in file name lengths.
Go to the $HOME/yocto-labs/ directory.
Install the required packages:
sudo apt install bc build-essential chrpath cpio diffstat gawk git python texinfo\
wget
Download Yocto
Download the dunfell version of Poky:
Return to your project root directory (cd $HOME/yocto-labs/) and download the meta-arm and
meta-ti layers:
cd $HOME/yocto-labs
source poky/oe-init-build-env
You must specify which machine is your target. By default it is qemu. We need to build an
image for a beaglebone. Update the MACHINE configuration variable accordingly. Be careful,
beaglebone is different from the beagleboard machine!
Also, if you need to save disk space on your computer you can add INHERIT += "rm_work" in
the previous configuration file. This will remove the package work directory once a package is
built.
Don’t forget to make the configuration aware of the ARM and TI layers. Edit the layer configura-
tion file ($BUILDDIR/conf/bblayers.conf) and append the full path to the meta-arm-toolchain,
meta-arm, meta-ti directories to the BBLAYERS variable.
bitbake core-image-minimal
Once the build finished, you will find the output images under $BUILDDIR/tmp/deploy/images/
beaglebone.
In this first lab we will use an SD card to store the bootloader, kernel and root filesystem files.
The SD card image has been generated and is named core-image-minimal-beaglebone.wic.xz.
Now uncompress and flash the image with the following command:
xz -dc $BUILDDIR/tmp/deploy/images/beaglebone/\
core-image-minimal-beaglebone.wic.xz | sudo dd of=/dev/sdX conv=fdatasync bs=\
4M
The Beaglebone serial connector is exported on the 6 pins close to one of the 48 pins headers.
Using your special USB to Serial adapter provided by your instructor, connect the ground wire
(blue) to the pin closest to the power supply connector (let’s call it pin 1), and the TX (red) and
RX (green) wires to the pins 4 (board RX) and 5 (board TX)2 .
You always should make sure that you connect the TX pin of the cable to the RX pin of the board,
and vice-versa, whatever the board and cables that you use.
Once the USB to Serial connector is plugged in, a new serial port should appear: /dev/ttyUSB0.
You can also see this device appear by looking at the output of dmesg.
To communicate with the board through the serial port, install a serial communication program,
such as picocom:
If you run ls -l /dev/ttyUSB0, you can also see that only root and users belonging to the
dialout group have read and write access to this file. Therefore, you need to add your user to
the dialout group:
Important: for the group change to be effective, in Ubuntu 18.04, you have to completely reboot
the system 3 . A workaround is to run newgrp dialout, but it is not global. You have to run it
in each terminal.
Now, you can run picocom -b 115200 /dev/ttyUSB0, to start serial communication on /dev/
ttyUSB0, with a baudrate of 115200. If you wish to exit picocom, press [Ctrl][a] followed by
[Ctrl][x].
There should be nothing on the serial line so far, as the board is not powered up yet.
3 As explained on https://askubuntu.com/questions/1045993/after-adding-a-group-logoutlogin-is-not-
enough-in-18-04/.
First we need to set the kernel boot arguments U-Boot will pass to the Linux kernel at boot
time:
If you later want to make changes to this setting, you can use:
editenv bootargs
Then, instead of configuring the host IP address from Network Manager’s graphical interface,
let’s do it through its command line interface, which is so much easier to use:
We can force Yocto to select another kernel by explicitly defining which one to use in our
local configuration. Try switching from linux-ti-staging to linux-dummy only using the local
configuration.
Then check the previous step worked by dry-running again BitBake.
BitBake tips
BitBake is a powerful tool which can be used to execute specific commands. Here is a list of
some useful ones, used with the virtual/kernel package.
• The Yocto recipes are divided into numerous tasks, you can print them by using: bitbake
-c listtasks virtual/kernel.
• BitBake allows to call a specific task only (and its dependencies) with: bitbake -c <task>
virtual/kernel. (<task> can be menuconfig here).
• You can force to rebuild a package by calling: bitbake -f virtual/kernel
• world is a special keyword for all packages. bitbake --runall=fetch world will download
all packages sources (and their dependencies).
• You can get a list of locally available packages and their current version with:
bitbake -s
• You can also find detailed information on available packages, their current version, depen-
dencies or the contact information of the maintainer by visiting:
http://recipes.yoctoproject.org/
For detailed information, please run bitbake -h
Going further
If you have some time left, let’s improve our setup to use TFTP, in order to avoid having to
reflash the SD card for every test. What you need to do is:
1. Install a TFTP server (package tftpd-hpa) on your system.
2. Copy the Linux kernel image and Device Tree to the TFTP server home directory (specified
in /etc/default/tftpd-hpa) so that they are made available by the TFTP server.
3. Change the U-Boot bootcmd to load the kernel image and the Device Tree over TFTP.
See the training materials of our Embedded Linux system development course for details!
bitbake ninvaders
Try to make the recipe on your own. Also eliminate the warnings related to your recipe: some
configuration variables are not mandatory but it is a very good practice to define them all.
If you hang on a problem, check the following points:
• The common recipe is included in the version specific one
• The checksum and the URI are valid
• The dependencies are explicitly defined
• The internal state has changed, clean the working directory:
bitbake -c cleanall ninvaders
Tip: BitBake has command line flags to increase its verbosity and activate debug outputs. Also,
remember that you need to cross-compile nInvaders for ARM ! Maybe, you will have to configure
your recipe to resolve some mistakes done in the application’s Makefile (which is often the case).
A bitbake variable permits to add some Makefile’s options, you should look for it.
Tools
You can access the configuration and state of layers with the bitbake-layers command. This
command can also be used to retrieve useful information about available recipes. Try the
following commands:
bitbake-layers show-layers
bitbake-layers show-recipes linux-yocto
bitbake-layers show-overlayed
bitbake-layers create-layer
Try adding the patches included in this lab to your BitBake append file. Do not forget to also add
the defconfig file provided alongside the patches. This file contains the kernel configuration.
It is handled automatically in the linux-ti-staging original recipe.
You can now rebuild the kernel to take the new patches into account:
bitbake virtual/kernel
We will connect it to the second I2C port of the CPU (i2c1), with pins available on the P9
connector.
SCL
PWR
GND SDA
Serial
Wii Nunchuk
GND
PWR
SDA
SCL
Patch nInvaders
The nInvaders game uses keyboard events for its controls. We first need to apply a patch in-
troducing joystick support. The patch is located at ~/yocto-labs/bootlin-lab-data/nunchuk/
ninvaders/.
Add the patch to the nInvaders SRC_URI.
Then build a full core-image-minimal and update the NFS root directory.
Play nInvaders!
After booting the board you should be able to play nInvaders with the keyboard…and the
Nunchuk! The C button is used to confirm and to fire, and Z to pause the game.
Access the board command line through SSH, and launch the game:
$ ninvaders
DEFAULTTUNE = "armv7athf-neon"
require conf/machine/include/tune-cortexa8.inc
– usbhost
– vfat
– ext2
– alsa
Going further
We chose a quite generic tune (armv7athf-neon). It’s the same one as meta-ti’s definition for
the Beaglebone machine. You can see what Bitbake did in $BUILDDIR/tmp/work.
Now, we can change the tune to cortexa8thf-neon. Rebuild the image, and look at $BUILDDIR/
tmp/work. What happened?
tar xf ctris-0.42-1-src.tar.bz2
tar xf ctris-0.42.tar.bz2
cd ctris-0.42
Then modify the Makefile, to make sure that the environment variables exported by the SDK
script are not overridden.
Compile the application. You can check the application was successfully compiled for the right
target by using the file command. The ctris binary should be an ELF 32-bit LSB executable
compiled for ARM.
Finally, you can copy the binary to the board, by using the scp command. Then run it and
play a bit to ensure it is working fine!