Everyday Yocto Development
Applies to: i.MX
This page collects the Yocto tasks that come up once you have your own
layer: running single bitbake tasks, finding out where a variable is set,
changing the kernel configuration and device tree, building your own
product image, and upgrading a recipe. It continues from
Developing Applications and Kernel Modules, which creates the layer meta-mylayer
and the hello-cmake recipe used here.
The examples are from a cargt-imx-xwayland build for
imx93-cargt-00363-00428 (wrynose). Commands run in the build
directory, after source setup-environment <build_dir> (see
Yocto Development).
Running Single Tasks
A recipe is built by a chain of tasks: fetch, unpack, patch, configure,
compile, install, package and so on. bitbake -c <task> <recipe> runs
one of them, together with the tasks it depends on. listtasks shows
them all:
$ bitbake -c listtasks hello-cmake
...
do_build Default task for a recipe - depends on all other normal tasks required to 'build' a recipe
do_clean Removes all output files for a target
do_cleanall Removes all output files, shared state cache, and downloaded source files for a target
do_cleansstate Removes all output files and shared state cache for a target
do_compile Compiles the source in the compilation directory
do_configure Configures the source by enabling and disabling any build-time and configuration options for the software being built
do_devshell Starts a shell with the environment set up for development/debugging
do_fetch Fetches the source code
do_install Copies files from the compilation directory to a holding area
...
do_patch Locates patch files and applies them to the source code
...
do_unpack Unpacks the source code into a working directory
bitbake -c compile -f <recipe> forces a task to run again even if
bitbake thinks it is up to date. bitbake -c devshell <recipe> opens a
shell in the recipe’s source directory with the cross-compiler set up,
which is useful to try a command by hand.
clean, cleansstate and cleanall
Bitbake keeps the result of every task in the shared state cache (sstate), and restores it instead of running the task again when nothing has changed. The three clean tasks remove different amounts:
Task |
Removes |
|---|---|
|
The recipe’s work directory and its output in the build directory. The next build restores it from sstate. |
|
The same, and the recipe’s sstate. The next build runs every task again. |
|
The same, and the downloaded source. The next build fetches it again. |
After clean, the next build restores everything from sstate and
nothing is compiled:
$ bitbake -c clean hello-cmake
$ bitbake hello-cmake
...
Sstate summary: Wanted 125 Local 125 Mirrors 0 Missed 0 Current 295 (100% match, 100% complete)
...
NOTE: recipe hello-cmake-1.0-r0: task do_populate_sysroot_setscene: Succeeded
After cleansstate, its tasks are missing from the cache, and it is
compiled again:
$ bitbake -c cleansstate hello-cmake
$ bitbake hello-cmake
...
Sstate summary: Wanted 125 Local 114 Mirrors 0 Missed 11 Current 295 (91% match, 97% complete)
...
NOTE: recipe hello-cmake-1.0-r0: task do_compile: Started
NOTE: recipe hello-cmake-1.0-r0: task do_compile: Succeeded
Use clean when a build directory is in a bad state, and
cleansstate when you suspect the cached result itself. If several
build directories share one sstate directory, cleansstate removes the
recipe’s cache for all of them.
Finding Out Where Things Come From
bitbake-getvar shows a variable’s value for a recipe and every place
that sets or changes it:
$ bitbake-getvar -r hello-cmake WORKDIR
#
# $WORKDIR [2 operations]
# set .../openembedded-core/meta/conf/bitbake.conf:416
# "${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS}/${PN}/${PV}"
...
WORKDIR=".../tmp/work/armv8a-poky-linux/hello-cmake/1.0"
--value prints just the value, for scripts. bitbake -e <recipe>
prints the whole environment of a recipe; the source, build and install
directories are often what you need:
$ bitbake -e hello-cmake | grep -E '^(WORKDIR|S|B|D)='
B=".../tmp/work/armv8a-poky-linux/hello-cmake/1.0/build"
D=".../tmp/work/armv8a-poky-linux/hello-cmake/1.0/image"
S=".../tmp/work/armv8a-poky-linux/hello-cmake/1.0/sources"
WORKDIR=".../tmp/work/armv8a-poky-linux/hello-cmake/1.0"
bitbake-layers answers questions about layers. show-appends lists
the .bbappend files that change a recipe, which shows whether yours is
picked up:
$ bitbake-layers show-appends linux-imx
...
linux-imx_6.18.bb:
.../meta-mylayer/recipes-kernel/linux-pwm/linux-imx_%.bbappend
.../meta-mylayer/recipes-kernel/linux/linux-imx_%.bbappend
...
bitbake-layers show-recipes <recipe> lists every layer that provides a
recipe and its version, and show-layers lists the layers with their
priorities.
Choosing How to Change the Kernel
Start with the lightest route that does the job; each route further down the table takes more work. A kernel you build yourself has its own release string, so modules from the Cargt package feeds do not load into it.
You need |
Lightest route |
See |
|---|---|---|
A driver that the Cargt kernel builds as a module, but your image leaves out |
Install |
|
Your own driver |
An out-of-tree module recipe ( |
Developing Applications and Kernel Modules, “A Recipe for a Kernel Module” |
Different wiring or peripherals on your carrier |
A device tree change |
|
A driver that is not enabled, a built-in option, or a kernel patch |
A configuration fragment or patch, and a full kernel rebuild |
Changing the Kernel Configuration
menuconfig opens the kernel’s configuration menu in a terminal:
bitbake -c menuconfig linux-imx
This example enables the driver for CH340 and CH341 USB serial adapters.
Press /, search for USB_SERIAL_CH341, press 1 to go to it, and
m to build it as a module:
→ Search (USB_SERIAL_CH341) → USB Serial Converter support
...
<M> USB Winchiphead CH341 Single Port Serial Driver
Exit and save. The change is only in the build directory and is lost at
the next clean. diffconfig turns it into a configuration
fragment:
$ bitbake -c diffconfig linux-imx
...
Config fragment has been dumped into:
.../tmp/work/imx93_cargt_00363_00428-poky-linux/linux-imx/6.18.20+git/fragment.cfg
$ cat .../linux-imx/6.18.20+git/fragment.cfg
CONFIG_RUSTC_VERSION=107500
CONFIG_RUSTC_LLVM_VERSION=170006
CONFIG_USB_SERIAL_CH341=m
Keep only the options you changed: the CONFIG_RUSTC_* lines come from
the Rust compiler on the build PC, not from your change. Save the fragment
in your layer, for example as
recipes-kernel/linux/files/usb-serial-ch341.cfg:
CONFIG_USB_SERIAL_CH341=m
and add it to the kernel recipe in
recipes-kernel/linux/linux-imx_%.bbappend:
FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
SRC_URI += "file://usb-serial-ch341.cfg"
Run bitbake linux-imx. The kernel’s configuration is built again with
the fragment, and the driver is packaged as
kernel-module-ch341; add that package to your image, or install it
with apt from your package repository (see Package Management on a Cargt design).
Using Hardware from Linux has another fragment, for the PCA9685 PWM driver.
Note
A kernel module only loads into the kernel it was built for. After a kernel configuration change, update the whole image, not just the module.
Changing the Device Tree
A device tree for your own carrier or display goes in your layer as a
.dts file that includes the Cargt one and changes what differs. A
linux-imx_%.bbappend copies it into the kernel source and adds it to
KERNEL_DEVICETREE. Machine Learning on the i.MX 93 NPU walks through a complete example, which
adds the i.MX 93 NPU to the imx93-cargt-00363-00428 device trees.
After bitbake linux-imx, the new .dtb is in
tmp/deploy/images/<machine>. To check that it contains your change,
decompile it with dtc (sudo apt install device-tree-compiler on
Ubuntu):
$ dtc -q -I dtb -O dts tmp/deploy/images/imx93-cargt-00363-00428/imx93-cargt-00363-00428-glt0557201280is1-npu.dtb | grep -A5 ethosu
...
ethosu {
compatible = "arm,ethosu";
fsl,cm33-proc = <0x54>;
memory-region = <0x55>;
power-domains = <0x56>;
};
Building the Kernel and U-Boot Outside BitBake
While you work on a driver or a device tree, building the kernel with
make is quicker than a full bitbake linux-imx each time. Use
BitBake for anything you ship: it applies the Cargt patches and
configuration fragments the same way every time, and it builds the
packages and update files.
The examples are for an i.MX 93 00363 on the 00365
(imx93-cargt-00363-00365, wrynose). The STM32MP2 steps are the same
with linux-stm32mp and u-boot-stm32mp.
The Kernel
Get the Cargt kernel source.
devtool modifyunpacks it intoworkspace/sources/linux-imxin your build directory, as a Git repository with each Cargt patch as a commit:devtool modify linux-imx
While the recipe is in the devtool workspace,
bitbake linux-imxand image builds use this source too, so your changes go into the next image.devtool finishturns your commits into patches in your layer when you are done (see Upgrading a Recipe).Use the cross-compiler from your Yocto build. It is the one BitBake builds the kernel with. From the build directory:
export PATH=$PWD/tmp/work/imx93_cargt_00363_00365-poky-linux/linux-imx/6.18.20+git/recipe-sysroot-native/usr/bin/aarch64-poky-linux:$PATH
On a PC without the Yocto build, an SDK built with
bitbake cargt-image-dev -c populate_sdkhas the same compiler.Start from the Cargt configuration. The
.configfrom your lastbitbake linux-imxalready has the Cargt fragments in it. Build into a separate output directory, so the source tree stays clean:mkdir -p ~/kernel-out cp tmp/work/imx93_cargt_00363_00365-poky-linux/linux-imx/6.18.20+git/build/.config ~/kernel-out/ cd workspace/sources/linux-imx make O=~/kernel-out ARCH=arm64 CROSS_COMPILE=aarch64-poky-linux- olddefconfig make O=~/kernel-out ARCH=arm64 CROSS_COMPILE=aarch64-poky-linux- -j$(nproc) Image dtbs modules
The first build, with all the modules, took about 11 minutes on a 16-core PC. After a change,
makebuilds only what changed. Leave outmoduleswhen you only change built-in code or a device tree.The kernel is
~/kernel-out/arch/arm64/boot/Image, and the Cargt device trees are in~/kernel-out/arch/arm64/boot/dts/freescale.Try it on a board. The kernel and the device trees are files in
/booton the root file system, so a test kernel can be copied over the published one. Keep a copy of the original first:ssh root@<board-ip> cp /boot/Image /boot/Image.orig scp ~/kernel-out/arch/arm64/boot/Image root@<board-ip>:/boot/ scp ~/kernel-out/arch/arm64/boot/dts/freescale/imx93-cargt-00363-00365.dtb root@<board-ip>:/boot/
Your kernel has its own release string (
uname -r), so it does not load the modules in the image. If you need modules, install them into a directory withmake O=~/kernel-out ARCH=arm64 INSTALL_MOD_PATH=~/kernel-mods modules_installand copy~/kernel-mods/lib/modules/<release>to/lib/moduleson the board.If the new kernel doesn’t boot, stop at the U-Boot prompt (see The U-Boot Command Line) and boot the original once, without saving anything:
setenv image boot/Image.orig boot
The next software update replaces all of these files.
U-Boot
On i.MX, U-Boot alone does not boot. imx-mkimage packs it into
imx-boot with the SPL, the DDR training firmware and Arm Trusted
Firmware, plus the EdgeLock Enclave firmware on the i.MX 9 SoCs and the
OEI and System Manager on the i.MX 95 (see Secure Boot (AHAB) on i.MX 9). Let BitBake do the packing, and use devtool for
the source:
devtool modify u-boot-imx
# edit workspace/sources/u-boot-imx
bitbake imx-boot
The new boot image is tmp/deploy/images/<machine>/imx-boot.tagged.
Run it from RAM over USB without writing anything, with uuu
imx-boot, or write only the boot loader with uuu -b emmc
imx-boot.tagged; see “Other UUU options” in Getting Started.
On the i.MX 95, use the uuu script there instead.
On STM32MP2, U-Boot is packed into the FIP with TF-A and OP-TEE; see
“How STM32MP2 Boards Boot” in The U-Boot Command Line. Use devtool modify u-boot-stm32mp and
rebuild the FIP with BitBake in the same way.
Building Your Own Image
The Cargt images are a good starting point for a product image. Keep the
new image recipe in your layer, for example
recipes-images/images/my-product-image.bb. This one starts from
cargt-image-core, adds your programs, and removes the development
features, such as the empty root password and the compilers and debuggers:
SUMMARY = "Example product image: cargt-image-core with our programs and without the development features"
require recipes-cargt/images/cargt-image-core.bb
# The Cargt image sets its own name; use this recipe's name for the output files
export IMAGE_BASENAME = "${PN}"
IMAGE_INSTALL:append = " hello-cmake evtest"
IMAGE_FEATURES:remove = " \
allow-empty-password \
allow-root-login \
empty-root-password \
serial-autologin-root \
tools-sdk \
tools-debug \
tools-profile \
"
Important
The Cargt image recipes set IMAGE_BASENAME. Without the line
that sets it to ${PN}, your image’s files are named
cargt-image-core-... and overwrite the real cargt-image-core
in the deploy directory.
Build it with bitbake my-product-image. The files are in
tmp/deploy/images/<machine> as my-product-image-<machine>.rootfs.*,
and the .manifest lists every package in the image:
$ M=tmp/deploy/images/imx93-cargt-00363-00428/my-product-image-imx93-cargt-00363-00428.rootfs.manifest
$ grep -E '^(hello-cmake|evtest|gdb|gcc) ' $M
evtest armv8a 1.36-r0
hello-cmake armv8a 1.0-r0
$ wc -l < $M
1450
It has 1450 packages, against 2091 in cargt-image-dev, and its root
file system archive is half the size. With the empty root password and
root login removed, nobody can log in until you add a way: for example an
SSH key for root, or your own user, from your layer. Flash it like any
other image; see Getting Started.
Sizing a Production Image
cargt-image-dev is built for development, not for size. Measured on
November 8, 2026, the published i.MX cargt-image-dev images install
1.4 to 1.5 GB on scarthgap and 1.6 to 2.5 GB on wrynose, and the wrynose-rt
cargt-image-rt images 2.2 to 2.8 GB.
A few packages account for much of that. In cargt-image-dev for
imx93-cargt-00363-00428 on scarthgap, on the same date:
Package |
Installed |
What it is |
|---|---|---|
|
358 MB |
Teleport remote access, a single package |
|
169 MB |
Compilers and build tools for building on the board |
|
99 MB |
NXP’s i.MX security packages |
|
91 MB |
Kernel source for building modules on the board |
GStreamer |
80 MB |
GStreamer and its plugins ( |
cargt-image-core, which the example above starts from, has no
teleport, kernel-devsrc or GStreamer packagegroup, and the
example’s IMAGE_FEATURES:remove drops tools-sdk, which installs
packagegroup-core-sdk. It still has packagegroup-imx-security;
leave it out if your product does not use it. Check your image’s
.manifest for the rest.
Using the Cargt Layer in Your Own Yocto Setup
The simplest way to build a product is to keep the Cargt setup: add your
layer next to meta-imx-cargt and build with a Cargt DISTRO and
MACHINE (see Yocto Development). If you move the Cargt machines into your own
setup instead, for example with your own DISTRO or starting from NXP’s
images, keep the pieces below. The board still boots without most of them,
but parts of these docs stop applying, and some faults only show up later.
These are from meta-imx-cargt (wrynose). For STM32MP2, the same
pieces are in meta-st-cargt and meta-cargt-stm32mp-addons.
Keep |
Why |
|---|---|
The Cargt |
The boot loader reads the SOM’s EEPROM to pick the DDR timing for the SOM variant, and sets up the board’s USB-C ports. NXP’s U-Boot doesn’t know the Cargt boards. See Identifying Your SOM and Choosing the MACHINE. |
The Cargt kernel device trees and kernel configuration fragments
( |
The device trees describe the carrier. The fragments turn on the drivers the boards need, such as the display panels and the RTCs. |
|
The Cargt distros set both. The Cargt images only install
NetworkManager and |
|
The |
|
They load the Wi-Fi driver first and the Bluetooth driver only once
Wi-Fi is up. If Bluetooth starts first, it loads its own firmware
and every board reports the same placeholder address,
|
|
|
|
The per-machine |
|
Writes |
The package feed settings in |
Each SoC gets its own package architecture, so machines with
different |
To see everything else a Cargt image installs, compare your image’s
.manifest with cargt-image-core’s; see Building Your Own Image.
Upgrading a Recipe
devtool latest-version compares a recipe with the newest upstream
release, and devtool check-upgrade-status <recipe> ... does it for
several at once:
$ devtool latest-version socat
...
INFO: Current version: 1.8.1.1
INFO: Latest version: 1.8.1.3
devtool upgrade fetches the new version into the workspace, re-applies
the recipe’s patches, and writes a recipe for it:
$ devtool upgrade socat -V 1.8.1.3
...
INFO: Fetching http://www.dest-unreach.org/socat/download/socat-1.8.1.3.tar.bz2...
INFO: Upgraded source extracted to .../workspace/sources/socat
INFO: New recipe is .../workspace/recipes/socat/socat_1.8.1.3.bb
$ devtool build socat
When it builds and works, devtool finish moves the new recipe and its
patches into your layer. The original recipe stays in its own layer, and
bitbake now uses the newer version from yours:
$ devtool finish socat ../sources/meta-mylayer
INFO: Updating patch 0001-fix-compile-procan.c-failed.patch
INFO: Moving recipe file to .../meta-mylayer/recipes-connectivity/socat
INFO: Preserving source tree in .../workspace/attic/sources/socat.20261103151309
$ bitbake-layers show-recipes socat
...
socat:
meta-mylayer 1.8.1.3
meta 1.8.1.1
Note
devtool finish refuses with Source tree is not clean if the
build changed files in the source tree. Recipes that use autotools
regenerate configure and similar files there. Discard those changes
before finishing:
cd workspace/sources/socat
git status --short # shows the regenerated files
git restore configure install-sh
git clean -fd