Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Embedded Linux Development Using Yocto Project Cookbook

You're reading from   Embedded Linux Development Using Yocto Project Cookbook Practical recipes to help you leverage the power of Yocto to build exciting Linux-based systems

Arrow left icon
Product type Paperback
Published in Jan 2018
Publisher
ISBN-13 9781788399210
Length 456 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Alex Gonzalez Alex Gonzalez
Author Profile Icon Alex Gonzalez
Alex Gonzalez
Arrow right icon
View More author details
Toc

Table of Contents (7) Chapters Close

Preface 1. The Build System FREE CHAPTER 2. The BSP Layer 3. The Software Layer 4. Application Development 5. Debugging, Tracing, and Profiling 6. Other Books You May Enjoy

Building your first image

Before building our first image, we need to decide what type of image we want to build. This recipe will introduce some of the available Yocto images and provide instructions to build a simple image.

Getting ready

Poky contains a set of default target images. You can list them by executing the following commands:

$ cd /opt/yocto/poky
$ ls meta*/recipes*/images/*.bb

A full description of the different images can be found in the Yocto Project Reference Manual, on Chapter 13, Images. Typically, these default images are used as a base and customized for your own project needs. The most frequently used base default images are:

  • core-image-minimal: This is the smallest BusyBox, sysvinit, and udev-based console-only image
  • core-image-full-cmdline: This is the BusyBox-based console-only image with full hardware support and a more complete Linux system, including Bash
  • core-image-lsb: This is a console-only image that is based on Linux Standard Base (LSB) compliance
  • core-image-x11: This is the basic X11 Windows-system-based image with a graphical terminal
  • core-image-sato: This is the X11 Window-system-based image with a SATO theme and a GNOME mobile desktop environment
  • core-image-weston: This is a Wayland protocol and Weston reference compositor-based image

You will also find images with the following suffixes:

  • dev: This image is suitable for development work, as it contains headers and libraries
  • sdk: This image includes a complete SDK that can be used for development on the target
  • initramfs: This is an image that can be used for a RAM-based root filesystem, which can optionally be embedded with the Linux kernel

How to do it...

  1. To build an image, we need to configure the machine we are building it for and pass its name to BitBake. For example, for the qemuarm machine, we would run the following:
$ cd /opt/yocto/poky/
$ source /opt/yocto/poky/oe-init-build-env qemuarm
$ MACHINE=qemuarm bitbake core-image-minimal
  1. Or we could export the MACHINE variable to the current shell environment before sourcing the oe-init-build-env script with the following:
$ export MACHINE=qemuarm 
  1. On an already configured project, we could also edit the conf/local.conf configuration file to change the default machine to qemuarm:
- #MACHINE ?= "qemuarm"
+ MACHINE ?= "qemuarm"
  1. Then, after setting up the environment, we execute the following:
$ bitbake core-image-minimal

With the preceding steps, BitBake will launch the build process for the specified target image.

How it works...

When you pass a target recipe to BitBake, it first parses the following configuration files in order:

  • conf/bblayers.conf: This file is parsed to find all the configured layers
  • conf/layer.conf: This file is parsed on each configured layer
  • meta/conf/bitbake.conf: This file is parsed for its own configuration
  • conf/local.conf: This file is used for any other configuration the user may have for the current build
  • conf/machine/<machine>.conf: This file is the machine configuration; in our case, this is qemuarm.conf
  • conf/distro/<distro>.conf: This file is the distribution policy; by default, this is the poky.conf file

There are also some other distribution variants included with Poky:

    • poky-bleeding: Extension to the Poky default distribution that includes the most up-to-date versions of packages
    • poky-lsb: LSB compliance extension to Poky
    • poky-tiny: Oriented to create headless systems with the smallest Linux kernel and BusyBox read-only or RAM-based root filesystems, using the musl C library

And then, BitBake parses the target recipe that has been provided and its dependencies. The outcome is a set of interdependent tasks that BitBake will then execute in order.

A depiction of the BitBake build process is shown in the following diagram:

BitBake build process

There's more...

Most developers won't be interested in keeping the whole build output for every package, so it is recommended to configure your project to remove it with the following configuration in your conf/local.conf file:

INHERIT += "rm_work" 

But at the same time, configuring it for all packages means that you won't be able to develop or debug them.

You can add a list of packages to exclude from cleaning by adding them to the RM_WORK_EXCLUDE variable. For example, if you are going to do BSP work, a good setting might be:

RM_WORK_EXCLUDE += "linux-wandboard u-boot-fslc" 

Remember that you can use a custom template local.conf.sample configuration file in your own layer to keep these configurations and apply them for all projects so that they can be shared across all developers.

On a normal build, the -dbg packages that include debug symbols are not needed. To avoid creating -dbg packages, do this:

INHIBIT_PACKAGE_DEBUG_SPLIT = "1" 

Once the build finishes, you can find the output images in the tmp/deploy/images/qemuarm directory inside your build directory.

You can test run your images on the QEMU emulator by executing this:

$ runqemu qemuarm core-image-minimal  

The runqemu script included in Poky's scripts directory is a launch wrapper around the QEMU machine emulator to simplify its usage.

The Yocto Project also has a set of precompiled images for supported hardware platforms that can be downloaded from http://downloads.yoctoproject.org/releases/yocto/yocto-2.4/machines/.

You have been reading a chapter from
Embedded Linux Development Using Yocto Project Cookbook - Second Edition
Published in: Jan 2018
Publisher:
ISBN-13: 9781788399210
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image