Back to Articles

AI Assisted Development · #2 of 6

Creating Yocto Recipes: AI, devtool or vi?

Comparing AI-assisted Yocto recipe creation with devtool and manual engineering using hmon and MQTTSuite, with lessons on verification and maintainability.

An engineer compares vi, devtool and Codex for creating Yocto recipes.

Part 2 of the series: Can AI Make a Yocto Engineer’s Life Easier?

One of the things that makes me slightly uncomfortable about some of the demonstrations of AI-assisted software development is that they demonstrate how quickly AI can achieve something without considering how quickly we could have achieved the same thing using the tools we already have.

Yocto is a particularly good example of this. We already have some extremely useful tools for creating recipes, investigating dependencies and integrating applications into an embedded Linux system. Before getting too excited about AI’s ability to generate Yocto recipes, I wanted to establish whether it actually offered a significant advantage over those existing tools.

Of course, creating a recipe isn’t necessarily a particularly complicated task. Sometimes the quickest way of creating a Yocto recipe is just to open vi and write the bloody recipe!

However, there are also occasions when what initially appears to be a relatively straightforward application turns into several hours of investigating dependencies, understanding somebody else’s build system and working out why an application that builds perfectly happily on a desktop Linux system doesn’t want to cross-compile.

These are two very different engineering problems, and I wanted to investigate how useful AI was in both situations.

Designing the experiments

I selected two applications of considerably different complexity. The first was hmon, a relatively straightforward terminal-based system resource monitor. The second was MQTTSuite, a collection of MQTT applications that depends on the SNode.C networking framework. I chose this deliberately as a more complex example with dependencies that didn’t have a recipe either.

For both experiments, I used the existing Yocto environment that I had developed as part of my project to repurpose a 2017 MacBook Pro. This provided me with a working Yocto project based on Wrynose (Yocto 6.0), with an existing machine configuration, distribution and collection of layers.

I wasn’t intending to install either application on the MacBook. The project simply provided a suitable environment in which to conduct the experiments. Consequently, the objective was to create standalone recipes that built successfully and passed package QA, rather than to demonstrate the applications running on the target.

For each application, I compared a conventional approach using devtool with an approach in which I delegated the task to Codex.

I also wanted to consider more than just the amount of time required to achieve a successful build. What did the resulting recipes look like? Had any unnecessary complexity been introduced? Were the solutions maintainable? Had the AI made architectural decisions that I would have made differently?

These are practical engineering experiments rather than a statistically rigorous benchmark, but they provide some interesting insights into where AI can be useful.

Experiment 1 — hmon

I selected hmon because it represents the sort of application that we regularly encounter when working with Yocto. It is a relatively small application that uses CMake and depends on ncurses.

There is nothing particularly unusual about its build requirements, and I would expect Yocto’s existing recipe creation tools to make a reasonably good job of generating a recipe for it.

Using devtool

The conventional approach was straightforward. I used devtool to generate the recipe, built the application and produced a standalone recipe that could be included in my layer.

Once we remove the automatically generated comments and an empty EXTRA_OECMAKE assignment, the resulting recipe looks like this:

LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=0a75f723315e8b66917ad5325df9b13a"

SRC_URI = "git://github.com/sdk445/hmon.git;protocol=https;branch=main"

PV = "1.0+git"
SRCREV = "0e409d4d4f3e81a8c811194663a9d8abdf8f00b2"

DEPENDS = "ncurses"

inherit cmake

There isn’t a great deal to explain here. We identify the licence, specify where the source code comes from, pin the source revision, identify the build dependency and inherit the appropriate build class.

This is exactly the sort of recipe I like to see. It is straightforward, makes use of the mechanisms that Yocto already provides and doesn’t require an engineer to spend much time understanding how the application is being built.

The entire process took 1 minute and 17 seconds.

Using Codex

I then delegated the equivalent task to Codex, allowing it to investigate the application, create the recipe and perform the necessary builds.

Codex took 3 minutes and 18 seconds to complete the task.

It produced a working recipe and, in some respects, a more complete one than the recipe generated using devtool. It included a summary, a homepage and an explicit runtime dependency on ncurses-terminfo-base. It had clearly considered some of the requirements of running a terminal-based application, rather than concentrating exclusively on getting the application to compile.

However, during its investigation, Codex encountered a build failure and introduced a patch to the upstream CMake configuration.

The original application used CMake’s Curses discovery mechanism. Codex modified this to use pkg-config to locate ncursesw, introducing the following:

find_package(PkgConfig REQUIRED)
pkg_check_modules(NCURSESW REQUIRED IMPORTED_TARGET ncursesw)

It then modified the application’s linking configuration to use the imported target:

target_link_libraries(hmon PRIVATE PkgConfig::NCURSESW)

There is nothing inherently wrong with this approach. Using pkg-config to discover libraries and their associated compiler and linker flags is a perfectly reasonable thing to do when cross-compiling an application.

The question is whether we actually needed to do it.

Was the patch necessary?

One of the problems with reviewing AI-generated implementations is that it is very easy to look at a technically reasonable modification, accept the explanation for that modification and move on. After all, the application now builds successfully, so the modification must have fixed something.

However, having already built hmon without modifying the upstream source, I wanted to investigate whether this patch was actually necessary.

There was a slight complication in that Codex and devtool had selected different upstream source revisions. I couldn’t simply assume that because the recipe generated by devtool built successfully without a patch, the same would necessarily be true of the recipe generated by Codex.

The simplest way of establishing whether the patch was necessary was to disable it and perform a clean rebuild using the Codex recipe.

I commented out the patch in SRC_URI, removed the inheritance of the pkgconfig class and rebuilt the application.

It built successfully.

The resulting recipe, with the experimental comments removed, looks like this:

SUMMARY = "Real-time terminal system resource monitor"
HOMEPAGE = "https://github.com/sdk445/hmon"

LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=0a75f723315e8b66917ad5325df9b13a"

SRC_URI = "git://github.com/sdk445/hmon.git;protocol=https;branch=main;destsuffix=${BP}"
SRCREV = "dc7f7062c8c10fed90d64442acc0fc8c861f965f"

DEPENDS = "ncurses"

inherit cmake

RDEPENDS:${PN} += "ncurses-terminfo-base"

We now have a recipe that retains the useful additions made by Codex without introducing an unnecessary modification to the upstream application.

Why does this matter?

Some people might argue that introducing a small patch to a CMake configuration isn’t particularly significant. The application builds, the patch is relatively straightforward and we can move on to something more interesting.

However, every patch we introduce into a Yocto recipe becomes something that we potentially need to maintain. When we upgrade the application, we need to establish whether the patch still applies, whether it is still appropriate and whether changes in the upstream source have affected its behaviour.

Multiply that by the number of recipes in a substantial embedded Linux product and we can introduce a considerable amount of unnecessary maintenance work.

What concerns me isn’t that Codex introduced a patch. Engineers introduce unnecessary patches as well. What concerns me is that an engineer who is relatively new to Yocto might accept the patch, along with the perfectly plausible explanation that accompanies it, without questioning whether it is actually required.

A successful build demonstrates that the implementation works at the build level. It doesn’t demonstrate that every modification made during the investigation was necessary.

Comparing the results

MetricdevtoolCodex
Elapsed time1m 17s3m 18s
Failed build attempts01
Patches initially introduced01
Standalone recipe buildPassedPassed
Package QAPassedPassed
Target runtime testingNot performedNot performed

Codex took approximately two and a half times as long as the conventional approach, although the absolute difference was only a couple of minutes.

It also performed additional verification and produced some useful descriptive metadata. Consequently, I don’t think it would be particularly fair to simply declare devtool the winner based on the elapsed time.

However, for an application of this complexity, I’m not convinced that delegating the entire task to AI offers a particularly significant advantage. The existing Yocto tools are already extremely effective, and the resulting recipe is sufficiently straightforward that I could quite happily have written it myself.

hmon elapsed time comparison

The second experiment was rather different.

Experiment 2 — MQTTSuite

MQTTSuite is a collection of applications providing MQTT functionality, including a broker, bridge, integrator, command-line client and database store. It makes use of the SNode.C C++ networking framework, which provides a range of networking capabilities including HTTP, WebSockets, TLS and MQTT.

Unlike hmon, this wasn’t simply a case of identifying a couple of dependencies, inheriting the cmake class and building the application.

There were two recipes to create, a number of dependencies to resolve, problems with the upstream CMake configurations and some interesting packaging requirements.

This is the sort of application where the amount of time required to create a recipe is determined less by the amount of metadata that needs to be written and more by the amount of investigation that needs to be performed.

Using devtool

I started with the conventional approach, using devtool to generate the recipes and then investigating the problems that arose during the builds.

One of the limitations of automatically generating recipes is that the recipe creation tools can only work with the information they are able to extract from the application. They can identify that an application uses CMake and attempt to map its dependencies to existing Yocto recipes, but they cannot necessarily understand all of the assumptions made by the upstream developers.

The initial recipe generation is therefore often the easy bit.

In this particular case, I spent approximately three hours investigating the build problems, modifying the recipes and creating the patches necessary to integrate the applications into Yocto.

The resulting implementation consisted of two recipes and four patches.

Using Codex

I then gave Codex the task of integrating MQTTSuite and its SNode.C dependency into the same Yocto project.

Codex was able to investigate the upstream repositories, examine the existing Yocto metadata, identify dependencies, modify the build configurations and perform the necessary builds.

It completed the task in 13 minutes and 27 seconds.

The resulting implementation consisted of two recipes, three patches and an additional licence notice.

Both approaches used the same primary upstream source revisions for MQTTSuite and SNode.C, making this aspect of the comparison more consistent than the hmon experiment.

At this point, it would be very tempting to conclude that Codex had achieved a significant improvement in engineering productivity and leave it at that.

However, the more interesting question is what it actually produced.

Comparing the MQTTSuite implementations

One of the things I found particularly encouraging about this experiment was that both approaches independently identified several of the same underlying technical problems.

Managing dependencies

One of the problems with the upstream SNode.C build configuration was its use of CMake’s FetchContent mechanism to obtain spdlog.

From the perspective of an upstream application developer, this is a perfectly understandable approach. It allows the application to obtain the version of a dependency that it requires without necessarily expecting the developer to have installed it separately.

However, within Yocto, we generally want BitBake to manage our source fetching and build dependencies. We don’t want individual applications downloading additional source code during their configuration or compilation tasks.

The conventional implementation replaced the upstream mechanism with:

find_package(spdlog 1.17.0 REQUIRED CONFIG)

Codex independently implemented:

find_package(spdlog 1.17.0 CONFIG REQUIRED)

These are functionally equivalent.

Both recipes then included spdlog in their build dependencies, allowing Yocto to build the dependency and make it available within the appropriate recipe sysroot.

What I find encouraging here is that Codex didn’t simply find a way of allowing the CMake configuration to download spdlog. It identified the underlying integration problem and implemented a solution that made appropriate use of Yocto’s existing dependency management mechanisms.

Relocatable CMake configurations

Another problem concerned the CMake configuration exported by SNode.C for use by applications that depend on it.

When we build a library using Yocto, that library is built within a recipe-specific environment. Its headers, libraries and associated configuration files are subsequently made available within the sysroots of recipes that depend on it.

If the exported CMake configuration contains absolute paths referring to the original build environment, those paths may not be valid when another recipe attempts to consume the library.

Both implementations identified this problem and introduced modifications to make the installed CMake configuration relocatable.

There was also a problem with the validation of requested CMake package components. My implementation addressed this with a separate patch, whereas Codex incorporated the relevant changes into its patch dealing with the exported CMake configuration.

Codex also introduced a separate patch dealing with runtime library search paths for the MCP transport libraries.

These are considerably more interesting problems than simply determining which recipe should be added to DEPENDS. They require an understanding of the relationship between CMake, cross-compilation, installed library configuration and Yocto’s recipe-specific build environments.

The fact that Codex independently arrived at several of the same solutions that I had developed was one of the more positive results of the experiment.

It doesn’t establish that every modification made by Codex was necessary or that every aspect of its implementation was correct, but it does demonstrate its ability to investigate and resolve substantial integration problems.

Source fetching

There were also differences in how the two implementations obtained the upstream source code.

My recipes used Yocto’s Git submodule fetcher, gitsm://, allowing the submodules associated with the upstream repositories to be fetched.

Codex instead explicitly identified the JSON schema validator repository required by MQTTSuite and specified the relevant revision separately:

SRCREV_suite = "6e7b559b82b26f4757e0431148277811519e422e"
SRCREV_validator = "f032e8fb00000e22856a0c945115d7e315506e94"
SRCREV_FORMAT = "suite_validator"

Both approaches have their merits. Using the submodule fetcher allows us to follow the structure defined by the upstream project, whereas explicitly fetching the required repositories gives us greater visibility over the individual sources being obtained.

This is an example of a difference in implementation that deserves consideration but doesn’t necessarily indicate that either approach is wrong.

Packaging and runtime dependencies

There were several other differences in the resulting metadata.

Both implementations recognised that the application installed mapping plugins that needed to be packaged separately. Codex went a little further by introducing a version-matched runtime dependency between the main package and the plugin package:

RDEPENDS:${PN} += "snodec ${PN}-mapping-plugins (= ${EXTENDPKGV})"

It also recommended the installation of CA certificates:

RRECOMMENDS:${PN} += "ca-certificates"

These are useful considerations for an application that provides networking and TLS functionality.

Codex also disabled several optional SNode.C components, including applications, tests and the control TUI. My implementation explicitly disabled the tests but otherwise left more of the upstream configuration unchanged.

Consequently, although both implementations built successfully, we should not assume that they produced identical sets of binaries or identical package contents.

This is another example of an engineering decision that needs to be considered in the context of the intended product. Are we packaging SNode.C as a general-purpose networking framework, or are we packaging only the functionality required by MQTTSuite?

The answer may influence which optional components we want to build.

Licence information

Codex also performed a more detailed investigation of the licence information associated with MQTTSuite and its bundled web resources.

The two recipes contained different licence expressions and different selections of licence files. Codex additionally included a licence notice associated with the Lucide React component used by the bundled dashboards.

This is useful work, particularly given the complexity of establishing the licensing requirements of applications containing third-party libraries and bundled web assets.

However, I wouldn’t regard the more detailed licence expression generated by Codex as proof that the licensing requirements had been fully established. That would require a separate review of the upstream source, bundled components and the obligations associated with their respective licences.

As with the rest of the implementation, AI can assist with the investigation, but it doesn’t remove the engineering responsibility for reviewing the results.

Not all patches are bad

One of the more interesting differences between the two MQTTSuite implementations concerns the location of the installed web resources.

The upstream application installed these resources beneath the configured installation prefix, resulting in a location that would normally be:

/usr/var/www/mqttsuite

Codex accommodated this behaviour within its packaging configuration:

FILES:${PN} += "${prefix}/var/www/mqttsuite"

My implementation took a different approach. I modified the upstream CMake configuration and associated application code to respect configurable installation directories, allowing me to install the web resources beneath:

/var/www/mqttsuite

The corresponding packaging configuration included:

FILES:${PN} += "${localstatedir}/www/mqttsuite"

This was a deliberate architectural decision on my part, rather than a modification that was required to make the application build.

I wanted the application to respect the configured installation directories rather than accepting the location selected by the upstream implementation.

Codex, on the other hand, achieved a successful build without introducing that additional patch.

This gives us an interesting contrast with the hmon experiment. In that experiment, I removed a patch introduced by Codex because it wasn’t required. In this experiment, I introduced a patch that Codex hadn’t considered necessary.

Am I contradicting myself?

No. The difference is that the MQTTSuite patch implements a deliberate engineering requirement, whereas the hmon patch was introduced to resolve a build problem that I subsequently demonstrated could be resolved without modifying the upstream source.

The objective isn’t to have the fewest patches. It is to have the fewest patches necessary to meet our requirements.

There is also an important lesson here about communicating those requirements to AI. If I haven’t specified my requirements concerning the filesystem layout, I cannot reasonably criticise Codex for selecting a different approach.

Both implementations successfully packaged the application, but they made different decisions about how the application should be integrated into the wider system.

Comparing the results

Metricdevtool-based approachCodex
Elapsed timeApproximately 3 hours13m 27s
Recipes created22
SNode.C patches33
MQTTSuite patches10
Total patches43
Standalone recipe buildPassedPassed
Package QAPassedPassed
Target runtime testingNot performedNot performed

Codex achieved the build objective in approximately 7.5% of the time taken using the conventional approach.

That represents an elapsed time difference of approximately two hours and forty-seven minutes.

Unlike the hmon experiment, where the difference in elapsed time was relatively insignificant, this represents a potentially substantial productivity improvement.

However, there is another aspect of the comparison that I think is even more important.

MQTTSuite elapsed time comparison

Are we measuring the wrong thing?

When discussing the productivity improvements associated with AI, we tend to concentrate on the amount of time required to complete a task.

Whilst this is obviously an important consideration, elapsed time and engineering time are not necessarily the same thing.

During the approximately three hours that I spent integrating MQTTSuite using the conventional approach, I was actively involved in investigating build failures, understanding the upstream build configurations, creating patches and modifying recipes.

During the thirteen minutes and twenty-seven seconds that Codex was working on the equivalent task, I could have been doing something else.

This distinction is particularly important when you are working on a substantial Yocto project. There are frequently numerous tasks that need to be performed, and the ability to delegate one of those tasks whilst concentrating on another can be considerably more valuable than simply reducing the elapsed time associated with an individual task.

However, delegation isn’t free.

I still need to establish the requirements, communicate those requirements to Codex, review the resulting implementation and investigate anything that I don’t understand or agree with. If the implementation contains unnecessary complexity, I may also need to spend time simplifying it.

There is also the longer-term cost of maintaining the resulting metadata. Saving an hour during the initial implementation isn’t necessarily a particularly good investment if the resulting solution introduces several hours of additional maintenance work every time we upgrade the Yocto release.

I didn’t formally measure the amount of active engineering time associated with either approach, so I cannot put a precise figure on the engineering time saved during these experiments.

Nevertheless, the MQTTSuite experiment demonstrates why the ability to delegate substantial technical investigations is one of the aspects of AI-assisted development that I find particularly interesting.

A successful build isn’t the end of the investigation

There is a limitation to these experiments that I want to make particularly clear.

Neither hmon nor MQTTSuite was installed on the MacBook. I was using the MacBook project as a framework in which to investigate recipe creation, rather than developing applications that I intended to include in its final image.

Both approaches produced standalone recipes that built successfully and passed package QA. That was the objective of the experiments.

However, package QA doesn’t establish that an application functions correctly on the target. It doesn’t necessarily identify missing runtime resources, incorrect plugin loading behaviour or problems that only become apparent when an application is used in a particular configuration.

For MQTTSuite, I would still want to investigate the runtime behaviour of the applications, the loading of plugins, the availability of web resources and the functionality of the networking and TLS components before accepting either implementation into a production system.

Similarly, I would want to verify that hmon behaved correctly in the intended terminal environment.

We need to be careful when describing what AI has achieved. In these experiments, Codex successfully integrated the applications into the Yocto build environment. That is a useful achievement, but it isn’t the same as demonstrating a fully functional, production-ready application.

What did I learn?

The results of the two experiments are summarised below.

Applicationdevtool-based approachCodexFaster approach
hmon1m 17s3m 18sdevtool
MQTTSuite~3 hours13m 27sCodex

For the relatively straightforward application, Yocto’s existing recipe creation tools were extremely effective. Codex took longer and introduced a modification that I subsequently demonstrated wasn’t necessary.

For the considerably more complicated application, Codex was able to perform a substantial amount of technical investigation and independently arrive at several of the same solutions that I had developed. It achieved the build objective in a fraction of the time.

What interests me about these results is that they suggest that the greatest value of AI may not necessarily be in generating Yocto metadata. Generating the metadata is often the relatively straightforward part of the job.

The greater value may be in investigating unfamiliar build systems, understanding dependencies, identifying cross-compilation problems and developing appropriate solutions to those problems.

Those are the activities that can consume a considerable amount of engineering time.

However, the experiments also demonstrate that the ability to generate a working implementation doesn’t necessarily imply an ability to recognise the most appropriate implementation.

Codex introduced an unnecessary patch in one experiment and omitted a patch that implemented a deliberate architectural decision in the other. Neither of those decisions prevented the applications from building successfully.

It took an understanding of the technology and the intended requirements to recognise the significance of those differences.

Choosing the right tool

I don’t think these experiments demonstrate that AI is better than devtool, or that devtool is better than AI.

They demonstrate that we have different tools available to us and that those tools have different strengths.

If I’m integrating a relatively straightforward CMake application, I will probably continue to use devtool. If I’m dealing with a more complicated application that requires a substantial amount of investigation, I am increasingly likely to consider delegating some of that investigation to Codex.

There will also be occasions when I already understand the application, know which dependencies are required and know which Yocto mechanisms I need to use. In those situations, I don’t necessarily need either tool.

Part of being an engineer is knowing when to use the right tool and, sometimes, knowing when not to use a tool at all.

What I don’t want to do is introduce AI into my engineering workflow simply because AI is available. I want to introduce it where it provides a genuine benefit, whilst retaining the knowledge and judgement required to evaluate what it produces.

That brings us to a rather more significant question. If AI makes it easier to produce working Yocto implementations, how do we ensure that those implementations are actually good engineering solutions?

That’s what I’ll be investigating in the next article: A Working Yocto Project Isn’t Necessarily a Good Yocto Project.