Installing Ubuntu on Xilinx ZYNQ-7000 AP SoC Using PetaLinux

My other articles :

There are many tutorials for installing Ubuntu or Linaro distributions on ZYNQ Processing System, but most of them are outdated and some of them use cross compilation tools for building kernel and kernel modules which most of the beginners find difficult. And most of the tutorials use a specific hardware in the FPGA part, which we cannot change. When I first started working on installing Ubuntu on ZYNQ ZC702, I had to go through all of these methods to identify the task of each tool chain. Therefore, most easy and quick way to install Ubuntu on ZYNQ-7000 AP SoC using ZC702 evaluation kit, is documented below.

Introduction to PetaLinux

PetaLinux is a tool chain provided by Xilinx to generate Linux kernel images, root file systems and kernel modules for ZYNQ like embedded systems with programmable hardware(for different hardware designs in the FPGA section).

Using PetaLinux tool chain, we can easily build kernel and modules for ZYNQ PS without using separate cross compilation tools. One disadvantage of using PetaLinux is, each PetaLinux version comes with the specific Linux kernel version. For example PetaLinux 2016.4 comes with a default kernel version of 4.6.0. But there is a method provided by Xilinx to change the default kernel version used by Petalinux, you can easily find this by Googling.

Note : PetaLinux tool can generate U-Boot files, First Stage Boot Loader(FSBL) and BOOT.BIN for a specific hardware design. Same things can be done using Xilinx SDK.

Prerequisites

  1. PC with Linux installed (Preferably Ubuntu 16.04 or later)
  2. SD card ( 8 GB or bigger)
  3. SD card reader
  4. Xilinx ZYNQ ZC702 Evaluation Kit
  5. PC with Vivado 2014.4 or later installed

Start

I will briefly explain about installing PetaLinux and preparing the SD card for booting Linux. I have given more attention to using PetaLinux.

Update : I encountered the following type of error when executing PetaLinux commands on Ubuntu 16.04 at first

ERROR: linux-xlnx-4.6-xilinx+gitAUTOINC+2762bc9163-r0 do_menuconfig: Unable to spawn terminal screen:

This was solved by installing screen package using the following command

sudo apt-get install screen

I am not sure whats the cause for the error or how good a solution is this, I found this searching through web and it worked for me.

Step 1 : Install PetaLinux 2016.4

Download Link : https://www.xilinx.com/support/download/index.html/content/xilinx/en/downloadNav/embedded-design-tools/2016-4.html

Go to above link and select “PetaLinux 2016.4 Installer” and download. You will asked to create a Xilinx account if you haven’t already.

Follow the installation instructions for Petalinux 2016.4 which is included in its reference guide provided by Xilinx.

PetaLinux 2016.4 Reference Guide : https://www.xilinx.com/support/documentation/sw_manuals/xilinx2016_4/ug1144-petalinux-tools-reference-guide.pdf

Also download the workflow tutorial of PetaLinux 2016.4 provided by Xilinx, it will be used as a reference to the latter part of the article.

PetaLinux 2016.4 Workflow Tutorial : https://www.xilinx.com/support/documentation/sw_manuals/xilinx2016_4/ug1156-petalinux-tools-workflow-tutorial.pdf

Step 2 : Prepare SD card for booting Linux

This can be easily done with gparted application for Linux. In Ubuntu, open a terminal and type following command to start gparted.

sudo gparted

If gparted is not installed, you can install it using the following command.

sudo apt-get install gparted

Connect the SD card to the PC using SD card reader and start gparted using above command. Follow the steps below to prepare the SD card.

  • Select the SD card in gparted
  • Make sure its unmounted and delete the partition of the SD card so that it displays ‘unallocated’ in gparted
  • Right click the unallocated space and create a new partition with following settings, Free Space Proceeding (MiB): 4, New Size (MiB) : 512, File System : FAT32, Label : BOOT. Don’t change other settings and click Add to finish.
  • Right click the remaining unallocated space and create a new partition with following settings, Free Space Proceeding (MiB): 0, Free Space Following(MiB): 0, File System : ext4, Label : rootfs. Don’t change other settings and click Add to finish.
  • Apply all changes to create the partitions.

Step 3 : Create the Hardware Design

In this step I will use the most basic hardware design that the Linux can be booted in. There are also few hardware requirements for running Linux in Zynq-7000, according to the PetaLinux Workflow Tutorial I mentioned earlier. Those requirements are listed below,

  1. At least one Triple Timer Counter(TTC)
  2. External Memory controller with at least 32 MB of memory
  3. UART for serial console
  4. Optional : Non-volatile memory (QSPI Flash, SD/MMC)
  5. Optional : Ethernet (Required for Network access)

Its okay if you don’t understand each of these, I will explain how to create the basic hardware design with required components in following steps.

  • Open Vivado and create a new RTL project for ZYNQ-7 ZC702 Evaluation board.
  • Click ‘Create Block Design’ from the ‘Project Manager’ window
  • Add ‘ZYNQ7 Processing System’ IP from the ‘Add IP’ window
  • Connect FCLK_CLK0 output pin to M_AXI_GP0_ACLK input pin of ‘ZYNQ7 Processing System’ IP, after connecting it will be like the following figure.
  • Click ‘Run Block Automation’ from the designer assistance, after that it will look like the following.

Note : Running block automation adds the presets of the board to the design and usually it automatically sets all features required to run Linux on ZYNQ PS. But to make sure, we will check those features in the next step.

  • Double click the ZYNQ PS IP to open the Re-customize IP window and select Peripheral I/O Pins tab. Then check the configuration with the following figure.
  • After confirming the configuration, click OK to close the window
  • Right click the block design file, as in the following figure, and select ‘Create HDL Wrapper’. Tick “Let Vivado manage wrapper and auto-update” and click ok.
  • Synthesize the design and generate the bit stream
  • After bit stream is generated, go to File > Export > Export Hardware, tick Include bitstream and click OK.

From the above step, hardware description file(.hdf) of the created design, will be saved in the <project_name>.sdk folder in the project directory. Remember this directory, it will be needed for the next step.

Note : For the next step, above <project_name>.sdk folder must be in the same operating system as the one you installed PetaLinux. If you have done above step in a different operating system, simply copy the folder to the relevant operating system.

Step 4 : Generating kernel images for the designed hardware using PetaLinux

Open a terminal in the Linux OS that you installed PetaLinux and go to the directory that you want to create the PetaLinux project. I will name my PetaLinux project as ‘test_boot’.

  • Create the project ‘test_boot’ and enter the ‘test_boot’ folder
petalinux-create --type project --template zynq --name test_bootcd test_boot
  • If the previously generated .hdf file is at “/home/user/basic/basic.sdk/” directory,
petalinux-config --get-hw-description=/home/user/basic/basic.sdk/
  • Execute the following command to configure the project
petalinux-config

This will pop-up a window(shown in the following figure) to configure the project. There are few things that needs to be configured, in this window, in order to point the kernel to a custom root file system.

  1. Go to Subsystem AUTO Hardware Settings -> Advanced bootable images storage Settings -> boot image settings and set ‘image storage media’ option to ‘primary sd’
  2. Go to Subsystem AUTO Hardware Settings -> Advanced bootable images storage Settings -> kernel image settings and set ‘image storage media’ option to ‘primary sd’
  3. Go to Subsystem AUTO Hardware Settings -> Advanced bootable images storage Settings -> dtb image settings and set ‘image storage media’ option to ‘primary sd’
  4. Go to Image Packaging Configurations and set ‘Root filesystem type’ option to ‘SD card’

Select Exit and save the new configuration.

  • Run the following command to build the project and generate boot files
petalinux-build
  • After project is successfully built, run the following command to generate the BOOT.BIN file. (This is a single line command)
petalinux-package --boot --format BIN --fsbl ./images/linux/zynq_fsbl.elf --fpga ./images/linux/download.bit --u-boot

Note : In the above command, I have used the name ‘download.bit’ as the bit file name. Change the command according to your file name.

Step 5 : Downloading Ubuntu 16.04 LTS Root File System for Zynq

Important : You also can download and install Debian 9.2, which is lightweight compared to Ubuntu (I actually prefer Debian), using the following link (See the following reference link for more information): https://rcn-ee.com/rootfs/eewiki/minfs/debian-9.2-minimal-armhf-2017-10-07.tar.xz

Download the Ubuntu 16.04 rootfs using the following command. (Reference : https://eewiki.net/display/linuxonarm/Zynq-7000)

wget -c https://rcn-ee.com/rootfs/eewiki/minfs/ubuntu-16.04.2-minimal-armhf-2017-06-18.tar.xz

To verify the downloaded file, execute following two commands on the downloaded location

sha256sum ubuntu-16.04.2-minimal-armhf-2017-06-18.tar.xzffaf4c1ad3cace3a5ca841cbe97a84ab5e6a4d2a695ba620a0b4b3f3f7dcc01b  ubuntu-16.04.2-minimal-armhf-2017-06-18.tar.xz

After verifying, extract the contents using following command

tar xf ubuntu-16.04.2-minimal-armhf-2017-06-18.tar.xz

If the rootfs partition of the SD card is mounted at /media/rootfs, execute the following command to untar the Ubuntu root file system and copy it to rootfs partition and setting the permission.

sudo tar xfvp ./*-*-*-armhf-*/armhf-rootfs-*.tar -C /media/rootfs/sync
sudo chown root:root /media/rootfs/
sudo chmod 755 /media/rootfs/

Step 6 : Booting Linux on ZC702

Connect the prepared SD card to the PC and copy the contents of the “<petalinux_project_directory>/images/linux/” directory to the BOOT partition of the SD card

  • From the Petalinux project directory, run the following command to copy the kernel boot files to BOOT partition (If BOOT partition is mounted at /media/BOOT)
sudo cp ./images/linux/* /media/BOOT/
  • After copying is done, eject the both partitions of the SD card from the PC and insert it to ZC702 board.
  • Connect the mini-USB cable(comes with the board) to the UART port of the board and to your PC
  • Set the switch configuration of ZC702 to boot from SD card (Shown in the following figure)
Switch configuration of ZC702 to boot from SD card
  • Setup a serial terminal application in you PC (Minicom in Linux, putty in Windows) and Power on the board.
  • If all the things were successful, you will see Ubuntu booting up on ZC702 board, default username is ubuntu and the password is temppwd

All done, Enjoy Ubuntu on ZYNQ!

Please leave comments below if you face any problems.

Check my next article for using USB in Linux (for interfacing a webcam and USB tethering).

PS : I have put my mail if you don’t want to bother creating a Medium account. But I prefer if you comment here, its easier for me and others also can benefit from our discussions.

Email : chathura.abeyrathne.lk@gmail.com

LinkedIn : linkedin.com/in/chathuraniroshan

--

--