Run XRT (Xilinx Runtime) on Debian GNU / Linux for Ultra96 / Ultra96-V2 (Build)

Introduction

The author provides Debian GNU / Linux for Ultra96 / Ultra96-V2 (ZynqMP) 1. In addition, XRT (Xilinx Runtime) is an environment for running programs developed in the development environment (Vitis) provided by Xilinx on the platform 2.

Originally, XRT for MPSoC Edge Device works only in the Linux environment (Petalinux) provided by Xilinx, but the procedure for running XRT on Debian GNU / Linux for Ultra96 / Ultra96-V2 is included in some parts. I will explain them separately.

This article provides steps to build XRT for Debian GNU / Linux for Ultra96 / Ultra96-V2.

Caution

__ The Debian Package presented in this article is not official by Xilinx. __

Build XRT

Build environment

Building XRT for ZynqMP-FPGA-Linux is a bit tedious. A Linux distribution such as Ubuntu or CentOS is required to build XRT. Various development tools must be installed in the build. Furthermore, it is very troublesome to cross-compile for ARM64 with a PC as a host, probably to make a Debian Package.

So I run Ubuntu 18.04 on Ultra96-V2 and self-build on it. Ubuntu 18.04 for Ultra96-V2 is available at the following URL:

Download XRT

Download the XRT source code from the following URL.

[email protected]:~$ cd work
[email protected]:~/work$ git clone https://github.com/Xilinx/XRT
Cloning into 'XRT'...
remote: Enumerating objects: 30, done.
remote: Counting objects: 100% (30/30), done.
remote: Compressing objects: 100% (30/30), done.
remote: Total 43591 (delta 13), reused 7 (delta 0), pack-reused 43561
Receiving objects: 100% (43591/43591), 58.10 MiB | 2.57 MiB/s, done.
Resolving deltas: 100% (33849/33849), done.
Checking out files: 100% (1682/1682), done.
[email protected]:~/work$ cd XRT
[email protected]:~/work/XRT$

Modify some files to build XRT for ZynqMP-FPGA-Linux. So it's better to fork than to clone https://github.com/Xilinx/XRT directly.

Install the Debian Package required for build

Install the packages required for the build. Fortunately, XRT provides a script that installs the packages needed for the build.

If you run ./src/runtime_src/tools/scripts/xrtdeps.sh with super user privileges, the apt program will install the missing Debian Package.

[email protected]:~/work/XRT$ sudo ./src/runtime_src/tools/scripts/xrtdeps.sh
Installing packages...
Reading package lists... Done
Building dependency tree
Reading state information... Done
	:
(Omission)
	:
The following packages were automatically installed and are no longer required:
  libgl2ps1.4 libibverbs1 liblept5 libnetcdf-c++4 libnl-route-3-200
  libopencv-flann-dev libopencv-flann3.2 libopencv-ml-dev libopencv-ml3.2
  libopencv-photo-dev libopencv-photo3.2 libopencv-shape-dev
  libopencv-shape3.2 libopencv-ts-dev libopencv-video-dev libopencv-video3.2
  libtcl8.6 libtesseract4 libtk8.6 libxss1
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 26 not upgraded.

XRT changes

We'll make some modifications to the XRT build file, so create a branch. It is based on the latest commit (aac1e6871e95da47ccff4392d5849462bbd4ecad) of the master branch at this time (March 25, 2020).

[email protected]:~/work/XRT$ git checkout aac1e6871e95da47ccff4392d5849462bbd4ecad 
[email protected]:~/work/XRT$ git checkout -b 2019.2_Ultra96
Switched to a new branch '2019.2_Ultra96'

We'll make changes to this branch. For specific changes, see "XRT Changes" in the next chapter.

Here, we have prepared the changes as a patch file, so we will apply it. The patch file is available at the following URL.

Rename the package file

[email protected]:~/work/XRT$ patch -p1 < ../files/00-xrt.patch 
patching file src/CMake/cpackLin.cmake
[email protected]:~/work/XRT$ git add --update
[email protected]:~/work/XRT$ git commit -m "[add] linux flavor name to built debian package name"
[2019.2_Ultra96 9ff0a408] [add] linux flavor name to built debian package name
 1 file changed, 1 insertion(+), 1 deletion(-)

Removed cap on dependent Debian Package versions

[email protected]:~/work/XRT$ patch -p1 < ../files/01-xrt.patch 
patching file src/CMake/cpackLin.cmake
[email protected]:~/work/XRT$ git add --update
[email protected]:~/work/XRT$ git commit -m "[remove] upper limit of version of depend packages"
[2019.2_Ultra96 7e93ed34] [remove] upper limit of version of depend packages
 1 file changed, 1 insertion(+), 1 deletion(-)

Added XRT_EDGE_BUILD

[email protected]:~/work/XRT$ patch -p1 < ../files/02-xrt.patch 
patching file build/build.sh
patching file src/CMake/config/dkms-zocl/dkms.conf.in
patching file src/CMake/config/edge/postinst.in
patching file src/CMake/config/edge/prerm.in
patching file src/CMake/cpackLin.cmake
patching file src/CMake/dkms-edge.cmake
patching file src/CMake/nativeLnx.cmake
patching file src/CMakeLists.txt
patching file src/runtime_src/CMakeLists.txt
patching file src/runtime_src/core/CMakeLists.txt
patching file src/CMake/cpackLin.cmake
[email protected]:~/work/XRT$ git add --update
[email protected]:~/work/XRT$ git add src/CMake/config/dkms-zocl
[email protected]:~/work/XRT$ git add src/CMake/config/edge
[email protected]:~/work/XRT$ git add src/CMake/dkms-edge.cmake
[email protected]:~/work/XRT$ git commit -m "[add] XRT_EDGE_BUILD for MPSoC Edge"
[2019.2_Ultra96 95287c93] [add] XRT_EDGE_BUILD for MPSoC Edge
 10 files changed, 376 insertions(+), 10 deletions(-)
 create mode 100644 src/CMake/config/dkms-zocl/dkms.conf.in
 create mode 100644 src/CMake/config/edge/postinst.in
 create mode 100644 src/CMake/config/edge/prerm.in
 create mode 100644 src/CMake/dkms-edge.cmake

Added 10-zocl.rules

[email protected]:~/work/XRT$ patch -p1 < ../files/03-xrt.patch 
patching file src/CMake/config/edge/postinst.in
patching file src/CMake/dkms-edge.cmake
patching file src/runtime_src/core/edge/drm/zocl/10-zocl.rules
[email protected]:~/work/XRT$ git add --update
[email protected]:~/work/XRT$ git add src/runtime_src/core/edge/drm/zocl/10-zocl.rules
[email protected]:~/work/XRT$ git commit -m "[add] 10-zocl.rules for udev"
[2019.2_Ultra96 04a8069d] [add] 10-zocl.rules for udev
 3 files changed, 3 insertions(+)
 create mode 100644 src/runtime_src/core/edge/drm/zocl/10-zocl.rules

Build

Go to the build directory and run build.sh there with the "-edge" option to start the build. Ultra96 / Ultra96-V2 takes a lot of time. It took about an hour in my environment.

[email protected]:~/work/XRT$ cd build/
[email protected]:~/work/XRT/build$ ./build.sh -edge
cmake -DRDI_CCACHE=0 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_TOOLCHAIN_FILE= ../../src
-- The C compiler identification is GNU 8.3.0
-- The CXX compiler identification is GNU 8.3.0
-- Check for working C compiler: /usr/bin/gcc-8
-- Check for working C compiler: /usr/bin/gcc-8 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/g++-8
-- Check for working CXX compiler: /usr/bin/g++-8 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Host system processor is aarch64
-- Target system processor is aarch64
	:
(Omission)
	:
[email protected]:~/work/XRT/build$ 

When the build is finished, you will have a Debian Package under the build / Edge directory.

[email protected]:~/work/XRT$ cd build/
[email protected]:~/work/XRT/build$ ls -1 Edge/xrt_*
Edge/xrt_202010.2.6.0_Ubuntu_18.04-arm64-xbtest.deb
Edge/xrt_202010.2.6.0_Ubuntu_18.04-arm64-xbtest.tar.gz
Edge/xrt_202010.2.6.0_Ubuntu_18.04-arm64-xrt.deb
Edge/xrt_202010.2.6.0_Ubuntu_18.04-arm64-xrt.tar.gz

Of these, the Debian Package required for Ultra96 / Ultra96-V2 is Edge / xrt_202010.2.6.0_Ubuntu_18.04-arm64-xrt.deb.

XRT changes

This chapter describes my own changes to the original XRT.

Rename the package file

In the original XRT, the Debian Package you built would be named xrt_202010.2.6.0_18.04-arm64-xrt.deb, but to make it clear that it is a package for Ubuntu xrt_202010.2.6.0_Ubuntu_18.04- Make it arm64-xrt.deb.

ZynqMP-FPGA-XRT/files/00-xrt.patch


diff --git a/src/CMake/cpackLin.cmake b/src/CMake/cpackLin.cmake
index 4f45f97a..9f6eebe4 100644
--- a/src/CMake/cpackLin.cmake
+++ b/src/CMake/cpackLin.cmake
@@ -79,7 +79,7 @@ else ()
   SET (CPACK_GENERATOR "TGZ")
 endif()
 
-SET(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}_${XRT_VERSION_RELEASE}.${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}_${CPACK_REL_VER}-${CPACK_ARCH}")
+SET(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}_${XRT_VERSION_RELEASE}.${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}_${LINUX_FLAVOR}_${CPACK_REL_VER}-${CPACK_ARCH}")
 
 message("-- ${CMAKE_BUILD_TYPE} ${PACKAGE_KIND} package")
 

Removed cap on dependent Debian Package versions

The original limits the versions of libboost-dev, libboost-filesystem-dev, and libc6 that the Debian Package you build depends on. If this is the case, the distribution to be installed may be too restrictive and the installation may fail. For example, trying to install this Debian Package on Debian 10 will fail.

So, which may be a problem later, modify cpackLin.cmake to remove the version limit as follows:

ZynqMP-FPGA-XRT/files/01-xrt.patch


diff --git a/src/CMake/cpackLin.cmake b/src/CMake/cpackLin.cmake
index 9f6eebe4..5b056580 100644
--- a/src/CMake/cpackLin.cmake
+++ b/src/CMake/cpackLin.cmake
@@ -49,7 +49,7 @@ if (${LINUX_FLAVOR} MATCHES "^(Ubuntu|Debian)")
   SET(CPACK_DEBIAN_PACKAGE_SHLIBDEPS "OFF")
   SET(CPACK_DEBIAN_AWS_PACKAGE_DEPENDS "xrt (>= ${XRT_VERSION_MAJOR}.${XRT_VERSION_MINOR}.${XRT_VERSION_PATCH})")
   SET(CPACK_DEBIAN_XBTEST_PACKAGE_DEPENDS "xrt (>= ${XRT_VERSION_MAJOR}.${XRT_VERSION_MINOR}.${XRT_VERSION_PATCH}), libjson-glib-dev")
-  SET(CPACK_DEBIAN_XRT_PACKAGE_DEPENDS "ocl-icd-opencl-dev (>= 2.2.0), libboost-dev (>= ${Boost_VER_STR}), libboost-dev (<< ${Boost_VER_STR_ONEGREATER}), libboost-filesystem-dev (>=${Boost_VER_STR}), libboost-filesystem-dev (<<${Boost_VER_STR_ONEGREATER}), uuid-dev (>= 2.27.1), dkms (>= 2.2.0), libprotoc-dev (>=2.6.1), libssl-dev (>=1.0.2), protobuf-compiler (>=2.6.1), libncurses5-dev (>=6.0), lsb-release, libxml2-dev (>=2.9.1), libyaml-dev (>= 0.1.6), libc6 (>= ${GLIBC_VERSION}), libc6 (<< ${GLIBC_VERSION_ONEGREATER}), python (>= 2.7), python-pip, libudev-dev ")
+  SET(CPACK_DEBIAN_XRT_PACKAGE_DEPENDS "ocl-icd-opencl-dev (>= 2.2.0), libboost-dev (>= ${Boost_VER_STR}), libboost-filesystem-dev (>=${Boost_VER_STR}), uuid-dev (>= 2.27.1), dkms (>= 2.2.0), libprotoc-dev (>=2.6.1), libssl-dev (>=1.0.2), protobuf-compiler (>=2.6.1), libncurses5-dev (>=6.0), lsb-release, libxml2-dev (>=2.9.1), libyaml-dev (>= 0.1.6), libc6 (>= ${GLIBC_VERSION}), python (>= 2.7), python-pip, libudev-dev ")
 
 elseif (${LINUX_FLAVOR} MATCHES "^(RedHat|CentOS|Amazon)")
   execute_process(

Added XRT_EDGE_BUILD

Originally, the variable XRT_NATIVE_BUILD is set to "yes" if the host and target processors are the same. And when XRT_NATIVE_BUILD is "yes" (when the host processor and target processor are the same), src / runtime_src / core / pcie is when "no" (when the host processor and target processor are different), src / runtime_src / core src / runtime_src / core / CMakeLists.txt is defined to build / edge.

src/runtime_src/core/CMakeLists.txt


include_directories(
  ${CMAKE_CURRENT_SOURCE_DIR}
  )
add_subdirectory(include)
add_subdirectory(common)
 if (${XRT_NATIVE_BUILD} STREQUAL "yes")
   add_subdirectory(pcie)
   add_subdirectory(tools)
 else()
   add_subdirectory(edge)
 endif()

In addition, src / CMake / nativeLnx.cmake, which is included when XRT_NATIVE_BUILD is "yes" (when the host processor and target processor are the same), builds and installs the driver for the host as follows. I will.

src/CMake/nativeLnx.cmakext


	:
	(Omission)
	:
include (CMake/dkms.cmake)
include (CMake/dkms-aws.cmake)
include (CMake/dkms-azure.cmake)
include (CMake/dkms-container.cmake)
	:
	(Omission)

If you run Ubuntu 18.04 on Ultra96-V2 and self-build on it, the host and target processors will be on the same arm64. If left unchecked, it will be built for pcie instead of edge.

So add the XRT_EDGE_BUILD variable to src / CMakfile.txt as follows:

src/CMakeLists.txt


	:
	(Omission)
	:	
set(XRT_EDGE_BUILD "no")
if (XRT_NATIVE_BUILD STREQUAL "no")
  set(XRT_EDGE_BUILD "no")
endif()
if (DEFINED ENV{XRT_EDGE_BUILD})
  set(XRT_EDGE_BUILD $ENV{XRT_EDGE_BUILD})
endif():
	:
	(Omission)

And if XRT_EDGE_BUILD is "yes", modify each file to build for edge.

src/runtime_src/core/CMakeLists.txt


include_directories(
  ${CMAKE_CURRENT_SOURCE_DIR}
  )
add_subdirectory(include)
add_subdirectory(common)
 if (${XRT_EDGE_BUILD} STREQUAL "yes")
   add_subdirectory(edge)
 else()
   add_subdirectory(pcie)
   add_subdirectory(tools)
 endif()

src/CMake/nativeLnx.cmakext


	:
	(Omission)
	:
if (${XRT_EDGE_BUILD} STREQUAL "yes")
  include (CMake/dkms-edge.cmake)
else()
  include (CMake/dkms.cmake)
  include (CMake/dkms-aws.cmake)
  include (CMake/dkms-azure.cmake)
  include (CMake/dkms-container.cmake)
endif()
	:
	(Omission)

Then add the driver (zocl) for edge to the Debian package and add the following files to build using dkms during installation.

Also, when XRT_NATIVE_BUILD is "yes" (when the host processor and target processor are the same), there is a setting in src / runtime_src / CMakeLists.txt that adds "-Wall" and-"Werror" to the compile options. ..

src/runtime_src/CMakeLists.txt


	:
	(Omission)
	:
# TODO CL_TARGET_OPENCL_VERSION is not defined..
if (${XRT_NATIVE_BUILD} STREQUAL "yes")
  add_compile_options("-Wall" "-Werror")
endif()
	:
	(Omission)

If there is a "-Werror" option, an error will occur when building under src / runtime_src / core / edge and compilation will fail. Therefore, when XRT_EDGE_BUILD is "yes", modify src / runtime_src / CMakeLists.txt so that "-Wall" and "-Werror" are not added to the compile options.

src/runtime_src/CMakeLists.txt


	:
	(Omission)
	:
# TODO CL_TARGET_OPENCL_VERSION is not defined..
if (${XRT_EDGE_BUILD} STREQUAL "no")
  add_compile_options("-Wall" "-Werror")
endif()	:
	(Omission)

Finally, modify build / build.sh so that XRT_EDGE_BUILD is "yes" if the host processor is arm64 and the "-edge" option is added.

build/build/sh


	:
	(Omission)
	:
f [[ $CPU == "aarch64" ]] && [[ $edge == 1 ]]; then
  mkdir -p $edge_dir
  cd $edge_dir
  if [[ $nocmake == 0 ]]; then
    echo "$CMAKE -DRDI_CCACHE=$ccache -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT\\
_COMPILE_COMMANDS=ON ../../src"
    time env XRT_EDGE_BUILD=yes $CMAKE -DRDI_CCACHE=$ccache -DCMAKE_BUILD_TYPE=\\
Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ../../src
  fi
  if [[ $docs == 1 ]]; then
    echo "make xrt_docs"
    make xrt_docs
  else
    echo "make -j $jcore $verbose DESTDIR=$PWD"
    time make -j $jcore $verbose DESTDIR=$PWD
    time ctest --output-on-failure
    time make package
  fi
  cd $BUILDDIR
fi
	:
	(Omission)

Added 10-zocl.rules

Change the permissions so that zocl can be written by the user. Specifically, add the following 10-zocl.rules to /etc/udev/rule.d.

Shell:/etc/udev/rule.d/10-zocl.rules


KERNEL=="renderD*",MODE="0666"

Make sure 10-zocl.rules is installed in /etc/udev/rule.d when you install the Debian Package.

ZynqMP-FPGA-XRT/files/03-xrt.patch


diff --git a/src/CMake/config/edge/postinst.in b/src/CMake/config/edge/postinst.in
index 22136c09..b85a1032 100644
--- a/src/CMake/config/edge/postinst.in
+++ b/src/CMake/config/edge/postinst.in
@@ -48,6 +48,7 @@ echo "Invoking DKMS common.postinst for xrt"
 /usr/lib/dkms/common.postinst xrt @[email protected] "" "" $2
 if [ $? -eq 0 ]; then
     echo "Finished DKMS common.postinst"
+    install -m 644 /usr/src/[email protected][email protected]/driver/edge/drm/zocl/10-zocl.rules /etc/udev/rules.d
     echo "Loading new XRT Linux kernel modules"
     udevadm control --reload-rules
     modprobe zocl
diff --git a/src/CMake/dkms-edge.cmake b/src/CMake/dkms-edge.cmake
index d1d39750..61664945 100644
--- a/src/CMake/dkms-edge.cmake
+++ b/src/CMake/dkms-edge.cmake
@@ -38,6 +38,7 @@ SET (XRT_DKMS_CORE_COMMON_DRV    ${XRT_DKMS_CORE_DIR}/common/drv)
 SET (XRT_DKMS_DRIVER_SRCS
   edge/drm/zocl/LICENSE
   edge/drm/zocl/Makefile
+  edge/drm/zocl/10-zocl.rules
   edge/drm/zocl/sched_exec.c
   edge/drm/zocl/sched_exec.h
   edge/drm/zocl/zocl_bo.c
diff --git a/src/runtime_src/core/edge/drm/zocl/10-zocl.rules b/src/runtime_src/core/edge/drm/zocl/10-zocl.rules
new file mode 100644
index 00000000..11ed38e1
--- /dev/null
+++ b/src/runtime_src/core/edge/drm/zocl/10-zocl.rules
@@ -0,0 +1 @@
+KERNEL=="renderD*",MODE="0666"

reference

[Overview]: https://qiita.com/ikwzm/items/0d3a8adfe725cd17f932 "" Running XRT (Xilinx Runtime) on Debian GNU / Linux for Ultra96 / Ultra96-V2 (Overview) "@Qiita" [Build]: https://qiita.com/ikwzm/items/d8013ea91125a3fc46aa "Running XRT (Xilinx Runtime) on Debian GNU / Linux for Ultra96 / Ultra96-V2 (Build)" @Qiita " [Installation]: https://qiita.com/ikwzm/items/6612eacc4a0d324a0a68 "" Running XRT (Xilinx Runtime) on Debian GNU / Linux for Ultra96 / Ultra96-V2 (Installation) "@Qiita" [Practice]: https://qiita.com/ikwzm/items/58cfea3f9d0f42840511 "" Running XRT (Xilinx Runtime) on Debian GNU / Linux for Ultra96 / Ultra96-V2 (Practice) "@Qiita" [Vitis Edition]: https://qiita.com/ikwzm/items/e70d8d0e44fe3784a708 "" Running XRT (Xilinx Runtime) on Debian GNU / Linux for Ultra96 / Ultra96-V2 (Vitis Edition) "@Qiita" ["Debian GNU / Linux (v2019.2 version) boot image for UltraZed / Ultra96 / Ultra96-V2" @Qiita]: https://qiita.com/ikwzm/items/92221c5ea6abbd5e991c "" UltraZed / Ultra96 / Ultra96- Debian GNU / Linux for V2 (v2019.2 version) Providing boot image "@Qiita"

Recommended Posts

Run XRT (Xilinx Runtime) on Debian GNU / Linux for Ultra96 / Ultra96-V2 (Build)
Run XRT (Xilinx Runtime) on Debian GNU / Linux for Ultra96 / Ultra96-V2 (Build) [Unfinished]
Run XRT (Xilinx Runtime) on Debian GNU / Linux for Ultra96 / Ultra96-V2 (Installation)
Run XRT (Xilinx Runtime) on Debian GNU / Linux for Ultra96 / Ultra96-V2 (Installation) [Unfinished]
Run XRT (Xilinx Runtime) on Debian GNU / Linux for Ultra96 / Ultra96-V2 (Vitis edition)
Running XRT (Xilinx Runtime) on Debian GNU / Linux for Ultra96 / Ultra96-V2 (Overview)
Running XRT (Xilinx Runtime) on Debian GNU / Linux for Ultra96 / Ultra96-V2 (Practice)
Run Lima Driver on Debian GNU / Linux for Ultra96 / Ultra96-V2
Run X Window on Debian GNU / Linux for Ultra96 / Ultra96-V2 (LibMali)
Run X Window on Debian GNU / Linux for Ultra96 / Ultra96-V2 (Video Driver)
Run X Window on Debian GNU / Linux for Ultra96 / Ultra96-V2 (Gnome Desktop)
Run X Window on Debian GNU / Linux for Ultra96 / Ultra96-V2 (Mali Driver)
Running X Window on Debian GNU / Linux for Ultra96 / Ultra96-V2 (fbdev)
Running X Window on Debian GNU / Linux for Ultra96 / Ultra96-V2 (Overview)
Run bootgen on Debian GNU / Linux, Ubuntu
Debian GNU / Linux (v2019.2 version) boot image provided for UltraZed / Ultra96 / Ultra96-V2
Run Debian (Linux) & LXQt on Athlon 200GE (AMD)
Linux Kernel Build for DE10nano
Linux on Windows -1-: debian introduction
Run FreeBSD on Linux + qemu