From 05dd69f09311681100eab362b2949ae957e85be1 Mon Sep 17 00:00:00 2001 From: STFleming Date: Tue, 6 Sep 2022 11:48:50 +0100 Subject: [PATCH] Adding support for the KR260 --- README.md | 41 ++++++++-- install.sh | 229 +++++++++++++++++++++++++++++++++++++++-------------- pynq | 2 +- setup.py | 3 +- 4 files changed, 207 insertions(+), 68 deletions(-) diff --git a/README.md b/README.md index 11bd837..17d6068 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,28 @@ ![](./kriapynq.png) -This repository contains the install scripts needed to add PYNQ to your Kria KV260 Vision AI Starter Kit's official Ubuntu SDCard Image. From that installation, a complete Python and Jupyter environment is installed on the Kria SOM along with multiple programmable logic overlays all ready to use. +This repository contains the install scripts needed to add PYNQ to the official Ubuntu SDCard Image of your: +* Kria KV260 Vision AI Starter Kit +* Kria KR260 Robotic Starter Kit + +From that installation, a complete Python and Jupyter environment is installed on the Kria SOM along with multiple programmable logic overlays all ready to use. ## Installation #### 1. Get the Ubuntu SD Card Image -Follow the steps to [Get Started with Kria KV260 Vision AI Starter Kit](https://www.xilinx.com/products/som/kria/kv260-vision-starter-kit/kv260-getting-started-ubuntu/setting-up-the-sd-card-image.html) until you complete the [Booting your Starter Kit](https://www.xilinx.com/products/som/kria/kv260-vision-starter-kit/kv260-getting-started-ubuntu/booting-your-starter-kit.html) section + +#### KV260 +Follow the steps to [Get Started with Kria KV260 Vision AI Starter Kit](https://www.xilinx.com/products/som/kria/kv260-vision-starter-kit/kv260-getting-started-ubuntu/setting-up-the-sd-card-image.html) until you complete the [Booting your Starter Kit](https://www.xilinx.com/products/som/kria/kv260-vision-starter-kit/kv260-getting-started-ubuntu/booting-your-starter-kit.html) section. + +#### KR260 +Follow the steps to [Get Started with Kria KR260 Robotic Starter Kit](https://www.xilinx.com/products/som/kria/kr260-robotics-starter-kit/kr260-getting-started/setting-up-the-sd-card-image.html) until you complete the [Booting your Starter Kit](https://www.xilinx.com/products/som/kria/kr260-robotics-starter-kit/kr260-getting-started/booting-your-starter-kit.html) section. #### 2. Install PYNQ -Then install PYNQ on your Kria KV260 Vision AI Starter Kit. Simply clone this repository from the KV260 and run the install.sh script. +Then install PYNQ on your Kria device. Simply clone this repository from your Kria and run the install.sh script specifying the device with the `-b` flag. ```bash git clone https://github.com/Xilinx/Kria-PYNQ.git cd Kria-PYNQ/ -sudo bash install.sh +sudo bash install.sh -b { KV260 | KR260 } ``` This script will install the required debian packages, create Python virtual environment and configure a Jupyter portal. This process takes around 25 minutes. @@ -24,23 +33,39 @@ JupyterLab can now be accessed via a web browser `:9090/lab` or `kri ## Included Overlays -#### Base Overlay [\[GitHub\]](kv260/base) +#### Base Overlay [\[GitHub\]](kv260/base) This overlay includes support for the KV260's Raspberry Pi camera and PMOD interfaces. A [Digilent Pcam 5C](https://digilent.com/reference/add-ons/pcam-5c/start?redirect=1) camera can be attached to the KV260 and controlled from Jupyter notebooks. Additionally, a variety of Grove and PMOD devices are supported on the PMOD interface - all controllable from a Xilinx Microblaze processor in programmable logic. -#### DPU-PYNQ [\[GitHub\]](https://github.com/Xilinx/DPU-PYNQ) [\[PYPI\]](https://pypi.org/project/pynq-dpu/) -This overlay contains a Vitis-AI 1.4.0 Deep Learning Processor Unit (DPU) and comes with a variety of notebook examples with pre-trained ML models. +__Supported boards__: _KV260_ -#### Composable Pipeline [\[GitHub\]](https://github.com/Xilinx/PYNQ_Composable_Pipeline) +#### DPU-PYNQ (v2.5) [\[GitHub\]](https://github.com/Xilinx/DPU-PYNQ) [\[PYPI\]](https://pypi.org/project/pynq-dpu/) +This overlay contains a Vitis-AI 2.5.0 Deep Learning Processor Unit (DPU) and comes with a variety of notebook examples with pre-trained ML models. + +__Supported boards__: _KV260_, _KR260_ + +#### Composable Pipeline (v1.1 soft-release) [\[GitHub\]](https://github.com/Xilinx/PYNQ_Composable_Pipeline) The Composable pipeline is an overlay with a novel and clever architecture that allow us to adapt how the data flows between a series of IP cores. +__Supported boards__: _KV260_ + #### PYNQ-Helloworld [\[GitHub\]](https://github.com/Xilinx/PYNQ-HelloWorld) [\[PYPI\]](https://pypi.org/project/pynq-helloworld/) One of PYNQ's first overlays, the PYNQ-Helloworld overlay includes an image resizer block in programmable logic. This overlay demonstrates a simple but powerful use of programmable logic HLS blocks to do image processing. +__Supported boards__: _KV260_, _KR260_ + +## Selftest + +A self-test script for each board is generated at the end of the build. This test script runs some of the Overlay tests. To run the self-test navigate to the ``Kria-PYNQ`` install directory and run: +```bash +sudo ./selftest.sh +``` + ## References - [PYNQ](https://www.pynq.io) - [KV260 Vision AI Starter Kit](https://www.xilinx.com/products/som/kria/kv260-vision-starter-kit) +- [KR260 Robotic Starter Kit](https://www.xilinx.com/products/som/kria/kr260-robotics-starter-kit.html) - [Canonical Xilinx Ubuntu Images](https://ubuntu.com/download/xilinx) ---- diff --git a/install.sh b/install.sh index b6da246..2d06a6d 100755 --- a/install.sh +++ b/install.sh @@ -1,7 +1,6 @@ #!/bin/bash # Copyright (C) 2021 Xilinx, Inc -# # SPDX-License-Identifier: BSD-3-Clause set -e @@ -17,28 +16,71 @@ if [ "$EUID" -ne 0 ] exit fi +#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# Input Arguments +#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +USAGE="${RED} usage: ${NC} sudo ./install -b '{KV260 | KR260}'" + +if [ "$#" -ne 2 ]; then + echo -e $USAGE + exit 0 +fi + +while getopts b: flag +do + case "${flag}" in + b) board=${OPTARG};; + *) echo -e $USAGE; exit 0;; + esac +done + +case $board in + "KV260") echo -e ;; + "KR260") echo -e ;; + *) echo -e $USAGE; exit 0;; +esac +#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo -e "${GREEN}Installing PYNQ, this process takes around 25 minutes ${NC}" +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +# Autorestart services +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +sudo sed -i 's/#$nrconf{restart} = '"'"'i'"'"';/$nrconf{restart} = '"'"'a'"'"';/g' /etc/needrestart/needrestart.conf +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +echo -e "${YELLOW} Extracting archive pynq-v3.0-binaries.tar.gz${NC}" +# Get the pynq binaries +wget https://www.xilinx.com/bin/public/openDownload?filename=pynq-v3.0-binaries.tar.gz -O /tmp/pynq-v3.0-binaries.tar.gz +pushd /tmp +if [ $(file --mime-type -b pynq-v3.0-binaries.tar.gz) != "application/gzip" ]; then + echo -e "${RED}Could not extract pynq binaries, is the tarball named correctly?${NC}\n" + exit +fi +tar -xvf pynq-v3.0-binaries.tar.gz +popd + ARCH=aarch64 HOME=/root PYNQ_JUPYTER_NOTEBOOKS=/home/$LOGNAME/jupyter_notebooks -BOARD=KV260 +BOARD=$board PYNQ_VENV=/usr/local/share/pynq-venv # Get PYNQ SDbuild Packages +git config --global --add safe.directory $(pwd) +git config --global --add safe.directory $(pwd)/pynq if [ -d ".git/" ] then git submodule init && git submodule update else rm -rf pynq/ - git clone https://github.com/Xilinx/PYNQ.git -b image_v2.7 --depth 1 pynq + git clone https://github.com/Xilinx/PYNQ.git --branch v3.0.1 --depth 1 pynq fi # Stop unattended upgrades to prevent apt install from failing systemctl stop unattended-upgrades.service - # Wait for Ubuntu to finish unattended upgrades while [[ $(lsof -w /var/lib/dpkg/lock-frontend) ]] || [[ $(lsof -w /var/lib/apt/lists/lock) ]] do @@ -49,32 +91,43 @@ done # Install Required Debian Packages apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 \ --verbose 803DDF595EA7B6644F9B96B752150A179A9E84C9 -echo "deb http://ppa.launchpad.net/ubuntu-xilinx/updates/ubuntu focal main" > /etc/apt/sources.list.d/xilinx-gstreamer.list +echo "deb http://ppa.launchpad.net/ubuntu-xilinx/updates/ubuntu jammy main" > /etc/apt/sources.list.d/xilinx-gstreamer.list apt update apt-get -o DPkg::Lock::Timeout=10 update && \ -apt-get install -y python3.8-venv python3-cffi libssl-dev libcurl4-openssl-dev \ +apt-get install -y python3.10-venv python3-cffi libssl-dev libcurl4-openssl-dev \ portaudio19-dev libcairo2-dev libdrm-xlnx-dev libopencv-dev python3-opencv graphviz i2c-tools \ fswebcam # Install PYNQ Virtual Environment -pushd pynq/sdbuild/packages/python_packages_focal +pushd pynq/sdbuild/packages/python_packages_jammy mkdir -p $PYNQ_VENV cat > $PYNQ_VENV/pip.conf <> /etc/profile.d/pynq_venv.sh echo "export BOARD=$BOARD" >> /etc/profile.d/pynq_venv.sh echo "export XILINX_XRT=/usr" >> /etc/profile.d/pynq_venv.sh source /etc/profile.d/pynq_venv.sh +# Check to makesure that we are in the venv before proceeding. +if [[ "$VIRTUAL_ENV" == "" ]] +then + echo "ERROR: could not enter the Pynq venv, stopping the installation" + exit 1 +fi + +# Installing PYNQ-Metadata +python3 -m pip install pynqmetadata==0.1.2 + +# Install PYNQ-Utils +python3 -m pip install pynqutils==0.1.1 # PYNQ JUPYTER pushd pynq/sdbuild/packages/jupyter @@ -82,40 +135,28 @@ pushd pynq/sdbuild/packages/jupyter ./qemu.sh popd - # PYNQ Allocator pushd pynq/sdbuild/packages/libsds ./pre.sh ./qemu.sh popd +# Install PYNQ-3.0.1 +python3 -m pip install pynq==3.0.1 -# PYNQ Python Package -python -m pip install pynq - - -# Get PYNQ Binaries (ublaze compiler and xclbinutils +## GCC-MB and XCLBINUTILS pushd /tmp -wget https://bit.ly/pynq_binaries_2_7 -O pynq_binaries.tar.gz -if [ $(file --mime-type -b pynq_binaries.tar.gz) != "application/gzip" ]; then - echo -e "${RED}Could not download pynq binaries, server may be down${NC}\n" - exit -fi - -tar -xf pynq_binaries.tar.gz -cp -r /tmp/pynq-v2.7-binaries/gcc-mb/microblazeel-xilinx-elf /usr/local/share/pynq-venv/bin/ +cp -r /tmp/pynq-v3.0-binaries/gcc-mb/microblazeel-xilinx-elf /usr/local/share/pynq-venv/bin/ echo "export PATH=\$PATH:/usr/local/share/pynq-venv/bin/microblazeel-xilinx-elf/bin/" >> /etc/profile.d/pynq_venv.sh -cp pynq-v2.7-binaries/xrt/xclbinutil /usr/local/share/pynq-venv/bin/ +cp /tmp/pynq-v3.0-binaries/xrt/xclbinutil /usr/local/share/pynq-venv/bin/ chmod +x /usr/local/share/pynq-venv/bin/xclbinutil popd - # define the name of the platform echo "$BOARD" > /etc/xocl.txt - # Compile pynq device tree overlay and insert it by default pushd dts/ make @@ -126,33 +167,47 @@ echo "python3 /usr/local/share/pynq-venv/pynq-dts/insert_dtbo.py" >> /etc/profil source /etc/profile.d/pynq_venv.sh popd -# Set up pynq pl_server -cp pynq/sdbuild/packages/pynq/pl_server.sh /usr/local/bin -cp pynq/sdbuild/packages/pynq/pl_server.service /lib/systemd/system -systemctl enable pl_server - -#Install base overlay -python3 -m pip install . - - -#Install PYNQ-HelloWorld -python3 -m pip install pynq-helloworld - +# =================== Notebooks =========================== +# Install example notebooks using the board +# flag to determine which packages are loaded +# onto which board. +# ========================================================= -# Install composable overlays -pushd /tmp -git clone https://github.com/Xilinx/PYNQ_Composable_Pipeline.git -python3 -m pip install PYNQ_Composable_Pipeline/ --no-use-pep517 -popd - - -# Install Pynq Peripherals -python3 -m pip install git+https://github.com/Xilinx/PYNQ_Peripherals.git +if [[ "$board" == "KV260" ]] +then + echo "KV260 notebooks" + #Install PYNQ-HelloWorld + python3 -m pip install pynq_helloworld --no-build-isolation + + #Install base overlay + python3 -m pip install . + + # Install composable overlays + pushd /tmp + rm -rf ./PYNQ_Composable_Pipeline + git clone https://github.com/Xilinx/PYNQ_Composable_Pipeline.git -b v1.1.0-dev + #git clone https://github.com/Xilinx/PYNQ_Composable_Pipeline.git + python3 -m pip install PYNQ_Composable_Pipeline/ --no-use-pep517 + popd + + # Install Pynq Peripherals + python3 -m pip install git+https://github.com/Xilinx/PYNQ_Peripherals.git + + # Install DPU-PYNQ + yes Y | apt remove --purge vitis-ai-runtime + python3 -m pip install pynq-dpu==2.5 --no-build-isolation +fi -# Install DPU-PYNQ -yes Y | apt remove --purge vitis-ai-runtime -python3 -m pip install pynq-dpu --no-use-pep517 +if [[ "$board" == "KR260" ]] +then + echo "KR260 notebooks" + #Install PYNQ-HelloWorld + python3 -m pip install pynq_helloworld --no-build-isolation + # Install DPU-PYNQ + yes Y | apt remove --purge vitis-ai-runtime + python3 -m pip install pynq-dpu==2.5 --no-build-isolation +fi # Deliver all notebooks yes Y | pynq-get-notebooks -p $PYNQ_JUPYTER_NOTEBOOKS -f @@ -160,40 +215,98 @@ yes Y | pynq-get-notebooks -p $PYNQ_JUPYTER_NOTEBOOKS -f # Copy additional notebooks from pynq cp pynq/pynq/notebooks/common/ -r $PYNQ_JUPYTER_NOTEBOOKS +# ========================================================= + # Patch notebooks sed -i "s/\/home\/xilinx\/jupyter_notebooks\/common/\./g" $PYNQ_JUPYTER_NOTEBOOKS/common/python_random.ipynb sed -i "s/\/home\/xilinx\/jupyter_notebooks\/common/\./g" $PYNQ_JUPYTER_NOTEBOOKS/common/usb_webcam.ipynb -for notebook in $PYNQ_JUPYTER_NOTEBOOKS/pynq_peripherals/*/*.ipynb; do + +for notebook in $PYNQ_JUPYTER_NOTEBOOKS/common/*.ipynb; do sed -i "s/pynq.overlays.base/kv260/g" $notebook sed -i "s/PMODB/PMODA/g" $notebook done +if [[ "$board" == "KV260" ]] +then + for notebook in $PYNQ_JUPYTER_NOTEBOOKS/pynq_peripherals/*/*.ipynb; do + sed -i "s/pynq.overlays.base/kv260/g" $notebook + sed -i "s/PMODB/PMODA/g" $notebook + done +fi + sed -i 's/Specifically a RALink WiFi dongle commonly used with \\n//g' $PYNQ_JUPYTER_NOTEBOOKS/common/wifi.ipynb sed -i 's/Raspberry Pi kits is connected into the board.//g' $PYNQ_JUPYTER_NOTEBOOKS/common/wifi.ipynb - # Patch microblaze to use virtualenv libraries -sed -i "s/opt\/microblaze/usr\/local\/share\/pynq-venv\/bin/g" /usr/local/share/pynq-venv/lib/python3.8/site-packages/pynq/lib/pynqmicroblaze/rpc.py +sed -i "s/opt\/microblaze/usr\/local\/share\/pynq-venv\/bin/g" /usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/lib/pynqmicroblaze/rpc.py +# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- # Remove unnecessary notebooks -rm -rf $PYNQ_JUPYTER_NOTEBOOKS/pynq_peripherals/app* $PYNQ_JUPYTER_NOTEBOOKS/pynq_peripherals/grove_joystick +# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- + +if [[ "$board" == "KV260" ]] +then + rm -rf $PYNQ_JUPYTER_NOTEBOOKS/pynq_peripherals/app* $PYNQ_JUPYTER_NOTEBOOKS/pynq_peripherals/grove_joystick +fi + +if [[ "$board" == "KR260" ]] +then + rm -rf $PYNQ_JUPYTER_NOTEBOOKS/common/zynq_clocks.ipynb + rm -rf $PYNQ_JUPYTER_NOTEBOOKS/common/overlay_download.ipynb +fi +# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- # Change notebooks folder ownership and permissions chown $LOGNAME:$LOGNAME -R $PYNQ_JUPYTER_NOTEBOOKS chmod ugo+rw -R $PYNQ_JUPYTER_NOTEBOOKS - -# Start Jupyter and pl_server services now +# Start Jupyter services systemctl start jupyter.service -systemctl start pl_server.service + +# Start the service for clearing the statefile on boot +cp pynq/sdbuild/packages/clear_pl_statefile/clear_pl_statefile.sh /usr/local/bin +cp pynq/sdbuild/packages/clear_pl_statefile/clear_pl_statefile.service /lib/systemd/system +systemctl enable clear_pl_statefile # Purge libdrm-xlnx-dev to allow `apt upgrade` apt-get purge -y libdrm-xlnx-dev apt-get purge -y libdrm-xlnx-amdgpu1 +# OpenCV +python3 -m pip install opencv-python +apt-get install ffmpeg libsm6 libxext6 -y + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# Selftest generation +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +python3 -m pip install pytest + +echo "#!/bin/bash" > selftest.sh +echo "if [ \"\$EUID\" -ne 0 ]" >> selftest.sh +echo " then echo -e \"\${RED}Please run as root\${NC}\"" >> selftest.sh +echo " exit" >> selftest.sh +echo "fi" >> selftest.sh +echo "source /etc/profile.d/pynq_venv.sh" >> selftest.sh + +if [[ "$board" == "KV260" ]] +then + echo "pushd /usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq_composable/runtime_tests" >> selftest.sh + echo "python3 -m pytest test_apps.py" >> selftest.sh + echo "python3 -m pytest test_composable.py" >> selftest.sh + echo "python3 -m pytest test_mmio_partial_bitstreams.py" >> selftest.sh + echo "popd" >> selftest.sh + echo "python3 -m pytest /usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq_dpu/tests" >> selftest.sh +fi + +if [[ "$board" == "KR260" ]] +then + echo "python3 -m pytest /usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq_dpu/tests" >> selftest.sh +fi +chmod a+x ./selftest.sh +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + # Ask to connect to Jupyter ip_addr=$(ip addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}') echo -e "${GREEN}PYNQ Installation completed.${NC}\n" echo -e "\n${YELLOW}To continue with the PYNQ experience, connect to JupyterLab via a web browser using this url: ${ip_addr}:9090/lab or $(hostname):9090/lab - The password is xilinx${NC}\n" - diff --git a/pynq b/pynq index 59515a9..a056b84 160000 --- a/pynq +++ b/pynq @@ -1 +1 @@ -Subproject commit 59515a9b5de6fad0ff0538bfc50010b16f53c9a8 +Subproject commit a056b8455f80a145839177102288e1f1d2b8ebe3 diff --git a/setup.py b/setup.py index 7e0f4c8..af67ba7 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,8 @@ import tempfile import urllib.request from glob import glob -from pynq.utils import build_py +#from pynq.utils import build_py +from pynqutils.setup_utils import build_py from setuptools import setup, find_packages