diff --git a/repos/base/board/pbxa9/qemu_args b/repos/base/board/pbxa9/qemu_args new file mode 100644 index 0000000000..cbda496704 --- /dev/null +++ b/repos/base/board/pbxa9/qemu_args @@ -0,0 +1 @@ +-m 768 -M realview-pbx-a9 diff --git a/repos/base/board/pc/qemu_args b/repos/base/board/pc/qemu_args new file mode 100644 index 0000000000..2df5a69e38 --- /dev/null +++ b/repos/base/board/pc/qemu_args @@ -0,0 +1 @@ +-machine q35 diff --git a/repos/base/board/riscv_qemu/qemu_args b/repos/base/board/riscv_qemu/qemu_args new file mode 100644 index 0000000000..24228a8b18 --- /dev/null +++ b/repos/base/board/riscv_qemu/qemu_args @@ -0,0 +1,2 @@ +-m 128 -machine virt -cpu rv64,priv_spec=v1.10.0 +-bios default diff --git a/repos/base/board/rpi3/qemu_args b/repos/base/board/rpi3/qemu_args new file mode 100644 index 0000000000..ce368f9589 --- /dev/null +++ b/repos/base/board/rpi3/qemu_args @@ -0,0 +1 @@ +-M raspi3 -m 1024 diff --git a/repos/base/board/virt_qemu/qemu_args b/repos/base/board/virt_qemu/qemu_args new file mode 100644 index 0000000000..c6fb1fb6f4 --- /dev/null +++ b/repos/base/board/virt_qemu/qemu_args @@ -0,0 +1,6 @@ +-m 2048 +-global virtio-mmio.force-legacy=false +-device virtio-mouse-device +-device virtio-keyboard-device +arm_v8a: -M virt,virtualization=true,gic-version=3 -cpu cortex-a53 -smp 4 +arm_v7a: -M virt,virtualization=true -cpu cortex-a15 -smp 2 diff --git a/tool/run/power_on/qemu b/tool/run/power_on/qemu index 48cd20f0e2..32b052c44c 100644 --- a/tool/run/power_on/qemu +++ b/tool/run/power_on/qemu @@ -35,6 +35,42 @@ proc check_version {qemu_version qemu_min qemu_max} { return [expr {($cmp_min < $cmp) && ($cmp < $cmp_max)}] } +## +# +# +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. + # Arguments might be general or restricted to a particular spec as follows: + # general arguments + # arm_v7a: arguments for arm_v7a + # + set qemu_args "" + foreach line [split $file_content "\n"] { + if {[regexp {^([\w]+):(.*)$} $line dummy spec arg]} { + if {[have_spec $spec]} { append qemu_args " $arg" } + } else { + # general arguments + append qemu_args " $line" + } + } + + return $qemu_args +} + ## # Execute scenario using Qemu # @@ -43,6 +79,9 @@ proc run_power_on { } { global qemu global qemu_spawn_id + # save original qemu_args to support retrying + set original_qemu_args $qemu_args + # # Back out on platforms w/o Qemu support # @@ -93,35 +132,6 @@ proc run_power_on { } { } } - # tweak emulated platform for specific platforms - if {[have_board pbxa9]} { - # - # 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" - } - if {[have_board vpb926]} { append qemu_args " -M versatilepb -m 128 " } - if {[have_board zynq_qemu]} { append qemu_args " -M xilinx-zynq-a9 -cpu cortex-a9 -m 256 " } - if {[have_board rpi3]} { append qemu_args " -M raspi3 -m 512 " } - - if {[have_board virt_qemu]} { - append qemu_args " -M virt,virtualization=true" - 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" - append qemu_args " -global virtio-mmio.force-legacy=false " - append qemu_args " -device virtio-mouse-device" - append qemu_args " -device virtio-keyboard-device" - } - # on x86, we support booting via pxe or iso/disk image if {[have_board pc]} { @@ -174,21 +184,28 @@ proc run_power_on { } { puts "Aborting, cannot execute Qemu without a ISO or disk image" exit -4 } } } } - - append qemu_args " -machine q35 " - } - - if {[have_board riscv_qemu]} { - append qemu_args " -m 128 -machine virt -cpu rv64,priv_spec=v1.10.0 " - append qemu_args " -bios default " } # 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 " } + 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 } + + # append custom board-specific qemu_args + append qemu_args " $board_qemu_args" + eval spawn $qemu $qemu_args set qemu_spawn_id $spawn_id + # restore original qemu_args to support retrying + set qemu_args $original_qemu_args + return true } diff --git a/tool/run/qemu.inc b/tool/run/qemu.inc index 41657fadd1..c51d172111 100644 --- a/tool/run/qemu.inc +++ b/tool/run/qemu.inc @@ -41,10 +41,12 @@ proc append_qemu_nic_args { { extra_netdev_args "" } } { ## # Check whether Qemu support is available # -# XXX should by removed in favor of [have_include "exec/qemu"] -# proc is_qemu_available { } { - if {[have_board rpi] || [have_board linux]} { + set qemu_args_file [file join "board" [board] "qemu_args"] + + set repo [repository_contains $qemu_args_file] + + if {$repo == ""} { puts stderr "skipping execution because platform is not supported by qemu" return false }