-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcray-cxi-driver.spec
266 lines (217 loc) · 8.05 KB
/
cray-cxi-driver.spec
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# Copyright 2021 Hewlett Packard Enterprise Development LP
%define release_extra 0
%{!?dkms_source_tree:%define dkms_source_tree /usr/src}
%define dkms_source_dir %{dkms_source_tree}/%{name}-%{version}-%{release}
# Enable AMD GPU dependencies by building with --with=amdgpu rpmbuild option
%bcond_with amdgpu
# Enable Nvidia GPU dependencies by building with --with=nvidiagpu rpmbuild option
%bcond_with nvidiagpu
%if 0%{?rhel}
%define distro_kernel_package_name kmod-%{name}
%else
%define distro_kernel_package_name %{name}-kmp
%endif
# Exclude -preempt kernel flavor, this seems to get built alongside the -default
# flavor for stock SLES. It doesn't get used, and its presence can cause issues
%define kmp_args_common -x azure preempt -p %{_sourcedir}/%name.rpm_preamble
%if 0%{?rhel}
# On RHEL, override the kmod RPM name to include the kernel version it was built
# for; this allows us to package the same driver for multiple kernel versions.
%define kmp_args -n %name-k%%kernel_version %kmp_args_common
%else
%define kmp_args %kmp_args_common
%endif
Name: cray-cxi-driver
Version: 1.0.0
Release: %(echo ${BUILD_METADATA})
Summary: HPE Cassini Driver
License: GPL-2.0
Source0: %{name}-%{version}.tar.gz
Prefix: /usr
BuildRequires: cray-cassini-headers-user kernel-devel
BuildRequires: cray-slingshot-base-link-devel
BuildRequires: cassini2-firmware-devel
BuildRequires: sl-driver-devel
%if %{with nvidiagpu}
%if %{with shasta_premium}
# COS needs the nvidia-gpu-build helper package to install cuda-drivers
# successfully
%if "%(echo $SHS_NEW_BUILD_SYSTEM)" == "y"
%else
BuildRequires: nvidia-gpu-build
%endif
%endif
%if 0%{?sle_version}
BuildRequires: cuda-drivers
%else
BuildRequires: nvidia-kmod-headers nvidia-driver-devel
%endif
%endif
%if %{with amdgpu}
BuildRequires: rock-dkms
%endif
BuildRequires: %kernel_module_package_buildreqs
# Generate a preamble that gets attached to the kmod RPM(s). Kernel module
# dependencies can be declared here. The 'Obsoletes' and 'Provides' lines for
# RHEL allow the package to be referred to by its base name without having to
# explicitly specify a kernel version.
%(/bin/echo -e "\
Requires: cray-hms-firmware \n\
Requires: cray-libcxi-retry-handler \n\
%if 0%%{?rhel} \n\
Requires: kmod-cray-slingshot-base-link \n\
Obsoletes: kmod-%%{name} \n\
Provides: kmod-%%{name} = %%version-%%release \n\
%else \n\
Requires: cray-slingshot-base-link-kmp-%1 \n\
Requires: sl-driver-kmp-%1 \n\
%endif" > %{_sourcedir}/%{name}.rpm_preamble)
%if 0%{with shasta_premium}
# The nvidia-gpu-build-obs package (necessary for building against CUDA
# drivers) causes a bogus default kernel flavor to be added. This causes
# builds to fail, as upstream dependencies (i.e. SBL) are not built for
# default on shasta-premium. Work around this by explicitly excluding the
# default flavor on shasta-premium
%kernel_module_package -x 64kb default %kmp_args
%else
%kernel_module_package %kmp_args
%endif
%description
Cassini driver
%package udev
Summary: Udev rules for Cassini driver
Requires: (%{distro_kernel_package_name} or %{name}-dkms)
%description udev
Udev rules for Cassini driver
%package devel
Summary: Development files for Cassini driver
Requires: cray-cassini-headers-user
Requires: cray-slingshot-base-link-devel
Requires: sl-driver-devel
%description devel
Development files for Cassini driver
%package dkms
Summary: DKMS package for Cassini driver
BuildArch: noarch
Requires: dkms
Requires: cray-cassini-headers-user
Requires: cassini2-firmware-devel
Requires: sl-driver-dkms
Requires: sl-driver-devel
Requires: cray-slingshot-base-link-dkms
Requires: cray-slingshot-base-link-devel
Conflicts: kmod-%name
Conflicts: %name-kmp
%description dkms
DKMS support for Cassini driver
%prep
%setup
set -- *
mkdir source
mv "$@" source/
mkdir obj
%build
for flavor in %flavors_to_build; do
rm -rf obj/$flavor
cp -r source obj/$flavor
make -C %{kernel_source $flavor} modules \
M=$PWD/obj/$flavor/cxi \
NO_BUILD_TESTS=1 \
CASSINI_HEADERS_DIR=%{_includedir} \
FIRMWARE_CASSINI_DIR=%{_includedir} \
SLINGSHOT_BASE_LINK_DIR=%{_includedir} \
SL_DIR=%{_includedir} \
KBUILD_EXTRA_SYMBOLS="%{prefix}/src/slingshot-base-link/$flavor/Module.symvers \
%{prefix}/src/sl/$flavor/Module.symvers" \
%{?_smp_mflags}
done
%install
export INSTALL_MOD_PATH=$RPM_BUILD_ROOT
export INSTALL_MOD_DIR=extra/%{name}
for flavor in %flavors_to_build; do
make -C %{kernel_source $flavor} M=$PWD/obj/$flavor/cxi NO_BUILD_TESTS=1 modules_install
install -D $PWD/obj/$flavor/cxi/Module.symvers $RPM_BUILD_ROOT/%{prefix}/src/cxi/$flavor/Module.symvers
done
# Remove any test modules (test-atu.ko, test-domain.ko, etc.) that got installed
rm -rf $INSTALL_MOD_PATH/lib/modules/*/$INSTALL_MOD_DIR/tests/
install -D source/include/linux/cxi.h %{buildroot}/%{_includedir}/linux/cxi.h
install -D source/include/uapi/misc/cxi.h %{buildroot}/%{_includedir}/uapi/misc/cxi.h
install -D --mode=0644 --target-directory=%{buildroot}/%{_udevrulesdir} source/50-cxi-driver.rules
%if 0%{?rhel}
# Centos/Rocky/RHEL does not exclude the depmod-generated modules.* files from
# the RPM, causing file conflicts when updating
find $RPM_BUILD_ROOT -iname 'modules.*' -exec rm {} \;
%endif
# DKMS bits
mkdir -p %{buildroot}/%{dkms_source_dir}
cp -r source/* %{buildroot}/%{dkms_source_dir}
sed \
-e '/^$/d' \
-e '/^#/d' \
-e 's/@PACKAGE_NAME@/%{name}/g' \
-e 's/@PACKAGE_VERSION@/%{version}-%{release}/g' \
%{buildroot}/%{dkms_source_dir}/dkms.conf.in \
> %{buildroot}/%{dkms_source_dir}/dkms.conf
rm %{buildroot}/%{dkms_source_dir}/dkms.conf.in
echo "%dir %{dkms_source_dir}" > dkms-files
echo "%{dkms_source_dir}" >> dkms-files
%pre dkms
%post dkms
if [ -f /usr/libexec/dkms/common.postinst ] && [ -x /usr/libexec/dkms/common.postinst ]
then
postinst=/usr/libexec/dkms/common.postinst
elif [ -f /usr/lib/dkms/common.postinst ] && [ -x /usr/lib/dkms/common.postinst ]
then
postinst=/usr/lib/dkms/common.postinst
else
echo "ERROR: did not find DKMS common.postinst" >&2
exit 1
fi
${postinst} %{name} %{version}-%{release}
%preun dkms
# 'dkms remove' may fail in some cases (e.g. if the user has already run 'dkms
# remove'). Allow uninstallation to proceed even if it fails.
/usr/sbin/dkms remove -m %{name} -v %{version}-%{release} --all --rpm_safe_upgrade || true
%triggerin dkms -- cuda-drivers, intel-dmabuf-peer-mem-dkms, amdgpu-dkms
# Trigger dkms common.postinst to rebuild the DKMS module if a new GPU driver is
# installed.
# Skip if DKMS package is being uninstalled in this transaction
if [ $1 -eq 0 ]; then exit 0; fi
# Skip if triggering package is being upgraded, since %triggerpostun for the old
# package will run after %triggerin for the new package.
if [ $2 -ge 2 ]; then exit 0; fi
if [ -f /usr/libexec/dkms/common.postinst ] && [ -x /usr/libexec/dkms/common.postinst ]
then
postinst=/usr/libexec/dkms/common.postinst
elif [ -f /usr/lib/dkms/common.postinst ] && [ -x /usr/lib/dkms/common.postinst ]
then
postinst=/usr/lib/dkms/common.postinst
else
echo "ERROR: did not find DKMS common.postinst" >&2
exit 1
fi
${postinst} %{name} %{version}-%{release}
%triggerpostun dkms -- cuda-drivers, intel-dmabuf-peer-mem-dkms, amdgpu-dkms
# Trigger dkms common.postinst to rebuild the DKMS module after a GPU driver is
# uninstalled.
# Skip trigger if DKMS package is being uninstalled in this transaction
if [ $1 -eq 0 ]; then exit 0; fi
if [ -f /usr/libexec/dkms/common.postinst ] && [ -x /usr/libexec/dkms/common.postinst ]
then
postinst=/usr/libexec/dkms/common.postinst
elif [ -f /usr/lib/dkms/common.postinst ] && [ -x /usr/lib/dkms/common.postinst ]
then
postinst=/usr/lib/dkms/common.postinst
else
echo "ERROR: did not find DKMS common.postinst" >&2
exit 1
fi
${postinst} %{name} %{version}-%{release}
%files udev
%{_udevrulesdir}/50-cxi-driver.rules
%files devel
%{_includedir}/linux/cxi.h
%{_includedir}/uapi/misc/cxi.h
%{prefix}/src/cxi/*/Module.symvers
%files dkms -f dkms-files
%changelog