Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This reference is a summary of the major commands in PetaLinux and their equivalent functionality in native Yocto. This can be used as a ready reckoner for those who are used to using PetaLinux and are looking to replicate their workflow in Yocto who are used to using PetaLinux.

Info

The primary source of detail on Yocto commands should be the documentation provided by the project. This can be found at https://docs.yoctoproject.org/dev/ . Select the version of Yocto from the pull down menu for version-specific context of the documentation

...

For Yocto Project, the machine is not defined on project creation. It can be modified in build/conf/local.conf afterwards. By default, the machine is set to zynqmp-generic, however can be changed in local.conf, or on invocation of the bitbake build command, using the MACHINE=[target template] command line override.

...

A PetaLinux BSP is a configuration file containing all the necessary settings and artifacts required to build a project with the PetaLinux tools for a given hardware project. The file is of extension has a .bsp extension, and can be downloaded from the AMD website for a given board. The meta-xilinx-bsp layer has a number of built-in BSPs in native Yocto that can be used as a starting point for supported boards.

PetaLinux Example

Download a bsp BSP file from the website - eg for example, xilinx-zcu102-v2023.1-05080224.bsp

Code Block
petalinux-create --type project -s xilinx-zcu102-v2023.1-05080224.bsp
cd xilinx-zcu102-2023.1/

...

In PetaLinux, the tools need to be made available to the commandlinecommand line, however no project-specific initialization is required. With Yocto, the SDK needs to be setup set up for the local project prior to running bitbake commands.

...

This Yocto Example is broken into two pieces. In the first piece, we create a new layer, which allows us to store details about a machine configuration. This layer has a configuration file made, to specify that the hardware is similar to the zxcu102 ZCU102 board, and then we make any necessary changes in that file to override defaults. In our case, we override the XSA file that is being used, to point to our own one. Note - this only needs to be done once per new xsa file. Once the layer is in place and configured, we only need to follow part 2, to change the machine name in local.conf to use the configuration specified.

Info

Understanding and Creating Layers from the Yocto project documentation gives more detail on layers, how to create them and add them and best practices

Part 1 -

...

Setting up a new layer and machine configuration (do once)

Code Block
bitbake-layers create-layer ../sources/meta-myhardware # Create a new layer for your custom hardware configuration to live (name as applicable)
bitbake-layers add-layer ../sources/meta-myhardware # Allow bitbake to find the layer when building
mkdir ../sources/meta-myhardware/conf/machine # Make a new folder in your layer to store machine configurations

cat << EOF > ../sources/meta-myhardware/conf/machine/myhardware-zcu102-zynqmp.conf 
#Base this machine configuration off of the zcu102 board and then make changes below
require conf/machine/zcu102-zynqmp.conf
HDF_BASE = "file://"
# Replace with the path to your XSA file from hardware
HDF_PATH = "/path/to/my/design.xsa" 
EOF

Part 2 -

...

Edit the configuration to use the newly

...

created machine configuration

Info

The command below replaces the line in local.conf to specify the new target machine using the command line tools. However in an active project you may might prefer to open the file in a text editor, find the line and modify it by hand.

...

Info

Many other image targets exist in Yocto, and these can be further customized. For a list of some common image types, see https://docs.yoctoproject.org/dev/ref-manual/images.html

Packaging and Booting

Generate the boot Image

This step is used to generate a boot.bin file for booting the target. This would usually contain a PDI file, PLM, PSM firmware, TF-A, U-Boot boot boot loader and DTB.

PetaLinux Example

...

Details can be found in the meta-xilinx documentation here : https://github.com/Xilinx/meta-xilinx/blob/master/docs/README.booting.flash.md

...

Code Block
runqemu nographic slirp

Info

More runqemu options is are available in the documentation https://docs.yoctoproject.org/dev/dev-manual/qemu.html

Boot Image on

...

Hardware with an SD card

PetaLinux Example

Code Block
petalinux-package --boot --fsbl zynqmp_fsbl.elf --fpga system.bit --u-boot --force
petalinux-package --wic

...

To automatically create an SD card raw image WIC file, you can either add IMAGE_FSTYPES:append=" wic" to conf/local.conf:

Code Block
sed -i '/MACHINE ??=/a IMAGE_FSTYPES:append=" wic"' conf/local.conf

or if you have a custom machine layer, you can add the IMAGE_FSTYPES += “wic” field to that layer:

Code Block
echo 'IMAGE_FSTYPES += "wic"' >>  ../sources/meta-myhardware/conf/machine/myhardware-zcu102-zynqmp.conf # Change path to match your machine layer

The next invocation of bitbake <target filesystem image> will then create the wic WIC file to be copied to the SD card.

...

Upgrading the Installed tool with more Platforms

...

PetaLinux Example

Code Block
petalinux-upgrade -u https://petalinux.xilinx.com/sswreleases/rel-v2023/sdkupdate/  -p <architecture>

...

Including Prebuilt Applications

...

PetaLinux Example

Code Block
petalinux-create -t apps --template install --name myapp --enable
cd <plnx-proj-root>/project-spec/meta-user/recipes-apps/myapp/files
rm myapp
cp <path-to-prebuilt-app> ./

...

Only perform this step if you dont do not already have an application layer created

...

This points the build system to your Makefile and sources and specifying specifies to use make to build and install them

...

Creating and Adding Custom Applications

...

PetaLinux Example

Code Block
petalinux-create -t apps --name myapp --enable

...

Info

This example looks a lot longer, as all files, including the source code for “Hello world” and it’s its Makefile are included below to make a complete working example that builds. PetaLinux achieves a similar goal by copying a template from the installation.

...

Only perform this step if you dont do not already have an application layer created

...

This points the build system to your Makefile and sources and specifying specifyies to use make to build and install them

...

Creating and Adding Custom Kernel Modules

...

PetaLinux Example

Code Block
petalinux-create -t modules --name mymodule --enable

...

Info

Please see Incorporating Out-of-Tree Modules in the Yocto Mega Manual for details of on building out-of-tree kernel modules. A brief example is illustrated below based off of those instructions

...

Only perform this step if you dont do not already have an application layer created

Code Block
bitbake-layers create-layer ../sources/meta-myapplications
bitbake-layers add-layer ../sources/meta-myapplications

Step 2 - Copy a kernel out-of-tree module example from the poky meta-skeleton sources into the local layer

Code Block
mkdir -p ../sources/meta-myapplications/recipes-kernel
pushd ../sources/meta-myapplications/recipes-kernel
cp -rv ../../poky/meta-skeleton/recipes-kernel/hello-mod .

Step 4 - Enable kernel module build in the layer

Code Block
echo "MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS += \"hello-mod\"" >> ../conf/layer.conf

Step 5 - Build root file system with the included out-of-tree module

Code Block
popd
bitbake petalinux-image-minimal

Kernel modules can be found in /lib/modules/<kernel-version> on the running target:

Code Block
$ ls /lib/modules/`uname -r`/extra
hello.ko
$ sudo modprobe hello
[   62.576953] hello: loading out-of-tree module taints kernel.
[   62.578843] Hello World!
$ sudo rmmod hello
[  477.634516] Goodbye Cruel World!

Application Auto Run at Startup

PetaLinux Example

Follow the steps at PetaLinux Yocto Tips

...

Code Block
bitbake-layers create-layer ../sources/meta-myapplications
bitbake-layers add-layer ../sources/meta-myapplications

mkdir -p ../sources/meta-myapplications/recipes-apps/myapp-init/files

Create the myappinit.bb, files/myapp-init.service and files/myapp-init files as per the instructions into ../sources/meta-myapplications/recipes-apps/myapp-init

Instruction Step 4 - instead of running petalinux-build, run:

...

Code Block
bitbake core-image-minimal # (or a image of your choice)

Adding Layers

PetaLinux Example

Code Block
petalinux-config 

...

Adding an Existing Recipe into the Root File System

PetaLinux Example

Locate the recipe
Add the CONFIG_<recipename> into <plnx-proj-root>/project-spec/meta-user/conf/user-rootfsconfig. Run

Code Block
petalinux-config -c rootfs

...

Yocto Example

Modify either the conf/local.conf or a custom enabled layer’s conf/layer.conf and add the package:

Code Block
echo "IMAGE_INSTALL:append = \" myrecipe\"" >> ../sources/meta-myapplications/conf/layer.conf #or
echo "IMAGE_INSTALL:append = \" myrecipe\"" >> conf/local.conf
bitbake core-image-minimal

Adding a Package Group

PetaLinux Example

Step by step guide in detail are in UG1144:

Create a bb file
Add the confifguration configuration to user-rootfsconfig
Run the following command to select:

...