cachepc-amdsev

Fork of AMDESE/AMDSEV with changes for cachepc side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-amdsev
Log | Files | Refs | README | sfeed.txt

common.sh (3852B)


      1#!/bin/bash
      2
      3run_cmd()
      4{
      5	echo "$*"
      6
      7	eval "$*" || {
      8		echo "ERROR: $*"
      9		exit 1
     10	}
     11}
     12
     13build_kernel()
     14{
     15	set -x
     16	kernel_type=$1
     17	shift
     18	mkdir -p linux
     19	pushd linux >/dev/null
     20
     21	if [ ! -d guest ]; then
     22		run_cmd git clone ${KERNEL_GIT_URL} guest
     23		pushd guest >/dev/null
     24		run_cmd git remote add current ${KERNEL_GIT_URL}
     25		popd
     26	fi
     27
     28	if [ ! -d host ]; then
     29		# use a copy of guest repo as the host repo
     30		run_cmd cp -r guest host
     31	fi
     32
     33	for V in guest host; do
     34		# Check if only a "guest" or "host" or kernel build is requested
     35		if [ "$kernel_type" != "" ]; then
     36			if [ "$kernel_type" != "$V" ]; then
     37				continue
     38			fi
     39		fi
     40
     41		if [ "${V}" = "guest" ]; then
     42			BRANCH="${KERNEL_GUEST_BRANCH}"
     43		else
     44			BRANCH="${KERNEL_HOST_BRANCH}"
     45		fi
     46
     47		# Nuke any previously built packages so they don't end up in new tarballs
     48		# when ./build.sh --package is specified
     49		rm -f linux-*-snp-${V}*
     50
     51		VER="-snp-${V}"
     52
     53		MAKE="make -C ${V} -j $(getconf _NPROCESSORS_ONLN) LOCALVERSION="
     54
     55		run_cmd $MAKE distclean
     56
     57		pushd ${V} >/dev/null
     58			# If ${KERNEL_GIT_URL} is ever changed, 'current' remote will be out
     59			# of date, so always update the remote URL first
     60			run_cmd git remote set-url current ${KERNEL_GIT_URL}
     61			run_cmd git fetch current
     62			run_cmd git checkout current/${BRANCH}
     63			COMMIT=$(git log --format="%h" -1 HEAD)
     64
     65			run_cmd "cp /boot/config-$(uname -r) .config"
     66			run_cmd ./scripts/config --set-str LOCALVERSION "$VER-$COMMIT"
     67			run_cmd ./scripts/config --disable LOCALVERSION_AUTO
     68			run_cmd ./scripts/config --enable  DEBUG_INFO
     69			run_cmd ./scripts/config --enable  DEBUG_INFO_REDUCED
     70			run_cmd ./scripts/config --enable  AMD_MEM_ENCRYPT
     71			run_cmd ./scripts/config --disable AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT
     72			run_cmd ./scripts/config --enable  KVM_AMD_SEV
     73			run_cmd ./scripts/config --module  CRYPTO_DEV_CCP_DD
     74			run_cmd ./scripts/config --disable SYSTEM_TRUSTED_KEYS
     75			run_cmd ./scripts/config --disable SYSTEM_REVOCATION_KEYS
     76			run_cmd ./scripts/config --module  SEV_GUEST
     77			run_cmd ./scripts/config --disable IOMMU_DEFAULT_PASSTHROUGH
     78			run_cmd ./scripts/config --disable PREEMPT_COUNT
     79			run_cmd ./scripts/config --disable PREEMPTION
     80			run_cmd ./scripts/config --disable PREEMPT_DYNAMIC
     81			run_cmd ./scripts/config --disable DEBUG_PREEMPT
     82		popd >/dev/null
     83
     84		yes "" | $MAKE olddefconfig
     85
     86		# Build 
     87		run_cmd $MAKE >/dev/null
     88
     89		if [ "$ID" = "debian" ] || [ "$ID_LIKE" = "debian" ]; then
     90			run_cmd $MAKE bindeb-pkg
     91		else
     92			run_cmd $MAKE "RPMOPTS='--define \"_rpmdir .\"'" binrpm-pkg
     93			run_cmd mv ${V}/x86_64/*.rpm .
     94		fi
     95	done
     96
     97	popd
     98}
     99
    100build_install_ovmf()
    101{
    102	DEST="$1"
    103
    104	GCC_VERSION=$(gcc -v 2>&1 | tail -1 | awk '{print $3}')
    105	GCC_MAJOR=$(echo $GCC_VERSION | awk -F . '{print $1}')
    106	GCC_MINOR=$(echo $GCC_VERSION | awk -F . '{print $2}')
    107	if [ "$GCC_MAJOR" == "4" ]; then
    108		GCCVERS="GCC${GCC_MAJOR}${GCC_MINOR}"
    109	else
    110		GCCVERS="GCC5"
    111	fi
    112
    113	BUILD_CMD="nice build -q --cmd-len=64436 -DDEBUG_ON_SERIAL_PORT=TRUE -n $(getconf _NPROCESSORS_ONLN) ${GCCVERS:+-t $GCCVERS} -a X64 -p OvmfPkg/OvmfPkgX64.dsc"
    114
    115	[ -d ovmf ] || {
    116		run_cmd git clone --single-branch -b ${OVMF_BRANCH} ${OVMF_GIT_URL} ovmf
    117
    118		pushd ovmf >/dev/null
    119			run_cmd git submodule update --init --recursive
    120		popd >/dev/null
    121	}
    122
    123	pushd ovmf >/dev/null
    124		run_cmd make -C BaseTools
    125		. ./edksetup.sh --reconfig
    126		run_cmd $BUILD_CMD
    127
    128		mkdir -p $DEST
    129		run_cmd cp -f Build/OvmfX64/DEBUG_$GCCVERS/FV/OVMF_CODE.fd $DEST
    130		run_cmd cp -f Build/OvmfX64/DEBUG_$GCCVERS/FV/OVMF_VARS.fd $DEST
    131	popd >/dev/null
    132}
    133
    134build_install_qemu()
    135{
    136	DEST="$1"
    137
    138	[ -d qemu ] || run_cmd git clone --single-branch -b ${QEMU_BRANCH} ${QEMU_GIT_URL} qemu
    139
    140	MAKE="make -j $(getconf _NPROCESSORS_ONLN) LOCALVERSION="
    141
    142	pushd qemu >/dev/null
    143		run_cmd ./configure --disable-werror --target-list=x86_64-softmmu --prefix=$DEST
    144		run_cmd $MAKE
    145		run_cmd $MAKE install
    146	popd >/dev/null
    147}