By: Mohammad S. Sadri

Last update: Aug-26-2019

Sometimes there are a set of tasks which should be done in system bring up as soon as possible.

For example, when we are running PetaLinux on a ZYNQ ultrascale+ platform, typical boot time is around 5 to 10 seconds. Some times this is too late to wait for PetaLinux to come up completely to setup a part of the hardware. Indeed we want to setup some parts as soon as the bitstream is programmed into the PL.

FSBL is usually a good place to run such early hardware setup codes. Here i go through the steps that one needs to do to customize the FSBL. Our target PetaLinux is version 2018.3.

The following instructions are tested on the Avnet Ultrazed SOM hardware.

Step 1: Obtain FSBL source code and make the patch

We need to first download the source code of FSBL so that we can be able to make the changes we want.

git clone https://github.com/Xilinx/embeddedsw.git
cd embeddedsw/
git checkout tags/xilinx-v2018.3
git branch my
git checkout my

Now we can make whatever change we want in the FSBL source codes.

The files for FSBL are located at this path. Note that our target device is a ZYNQ Ultrascale+ device.

/lib/sw_apps/zynqmp_fsbl/src

Now that we have made our changes, we create a patch file which reflects the changes we have made.

git commit -s
git format-patch -1

We have now the patch file, rename it to an easy name, e.g. 0001-fsbl.patch

Step2 : Build PetaLinux

Create a folder in your PetaLinux project for your FSBL patch. it should be located at this path:

project-spec/meta-user/recipes-bsp/fsbl/files/

Now in the following path:

project-spec/meta-user/recipes-bsp/fsbl/

And now fill up the file with the following content:

create a file named: fsbl_%.bbappend and put the following content inside:

do_configure_prepend() {
    if [ -d "${S}/patches" ]; then
       rm -rf ${S}/patches
    fi
  
    if [ -d "${S}/.pc" ]; then
       rm -rf ${S}/.pc
    fi
}
  
SRC_URI_append = " \
        file://0001-fsbl.patch \
        "
  
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
  
#Add debug for FSBL(optional)
XSCTH_BUILD_DEBUG = "1"
  
#Enable appropriate FSBL debug flags
YAML_COMPILER_FLAGS_append = " -DFSBL_DEBUG_INFO"

Alright final petalinux commands to build everything:

petalinux-build -x mrproper

petalinux-build

Now you should havea fsbl with your changes integrated inside. Also as you have noticed, I have enabled debug messages of FSBL.

Final point: make sure you regenerate the BOOT.BIN file since FSBL will be integrated in that file.