summaryrefslogtreecommitdiff
path: root/qemu/run_qemu.sh
blob: d3d24dfdbcf0155ae3b5571873afbb5f3d75548e (plain)
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
93
94
95
96
97
#!/bin/bash

# This script can be run inside docker container to run on supported version of qemu:
# docker run -v `pwd`:/mnt -w/mnt -ti linaro/ci-amd64-ledge:stable /mnt/run_qemu.sh aarch64 ledge-iot-ledge-qemuarm64-.rootfs.wic

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='firmware.uefi-edk2.bin'
ovmf_vars='LEDGE_AARCH64_QEMU_VARS.bin'
firmware_file='firmware.uefi.uboot.bin'

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 2048 -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 '
common_args+=' -net nic,model=virtio,macaddr=DE:AD:BE:EF:36:03 -net user '

case "$arch" in
	x86_64)
		extra_args+=' -cpu host -enable-kvm '
		if [ "$firmware" = 'ovmf' ]; then
			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+=" -pflash $ovmf_file -pflash $ovmf_vars"
		else
			extra_args+=" -pflash $firmware_file"
			extra_args+=' -machine virt,secure=on '
			extra_args+=' -d unimp '
			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 $firmware_file "
			extra_args+=' -no-reboot'
			extra_args+=' -machine virt,secure=on '
			extra_args+=' -d unimp '
			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 "$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