PetaLinux Yocto Tips

This page is intended to be a collection place for tips and tricks related to Yocto layers and how Yocto works under Petalinux.

Table of Contents

Documentation

The first place you should start to better understand many details of the Yocto project is the Yocto project website

Working with a User Space Yocto Layer


This tip has been adapted to PetaLinux using the meta-example layer available here meta-example

Installing the meta-example layer on your host

About the meta-example layer


This example layer is providing 3 build recipes, bbexample, bbexample-rt and bbexample-lt respectively fetching the source code from a git tree, a remote tar file and a local tar file

Configuring the layer path in the PetaLinux build system


Move to your PetaLinux project build directory, edit the conf/bblayers.conf file and add your layer path to BBLAYERS

Building the meta-layer example package based on a local source archive


The recipe we are going to build is https://github.com/DynamicDevices/meta-example/blob/master/recipes-example/bbexample/bbexample-lt_1.0.bb

The recipe bbexample-lt is using some variables

1. SRC_URI Space-delimited list of URIs to download source code, patches, and other files from git, local absolute path, https, ftp etc.
2. PN is the Package Name. The value of this variable is derived by BitBake from the base name of the recipe file.
3. PV is the Package Version. which is derived by BitBake from the base name of the recipe file


The recipe bbexample-lt can invoked using the following command


here is the command output

You have now successfully built the layer but you still need to include the binary produced into the kernel root file system

Including the meta-layer example build output in the Linux root file system


There are two options in order to do so

1. Edit your project conf/local.conf and add
2. Adding a package to an image via a .bbappend

You may wish to add specific packages to specific images, which is generally viewed as better practice. We are using core-image-minimal bitbake recipe for this tip by creating file core-image-minimal.bbappend. This .bbappend file is extending the original core-image-minimal recipe in order to include the layer build output into the Linux root file system.
core-image-minimal.bbappend file content

Running the meta-layer example under QEMU


1. Rebuild your layer
2. Rebuild your kernel
3. Start qemu
4. Log on qemu and start the application

Patching the Linux Kernel of a PetaLinux Project


1. Copy the patch to project file <plnx-proj-root>/project-spec/meta-user/recipes-kernel/linux/linux-xlnx directory.

2. Modify project file <plnx-proj-root>/project-spec/meta-user/recipes-kernel/linux/linux-xlnx_%.bbappend to use the patch file by adding the patch file name to the SRC_URI_append variable. If the variable does not exist in the file then add a new line with

3. Make sure the priority for the meta-user layer is 7 in the project file <plnx-proj-root>/project-spec/meta-user/conf/layer.conf .

Note: Any patches in the project will not be applied to an external source tree for the Linux kernel or u-boot. The user should apply patches to the external source tree.

How to Modify inittab or getty in a PetaLinux Project


1. Create a sysvinit directory in meta-user layer as
2. Create a sysvinit-inittab_%.bbappend file and your own inittab file or your inittab patch


Or

How to Patch the FSBL in a PetaLinux Project


Note: This method can't be used for v2016.4 PetaLinux Projects. PetaLinux tools use externalsrc methodology to fetch the source code from XSDK. Yocto does not allow patching in this externalsrc mechanism. Hence this method can't be used in Yocto.


1. Create a fsbl and files directory in meta-user layer as
2. Copy patch files to <plnx-proj-root>/project-spec/meta-user/recipes-bsp/fsbl/files as
Note that patches should be generated based on the embeddedsw GIT repo which contains FSBL as the patches require the path into the repo to apply correctly.

3. Create a fsbl_%.bbappend file and add below content

4. Remove the <plnx-proj-root>/components/plnx_workspace and clean your project workspace before rebuilding FSBL components
5. Rebuilding FSBL components

How to Patch the PMU Firmware in a PetaLinux Project


Note: This method can't be used for v2016.4 PetaLinux Projects. PetaLinux tools use externalsrc methodology to fetch the source code from XSDK. Yocto does not allow patching in this externalsrc mechanism. Hence this method can't be used in Yocto.

1. Create a pmu/pmu-firmware and files directory in meta-user layer as
2. Copy patch files to <plnx-proj-root>/project-spec/meta-user/recipes-bsp/pmu/files as
3. Create a pmu-firmware_%.bbappend file and add below content

4. Remove the <plnx-proj-root>/components/plnx_workspace and clean your project workspace before rebuilding PMUFW components
5. Rebuilding PMUFW components

Configuring the FSBL and PMUFW Debugs in a PetaLinux Project


Create a fsbl_%.bbappend file and add below content
To enable debugs in FSBL:
To add compiler flags in FSBL:
To add BSP flags(secure mode) in FSBL:
Create a pmu-firmware_%.bbappend file and add below content
To enable debugs in PMUFW refer this https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/18841724/PMU+Firmware page for DEBUG flags list
 To add compiler flags in PMUFW, see PMU FW Build Flags:

To add BSP flags(secure mode) in PMUFW:

To add BSP flags(debug mode) in PMUFW: For example if you want to enable https://github.com/Xilinx/embeddedsw/blob/release-2018.3/lib/sw_apps/zynqmp_pmufw/misc/xfpga_config.h#L34 debug is Xil BSP libraries

By pass PMUFW debug logs on different UART console:
Remove the <plnx-proj-root>/components/plnx_workspace and clean you project workspace before rebuilding FSBL or PMUFW components

How to Update psu_init Files in PetaLinux Project


1. Modify <plnx-proj-root>/project-spec/hw-description/psu_init.c file as per your requirement 

2. Create a FSBL bbappend file under <plnx-proj-root>/project-spec/meta-user/recipes-bsp/fsbl/fsbl_%.bbappend and add below content to update psu_init.c changes to FSBL

How to Add Pre-built Libraries in PetaLinux or Yocto Recipes


1. Create a new recipe or in existing recipe in meta-user layer as shown
2. Copy pre-built libraries files and header file required for libraries to <plnx-proj-root>/project-spec/meta-user/recipes-apps/libcpsample/files as
3. Add the below content to recipe file
4. Build the pre-built library recipe

Creating Libraries in a PetaLinux Project


1. Create a library using petalinux tools
2. Modify the libsample.bb recipe file <plnx-proj-root>/project-spec/meta-user/recipes-apps/libsample/libsample.bb as
3. Modify the <plnx-proj-root>/project-spec/meta-user/recipes-apps/libsample/files/Makefile generated from petalinux tools as
4. Build the library recipe
Creating Apps(which uses libraries) in PetaLinux Project


1. Create a library using petalinux tools
2. Modify the sampleapp.bb recipe file <plnx-proj-root>/project-spec/meta-user/recipes-apps/sampleapp/sampleapp.bb as
3. Modify the <plnx-proj-root>/project-spec/meta-user/recipes-apps/libsample/files/sampleapp.c generated from petalinux tools as
4. Build the apps recipe

How to Auto Mount SD card in Yocto Recipes


1. Create a base-files directory in meta-user layer as
2. Create a base-files_%.bbappend file and add below content
3. Rebuild rootfs

How to Configure a Second Ethernet Interface(eth1) to Get the IP Address from DHCP in Yocto Recipes

Method 1: Append auto eth1 to existing interfaces file


1. Create a init-ifupdown directory in meta-user layer as
2. Create a init_ifupdown_%.bbappend file and add below content
3. Rebuild rootfs

Method 2: Use your own interfaces file


1. Create a init-ifupdown directory in meta-user layer as
2. Create your own network interface file as show below
3. Create a init_ifupdown_%.bbappend file and add below content
4. Rebuild rootfs

How to Run RootFS Post Process Command in PetaLinux


Below is one of the example and you can add rootfs post process command in <plnx-proj-root>/project-spec/meta-user/recipes-core/images/petalinuxbsp-user-image.bbappend file. You add a function which can perform modifying file, deleting and adding file and directories.
  1. Create a petalinux-user-image.bbappend file in meta-user layer as show below if doesn't exists(Note: Don't use project-spec/meta-user/recipes-core/images/petalinux-image-full.bbappend(2018.3 or later) or petalinux-image.bbappend(2018.2 or below))

  2. Create a post process function as shown below in petalinux-user-image.bbappend 

  3. Clean petalinux-user-image sstate and rebuild petalinux-user-image recipe.

How to Add Users and Set Passwords for Users in PetaLinux

  1. Create a petalinux-user-image.bbappend file in meta-user layer as show below (Note: Don't use project-spec/meta-user/recipes-core/images/petalinux-image-full.bbappend(2018.3 or later) or petalinux-image.bbappend(2018.2 or below))

  2. Inherit extrausers.bbclass from openembedded-core and add users in petalinux-user-image.bbappend 

  3. Rebuild rootfs

How to Override a Recipe Variable in PetaLinux

  1. First step is to find the recipe directory hierarchy, search the recipe in https://layers.openembedded.org/layerindex/branch/rocko/recipes/
  2. Here we are taking Protobuf package as example as SRC_URI like is broken in Yocto 2.4 release. Same concept applies to all the recipes. Protobuf is categorized in meta-openembedded/meta-oe/recipes-devtools/protobuf
  3. Create a directory recipes-devtools/protobuf directory in <plnx-porj-root>/project-spec/meta-user

  4. Create a protobuf_%.bbappend file. Note: The % wildcard is actually allow matching of the name and version up to the point of encountering the %. This approach will allow for matching of the major or major.minor. version of recipes.

  5. Now override a recipe variable for protobuf recipe.

  6. Build protobuf

How to Enable Verbose in sysvinit

  1. First step is to find the recipe directory hierarchy, search the recipe in http://layers.openembedded.org/layerindex/branch/thud/recipes/
  2. sysvinit is categorized in meta/recipes-core/sysvinit
  3. Create a directory recipes-core/sysvinit directory in <plnx-porj-root>/project-spec/meta-user

  4. Create a sysvinit_%.bbappend file. Note: The % wildcard is actually allow matching of the name and version up to the point of encountering the %. This approach will allow for matching of the major or major.minor. version of recipes.

  5. Now enable verbose for sysvinit recipe (refer http://cgit.openembedded.org/openembedded-core/tree/meta/recipes-core/sysvinit/sysvinit/rcS-default?h=thud#n15)

  6. Clean and rebuild sysvinit

How to reduce build time using SSTATE CACHE

The OpenEmbedded(OE) build system produces a lot of intermediate output when processing the many tasks entailed in building the packages comprising the Linux OS stack. SSTATE(Shared State) CACHE provides a cache mechanism which drastically reduces build time, especially when you create a new PetaLinux project and run "petalinux-build --sdk". The OE build system detects changes in the "inputs" to a given task by creating a checksum (or signature) of the task's inputs. If the checksum changes, the system assumes the inputs have changed and the task needs to be rerun. The intermediate output can be reused for future builds and shared between multiple build environments to speed up the build process.

Two key variables are used with the shared state cache feature.  The SSTATE_DIR variable contains the path to the shared state cache. The variable DL_DIR tells BitBake where to place the source downloads. The default setting places the files in the directory downloads beneath the top directory(TOPDIR) of your build environment. The variable TOPDIR contains the full (absolute) path to the build environment. Source downloads can be shared among multiple build environments.

For best practice you need to set DL_DIR and SSTATE_DIR outside the petalinux project so that when you run "petalinux-build -s mrproper" which removes build(TOPDIR)directory forcefully, but retaining DL_DIR and SSTATE_DIR directories. These contents can be reused for incremental build or building another project. Note: You can use DL_DIR content for all the PetaLinux project irrespective of the architecture(AARCH64, ARM, MicroBlaze) but SSTATE_DIR can be used for only one architecture. For example, if you build a AARCH64 PetaLinux project the content of SSTATE_DIR can be reused for another AARCH64 project but not for ARM or MicroBlaze projects.

In order to utilize the sstate cache feature in PetaLinux projects follow these steps.

  1. Download and untar the PetaLinux release sstate-cache files from https://www.xilinx.com/support/download/index.html/content/xilinx/en/downloadNav/embedded-design-tools.html. Here we are taking 2019.2 as an example.
  2. Go to your 2019.2 PetaLinux project and set the following options using petalinux-config

  3. For setting up the download and shared state directories add the following variables in the <plnx-proj-root>/project-spec/meta-user/conf/petalinuxbsp.conf file.

  4. Now you need to start the build and if you are building the SDK (petalinux --sdk) then enabling the network is mandatory for a fresh build.

  5. If you are building without network access then set the BB_NO_NETWORK variable.

Yocto References 


Related Links
Xilinx Yocto