Skip to content

Commit f080356

Browse files
XRT-589 Enabling Cross Compilation of XRT (Xilinx#3729)
1 parent a91ca85 commit f080356

File tree

13 files changed

+531
-18
lines changed

13 files changed

+531
-18
lines changed

build/cross_compile.sh

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
error()
6+
{
7+
echo "ERROR: $1" 1>&2
8+
usage_and_exit 1
9+
}
10+
11+
usage()
12+
{
13+
echo "Usage: $PROGRAM [options] "
14+
echo " options:"
15+
echo " -help Print this usage"
16+
echo " -aarch Architecture <aarch32/aarch64>"
17+
echo " -sysroot Absolute path to sysroot of target architecture"
18+
echo " -compiler [optional] Path to 'gcc' cross compiler"
19+
echo " If not specified default paths in host will be searched"
20+
echo " -clean, clean Remove build directories"
21+
echo ""
22+
}
23+
24+
usage_and_exit()
25+
{
26+
usage
27+
exit $1
28+
}
29+
30+
SAVED_OPTIONS=$(set +o)
31+
# Don't print all commands
32+
set +x
33+
# Get real script by read symbol link
34+
THIS_SCRIPT=`readlink -f ${BASH_SOURCE[0]}`
35+
36+
PROGRAM=`basename $0`
37+
38+
BUILDDIR=$(readlink -f $(dirname ${BASH_SOURCE[0]}))
39+
CORE=`grep -c ^processor /proc/cpuinfo`
40+
CMAKE=cmake
41+
OS_HOST=`grep '^ID=' /etc/os-release | awk -F= '{print $2}' | tr -d '"'`
42+
43+
if [[ $OS_HOST == "centos" ]] || [[ $OS_HOST == "rhel" ]]; then
44+
CMAKE=cmake3
45+
if [[ ! -x "$(command -v $CMAKE)" ]]; then
46+
echo "$CMAKE is not installed, please install it"
47+
exit 1
48+
fi
49+
fi
50+
51+
clean=0
52+
jcore=$CORE
53+
54+
while [ $# -gt 0 ]; do
55+
case $1 in
56+
-help )
57+
usage_and_exit 0
58+
;;
59+
-aarch )
60+
shift
61+
AARCH=$1
62+
;;
63+
-sysroot )
64+
shift
65+
SYSROOT=$1
66+
;;
67+
-clean | clean )
68+
clean=1
69+
;;
70+
-compiler )
71+
shift
72+
COMPILER=$1
73+
;;
74+
--* | -* )
75+
error "Unregognized option: $1"
76+
;;
77+
* )
78+
error "Unregognized option: $1"
79+
;;
80+
esac
81+
shift
82+
done
83+
84+
edge_dir_aarch64="Edge_aarch64"
85+
edge_dir_aarch32="Edge_aarch32"
86+
toolchain="toolchain-edge.cmake"
87+
88+
here=$PWD
89+
cd $BUILDDIR
90+
91+
if [[ $clean == 1 ]]; then
92+
echo $PWD
93+
echo "/bin/rm -rf $edge_dir_aarch64 $edge_dir_aarch32"
94+
/bin/rm -rf $edge_dir_aarch64 $edge_dir_aarch32
95+
exit 0
96+
fi
97+
98+
# Sanity Check
99+
if [ -z $AARCH ] || [ -z $SYSROOT ] ; then
100+
error "Please provide the required options 'aarch', 'sysroot'"
101+
fi
102+
103+
if [ ! -d $SYSROOT ]; then
104+
error "SYSROOT is not accessible"
105+
fi
106+
107+
if [ $AARCH == "aarch64" ]; then
108+
mkdir -p $edge_dir_aarch64
109+
cd $edge_dir_aarch64
110+
elif [ $AARCH == "aarch32" ]; then
111+
mkdir -p $edge_dir_aarch32
112+
cd $edge_dir_aarch32
113+
AARCH="arm"
114+
else
115+
error "$AARCH not exist"
116+
fi
117+
118+
if [ -z $COMPILER ]; then
119+
echo "INFO: Path to gcc cross compiler is not specified, will be searched in default paths in host"
120+
if [ $AARCH == "aarch64" ]; then
121+
target_abi="linux-gnu"
122+
c_compiler="aarch64-${target_abi}-gcc"
123+
cxx_compiler="aarch64-${target_abi}-g++"
124+
else
125+
target_abi="linux-gnueabihf"
126+
c_compiler="arm-${target_abi}-gcc"
127+
cxx_compiler="arm-${target_abi}-g++"
128+
fi
129+
else
130+
c_compiler=$COMPILER
131+
dir=$(dirname "${COMPILER}")
132+
if [ $AARCH == "aarch64" ]; then
133+
cxx_compiler=${dir}/aarch64-linux-gnu-g++
134+
else
135+
cxx_compiler=${dir}/arm-linux-gnueabihf-g++
136+
fi
137+
fi
138+
139+
if [ ! -f ${SYSROOT}/etc/os-release ]; then
140+
#Use case for Petalinux Sysroot
141+
echo "INFO: OS Flavor of SYSROOT cannot be determined, generating RPM packages of XRT"
142+
OS_TARGET="CentOS"
143+
echo "INFO: Cross Compiling XRT for $AARCH"
144+
else
145+
OS_TARGET=`grep '^ID=' ${SYSROOT}/etc/os-release | awk -F= '{print $2}' | tr -d '"'`
146+
if [ $OS_TARGET == "ubuntu" ]; then
147+
OS_TARGET="Ubuntu"
148+
VERSION=`grep '^VERSION_ID=' ${SYSROOT}/etc/os-release | awk -F= '{print $2}' | tr -d '"'`
149+
else
150+
OS_TARGET=`cat ${SYSROOT}/etc/redhat-release | awk '{print $1}' | tr -d '"'`
151+
VERSION=`cat ${SYSROOT}/etc/redhat-release | awk '{print $4}' | tr -d '"'`
152+
fi
153+
echo "INFO: Cross Compiling XRT for $AARCH and Target System $OS_TARGET, Version:$VERSION"
154+
fi
155+
156+
echo "INFO: $CMAKE -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_TOOLCHAIN_FILE=$BUILDDIR/$toolchain -Daarch=$AARCH -Dsysroot=$SYSROOT -Dflavor=$OS_TARGET -Dversion=$VERSION -DCROSS_COMPILE=yes -DCMAKE_C_COMPILER=$c_compiler -DCMAKE_CXX_COMPILER=$cxx_compiler ../../src"
157+
158+
time env XRT_NATIVE_BUILD=no $CMAKE -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_TOOLCHAIN_FILE=$BUILDDIR/$toolchain -Daarch=$AARCH -Dsysroot:PATH=$SYSROOT -Dflavor=$OS_TARGET -Dversion=$VERSION -DCROSS_COMPILE=yes -DCMAKE_C_COMPILER=$c_compiler -DCMAKE_CXX_COMPILER=$cxx_compiler ../../src
159+
160+
echo "make -j $jcore DESTDIR=$PWD install"
161+
time make -j $jcore DESTDIR=$PWD install
162+
163+
time make package
164+
165+
eval "$SAVED_OPTIONS"; # Restore shell options
166+
echo "** COMPLETE [${BASH_SOURCE[0]}] **"
167+
echo ""
168+
cd $here

build/toolchain-edge.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
set(CPACK_PACKAGE_CONTACT "[email protected]")
2+
set(CMAKE_SYSTEM_NAME Linux)
3+
set(CMAKE_SYSTEM_PROCESSOR ${aarch})
4+
SET(CMAKE_SYSROOT ${sysroot})
5+
SET(CMAKE_FIND_ROOT_PATH ${sysroot})
6+
SET(ENV{PKG_CONFIG_SYSROOT_DIR} ${sysroot})
7+
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
8+
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
9+
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
10+
SET(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
PACKAGE_NAME="xrt-zocl"
2+
PACKAGE_VERSION="@XRT_VERSION_STRING@"
3+
MAKE[0]="cd driver/zocl; make -j KERNEL_SRC=${kernel_source_dir}; cd ../.."
4+
CLEAN="cd driver/zocl; make clean KERNEL_SRC=${kernel_source_dir}; cd ../.."
5+
BUILT_MODULE_NAME[0]="zocl"
6+
BUILT_MODULE_LOCATION[0]="driver/zocl"
7+
DEST_MODULE_LOCATION[0]="/kernel/extras"
8+
AUTOINSTALL="yes"

src/CMake/config/postinst-edge.in

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/sh
2+
3+
#
4+
# UBUNTU NOTE
5+
# -----------
6+
# 1. When downgrading (say from 2.3.0 to 2.2.0) then prerm of 2.3.0 is run
7+
# followed by postinst of 2.2.0. The prerm is invoked with "upgrade 2.2.0"
8+
# argument and postinst is invoked with "configure 2.3.0" argument.
9+
# 2. When upgrading (say from 2.2.0 to 2.3.0) then prerm of 2.2.0 is run
10+
# followed by postinst of 2.3.0. The prerm is invoked with "upgrade 2.3.0"
11+
# argument and postinst is invoked with "configure 2.2.0" argument.
12+
# 3. When re-installing (say from 2.2.0 to 2.2.0) then prerm of 2.2.0 is run
13+
# followed by postinst of 2.2.0. The prerm is invoked with "upgrade 2.2.0"
14+
# argument and postinst is invoked with "configure 2.2.0" argument.
15+
#
16+
# RHEL/CentOS NOTE
17+
# ----------------
18+
# 1. When downgrading (say from 2.3.0 to 2.2.0) then oddly postinst of 2.2.0
19+
# is run first followed by prerm of 2.3.0. The postinst is invoked with
20+
# "2" and prerm is invoked with "1".
21+
# 2. When upgrading (say from 2.2.0 to 2.3.0) then prerm of 2.2.0 is NOT run
22+
# but postinst of 2.3.0 is run. The postinst is invoked with "2" argument.
23+
# 3. When re-installing (say from 2.2.0 to 2.2.0) then prerm is NOT run but
24+
# and postinst of 2.2.0 is run. The postinst is invoked with "2" argument.
25+
26+
rmmodules()
27+
{
28+
find /lib/modules -type f -name zocl.ko -delete
29+
find /lib/modules -type f -name zocl.ko.kz -delete
30+
find /lib/modules -type f -name zocl.ko.xz -delete
31+
depmod -A
32+
}
33+
34+
installdir=/usr
35+
systemddir=/etc/systemd/system
36+
37+
echo "Unloading old XRT Linux kernel modules"
38+
rmmod zocl
39+
XRT_VERSION_STRING_OLD=`dkms status -m xrt | awk -F, '{print $2}'`
40+
for OLD in $XRT_VERSION_STRING_OLD; do
41+
echo "Unregistering old XRT Linux kernel module sources $OLD from dkms"
42+
dkms remove -m xrt -v $OLD --all
43+
break
44+
done
45+
rmmodules
46+
47+
echo "Invoking DKMS common.postinst for xrt"
48+
/usr/lib/dkms/common.postinst xrt @XRT_VERSION_STRING@ "" "" $2
49+
if [ $? -eq 0 ]; then
50+
echo "Finished DKMS common.postinst"
51+
install -m 644 /usr/src/xrt-@XRT_VERSION_STRING@/driver/zocl/10-zocl.rules /etc/udev/rules.d
52+
53+
echo "Loading new XRT Linux kernel modules"
54+
udevadm control --reload-rules
55+
modprobe zocl
56+
udevadm trigger
57+
fi
58+
59+
if [ -z "`dkms status -m xrt -v @XRT_VERSION_STRING@ |grep installed`" ]; then
60+
echo "****************************************************************"
61+
echo "* DKMS failed to install XRT drivers."
62+
echo "* Please check if kernel development headers are installed for OS variant used."
63+
echo "* "
64+
echo "* Check build logs in /var/lib/dkms/xrt/@XRT_VERSION_STRING@"
65+
echo "****************************************************************"
66+
fi
67+
68+
if [ ! -e /etc/OpenCL/vendors/xilinx.icd ]; then
69+
echo "INFO: Creating ICD entry for Xilinx Platform"
70+
mkdir -p /etc/OpenCL/vendors
71+
echo "libxilinxopencl.so" > /etc/OpenCL/vendors/xilinx.icd
72+
chmod -R 755 /etc/OpenCL
73+
fi
74+
75+
exit 0

src/CMake/config/prerm-edge.in

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/sh
2+
3+
#
4+
# UBUNTU NOTE
5+
# -----------
6+
# 1. When downgrading (say from 2.3.0 to 2.2.0) then prerm of 2.3.0 is run
7+
# but postinst of 2.2.0 is run. The prerm is invoked with "upgrade 2.2.0"
8+
# argument and postinst is invoked with "configure 2.3.0" argument.
9+
# 2. When upgrading (say from 2.2.0 to 2.3.0) then prerm of 2.2.0 is run
10+
# but postinst of 2.3.0 is run. The prerm is invoked with "upgrade 2.3.0"
11+
# argument and postinst is invoked with "configure 2.2.0" argument.
12+
# 3. When re-installing (say from 2.2.0 to 2.2.0) then prerm of 2.2.0 is run
13+
# and postinst of 2.2.0 is run. The prerm is invoked with "upgrade 2.2.0"
14+
# argument and postinst is invoked with "configure 2.2.0" argument.
15+
#
16+
# RHEL/CentOS NOTE
17+
# ----------------
18+
# 1. When downgrading (say from 2.3.0 to 2.2.0) then oddly postinst of 2.2.0
19+
# is run first followed by prerm of 2.3.0 run. The postinst is invoked with
20+
# "2" and prerm is invoked with "1".
21+
# 2. When upgrading (say from 2.2.0 to 2.3.0) then prerm of 2.2.0 is NOT run
22+
# but postinst of 2.3.0 is run. The postinst is invoked with "2" argument.
23+
# 3. When re-installing (say from 2.2.0 to 2.2.0) then prerm is NOT run but
24+
# and postinst of 2.2.0 is run. The postinst is invoked with "2" argument.
25+
26+
# In the case of upgrade, downgrade or re-install we would like to preserve the
27+
# configuration of the components and hence we want to handle the configuration
28+
# in postinst script.
29+
30+
OSDIST=`grep '^ID=' /etc/os-release | awk -F= '{print $2}' | tr -d '"'`
31+
if [ [ $OSDIST == "centos" ] || [ $OSDIST == "rhel" ] ] && [ $1 -ge 1 ]; then
32+
echo "Cleanup is skipped for package upgrade/downgrade/re-install on RHEL/CentOS"
33+
exit 0
34+
fi
35+
36+
OSDIST=`grep '^ID=' /etc/os-release | awk -F= '{print $2}' | tr -d '"'`
37+
if [ $OSDIST == "ubuntu" ] && [ "$1" = "upgrade" ]; then
38+
echo "Unregistering old XRT Linux kernel module sources @XRT_VERSION_STRING@ from dkms on Ubuntu/Debian"
39+
dkms remove -m xrt -v @XRT_VERSION_STRING@ --all
40+
echo "Cleanup is skipped for package upgrade/downgrade/re-install on Ubuntu/Debian"
41+
exit 0
42+
fi
43+
44+
# If we are here XRT is being uninstalled. It is NOT one of upgrade, downgrade or
45+
# re-install.
46+
47+
echo "Unloading old XRT Linux kernel modules"
48+
rmmod zocl
49+
50+
echo "Unregistering XRT Linux kernel module sources @XRT_VERSION_STRING@ from dkms"
51+
dkms remove -m xrt -v @XRT_VERSION_STRING@ --all
52+
find /lib/modules -type f -name zocl.ko -delete
53+
find /lib/modules -type f -name zocl.ko.kz -delete
54+
find /lib/modules -type f -name zocl.ko.xz -delete
55+
depmod -A
56+
57+
rm -f /etc/udev/rules.d/10-zocl.rules
58+
59+
exit 0

src/CMake/cpackLin.cmake

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ SET(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
1515
SET(CPACK_DEB_COMPONENT_INSTALL ON)
1616
SET(CPACK_RPM_COMPONENT_INSTALL ON)
1717

18-
execute_process(
19-
COMMAND lsb_release -r -s
20-
OUTPUT_VARIABLE CPACK_REL_VER
21-
OUTPUT_STRIP_TRAILING_WHITESPACE
18+
if (DEFINED CROSS_COMPILE)
19+
set(CPACK_REL_VER ${LINUX_VERSION})
20+
else()
21+
execute_process(
22+
COMMAND lsb_release -r -s
23+
OUTPUT_VARIABLE CPACK_REL_VER
24+
OUTPUT_STRIP_TRAILING_WHITESPACE
2225
)
26+
endif()
2327

2428
include (CMake/glibc.cmake)
2529

@@ -49,6 +53,17 @@ if (${LINUX_FLAVOR} MATCHES "^(Ubuntu|Debian)")
4953
SET(CPACK_DEBIAN_PACKAGE_SHLIBDEPS "OFF")
5054
SET(CPACK_DEBIAN_AWS_PACKAGE_DEPENDS "xrt (>= ${XRT_VERSION_MAJOR}.${XRT_VERSION_MINOR}.${XRT_VERSION_PATCH})")
5155
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}), libboost-program-options-dev (>=${Boost_VER_STR}), libboost-program-options-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}), libudev-dev, python3, python3-pip")
56+
if (DEFINED CROSS_COMPILE)
57+
if (${aarch} STREQUAL "aarch64")
58+
SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "arm64")
59+
SET(CPACK_ARCH "aarch64")
60+
else()
61+
SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "armhf")
62+
SET(CPACK_ARCH "aarch32")
63+
endif()
64+
SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_BINARY_DIR}/postinst;${CMAKE_CURRENT_BINARY_DIR}/prerm")
65+
SET(CPACK_DEBIAN_PACKAGE_DEPENDS ${CPACK_DEBIAN_XRT_PACKAGE_DEPENDS})
66+
endif()
5267

5368
elseif (${LINUX_FLAVOR} MATCHES "^(RedHat|CentOS|Amazon|Fedora)")
5469
execute_process(
@@ -79,6 +94,19 @@ elseif (${LINUX_FLAVOR} MATCHES "^(RedHat|CentOS|Amazon|Fedora)")
7994
SET(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/usr/local" "/usr/src" "/opt" "/etc/OpenCL" "/etc/OpenCL/vendors" "/usr/lib" "/usr/lib/pkgconfig" "/usr/lib64/pkgconfig" "/lib" "/lib/firmware")
8095
SET(CPACK_RPM_AWS_PACKAGE_REQUIRES "xrt >= ${XRT_VERSION_MAJOR}.${XRT_VERSION_MINOR}.${XRT_VERSION_PATCH}")
8196
SET(CPACK_RPM_XRT_PACKAGE_REQUIRES "ocl-icd-devel >= 2.2, boost-devel >= 1.53, boost-filesystem >= 1.53, boost-program-options >= 1.53, libuuid-devel >= 2.23.2, dkms >= 2.5.0, protobuf-devel >= 2.5.0, protobuf-compiler >= 2.5.0, ncurses-devel >= 5.9, redhat-lsb-core, libxml2-devel >= 2.9.1, libyaml-devel >= 0.1.4, openssl-devel >= 1.0.2, libudev-devel, python3 >= 3.6, python3-pip")
97+
if (DEFINED CROSS_COMPILE)
98+
if (${aarch} STREQUAL "aarch64")
99+
SET(CPACK_RPM_PACKAGE_ARCHITECTURE "aarch64")
100+
SET(CPACK_ARCH "aarch64")
101+
else()
102+
SET(CPACK_RPM_PACKAGE_ARCHITECTURE "armv7l")
103+
SET(CPACK_ARCH "aarch32")
104+
endif()
105+
SET(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/postinst")
106+
SET(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/prerm")
107+
SET(CPACK_RPM_PACKAGE_REQUIRES ${CPACK_RPM_XRT_PACKAGE_REQUIRES})
108+
endif()
109+
82110
else ()
83111
SET (CPACK_GENERATOR "TGZ")
84112
endif()

0 commit comments

Comments
 (0)