-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdo-update-makerpm.sh
executable file
·401 lines (357 loc) · 11.2 KB
/
do-update-makerpm.sh
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
#!/bin/bash
DEFAULT_KERNEL_VERSION=""
kerneldir="./"
modules_cnt=0
# Add each module separately
modules[$modules_cnt]="rdmavt"
files_to_copy[$modules_cnt]="
drivers/infiniband/sw/rdmavt/ah.c
drivers/infiniband/sw/rdmavt/ah.h
drivers/infiniband/sw/rdmavt/cq.c
drivers/infiniband/sw/rdmavt/cq.h
drivers/infiniband/sw/rdmavt/mad.c
drivers/infiniband/sw/rdmavt/mad.h
drivers/infiniband/sw/rdmavt/mcast.c
drivers/infiniband/sw/rdmavt/mcast.h
drivers/infiniband/sw/rdmavt/mmap.c
drivers/infiniband/sw/rdmavt/mmap.h
drivers/infiniband/sw/rdmavt/mr.c
drivers/infiniband/sw/rdmavt/mr.h
drivers/infiniband/sw/rdmavt/pd.c
drivers/infiniband/sw/rdmavt/pd.h
drivers/infiniband/sw/rdmavt/qp.c
drivers/infiniband/sw/rdmavt/qp.h
drivers/infiniband/sw/rdmavt/srq.c
drivers/infiniband/sw/rdmavt/srq.h
drivers/infiniband/sw/rdmavt/trace.c
drivers/infiniband/sw/rdmavt/trace.h
drivers/infiniband/sw/rdmavt/trace_rvt.h
drivers/infiniband/sw/rdmavt/trace_qp.h
drivers/infiniband/sw/rdmavt/trace_tx.h
drivers/infiniband/sw/rdmavt/trace_mr.h
drivers/infiniband/sw/rdmavt/trace_rc.h
drivers/infiniband/sw/rdmavt/trace_cq.h
drivers/infiniband/sw/rdmavt/vt.c
drivers/infiniband/sw/rdmavt/vt.h
drivers/infiniband/sw/rdmavt/rc.c
"
((modules_cnt++))
modules[$modules_cnt]="hfi1"
files_to_copy[$modules_cnt]="
drivers/infiniband/hw/hfi1/affinity.c
drivers/infiniband/hw/hfi1/affinity.h
drivers/infiniband/hw/hfi1/aspm.c
drivers/infiniband/hw/hfi1/aspm.h
drivers/infiniband/hw/hfi1/chip.c
drivers/infiniband/hw/hfi1/chip.h
drivers/infiniband/hw/hfi1/chip_registers.h
drivers/infiniband/hw/hfi1/common.h
drivers/infiniband/hw/hfi1/debugfs.c
drivers/infiniband/hw/hfi1/debugfs.h
drivers/infiniband/hw/hfi1/device.c
drivers/infiniband/hw/hfi1/device.h
drivers/infiniband/hw/hfi1/driver.c
drivers/infiniband/hw/hfi1/efivar.c
drivers/infiniband/hw/hfi1/efivar.h
drivers/infiniband/hw/hfi1/eprom.c
drivers/infiniband/hw/hfi1/eprom.h
drivers/infiniband/hw/hfi1/file_ops.c
drivers/infiniband/hw/hfi1/firmware.c
drivers/infiniband/hw/hfi1/hfi.h
drivers/infiniband/hw/hfi1/ipoib.h
drivers/infiniband/hw/hfi1/ipoib_main.c
drivers/infiniband/hw/hfi1/ipoib_tx.c
drivers/infiniband/hw/hfi1/init.c
drivers/infiniband/hw/hfi1/intr.c
drivers/infiniband/hw/hfi1/iowait.h
drivers/infiniband/hw/hfi1/mad.c
drivers/infiniband/hw/hfi1/mad.h
drivers/infiniband/hw/hfi1/mmu_rb.c
drivers/infiniband/hw/hfi1/mmu_rb.h
drivers/infiniband/hw/hfi1/opa_compat.h
drivers/infiniband/hw/hfi1/pcie.c
drivers/infiniband/hw/hfi1/pin_amd.c
drivers/infiniband/hw/hfi1/pin_system.c
drivers/infiniband/hw/hfi1/pin_nvidia.c
drivers/infiniband/hw/hfi1/pin_nvidia.h
drivers/infiniband/hw/hfi1/pinning.c
drivers/infiniband/hw/hfi1/pinning.h
drivers/infiniband/hw/hfi1/pio.c
drivers/infiniband/hw/hfi1/pio_copy.c
drivers/infiniband/hw/hfi1/pio.h
drivers/infiniband/hw/hfi1/platform.c
drivers/infiniband/hw/hfi1/platform.h
drivers/infiniband/hw/hfi1/qp.c
drivers/infiniband/hw/hfi1/qp.h
drivers/infiniband/hw/hfi1/qsfp.c
drivers/infiniband/hw/hfi1/qsfp.h
drivers/infiniband/hw/hfi1/rc.c
drivers/infiniband/hw/hfi1/ruc.c
drivers/infiniband/hw/hfi1/sdma.c
drivers/infiniband/hw/hfi1/sdma.h
drivers/infiniband/hw/hfi1/sdma_txreq.h
drivers/infiniband/hw/hfi1/sysfs.c
drivers/infiniband/hw/hfi1/trace.c
drivers/infiniband/hw/hfi1/trace.h
drivers/infiniband/hw/hfi1/trace_ctxts.h
drivers/infiniband/hw/hfi1/trace_dbg.h
drivers/infiniband/hw/hfi1/trace_ibhdrs.h
drivers/infiniband/hw/hfi1/trace_misc.h
drivers/infiniband/hw/hfi1/trace_rc.h
drivers/infiniband/hw/hfi1/trace_rx.h
drivers/infiniband/hw/hfi1/trace_tx.h
drivers/infiniband/hw/hfi1/trace_mmu.h
drivers/infiniband/hw/hfi1/trace_nvidia.h
drivers/infiniband/hw/hfi1/uc.c
drivers/infiniband/hw/hfi1/ud.c
drivers/infiniband/hw/hfi1/user_exp_rcv.c
drivers/infiniband/hw/hfi1/user_exp_rcv.h
drivers/infiniband/hw/hfi1/user_pages.c
drivers/infiniband/hw/hfi1/user_sdma.c
drivers/infiniband/hw/hfi1/user_sdma.h
drivers/infiniband/hw/hfi1/verbs.c
drivers/infiniband/hw/hfi1/verbs.h
drivers/infiniband/hw/hfi1/verbs_txreq.c
drivers/infiniband/hw/hfi1/verbs_txreq.h
drivers/infiniband/hw/hfi1/vnic.h
drivers/infiniband/hw/hfi1/vnic_main.c
drivers/infiniband/hw/hfi1/vnic_sdma.c
drivers/infiniband/hw/hfi1/exp_rcv.c
drivers/infiniband/hw/hfi1/exp_rcv.h
drivers/infiniband/hw/hfi1/iowait.c
drivers/infiniband/hw/hfi1/opfn.c
drivers/infiniband/hw/hfi1/opfn.h
drivers/infiniband/hw/hfi1/rc.h
drivers/infiniband/hw/hfi1/tid_rdma.c
drivers/infiniband/hw/hfi1/tid_rdma.h
drivers/infiniband/hw/hfi1/trace_iowait.h
drivers/infiniband/hw/hfi1/trace_tid.h
drivers/infiniband/hw/hfi1/fault.c
drivers/infiniband/hw/hfi1/fault.h
drivers/infiniband/hw/hfi1/msix.c
drivers/infiniband/hw/hfi1/msix.h
drivers/infiniband/hw/hfi1/netdev_rx.c
drivers/infiniband/hw/hfi1/ipoib_rx.c
drivers/infiniband/hw/hfi1/netdev.h
"
include_dirs[0]="include/rdma"
include_dirs[1]="include/rdma/hfi"
include_dirs[2]="include/uapi/rdma"
include_files_to_copy[0]="
include/rdma/rdmavt_qp.h
include/rdma/rdmavt_mr.h
include/rdma/rdmavt_cq.h
include/rdma/rdma_vt.h
include/rdma/ib_hdrs.h
include/rdma/ib_sysfs.h
include/rdma/opa_vnic.h
include/rdma/opa_addr.h
include/rdma/tid_rdma_defs.h
include/uapi/rdma/rvt-abi.h
"
include_files_to_copy[1]="
include/uapi/rdma/hfi/hfi1_user.h
include/uapi/rdma/hfi/hfi1_ioctl.h
"
include_files_to_copy[2]="
include/uapi/rdma/rdma_user_ioctl.h
include/uapi/rdma/rdma_user_ioctl_cmds.h
"
include_dirs_cnt=${#include_dirs[@]}
# ridiculously long to encourage good names later
rpmname="ifs-kernel-updates"
set -e
if [[ -e /etc/os-release ]]; then
. /etc/os-release
if [[ "$ID" == "sle_hpc" ]]; then
ID="sles"
fi
else
echo "File /etc/os-release is missing."
exit 1
fi
VERSION_ID_MAJOR=${VERSION_ID%%.*}
VERSION_ID_MINOR=${VERSION_ID#*.}
if [[ $VERSION_ID_MINOR == $VERSION_ID ]]; then
VERSION_ID_MINOR=''
fi
echo "VERSION_ID = $VERSION_ID"
echo "PRETTY_NAME = $PRETTY_NAME"
if [[ -n "$MVERSION" ]]; then
echo "MVERSION = $MVERSION"
fi
function usage
{
cat <<EOL
usage:
${0##*/} -h
${0##*/} [-G] [-A] [-w dirname]
${0##*/} -S srcdir [-w dirname]
Options:
-S srcdir - fetch source directly from a specified directory
-w dirname - work directory, defaults to a mktemp directory
-h - this help text
EOL
}
srcdir=""
workdir=""
filedir=""
distro=""
distro_dir=""
build_amd=
build_nvidia=
while getopts "S:hw:GA" opt; do
case "$opt" in
S) srcdir="$OPTARG"
[ ! -e "$srcdir" ] && echo "srcdir $srcdir not found" && exit 1
srcdir=$(readlink -f "$srcdir")
;;
h) usage
exit 0
;;
w) workdir="$OPTARG"
;;
G)
build_nvidia=y
echo "Will build with NVIDIA GPU support"
;;
A)
build_amd=y
echo "Will build with AMD GPU support"
;;
esac
done
if [[ $ID == "rhel" ]]; then
distro_dir=RHEL$VERSION_ID_MAJOR$VERSION_ID_MINOR
if [[ $VERSION_ID_MAJOR == "7" && $VERSION_ID_MINOR -ge 8 ]]; then
distro_dir=RHEL77
VERSION_ID="7.8"
VERSION_ID_MINOR="8"
fi
elif [[ $ID == "sles" ]]; then
if [[ -z $VERSION_ID_MINOR ]]; then
distro_dir=SLES$VERSION_ID_MAJOR
else
distro_dir=SLES${VERSION_ID_MAJOR}SP${VERSION_ID_MINOR}
fi
fi
# create final version of the variables
if [ -n "$workdir" ]; then
mkdir -p "$workdir" || exit 1
else
workdir=$(mktemp -d --tmpdir=$(pwd) build.XXXX)
[ ! $? ] && exit 1
fi
distro=$ID
echo "distro = $distro"
# configure the file dir
filedir=$srcdir/files
rpmrelease=`git rev-list --count HEAD`
if [[ $build_nvidia = y ]]; then
rpmrelease+="cuda"
fi
# after cd, where are we *really*
cd -P "$workdir"; workdir=$(pwd)
tardir=$workdir/stage
rm -rf $tardir
for (( i = 0 ; i <= modules_cnt ; i++ ))
do
mkdir -p $tardir/${modules[$i]}
done
echo "Working in $workdir"
# create the Makefiles
echo "Creating Makefile ($tardir/Makefile)"
cp $filedir/Makefile.top $tardir/Makefile
echo "Creating Makefile ($tardir/rdmavt/Makefile)"
cp $filedir/Makefile.rdmavt $tardir/rdmavt/Makefile
echo "Creating Makefile ($tardir/hfi1/Makefile)"
cp $filedir/Makefile.hfi $tardir/hfi1/Makefile
echo "Creating Symlink for spec files"
rm -f $filedir/ifs-kernel-updates.spec
ln -s $filedir/ifs-kernel-updates.spec.$distro $filedir/ifs-kernel-updates.spec
DEFAULT_KERNEL_VERSION=$(uname -r)
if [ "$DEFAULT_KERNEL_VERSION" == "" ]; then
echo "Unable to generate the kernel version"
exit 1
fi
echo "rpmrelease = $rpmrelease"
echo "Setting up RPM build area"
mkdir -p rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
# make sure rpm component strings are clean, should be no-ops
rpmname=$(echo "$rpmname" | sed -e 's/[.]/_/g')
rpmversion=$(echo "$DEFAULT_KERNEL_VERSION" | sed -e 's/-/_/g')
rpmrequires=$(echo "$DEFAULT_KERNEL_VERSION" | sed -e 's/.[^.]*$//')
# get kernel(-devel) rpm version and release values
if [ $distro = 'rhel' ]
then
kernel_rpmver=$(rpm -q --qf %{VERSION} kernel-$(uname -r))
kmod_subdir=extra
else
kernel_rpmver=$(rpm -q --qf %{VERSION} kernel-default)
kmod_subdir=updates
fi
# create a new $rpmname.conf and $rpmname.files
src_path=$workdir/rpmbuild/SOURCES/
# prepare files list and depmod config for every module built
echo "%defattr(644,root,root,755)" > $src_path/$rpmname.files
modlist=""
for (( i = 0 ; i <= modules_cnt ; i++ ))
do
echo "override ${modules[$i]} $kernel_rpmver-* weak-updates/${modules[$i]}" >> $src_path/$rpmname.conf
echo "/lib/modules/%2-%1/$kmod_subdir/$rpmname/${modules[$i]}.ko" >> $src_path/$rpmname.files
modlist+=" ${modules[$i]}"
done
echo "/etc/depmod.d/$rpmname.conf" >> $src_path/$rpmname.files
# build the tarball
echo "Copy the working files from $srcdir/$kerneldir"
echo "Copy the working files to $tardir"
pushd $srcdir/$kerneldir
for (( i = 0 ; i <= modules_cnt ; i++ ))
do
cp ${files_to_copy[$i]} $tardir/${modules[$i]}/
done
echo "Copying header files"
for (( i = 0 ; i < include_dirs_cnt ; i++ ))
do
mkdir -p $tardir/${include_dirs[$i]}
cp ${include_files_to_copy[$i]} $tardir/${include_dirs[$i]}/
done
cp $srcdir/$kerneldir/LICENSE $tardir/.
popd
echo "Building tar file"
(cd $tardir; tar cfz - --transform="s,^,${rpmname}-${rpmversion}/," *) > \
rpmbuild/SOURCES/$rpmname-$rpmversion.tgz
cd $workdir
# create the spec file
echo "Creating spec file"
cp $filedir/$rpmname.spec $workdir/rpmbuild/SPECS/$rpmname.spec
sed -i "s/RPMNAME/$rpmname/g" $workdir/rpmbuild/SPECS/$rpmname.spec
sed -i "s/RPMRELEASE/$rpmrelease/g" $workdir/rpmbuild/SPECS/$rpmname.spec
sed -i "s/RPMVERSION/$rpmversion/g" $workdir/rpmbuild/SPECS/$rpmname.spec
sed -i "s/MODLIST/$modlist/g" $workdir/rpmbuild/SPECS/$rpmname.spec
if [ $VERSION_ID = '8.0' ]; then
sed -i "s/kernel_source/kbuild/g" $workdir/rpmbuild/SPECS/$rpmname.spec
fi
if [[ -n "$MVERSION" ]]; then
sed -i "s/mversion MVERSION/mversion \"${MVERSION}\"/" $workdir/rpmbuild/SPECS/$rpmname.spec
else
sed -i "/mversion MVERSION/d" $workdir/rpmbuild/SPECS/$rpmname.spec
fi
if [[ $build_nvidia = y ]]; then
sed -i "s/CONFIG_HFI_NVIDIA/CONFIG_HFI1_NVIDIA=y/g" $workdir/rpmbuild/SPECS/$rpmname.spec
else
sed -i "s/CONFIG_HFI_NVIDIA//g" $workdir/rpmbuild/SPECS/$rpmname.spec
fi
if [[ $build_amd = y ]] ; then
sed -i "s/CONFIG_HFI_AMD/CONFIG_HFI1_AMD=y/g" $workdir/rpmbuild/SPECS/$rpmname.spec
else
sed -i "s/CONFIG_HFI_AMD//g" $workdir/rpmbuild/SPECS/$rpmname.spec
fi
# moment of truth, run rpmbuild
rm -rf ksrc
echo "Building SRPM"
cd rpmbuild
rpmbuild -bs --define "_topdir $(pwd)" SPECS/${rpmname}.spec
ret=$?
rm -f $filedir/ifs-kernel-updates.spec
exit $ret