Introducing automatic U-Boot patching
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/uboot_auto_configure.sh \ --config=$MY_BOARD_CONFIG \ --src-dir=$PWD \ --tmp-dir=/tmp/u-boot-auto-configure
Let's go through how it works:
- 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.
envand the assignment of
CCis 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-gccis quite common. Also, if your build environment already export
CCin the environment, then you can drop this assignment from the command line.
$META_MENDER_DIRshould point to a directory containing a clone of meta-mender.
--configparameter should be given the machine configuration for your board. This is the definition file inside the
configsfolder in U-Boot. An example is
am335x_boneblack_defconfigfor Beaglebone Black.
--src-dirsimply points to the current folder.
--tmp-dirpoints 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!