Skip to content
systemcoding.dev
Embedded Linux

Choose MACHINE, DISTRO and Image Targets in Yocto

MACHINE picks the hardware, DISTRO picks the policy and the image recipe picks the contents. Here is how to choose and change each one.

6 min read
Summarize in AI
Flat illustration of a single-board computer with its SoC, memory, header and ports, with the Linux, Debian and NXP logos.

Every Yocto build is the product of three independent choices, and mixing them up is the commonest source of confusion in the first week. You choose the hardware you are building for, the policy the system follows, and the set of software that goes into the image. They sit in three different places, they are changed in three different ways, and they combine freely. This post names the three, shows where each is set, explains how to list what is available, and walks through changing each one on a Scarthgap 5.0 LTS tree. It assumes you have a build directory from the first-build post.

The three choices

ChoiceVariable or argumentAnswers the questionDefined in
MachineMACHINEWhich hardware, CPU and kernel?conf/machine/<name>.conf in a layer
DistributionDISTROWhich policy: libc, init system, features, flags?conf/distro/<name>.conf in a layer
Imagethe bitbake targetWhich packages end up on the root filesystem?an image recipe, <name>.bb

Think of it as a shopping list with three lines. The machine decides how the system is compiled and which kernel and bootloader it needs. The distribution decides how software is configured across the whole system. The image decides which software is present. Changing one does not require changing the others, though some combinations make no sense, for example a graphical image on a machine without a display.

MACHINE: the hardware

A machine configuration describes a board or an architecture: the tuning flags for the compiler (DEFAULTTUNE), the kernel recipe to use (PREFERRED_PROVIDER_virtual/kernel), the bootloader, the serial console, and the types of image files to produce. Poky's own layers give you the QEMU machines such as qemux86-64, qemuarm64 and qemuriscv64, and a few reference boards in meta-yocto-bsp. Real boards come from board support package layers supplied by the vendor or the community.

To see which machines your layers offer, list the machine configuration files:

Shell
ls ../meta*/conf/machine/*.conf | xargs -n1 basename | sed 's/.conf$//'
Text
beaglebone-yocto
genericarm64
genericx86
genericx86-64
qemuarm
qemuarm64
qemuarmv5
qemumips
qemumips64
qemuppc
qemuppc64
qemuriscv32
qemuriscv64
qemux86
qemux86-64

The exact list depends on your release and the layers you have added, and some of these may be in a different folder name. Run it against your own tree. The command works because machine files are plain <name>.conf files below a conf/machine/ directory in each layer.

Set the machine in conf/local.conf:

Text
MACHINE = "qemuarm64"

Because the sample file sets MACHINE ??=, a plain = replaces it. You can also set it for a single invocation through the environment, without editing any file:

Shell
MACHINE=qemuarm64 bitbake core-image-minimal

That only works because MACHINE is passed through BB_ENV_PASSTHROUGH_ADDITIONS, a list of variables BitBake allows from the shell environment. Variables outside that list, such as an arbitrary one you invent, are ignored when exported from the shell. If you use this method, remember it is easy to forget which machine a build directory last built.

Each machine gets its own output directory, tmp/deploy/images/<machine>/, but all machines in one build directory share TMPDIR. Switching back and forth reuses the shared state cache, and the architecture-specific packages are stored under separate paths in tmp/work, so you can switch without a clean build.

DISTRO: the policy

A distribution configuration is a file in conf/distro/ that sets system-wide policy: which C library, which init system, which package format, the compiler options, and the default features. The Poky distribution is poky, set by DISTRO ?= "poky". Others you may meet are poky-tiny, a very small policy, poky-altcfg, which uses a different set of defaults, and distributions from other layers such as Arago or your own.

The value of DISTRO also gives the build its name in the banner and os-release. To use systemd instead of BusyBox init, you set features in the distribution, not in the image:

Text
DISTRO_FEATURES:append = " systemd"
VIRTUAL-RUNTIME_init_manager = "systemd"
DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
VIRTUAL-RUNTIME_initscripts = "systemd-compat-units"

Those four lines are the documented recipe for switching a Poky build to systemd, and the init post later in this series covers it end to end. They are an example of policy: they apply to every recipe and every image in the build. The colon form (:append) is the override syntax used since Honister; older posts show DISTRO_FEATURES_append, which no longer works on Scarthgap.

Changing DISTRO recompiles most things, because the policy is part of every recipe's task signature. Expect a long build after a distribution change, though the cache will return anything unaffected.

The image target: the contents

An image recipe is a .bb file that names the packages to install. You choose it by naming it on the command line. The images Poky ships under meta/recipes-core/images/ and meta/recipes-extended/images/ include:

ImageWhat it holds
core-image-minimalA console boot with BusyBox and little else
core-image-full-cmdlineA console system with common command-line tools and a full set of utilities
core-image-baseA console image with support for hardware features listed in MACHINE_FEATURES
core-image-satoA graphical image with a mobile-style desktop
core-image-westonA Wayland compositor image

List the image recipes in your layers with:

Shell
bitbake-layers show-recipes "*image*"
Text
NOTE: Starting bitbake server...
=== Matching recipes: ===
core-image-base:
  meta                 1.0
core-image-full-cmdline:
  meta                 1.0
core-image-minimal:
  meta                 1.0
core-image-sato:
  meta                 1.0

Your output will list more, because the wildcard matches many names, and the layer name and version column depend on your tree. To use any of them, name it:

Shell
bitbake core-image-full-cmdline

You can build several images in one invocation, and you can add packages to any image without writing a recipe by using IMAGE_INSTALL:append in local.conf, though a custom image recipe is the clean answer for anything you will keep. The dedicated custom-image post covers that.

How the three interact

A few rules explain most surprises.

  • The image does not choose the machine, but the machine can restrict the image. MACHINE_FEATURES lists what the hardware offers, and an image feature such as wifi is installed only if the matching machine feature exists. That is why core-image-base differs between machines.

  • The distribution can restrict recipes. A recipe may declare that it needs a distribution feature (REQUIRED_DISTRO_FEATURES), and if the feature is missing it is skipped with a message that mentions it.

  • The same recipes produce different binaries for different machines and distributions, because both enter the task hash. They do not share outputs unless the relevant variables match.

A common mistake is to try to solve a policy question inside the image, such as removing systemd from one image while the distribution still enables it. Decide first whether the choice is about the hardware, the policy, or the contents.

A worked change

Starting from the defaults, switch to an Arm 64-bit QEMU machine and a command-line image with SSH, leaving the distribution alone. In conf/local.conf:

Text
MACHINE = "qemuarm64"
EXTRA_IMAGE_FEATURES += "ssh-server-dropbear"

Then build and boot:

Shell
bitbake core-image-full-cmdline
runqemu qemuarm64 nographic slirp
Text
Poky (Yocto Project Reference Distro) 5.0.5 qemuarm64 ttyAMA0

qemuarm64 login:

The console device name ttyAMA0 reflects the emulated Arm board's UART, where the x86 machine used ttyS0. That difference comes from the machine configuration, not from the image or the distribution, which is a neat confirmation that you changed the right layer of the choice.

Share

Keep reading

Flat illustration of user space above the system call boundary, the kernel and the hardware, with the Linux, C and GNU logos.
Kernels

Write a Pin Controller Driver With pinctrl

Write a Linux 6.12 pin controller driver: pinctrl_desc, pins, groups and functions, the set_mux callback, and the device tree states that consumers select.

8 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.