Yocto or PetaLinux?
PetaLinux [1] and Yocto [2] are both build tools for creating custom embedded Linux platforms. Recently, I got into a discussion with a colleague as to which to use for an embedded Linux project. Given PetaLinux simplifies to some degree the complexities of Yocto, my colleague’s initial instinct was to use PetaLinux. However, I have on occasion bumped into the limitations of PetaLinux. This got me thinking that a comparison of the two would make for an interesting article.
It’s worth noting that PetaLinux was created by Xilinx, which has now been purchased by AMD [3]. At the time of writing the support forums and documentation hosting have moved over to AMD. But the Xilinx wiki lives on, and it seems unlikely that the APIs and code will have all their Xilinx references removed (function names beginning with X or Xil for example). I’ll continue to refer to Xilinx throughout this article as we are talking about the Xilinx part of the AMD portfolio.
Target Hardware and Applications
PetaLinux is targeted at designs involving a Field Programmable Gate Array (FPGA), for example a FPGA-based System-on-Chip (SoC), and implies the use of Xilinx hardware.
FPGAs are integrated circuits that can be reprogrammed for different tasks, they excel at high performance applications. Meanwhile SoCs package Central Processor Units (CPUs), memory, I/O ports, and other specialised processing units (like FPGAs) onto a single chip. The benefits of SoCs are they allow for smaller, lighter and more power efficient solutions.
The benefit of a SoC that includes an FPGA is that you have the benefits of a general-purpose processor (for example access to existing software platforms such as Linux and everything that comes with it), and a reprogrammable integrated circuit that can be used to execute high performance specialised tasks.
At Plextek we specialise in low size, weight and power (SWaP) solutions and often find ourselves utilising SoCs.
Yocto
Yocto is a set of build tools for creating embedded Linux operating systems. Broadly speaking Yocto also encapsulates the poky reference distribution and components from the OpenEmbedded project [6] [7]. The key components for the purpose of this discussion are:
- Distributions
- Layers
- BitBake
A distribution (typically abbreviated to distro) is a Linux based operating system. Yocto has a reference distribution called “poky” that has a set of image definitions you can use as a starting point.
A layer is a set of software components that can be added to your Yocto project. A Yocto project consists of a number of layers:
- Base layers (such poky and OpenEmbedded)
- Device specific layers (such as meta-xilinx)
- Layers that fulfil dependencies for your applications (e.g. if you needed libmetal then meta-openamp would fulfil this requirement)
- Project specific layers (such as board support and software)
Yocto makes use of the OpenEmbedded BitBake tool [8] for its build engine. You will be using the “bitbake” command line tool on a day-to-day basis for a Yocto project. BitBake is a generic task execution engine, which runs tasks written in shell script and Python. Essentially, it allows you to build packages (software components) and images (deployable files).
PetaLinux
PetaLinux is a set of tools that utilises many of the same underlying tools as Yocto, and as such can be seen as a wrapper for Yocto (although this is a simplification).
The first thing to note is that there are actually a few things called “PetaLinux”:
- A set of tools (a sort of Yocto wrapper)
- A reference distro
- A meta layer (meta-petalinux)
The PetaLinux set of tools includes the meta-petalinux layer, which defines the PetaLinux distribution. Xilinx provide quick start packages for boards (e.g. Xilinx ZCU102 etc) which can be fed into the petalinux-create command. This gets you a usable image for a reference board within a couple of commands.
The focus of PetaLinux is on getting you as a developer up and running with a development system as quickly as possible. This allows you to focus on specific elements, for example an FPGA and the software on the processor that utilises it.
Moving from PetaLinux to Yocto
If you start out with a PetaLinux project and wish to move to Yocto, there are a couple of ways of doing this. They are not zero effort however, and there are some issues to bear in mind.
Migration Script
There is a migration script which you can use to migrate from PetaLinux to Yocto. However, the Xilinx wiki page entry on performing this operation [4] states that it only works for 2021.1 to 2022.2 Xilinx versions. We’ve had mixed success with this approach; you won’t always get a usable build when it produces something and other times, you’ll just get nothing out. This is particularly the case when using the migration script on a version of PetaLinux that is not supported. It may get you most of the way there but expect to complete migration manually.
When the migration script does work, the file structure created is a little different to how you would typically structure a Yocto project, reflecting the PetaLinux folder structure. But this can be rearranged.
Port Across the Key Components
To do this, you’ll need to start out with a vanilla Yocto build (see the Yocto Quick Start page for inspiration [14]). At a minimum you’ll need your FPGA definition (XSA file), and a machine conf for you target hardware (see gen-machine-conf [13]). Then you can start adding the components you need to a new project specific meta layer. You can even include the meta-petalinux layer in your Yocto project and utilise the PetaLinux distro if that is what you require.
It can be time consuming. It’s best to create your own image definition, even if based on a pre-existing one. You’ll need this for adding your components and their dependencies to the build. It can also take a while to make sure you have all the relevant build configurations copied across to Yocto and they won’t necessarily be set in the same place.
System Requirements
The minimum system requirements for a PetaLinux and a Yocto project are essentially the same [1][11]:
PetaLinux / Yocto
2Mhz CPU Clock, 8 cores / 4 CPU cores
8GB RAM / 8GB RAM
100GB Disk Space / 90GB Disk Space
The similarity between the two is perhaps not surprising given that much of the underlying build system uses many of the same components.
However, it is worth noting that by default PetaLinux deletes all the intermediate build files once the build output is produced, in theory saving a bit of disk space.
Additionally, I would suggest that most Yocto projects would take up more than 90GB of disk space.
Comparison
Build Output - The build output is effectively the same, e.g. boot image and rootfs.
Command Line Tools - As a Yocto developer you will be using the BitBake tool to build recipes and images, but for PetaLinux you will be using the petalinux-* set of commands [9]. The petalinux-* commands are a higher-level abstraction of BitBake commands and therefore not all options are available (for example the ability to generate a dependency tree for a package). However, many operations are duplicated between each command set and Xilinx provide a cross reference on their Wiki page [12].
Complexity - There is a steep learning curve to build with Yocto, and PetaLinux attempts to get you to a useable output quicker.
Xilinx Workflow Integration - The Xilinx workflows (e.g. Vivado, Vitis, etc) are geared towards using PetaLinux.
Which to Choose?
This really comes down to if you need to productise your Linux platform. If you need to productise the platform then you will need to use Yocto; we’ll cover the reasons why in the next section. If you are developing components, or a platform which will not need productising, and do not already have Yocto expertise then PetaLinux is likely to be the place to start.
PetaLinux does give you the option to dip your toe in, which is useful if you don’t have much experience. If you’re using a SOM then the reference design provided by the board manufacturer is a good place to start, even if you end up porting to Yocto afterwards. We find more often than not that reference designs are provided as PetaLinux projects.
Plextek’s Projects
Plextek has worked on a number of embedded Linux platforms over the years, including the follow projects:
Foreign Object Detection (FOD) Radar
Ground Penetrating Radar (GPR)
Smart Cities Base station
Prototype hand-held scanner
They do indeed follow the pattern of prototypes using PetaLinux and products using Yocto.
Summary
In summary, if you’re not productising your device or you’re just developing the FPGA, then PetaLinux is a good candidate. But you need to be aware of its limitations if you do want to productise at a later date. If you are already familiar with Yocto then starting with Yocto from the beginning, even for a prototype project, will put you in good stead going forward. Yocto is an absolute must when you intend to productise your device, particularly in terms of security.