Setting Up the PetaLinux Environment

Introduction to PetaLinux

PetaLinux is an embedded Linux development toolkit launched by Xilinx (now under AMD), specifically designed for its FPGAs (such as Zynq, Zynq UltraScale+ MPSoC, MicroBlaze, etc.) and adaptive SoCs. It is built based on the Yocto Project and provides a complete toolchain that simplifies the development, customization, and deployment process of embedded Linux systems. PetaLinux is not a special Linux kernel but rather a set of tools for configuring the development environment, reducing the workload of configuring U-Boot, the kernel, and the root filesystem. It can automatically configure related software based on the hardware information exported from Vivado.

PetaLinux Installation Steps

Here, we choose to install PetaLinux on Ubuntu 20.04.6. Since the host machine uses Windows, we opt to install a Ubuntu 20.04.6 virtual machine after installing VirtualBox. You can also install Ubuntu via VMware. For specific instructions on how to install Ubuntu on VirtualBox or VMware, please search for relevant information online.

After installing the Ubuntu system, the following operations need to be performed.

image-20250627164525060

If the interpreter type matches, proceed. If not, use the following command to change dash to bash:

In the pop-up dialog box, click "NO".

After this, the system will start installing PetaLinux. When you see the message "Press Enter to display the license agreements", press Enter to continue. Then, three license agreements will appear. Press Q to exit, then press Y and Enter to continue. The system will then begin installing PetaLinux.

image-20250627170615206

The following output will appear:

You can write this to the system environment variables:

 

If the PetaLinux installation directory is displayed, it indicates that the working environment has been set up and is running properly.

Configuring the Petalinux Project

Exporting Hardware Project Information from Vivado to Obtain .xsa File

image-20250708134726752

 

This will pop up a character-based graphical interface for related configurations, which will be explained later.

 

Petalinux Project Configuration Interface

Executing the petalinux-config --get-hw-description command will pop up a window where you can configure the Petalinux project. If it has already been configured and you want to configure it again later, you can run the command "petalinux-config" to configure it.

image-20250708140532419

Use the "↑" and "↓" keys on the keyboard to select the menu to configure, and press the "Enter" key to enter the submenu. The blue highlighted first letter in the menu is the hotkey for that menu; pressing the key corresponding to that highlighted letter on the keyboard will quickly select the corresponding menu. After selecting a submenu, pressing the "Y" key will write the corresponding configuration option to the configuration file, and the menu prefix will change to "< * >". Pressing the "N" key will not compile the corresponding code, and pressing the "M" key will compile the corresponding code as a module, with the menu prefix changing to "< M >". Press the "Esc" key twice to exit, i.e., return to the previous level. Press the "?" key to view help information for this menu. Press the "/" key to open the search box, where you can enter the content to search for. At the bottom of the configuration interface, there are five buttons. The functions of these five buttons are as follows:

A brief introduction to these menus from top to bottom:

u-boot and Linux Kernel

In the Linux Components Selection option, you can configure the source of u-boot and the Linux kernel. Press the Enter key to enter the next selection interface. u-boot and the Linux kernel are downloaded from GitHub by default, requiring the Linux host to be connected to the internet to download. This experiment has downloaded the corresponding resources locally. Download links: linux-xlnx, uboot-xlnx

Note: ① Be sure to use the version corresponding to petalinux; we are using petalinux2021.1 version. ② If multiple petalinux projects need to use local source code, each petalinux project must have its own corresponding kernel source code and u-boot source code. Otherwise, if one petalinux project modifies the source code, it will affect other projects.

image-20250811134401230

 

image-20250708154325387

Copy the kernel source code to the virtual machine and extract it. Here we choose to extract it to /home/mind/petalinux_downloads (you need to create the petalinux_downloads folder first).

image-20250708141924947

Change the source of the Linux kernel/u-boot to local acquisition and configure the address of the downloaded offline package after extraction:

Select Linnux Components Selection --> u-boot --> ext-local-src

Linnux Components Selection --> linux-kernel --> ext-local-src

After selection, two additional options will appear: External u-boot local source settings --->

External u-boot local source settings --->

Select these two items, fill in the corresponding addresses, save, and exit.

image-20250708142114624

image-20250708142020912

image-20250708142041644

image-20250708142150144

Setting Up Offline Compilation

The Petalinux compilation project requires downloading some resources online by default. If the network is poor, compilation can be very slow or even fail. To solve this problem, we can pre-download two offline resource packages and then set up Petalinux for offline compilation. At this point, the u-boot and Linux resource packages have been downloaded from GitHub. We still need to download downloads, ssate:

Note: Be sure to download the files corresponding to the Petalinux version. We are using Petalinux version 2021.1, so we need to find these two files under the 2021.1 label to download.

image-20250811134812601

 

Select the Petalinux tool arm- sstate-cache:

image-20250811135409751

image-20250811135440321

Copy the downloaded compressed packages to the virtual machine and extract them. Here we choose to extract them to /home/mind/petalinux-downloads:

image-20250708141924947

Select the bottom option "Yocto Settings —>":

image-20250708142626192

 

In the "Yocto Settings —>" interface, deselect "Enable Network sstate feeds" and select "Enable BB NO NETWORK". Because we have already downloaded the required packages locally, there is no need to connect to the internet during compilation, which can shorten the compilation time.

Note: Even if offline compilation is set up, the Ubuntu system must be able to connect to the network when building the project, as Petalinux needs to download some source code from GitHub.

image-20250708143753844

Set the path for the "sstate_aarch64" package. Select the "Local sstate feeds settings —>" option on this page and configure the path where the corresponding extracted files are located.

image-20250708160707544

image-20250708143851198

Set the path for the "downloads" package. First select the < Exit > option to return to the interface shown below, then select the "Add pre-mirror url —>" option: file:/// must be added before this path.

image-20250708144003442

image-20250708144036650

Changing the Filesystem Type

On the initial page, select Image Packaging Configuration ---->

 

image-20250708161228286

The first option is the configuration of the root filesystem type, which defaults to INITRD and can generally be left as default. If we need to run Ubuntu or Debian root filesystems, it needs to be configured as EXT4 (SD/eMMC/SATA/USB). For NFS mount boot, it needs to be configured as NFS. Here it is set to EXT4.

Note: The INITRD type root filesystem is completely new and unmodified every time the Linux system is restarted. This means that all modifications made after starting the system are lost after power-off, and the system will restart with the previous unmodified root filesystem. Choosing "EXT4" allows the root filesystem to be placed on an ext4 partition of an SD card or eMMC, so all modifications made after starting the system will not be lost after power-off.

"Copy final images to tftpboot" option: When a folder named tftpboot is created in the Ubuntu root directory, the project will automatically copy the relevant files to the /tftpboot directory after generating the image.

image-20250708161334786

 

Finally, click Save, Exit.

Burning the Image to the TF Card

After configuring the Petalinux project and executing the following commands, the kernel image and file system will be generated:

At this point, the following files are generated in the image/linux directory: BOOT.bin, boot.scr, image.ub, and rootfs.tar.gz. Next, the kernel image and file system need to be saved to the TF card.

Insert the TF card. At this time, you can check and select the connection location of the TF card at the bottom right corner of the virtual machine:

image-20250708171452626

Type "p" to see the current partition status.

Type "d" to delete a partition. If there are multiple partitions, you need to type "d" multiple times.

Type "p" again to see the current partition status. If the current partition is not a DOS partition, type "o" to change it to DOS.

Type "n" to create a partition. Type "p", then enter "1", "2048", and "+200M" in sequence.

Type "t" to set the partition type, then type "c" to set the type to "W95 FAT32 LBA".

Type "a" to set the partition as the boot partition.

Use the "n" command to allocate all remaining space to the second partition. Just press Enter directly.

Type "p" to check if there are two partitions. If everything is correct, type "w" to write the partition table to the TF card.

image-20250708145305669

image-20250715154826897

Creating and Using BSP Packages

Using Petalinux BSP packages, we can conveniently and quickly provide our verified Petalinux projects to others or use others' verified Petalinux projects. You only need to master two commands for creating and using BSP packages.

Use the following command to create a BSP package for the Petalinux project in the current terminal path:

Use the following command to create a Petalinux project using the BSP package in the current terminal path:

Note: If the project used to create the BSP package can be compiled successfully, then the project created using the BSP package can also be compiled directly.