Refactor run_qemu.sh to construct entire command into a variable

So as to be able to invoke QEMU twice during one invocation of the
script, refactor run_qemu.sh to construct the entire QEMU command into
the CMD variable before passing it to `exec`. No functional change
intended.

Test: make test
Change-Id: I79459ce84bfc90f58e04a042d3a40fa6c16bc04a
diff --git a/aarch64/run_qemu.sh b/aarch64/run_qemu.sh
index 226f288..5fb1a37 100755
--- a/aarch64/run_qemu.sh
+++ b/aarch64/run_qemu.sh
@@ -54,7 +54,6 @@
 
 CMD=()
 APPEND=()
-EXTRA_ARGS=()
 EXTRA_RO_MOUNTS=()
 
 while getopts ":e:L:k:r:R:c:s:m:g:t:vGh" OPT; do
@@ -94,37 +93,42 @@
 	exit 1
 fi
 
-if [ "${TIMEOUT}" != "" ]; then
+if [ -n "${TIMEOUT}" ]; then
 	CMD+=(timeout -k 1s --foreground "${TIMEOUT}")
 fi
+
+# Note: Due to a bug in older versions of Bash, use '${array[@]+"${array[@]}"}'
+# to expand potentially empty arrays. '${array[@]}' is treated as undefined.
 CMD+=("${QEMU}")
+CMD+=(-M virt)
+CMD+=(-machine virtualization=true -machine virt,gic-version=${GIC})
+CMD+=(-cpu "${CPU}")
+CMD+=(-smp "${SMP}")
+CMD+=(-m "${RAM}")
+CMD+=(-L "${ROM_DIR}")
+CMD+=(-kernel "${KERNEL}")
+CMD+=(-drive file="${ROOTFS}",readonly,if=virtio,format=raw)
+CMD+=(-object rng-random,filename=/dev/urandom,id=rng0)
+CMD+=(-device virtio-rng-pci,rng=rng0)
+CMD+=(-nographic -nodefaults -serial stdio)
+
 APPEND+=(rootwait root=/dev/vda)
 
 # Note: Due to a bug in older versions of Bash, use '${array[@]+"${array[@]}"}'
 # to expand potentially empty arrays. '${array[@]}' is treated as undefined.
 for MOUNT in ${EXTRA_RO_MOUNTS[@]+"${EXTRA_RO_MOUNTS[@]}"}; do
-	EXTRA_ARGS+=(-drive "file=${MOUNT},readonly,if=virtio,format=raw")
+	CMD+=(-drive "file=${MOUNT},readonly,if=virtio,format=raw")
 done
 
 if [ "${GDB}" -eq 1 ]; then
-	EXTRA_ARGS+=(-S -s)
+	CMD+=(-S -s)
 	APPEND+=(nokaslr)
 fi
 
+CMD+=(-append "${APPEND[*]}")
+
 if [ "${VERBOSE}" -eq 1 ]; then
 	set -x
 fi
 
-# Note: Due to a bug in older versions of Bash, use '${array[@]+"${array[@]}"}'
-# to expand potentially empty arrays. '${array[@]}' is treated as undefined.
-exec "${CMD[@]}"							\
-	-M virt								\
-	-machine virtualization=true -machine virt,gic-version=${GIC}	\
-	-cpu "${CPU}" -smp "${SMP}" -m "${RAM}"				\
-	-L "${ROM_DIR}" -kernel "${KERNEL}"				\
-	-drive file="${ROOTFS}",readonly,if=virtio,format=raw		\
-	-object rng-random,filename=/dev/urandom,id=rng0		\
-	-device virtio-rng-pci,rng=rng0					\
-	-nographic -nodefaults -serial stdio				\
-	-append "${APPEND[*]}"						\
-	${EXTRA_ARGS[@]+"${EXTRA_ARGS[@]}"}
+exec "${CMD[@]}"