Have you ever wished that your PetaLinux project didn't take so long to build? Have you ever wanted a way to make the build happen faster?
Alas! There are simple steps to follow to accelerate your PetaLinux project build times. As much as a 50% reduction in build time can be achieved!
Project Build Caches
The building of a PetaLinux project produces a lot of intermediate output files as bitbake builds the many recipes and processes the thousands of tasks for the u-boot, kernel, and rootfs configurations. If you have ever examined the 'build' folder of a PetaLinux project you have probably noticed the 'downloads' and 'sstate-cache' folders:
These folders hold the intermediate outputs of the build tasks and provide a cache mechanism so the same tasks don't have to be repeated every time 'petalinux-build' is run. However, if a full 'mrproper' clean ('petalinux-build -x mrproper -f') of a PetaLinux project is run these outputs are deleted, and this makes subsequent project builds take longer as these output cache folders are re-created. It is sometimes necessary to do a 'mrproper' clean, though, especially when recovering from a previously failed build. The solution is that there is a way to store these cache folders outside the PetaLinux project folders so they can be reused and shared for future builds.
There are two project variables, SSTATE_DIR and DL_DIR, that specify the locations of these cache folders. The SSTATE_DIR specifies the path to the shared state (sstate) cache and the DL_DIR tells bitbake where to store the source downloads for the packages it needs to build. The SSTATE_DIR is architecture-specific (AARCH64 for Zynq MPSoC, ARM for Zynq, and mb-full for MicroBlaze). A PetaLinux project that targets a Zynq device (ARM) cannot share the SSTATE_DIR of a project that targets a Zynq MPSoC (AARCH64) device or a MicroBlaze soft CPU. However, DL_DIR can be shared by all PetaLinux projects regardless of CPU type.
To set the SSTATE_DIR and DL_DIR variables for a PetaLinux project, one must first create the downloads and architecture-specific sstate folders outside of the PetaLinux project. These folders can be anywhere the user has read/write permissions. For example the Avnet build scripts (Using Avnet Build Scripts to Build a PetaLinux BSP) will create these folders in the same parent folder as the associated git repository (https://github.com/Avnet/petalinux):
Edit the petalinuxbsp.conf file of the PetaLinux project (<project>/project-spec/meta-user/conf/petalinuxbsp.conf) and add the SSTATE_DIR and DL_DIR variables to the end of the file:
DL_DIR = "/path/to/cache/<PetaLinux version>/downloads"
SSTATE_DIR = "/path/to/cache/<PetaLinux version>/sstate_<arm | aarch64 | mb-full>"
If the 'downloads' and 'sstate-cache' folders already exist in the build folder of your PetaLinux project you can copy or move their contents to the cache folders you just created.
Installed Caches From Xilinx
In addition to storing local copies of the software package downloads and sstate cache, it is also possible to install full archives of the standard PetaLinux packages. Xilinx provides downloads archives and sstate caches that contain the standard packages that can be built with PetaLinux. This downloads archive and sstate cache can be downloaded from Xilinx for the version of PetaLinux you are using:
Extract the downloads and cache archives to a convenient folder on the hard drive. Since they are PetaLinux version-specific, a good place is probably the PetaLinux install folder:
Launch a command window and edit the PetaLinux project configuration to update the 'Local sstate feeds settings' and 'Add pre-mirror url' settings for the locations of the downloads archive and sstate cache. Don't forget to run the PetaLinux settings shell script first:
$ source /path/to/petalinux/install/settings.sh
$ cd /path/to/petalinux/project
Navigate to Yocto Settings -> Add pre-mirror url and enter the path to the installed downloads archive. Note the path must be prepended with 'file://'. Click OK:
Navigate to Yocto Settings -> Local sstate feeds settings and enter the path to the installed sstate cache. Click OK:
Save and exit the System Configuration editor.
Test the Changes with a Fresh Project Build
Clean and rebuild the PetaLinux project:
$ petalinux-build -x mrproper -f
Dramatic Improvement in Build Time!
These steps to create project build caches and install the Xilinx-provided caches can have a dramatic effect on reducing build times for your PetaLinux projects. As much as a 50% reduction in build time can be achieved! For PetaLinux projects with large filesystems, such as that for Avnet's board, this can save many hours of build time. Imagine all the fun you can have while you aren't waiting for PetaLinux to finish building your project...