blob: dd443ab5a7b189bfea32588688345ac8219a32db (
plain)
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
|
# Copyright 1999-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
PYTHON_COMPAT=( python3_{13..14} )
inherit linux-mod-r1 multiprocessing optfeature python-any-r1 toolchain-funcs
DESCRIPTION="AMD XDNA Driver"
HOMEPAGE="https://github.com/amd/xdna-driver"
if [[ ${PV} == 999999 ]] ; then
EGIT_REPO_URI="https://github.com/amd/xdna-driver.git"
EGIT_SUBMODULES=()
inherit git-r3
BDEPEND="${PYTHON_DEPS}"
else
SRC_URI="https://github.com/amd/xdna-driver/archive/refs/tags/${PV}.tar.gz -> ${P}.tar.gz"
KEYWORDS="~amd64"
# For live ebuild firmware is fetched from amd-ipu-staging branch of https://gitlab.com/kernel-firmware/drm-firmware.
# For release commit, see https://github.com/amd/xdna-driver/issues/1236
# (requires manual date-based commit selection)
FW_COMMIT=9c532be0fe8d6ac30e8a5e1c0b54a88ae94f50b6
# To regenerate, run:
# ebuild xdna-driver-<version>.ebuild info
declare -Ag FIRMWARES=(
[1502_00/npu.sbin.1.5.5.391]=npu.dev.sbin
[17f1_10/npu.sbin.1.1.0.206]=npu.dev.sbin
[17f1_10/cert.sbin.1.0.0.28]=cert.dev.sbin
[17f2_10/npu.sbin.1.1.0.206]=npu.dev.sbin
[17f2_10/cert.sbin.1.0.0.28]=cert.dev.sbin
[17f0_10/1.7_npu.sbin.1.1.2.64]=npu.dev.sbin
[17f0_11/1.7_npu.sbin.1.1.2.65]=npu.dev.sbin
)
FW_URI_PREFIX=https://gitlab.com/kernel-firmware/drm-firmware/-/raw/${FW_COMMIT}/amdnpu
SRC_URI+=" "
for fw in "${!FIRMWARES[@]}"; do
SRC_URI+="${FW_URI_PREFIX}/${fw} -> ${FW_COMMIT:0:6}-${fw%%/*}__${FIRMWARES[${fw}]} "
done
fi
S="${WORKDIR}/${P}/drivers/accel/amdxdna"
LICENSE="GPL-2 linux-fw-redistributable"
SLOT="0"
# Re-use compress-* USE flags from sys-kernel/linux-firmware.
IUSE="compress-xz compress-zstd"
REQUIRED_USE="?? ( compress-xz compress-zstd )"
BDEPEND+="
compress-xz? ( app-arch/xz-utils )
compress-zstd? ( app-arch/zstd )
"
DEPEND="${PYTHON_DEPS}"
pkg_setup() {
if use compress-xz || use compress-zstd ; then
local CONFIG_CHECK
if kernel_is -ge 5 19; then
use compress-xz && CONFIG_CHECK="~FW_LOADER_COMPRESS_XZ"
use compress-zstd && CONFIG_CHECK="~FW_LOADER_COMPRESS_ZSTD"
else
use compress-xz && CONFIG_CHECK="~FW_LOADER_COMPRESS"
if use compress-zstd; then
eerror "Kernels <5.19 do not support ZSTD-compressed firmware files"
fi
fi
linux-info_pkg_setup
fi
linux-mod-r1_pkg_setup
if [[ ${PV} == 999999 ]] ; then
python-any-r1_pkg_setup
fi
}
pkg_info() {
if [[ ${PV} != 999999 ]] ; then
local INFO_FILE="https://raw.githubusercontent.com/amd/xdna-driver/${PV}/tools/info.json"
local COMMON_PREFIX=https://gitlab.com/kernel-firmware/drm-firmware/-/raw/amd-ipu-staging/amdnpu/
# shellcheck disable=SC2016
local JQ_EXPR='.firmwares[] | (.url | sub($prefix; "")) as $p | " [" + $p + "]=" + .fw_name'
echo 'declare -Ag FIRMWARES=('
curl -s "$INFO_FILE" | jq -r --arg prefix "$COMMON_PREFIX" "$JQ_EXPR"
echo ')'
fi
}
src_unpack() {
local firmware_dir="${WORKDIR}/${P}/amdxdna_bins/firmware"
if [[ ${PV} == 999999 ]] ; then
git-r3_src_unpack
# This downloads files specified in https://github.com/amd/xdna-driver/blob/main/tools/WHENCE
# Firmware files signatures are not present in the Manifest, but effectively pinned via "whence-commit"
"${EPYTHON}" "${P}/tools/sync_from_whence.py" firmware --out "${firmware_dir}" || die
else
default
mkdir -p "${firmware_dir}" || die
for fw in "${!FIRMWARES[@]}"; do
local dir="${fw%%/*}"
local src_filename="${FW_COMMIT:0:6}-${dir}__${FIRMWARES[${fw}]}"
mkdir -p "${firmware_dir}/${dir}" || die
cp "${DISTDIR}/${src_filename}" "${firmware_dir}/${dir}/${FIRMWARES[${fw}]}" || die
done
fi
}
src_prepare() {
sed -e "s/-Werror//" -i Kbuild || die
default
}
src_configure() {
pushd "${WORKDIR}/${P}/" || die
KERNEL_SRC="${KERNEL_DIR}" \
KERNEL_VER="${KV_FULL}" \
ARCH="$(tc-arch-kernel)" \
CC="${KERNEL_CC}" ./drivers/accel/tools/configure_kernel.sh || die
popd || die
}
src_compile() {
local modlist=( amdxdna )
local modargs=( KERNEL_VER="${KV_FULL}" )
linux-mod-r1_src_compile
}
src_install() {
insinto /lib/firmware/amdnpu
doins -r "${WORKDIR}/${P}/amdxdna_bins/firmware"/*
if use compress-xz || use compress-zstd; then
pushd "${ED}/lib/firmware/amdnpu" &>/dev/null || die
einfo "Compressing firmware ..."
local compressor suffix
if use compress-xz; then
compressor="xz -T1 -C crc32"
suffix=".xz"
elif use compress-zstd; then
compressor="zstd -15 -T1 -C -q --rm"
suffix=".zst"
fi
# shellcheck disable=SC2086
find . -type f -print0 | \
xargs -0 -P $(makeopts_jobs) -I'{}' ${compressor} '{}'
assert
# Symlinks were copied verbatim by doins -r and now point at
# filenames that no longer exist because their targets were
# just compressed. Relink them at the new, compressed names.
local link target
while IFS= read -r -d '' link; do
target=$(readlink "${link}") || die
ln -sf "${target}${suffix}" "${link}${suffix}" || die
rm -f "${link}" || die
done < <(find . -type l -print0)
popd &>/dev/null || die
fi
# Prefer out-of-tree driver over kernel/drivers/accel/amdxdna/amdxdna.ko
insinto /etc/depmod.d
newins - amdxdna.conf <<-EOF
override amdxdna * extra
EOF
linux-mod-r1_src_install
}
pkg_postinst() {
linux-mod-r1_pkg_postinst
einfo "To reload kernel module between out-of-tree builds run:"
einfo "modprobe -r amdxdna && modprobe amdxdna"
einfo "However, switching between in-tree and out-of-tree builds requires a reboot."
optfeature "for runtime and xrt-smi tool" dev-libs/xrt-xdna
}
|