Mender blog

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:

  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!

Recent articles

Key takeaways from embedded world North America 2024

Key takeaways from embedded world North America 2024

The Mender team attended the first embedded world in North America to connect with industry leaders and discuss insights on IoT compliance, the CRA, RTOS vs. Linux for IoT, and the importance of secure OTA update orchestration.
Understanding the EU Cyber Resilience Act (CRA): Why it matters and how to comply

Understanding the EU Cyber Resilience Act (CRA): Why it matters and how to comply

The EU Cyber Resilience Act (CRA) was enacted in October 2024 and has impacted products with digital elements on the European market. Learn why CRA compliance is essential for manufacturers, the penalties for noncompliance, and how to meet the Act's cybersecurity standards.
How OTA updates enhance software-defined vehicles

How OTA updates enhance software-defined vehicles

Discover how OTA updates enhance software-defined vehicles by improving safety, reducing recalls, and delivering benefit to producers and consumers.
View more articles

Learn why leading companies choose Mender

Discover how Mender empowers both you and your customers with secure and reliable over-the-air updates for IoT devices. Focus on your product, and benefit from specialized OTA expertise and best practices.

 
sales-pipeline_295756365