forked from Xilinx/mlir-aie
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_drivers.sh
More file actions
executable file
·235 lines (207 loc) · 8.19 KB
/
Copy pathbuild_drivers.sh
File metadata and controls
executable file
·235 lines (207 loc) · 8.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/bin/bash
# Ensure the script exits immediately if a command fails
set -e
# Parse command-line arguments for verbosity
VERBOSE=0
if [[ "$1" == "--verbose" ]]; then
VERBOSE=1
echo "Verbose mode enabled."
fi
# Function to run build commands with optional output redirection
run_build() {
if [[ $VERBOSE -eq 1 ]]; then
"$@"
else
"$@" > /dev/null 2>&1
fi
}
echo "Detecting Ubuntu version..."
# Detect Ubuntu version
UBUNTU_VERSION=$(lsb_release -rs)
echo "Ubuntu version detected: $UBUNTU_VERSION"
# Verify Ubuntu version is 22.04 or newer
UBUNTU_MAJOR=$(echo "$UBUNTU_VERSION" | cut -d'.' -f1)
UBUNTU_MINOR=$(echo "$UBUNTU_VERSION" | cut -d'.' -f2)
if [[ "$UBUNTU_MAJOR" -lt 22 ]]; then
echo "Error: Ubuntu version must be 22.04 or newer. Current version: $UBUNTU_VERSION"
exit 1
fi
echo "Checking kernel version..."
# Check if the kernel version is at least 6.10
KERNEL_VERSION=$(uname -r | cut -d'.' -f1,2)
REQUIRED_VERSION="6.10"
if [[ "$(echo -e "$KERNEL_VERSION\n$REQUIRED_VERSION" | sort -V | head -n1)" != "$REQUIRED_VERSION" ]]; then
echo "Error: Kernel version must be at least Linux 6.10. Current version: $KERNEL_VERSION"
exit 1
fi
# For kernel 6.10, verify required kernel config options
if [[ "$KERNEL_VERSION" == "6.10" ]]; then
echo "Kernel 6.10 detected. Verifying required kernel configuration..."
# Check if kernel config is available
if [ -f "/boot/config-$(uname -r)" ]; then
CONFIG_FILE="/boot/config-$(uname -r)"
elif [ -f "/proc/config.gz" ]; then
CONFIG_FILE="/proc/config.gz"
else
echo "Warning: Cannot find kernel config file. Proceeding anyway..."
CONFIG_FILE=""
fi
if [ -n "$CONFIG_FILE" ]; then
# Check for required config options
if [ "${CONFIG_FILE##*.}" = "gz" ]; then
CONFIG_AMD_IOMMU=$(zcat "$CONFIG_FILE" | grep "^CONFIG_AMD_IOMMU=" | cut -d'=' -f2)
CONFIG_DRM_ACCEL=$(zcat "$CONFIG_FILE" | grep "^CONFIG_DRM_ACCEL=" | cut -d'=' -f2)
else
CONFIG_AMD_IOMMU=$(grep "^CONFIG_AMD_IOMMU=" "$CONFIG_FILE" | cut -d'=' -f2)
CONFIG_DRM_ACCEL=$(grep "^CONFIG_DRM_ACCEL=" "$CONFIG_FILE" | cut -d'=' -f2)
fi
if [[ "$CONFIG_AMD_IOMMU" != "y" ]]; then
echo "Error: CONFIG_AMD_IOMMU is not enabled in kernel. This is required for kernel 6.10."
echo "Please upgrade to kernel 6.11 or newer, or rebuild kernel with CONFIG_AMD_IOMMU=y"
exit 1
fi
if [[ "$CONFIG_DRM_ACCEL" != "y" ]]; then
echo "Error: CONFIG_DRM_ACCEL is not enabled in kernel. This is required for kernel 6.10."
echo "Please upgrade to kernel 6.11 or newer, or rebuild kernel with CONFIG_DRM_ACCEL=y"
exit 1
fi
echo "Kernel 6.10 configuration verified: CONFIG_AMD_IOMMU and CONFIG_DRM_ACCEL are enabled."
fi
else
# Verify kernel is at least 6.11
MINIMUM_RECOMMENDED="6.11"
if [[ "$(echo -e "$KERNEL_VERSION\n$MINIMUM_RECOMMENDED" | sort -V | head -n1)" != "$MINIMUM_RECOMMENDED" ]]; then
echo "Warning: Kernel version $KERNEL_VERSION is between 6.10 and 6.11."
echo "Kernel 6.11 or newer from Ubuntu HWE is recommended for best compatibility."
else
echo "Kernel $KERNEL_VERSION detected (>= 6.11). No additional config checks needed."
fi
fi
echo "Setting up XDNA driver repository..."
# Clone or update the XDNA driver repository and initialize submodules
XDNA_TAG=944ca35a395b7dfa37ac3f437f1da48feca7bffc
# (1.7 tag as of 2026/05/27)
if [ -d "xdna-driver" ]; then
echo "xdna-driver directory already exists. Removing and re-cloning to ensure clean state..."
rm -rf xdna-driver
fi
echo "Cloning the XDNA driver repository..."
git clone https://github.com/amd/xdna-driver.git
cd xdna-driver
echo "Checking out tag $XDNA_TAG..."
git checkout "$XDNA_TAG"
git submodule update --init --recursive
cd ..
export XDNA_SRC_DIR=$(realpath xdna-driver)
echo "Applying pkg-config fix for CMake compatibility..."
# Fix pkg-config path to use system version instead of old /tools/xgs/bin/pkg-config
sed -i '/# --- PkgConfig ---/a # Force use of system pkg-config to avoid version compatibility issues\nset(PKG_CONFIG_EXECUTABLE "/usr/bin/pkg-config" CACHE FILEPATH "Path to pkg-config executable")' "$XDNA_SRC_DIR/xrt/src/CMake/nativeLnx.cmake"
echo "Applying GCC 13 compatibility fix..."
# Add compiler flag to work around GCC 13 standard library issue
export CXXFLAGS="-D_GLIBCXX_USE_CXX11_ABI=1 ${CXXFLAGS}"
echo "Installing XRT dependencies..."
# Install XRT dependencies
cd "$XDNA_SRC_DIR"
sudo ./tools/amdxdna_deps.sh
echo "Building XRT..."
# Build XRT
cd "$XDNA_SRC_DIR/xrt/build"
run_build ./build.sh -npu -opt -noctest
echo "Removing any existing XRT and XDNA-driver packages..."
# Find and remove any installed packages that start with "xrt"
packages=$(dpkg -l | awk '/^ii/ && $2 ~ /^xrt/ { print $2 }')
if [ -z "$packages" ]; then
echo "No packages starting with 'xrt' are installed."
else
echo "Removing the following packages:"
echo "$packages"
sudo apt-get remove -y $packages
fi
echo "Installing new XRT packages..."
# Install XRT packages based on Ubuntu version
cd "$XDNA_SRC_DIR/xrt/build/Release"
# Set package patterns based on Ubuntu version
case "$UBUNTU_VERSION" in
"22.04")
base_pattern="*22.04-amd64-base.deb"
dev_pattern="*22.04-amd64-base-dev.deb"
npu_pattern="*22.04-amd64-npu.deb"
;;
"24.04")
base_pattern="*24.04-amd64-base.deb"
dev_pattern="*24.04-amd64-base-dev.deb"
npu_pattern="*24.04-amd64-npu.deb"
;;
"24.10")
base_pattern="*24.10-amd64-base.deb"
dev_pattern="*24.10-amd64-base-dev.deb"
npu_pattern="*24.10-amd64-npu.deb"
;;
"25.04")
base_pattern="*25.04-amd64-base.deb"
dev_pattern="*25.04-amd64-base-dev.deb"
npu_pattern="*25.04-amd64-npu.deb"
;;
*)
# For any other version >= 22.04, try to find packages matching the version
echo "Ubuntu version $UBUNTU_VERSION detected. Attempting to find matching packages..."
base_pattern="*${UBUNTU_VERSION}-amd64-base.deb"
dev_pattern="*${UBUNTU_VERSION}-amd64-base-dev.deb"
npu_pattern="*${UBUNTU_VERSION}-amd64-npu.deb"
;;
esac
# Find matching .deb files
base_pkg=$(ls $base_pattern 2>/dev/null | head -n 1)
dev_pkg=$(ls $dev_pattern 2>/dev/null | head -n 1)
npu_pkg=$(ls $npu_pattern 2>/dev/null | head -n 1)
if [[ -z "$base_pkg" || -z "$dev_pkg" || -z "$npu_pkg" ]]; then
echo "Error: Could not find .deb packages matching one or more patterns:"
echo " - $base_pattern"
echo " - $dev_pattern"
echo " - $npu_pattern"
echo "Available packages:"
ls -1 *.deb 2>/dev/null || echo "No .deb files found"
exit 1
fi
echo "Installing packages: $base_pkg, $dev_pkg, $npu_pkg"
sudo apt reinstall -y "./$base_pkg"
sudo apt reinstall -y "./$dev_pkg"
sudo apt reinstall -y "./$npu_pkg"
echo "Building XDNA Driver..."
# Build XDNA Driver
cd "$XDNA_SRC_DIR/build"
run_build ./build.sh -release
echo "Installing XDNA plugin..."
# Install XDNA plugin based on Ubuntu version
cd "$XDNA_SRC_DIR/build/Release"
# Set plugin pattern based on Ubuntu version
case "$UBUNTU_VERSION" in
"22.04")
plugin_pattern="*22.04-amd64-amdxdna.deb"
;;
"24.04")
plugin_pattern="*24.04-amd64-amdxdna.deb"
;;
"24.10")
plugin_pattern="*24.10-amd64-amdxdna.deb"
;;
"25.04")
plugin_pattern="*25.04-amd64-amdxdna.deb"
;;
*)
# For any other version >= 22.04, try to find package matching the version
echo "Ubuntu version $UBUNTU_VERSION detected. Attempting to find matching plugin package..."
plugin_pattern="*${UBUNTU_VERSION}-amd64-amdxdna.deb"
;;
esac
# Find the plugin package file
plugin_pkg=$(ls $plugin_pattern 2>/dev/null | head -n 1)
if [[ -z "$plugin_pkg" ]]; then
echo "Error: Could not find plugin package matching pattern: $plugin_pattern"
echo "Available packages:"
ls -1 *.deb 2>/dev/null || echo "No .deb files found"
exit 1
fi
echo "Installing plugin package: $plugin_pkg"
sudo apt reinstall -y "./$plugin_pkg"
echo "xdna-driver and XRT built and installed successfully."