Module 14 · Lesson 43 of 92

Building the image and enabling the layer

Enable a custom Yocto BSP layer, verify kernel and U-Boot changes, and build, inspect and boot a Wic image on a BeagleBone Black.

  • Beginner to advanced
  • 11 min read
  • 45 min lab
What you will need

Ubuntu 24.04 in WSL2 or a VM with an initialized Yocto build and a working BeagleBone Black BSP baseline; a BeagleBone Black, serial console, microSD card and reader for the boot test

Your place in the module
By the end you can 4 objectives
  • Create and enable a BSP layer and verify that BitBake applies its recipe appends.
  • Build the kernel and U-Boot with devtool and locate each effective configuration.
  • Trace boot artifacts from the deploy directory into a Wic image.
  • Verify that the resulting image boots on the reference board.
Video coming soonBuilding the image and enabling the layer
The video for this lesson is being recorded. Read the lesson below in the meantime.
Recall first from Wiring the U-Boot and firmware recipes
  • UBOOT_MACHINE selects a U-Boot defconfig in the single-configuration case.
  • UBOOT_BINARY names the full U-Boot build output and UBOOT_IMAGE names its deployed image in the common recipe.
  • SPL_BINARY identifies an SPL output to deploy when the selected configuration builds it.
01

Enable the SensorNode BSP layer

3 min read

All the recipes exist, so now you assemble the flashable image and make the build see the layer. This lesson answers devtool for recipe development, the wic partition layout, and creating and enabling the layer.

A successful image build can still leave a board unable to boot. On the BeagleBone Black, the AM335x ROM needs to find the first boot stage on the chosen medium before Linux can do anything. A Linux host can inspect the card's partitions with lsblk, but the serial console tells you how far the board itself got. Use both observations to verify the image. Start with the Yocto release and BeagleBone Black BSP that already boot on your reference board, and keep that known-good card available. Here, sensornode is a custom machine for the same physical board.

Run these commands from the configured build directory, with the Yocto build environment already active. The example places the new layer next to the build directory.

bash
bitbake-layers create-layer ../meta-sensornode
bitbake-layers add-layer ../meta-sensornode
bitbake-layers show-layers

create-layer generates the layer skeleton, including conf/layer.conf and an example recipe you can remove. add-layer adds the directory to BBLAYERS in the build's conf/bblayers.conf. When another developer enables the layer, they need the underlying BSP layers too. Keep the release and layer revisions recorded with the lab so that the same machine and recipe names are available across builds.

In conf/layer.conf, BBFILE_COLLECTIONS registers the layer's collection name, such as sensornode. The suffixes in BBFILE_PATTERN_sensornode, BBFILE_PRIORITY_sensornode and LAYERSERIES_COMPAT_sensornode all refer to that name. Keep the generated BBFILES patterns, which tell BitBake where to discover .bb and .bbappend files, and keep the collection's path pattern consistent with the layer directory. Set LAYERSERIES_COMPAT_sensornode to the release series you actually support and test. For example, scarthgap is the series name to use for a build on that series. If the layer requires another collection for its machine include or recipe appends, declare that collection in LAYERDEPENDS_sensornode, using the name from the dependency's own BBFILE_COLLECTIONS.

A higher BBFILE_PRIORITY wins when layers offer competing recipes with the same name, even if the lower-priority layer has a higher recipe version. A matching .bbappend extends a recipe through BitBake's normal parsing and override rules. Multiple layers can append to the same recipe, so inspect the final variable values when two appends touch the same setting. Provider preferences such as PREFERRED_PROVIDER_virtual/kernel serve a different purpose. They choose which recipe supplies the virtual target.

Put the board settings in conf/machine/sensornode.conf. For the Poky reference machine beaglebone-yocto, you can start with require conf/machine/beaglebone-yocto.conf. Review the inherited settings and machine overrides. If the baseline uses settings qualified with :beaglebone-yocto that your derivative needs, preserve that override explicitly and keep sensornode available for your own board settings. Check the inherited kernel and bootloader providers, the board DTB, the U-Boot configuration, and the Wic settings before changing any of them. Set MACHINE = "sensornode" in the build's conf/local.conf.

bash
bitbake-layers show-appends
bitbake -e virtual/kernel
bitbake -e virtual/bootloader

In show-appends, find both of your append files under the expected base recipes. In each environment dump, inspect PN to confirm the selected recipe name and use the variable history above a setting to see which metadata supplied it. A visible kernel append can belong to a different recipe from the one selected by virtual/kernel. Check the provider and the append together before spending time on a build.

Enable and check the BSPCreatelayerAdd toBBLAYERSSelectMACHINECheckappendsCheckprovidersCreatelayerAdd toBBLAYERSSelectMACHINECheckappendsCheckproviders
From registering the layer to checking the selected recipes
02

Develop and verify the kernel and U-Boot

4 min read

Use devtool when you need to edit source and build it under the same recipe that supplies your image. Take the two recipe names from PN. The commands below read those names for the current machine. Run them with the regular providers selected and before creating workspace entries.

bash
kernel_recipe=$(bitbake -e virtual/kernel | sed -n 's/^PN="\([^"]*\)"$/\1/p')
bootloader_recipe=$(bitbake -e virtual/bootloader | sed -n 's/^PN="\([^"]*\)"$/\1/p')

devtool modify "$kernel_recipe"
devtool modify "$bootloader_recipe"
devtool status

devtool modify prepares the recipe's source with its patches applied and adds workspace metadata that points BitBake to the editable tree. devtool status shows where to edit. For example, change a tracked board defconfig or a source file there, then run devtool build with the corresponding recipe name. Recipe-owned defconfigs and fragments listed in SRC_URI can live in the layer rather than in the upstream Git repository. Check the existing append and keep edits to those inputs with the metadata that supplies them.

bash
devtool build "$kernel_recipe"
devtool build "$bootloader_recipe"

bitbake -e "$kernel_recipe" | sed -n '/^B=/p'
bitbake -e "$bootloader_recipe" | sed -n '/^B=/p'

B is the build directory. After configuration, copy the kernel's effective .config out of that directory before another configure run or workspace cleanup. For U-Boot, locate .config in the configured output directory under B, or directly in B if the recipe builds there. Recipes that build several U-Boot configurations can produce several .config files. Inspect log.do_configure under the recipe's T directory for the selected defconfig and output directory, and save the configuration corresponding to the bootloader binary you intend to deploy.

Compare the effective kernel .config with the requested settings from the custom defconfig and each fragment. A requested CONFIG_ value can change during Kconfig resolution when dependencies, defaults or another fragment affect it. For a recipe that supports the kernel_configcheck task, bitbake -c kernel_configcheck virtual/kernel provides an additional check on configuration requests. Keep the full .config as evidence of the result. If you want a compact baseline, use the kernel's savedefconfig target in the configured build environment, then feed that baseline back through the recipe and verify the effective settings again. The saved minimal defconfig and effective .config answer different questions. The first records inputs relative to defaults. The second records what the build actually selected.

Commit upstream source edits in the workspace and carry them into the layer as recipe patches. devtool finish can export committed source changes into a destination layer and remove the workspace override. Review its output alongside your existing append. Save any separate defconfig and fragment edits in meta-sensornode as well. If you transferred the changes manually, devtool reset with the recipe name removes its workspace override. Check devtool status for both recipes before the final image build. A build that still points into the workspace can succeed with changes that nobody else can reproduce from the layer.

Develop and verify recipe changesdevtoolmodifydevtoolbuildSaveeffectiveconfigSave layerchangesRemoveworkspaceoverridesRebuildimagedevtoolmodifydevtoolbuildSaveeffectiveconfigSave layerchangesRemoveworkspaceoverridesRebuildimage
Build in the devtool workspace and verify the saved recipe changes with the workspace overrides removed
Going deeperExplore the mechanism

For a Git-backed kernel or U-Boot recipe, pin SRCREV to the full commit ID for the source you tested. If the recipe fetches several named repositories, pin the revision for each named source. A branch selects the line of development and can advance over time. A pinned commit selects the source content. In older metadata, ${SRCPV} was used in PV to include fetcher-derived source revision information in the version string. SRCPV is deprecated in modern Yocto metadata. When following an older recipe, read it as version information. The fetcher's source selection comes from SRCREV.

Prefer the recipe's existing variables and configuration inputs when changing how it configures or builds. If you need an extra operation before or after an existing shell task, use a narrowly scoped extension such as do_configure:append:sensornode() or do_compile:prepend:sensornode(). Check that its inputs are declared and that it can run again after an interrupted build. If you must replace a task, inspect the original implementation and preserve the behavior the recipe relies on, including cross-toolchain arguments, source and output directories, configuration variants and files consumed by later tasks. Check the task logs with the workspace override removed. Changing a file directly under the temporary work directory gives the task no tracked input from which to recreate that change.

03

Build the Wic image and verify the boot

5 min read

A contains the filesystem data and partition table for the target medium. The .wks file declares each partition and how Wic populates it. For the lab, begin with the known-good BeagleBone Black layout. If you copy that file into meta-sensornode/wic/, give it a distinct name and select it with WKS_FILE in the machine configuration. Inspect WKS_FILE and WKS_FULL_PATH in bitbake -e core-image-minimal to verify which file BitBake found.

In the layout used here, the first partition is the bootable FAT filesystem, populated by --source bootimg-partition. A Linux root filesystem partition uses --source rootfs to receive the root filesystem assembled by the image recipe. Read the actual .wks directives to see the partition table type, filesystem types, alignment and boot flag. The Poky reference file meta-yocto-bsp/wic/beaglebone-yocto.wks (scarthgap branch) has these directives:

text
part /boot --source bootimg-partition --ondisk mmcblk0 --fstype=vfat --label boot --active --align 4 --fixed-size 32 --sourceparams="loader=u-boot" --use-uuid
part / --source rootfs --ondisk mmcblk0 --fstype=ext4 --label root --align 4 --use-uuid
bootloader --append="console=ttyS0,115200"

The boot partition is FAT, 32 MB, and carries the --active flag; the root partition is ext4 and both are referenced by UUID. Preserve the baseline's placement and flags. A filesystem that mounts correctly on Ubuntu can still have a layout that fails the board's ROM boot requirements.

IMAGE_BOOT_FILES tells bootimg-partition which files to take from DEPLOY_DIR_IMAGE. Entries are space-separated. An entry such as source;destination copies a deployed file under the specified destination name or path inside the boot filesystem. Without a destination, the file keeps its basename. The copy list works with this Wic source plugin. Check the plugin named by the .wks file before assuming the same variable applies to another board or layout.

For the BeagleBone Black FAT boot path in this lab, SPL lands at the boot filesystem root as MLO. Full U-Boot lands there as u-boot.img for SPL to load. The Linux zImage and the BeagleBone Black DTB, am335x-boneblack.dtb, also go on the FAT partition in this layout. Their destination paths must match the paths U-Boot uses. Keep any baseline boot script or configuration that selects those paths and passes the root device to Linux. Check the source side of every copy entry against the actual deploy filenames. If a different board uses a raw bootloader location, that location needs an explicit image layout rule, such as a Wic rawcopy entry when appropriate for that BSP.

BeagleBone Black Wic layoutWic disk imageFAT boot partitionMLOSPLu-boot.imgfull U-BootzImageLinux kernelBoard DTBam335x-boneblack.dtbRoot filesystem partitionLinux userspace and filesWic disk imageFAT boot partitionMLOSPLu-boot.imgfull U-BootzImageLinux kernelBoard DTBam335x-boneblack.dtbRoot filesystem partitionLinux userspace and files
The BeagleBone Black FAT boot files and Linux root filesystem in the Wic image

If the image's effective IMAGE_FSTYPES already includes wic, build it as it stands. Otherwise add IMAGE_FSTYPES += "wic" in conf/local.conf for this lab. Check that the image depends on the deployment tasks that supply its boot files. If a custom producer's deploy task is missing from the dependency graph, declare the dependency in metadata so it runs before Wic. A binary left over in the deploy directory can conceal a missing dependency during a rebuild.

bash
bitbake core-image-minimal

Read DEPLOY_DIR_IMAGE from bitbake -e core-image-minimal. With the default build directories it is under tmp/deploy/images/sensornode/. Select the uncompressed .wic generated for the current build. Use wic ls with the image path to list its partitions, then use wic ls with the image path followed by :1 to list the first partition. Compare the listing with IMAGE_BOOT_FILES and the paths in the boot configuration. Also compare the root partition in the image with the root device or identifier the boot configuration passes to Linux.

Flash from an Ubuntu environment that can see the SD reader as a block device. If WSL2 or the VM cannot see the reader, use an Ubuntu host or pass the reader through to the VM. Run lsblk -o NAME,SIZE,MODEL,TYPE,MOUNTPOINTS before and after inserting the card to identify it. Confirm the whole-device path and unmount any mounted filesystems from that card. In the following example, set image to the full path of the .wic file and card to the verified whole-card device path before running the command. dd overwrites the destination beginning at the start of the device.

bash
sudo dd if="$image" of="$card" bs=4M conv=fsync status=progress

Boot the BeagleBone Black from the microSD card using the board's boot selection procedure, with the serial console connected before power-on. Record the SPL and U-Boot messages, the kernel startup and the userspace prompt. At the prompt, use cat /proc/cmdline to see the boot arguments and findmnt / to check the mounted root filesystem. Confirm that the root is on the flashed card, since the board can also boot from onboard eMMC. If the console stops before U-Boot, compare the card's boot layout and loaders with the baseline. If Linux starts and cannot mount root, check the root identifier and whether the required storage and filesystem support are built in for this boot path.

The next lesson, “The distro layer and its features,” explains where to set distribution-wide policy once the machine can boot an image from its own BSP layer.

Key takeaways

  • Adding a layer registers its metadata, while MACHINE selects the board configuration.
  • The effective .config records Kconfig's resolved settings after defaults, dependencies and fragments have been applied.
  • A Wic kickstart file defines the disk layout, and the bootimg-partition plugin uses IMAGE_BOOT_FILES to populate the boot filesystem.
  • A build with the devtool workspace overrides removed verifies that the saved BSP metadata supplies the changes.
Reflect
  1. Explain to a colleague, in two sentences: create and enable a BSP layer and verify that BitBake applies its recipe appends.
  2. Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
  3. What surprised you when you ran the commands yourself?
On a real board

Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.

References and further reading

Find your next step

↑ ↓ to move · Enter to open · Esc to close