Skip to main content

TECH VEDA

Corporate on-site training - Submit proposal Pick your modulesSharpen your kernel skills: deep dives, drivers, Yocto, CVEs, careers — updated daily. Read the blog →
System Design

Yocto Development vs Production Images: Best Practices

Development vs production image in Yocto: keep one image recipe, derive a development image from the production recipe, or use two build configurations.

Yocto Development vs Production Images: Best Practices

For a product built with the Yocto Project, define the development vs production image difference with two image recipes in one distro: a production image that is the base, and a development image that requires it and adds root login, an SSH server and debug tools. Both images then use the same packages, kernel and distro configuration, and the difference between them is a few reviewed lines in a layer. The cost is that tests run on the development image do not fully cover the production image, so the final test pass must run on the production image itself. Use a separate build configuration only for differences that an image recipe cannot express, such as kernel debug options.

During development, engineers need to log in as root, copy files over SSH and run gdb and strace on the target. The released device should allow none of this by default. Every team therefore has a development vs production image split in some form. The design question is where that split is defined: in a developer’s build directory, in an image recipe, or in a separate build configuration. The answer decides how easily a development setting can reach a released image.

The context

The Yocto Project Security Manual states the requirement directly: remove or disable debugging functionality before producing the final image. Four forces act on how a team meets it.

  • Access during development. Root login without a password, on the serial console and over SSH, saves time each time a board is reflashed.
  • Explicit image features. Before release 5.2 (Walnascar), one image feature named debug-tweaks enabled this access. Release 5.2 removed it because the name did not state what it did. The same result now needs four features: allow-empty-password, allow-root-login, empty-root-password and post-install-logging.
  • Where the setting is stored. The documentation shows these features added through EXTRA_IMAGE_FEATURES in local.conf or in a distro configuration file, or through the configuration fragment core/yocto/root-login-with-empty-password. A fragment enabled with bitbake-config-build is recorded in OE_FRAGMENTS in conf/toolcfg.conf, which is a file in the build directory and not in a layer.
  • Test coverage. The image that is tested should be the image that is released, or as close to it as possible.

The options for a development vs production image

Option 1: one image recipe, development settings in the build directory

This is the simplest form of a development vs production image split. There is one image recipe. Each developer enables the development features in local.conf or with the fragment. The release build is expected to use a build directory that does not have them.

  • Pros: there is nothing extra to maintain, and each developer can add the tools that the current task needs.
  • Cons: whether an image accepts a root login without a password depends on files in the build directory, and these files are normally not reviewed or kept in version control. The development image and the production image have the same file name. A setting in local.conf applies to every image built in that directory.

Option 2: two image recipes in one distro

The production image recipe is the base. A second recipe requires it and adds the development features. OpenEmbedded-Core uses the same pattern: core-image-minimal-dev.bb requires core-image-minimal.bb and adds one image feature, dev-pkgs. For a product whose production recipe is product-image.bb and inherits the core-image class, the development recipe is short:

# product-image-dev.bb
require product-image.bb

DESCRIPTION = "Product image with development access and debug tools"

IMAGE_FEATURES += "allow-empty-password allow-root-login empty-root-password ssh-server-dropbear tools-debug"

Both images are built from the same build directory:

raghu@techveda.org:~$ bitbake product-image product-image-dev
  • Pros: the difference between the two images is stored in a layer, so it is reviewed and versioned. Both recipes use the same MACHINE and DISTRO, so both images are assembled from the same packages and the same kernel, and these are built once. The image names differ, so the output files cannot be confused. A release job can be restricted to the production recipe name.
  • Cons: an image recipe can change only what is installed in the root filesystem and how the image is configured. It cannot change kernel options or compiler flags. The installed set differs between the two images, so image size, free space and start-up behaviour can differ. There are two images to build and store.

Option 3: two build configurations

A second distro configuration file, or a second set of kernel configuration fragments, defines the development build. This is the only option that changes what is compiled: kernel options such as CONFIG_KGDB and CONFIG_MAGIC_SYSRQ, distro features, or the compiler and linker flags in security_flags.inc.

  • Pros: any difference can be expressed. The production kernel can be built without debug facilities.
  • Cons: the two builds contain different binaries, so a result measured on the development build is not evidence about the production build. Every recipe affected by the difference is built twice. The two configurations can diverge over time if only one of them is used daily.

The decision

For the common case, a product with one or a few hardware variants that is built by a CI system, choose Option 2 for the development vs production image split. Make the production recipe the base and let the development recipe add to it. If someone then forgets a line, the result is a development image with a missing tool, and not a production image with open access. Three rules complete the design:

  1. Keep EXTRA_IMAGE_FEATURES and the root login fragment out of the build configuration that CI uses.
  2. Let the release job build only the production recipe.
  3. Run the final acceptance tests on the production image.

The other options are the right choice in these conditions:

  • Option 1 is sufficient for a prototype or an evaluation board, when no unit leaves the laboratory. Move to Option 2 before the first unit is delivered outside the team.
  • Option 3 is necessary when the development build needs kernel debug options that must be absent from the production kernel. Limit the difference to named kernel configuration fragments and keep the root filesystem on Option 2. Development and production units also commonly use different signing keys. That is a separate decision, described in Secure Boot Key Custody: Who Holds the Signing Key?
  • Buildroot builds one root filesystem per configuration, so the same development vs production image split needs a second defconfig that is built in its own output directory. The relevant settings are BR2_TARGET_ENABLE_ROOT_LOGIN and BR2_TARGET_GENERIC_ROOT_PASSWD. This is closer to Option 3, and its cost of building twice applies.

TECH VEDA’s Embedded Linux on EdgeAI platforms course works with Yocto image recipes and distro configuration of this kind.

Consequences

  • Testing. Daily work happens on the development image, so the production image is used less. Tests that depend on an SSH login cannot run on it. The production image needs a test method that does not depend on development access.
  • Diagnosis in the field. Production units have no gdb or strace. The build still produces the -dbg packages, so store them with each release and analyse failures on a host.
  • Root account. When empty-root-password is absent, the build forces a non-empty password entry for root in /etc/passwd and /etc/shadow. The team must decide how production units are accessed for service, if at all. The Yocto documentation recommends the extrausers class for setting passwords. It also advises against one hardcoded password for every device, and suggests a different random password for each device, set after the image is deployed.
  • Maintenance. The development recipe inherits every change to the production recipe. If the production image later enables read-only-rootfs, the development image becomes read-only as well, and the team must decide whether that is acceptable. The layout of writable state is discussed in Read-Only Root Filesystem on Embedded Linux.
  • Release process. With a development vs production image split in recipes, the release checklist should still confirm from the build output that the development features are absent.

Key takeaways

  • Define the development vs production image difference in an image recipe in a layer, not in local.conf or a fragment enabled in one build directory.
  • Make the production recipe the base. The development recipe requires it and adds features.
  • Since release 5.2 the development access is four explicit image features. debug-tweaks no longer exists.
  • Use a second build configuration only for kernel options and flags, and expect to test both builds.
  • Run the final tests on the production image.
Was this worth your time?

Frequently asked questions

What replaced debug-tweaks in the Yocto Project?
Release 5.2 (Walnascar) removed the debug-tweaks image feature. The same result needs four image features: allow-empty-password, allow-root-login, empty-root-password and post-install-logging.

Does a separate development image recipe rebuild all the packages?
No. When both recipes use the same machine and distro configuration, both images are assembled from the same packages and the same kernel. The second recipe adds only root filesystem assembly and image creation.

Can an image recipe remove kernel debug options from the production build?
No. An image recipe changes what is installed in the root filesystem and how the image is configured. Kernel options such as CONFIG_KGDB need a kernel configuration fragment, which means a second build configuration.

How should the root password be set on a production image?
The Yocto documentation recommends the extrausers class for setting passwords. It advises against one hardcoded password for every device and suggests a different random password for each device, set after the image is deployed.

Further reading

RB
Raghu Bharadwaj

Founder, TECH VEDA — 20+ years teaching the Linux kernel, device drivers and embedded systems.

Follow on LinkedIn

Get the best of TECH VEDA by email

The best of our kernel and embedded Linux writing, a few emails a month. No spam.

We email occasionally and never share your address.