Introducing automatic U-Boot patching

18th Dec 2017

In the rocko branch of the meta-mender layer, we have just added a new feature which allows U-Boot to be auto-configured, avoiding the need to do the tedious and difficult task of creating a manual patch for it. For now, the feature only works for devices with MMC/SD card storage, but we plan to extend support to Flash based devices later. You can read more about the new feature, as well as some of its limitations, on our documentation site.

The Yocto Project build system will attempt to use this auto-patching method automatically, but in this article we will focus on how users that don't use Yocto can use the backend parts of the feature to produce a similar patch for their build system. The core of the feature is a script which takes as input a directory containing a checkout of U-Boot source code, and then uses this to produce a patch against that tree. The tree should have all patches applied that you normally apply during a U-Boot build, and it also needs to have all Mender patches applied. You can read more about how the Mender patches are applied in the earlier blog post about non-Yocto build systems, specifically the part under "U-Boot".

After a directory containing the source code for your board has been prepared, you should also make sure that your shell environment has the correct build environment, since the script will reuse some of the components, such as the cross compiler. How to do this is specific to each build system, so you will have to consult its documentation. When things are set up correctly, here is how you call the script:

cd u-boot
env \
    CC=arm-linux-gnueabi-gcc \
    $META_MENDER_DIR/meta-mender-core/recipes-bsp/u-boot/files/ \
    --config=$MY_BOARD_CONFIG \
    --src-dir=$PWD \

Let's go through how it works:

  1. The initial line is just to enter in the right folder. You should replace this with whatever folder your U-Boot source code is in.
  2. env and the assignment of CC is to feed the correct cross compiler to the script. This might be something else than arm-linux-gnueabi-gcc, especially if doing this inside a specialized build environment, but arm-linux-gnueabi-gcc is quite common. Also, if your build environment already export CC in the environment, then you can drop this assignment from the command line.
  3. $META_MENDER_DIR should point to a directory containing a clone of meta-mender.
  4. The --config parameter should be given the machine configuration for your board. This is the definition file inside the configs folder in U-Boot. An example is am335x_boneblack_defconfig for Beaglebone Black.
  5. --src-dir simply points to the current folder.
  6. --tmp-dir points to a temporary folder that can be used to carry out some of the build steps that the script will perform underways.

After the above script has finished, hopefully successfully, your original directory will have been modified and you can use git diff to see what the resulting patch is. Then integrate this patch into your build procedure, or submit it to Git, and you should hopefully have a working U-Boot with Mender integration!