Skip to content
systemcoding.dev
Embedded Linux

Modify a Recipe's Source Tree With devtool modify

Extract a recipe's source into a Git tree with devtool modify on Yocto 5.0, edit and rebuild it, then turn your commits into patches with devtool finish.

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.

The old way to patch a package in Yocto is slow and easy to get wrong. You run bitbake -c unpack, copy the source somewhere, edit it, produce a diff by hand, write the patch into a layer, add it to SRC_URI, and rebuild to find out whether the patch applies. devtool modify replaces that loop with a Git repository you can edit directly. It extracts the recipe's source, applies its existing patches as commits, builds from the working tree, and at the end turns your new commits into patch files in the right layer. This post walks the whole cycle on Yocto Project 5.0 (Scarthgap) with a small recipe, nano, and shows what devtool writes where. It assumes you have a working build directory and have read the earlier posts on images in this cluster.

What devtool modify sets up

According to the Yocto reference for devtool, devtool modify extracts the source for a recipe, sets it up as a Git repository if it was not fetched from Git, checks out a development branch, and applies the recipe's patches as commits on top. The default branch is named devtool. The recipe itself stays in its original layer. What devtool adds is a workspace layer inside your build directory, holding the extracted source and a .bbappend that redirects the recipe's build to that tree.

That arrangement is the whole trick. While the recipe is in the workspace, BitBake builds from your working directory instead of fetching and unpacking the upstream tarball, so a rebuild after an edit only recompiles what changed.

Extract the source

Start from a sourced build environment:

Shell
devtool modify nano
Text
NOTE: Starting bitbake server...
NOTE: Creating workspace layer in /home/dev/poky/build/workspace
Parsing recipes: 100% |#########################################| Time: 0:00:41
Parsing of 912 .bb files complete (0 cached, 912 parsed). 1856 targets, 71 skipped, 0 masked, 0 errors.
NOTE: Fetching nano...
NOTE: Unpacking...
NOTE: Patching...
INFO: Recipe nano now set up to build from /home/dev/poky/build/workspace/sources/nano

Counts and timing vary by checkout. The last line is the one to read: it names the source tree. Check the workspace state at any time with devtool status:

Shell
devtool status
Text
nano: /home/dev/poky/build/workspace/sources/nano (/home/dev/poky/meta/recipes-support/nano/nano_7.2.bb)

Each line names the recipe, its source tree, and the recipe file in its original layer. The source directory is an ordinary Git repository:

Shell
cd workspace/sources/nano
git branch
git log --oneline -3
Text
* devtool
  master
a1b2c3d Commit of local file(s) removed for nano
4f5e6d7 nano: example commit
8c9d0e1 Upstream baseline

The exact messages and hashes depend on the recipe's patches. If a recipe has none, you only see the baseline commit. The branch is devtool, the one the manual names.

Edit, build and test

Make the change in the tree like any other source edit. For a demonstration, change the version banner string, then commit it, because only committed changes become patches:

Shell
cd ~/poky/build/workspace/sources/nano
sed -i 's/GNU nano/GNU nano (lab build)/' src/nano.c
git add src/nano.c
git commit -m "nano: mark lab builds in the version banner"

Building through devtool rebuilds only this recipe from the workspace source:

Shell
devtool build nano
Text
NOTE: Starting bitbake server...
NOTE: nano: compiling from external source tree /home/dev/poky/build/workspace/sources/nano
NOTE: Tasks Summary: Attempted 724 tasks of which 718 didn't need to be rerun and all succeeded.

The line about compiling from an external source tree confirms that the append file is in effect. If it is missing, the recipe is being built from the upstream tarball and your edit is not in play.

To get the result onto a device, the next post covers devtool deploy-target. To bake it into an image instead, devtool build-image <image> rebuilds an image with the workspace recipe's packages.

Turn the commits into patches

When the change is right, devtool finish writes it into a layer and retires the workspace entry. The manual states the effect: it creates patches corresponding to commits in the local Git repository, moves a new recipe to the layer you name if the recipe was new, and resets the workspace so the recipe builds normally again. Run it from the build directory with the name of the recipe and the target layer:

Shell
devtool finish nano ~/poky/meta-mine
Text
INFO: Updating patch 0001-nano-mark-lab-builds-in-the-version-banner.patch
INFO: Adding new patch 0001-nano-mark-lab-builds-in-the-version-banner.patch
INFO: Updating recipe nano_7.2.bbappend
INFO: Preserving source tree in /home/dev/poky/build/workspace/sources/nano

Since nano came from a layer other than meta-mine, devtool finish created a .bbappend in your layer that adds the patch to SRC_URI rather than editing the original recipe. That is almost always the right result. The patch file sits in a directory named after the recipe next to the append file, and the append lists it:

meta-mine/recipes-support/nano/nano_%.bbappendbitbake
FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"

SRC_URI += "file://0001-nano-mark-lab-builds-in-the-version-banner.patch"

The generated name for the append file may be version-specific, such as nano_7.2.bbappend, depending on how the command was told to write it. Either works as long as it matches the recipe version you build.

Back out without finishing

If the experiment is a dead end, devtool reset removes the recipe from the workspace and the append that redirects the build:

Shell
devtool reset nano
Text
NOTE: Cleaning sysroot for recipe nano...
NOTE: Leaving source tree /home/dev/poky/build/workspace/sources/nano as-is; if you no longer need it then please delete it manually

The source tree is preserved, so nothing you wrote is lost, and you can delete it by hand when you are certain. The manual warns that if devtool reset finds that the recipe or append was changed, it moves them to an attic directory in the workspace instead of deleting them.

Two mistakes that cost an afternoon

The first is editing without committing. devtool finish and devtool update-recipe only turn commits into patches, so an edit left in the working tree builds fine, tests fine, and then vanishes from the layer. Run git status in the source tree before you finish, and treat a dirty tree as a reason to stop.

The second is forgetting that the workspace is global to the build directory. While nano is in the workspace, every image you build from that directory uses your modified source, including images unrelated to your work. If a colleague asks why their build contains your banner, devtool status explains it. Finish or reset the recipe when you are done.

If you want the patch without closing the workspace entry, devtool update-recipe nano -a ~/poky/meta-mine writes the patch and the append file into your layer and leaves the tree in place for more work. The manual describes the -a option as the way to apply customizations in your own layer rather than the original recipe.

Use an existing checkout

You are not limited to the default location. If the source is already a Git checkout, point devtool modify at it with the -n option so it does not extract anything new:

Shell
devtool modify -n nano ~/src/nano
Text
INFO: Recipe nano now set up to build from /home/dev/src/nano

The manual's caveat applies: if an oe-local-files directory does not exist and you run devtool finish, non-patch files that sit next to the recipe are treated as deleted. Keep that directory around when you reuse a tree.

When devtool modify is not the right tool

It works best for recipes that fetch a source archive or a Git repository and build it in place. A recipe whose build generates much of its source, or one that rewrites files in do_unpack, can surprise you because the workspace tree skips those steps. A change to the recipe's build flags, rather than the source, is an edit to the recipe or a .bbappend. And a one-line change that you want everyone to review is often easier as a Git patch against upstream, sent to the project.

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.