-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdo-update-makerpm.sh
executable file
·317 lines (270 loc) · 7.96 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
#!/bin/bash
DEFAULT_KERNEL_VERSION=""
kerneldir="./"
modules_cnt=0
# Add each module separately
modules[$modules_cnt]="rv"
files_to_copy[$modules_cnt]="
drivers/infiniband/ulp/rv/rv_main.c
drivers/infiniband/ulp/rv/rv_file.c
drivers/infiniband/ulp/rv/rv_mr.c
drivers/infiniband/ulp/rv/rv_rdma.c
drivers/infiniband/ulp/rv/rv_conn.c
drivers/infiniband/ulp/rv/rv.h
drivers/infiniband/ulp/rv/rv_mr_cache.c
drivers/infiniband/ulp/rv/rv_mr_cache.h
drivers/infiniband/ulp/rv/trace.c
drivers/infiniband/ulp/rv/trace.h
drivers/infiniband/ulp/rv/trace_mr_cache.h
drivers/infiniband/ulp/rv/trace_conn.h
drivers/infiniband/ulp/rv/trace_dev.h
drivers/infiniband/ulp/rv/trace_mr.h
drivers/infiniband/ulp/rv/trace_user.h
drivers/infiniband/ulp/rv/trace_rdma.h
drivers/infiniband/ulp/rv/trace_misc.h
include/uapi/rv/rv_user_ioctls.h
"
# Add each module separately
include_dirs[0]="include/uapi/rv"
include_files_to_copy[0]="
include/uapi/rv/rv_user_ioctls.h
"
include_dirs[1]="compat/"
include_files_to_copy[1]=""
include_dirs_cnt=${#include_dirs[@]}
# ridiculously long to encourage good names later
# XXX: should we rename it as efs-kernel-updates?
rpmname="iefs-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] [-w dirname]
${0##*/} -S srcdir [-w dirname]
Options:
-G - Enable building a GPU Direct package
-S srcdir - fetch source directly from a specified directory
-w dirname - work directory, defaults to a mktemp directory
-h - this help text
EOL
}
gpubuild="false"
srcdir=""
workdir=""
filedir=""
ifs_distro=""
distro=""
distro_dir=""
compat_dir=""
while getopts ":GS:hw:" opt; do
case "$opt" in
G) gpubuild="true"
;;
S) srcdir="$OPTARG"
[ ! -e "$srcdir" ] && echo "srcdir $srcdir not found" && exit 1
srcdir=$(readlink -f "$srcdir")
;;
h) usage
exit 0
;;
w) workdir="$OPTARG"
;;
esac
done
if [[ $ID == "rhel" ]]; then
compat_dir=RH$VERSION_ID_MAJOR$VERSION_ID_MINOR
elif [[ $ID == "sles" ]]; then
if [[ -z $VERSION_ID_MINOR ]]; then
compat_dir=SLES$VERSION_ID_MAJOR
else
compat_dir=SLES${VERSION_ID_MAJOR}SP${VERSION_ID_MINOR}
fi
fi
if [[ ! -d $PWD/compat/$compat_dir ]]; then
echo "compat directory $compat_dir is missing, cannot build"
exit
fi
if [ $gpubuild = 'true' ]; then
echo "GPU Direct enabled build"
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
ifs_distro="IFS_$compat_dir"
distro=$ID
echo "ifs_distro = $ifs_distro"
echo "compat_dir = $compat_dir"
echo "distro = $distro"
files_to_copy[0]+="
compat/$compat_dir/compat.c
compat/common/compat_common.c
"
include_files_to_copy[1]="
compat/$compat_dir/compat.h
compat/common/compat_common.h
"
if [ $gpubuild = 'true' ]; then
files_to_copy[0]+="
drivers/infiniband/ulp/rv/gpu.c
drivers/infiniband/ulp/rv/gpu.h
drivers/infiniband/ulp/rv/gdr_ops.c
drivers/infiniband/ulp/rv/gdr_ops.h
"
fi
# configure the file dir
filedir=$srcdir/files
# 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"
echo "NVIDIA env var: $NVIDIA_GPU_DIRECT"
# create the Makefiles
echo "Creating Makefile ($tardir/Makefile)"
if [ $gpubuild = 'true' ]; then
cp $filedir/Makefile.top.gpu $tardir/Makefile
else
cp $filedir/Makefile.top $tardir/Makefile
fi
sed -i "s/IFS_DISTRO/$ifs_distro/g" $tardir/Makefile
echo "Creating Makefile ($tardir/rv/Makefile)"
if [ $gpubuild = 'true' ]; then
cp $filedir/Makefile.rv.gpu $tardir/rv/Makefile
else
cp $filedir/Makefile.rv $tardir/rv/Makefile
fi
if [[ ! -s $srcdir/compat/$compat_dir/compat.c ]]; then
sed -i "s/compat.o//g" $tardir/rv/Makefile
fi
DEFAULT_KERNEL_VERSION=$(uname -r)
if [ "$DEFAULT_KERNEL_VERSION" == "" ]; then
echo "Unable to generate the kernel version"
exit 1
fi
if echo $srcdir | grep -q "components"; then
rpmrelease=$(git rev-list WFR_driver_first..HEAD -- $srcdir | wc -l)
echo "ifs-all build"
else
rpmrelease=$(cd "$srcdir"; git rev-list "WFR_driver_first..HEAD" | wc -l)
echo "wfr-linux-devel build"
fi
rpmrelease=$((rpmrelease + 5000))
if [ $gpubuild = 'true' ]; then
rpmrelease+="cuda"
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
cat > $src_path/dkms.conf << EOF
MAKE="make -C \${kernel_source_dir} MVERSION=${MVERSION} CONFIG_INFINIBAND_RV=m M=\${dkms_tree}/${rpmname}/${rpmrelease}/build"
CLEAN="make clean"
PACKAGE_NAME="${rpmname}"
PACKAGE_VERSION="${rpmrelease}"
AUTOINSTALL="yes"
EOF
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
echo "BUILT_MODULE_NAME[$i]='${modules[$i]}'" >> $src_path/dkms.conf
echo "BUILT_MODULE_LOCATION[$i]='${modules[$i]}/'" >> $src_path/dkms.conf
echo "DEST_MODULE_LOCATION[$i]='/$kmod_subdir/$rpmname'" >> $src_path/dkms.conf
modlist+=" ${modules[$i]}"
done
echo "rv" >> $src_path/modules-load.conf
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"
cp $src_path/dkms.conf $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"
if [ $distro = 'rhel' ]
then
cp $filedir/$rpmname.spec.rhel $workdir/rpmbuild/SPECS/$rpmname.spec
else
cp $filedir/$rpmname.spec.sles $workdir/rpmbuild/SPECS/$rpmname.spec
fi
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
# moment of truth, run rpmbuild
rm -rf ksrc
echo "Building SRPM"
cd rpmbuild
rpmbuild -bs --define "_topdir $(pwd)" SPECS/${rpmname}.spec
ret=$?
exit $ret