Skip to content

Commit 2f63d5a

Browse files
kashifclaude
andcommitted
Add Arch Linux support for xdna-driver
This commit adds complete support for building and installing the AMD XDNA driver on Arch Linux. Changes: - tools/amdxdna_deps.sh: Add pacman support for jq installation - CMake/pkg.cmake: Add Arch Linux detection and TGZ package generation - xrt submodule: Updated with Arch Linux support (packaging + dependencies) - README.md: Add detailed Arch Linux installation instructions New files: - PKGBUILD-xrt-plugin: Arch package build script for XDNA driver plugin - xrt-plugin-amdxdna.install: Pacman install hooks for DKMS and kernel module XRT-specific packaging: - XRT PKGBUILDs moved to xrt/packaging/arch/ (maintained in XRT submodule) - See xrt/packaging/arch/README.md for XRT packaging instructions The build system now properly detects Arch Linux and generates .tar.gz packages that can be repackaged into proper Arch packages (.pkg.tar.zst) using the provided PKGBUILDs. Tested on Arch Linux with kernel 6.17.8 and AMD Ryzen AI 9 HX 370 (NPU Strix). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 2a50abc commit 2f63d5a

File tree

6 files changed

+162
-6
lines changed

6 files changed

+162
-6
lines changed

CMake/pkg.cmake

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,27 @@ if("${XDNA_CPACK_LINUX_PKG_FLAVOR}" MATCHES "debian")
134134
set(CPACK_DEB_COMPONENT_INSTALL ON)
135135
set(CPACK_DEBIAN_PACKAGE_DEPENDS "xrt-base (>= ${XDNA_CPACK_XRT_BASE_VERSION}), xrt-base (<< ${XDNA_CPACK_XRT_BASE_NEXT_VERSION})")
136136
if(NOT SKIP_KMOD)
137-
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_BINARY_DIR}/package/postinst"
137+
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_BINARY_DIR}/package/postinst"
138138
"${CMAKE_CURRENT_BINARY_DIR}/package/prerm")
139139
endif()
140140
elseif("${XDNA_CPACK_LINUX_PKG_FLAVOR}" MATCHES "fedora")
141141
set(CPACK_GENERATOR "RPM")
142142
set(CPACK_RPM_COMPONENT_INSTALL ON)
143143
set(CPACK_RPM_PACKAGE_REQUIRES "xrt-base >= ${XDNA_CPACK_XRT_BASE_VERSION}, xrt-base < ${XDNA_CPACK_XRT_BASE_NEXT_VERSION}")
144144
if(NOT SKIP_KMOD)
145-
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/package/postinst")
146-
set(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/package/prerm")
145+
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/package/postinst")
146+
set(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/package/prerm")
147+
endif()
148+
elseif("${XDNA_CPACK_LINUX_PKG_FLAVOR}" MATCHES "arch")
149+
set(CPACK_GENERATOR "TGZ")
150+
# For Arch Linux, we generate a tarball that can be used for manual installation
151+
# or to create a PKGBUILD. Post-install scripts need to be run manually.
152+
set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
153+
message(STATUS "Arch Linux detected - generating TGZ package")
154+
if(NOT SKIP_KMOD)
155+
message(STATUS "Post-install script: ${CMAKE_CURRENT_BINARY_DIR}/package/postinst")
156+
message(STATUS "Pre-remove script: ${CMAKE_CURRENT_BINARY_DIR}/package/prerm")
157+
message(STATUS "Note: For Arch Linux, you'll need to run these scripts manually or create a PKGBUILD")
147158
endif()
148159
else("${XDNA_CPACK_LINUX_PKG_FLAVOR}" MATCHES "debian")
149160
message(FATAL_ERROR "Unknown Linux package flavor: ${XDNA_CPACK_LINUX_PKG_FLAVOR}")

PKGBUILD-xrt-plugin

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Maintainer: Your Name <[email protected]>
2+
pkgname=xrt-plugin-amdxdna
3+
pkgver=2.21.0
4+
pkgrel=1
5+
pkgdesc="AMD XDNA Driver plugin for Xilinx RunTime"
6+
arch=('x86_64')
7+
url="https://github.com/amd/xdna-driver"
8+
license=('Apache-2.0')
9+
depends=('xrt-base' 'xrt-npu' 'dkms' 'linux-headers')
10+
provides=('xrt-plugin-amdxdna')
11+
conflicts=('amdxdna-driver' 'amdxdna-driver-bin')
12+
install=xrt-plugin-amdxdna.install
13+
14+
package() {
15+
cd "$srcdir"
16+
17+
# Extract the tarball directly into the package directory
18+
tar -xzf /home/kashif/Downloads/xdna-driver/build/Release/xrt_plugin.2.21.0_-x86_64-amdxdna.tar.gz -C "$pkgdir"
19+
20+
# Copy the install scripts for reference (they'll be called from .install file)
21+
mkdir -p "$pkgdir/opt/xilinx/xrt/share/amdxdna/package"
22+
install -Dm755 /home/kashif/Downloads/xdna-driver/build/Release/package/postinst \
23+
"$pkgdir/opt/xilinx/xrt/share/amdxdna/package/postinst"
24+
install -Dm755 /home/kashif/Downloads/xdna-driver/build/Release/package/prerm \
25+
"$pkgdir/opt/xilinx/xrt/share/amdxdna/package/prerm"
26+
}

README.md

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ cd <root-of-source-tree>
103103
exit
104104
```
105105

106-
### Steps to create release build DEB package:
106+
### Steps to create release build DEB package (Ubuntu/Debian):
107107

108108
``` bash
109109
cd <root-of-source-tree>/build
@@ -121,7 +121,54 @@ cd ../../build
121121
# To adapt according to your OS & version
122122
sudo apt reinstall ./Release/xrt_plugin.2.19.0_ubuntu22.04-x86_64-amdxdna.deb
123123
```
124-
You will find `xrt_plugin\*-amdxdna.deb` in Release/ folder. This package includes:
124+
125+
### Steps to create release build packages (Arch Linux):
126+
127+
``` bash
128+
cd <root-of-source-tree>
129+
130+
# Install dependencies (requires sudo)
131+
sudo ./tools/amdxdna_deps.sh
132+
133+
# Get submodules
134+
git submodule update --init --recursive
135+
136+
# Build XRT
137+
cd xrt/build
138+
./build.sh -npu -opt
139+
140+
# Build and install XRT packages using pacman
141+
# PKGBUILDs are in xrt/packaging/arch/
142+
cd ../packaging/arch
143+
makepkg -p PKGBUILD-xrt-base
144+
sudo pacman -U xrt-base-*.pkg.tar.zst
145+
146+
makepkg -p PKGBUILD-xrt-npu
147+
sudo pacman -U xrt-npu-*.pkg.tar.zst
148+
149+
# Build XDNA driver
150+
cd ../../../build
151+
./build.sh -release
152+
153+
# Build and install XDNA plugin package
154+
cd ..
155+
makepkg -p PKGBUILD-xrt-plugin
156+
sudo pacman -U xrt-plugin-amdxdna-*.pkg.tar.zst
157+
158+
# Configure memory limits (required for NPU access)
159+
sudo bash -c 'echo "* soft memlock unlimited" >> /etc/security/limits.conf'
160+
sudo bash -c 'echo "* hard memlock unlimited" >> /etc/security/limits.conf'
161+
162+
# Log out and log back in (or reboot) for memory limit changes to take effect
163+
```
164+
165+
**Note for Arch Linux users**: The build system generates `.tar.gz` packages which are repackaged into proper Arch packages (`.pkg.tar.zst`) using the provided PKGBUILDs:
166+
- XRT packages: `xrt/packaging/arch/` (PKGBUILD-xrt-base, PKGBUILD-xrt-npu)
167+
- XDNA driver: root directory (PKGBUILD-xrt-plugin)
168+
169+
This ensures proper integration with pacman for installation, upgrades, and removal.
170+
171+
You will find `xrt_plugin\*-amdxdna.deb` (Ubuntu/Debian) or `xrt_plugin*.tar.gz` (Arch Linux) in Release/ folder. This package includes:
125172
* The `.so` library files, which will be installed into `/opt/xilinx/xrt/lib` folder
126173
* The XDNA driver and DKMS script, which build, install and load
127174
`amdxdna.ko` driver when installing the .DEB package on target machine

tools/amdxdna_deps.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ if [ -x "$(command -v apt-get)" ]; then
1010
apt-get install -y jq
1111
elif [ -x "$(command -v dnf)" ]; then
1212
dnf install -y jq
13+
elif [ -x "$(command -v pacman)" ]; then
14+
pacman -Syu --needed --noconfirm jq
1315
fi
1416

1517
$SCRIPT_DIR/../xrt/src/runtime_src/tools/scripts/xrtdeps.sh

xrt-plugin-amdxdna.install

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
post_install() {
2+
echo "Installing AMD XDNA driver via DKMS..."
3+
4+
install_datadir=/opt/xilinx/xrt/share/amdxdna
5+
udev_rules_d=/etc/udev/rules.d
6+
amdxdna_rules_file=99-amdxdna.rules
7+
dracut_conf_d=/etc/dracut.conf.d
8+
dracut_conf_file=amdxdna.dracut.conf
9+
10+
# On systems with dracut, exclude driver from initram
11+
if [ -e ${dracut_conf_d} ]; then
12+
if [ ! -f ${dracut_conf_d}/${dracut_conf_file} ]; then
13+
touch ${dracut_conf_d}/${dracut_conf_file}
14+
fi
15+
echo "omit_drivers+=\" amdxdna \"" > ${dracut_conf_d}/${dracut_conf_file}
16+
fi
17+
18+
# Install DKMS module
19+
echo "Installing amdxdna Linux kernel module via DKMS..."
20+
$install_datadir/dkms_driver.sh --install
21+
22+
# Setup udev rules
23+
echo "Setting up udev rules..."
24+
if [ ! -f ${udev_rules_d}/${amdxdna_rules_file} ]; then
25+
touch ${udev_rules_d}/${amdxdna_rules_file}
26+
fi
27+
echo 'KERNEL=="accel*",DRIVERS=="amdxdna",MODE="0666"' > ${udev_rules_d}/${amdxdna_rules_file}
28+
29+
# Load the kernel module
30+
echo "Loading amdxdna kernel module..."
31+
rmmod amdxdna > /dev/null 2>&1 || true
32+
modprobe amdxdna
33+
34+
echo "AMD XDNA driver installation complete!"
35+
echo "You can test it with: source /opt/xilinx/xrt/setup.sh && xrt-smi validate"
36+
}
37+
38+
post_upgrade() {
39+
post_install
40+
}
41+
42+
pre_remove() {
43+
echo "Removing AMD XDNA driver..."
44+
45+
install_datadir=/opt/xilinx/xrt/share/amdxdna
46+
udev_rules_d=/etc/udev/rules.d
47+
amdxdna_rules_file=99-amdxdna.rules
48+
dracut_conf_d=/etc/dracut.conf.d
49+
dracut_conf_file=amdxdna.dracut.conf
50+
51+
# Unload kernel module
52+
if lsmod | grep -q "amdxdna "; then
53+
rmmod amdxdna
54+
fi
55+
56+
# Remove dracut config
57+
if [ -f ${dracut_conf_d}/${dracut_conf_file} ]; then
58+
rm -f ${dracut_conf_d}/${dracut_conf_file}
59+
fi
60+
61+
# Remove udev rules
62+
if [ -f ${udev_rules_d}/${amdxdna_rules_file} ]; then
63+
rm -f ${udev_rules_d}/${amdxdna_rules_file}
64+
fi
65+
66+
# Remove DKMS module
67+
$install_datadir/dkms_driver.sh --remove
68+
69+
echo "AMD XDNA driver removed!"
70+
}

0 commit comments

Comments
 (0)