Working on U-boot from Yocto (iMX8)

Posted by Marcus Folkesson on Thursday, April 11, 2024

Working on U-boot from Yocto (iMX8)

I have been asked a couple of times how to quickly make changes for U-Boot in Yocto. Those who asked have used to rebuild and flash an entire image each time, which takes an unnecessarily which is not a fast procedure.

To rebuild U-Boot is`nt significantly different from any other recipe, but one difference is that imx-mkimage must also be built to generate a bootable image.

I wrote this post because it is just easier for me to write it down and refer rather than keep repeat myself :-)

So, this is my workflow when working with U-boot for iMX8 in an Yocto environment.

Tools I use

bitbake

All working with Yocto will somehow use bitbake. No further explanation.

devtool

devtool [1] is a command line tool that provides a number of features that help you build, test and package software. It is incredible useful when working with Yocto and making changes to the software. It will let you work with the software, make changes, commit and then smoothly create patches and include them into the recipe.

kas

kas [2] is my absolute favorite tool to administrate and setup bitbake based projects.

I always use kas-container which is part of the projects. kas-container does the very same thing as kas but execute every command in a container. This is useful if you, for example, using a rolling distribution (Archlinux in my case) where the tools is not always compatible with the latest software on your system.

The following steps will assume that you use kas-container, but can easely be adapted to whatever you use.

kas-container and menuconfig

There is one thing that you must be aware of though - the Dockerfile [3] used by kas-container does not include all dependencies to run menuconfig. So if you want to make changes to the configuration file using menuconfig then you need to add them somehow.

I do always clone the repository [4] myself and add the missing dependencies (bison and flex):

 1[08:55:11]marcus@goliat:~/git/kas$ git diff
 2diff --git a/Dockerfile b/Dockerfile
 3index 0e79cb5..b5b3866 100644
 4--- a/Dockerfile
 5+++ b/Dockerfile
 6@@ -33,7 +33,7 @@ RUN apt-get update && \
 7	python3-pip python3-setuptools python3-wheel python3-yaml python3-distro python3-jsonschema \
 8	python3-newt python3-colorlog python3-kconfiglib \
 9	gosu lsb-release file vim less procps tree tar bzip2 zstd pigz lz4 unzip tmux libncurses-dev \
10-        git-lfs mercurial iproute2 ssh-client telnet curl rsync gnupg awscli sudo \
11+        git-lfs mercurial iproute2 ssh-client telnet curl rsync gnupg awscli sudo bison flex \
12	socat bash-completion && \
13 apt-get clean && \
14rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

Another thing to keep in mind; Yocto does not have a menuconfig option for U-boot. In other words, you cannot use devtool menuconfig u-boot-imx in order to open up menuconfig. You have to run make menuconfig by yourself in the working directory.

This is no problem if you run just kas though.

The workflow

Start a development shell in the container:

1kas-container shell ./my-kas-file.yml

Use devtool to create a workspace for the u-boot-imx repository:

1devtool modify u-boot-imx
2cd /build/workspace/sources/u-boot-imx

You will find the workspace in /build/workspace/sources/u-boot-imx.

Now you can make changes to the source code as you like and even commit your changes.

1#make changes to the repository
2git commit -a --signoff -m "my cool changes"

Usually you just run devtool build <package> and eventually devtool deploy <package> to test it on target. However, this does not work for u-boot (for at least iMX8) as the output needs to be run though the ìmx-mkimage tool before is is usable.

Also, devtool build-image does not work either as it will only include the newly built u-boot into the image without run it through imx-mkimage.

So, what we have to do is generate patches and add them into the recipe. devtool will help us with that:.

1devtool update-recipe u-boot-imx -a /work/layers/meta-custom

-a /work/layers/meta-custom, tells devtool to update that specific layer, otherwise it will update meta-freescale, and that is something we want to avoid.

kas-container maps the working directory to /work/, you will probably find your layers there.

The last thing we need to do is to build the imx-boot target that is provided by the imx-mkimage recipe. imx-boot will also rebuild u-boot-imx with our patches applied.

To do this we use bitbake:

1bitbake imx-boot

That is all.

The generate imx-boot image you find in build/tmp/deploy/images/<machine>/imx-boot is ready to be flashed to your hardware using the uuu [5] tool.

Summary

Working with U-boot is not more complicated to work on than anything else, but you should be aware of that you cannot use devtool as usual as the image u-boot-imx produce is not the final product that can be flashed to the hardware.

Also, there is no good ways to invoke the complete build chain with only devtool, so bitbake has to be used for that.