UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 

Introduction To PetaLinux Part 2

Moderator
Moderator
4 0 460

Please Note: This blog uses tools tips. Anywhere you see an underlined word, hover over it to see an explanation!

 

Introduction

This Blog entry is a continuation of Introduction to PetaLinux Part 1. It is aimed at anyone who wants to get started with PetaLinux and learn about its key tools, concepts, and capabilities. In the first blog entry we looked at how to create a PetaLinux project and how to modify an image. In the second blog entry, we will continue with the project created in Part 1 and look at how to build the system image and boot it on a Zynq® UltraScale+™ ZCU102 evaluation kit.

I will run through the basic steps needed in this tutorial, however the scope of the blog is limited. You can find out more information about PetaLinux on the Xilinx website here

 

PetaLinux Design Flow:

In the first blog we went through section 1, outlined in the red circle below. We learned how to create a PetaLinux project and modify an image.

In this tutorial, we will build the image and load it onto our board (section 2 and section 3 in the diagram below). We will then test the board to see if the configuration was implemented as expected. 

pic1.PNG

 

 

Step 1 – Building the Image:

Procedure:

In this step we will build the image in order to convert it into a form that your board can run and understand. If you wish to skip this step, or have not completed Introduction to PetaLinux Part 1, you can download the built files attached to this blog entry.

 

The system can be built using just one command.

In your Linux terminal, move into your project directory using the cd command.

Build the image using the command below:

petalinux-build

 

Explanation:

 

1) Commands Run:

The petalinux-build command performs a number of steps automatically (listed below) to simplify the build process for the user.

However, alternatively the steps can be performed manually. If you wish you can execute them one-by-one, in the following order, instead of using the build command above.

Step 1:

petalinux-build -x bootloader

The First Stage Bootloader or FSBL is created. The FSBL will configure the processing sub-system, and will load the PL, and hand-off to the secondary bootloader (U-Boot).

Step 2:

petalinux-build -x pmufwls

The Programmable Management Unit Firmware, or PMUFW is built. The PMUFW controls the power-up, and monitoring of resources within the system.

Step 3:

petalinux-build -x arm-trusted-firmware

The ARM Trusted Firmware, or ATF is built. The ATF provides a reference to secure software for the ARMv8 architecture.

Step 4:

petalinux-build -x device-tree

The devicetree is built. The devicetree is created using a Tcl based tool called the Device Tree Generator (DTG) which uses the HSI utilities to create the devicetree nodes.

The DTG is built into PetaLinux. Petalinux uses the Hardware Description File (HDF) as an input into the DTG. The HDF describes the HW to the DTG. If no HDF is provided, then PetaLinux will use a default based on the template (ZynqMP in this case). The devicetree is used to describe the HW to the kernel.

Step 5:

petalinux-build -x u-boot

The U-Boot is built during this step. The U-Boot is an open source application that is used to boot the kernel. PetaLinux will use a specific branch (version) of the U-Boot that contains additional information for Xilinx development boards; defconfig, and devicetree information.

Users can also build individual components on their own (for example the device-tree) using the prepend -x <component> command.

2) Files Added:

Once the petalinux-build command is complete, the following files (of note) are added to the <project root>/images/linux folder:

  • image.ub
    • Note the .ub extension. There is an mkimage utility in the U-Boot tool that will add header information to the kernel image that is used by the U-Boot application in the booting of the kernel.
  • zynqmp_fsbl.elf
  • pmu.elf (or pmufw.elf in newer versions of Petalinux)
  • u-boot.elf
  • bl31.elf (this is the ATF)
  • design_1_wrapper.bit (or system.bit in newer versions of PetaLinux)

     

pic2.png

 

 

Step 2 – Packaging the Files

The key files built in the previous step need to be packaged into a bootable image for the board to be able to run (an SD image in this case). There is a petalinux-package command that will use the bootgen utility to create the SD boot image.  

If you wish to skip this step, or have not completed Introduction to PetaLinux Part 1, you can download the files attached to this blog.

cd images/linux
petalinux-package --boot --fsbl zynqmp_fsbl.elf --fpga system.bit --u-boot

or

petalinux-package --boot --fsbl zynqmp_fsbl.elf --fpga design_1_wrapper.bit --u-boot

 

pic5.PNG

 

Step 3 – Booting Linux on a ZCU102 board:

In this section we will learn how to put our Petalinux project files onto our ZCU102 board.

In order to work, our board needs two files, the BOOT.bin file and the image.ub file.

 

Procedure:

Copy the BOOT.bin, and the image.ub (available in <project root>/images/linux) from your computer onto an SD card and place this in the SD card slot on the ZCU102 board. If you did not complete the previous steps, the image and boot files are attached to this blog.

Adjust the boot mode pins on the ZCU102 board (Switch SW6), so that they are set to SD mode. For more info on the ZCU102 board and how to set it up, please see the user guide here.

 

pic6.png

 

000.png

 

Connect the UART from the ZCU102 to the computer so that you can see the output of the board.

Power on the board.

Open a terminal communication software (such as TeraTerm) on your computer to see the output from the board.

If you are unsure of how to set up up your board, it is explained in more detail in the user guide

 

You should see the following in the terminal output, as shown in the screen capture below:

  • FSBL Application (with Debug) execute
  • The ATF (ARM Trusted Firmware) execute
  • U-Boot execute, and load the image.ub, and execute
  • Kernel boot

 

Note: The default login/password is root

 

pic7.png

 

 

Step 4 - Exploring the kernel

In Introduction to PetaLinux Part 1, we designed our hardware in Verilog as can be seen in the diagram below. Because we used the pre-defined settings for the Zynq UltraScale+ PS, the PS GPIO is already enabled in the zynq_ultra_ps_e_0 IP (in the green box below).

We added an AXI GPIO and LEDs to the hardware, as can be seen in the red box in the diagram below.

Verilog Diag2.pngIn order to check if the board is configured correctly, in this step we will manually test the LEDs on the board.

 

Procedure:

1) Finding the AXI GPIO address:

First, we need to find the address of the AXI GPIO in order to be able to send signals to the LEDs.  

In the Linux console, from your root directory cd into the GPIO directory:

 cd /sys/class/gpio/

When you open the directory, you can use the ls command to see a number of GPIO chips, labelled ‘gpiochipXXXX’:

ls /sys/class/gpio

You will see the following output:

export  gpiochip330  gpiochip504  unexport

 

But how do we know which of these chips is associated with the AXI GPIO?  

To check, we need to look at the GPIO chips label:

cat /sys/class/gpio/gpiochip330/label

This will output the following:

zynqmp_gpio

 

This implies that it is the GPIO chip for the Zynq MP, which is not what we are looking for.

 

If we check the second chip's label:

cat /sys/class/gpio/gpiochip504/label

We get the following output:

/amba_pl@0/gpio@a0000000

 

The AMBA_PL name tells us that this is an AXI GPIO chip. The number after it is its address.

This is the GPIO chip we were looking for. We now know that the base pin number we need is 504, and that it has an offset address of 0. 

 

2) Toggling the LED

To toggle the AXI GPIO pin 0, use the commands below in your terminal communication software (for example, TeraTerm).

The formula for calculating the pin is as follows:

base_pin + offset, or 504 + 0 = 504

We will use Sysfs commands to control the LED. Sysfs is a pseudo file system provided by the Linux kernel. If you wish to learn more about these commands, please see Sysfs.

Type the following commands into your terminal communication software (for example, TeraTerm):

echo 504 > /sys/class/gpio/export (asks the kernel to export control of GPIO 504 to userspace)
echo out > /sys/class/gpio/gpio504/direction (initialises GPIO value as low)
echo 1 > /sys/class/gpio/gpio504/value (LED Turns ON)
echo 0 > /sys/class/gpio/gpio504/value (LED Turns OFF)
echo 504 > /sys/class/gpio/unexport (unexport control of GPIO 504 from userspace)

pic8.png

 

You should see the LED (DS38) on the board toggle on, and then off.

 

004.jpg

 

If you see the LED turn on and off then congratulations! Your PetaLinux project is now running on the board and was configured correctly.

If you wish to continue building on your PetaLinux knowledge, please feel free to explore the Xilinx website which contains plenty of great examples and articles on PetaLinux.