Merge changes I5044588e,Ibc815c02,I191645b8

* changes:
  Add test-kut-pkvm configuration
  Add command line options for controlling PKVM mode
  Fix error message for invalid command line opts
diff --git a/Makefile b/Makefile
index 105a114..a7be173 100644
--- a/Makefile
+++ b/Makefile
@@ -73,10 +73,11 @@
 TARGET = aarch64-linux-gnu
 # The GCC toolchain is needed when building kvm-unit-tests as well as Linux
 # with Clang, because of lack of support for the LLVM integrated assembler.
-GCC_TOOLCHAIN_DIR = $(TOOLCHAIN_GCC_49)/bin/
+GCC_TOOLCHAIN_DIR = $(TOOLCHAIN_GCC_49)
+GCC_TOOLCHAIN_BIN = $(GCC_TOOLCHAIN_DIR)/bin/
 LLVM = "LLVM=1"
-# KVM Unit Tests requires additional flags to build with Clang.
-KUT_COMMON_CFLAGS := -Qunused-arguments --target=$(TARGET) -fno-integrated-as -Wno-asm-operand-widths -fpic --gcc-toolchain=$(GCC_TOOLCHAIN_DIR) --prefix=$(GCC_TOOLCHAIN_DIR)/$(TARGET)-
+# Some targets require additional flags to build with Clang.
+COMMON_CFLAGS := -Qunused-arguments --target=$(TARGET) -fno-integrated-as -Wno-asm-operand-widths -fpic --gcc-toolchain=$(GCC_TOOLCHAIN_DIR) --sysroot=$(GCC_TOOLCHAIN_DIR)/$(TARGET)/libc --prefix=$(GCC_TOOLCHAIN_BIN)/$(TARGET)-
 else
 $(error Unrecognized toolchain: TOOLCHAIN=$(TOOLCHAIN))
 endif
@@ -87,7 +88,7 @@
 LD := $(TOOLCHAIN_BIN)/$(TARGET)-ld
 OBJCOPY := $(TOOLCHAIN_BIN)/$(TARGET)-objcopy
 OBJDUMP := $(TOOLCHAIN_BIN)/$(TARGET)-objdump
-GCC_TOOLCHAIN_DIR := $(TOOLCHAIN_BIN)
+GCC_TOOLCHAIN_BIN := $(TOOLCHAIN_BIN)
 endif
 
 ##
@@ -172,7 +173,7 @@
 			--prefix=$(KUT_OUT) --arch=$(ARCH) \
 			--cc=$(CC) --ld=$(LD) \
 			--objcopy=$(OBJCOPY) --objdump=$(OBJDUMP)
-	COMMON_CFLAGS="$(KUT_COMMON_CFLAGS)" \
+	COMMON_CFLAGS="$(COMMON_CFLAGS)" \
 		$(MAKE) -C $(KUT_OUT) standalone
 	touch $(KUT_STAMP)
 
@@ -195,7 +196,7 @@
 	CROSS_COMPILE="$(TARGET)-" \
 	$(MAKE) \
 	$(LLVM) \
-	GCC_TOOLCHAIN_DIR="$(GCC_TOOLCHAIN_DIR)" \
+	GCC_TOOLCHAIN_DIR="$(GCC_TOOLCHAIN_BIN)" \
 	-C $(LINUX_SRC) \
 	V=$(LINUX_VERBOSE) \
 	O=$(LINUX_OUT)
diff --git a/aarch64/package_payloads.sh b/aarch64/package_payloads.sh
new file mode 100755
index 0000000..36ab253
--- /dev/null
+++ b/aarch64/package_payloads.sh
@@ -0,0 +1,102 @@
+#!/usr/bin/env bash
+
+# Copyright 2020 The Android KVM Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+source "$(dirname "${BASH_SOURCE[0]}")/../common.inc"
+
+function usage()
+{
+	cat <<EOF
+
+Packages the files passed in the command line in a bash script as base64
+payloads, and executes the specified command at the end of the script.
+
+The files are packaged under their basenames and extracted into the same
+temporary directory. The command is run from that temporary directory.
+
+Usage: $0 [-h] -c COMMAND <file> [<file> ...]
+    -h    output this help text
+    -c    command to run by the packaged script
+EOF
+}
+
+# Generates the header for the packaged script.
+function generate_header()
+{
+	echo "#!/usr/bin/env bash"
+        echo "set -euo pipefail"
+	echo "IMGDIR=\$(mktemp -d)"
+	echo "cd \${IMGDIR}"
+	echo
+}
+
+# Generates a base64 payload image for the image files passed.
+# First parameter holds the full path of the image to be packages.
+# Second parameter holds the name of the image to be generated.
+function generate_image()
+{
+	local image_path="${1}"
+	local image_name="${2}"
+
+	echo "base64 -d << 'EOF' | zcat > \"${image_name}\""
+	gzip -c "${image_path}" | base64
+	echo "EOF"
+	echo
+}
+
+while getopts ":c:h" opt; do
+	case $opt in
+	c) 	COMMAND="${OPTARG}";;
+	h)
+		usage
+		exit 0
+		;;
+	\?)
+		echo "Invalid option: ${!OPTIND}" 1>&2
+		usage 1>&2
+		exit 1
+		;;
+	:)
+		echo "Invalid option: -${OPTARG} requires an argument" 1>&2
+		usage 1>&2
+		exit 1
+		;;
+	esac
+done
+shift $((OPTIND - 1))
+
+if [ -z "$@" ]; then
+        echo "Must specify at least one image file to package." 1>&2
+        exit 1
+fi
+
+IMAGES=("$@")
+
+# Validate that all image files exist before emitting anything.
+for image in "${IMAGES[@]}"; do
+        if [ ! -f "${image}" ]; then
+		echo "Image file not found: ${image}" 1>&2
+		exit 1
+	fi
+done
+
+# Generate the packaged script.
+generate_header
+
+for image in "${IMAGES[@]}"; do
+        generate_image "${image}" "$(basename ${image})"
+done
+
+echo "${COMMAND}"