From 8ba400eca7c03c4ab1e7ef5019138ec167a2241c Mon Sep 17 00:00:00 2001 From: Andrej Rosano Date: Thu, 17 Sep 2015 13:59:01 +0200 Subject: [PATCH] Add arm64 qemu image support Allows image_to_vm.sh to build also arm64 qemu images. Signed-off-by: Andrej Rosano --- build_library/qemu_template.sh | 51 +++++++++++++++++++++++++++------- build_library/vm_image_util.sh | 18 ++++++++++-- 2 files changed, 57 insertions(+), 12 deletions(-) diff --git a/build_library/qemu_template.sh b/build_library/qemu_template.sh index 66cb2234fc..1a73c22042 100755 --- a/build_library/qemu_template.sh +++ b/build_library/qemu_template.sh @@ -1,6 +1,7 @@ #!/bin/sh SCRIPT_DIR="`dirname "$0"`" +VM_BOARD= VM_NAME= VM_UUID= VM_IMAGE= @@ -136,8 +137,15 @@ if [ "${SAFE_ARGS}" -eq 1 ]; then # Disable KVM, for testing things like UEFI which don't like it set -- -machine accel=tcg "$@" else - # Emulate the host CPU closely in both features and cores. - set -- -machine accel=kvm -cpu host -smp "${VM_NCPUS}" "$@" + case "${VM_BOARD}" in + amd64-usr) + # Emulate the host CPU closely in both features and cores. + set -- -machine accel=kvm -cpu host -smp "${VM_NCPUS}" "$@" ;; + arm64-usr) + #FIXME(andrejro): tune the smp parameter + set -- -machine virt -cpu cortex-a57 -machine type=virt -smp 1 "$@" ;; + *) die "Unsupported arch" ;; + esac fi # ${CONFIG_DRIVE} or ${CONFIG_IMAGE} will be mounted in CoreOS as /media/configdrive @@ -152,7 +160,15 @@ if [ -n "${CONFIG_IMAGE}" ]; then fi if [ -n "${VM_IMAGE}" ]; then - set -- -drive if=virtio,file="${SCRIPT_DIR}/${VM_IMAGE}" "$@" + case "${VM_BOARD}" in + amd64-usr) + set -- -drive if=virtio,file="${SCRIPT_DIR}/${VM_IMAGE}" "$@" ;; + arm64-usr) + set -- -drive if=none,id=blk,file="${SCRIPT_DIR}/${VM_IMAGE}" \ + -device virtio-blk-device,drive=blk "$@" + ;; + *) die "Unsupported arch" ;; + esac fi if [ -n "${VM_KERNEL}" ]; then @@ -177,11 +193,26 @@ if [ -n "${VM_PFLASH_RO}" ] && [ -n "${VM_PFLASH_RW}" ]; then -drive if=pflash,file="${SCRIPT_DIR}/${VM_PFLASH_RW}",format=raw "$@" fi -# Default to KVM, fall back on full emulation -qemu-system-x86_64 \ - -name "$VM_NAME" \ - -m ${VM_MEMORY} \ - -net nic,vlan=0,model=virtio \ - -net user,vlan=0,hostfwd=tcp::"${SSH_PORT}"-:22,hostname="${VM_NAME}" \ - "$@" +case "${VM_BOARD}" in + amd64-usr) + # Default to KVM, fall back on full emulation + qemu-system-x86_64 \ + -name "$VM_NAME" \ + -m ${VM_MEMORY} \ + -net nic,vlan=0,model=virtio \ + -net user,vlan=0,hostfwd=tcp::"${SSH_PORT}"-:22,hostname="${VM_NAME}" \ + "$@" + ;; + arm64-usr) + qemu-system-aarch64 -nographic \ + -bios QEMU_EFI.fd \ + -name "$VM_NAME" \ + -m ${VM_MEMORY} \ + -netdev user,id=eth0,hostfwd=tcp::"${SSH_PORT}"-:22,hostname="${VM_NAME}" \ + -device virtio-net-device,netdev=eth0 \ + "$@" + ;; + *) die "Unsupported arch" ;; +esac + exit $? diff --git a/build_library/vm_image_util.sh b/build_library/vm_image_util.sh index e0126680a0..152f720777 100644 --- a/build_library/vm_image_util.sh +++ b/build_library/vm_image_util.sh @@ -584,17 +584,23 @@ _write_qemu_common() { sed -e "s%^VM_NAME=.*%VM_NAME='${VM_NAME}'%" \ -e "s%^VM_MEMORY=.*%VM_MEMORY='${vm_mem}'%" \ + -e "s%^VM_BOARD=.*%VM_BOARD='${BOARD}'%" \ "${BUILD_LIBRARY_DIR}/qemu_template.sh" > "${script}" checkbashisms --posix "${script}" || die chmod +x "${script}" + arm64_msg="" + if [[ ${BOARD} == "arm64-usr" ]]; then + arm64_msg="-bios QEMU_EFI.fd" + fi + cat >"${VM_README}" <>"${VM_README}" <