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
|
|
|
|
#
|
|
|
|
|
|
|
|
|
2021-08-18 14:17:03 +00:00
|
|
|
##
|
|
|
|
#
|
|
|
|
#
|
|
|
|
proc board_qemu_args { } {
|
|
|
|
|
|
|
|
set qemu_args_file [file join "board" [board] "qemu_args"]
|
|
|
|
|
|
|
|
set repo [repository_contains $qemu_args_file]
|
|
|
|
|
|
|
|
if {$repo == ""} {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
set fh [open [file join $repo $qemu_args_file] "RDONLY"]
|
|
|
|
set file_content [read $fh]
|
|
|
|
close $fh
|
|
|
|
|
|
|
|
##
|
|
|
|
# Each line is appended to qemu_args.
|
|
|
|
#
|
|
|
|
set qemu_args ""
|
|
|
|
foreach line [split $file_content "\n"] {
|
|
|
|
# general arguments
|
|
|
|
append qemu_args " $line"
|
|
|
|
}
|
|
|
|
|
|
|
|
return $qemu_args
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2021-08-18 14:17:03 +00:00
|
|
|
# save original qemu_args to support retrying
|
|
|
|
set original_qemu_args $qemu_args
|
|
|
|
|
2015-01-08 21:08:48 +00:00
|
|
|
#
|
|
|
|
# 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" }
|
2021-02-10 07:31:39 +00:00
|
|
|
if {[have_spec riscv]} { set qemu "qemu-system-riscv64" }
|
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
|
|
|
|
#
|
2021-01-13 09:15:10 +00:00
|
|
|
if {[have_board rpi3]} { append qemu_args " -serial null " }
|
2019-03-29 10:08:06 +00:00
|
|
|
append qemu_args " -serial mon:stdio "
|
|
|
|
}
|
2015-01-08 21:08:48 +00:00
|
|
|
|
|
|
|
# on x86, we support booting via pxe or iso/disk image
|
2021-01-13 09:15:10 +00:00
|
|
|
if {[have_board pc]} {
|
2021-05-11 11:56:44 +00:00
|
|
|
|
2021-11-03 11:21:46 +00:00
|
|
|
if {[regexp -- {-m\s+} $qemu_args dummy]} {
|
|
|
|
# can be -m 1024 or -m 1024G or -m size=1024G
|
|
|
|
set qemu_ram [regexp -inline {\-m\s+\S+} $qemu_args]
|
|
|
|
if {![regexp {([0-9]+)([MG]?)} $qemu_ram dummy qemu_ram ram_unit]} {
|
|
|
|
puts "Cannot parse memory argument ($qemu_ram)\n"
|
2021-05-11 11:56:44 +00:00
|
|
|
exit 1
|
2018-04-05 13:16:06 +00:00
|
|
|
}
|
2021-05-11 11:56:44 +00:00
|
|
|
|
2021-11-03 11:21:46 +00:00
|
|
|
if { $ram_unit == "G" } {
|
|
|
|
set qemu_ram [expr {$qemu_ram*1024}] }
|
2021-05-11 11:56:44 +00:00
|
|
|
|
2021-11-03 11:21:46 +00:00
|
|
|
if {[have_spec okl4]} {
|
|
|
|
if {$qemu_ram < 800} {
|
|
|
|
puts "Configured memory ($qemu_ram) for OKL4 on Qemu must be at least 800M\n"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
##
|
|
|
|
# append memory argument if not present, 800M is a sane default because:
|
|
|
|
# - 800M is minimum for OKL4
|
|
|
|
# - 768M is required for certain test cases (#3387)
|
|
|
|
#
|
|
|
|
append qemu_args " -m 800 "
|
|
|
|
}
|
2021-05-11 11:56:44 +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
|
|
|
|
} } } }
|
2021-02-10 07:31:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# on ARM/RISC-V, we supply the boot image as kernel
|
|
|
|
if {[have_spec arm] || [have_spec arm_v8] || [have_spec riscv]} {
|
|
|
|
append qemu_args " -kernel [run_dir]/boot/image.elf " }
|
2015-01-08 21:08:48 +00:00
|
|
|
|
2021-08-18 14:17:03 +00:00
|
|
|
set board_qemu_args [board_qemu_args]
|
|
|
|
|
|
|
|
##
|
|
|
|
# remove any -m arguments from qemu args if specified by board_qemu_args
|
|
|
|
# note, that we must not match/remove -machine, but allow -m size=1G,slots=3,maxmem=4G
|
|
|
|
if {[regexp -- {-m\s+} $board_qemu_args dummy]} {
|
|
|
|
regsub -all {\-m\s+\S+} $qemu_args "" qemu_args }
|
|
|
|
|
2021-11-03 14:27:35 +00:00
|
|
|
##
|
|
|
|
# let user override any netdev
|
|
|
|
#
|
|
|
|
if {[regexp -- {-netdev\s+user,id=(\w+)} $qemu_args dummy netdev]} {
|
|
|
|
regsub -all "\\-netdev\\s+user,id=$netdev\\S*" $board_qemu_args "" board_qemu_args }
|
|
|
|
|
2023-06-02 07:05:50 +00:00
|
|
|
##
|
|
|
|
# If -cpu is specified by qemu_args, remove -cpu from board_qemu_args to
|
|
|
|
# support overwriting it, e.g. used for virtualization scenarios
|
|
|
|
#
|
|
|
|
if {[regexp -- {-cpu\s+} $qemu_args dummy]} {
|
|
|
|
regsub -all {\-cpu\s+\S*} $board_qemu_args "" board_qemu_args }
|
|
|
|
|
2021-08-18 14:17:03 +00:00
|
|
|
# append custom board-specific qemu_args
|
|
|
|
append qemu_args " $board_qemu_args"
|
|
|
|
|
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
|
|
|
|
2021-08-18 14:17:03 +00:00
|
|
|
# restore original qemu_args to support retrying
|
|
|
|
set qemu_args $original_qemu_args
|
|
|
|
|
2017-08-07 14:30:38 +00:00
|
|
|
return true
|
2015-01-08 21:08:48 +00:00
|
|
|
}
|