1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
#!/bin/bash
arch="$1"
disk_image="$2"
firmware="$3"
supported_arch='x86_64, arm, aarch64'
extra_args=''
common_args=''
qemu_prefix='qemu-system-'
efi_keys='ledge-kernel-uefi-certs.ext4.img'
ovmf_file='QEMU_EFI.fd'
print_help () {
echo "$0 <arch> <file> [firmware_type]"
echo "arch: Supported architectures $supported_arch"
echo "file: raw image file"
echo "firmware_type: optional. ovmf/u-boot. Defaults to U-boot"
exit 1
}
[ $# -lt 2 ] && print_help
# common args
common_args+=' -m 1024 -smp 2 -show-cursor'
common_args+=' -serial stdio '
common_args+=' -monitor null -nographic '
# setup RNG
common_args+=' -device virtio-rng-pci '
# setup common network
common_args+=' -device virtio-net-pci,netdev=net0,mac=52:54:00:12:34:02 '
common_args+=' -netdev tap,id=net0,ifname=tap0,script=no,downscript=no '
case "$arch" in
x86_64)
extra_args+=' -cpu host -enable-kvm '
if [ "$firmware" = 'ovmf' ]; then
ovmf_file='ovmf.qcow2'
extra_args+=" -drive file=$disk_image,id=hd,format=raw "
extra_args+=" -drive if=pflash,format=qcow2,file=$ovmf_file "
else
echo "U-Boot on x86-64 not supported"
exit 1
fi
;;
aarch64)
extra_args+=' -device virtio-blk-device,drive=disk0 '
extra_args+=" -drive id=disk0,file=$disk_image,if=none,format=raw "
extra_args+=' -cpu cortex-a57 '
if [ "$firmware" = 'ovmf' ]; then
extra_args+=' -machine virt'
extra_args+=" -bios $ovmf_file"
else
extra_args+=' -bios bl1.bin '
extra_args+=' -machine virt,secure=on '
extra_args+=' -d unimp -semihosting-config enable,target=native'
extra_args+=" -drive id=disk1,file=$efi_keys,if=none,format=raw"
extra_args+=' -device virtio-blk-device,drive=disk1 '
fi
;;
arm)
extra_args+=' -device virtio-blk-device,drive=disk0 '
extra_args+=" -drive id=disk0,file=$disk_image,if=none,format=raw "
extra_args+=' -cpu cortex-a15 '
if [ "$firmware" = 'ovmf' ]; then
extra_args+=' -machine virt'
extra_args+=" -bios $ovmf_file"
else
extra_args+=' -bios bl1.bin '
extra_args+=' -no-reboot'
extra_args+=' -machine virt,secure=on '
extra_args+=' -d unimp -semihosting-config enable,target=native'
extra_args+=" -drive id=disk1,file=$efi_keys,if=none,format=raw"
extra_args+=' -device virtio-blk-device,drive=disk1 '
fi
;;
*)
echo "Unknown arhcitecture $arch"
echo "Supported: $supported_arch"
exit 1
;;
esac
qemu_bin="$qemu_prefix""$arch"
# echo "Binary: $qemu_bin"
echo "Run: $qemu_bin $common_args $extra_args "
eval "sudo $qemu_bin" "$common_args" "$extra_args"
# OVMF
#qemu-system-aarch64 \
#-bios ${OVMF} -drive id=disk0,file=${DISK},if=none,format=raw -device virtio-blk-device,drive=disk0
|