2017-10-12 18:08:50 +00:00
|
|
|
#!/usr/bin/expect
|
|
|
|
|
2015-01-08 21:08:48 +00:00
|
|
|
##
|
|
|
|
# Reset the target machine or rather run the scenario with Qemu
|
|
|
|
#
|
|
|
|
|
|
|
|
source [genode_dir]/tool/run/qemu.inc
|
|
|
|
|
2017-10-12 18:08:50 +00:00
|
|
|
proc check_version {qemu_version qemu_min qemu_max} {
|
|
|
|
set version_min_list [split $qemu_min ".-"]
|
|
|
|
set version_min_list_len [llength $version_min_list]
|
|
|
|
|
|
|
|
set version_max_list [split $qemu_max ".-"]
|
|
|
|
set version_max_list_len [llength $version_max_list]
|
|
|
|
|
|
|
|
set version_list [split $qemu_version ".-"]
|
|
|
|
set version_list_len [llength $version_list]
|
|
|
|
|
|
|
|
set cmp 0
|
|
|
|
set cmp_min 0
|
|
|
|
set cmp_max 0
|
|
|
|
set i 0
|
|
|
|
|
|
|
|
foreach number $version_list {
|
|
|
|
set min 0
|
|
|
|
set max 0
|
|
|
|
if { $i < $version_min_list_len } { set min [lindex $version_min_list $i] }
|
|
|
|
if { $i < $version_max_list_len } { set max [lindex $version_max_list $i] }
|
|
|
|
|
|
|
|
set cmp [expr {$cmp + $number * pow(1000, $version_list_len - $i) }]
|
|
|
|
set cmp_min [expr {$cmp_min + $min * pow(1000, $version_list_len - $i) }]
|
|
|
|
set cmp_max [expr {$cmp_max + $max * pow(1000, $version_list_len - $i) }]
|
|
|
|
|
|
|
|
incr i
|
|
|
|
}
|
|
|
|
|
|
|
|
return [expr {($cmp_min < $cmp) && ($cmp < $cmp_max)}]
|
|
|
|
}
|
2015-01-08 21:08:48 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
# Execute scenario using Qemu
|
|
|
|
#
|
|
|
|
proc run_power_on { } {
|
|
|
|
global qemu_args
|
|
|
|
global qemu
|
|
|
|
global qemu_spawn_id
|
|
|
|
|
|
|
|
#
|
|
|
|
# Back out on platforms w/o Qemu support
|
|
|
|
#
|
|
|
|
if {![is_qemu_available]} { return 0 }
|
|
|
|
|
|
|
|
if {[have_spec x86_32]} { set qemu "qemu-system-i386" }
|
|
|
|
if {[have_spec x86_64]} { set qemu "qemu-system-x86_64" }
|
|
|
|
if {[have_spec arm]} { set qemu "qemu-system-arm" }
|
2019-03-29 10:08:06 +00:00
|
|
|
if {[have_spec arm_64]} { set qemu "qemu-system-aarch64" }
|
2015-01-08 21:08:48 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Only the x86_64 variant of Qemu provides the emulation of hardware
|
|
|
|
# virtualization features used by NOVA. So let's always stick to this
|
|
|
|
# variant of Qemu when working with NOVA even when operating in 32bit.
|
|
|
|
#
|
|
|
|
if {[have_spec nova]} { set qemu "qemu-system-x86_64" }
|
|
|
|
|
|
|
|
#
|
2019-03-29 10:08:06 +00:00
|
|
|
# Redirect serial output to stdio, but only when no explicit configuration
|
|
|
|
# of serial interfaces is specified in the run script.
|
|
|
|
# The 'mon' prefix enables the access to the qemu console.
|
2015-01-08 21:08:48 +00:00
|
|
|
#
|
2019-03-29 10:08:06 +00:00
|
|
|
if {![regexp -- {-serial} $qemu_args dummy]} {
|
|
|
|
|
|
|
|
#
|
|
|
|
# In the raspi3 model the first UART is never used as
|
|
|
|
# log output, but the second
|
|
|
|
#
|
|
|
|
if {[have_spec rpi3]} { append qemu_args " -serial null " }
|
|
|
|
append qemu_args " -serial mon:stdio "
|
|
|
|
}
|
2015-01-08 21:08:48 +00:00
|
|
|
|
2017-10-12 18:08:50 +00:00
|
|
|
# SVM virtualization is broken after $qemu_good_old and until before $qemu_good_new
|
2017-02-22 15:55:12 +00:00
|
|
|
# We use "-cpu phenom" when using VMs in Qemu
|
|
|
|
if {[regexp -- {-cpu phenom} $qemu_args dummy]} {
|
|
|
|
catch {exec $qemu --version} qemu_version
|
|
|
|
set qemu_version [regexp -inline {version[ ][0-9]+\.[0-9]+[\.0-9]*} $qemu_version]
|
|
|
|
set qemu_version [regexp -inline {[0-9]+\.[0-9]+[\.0-9]*} $qemu_version]
|
2017-10-12 18:08:50 +00:00
|
|
|
|
|
|
|
set qemu_good_old "2.4.1"
|
|
|
|
set qemu_good_new "2.8.1"
|
|
|
|
|
|
|
|
if {[check_version $qemu_version $qemu_good_old $qemu_good_new]} {
|
|
|
|
puts "\nYour Qemu version '$qemu_version' is not working with AMD SVM virtualisation"
|
|
|
|
puts "Known good Qemu versions are until $qemu_good_old and starting with $qemu_good_new\n"
|
2018-05-09 17:15:18 +00:00
|
|
|
exit 1
|
2017-02-22 15:55:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-08 21:08:48 +00:00
|
|
|
# tweak emulated platform for specific platforms
|
2015-09-03 12:55:05 +00:00
|
|
|
if {[have_spec pbxa9]} {
|
2015-01-08 21:08:48 +00:00
|
|
|
#
|
|
|
|
# For PBXA9 qemu adjusts provided RAM chips to the -m arg. Thus we
|
|
|
|
# filter user values and force value that enables all chips that Genode
|
|
|
|
# expects to be available. Not doing so leads to inexplicable errors.
|
|
|
|
#
|
|
|
|
regsub -all {\-m ([0-9])+} $qemu_args "" qemu_args
|
|
|
|
append qemu_args " -m 768"
|
|
|
|
append qemu_args " -M realview-pbx-a9"
|
|
|
|
}
|
2015-09-03 12:55:05 +00:00
|
|
|
if {[have_spec vpb926]} { append qemu_args " -M versatilepb -m 128 " }
|
|
|
|
if {[have_spec zynq_qemu]} { append qemu_args " -M xilinx-zynq-a9 -cpu cortex-a9 -m 256 " }
|
2019-03-29 10:08:06 +00:00
|
|
|
if {[have_spec rpi3]} { append qemu_args " -M raspi3 -m 512 " }
|
2015-01-08 21:08:48 +00:00
|
|
|
|
2019-09-14 23:10:20 +00:00
|
|
|
if {[have_spec virt_qemu]} {
|
2020-03-25 18:09:36 +00:00
|
|
|
append qemu_args " -M virt,virtualization=true"
|
2019-09-14 23:10:20 +00:00
|
|
|
if {[have_spec arm_v8a]} {
|
|
|
|
append qemu_args ",gic_version=3 -cpu cortex-a53 -smp 4"
|
|
|
|
}
|
|
|
|
if {[have_spec arm_v7a]} {
|
|
|
|
append qemu_args " -cpu cortex-a15 -smp 2"
|
|
|
|
}
|
|
|
|
append qemu_args " -m 2048"
|
|
|
|
}
|
|
|
|
|
2015-01-08 21:08:48 +00:00
|
|
|
# on x86, we support booting via pxe or iso/disk image
|
|
|
|
if {[have_spec x86]} {
|
2017-05-23 13:05:55 +00:00
|
|
|
if {![regexp -- {-m} $qemu_args dummy]} {
|
2018-04-05 13:16:06 +00:00
|
|
|
if {[have_spec okl4]} {
|
|
|
|
# okl4 system integration specifies RAM from 32 to 800 MiB
|
|
|
|
append qemu_args " -m 800 "
|
|
|
|
} else {
|
|
|
|
append qemu_args " -m 512 "
|
|
|
|
}
|
2017-05-23 13:05:55 +00:00
|
|
|
}
|
2015-01-08 21:08:48 +00:00
|
|
|
if {[have_include "load/tftp"]} {
|
|
|
|
append qemu_args " -boot n -tftp [run_dir] -bootp boot/pulsar -no-reboot -no-shutdown "
|
|
|
|
} else {
|
2017-01-11 21:05:03 +00:00
|
|
|
if {[have_include "image/iso"]} {
|
|
|
|
append qemu_args " -cdrom [run_dir].iso "
|
|
|
|
} else {
|
|
|
|
if {[have_include "image/disk"]} {
|
2017-09-20 20:56:00 +00:00
|
|
|
append qemu_args " -drive format=raw,file=[run_dir].img "
|
2017-01-11 21:05:03 +00:00
|
|
|
} else {
|
|
|
|
if {[have_include "image/uefi"]} {
|
2020-06-23 11:58:19 +00:00
|
|
|
set uefi_firmware "/usr/share/ovmf/OVMF.fd"
|
|
|
|
if {![file exists $uefi_firmware]} {
|
|
|
|
puts "'$uefi_firmware' uefi image missing. Please install a ovmf package matching your qemu version."
|
|
|
|
exit -3
|
|
|
|
}
|
|
|
|
append qemu_args " --bios $uefi_firmware -net none -drive format=raw,file=[run_dir].img "
|
2020-07-07 09:57:32 +00:00
|
|
|
|
|
|
|
# limit boot resolution in Qemu to 1920x1080
|
|
|
|
append qemu_args " -device VGA,vgamem_mb=8 "
|
2017-01-11 21:05:03 +00:00
|
|
|
} else {
|
|
|
|
puts "Aborting, cannot execute Qemu without a ISO or disk image"
|
|
|
|
exit -4
|
|
|
|
} } } }
|
2017-10-19 08:13:35 +00:00
|
|
|
|
|
|
|
append qemu_args " -machine q35 "
|
2015-01-08 21:08:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# on ARM, we supply the boot image as kernel
|
2019-03-29 10:08:06 +00:00
|
|
|
if {[have_spec arm] || [have_spec arm_v8]} { append qemu_args " -kernel [run_dir]/boot/image.elf " }
|
2015-01-08 21:08:48 +00:00
|
|
|
|
|
|
|
eval spawn $qemu $qemu_args
|
|
|
|
set qemu_spawn_id $spawn_id
|
2017-08-07 14:30:38 +00:00
|
|
|
|
|
|
|
return true
|
2015-01-08 21:08:48 +00:00
|
|
|
}
|