18c2ecf20Sopenharmony_ci#!/bin/bash
28c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0+
38c2ecf20Sopenharmony_ci#
48c2ecf20Sopenharmony_ci# Build a kvm-ready Linux kernel from the tree in the current directory.
58c2ecf20Sopenharmony_ci#
68c2ecf20Sopenharmony_ci# Usage: kvm-build.sh config-template resdir
78c2ecf20Sopenharmony_ci#
88c2ecf20Sopenharmony_ci# Copyright (C) IBM Corporation, 2011
98c2ecf20Sopenharmony_ci#
108c2ecf20Sopenharmony_ci# Authors: Paul E. McKenney <paulmck@linux.ibm.com>
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ciif test -f "$TORTURE_STOPFILE"
138c2ecf20Sopenharmony_cithen
148c2ecf20Sopenharmony_ci	echo "kvm-build.sh early exit due to run STOP request"
158c2ecf20Sopenharmony_ci	exit 1
168c2ecf20Sopenharmony_cifi
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ciconfig_template=${1}
198c2ecf20Sopenharmony_ciif test -z "$config_template" -o ! -f "$config_template" -o ! -r "$config_template"
208c2ecf20Sopenharmony_cithen
218c2ecf20Sopenharmony_ci	echo "kvm-build.sh :$config_template: Not a readable file"
228c2ecf20Sopenharmony_ci	exit 1
238c2ecf20Sopenharmony_cifi
248c2ecf20Sopenharmony_ciresdir=${2}
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ciT=${TMPDIR-/tmp}/test-linux.sh.$$
278c2ecf20Sopenharmony_citrap 'rm -rf $T' 0
288c2ecf20Sopenharmony_cimkdir $T
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_cicp ${config_template} $T/config
318c2ecf20Sopenharmony_cicat << ___EOF___ >> $T/config
328c2ecf20Sopenharmony_ciCONFIG_INITRAMFS_SOURCE="$TORTURE_INITRD"
338c2ecf20Sopenharmony_ciCONFIG_VIRTIO_PCI=y
348c2ecf20Sopenharmony_ciCONFIG_VIRTIO_CONSOLE=y
358c2ecf20Sopenharmony_ci___EOF___
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ciconfiginit.sh $T/config $resdir
388c2ecf20Sopenharmony_ciretval=$?
398c2ecf20Sopenharmony_ciif test $retval -gt 1
408c2ecf20Sopenharmony_cithen
418c2ecf20Sopenharmony_ci	exit 2
428c2ecf20Sopenharmony_cifi
438c2ecf20Sopenharmony_cincpus=`cpus2use.sh`
448c2ecf20Sopenharmony_cimake -j$ncpus $TORTURE_KMAKE_ARG > $resdir/Make.out 2>&1
458c2ecf20Sopenharmony_ciretval=$?
468c2ecf20Sopenharmony_ciif test $retval -ne 0 || grep "rcu[^/]*": < $resdir/Make.out | egrep -q "Stop|Error|error:|warning:" || egrep -q "Stop|Error|error:" < $resdir/Make.out
478c2ecf20Sopenharmony_cithen
488c2ecf20Sopenharmony_ci	echo Kernel build error
498c2ecf20Sopenharmony_ci	egrep "Stop|Error|error:|warning:" < $resdir/Make.out
508c2ecf20Sopenharmony_ci	echo Run aborted.
518c2ecf20Sopenharmony_ci	exit 3
528c2ecf20Sopenharmony_cifi
53