Cross-compiling System for Linux


Yocto


A Yocto build starts by building many of the native utilities needed by the build system itself. This is performed to minimize the dependencies on the host OS and to ensure a known set of package versions. Most configurations then proceed to build a tested and known good cross-compilation environment before moving on to building the binaries for the target platform.

The package definitions include various phases (e.g., fetch, compile, install, package) and must specify any runtime or build-time dependencies. The build is controlled by an executive called bitbake , which is responsible for processing the dependencies and scheduling the tasks.

Developing Embedded Linux Devices Using the Yocto Project

David Stewart

What is the Yocto Project (YP)? ... and what’s new


The purpose is to spend less time on things which are routine works (build system, core Linux components).

The Yocto Project is an open source collaboration project that helps developers create custom Linux-based systems that are designed for embedded products regardless of the product's hardware architecture. In summary, it provides tools and metadata for creating custom embedded systems
  • An image is a collection of 'baked' recipes (packages)
  • A 'recipe' is a set of instructions for building 'packages'
    • Where to get the source and which patches to apply
    • Dependencies (on libraries or other recipes, for example)
    • Config/compile options, 'install' customization
  • A 'layer' is a logical collection of recipes representing the core, a board support package (BSP), or an application stack


The Yocto Project's "Layer Model" is a development model. Layers are repositories that contain related sets of instructions that tell the OpenEmbedded build system what to do. You use different layers to logically separate information in your build. As an example, you could have BSP, GUI, distro configuration, middleware, or application layers.

Poky is the Yocto Project reference distribution. It contains the Open-Embedded build system (BitBake and OE-Core) as well as a set of metadata to get you started building your own distribution.


How does it work?


Yocto Project Quick Build

  • Use Git to Clone Poky
  • You need to get a copy of the Poky repository on your build host
    
    $ git clone git://git.yoctoproject.org/poky
    
    Create a local branch, for ex., based on the Yocto Project yocto-3.1 release, named my-yocto-3.1
    
    $ git checkout tags/yocto-3.1 -b my-yocto-3.1
    
  • Building Your Image
  • From within the poky directory, run the oe-init-build-env environment setup script to define Yocto Project's build environment on your build host.
    
    $ cd ~/poky
    $ source oe-init-build-env
    
    the script creates the Build Directory build if no Build Directory is specified.

    A local configuration file named local.conf becomes available under build/conf . For this example,

    • the default target are set to build for qemux86 , which is suitable for emulation.
    • the package manager used is set to the RPM package manager.
    Start the Build:
    
    $ bitbake core-image-sato
    
    Once this particular image is built, you can start QEMU, which is a Quick EMUlator that ships with the Yocto Project:
    
    $ runqemu qemux86-64
    

Yocto Project provides best of upstream for a stable base:



bitbake is a task executor and scheduler, Poky provides metadata: task definitions in recipes, classes and configurations.


Configurations


  • global configuration
    • build/conf/local.conf
    • local user-defined variables: conf/local.conf:
      • BB_NUMBER_THREADS,PARALLEL_MAKE
      • based on the number of threads in the machine
      • MACHINE
      • the target CPU architecture or platform
      • EXTRA_IMAGE_FEATURES
      • adds features (groups of packages)
      • INCOMPATIBLE_LICENSE
      • “GPLv3” eliminates packages using this license (for example)
    • distro/poky.conf
    • Yocto policy config variables
    • machine/*.conf
    • machine-specific variables
  • classes(*.bbclass)
  • encapsulation and inheritance of logic
  • Metadata and patches
  • Recipes(*.bb) for building packages. For ex.,
    • meta/recipes-core/coreutils/coreutils_6.9.bb
    • builds the core utilities (version 6.9) and installs them
    • meta-recipes-core/coreutils/coreutils-6.9/
    • includes patches, also could include extra files to install
  • Machine (BSP) configuration
  • BSPs are layers that add machine settings and recipes. Machine settings are specified in a layer's conf/machine/*.conf file(s)

Source Fetching

  • Recipes call out location of all sources, whether on the internet or local (Look for SRC_URI in *.bb files)
  • Bitbake can get sources from git, svn, bzr, from tarballs, and many, many more*
  • Versions of packages can be fixed or updated automatically (Add SRCREV_pn- PN = "${AUTOREV}” to local.conf)
  • Yocto Project sources mirror available as a fallback, if the sources move on the internet

Patching

  • Once sources are obtained, the patches are applied
  • This is a good place place to patch the software yourself
  • However, we encourage you to contribute development upstream whenever possible (we try to)

auto configure/build


Packaging


Once configure/compile/install is completed, packaging commences.
The package management mechanism can be set via PACKAGE_CLASSES in conf/local.conf.
The most popular package formats are supported: RPM, Debian, and ipk
You can split into multiple packages using PACKAGES and FILES in a *.bb file. Fo ex., :

PACKAGES =+ "sxpm cxpm"
FILES_cxpm = "${bindir}/cxpm"
FILES_sxpm = "${bindir}/sxpm"

Image Generation


Images are constructed using the packages built earlier in the process
Uses for these built images:
  • Live Image to boot a device
  • Root filesystem for QEMU emulator
  • Sysroot for App development

Application Development SDK

  • Cross toolchain and installation script generated.
  • This can be used to set up an application developer’s cross development environment to create apps
  • MACHINE=qemuarm bitbake poky-image-sato-sdk meta-toolchain package-index
  • QEMU built for target architecture emulation

Setting Up the App Development Environment




Embedded Linux Development Using Yocto Project Cookbook

2nd Edition
Practical recipes to help you leverage the power of Yocto to build exciting Linux-based systems

by
Alex González

The example code in the book can be accessed through several GitHub repositories at https://github.com/yoctocookbook2ndedition .

1. The Build System


1.1 Introduction


The Yocto Project ( http://www.yoctoproject.org/ ) is an embedded Linux distribution builder that makes use of several other open source projects.
Most of these are not designed for embedded systems, the Yocto Project allows you to create a Linux distribution designed for your particular embedded system. The Yocto Project provides a reference distribution for embedded Linux, called Poky.
The Yocto Project has the BitBake and OpenEmbedded-Core (OE-Core) projects at its base. Itbuilds the components needed for an embedded Linux product:
  • A bootloader image
  • A Linux kernel image
  • A root filesystem image
  • Toolchains and software development kits (SDKs) for application development

The Yocto Project makes a new release every 6 months.
codenameversionrelease date
Gatesgarth3.2Oct 2020
Dunfell3.1April 2020
Zeus3.0October 2019
Warrior2.7April 2019
Thud2.6Nov 2018
Sumo2.5April 2018
Rocko2.4Oct 2017
A Yocto release comprises the following components:
  • Poky, the reference build system and distribution
  • Board Support Packages (BSPs) with the recipes needed to support different architectures and boards
  • Build Appliance, a virtual machine image ready to use Yocto
  • Standard and extensible SDKs for the host system
  • Eclipse plugins
And for the different supported platforms:
  • Prebuilt toolchains
  • Prebuilt images
Yocto builds all the components mentioned from scratch, including the cross-compilation toolchain and the native tools it needs
It is recommended to use symmetric multiprocessing (SMP) systems with >= 8 GB and solid state drives (SSD) if possible.

1.2 Setting up the host system


1.2.1 Getting ready

The first build will also download all the sources from the internet.

Yocto is able to run on any Linux system if it has the following dependencies:
  • Git 1.8.3.1 or greater
  • Tar 1.27 or greater
  • Python 3.4.0 or greater

1.3 Installing Poky

1.3.1 Getting ready


Poky and BitBake are two of the open source projects used by Yocto:
  • Poky
  • You can download Poky via git:
    
    git://git.yoctoproject.org/poky
    
    • Development discussions
    • https://lists.yoctoproject.org/listinfo/poky
    • Poky development takes place in the master branch.
    • Before merging submitted patches into the master,maintainers test them in the master-next branch.
    • Stable Yocto releases have their own branch.
    • For ex., Yocto 2.4 is maintained in the rocko branch
  • BitBake
  • You can think of BitBake as the make utility in Yocto. It will parse the configuration and recipe metadata, schedule a task list, and run through it. BitBake is maintained by both the Yocto and OpenEmbedded communities.
The Poky distribution only supports virtualized QEMU machines for the following architectures:
  • ARM (qemuarm, qemuarm64)
  • x86 (qemux86)
  • x86-64 (qemux86-64)
  • PowerPC (qemuppc)
  • MIPS (qemumips, qemumips64)
The Poky distribution supports some reference hardware BSPs:
  • Texas Instruments BeagleBone (beaglebone)
  • Freescale MPC8315E-RDB (mpc8315e-rdb)
  • Intel x86-based PCs and devices (genericx86 and genericx86-64)
  • Ubiquiti Networks EdgeRouter Lite (edgerouter)

1.3.2 Getting ready

The Poky project incorporates a stable BitBake release.
To install a Yocto release, ZEUS 3.0.2,

$ sudo install -o $(id -u) -g $(id -g) -d /opt/yocto
$ cd /opt/yocto
/opt/yocto$ git clone -b zeus git://git.yoctoproject.org/poky.git
this clone the Poky repository, which includes BitBake, into a new poky directory under /opt/yocto.
Poky contains three metadata directories,
  • meta
  • This directory contains the OpenEmbedded-core metadata, which supports the ARM, ARM64, x86, x86-64, PowerPC, MIPS, and MIPS64 architectures and the QEMU emulated hardware.
  • meta-poky
  • This contains Poky's distribution-specific metadata
  • meta-yocto-bsp
  • This contains metadata for the reference hardware boards.
There is a template metadata layer, meta-skeleton , which can be used as a base for new layers.

1.4 Creating a build directory


Before building your first Yocto image, we need to create a build directory for it.
A build directory for our project is where the build output will be generated.

1.4.1 How to do it


A good practice is to have one build directory per architecture or machine type.
To create a build directory, we use the oe-init-build-env script provided by Poky.
The script will set up your environment to use the OpenEmbedded/Yocto build system, including adding the BitBake utility to your path.
You can specify a build directory to use or it will use build by default.

$ cd /opt/yocto/poky
$ source oe-init-build-env
/opt/yocto/poky/build$
The script will change to the specified/default build directory.

1.4.2 How it works


The oe-init-build-env script calls scripts/oe-setup-builddir script inside the Poky directory to create the build directory.
On creation, the build directory contains a conf directory with the following three files:
  • bblayers.conf
  • This file lists the metadata layers to be considered for this project.
  • local.conf
  • This file contains the project-specific configuration variables. You can set common configuration variables to different projects with a site.conf file, but this is not created by default. Similarly, there is also an auto.conf file which is used by autobuilders. BitBake will first read site.conf , then auto.conf , and finally local.conf .
  • templateconf.cfg
  • This file contains the directory that includes the template configuration files used to create the project.
    
    meta-poky/conf
    
    This directory is in your Poky installation directory

1.5 Building your first image


We need to decide what type of image to be built.

1.5.1 Getting ready


Poky contains a set of default target images which can be listed:

/opt/yocto/poky$ ls meta*/recipes*/images/*.bb
These default images are used as a base for your customized 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
Image names 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

1.5.2 How to do it

There are 2 ways for us to configure the MACHINE variable we are building it for and pass its name to BitBake:
  • export the MACHINE variable to the current shell environment
  • Before sourcing the oe-init-build-env script with the following:
    
    $ export MACHINE=raspberrypi4
    
  • edit the conf/local.conf configuration file to change the default machine
  • 
    MACHINE ?= "raspberrypi4"
    
Then, after setting up the environment(including the correct BSP layer: "1.6 Explaining the Raspberry Pi Yocto ecosystem"), we execute the following:

$ bitbake core-image-minimal
With the preceding steps, BitBake will launch the build process for the specified target image.

1.5.3 How it works

When you pass a target recipe to BitBake, it first parses the following configuration files under the build directory in order:
  1. BUILD/conf/bblayers.conf
  2. This file is parsed to find all the configured layers. For ex., /opt/yocto/poky/raspi4/conf/bblayers.conf:
    
    BBLAYERS ?= " \
      /opt/yocto/poky/meta \
      /opt/yocto/poky/meta-poky \
      /opt/yocto/poky/meta-yocto-bsp \
      /opt/yocto/meta-raspberrypi \
      "
    
    
  3. layer.conf
  4. This file for each configured layer assigned in conf/bblayers.conf is parsed.
  5. POKY/meta/conf/bitbake.conf
  6. This file is parsed for BitBake's own configuration settings such as the TMPDIR, CACHE...
  7. BUILD/conf/local.conf
  8. This file is used for any other configuration the user may have for the current build
  9. meta*/conf/machine/machine.conf
  10. This file is the machine configuration; in our case, this file raspberrypi4.conf is selected.
    
    $ ls meta-raspberrypi/conf/machine/*.conf
    ./meta-raspberrypi/conf/machine/raspberrypi0.conf       ./meta-raspberrypi/conf/machine/raspberrypi4-64.conf
    ./meta-raspberrypi/conf/machine/raspberrypi0-wifi.conf  ./meta-raspberrypi/conf/machine/raspberrypi4.conf
    ./meta-raspberrypi/conf/machine/raspberrypi2.conf       ./meta-raspberrypi/conf/machine/raspberrypi-cm3.conf
    ./meta-raspberrypi/conf/machine/raspberrypi3-64.conf    ./meta-raspberrypi/conf/machine/raspberrypi-cm.conf
    ./meta-raspberrypi/conf/machine/raspberrypi3.conf       ./meta-raspberrypi/conf/machine/raspberrypi.conf
    
  11. conf/distro/.conf
  12. This file is the distribution policy; by default, this is the poky.conf file
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.

1.5.4 There's more...


  • INHERIT
  • RM_WORK_EXCLUDE
  • INHIBIT_PACKAGE_DEBUG_SPLIT

1.6 Explaining the Raspberry Pi Yocto ecosystem


Unless you are working with one of the reference boards already supported by Poky, you will need to extend Poky to support your hardware by adding extra BSP layers.

1.6.1 Getting ready


The first thing to do is to select which base hardware your design is going to be based on.
We will use the board "Raspberry Pi 4" as a starting point for our embedded product design.

1.6.2 How to do it


The Yocto community that support Raspberry Pi boards is the layer called meta-raspberrypi .
You can download meta-raspberrypi from its Git repository or from Yocto project:

/opt/yocto$ git clone -b zeus git://git.yoctoproject.org/meta-raspberrypi


1.6.3 How it works...


The BSP extends Poky with the following layers:
  • meta-raspberrypi
The two most important configuration files under the Yocto build directory needed to be changed to support the additional BSP layer:
  • build/conf/bblayers.conf
  • This tells bitbake where the various layers are located. BBLAYERS assigned directories where Yocto will look for recipes along with .bb and .bbappend files. Append the path where the BSP for Raspbery Pi is downloaded:
    
    BBLAYERS ?= " \
      /opt/yocto/poky/meta \
      /opt/yocto/poky/meta-poky \
      /opt/yocto/poky/meta-yocto-bsp \
      /opt/yocto/meta-raspberrypi \
      "
    
    
  • build/conf/local.conf
  • Specify the target MACHINE for the build:
    
    MACHINE ?= "raspberrypi4"
    
    
    This is a configuration file that is provided in the additionally downloaded BSP layer: poky/meta-raspberrypi/conf/machine/*

1.7 Building Raspberry Pi 4 images


1.7.1 How to do it...


All of the Raspberry Pi board variants are bundled and defined by different Yocto machines:

/opt/yocto$ find meta-raspberrypi -name raspberrypi*.conf -print
meta-raspberrypi/conf/machine/raspberrypi4.conf
meta-raspberrypi/conf/machine/raspberrypi2.conf
meta-raspberrypi/conf/machine/raspberrypi0-wifi.conf
meta-raspberrypi/conf/machine/raspberrypi4-64.conf
meta-raspberrypi/conf/machine/raspberrypi-cm3.conf
meta-raspberrypi/conf/machine/raspberrypi3-64.conf
meta-raspberrypi/conf/machine/raspberrypi0.conf
meta-raspberrypi/conf/machine/raspberrypi3.conf
meta-raspberrypi/conf/machine/raspberrypi.conf
meta-raspberrypi/conf/machine/raspberrypi-cm.conf


  • source poky/oe-init-build-env rpi-build
  • Add the above depended layer to build/conf/bblayers.conf
  • Set MACHINE in build/conf/local.conf to one of the supported boards
  • bitbake core-image-base
  • 
    Parsing recipes: 100% |#######################################################################################################################################| Time: 0:00:34
    Parsing of 801 .bb files complete (0 cached, 801 parsed). 1329 targets, 67 skipped, 0 masked, 0 errors.
    NOTE: Resolving any missing task queue dependencies
    
    Build Configuration:
    BB_VERSION           = "1.44.0"
    BUILD_SYS            = "x86_64-linux"
    NATIVELSBSTRING      = "ubuntu-18.04"
    TARGET_SYS           = "arm-poky-linux-gnueabi"
    MACHINE              = "raspberrypi4"
    DISTRO               = "poky"
    DISTRO_VERSION       = "3.0.3"
    TUNE_FEATURES        = "arm vfp cortexa7 neon vfpv4 thumb callconvention-hard"
    TARGET_FPU           = "hard"
    meta                 
    meta-poky            
    meta-yocto-bsp       = "zeus:c77dade37c92bb3a25686a6759a231881bb96477"
    meta-raspberrypi     = "zeus:0e05098853eea77032bff9cf81955679edd2f35d"
    ...
    
  • Copy the built image file to the SD card
  • After a few hours of baking, the system image for our target is created under build/tmp/deploy/images/raspberrypi4:
    
    build/tmp/deploy/images/raspberrypi4/core-image-base-raspberrypi4.rpi-sdimg
    
    It is this file that will serve us to create our bootable SD card. Raspberry Pi have developed a graphical SD card writing tool that works on Mac OS, Ubuntu 18.04 and Windows, and is the easiest option for most users as it will download the image and install it automatically to the SD card. The use of the dd tool can overwrite any partition of your machine. If you specify the wrong device in the instructions below, you could delete your primary Linux partition. Please be careful:
    • Check which SD card are currently connected to your machine.
    • 
      $ lsblk -p
      ...
      /dev/sdd      8:48   1  29.7G  0 disk 
      ├─/dev/sdd1   8:49   1   256M  0 part /media/jerry/boot
      └─/dev/sdd2   8:50   1  29.5G  0 part /media/jerry/rootfs
      ...
      
      If any partitions on the SD card have been mounted, unmount them all with umount:
      
      $ umount /dev/sdd1
      $ umount /dev/sdd2
      
    • Backup the content of the working SD card
    • Make sure the device name is the name of the whole SD card as described above, not just a partition.
      
      sudo dd bs=4M  if=/dev/sdd conv=fsync of=2020-06-09-raspi-4.img
      
      Please note that block size set to 4M will work most of the time. If not, try 1M, although this will take considerably longer.
    • Verify the backup image
    • You can't mount the image as a whole because it actually contains partitions and a boot sector. However, you can mount the individual partitions in the image if you know their offset inside the file. To do it, examine the image as a block device with "fdisk -l *.img". The output should include a table like this:
      
      $ fdisk -l 2020-06-09-raspi-4.img
      Disk 2020-06-09-raspi-4.img: 26.6 GiB, 28498198528 bytes, 55660544 sectors
      Units: sectors of 1 * 512 = 512 bytes
      Sector size (logical/physical): 512 bytes / 512 bytes
      I/O size (minimum/optimal): 512 bytes / 512 bytes
      Disklabel type: dos
      Disk identifier: 0x6c586e13
      
      Device                  Boot  Start      End  Sectors  Size Id Type
      2020-06-09-raspi-4.img1        8192   532479   524288  256M  c W95 FAT32 (LBA)
      2020-06-09-raspi-4.img2      532480 62333951 61801472 29.5G 83 Linux
      
      
      We can find the offset in bytes by multiplying this unit size by the Start block of the partition:
      • offest of the 1st partition
      • 512 * 8192 = 4194304
      • offest of the 2nd partition
      • 512 * 532480 = 272629760
      After knowing the offest of each partition in the image file, these partition can be mounted:
      
      mount -v -o offset=4194304 -t vfat *.img /mnt/img/1
      mount -v -o offset=272629760 -t ext4 *.img /mnt/img/2
      
      If you get an "overlapping loop" error here, your version of mount requires you to specify the size as well as the offset of the first partition.
      
      mount -v -o offset=4194304,sizelimit=29360128 -t vfat *.img /mnt/img/one  
      
      The package kpartx makes it even easier for you. kpartx creates device maps from partition tables:
      • To mount all the partitions in a raw disk image
      • 
        kpartx -av disk.img
        
        This will output lines such as:
        
                      add map loop1p1 (254:4): 0 409597 linear 7:1 3
        
        The loop1p1 is the name of a device file under /dev/mapper which you can use to access the partition, for example to fsck it:
        
                      fsck /dev/mapper/loop1p1
        
      • When you're done, you need to remove the devices
      • 
        kpartx -d disk.img
        
      Note, loop device is a device driver that allows you to mount a file(single filesystem) act as a block device.
      
      $ mount -o loop disk1.iso /mnt/disk
      
      An ISO image is an archive file that contains everything that would be written to an optical disc, sector by sector. The data inside the ISO image will be structured according to the file system (usually ISO 9660 and its extensions or UDF) that was used on the optical disc from which it was created.
    After the content of the SD card is backup, you can create an new SD card content with the following command:
    
    $ ls -l *sdimg
    -rw-r--r-- 2 jerry jerry 192937984  六   9 20:21 core-image-base-raspberrypi4-20200609093357.rootfs.rpi-sdimg
    lrwxrwxrwx 2 jerry jerry        60  六   9 20:21 core-image-base-raspberrypi4.rpi-sdimg -> core-image-base-raspberrypi4-20200609093357.rootfs.rpi-sdimg
    
    $ fdisk -l core-image-base-raspberrypi4-20200609093357.rootfs.rpi-sdimg
    
    Disk core-image-base-raspberrypi4-20200609093357.rootfs.rpi-sdimg: 184 MiB, 192937984 bytes, 376832 sectors
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disklabel type: dos
    Disk identifier: 0x3fe7ef76
    
    Device                                                        Boot Start    End Sectors  Size Id Type
    core-image-base-raspberrypi4-20200609093357.rootfs.rpi-sdimg1 *     8192  90111   81920   40M  c W95 FAT32 (LBA)
    core-image-base-raspberrypi4-20200609093357.rootfs.rpi-sdimg2      90112 376831  286720  140M 83 Linux
    
    $ sudo dd if=core-image-base-raspberrypi4.rpi-sdimg of=/dev/sdd bs=4M  conv=fsync status=progress
    [sudo] password for jerry: 
    176160768 bytes (176 MB, 168 MiB) copied, 2 s, 87.0 MB/s
    46+0 records in
    46+0 records out
    192937984 bytes (193 MB, 184 MiB) copied, 17.8175 s, 10.8 MB/s
    
    
    Here, /dev/sdd corresponds to the device node assigned to the microSD card in your host system. To use the serial console for Raspberry Pi 3/4, the following 2 lines must be appended in /boot/config.txt,
    
    enable_uart=1
    core_freq=250
    
    To print the kernel boot messages, prefix the following lin in /boot/cmdline.txt:
    
    earlyprintk
    
  • Boot your RPI
  • You can now insert the SD card into the Raspberry Pi and power it up.
    • For the official Raspberry Pi OS, if you need to manually log in, the default user name is pi, with password raspberry.
    • Use the serial console ( 115200, 8N1, /dev/ttyUSB0) to login the built Yocto/Poky distribution: root, password is empty .

Using the Toaster web interface


Toaster is a web application interface to the Yocto Project's build system built on the Django framework with a database backend to store and represent build data.
It replaces the Hob user interface(a graphical interface for BitBake), which could be found on releases prior to Yocto 1.8.

Django的主要目標是簡化資料庫驅動的網站的開發。

1.7.2 Getting ready


your host machine needs to be set up as follows:

$ sudo apt-get install python3-pip
$ pip3 install --user -r /opt/yocto/poky/bitbake/toaster-requirements.txt

1.7.3 How to do it...


To start Toaster:

$ cd /opt/yocto/poky
$ source oe-init-build-env raspi4
$ source toaster start
/opt/yocto/poky/bitbake/bin/toaster is a shell script that will do necessary things to start the web server.
By default, Toaster binds to localhost on port 8000 and can be accessed by: http://127.0.0.1:8000 .
This port can be specified as follows:

$ source toaster start webport=IP:PORT

1.7.4 Administrator interface


To access the Django administration interface, you must create a superuser:
  • To append the pip3 local user path
  • 
    $ export PATH=$PATH:$HOME/.local/bin
    
  • From the Build Directory, invoke the createsuperuser command
  • 
    $ cd /opt/yocto/poky/raspi4
    $ ../bitbake/lib/toaster/manage.py createsuperuser
    
To access the Django administration interface through a browser.

http://127.0.0.1:8000/admin

You can manually start a build on the terminal and Toaster will monitor it.
You can then use the Toaster web UI to explore the build results.

1.7.5 Starting a build


You can also use the Toaster web interface to create a new project.


1.8 Running a Toaster Docker container


Docker is a software technology that provides OS level virtualization. 虛擬機器則是虛擬化硬體.
Docker 利用Linux核心中的資源分離機制,例如cgroups,以及Linux核心命名空間(namespaces),來建立獨立的容器(containers)。這可以在單一Linux實體下運作,避免啟動一個虛擬機器造成的額外負擔。
Dockers是有能力打包應用程式及其虛擬容器,可以在任何Linux伺服器上執行的依賴性工具,這有助於實現靈活性和可攜式性,應用程式在任何地方都可以執行,無論是公用雲、私有雲、單機等。
It allows you to create containers that run on Docker and are independent of the operating system underneath.


1.9 Configuring network booting for a development setup



1.9.1 Getting ready


The ideal setup for development work is to use both TFTP and NFS servers in your host system and to only store the bootloader in either the internal flash or a microSD card.
With this setup, the bootloader will fetch the Linux kernel from the TFTP server and the kernel will mount the root filesystem from the NFS server. Changes to either the kernel or the root filesystem are available without the need to reprogram.


1.9.


1.9.


1.9.


1.9.


1.9.



1.10 Using Docker as a Yocto build system container

1.11 Sharing downloads

1.12 Sharing the shared state cache

Setting up a package feed

1.13 Using build history

1.14 Working with build statistics

1.15 Debugging the build system



2. The BSP Layer



Yocto for Raspberry Pi

by
Pierre-Jean TEXIER
Petter Mabäcker

the code repository for this book

https://github.com/PacktPublishing/Yocto-for-Raspberry-Pi

1. Meeting the Yocto Project

The Yocto Project

"The Yocto Project is an open source collaboration project that provides templates, tools and methods to help you create custom Linux-based systems for embedded products regardless of the hardware architecture." It provides tools, processes, templates and methods so that developers can rapidly create and deploy products for embedded devices. The two main components that make up the Yocto Project are:
  • Poky
    Poky is the reference system of the Yocto Project with a six month release cycle. It provides meta data divided into layers and recipes for building various packages and images.
  • BitBake
    This is the scheduler. It is a tool based on the Gentoo distribution.

Understanding the build system

A build system enables you to:
  • Compile or cross-compile applications
  • Package applications
  • Test output binaries and ecosystem compatibility
  • Deploy generated images
Buildroot is rather dedicated to firmware generation, while Yocto/OpenEmbedded is oriented towards distribution.

The core components

The core components (other available tools are optional) of the Yocto Project are:
  • BitBake
  • OpenEmbedded-Core
  • Poky
  • The BSP layer (meta-raspberry, meta-fsl-arm, meta-ti, meta-intel, meta-sunxi, and so on)
OpenEmbedded Build System includes BitBake and OpenEmbedded-Core.

What is Poky?

Poky is maintained as a reference distribution under the Yocto Project. It provides the mechanism to build and combine thousands of distributed open source projects for a number of targets.

The Chief - BitBake

BitBake, the build engine, is a task scheduler (like GNU Make). Once the environment is built, BitBake will execute the task (an environment variable do_<task name> decides the task ) that has been requested. According to the information contained in the recipes (or metadata), it downloads the sources of projects from the assigned repository( local, http,git ) then builds in the order determined by the dependency graph generated dynamically. Finally, it installs binaries, generates the corresponding package, and builds the final image, which can be installed on the target(Raspberry Pi for us).

OpenEmbedded-Core

OpenEmbedded-Core is a base layer of recipes, classes and associated files that is meant to be common among many different OpenEmbedded-derived systems and forms the basis of the new structure for OpenEmbedded.

Exploring metadata

Metadata refers to the build instructions themselves as well as the data used to control what things get built and to affect how they are built.

Yocto Project - workflow

2. Building our First Poky Image for the Raspberry Pi

Installing the required packages for the host system

The steps necessary for the configuration of the host system depend on the Linux distribution used.

Poky on Ubuntu


$ sudo apt-get install gawk wget git diffstat unzip chrpath g++ gcc make python texinfo python3-distutils

Poky on Fedora


$ sudo yum install gawk make wget tar bzip2 gzip python unzip perl patch diffutils diffstat git cpp gcc gcc-c++ glibc-devel texinfo chrpath ccache perl-Data-Dumper perl-Text-ParseWords perl-Thread-Queue socat

Downloading the Poky metadata

The Yocto Project® build system (BitBake and the OE-Core metadata) is packaged with the reference distro (called Poky). Download the latest release branch master of the Yocto Project)

git clone -b master git://git.yoctoproject.org/poky.git

Downloading the Raspberry Pi BSP metadata

To download the specific layer (BSP Layer) to the Raspberry PI:

$ cd poky
$ git clone git://git.yoctoproject.org/meta-raspberrypi
make sure the meta data is downloaded:

$ ls meta-raspberrypi/conf/machine/*.conf
The folders under meta-raspberrypi:

$ tree -L 1  meta-raspberrypi
meta-raspberrypi
├── classes
├── conf
├── COPYING.MIT
├── docs
├── dynamic-layers
├── files
├── kas-poky-rpi.yml
├── lib
├── README.md
├── recipes-bsp
├── recipes-connectivity
├── recipes-core
├── recipes-devtools
├── recipes-graphics
├── recipes-kernel
├── recipes-multimedia
└── wic

Initialize the build environment: The oe-init-build-env script

oe-init-build-env is a script for the configuration/initialization of the build environment. This needs to be sourced to setup the environment. It is to initialize a certain number of environment variables and place itself in the build directory specified in the argument:

$ source oe-init-build-env build-directory

The build-directory folder is the place where we perform builds. If build-directory is not specified, it defaults to build . To initialize our environment:

$ source oe-init-build-env rpi-build
You had no conf/local.conf file. This configuration file has therefore been
created for you with some default values. You may wish to edit it to, for
example, select a different MACHINE (target hardware). See conf/local.conf
for more information as common configuration options are commented.

You had no conf/bblayers.conf file. This configuration file has therefore been
created for you with some default values. To add additional metadata layers
into your configuration please add entries to conf/bblayers.conf.

The Yocto Project has extensive documentation about OE including a reference
manual which can be found at:
    http://yoctoproject.org/documentation

For more information about OpenEmbedded see their website:
    http://www.openembedded.org/


### Shell environment set up for builds. ###

You can now run 'bitbake '

Common targets are:
    core-image-minimal
    core-image-sato
    meta-toolchain
    meta-ide-support

You can also run generated qemu images with a command like 'runqemu qemux86'

Other commonly useful commands are:
 - 'devtool' and 'recipetool' handle common recipe tasks
 - 'bitbake-layers' handles common layer tasks
 - 'oe-pkgdata-util' handles common target package tasks

~/poky/rpi-build$
After the initialzation, there are important files created under the build-folder ~/poky/rpi-build:

bblayers.conf  local.conf  templateconf.cfg

Editing the local.conf file

local.conf file is a file containing variables which can configure every aspect of the build process.
  • MACHINE variable
  • the target machine.
    
    MACHINE ?= "raspberrypi"
    
  • DISTRO variable
  • the distribution
  • PACKAGE_CLASSES variable
  • the type of package
  • PARALLEL_MAKE variable
  • the host configuration
The minimal set of variables we have to change from the default is:

MACHINE ?= "raspberrypi"

Editing the bblayers.conf file

Add lines: POKY_BBLAYERS_CONF_VERSION = "2"

BBPATH = "${TOPDIR}"
BBFILES ?= ""

BBLAYERS ?= " \
  /home/jerry/poky/meta \
  /home/jerry/poky/meta-poky \
  /home/jerry/poky/meta-yocto-bsp \
  /home/jerry/poky/meta-raspberrypi \
  "

Building the Poky image

Poky provides several pre-designed image recipes that we can use to build our own binary image:

~/poky$ ls meta*/recipes*/images/*.bb

Choice of image

Image recipes provided by meta-raspberry:

~/poky$ ls meta-raspberrypi/recipes-core/images/*.bb

  • rpi-basic-image.bb
  • This is an image based on core-image-minimal.
  • rpi-test-image.bb
  • This is an image based on rpi-hwup-image.bb with some added features(a splash screen).
  • rpi-hwup-image.bb
  • This is an image based on rpi-basic-image.bb and includes some packages

Running BitBake

BitBake, the build engine, which will parse all the recipes related to the image you pass as a parameter:

~/poky$ source oe-init-build-env rpi-build
~/poky/rpi-build$ bitbake rpi-basic-image

After a few hours of baking, the system image for our target is generated under tmp/deploy/images/raspberrypi/.


Creating an SD card

Booting the image on the Raspberry Pi

3. Mastering Baking with Hob and Toaster

Hob

Preparing the environment for Hob

Running Hob

Configuring recipes and packages

Building the image

Exploring Toaster

Installing the required packages for the host system

Running Toaster

Running BitBake

Running the web interface

4. Understanding BitBake

BitBake

BitBake is a task scheduler (like GNU Make) that parses shell and Python scripts. The code parsed generates and runs tasks (configure, compile, and so on), which are basically sets of steps ordered according to the code's dependencies.

Metadata

The metadata used by BitBake:
  • Configuration ( .conf ) files
  • Recipes ( .bb and .bbappend files)
  • Classes ( .bbclass files)
  • Include ( .inc ) files

Configuration

Configuration files, which are denoted by the .conf extension, define various configuration variables that govern the project's build process.

Classes

Class files, which are denoted by the .bbclass extension, contain information that is useful to share between metadata files.

Recipes

BitBake recipes, which are denoted by the .bb file extension , provide BitBake with the following information:
  • Descriptive information about the package
  • The version of the recipe
  • Existing dependencies
  • Where the source code resides
  • Whether the source code requires any patches
  • How to compile the source code
  • Where on the target machine to install the package being compiled

Parsing metadata

Preferences and providers

Dependencies

Fetching

The local file fetcher

The HTTP fetcher

The Git fetcher

Understanding BitBake's tasks

5. Creating, Developing, and Deploying on the Raspberry Pi

Software development kits (SDKs)

A generic SDK - meta-toolchain

image.bb -c populate_sdk

The Qt SDK - meta-toolchain-qt

The Qt5 SDK - meta-toolchain-qt5

Cross-compilation - an example

Configuration of the SDK environment

List of tools

Compilation

Raspberry Pi and a package manager

Package format availablility

Choosing a package format

Installing and updating a package on the target

RPM packages

Installing manually

Installing automatically

IPK packages

Installing manually Installing automatically

Our application - an introduction

Our application - creating the recipe

The recipe explained

6. Working with External Layers

Introducing layers

The basic concepts of layers

Theory

The software layer

README and COPYING

The classes folder

The conf folder

The recipes-* directory

The machine (BSP) layer

Adding external layers to the Raspberry Pi

7. Deploying a Custom Layer on the Raspberry Pi

Creating the meta-packt_rpi layer with the yocto-layer script

Adding gpio-packt to meta-packt_rpi

Patching gpio-packt

Generating the patch

Adding the patch to the recipe file

Creating the raspberry-packt-image.bb image

Creating the environment

Modifying the recipe file

Deploying the raspberry-packt-image.bb image

8. Diving into the Raspberry Pi's Peripherals and Yocto Recipes

The SPI bus

The spi-tools project Inclusion in the meta-oe layer Baking spi-tools Testing on the Raspberry Pi spi-config spi-pipe Conclusion

The i2c bus

The Wii Nunchuck

The Nunchuck connector

The Raspberry Pi connection

The Nunchuck's protocol

Encryption

Requesting sensor data

Testing the i2c connection

Creating the Nunchuck application

Integrating with meta-packt_rpi

Creating the Nunchuck recipe

Testing the Nunchuck application

V4L presentation

Video support

v4l-utils integration

9. Making a Media Hub on the Raspberry Pi

Project description â​​ CPU temperature monitoring

Overview

Hardware/software requirements

Creating the main application

server.js

index.html

Creating the Yocto/OE environment

Modifying the image

Creating the recipe file

Explanation

Autostarting - the init file

Explanation

Autostarting - the recipe file

Explanation

Deploying raspberry-packt-image

Testing the application

The future of this project

10. Playing with an LCD Touchscreen and the Linux Kernel

The Linux kernel

The Linux kernels versus the Raspberry Pi Linux kernel Getting started with the Linux kernel Configuring the kernel in Yocto Configuring the kernel with LCD support The Raspberry Pi device tree Configuring the touchscreen from the kernel perspective

Setting up an LCD display for the Raspberry Pi using the Yocto Project

The Raspberry Pi 7 touchscreen The PiTFT 2.8 resistive touchscreen

Developing applications and using them on an LCD display

Developing a custom application using Qt Summary

11. Contributing to the Raspberry Pi BSP Layer

Open source Contributing to open source projects Exploring Git What is Git? Working with Git Contributing to the Yocto Project Contributing to meta-raspberrypi Setting up your Git repository Creating your commit Sending changes to the community Follow-up Practical example - sending a custom tool upstream Summary

12. Home Automation Project - Booting a Custom Image

Home automation using a Raspberry Pi

Material required for the project

Setting up the base for the project

Creating a new layer Customizing the image recipe Building and booting the image

Creating the server side

Creating a packet list for your image

Setting up a customized package list Start using a customized package list in meta-packt-iot

Putting it all together

Serial and SSH connections to the Raspberry Pi

Controlling the relay using the Raspberry Pi

Controlling the lamp using the Raspberry Pi

Turning on/off the lamp from a smartphone

Extra - using a Raspberry Pi with an LCD as the client

References

留言

熱門文章