Getting Started with PetaLinux


Introduction

This page provides a quick guide to setting up PetaLinux, downloading and building a premade project, and booting a Linux image on your target device.

Prerequisites

Prior to starting this guide, in addition to a basic familiarity with Linux, your system should have Vivado and Xilinx SDK installed. For more information see our Installing Vivado guide.

Software

  • Xilinx Vivado 2016.2*
    • Same version as your desired PetaLinux installation
  • Xilinx SDK
    • Same version as your vivado installation
  • A supported Linux OS
    • Includes versions of Cent, SUSE Enterprise, RHEL, and Ubuntu. Check the specific PetaLinux version documentation for exact release information.

Overview

PetaLinux is an embedded Linux development solution for Xilinx Zynq chips as well as for MicroBlaze designs. This guide will be using the 2016.2 versions of PetaLinux, SDK, and Vivado and will be targeting a Zynq powered board. Included below is a list of the commands available in PetaLinux and a brief description of their functionality. For more detailed information see the PetaLinux Command Line Reference*.

PetaLinux Commands
petalinux-create - Creates a PetaLinux project. This can be a blank template project or created from premade 3rd party resources.
petalinux-config - Initialize or update project's hardware configuration or configure kernel and/or file system settings.
petalinux-build - Build specific components or an entire Linux system for the PetaLinux project (including FSBL, uboot, device tree, etc.)
petalinux-boot - Boots a specified Linux image either via JTAG onto hardware or QEMU software emulator.
petalinux-package - Formats the PetaLinux project for a specified deployment method.
petalinux-util - Command that provides a variety of support services for PetaLinux workflows.

Setup

1. Download & Install

Once the download has completed, make a directory in which you would like the PetaLinux tools to be installed in. From your terminal, change directory (cd) into the directory the installer was downloaded into and run the installer with a specified path to the directory you just created.

mkdir PetaLinux
cd Downloads
./petalinux-v2016.2-final-installer.run ../PetaLinux

This is just one option of installation location. You can install PetaLinux into any (typical) directory and it will work fine.

2. Dependencies

As with many software development tools, there are a variety of dependencies that you will need to have in order for PetaLinux to operate. Many of the packages may already be installed on your computer.

PetaLinux operates using dependencies on 32-bit libraries, so including those specific libraries indicated is required in order for it to operate correctly. In addition, PetaLinux can utilize a tftp server to streamline the development process, but it is not a requirement for it to function. If you would like to utilize tftp functionality, tftpd-hpa should be included in your dependency downloads.

sudo apt-get install tofrodos iproute gawk (etc)

The list of dependencies for other Linux distributions can also be found in the PetaLinux documentation, starting on page 10.

3. Set up Bash and Source Settings

Vivado and PetaLinux settings. The PetaLinux tools require you to use 'bash' as your shell rather than 'dash', which is likely your default shell if you're running Ubuntu. To change this, just enter the following command, which will set your default from 'dash' to 'bash'.

sudo dpkg-reconfigure dash

The next thing to take care of will be to source the tools for PetaLinux to use within the terminal window. This includes the 'settings64.sh' and 'settings.sh' files in your Vivado and PetaLinux installation directories, respectively. To avoid needing to type the source commands into the shell every time, you can add a couple lines to the .bashrc script. For Ubuntu, this will be bash.bashrc located in the /etc directory.

sudo gedit /etc/bash.bashrc

Once you have the script open, add the two commands for sourcing the appropriate files. Note that the path indicated here may be different depending on where you have the programs installed.

source /home/nate/Documents/plnx/2015_4/petalinux-v2015.4-final/settings.sh
source /opt/Xilinx/Vivado/2015.4/settings64.sh

With the two lines added, save the changes and close the editor.


Usage

4. Create Project

To use PetaLinux you will need to have a PetaLinux project directory to work in. This can be done by cloning a git repository of a premade PetaLinux project, downloading a board support package (BSP), or by creating a new project.

  • 4.1 Git - Clone Repository

Choose or create a directory you would like to clone a PetaLinux project repository into. Use the git clone command to clone your chosen Digilent repository. The PetaLinux repositories provided by Digilent are ready to use PetaLinux project folder structures, so once you have cloned the repository it is ready to be used.

git clone https://github.com/Digilent/Arty-Z7-old.git
  • 4.2 Board Support Package (BSP)

To create a project from a BSP, download the file from your desired source (unzip if necessary) and enter the following command.

petalinux-create -t project -s /path/to/download.bsp

Here '-t' is equivalent to '–type' described in the previous step (its parameter should remain 'project') and '-s' is for source and should be followed with the absolute file path to the BSP you want to use.

5. Configure, Build, Package

To run configuration on the project type in the following command.

petalinux-config

This will initialize a configuration menu for your PetaLinux project. Make sure your terminal window is at least its default dimensions or the menu will fail to launch. There are a variety of boot options available to you depending your application. If you are using the Digilent repository then the default values in the configuration menu will be fine, so just select the 'Exit' option to leave the config menu. The configuration process will then continue on (this will take some time).

Once the configuration is complete, you will need to build your image by entering the following command.

petalinux-build

The execution of this command will also take a few minutes to complete, depending on your system. Once this is finished enter the following command.

petalinux-package --boot --force --fsbl ./images/linux/zynq_fsbl.elf --fpga ./images/linux/linux_bd_wrapper.bit --u-boot

After this completes you should have your BOOT.bin and U-boot files ready to go.


Boot Options

The SD card you use will need to have two partitions on it. I recommend an 8GB card with the first partition (your BOOT partition) formatted as a File Allocation Table (FAT) of 1GB, and the second partition (your rootfs partition) formatted as an ext4 for the remaining space on the card. You can use a utility such as fdisk or gparted in your terminal to do the formatting for your SD card.

Copy the BOOT.bin and image.ub files into the first partition of your SD card. You can do this from your PetaLinux project root directory with the following commands.

cp images/linux/BOOT.bin /media/BOOT
cp images/linux/image.ub /media/BOOT

Once your boot files have been copied into the BOOT partition of your SD card, copy the root file system into the second partition, your 'rootfs' partition, with the following command.

cp images/linux/rootfs.cpio /media/rootfs

*Note: the paths “/media/BOOT” and “/media/rootfs” may not be where your SD card is mounted, so you should modify the copy command accordingly.

Once the root file system and boot files have been copied to the two partitions of your SD card, cd into the rootfs partition of the SD card and run the following command. This will unpack the file system into the partition from the rootfs.cpio file.

sudo pax -rvf rootfs.cpio

Once the command has resolved, eject your SD card. *You may get a warning that the SD card is still in use. Closing your terminal window should release any lock on the media device and allow you to unmount(eject) the card.

Insert your SD card into your board and connect it to an appropriate external power supply (verify correct jumper settings and voltage rating of your supply). Connect the board to your computer and verify the device has been discovered using ls dev. Using a serial communication package of your choice (minicom, PuTTY, etc.) open up a terminal connection to your target device to verify your Linux build.