Objective: This article will present the Petalinux approach of building custom images for the Ultra96-V2 board. It will utilize hardware design files built on Vivado from the previous article.
Recommended Prerequisite articles to read
In the previous article, we generated the hardware design in Vivado. We can now use it as the base upon which our custom Linux image will run. Xilinx provides a GUI-based tool, Petalinux, for creating such an image. This article will give a detailed procedure from installation of the tool to using it to generate bootable images.
1. Installing Petalinux 2019.2
There are different versions of the tool available from the Xilinx repository. In this series I will be working with the 2019.2 version. Download the Petalinux 2019.2 Installer. In the realm of custom image building and Xilinx tools, this is a relatively small zip file of 7.92 GB!
First, if you had not followed the Vitis and Vivado installation tutorial, you will need to install the packages outlined in page 10 of the Petalinux guide UG1144. For what it’s worth, my work station is running on Ubuntu Linux 18.04 LTS.
We will create an installation folder. For consistency, I install all Xilinx tools under /tools/Xilinx directory. Hence we will make a directory here.
$sudo mkdir –p PetaLinux/2019.2
We can now install the PetaLinux tools. We need to note that PetaLinux tools cannot be installed as a root user. Hence make sure the installation directory is writable (after installation is complete, we can revert the directory to globally read-execute).
sudo chmod -R o+w PetaLinux
Go to the Downloads folder and make the installer executable:
chmod +x petalinux-v2019.2-final-installer.run
This will take quite some time (around 25 minutes). You will have to accept the license terms and to exit from the editor, type colon + q i.e. (:q) and press enter. This brings you back to the terminal to continue with the installation process.
You may encounter the following error during the installation process if you created the installation directory as sudo.
For more details, we can check the log in the path given
From the above log, it can be seen that the error is due to permission issues. To solve this, we need to make the installation directory to be user owned. The steps below illustrate this.
Once the directory ownership has been changed, repeat the installation process.
After this installation, we need to set up the PetaLinux working environment by sourcing the settings script as shown below. You need to source the settings.sh every time you want to launch petalinux flow in a new terminal.
Once PetaLinux Tools has been installed, we can create a directory where we will handle all the PetaLinux Projects. In my case, the directory is /home/zynq/PetaLinux_projects.
2. Project Creation
In the $PetaLinux_projects directory, we issue the petalinux-create project and petalinux-config —get-hw-description commands as shown below. The latter points to the hardware design file we created and exported in Vivado in the previous article, which is located in the project_5_petalinuxBase directory.
The petalinux-config will launch the GUI to configure the image properties as shown below
3. Petalinux GUI Menu configuration
The key and important properties to configure here are:
i) Serial interface: Ultra96 has the serial interface hardwired to UART1 on the zynq device. Hence set this as the primary stdin/stdout and a baudrate of 115200. This setting is accessible under AUTO Hardware Settings – > Serial Settings. This will help us to see the output of the boot process via a serial output and we can use serial terminal such as Tera Term on the host computer to view this output.
ii) Machine name: In the DTG settings, input the machine name to be zcu100-revc. This is the name that petalinux expects for Ultra96 boards. Hence its quite important as it will be crucial for the tools to generate the right device tree for the board.
iii) Kernel Bootargs: We need to modify the kernel command line by setting the following kernel bootargs:
earlycon clk_ignore_unused earlyprintk root=/dev/mmcblk0p2 rw rootwait
This is accessed under DTG Settings-> Kernel Bootargs -> user set kernel bootargs
The above steps are shown in the screenshots slider below:
After setting the above properties, we can exit the GUI by double-pressing ESC key.
The petalinux tool takes the above configurations and generates appropriate recipe files that will be used in the build process.
4. Configure root file system
Depending on your application, you may need to add more packages and libraries to your image. This is where customization comes in. To access the GUI for doing this, use the command: $petalinux-config –c rootfs
Similarly, the kernel can be modified by: $petalinux-config –c kernel
This launches the GUI and you can add the packages and image features that you need as shown in the slider below:
However, the purpose of this article is to present the flow for a minimum console-only image. Hence we don’t really need to add any package and features other than those already selected by default. Hence exit the GUI.
5. Build petalinux project
Once we have configured both the kernel and rootfs to our satisfaction, we can start the build process of compiling the custom image.
6. Prepare generated images for SD card
Once the build process is complete, we can find the generated image files under the images/linux directory has shown below
We need now to generate a single boot image from the above files. This is accomplished by the following command, which will generate the BOOT.BIN image. This is of the form:
petalinux-package –boot –fsbl <FSBL image> –fpga <FPGA bitstream> –u-boot <u-boot elf>
The commands details are found in the PetaLinux Tools Documentation.
For a console-only image, we need two files to be copied into the SD card: BOOT.bin and image.ub. In the image below, notice the newly generated BOOT.BIN file.
7. Partition SD Card for Ultra96-V2 Boot
Follow the instructions below to partition the SD card for proper booting. Essentially, you want to create two partitions for boot (vfat) and rootfs (ext4) respectively. First identify the SD card in your system: sudo fdisk –l. In my case, it’s recognized as /dev/sdb.
8. Copy images to SD card and boot Ultra-V2 Board
If the SD card has been properly partitioned, we can copy the BOOT.bin and image.ub into the boot partition.
Through a serial terminal, we can access the Ultra96. You need to connect the Ultra96 UART pod to your host machine: