Add support for virtio-9p file sharing
To avoid the need for packaging files as a disk image, add a new flag to
run_qemu.sh which will share a folder with the QEMU-emulated VM. Folders
are shared as read only.
Test: ./build/aarch64/run_qemu.sh -D tag:path
Change-Id: I885f91f3764c481b2c284d97c882e86af3b3dc11
diff --git a/aarch64/run_qemu.sh b/aarch64/run_qemu.sh
index 68aca8b..180b889 100755
--- a/aarch64/run_qemu.sh
+++ b/aarch64/run_qemu.sh
@@ -61,6 +61,7 @@
-k kernel image
-r root filesystem image
-R additional drive image(s) to mount as read-only
+ -D 'tag:path' pair to mount as read-only using 9p
-F pvmfw image
-c CPU model (defaults to "${DEFAULT_CPU}")
-s number of CPU cores (defaults to ${DEFAULT_SMP})
@@ -134,14 +135,16 @@
CMD=()
APPEND=()
EXTRA_RO_MOUNTS=()
+EXTRA_9P_MOUNTS=()
-while getopts ":e:L:k:r:R:F:c:s:m:g:t:M:a:vGKh" OPT; do
+while getopts ":e:L:k:r:R:D:F:c:s:m:g:t:M:a:vGKh" OPT; do
case "${OPT}" in
e) QEMU="${OPTARG}" ;;
L) ROM_DIR="${OPTARG}" ;;
k) KERNEL="${OPTARG}" ;;
r) ROOTFS="${OPTARG}" ;;
R) EXTRA_RO_MOUNTS+=("${OPTARG}") ;;
+ D) EXTRA_9P_MOUNTS+=("${OPTARG}") ;;
F) PVMFW="${OPTARG}" ;;
c) CPU="${OPTARG}" ;;
s) SMP="${OPTARG}" ;;
@@ -221,6 +224,15 @@
CMD+=(-drive "file=${MOUNT},readonly=on,if=virtio,format=raw")
done
+# 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_9P_MOUNTS[@]+"${EXTRA_9P_MOUNTS[@]}"}; do
+ TAG=$(echo "$MOUNT" | cut -d: -f1)
+ DIR=$(echo "$MOUNT" | cut -d: -f2-)
+ CMD+=(-virtfs)
+ CMD+=("local,readonly=on,security_model=mapped-xattr,path=${DIR},mount_tag=${TAG}")
+done
+
if [ "${GDB}" -eq 1 ]; then
CMD+=(-S -s)
APPEND+=(nokaslr)