Table of Contents
Motivation to Rebuild Pynq_Z1 Image
Porting a supported PYNQ platform from PYNQ github to a custom board can be very challenging. I am still in the middle of learning how to build a PYNQ image on a custom board. I did spend a couple of weeks to reproduce Pynq_Z1_v2.6 image. However, it was a dead end from my experiment since there were a lot of dependencies for building Pynq_Z1_v2.6 image are no longer supported by the repositories which were called by the cross-compiler tool chains/Make scripts. After I failed to rebuild Pynq_Z1_v2.6 image on Ubuntu 18.04 last month, I think it is good to share my experience about reproducing PYNQ v3.01 image in house.
This blog is going to share my journey to rebuild Pynq_Z1_v3.0.1 image on Ubuntu 20.04.
Rebuild Pynq_Z1 image
I installed Oracle VirtualBox 7.0 on Windows 10. I downloaded Vitis 2022.1 and Petalinux 2022.1 from AMD/Xilinx website. I also installed Ubuntu 20.04 on VirtuaBox 7.0 environment. I will only describe how I reproduced Pynq_Z1_v3.0.1.img on my PC in this blog post.
As my last blog mentioned, one of the valuable resources for learning PYNQ is PYNQ official documentation website (Ref[1]). PYNQ SD Card image section covered most of the contents to build PYNQ images. I started my journey after I read “Building the Image From Source” section of Ref[1]. I did not use vagrant software to configure the environment. I already validated Vitis 2022.1 and Petalinux 2022.1 on Ubuntu 20.04. If you don’t know how to install Vitis 2022.1 and Petalinux 2022.1 on Ubuntu, please google the topic. There are many blogs about this topic to help you with proper installation procedures.
1. Clone PYNQ Github
Log into Ubuntu 20.04 environment and create a folder at home directory. I named it as project_folder to instead of ./Projects/Zynq/Arty_Z7_20/PYNQ_image_build. Then clone PYNQ github as below first.
$ (Project_folder) git clone https://github.com/Xilinx/PYNQ.git
Get into PYNQ folder as below, then check out v3.0.1 branch.
$(project_folder)/PYNQ git checkout v3.0.1
2. Setup build environment
Properly setup environment is very important. The key file of that is setup_host.sh under (project_folder)/PYNQ/sdbuild/script.
There is one line of scripts at setup_host.sh from v3.0.1 Github checkout which is out of date. Please correct it as below. The link of qemu download was changed to https://download.qemu.org at this blog drafting time.
After saving the updated setup_host.sh, use this command as below to building cross-compiler tool chains for PYNQ. Please pay attention to where to start running the script.
$(project_folder ) ./sdbuild/scripts/setup_host.sh
It will take one hour or so to build the cross-compiler tool chains. The time might be varied depending on the PC features. Here is the snapshot of the location of the cross-compiler tool chains on the Ubuntu.
I updated .bashrc file for PATH environment variable as below for this project. The PATH was updated as this
export PATH=”/opt/crosstool-ng/bin:/opt/qemu/bin:$PATH”
Notes: .bashrc is located at /home/flyingbean on my Ubuntu.
Please run the command after updating .bashrc at the same directory of .bashrc.
$ source .bashrc
I can check PYNQ environment with this command:
$(project_folder ) ./sdbuild/scripts/check_env.sh
3. Download prebuilt files
Starting from PYNQ v3.0.1, prebuilt folder has to be setup before building PYNQ image.
There is no any file under ./sdbuild/prebuilt from PYNQ github checkout.
Two files will be added into prebuilt folder before running Make flow. Ref[2] for v3.0.1 listed the download link for the files: one is rootfs tarball, another is PYNQ source distribution binary.
Since it is Zynq FPGA, PYNQ rootfs arm v3.0.1 is needed for the project. The name for Zynq rootfs tarball is jammy.art.3.0.1.gz . I copied jammy.arm.3.0.1.gz and pynq-3.0.1.tar.gz into ./sdbuild/prebuilt folder as below.
However, the MAKE flow of PYNQ only accepts normalized names with .tar.gz format tarball. So I renamed both files as the guidance from Ref[1] as below.
$(project_folder )/PYNQ/sdbuild/prebuilt$ mv jammy.arm.3.0.1.gz pynq_rootfs.arm.tar.gz
$(project_folder )/PYNQ/sdbuild/prebuilt$ mv pynq-3.0.1.tar.gz pynq_sdist.tar.gz
4.Build PYNQ v3.0.1 image
A simple make script can handle the image build flow as below.
$(project_folder )/PYNQ/sdbuild $ make BOARDS=Pynq-Z1
The whole building time is around a few hours here.
If there is no error during the building flow, the above snapshot is the end of successfully building a PYNQ image.
The PYNQ image file is located at output folder under sdbuild directory.
Test Rebuilt Pynq_Z1_v3.0.1 Image
I burned the reproduce Pynq-Z1-3.0.1.img into another SD card and inserted it into Arty-Z7-20 platform. It booted same as the original PYNQ image. Two user application cases were tested as follows for the reproduced Pynq_Z1_v3.0.1 image.
1. OpenCV testing via HDMI/Webcam
OpenCV is the key feature for Z7_Color_AID project. I did test the sample code from PYNQ image: opencv_filters_webcam.ipynb.
opencv_filters_webcam.ipynb on Jupyter lab:
2. PYNQ/Jupyter audio library sample code for audio output on Arty_Z7_20
I planed to use the audio output for Z7_Color_AID project. It is time to test the feature of PYNQ/Jupyter audio library on Arty_Z7_20. The baseline file is audio_playback.ipynb from /base/audio folder inside the Pynq_Z1_v3.0.1 image.
There is no audio recording feature on Arty_Z7_20 platform. So I commented out the record routing at audio_playback.ipynb as below.
I downloaded a sample WAV file as the audio file for the audio port on Arty_Z7_20 platform. I used a speaker to play the sample WAV format audio now.
The beauty of the PYNQ/Jupyter audio library is that I can play the audio from Web Browser as well.
Here is the video recording of the audio feature on PYNQ/Arty_Z7_20.
There are more features from PYNQ audio library for the sample WAV file, such as amplitude plot on time domain, frequency domain, even audio signal spectrogram as below.
I am fully impressed by PYNQ/Jupyter audio library features.
From now on, I will use the rebuilt PYNQ images for my projects.
Future Path on PYNQ/Z7_Color_AID Project
I will present what I learned from PYNQ overlay features and PYNQ library structure for the development of Z7_Color_AID project in the future blogs.
References
[1] PYNQ SD Card image v3.1 https://pynq.readthedocs.io/en/latest/pynq_sd_card.html 2024
[2] https://www.pynq.io/boards.html 2024