mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-22 22:21:10 +02:00
Add arm64 qemu image support
Allows image_to_vm.sh to build also arm64 qemu images. Signed-off-by: Andrej Rosano <andrej@inversepath.com>
This commit is contained in:
parent
99987eedcd
commit
8ba400eca7
@ -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
|
||||
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}" "$@"
|
||||
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 \
|
||||
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 $?
|
||||
|
@ -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}" <<EOF
|
||||
If you have qemu installed (or in the SDK), you can start the image with:
|
||||
cd path/to/image
|
||||
./$(basename "${script}") -curses
|
||||
./$(basename "${script}") -curses ${arm64_msg}
|
||||
|
||||
If you need to use a different ssh key or different ssh port:
|
||||
./$(basename "${script}") -a ~/.ssh/authorized_keys -p 2223 -- -curses
|
||||
./$(basename "${script}") -a ~/.ssh/authorized_keys -p 2223 -- -curses ${arm64_msg}
|
||||
|
||||
If you rather you can use the -nographic option instad of -curses. In this
|
||||
mode you can switch from the vm to the qemu monitor console with: Ctrl-a c
|
||||
@ -604,6 +610,14 @@ SSH into that host with:
|
||||
ssh 127.0.0.1 -p 2222
|
||||
EOF
|
||||
|
||||
if [[ ${BOARD} == "arm64-usr" ]]; then
|
||||
cat >>"${VM_README}" <<EOF
|
||||
|
||||
A prebuilt QEMU EFI firmware can be downloaded at the following link:
|
||||
http://snapshots.linaro.org/components/kernel/leg-virt-tianocore-edk2-upstream/latest/QEMU-AARCH64/RELEASE_GCC48/QEMU_EFI.fd
|
||||
EOF
|
||||
fi
|
||||
|
||||
VM_GENERATED_FILES+=( "${script}" "${VM_README}" )
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user