Yocto: Building Linux OS Images

Yocto Development And Build

Getting

$ git clone https://github.com/jfasch/FH-ENDLESS
$ git submodule init
Submodule 'Yocto/meta-raspberrypi' (https://github.com/agherzan/meta-raspberrypi) registered for path 'Yocto/meta-raspberrypi'
Submodule 'Yocto/poky' (https://git.yoctoproject.org/poky) registered for path 'Yocto/poky'
$ git submodule update
Cloning into '/home/jfasch/My-Projects/FH-ENDLESS-nici/Yocto/meta-raspberrypi'...
Cloning into '/home/jfasch/My-Projects/FH-ENDLESS-nici/Yocto/poky'...
Submodule path 'Yocto/meta-raspberrypi': checked out 'd5ffe135c73ab940148e595c6fb010d50ddcfc60'
Submodule path 'Yocto/poky': checked out 'a6c1af1af5baad083f0c98acd9957ccabdd49067'

Structure

The FH-ENDLESS project contains not only the Yocto build. For Yocto, go to the Yocto/ subdirectory.

poky/ (Submodule)

poky/ contains the upstream https://git.yoctoproject.org/poky sources - the Yocto core, so to say (Yocto has a long history, and it’s not always clear what the relationship between OpenEmbedded and Poky is).

meta-raspberrypi/ (Submodule)

This is the BSP layer for the raspberry build (see below).

Build Directories

As of 2024-11-27, there are the following build directories available:

  • qemuarm64/

  • qemux86-64/

  • raspberry3-build/

Each of those contains a conf/ subdirectory with two config files, conf/local.conf and conf/bblayers.conf. To avoid duplication of setting, these files delegate (include) common settings from the files common-local.conf and common-bblayers.conf in the toplevel Yocto/ directory.

Building

Best to start with the Qemu variant because it is more easily tested than the Raspi variants.

When you run bitbake the first time, you migt encounter errors like

$ bitbake endless-image-fulldev
ERROR: The following required tools (as specified by HOSTTOOLS) appear to be unavailable in PATH, please install them in order to proceed:
  chrpath diffstat lz4c patch rpcgen

Install the tools using your distribution’s package manager [1]

QEMU (MACHINE = qemux86-64)

Setup Environment
$ . ~/FH-ENDLESS/Yocto/poky/oe-init-build-env ~/FH-ENDLESS/Yocto/qemux86-64/
$ pwd
/home/jfasch/FH-ENDLESS/Yocto/qemux86-64
Build An Image (endless-image-fulldev)
$ bitbake endless-image-fulldev
Test

Start QEMU on it. The slirp option did the trick, everything just works.

$ runqemu nographic slirp

QEMU uses screen (or was it tmux?) to capture the terminal. C-a x is used to quit the session, and get back to the shell where you started.

SSH Login
$ ssh -p 2222 endless@localhost

Raspberry Pi 3 (MACHINE = raspberrypi3-64)

Setup Environment
$ . ~/FH-ENDLESS/Yocto/poky/oe-init-build-env ~/FH-ENDLESS/Yocto/raspberry3-build/
$ pwd
/home/jfasch/FH-ENDLESS/Yocto/raspberry3-build
Build An Image (endless-image-fulldev)
$ bitbake endless-image-fulldev
Test

Bring the generated .wic image onto the SD card.

The image file (see https://docs.yoctoproject.org/dev-manual/wic.html)

$ ls -l tmp/deploy/images/raspberrypi3-64/endless-image-fulldev-raspberrypi3-64.rootfs.wic.bz2
lrwxrwxrwx 2 jfasch jfasch 67 Nov 27 13:29 tmp/deploy/images/raspberrypi3-64/endless-image-fulldev-raspberrypi3-64.rootfs.wic.bz2 -> endless-image-fulldev-raspberrypi3-64.rootfs-20241127121726.wic.bz2

Uncompress

$ bzip -cd tmp/deploy/images/raspberrypi3-64/endless-image-fulldev-raspberrypi3-64.rootfs.wic.bz2 > uncompressed-image.wic
$ sudo cp uncompressed-image.wic /dev/mmcblk0

Over SSH on the fly directly onto the SD card that is in my laptop’s SD slot,

$ ssh $ENDLESS_SERVER \
     'bzip2 -cd /home/jfasch/FH-ENDLESS/Yocto/raspberry3-build/tmp/deploy/images/raspberrypi3-64/endless-image-fulldev-raspberrypi3-64.rootfs.wic.bz2' \
     | sudo sh -c 'cat > /dev/mmcblk0'

A Collection Of Commandlines

  • Find out which package provides a file

    $ oe-pkgdata-util find-path /usr/share/man/man1/groups.1
    shadow-doc: /usr/share/man/man1/groups.1
    

Kernel Config Fragments

https://wiki.koansoftware.com/index.php/Modify_the_linux_kernel_with_configuration_fragments_in_Yocto

Work Environment Preparation (On ENDLESS Server Machine)

Yocto can be built purely locally, on your own laptop. It might take a while though, and you’d have to make sure that the CPU is well ventilated.

This section describes a way to use a dedicated build server:

  • SSH for interactive remote login, to run Yocto’s build commands

  • SSH to mount the remote Yocto tree locally, so I can use a local text editor for development

The address of the remote build server is used by several commands described below; we store it in a variable that we reference below.

$ ENDLESS_SERVER=ddd.ddd.ddd.ddd

Interactive Login On $ENDLESS_SERVER

Required: an SSH account, setup by the administrator). My (jfasch’s) steps to setup my daily work environment follow. It’s all SSH, after all.

$ ssh jfasch@$ENDLESS_SERVER

Mounting And Unmounting My Home On $ENDLESS_SERVER

Use the sshfs command to mount the remote user’s home directory locally under ~/mounts/$ENDLESS_SERVER. We use the idmap mount option because the local user’s UID/GID might not match the remote user’s.

$ mkdir ~/mounts/$ENDLESS_SERVER
$ sshfs -o idmap=user -o uid=$(id -u) -o gid=$(id -g) $ENDLESS_SERVER: ~/mounts/$ENDLESS_SERVER
$ umount ~/mounts/$ENDLESS_SERVER

Raspberry Build

Project Setup

  • Change into ~/My-Projects/yocto

  • use poky@HEAD

    $ git clone https://git.yoctoproject.org/poky
    
  • Create raspberrypi3-64 build directory

    $ pwd
    ~/My-Projects/yocto
    $ . poky/oe-init-build-env raspberrypi3-64
    ... blah ...
    $ pwd
    ~/My-Projects/yocto/raspberrypi3-64
    
  • Set machine type that we build for

    In ~/My-Projects/yocto/raspberry3-build/conf/local.conf, add the following line

    MACHINE = "raspberrypi3-64"
    
  • Get meta-raspberrypi

    $ cd ~/My-Projects/yocto
    $ git clone https://github.com/agherzan/meta-raspberrypi
    
  • Add meta-raspberrypi to layers

    In ~/My-Projects/yocto/raspberry3-build/conf/bblayers.conf, add

    BBLAYERS += " ${HOME}/My-Projects/yocto/meta-raspberrypi"
    
  • Share download and sstate directories (for repeated builds, and in case we want to build for a Pi4)

    In ~/My-Projects/yocto/raspberry3-build/conf/local.conf, add the following lines

    DL_DIR = "${HOME}/My-Projects/yocto/DOWNLOAD
    SSTATE_DIR = "${HOME}/My-Projects/yocto/SSTATE"
    

Future Directions

Random/Half-Obsolete Notes

Footnotes