Back to Articles

AI Assisted Development · #3 of 6

A Working Yocto Project Isn't Necessarily a Good Yocto Project

Why a successful Yocto build is not necessarily a good engineering solution, and how project organisation, ownership and simplicity reduce technical debt.

An engineer compares a complicated machine with a simpler solution that meets the same requirements.

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

One of the reasons I started investigating the use of AI with Yocto was that I had encountered working implementations that were considerably more complicated than they needed to be. The problem wasn’t that they didn’t work. The problem was understanding why they worked the way they did and how much effort would be required to maintain them.

In the previous article, I looked at how AI could help us create Yocto recipes. We saw that it could save a considerable amount of time when dealing with complicated software, but we also saw an example of it introducing a patch that wasn’t necessary to achieve a successful build.

An unnecessary patch in a recipe is relatively easy to deal with. An unnecessary architectural mechanism that has become an integral part of a product is a rather different proposition.

Complexity breeds complexity

AI makes it remarkably easy to implement a complicated solution. Unfortunately, that isn’t the same as making it easy to implement a good solution.

Imagine that we ask an AI to solve a particular configuration problem. It produces a solution that works, but introduces an unnecessary mechanism. A few weeks later, we encounter another problem, partly as a consequence of that mechanism. We ask the AI to solve that problem too. It examines the existing implementation and produces another solution that accommodates it.

Each individual change might appear perfectly reasonable. Each change might pass its tests. However, over time, we can end up with a system whose complexity bears very little relationship to the original requirements.

What concerns me is that AI significantly reduces the effort required to create this complexity. Previously, the amount of work involved in implementing a complicated solution might have encouraged an engineer to look for a simpler alternative. That incentive is considerably reduced when an AI can implement the complicated solution in a matter of minutes.

Sometimes the best way to solve a problem is to remove the reason the problem exists in the first place.

This is particularly relevant to Yocto because it already provides mechanisms for solving a huge range of configuration and integration problems. Before introducing another Python function, custom BitBake task or configuration script, it is worth asking whether Yocto already provides a mechanism for achieving the same thing.

Of course, you need sufficient knowledge of Yocto to recognise when this is happening. If your only measure of success is whether BitBake completes without errors, you may never realise that you have introduced a problem.

The build has succeeded. The technical debt has just increased.

This is where I think we need to change the way we use AI. Rather than simply asking it to solve the next problem, we should also be using it to challenge the implementation we already have. Is this mechanism necessary? Are we duplicating functionality that already exists? Would changing the architecture remove the need for this workaround?

AI can be just as useful in helping us remove complexity as it is in helping us create it. We just need to ask it to do so.

How complexity can accumulate despite successful builds

Creating the foundations of a Yocto project

Having experimented with recipe creation, I wanted to see how well AI could establish a complete Yocto project from scratch.

I gave Codex two tasks. Both were to create a project using Yocto 6.1 (Blacksail), targeting qemux86-64 and building core-image-minimal using the Poky distribution. The difference was that the first was to use kas and the second was to use bitbake-setup and configuration fragments.

Both took approximately two minutes and 49 seconds to produce their configurations. I must admit that I wasn’t watching the clock particularly closely during the kas experiment, so I wouldn’t read anything into the relative timings.

What was more interesting was the quality of the results.

kasbitbake-setup
Upstream repositoriesExplicitly pinnedExplicitly pinned
Machine selectionYAML configurationProject configuration fragment
Distribution selectionYAML configurationUpstream configuration fragment
DocumentationProvidedProvided
Upgrade instructionsProvidedProvided

Both implementations used identical revisions of the upstream repositories. Both included instructions for establishing the build environment and upgrading to a subsequent Yocto release.

I was particularly pleased to see that the bitbake-setup implementation made use of the existing distro/poky fragment rather than unnecessarily duplicating its functionality.

There was very little to complain about.

However, if I were establishing a new Yocto project for a customer, I would do things differently.

Adequate doesn’t necessarily mean appropriate

When I establish a Yocto project, I am rarely thinking about just building an image. I am thinking about the engineers who will be working on that project, the additional hardware that might need to be supported, the software that will be integrated and the poor person who will eventually have to upgrade everything to a newer release of Yocto.

Quite often, that poor person is me!

There are engineering decisions I make almost automatically when establishing a project because I have experienced the consequences of not making them in the past.

These include establishing clear ownership of metadata, separating hardware support from distribution policy and application software, and ensuring that reusable functionality doesn’t become unnecessarily tied to a particular product.

None of these considerations was particularly relevant to building core-image-minimal for QEMU. Consequently, I hadn’t communicated them to the AI. It would therefore be unfair to criticise Codex for not taking them into account.

The experiments demonstrated that AI could produce an adequate starting point in a remarkably short period of time. What they didn’t demonstrate was that AI could independently establish the most appropriate architecture for a long-lived commercial product.

That requires a considerably greater understanding of the intended product, its development process and its expected lifetime.

This is an important distinction when using AI. We need to communicate not only what we want the system to do today, but also what we expect to do with it tomorrow.

Making ownership obvious

One of the things I encourage engineers to do when establishing a Yocto project is make it immediately obvious which metadata they own and which metadata they have downloaded from elsewhere.

The project structure I recommend looks like this:

project-name/
├── build/
├── layers/
│   ├── project-name/
│   │   ├── my-bsp/
│   │   ├── my-distro/
│   │   └── my-software/
│   └── third-party/
│       ├── meta-XXX/
│       └── meta-YYY/
└── scripts/

There is a very simple rule here. If something is under third-party, I downloaded it from somewhere else and DO NOT EDIT IT! If it is under my project directory, it is mine and I can modify it as much as I like.

Yocto already provides mechanisms for modifying the behaviour of third-party metadata without editing it directly. Use them! This makes upgrading third-party layers considerably easier and avoids the problem of having to remember what you changed six months ago and why.

It also means that when another engineer joins the project, they can immediately see where they should be making changes. I don’t need to explain the history of every layer before they can start working.

Now consider what happens when we introduce an AI coding agent into that environment. I want exactly the same rules to apply. I don’t want the AI modifying a recipe in a third-party layer simply because that happens to be the quickest way to resolve a build failure.

The directory structure is a simple way of communicating an important engineering principle to both humans and AI: what we own and what we don’t.

It is a convention I would encourage anyone developing a Yocto project to adopt, whether they are using AI or not.

Not all complexity is bad

I should make it clear that I am not suggesting that all complexity is bad. Some of the systems we develop have genuinely complicated requirements, and those requirements may necessitate complicated implementations.

There is, however, a difference between complexity that is demanded by the requirements and complexity that is introduced by the implementation.

The project structure I have just described introduces additional directories and layers. For a simple QEMU experiment, that might be unnecessary. For a commercial product, that additional structure can make the project considerably easier to maintain.

Good engineering isn’t about making everything as simple as possible regardless of the circumstances. It is about making things appropriately simple for their intended purpose.

The difficulty when using AI is that recognising the difference requires an understanding of both the technology and the requirements.

Reviewing the implementation, not just the result

When reviewing something that AI has produced, I think we need to apply exactly the same engineering principles as we would when reviewing something produced by another engineer.

A successful build is obviously important, but it is only one of the things I am interested in. I also want to understand the implementation and why particular decisions were made.

There are several questions I would encourage engineers to ask when reviewing a Yocto implementation:

  • Does Yocto already provide a mechanism for doing this?
  • Is the complexity justified by the requirements?
  • Is the functionality implemented in the appropriate layer?
  • Have we unnecessarily modified third-party metadata?
  • Could I reuse this functionality in another project?
  • What happens when I upgrade to the next release of Yocto?
  • Will another engineer understand this implementation?

These aren’t questions that are specific to AI-generated implementations. We should have been asking them long before AI came along. However, the speed at which AI can generate code and configuration makes them considerably more important.

One of the advantages of working with AI is that we can ask it to review its own implementation against these criteria. We can challenge its decisions, discuss alternative approaches and ask whether a simpler implementation is possible.

That doesn’t absolve us of the responsibility of reviewing the result, but it does give us another useful engineering tool.

Beyond the first successful build

My experiments with kas and bitbake-setup demonstrated that AI could establish the foundations of a Yocto project in a remarkably short period of time.

Would I use AI to establish my next Yocto project? Absolutely. However, I would provide it with my architectural requirements, project conventions and constraints rather than simply asking it to produce a working build.

I would also review what it produced before allowing further development to take place. Correcting a poor architectural decision at the beginning of a project is considerably easier than correcting it after two years of development.

We need to be careful that, in our enthusiasm for the productivity gains offered by AI, we don’t simply become more efficient at creating technical debt.

Getting something to work is only part of engineering. Creating something that can be understood, maintained, extended and upgraded is equally important.

AI reduces the cost of implementing complexity, but not necessarily the cost of maintaining it.

In the next article, I will take this investigation a step further. Rather than asking AI to establish a relatively simple QEMU project, I will ask it to create a Yocto project for real hardware, with both development and production requirements.

That is where some of the more interesting architectural decisions start to emerge.