Patching U-Boot boot script in Petalinux 2021.1

The U-Boot boot script process was changed in Petalinux 2021.1, and modifying it now requires a recipe to overwrite the original script.

Overview

In Petalinux 2020.1, U-Boot was modified to use the U-Boot “distro boot” feature, as previously discussed in the post U-Boot changes to distro boot. In that version, the boot.scr was included in the meta-user layer and it was easily accessible for modification. In the latest 2021.1, the boot.scr script among other things, was moved to the Xilinx Yocto layer, and it requires a Yocto bbappend recipe to overwrite it.

The recipe

Yocto uses a bbappend file to modify another related recipe in what is called a BitBake append file. These files use a .bbappend file type suffix, and use the same naming convention as the recipe they modify with the .bb file suffix.

The bbappend follows the same directory structure as the original recipe, as we’ll see below. In Petalinux, the U-Boot recipe resides under <project>/components/yocto/layers/meta-xilinx/meta-xilinx-bsp/recipes-bsp/u-boot.

Below is the contents of the whole U-Boot recipe, where the u-boot-zynq-scr recipe also resides:

.
├── files
│   └── 0001-Remove-redundant-YYLOC-global-declaration.patch
├── u-boot_%.bbappend
├── u-boot-spl-zynq-init.inc
├── u-boot-xlnx_2021.1.bb
├── u-boot-xlnx-dev.bb
├── u-boot-xlnx.inc
├── u-boot-zynq-scr
│   ├── boot.cmd.generic
│   ├── boot.cmd.qspi.versal
│   ├── boot.cmd.sd.versal
│   ├── boot.cmd.sd.zynq
│   ├── boot.cmd.sd.zynqmp
│   ├── boot.cmd.ubifs
│   └── pxeboot.pxe
├── u-boot-zynq-scr.bb
└── u-boot-zynq-uenv.bb

Customizing

We will create a directory structure matching this under the meta-user layer, as follows under <project>/project-spec/meta-user/recipes-bsp/u-boot

.
├── files
│   ├── bsp.cfg
│   └── platform-top.h
├── u-boot-xlnx_%.bbappend
├── u-boot-zynq-scr
│   └── boot.cmd.generic
└── u-boot-zynq-scr.bbappend

We copied the original boot script from the Yocto recipe (i.e. boot.cmd.generic in this case) and placed it under the u-boot-zynq-scr directory just created. The contents are now available in the user area to make any custom changes.

The u-boot-zynq-scr.bbappend is a simple script that overwrites the boot script in the original recipe with the local copy, and its contents are:

FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"

SRC_URI += "file://boot.cmd.generic"

The FILEEXTRAPATHS_prepend adds local files in this recipe to the original recipe, effectively overwriting (or adding) them. THISDIR is replaced with the current directory where the .bbappend resides, and PN is the package name, which in this case is u-boot-zynq-scr. This would be the directory location where the boot.cmd.generic file is searched.

Conclusion

Modifying the boot script is useful for custom boot procedures, such as mixed boot media or to handle fallback in case the U-Boot booting process fails to load a binary. In this post, we showed how to handle a custom U-Boot boot script modification using a Yocto BitBake append process.

Temperature sensor

In this post we will look at controlling a temperature sensor IC over I2C from Linux, and pre-setting its critical...

Previous
Adding U-Boot firmware utils to Petalinux 2023.1

The U-Boot firmware utils allow Linux to access the U-Boot environment partition, and its configuration has changed in Petalinux 2023.1....

Next