From e56da6a4642c843d7ba88f513840da7d473eecec Mon Sep 17 00:00:00 2001 From: Tuomas Tynkkynen Date: Fri, 24 Nov 2017 14:31:50 +0200 Subject: nixos/qemu-vm: Use different serial port on ARM/AArch64 --- nixos/modules/testing/test-instrumentation.nix | 22 ++++++++++++++-------- nixos/modules/virtualisation/qemu-vm.nix | 7 ++++++- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/nixos/modules/testing/test-instrumentation.nix b/nixos/modules/testing/test-instrumentation.nix index 7f5b55d5cca0..1d6c41406107 100644 --- a/nixos/modules/testing/test-instrumentation.nix +++ b/nixos/modules/testing/test-instrumentation.nix @@ -5,7 +5,13 @@ with lib; -let kernel = config.boot.kernelPackages.kernel; in +let + kernel = config.boot.kernelPackages.kernel; + # FIXME: figure out a common place for this instead of copy pasting + serialDevice = if pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64 then "ttyS0" + else if pkgs.stdenv.isArm || pkgs.stdenv.isAarch64 then "ttyAMA0" + else throw "Unknown QEMU serial device for system '${pkgs.stdenv.system}'"; +in { @@ -22,8 +28,8 @@ let kernel = config.boot.kernelPackages.kernel; in systemd.services.backdoor = { wantedBy = [ "multi-user.target" ]; - requires = [ "dev-hvc0.device" "dev-ttyS0.device" ]; - after = [ "dev-hvc0.device" "dev-ttyS0.device" ]; + requires = [ "dev-hvc0.device" "dev-${serialDevice}.device" ]; + after = [ "dev-hvc0.device" "dev-${serialDevice}.device" ]; script = '' export USER=root @@ -40,7 +46,7 @@ let kernel = config.boot.kernelPackages.kernel; in cd /tmp exec < /dev/hvc0 > /dev/hvc0 - while ! exec 2> /dev/ttyS0; do sleep 0.1; done + while ! exec 2> /dev/${serialDevice}; do sleep 0.1; done echo "connecting to host..." >&2 stty -F /dev/hvc0 raw -echo # prevent nl -> cr/nl conversion echo @@ -49,10 +55,10 @@ let kernel = config.boot.kernelPackages.kernel; in serviceConfig.KillSignal = "SIGHUP"; }; - # Prevent agetty from being instantiated on ttyS0, since it - # interferes with the backdoor (writes to ttyS0 will randomly fail + # Prevent agetty from being instantiated on ${serialDevice}, since it + # interferes with the backdoor (writes to ${serialDevice} will randomly fail # with EIO). Likewise for hvc0. - systemd.services."serial-getty@ttyS0".enable = false; + systemd.services."serial-getty@${serialDevice}".enable = false; systemd.services."serial-getty@hvc0".enable = false; boot.initrd.preDeviceCommands = @@ -88,7 +94,7 @@ let kernel = config.boot.kernelPackages.kernel; in # Panic if an error occurs in stage 1 (rather than waiting for # user intervention). boot.kernelParams = - [ "console=ttyS0" "panic=1" "boot.panic_on_fail" ]; + [ "console=${serialDevice}" "panic=1" "boot.panic_on_fail" ]; # `xwininfo' is used by the test driver to query open windows. environment.systemPackages = [ pkgs.xorg.xwininfo ]; diff --git a/nixos/modules/virtualisation/qemu-vm.nix b/nixos/modules/virtualisation/qemu-vm.nix index 3f10180cd1cc..770e5fb848a9 100644 --- a/nixos/modules/virtualisation/qemu-vm.nix +++ b/nixos/modules/virtualisation/qemu-vm.nix @@ -21,6 +21,11 @@ let "aarch64-linux" = "${qemu}/bin/qemu-system-aarch64 -enable-kvm -machine virt -cpu host"; }.${pkgs.stdenv.system}; + # FIXME: figure out a common place for this instead of copy pasting + serialDevice = if pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64 then "ttyS0" + else if pkgs.stdenv.isArm || pkgs.stdenv.isAarch64 then "ttyAMA0" + else throw "Unknown QEMU serial device for system '${pkgs.stdenv.system}'"; + vmName = if config.networking.hostName == "" then "noname" @@ -29,7 +34,7 @@ let cfg = config.virtualisation; qemuGraphics = if cfg.graphics then "" else "-nographic"; - kernelConsole = if cfg.graphics then "" else "console=ttyS0"; + kernelConsole = if cfg.graphics then "" else "console=${serialDevice}"; ttys = [ "tty1" "tty2" "tty3" "tty4" "tty5" "tty6" ]; # Shell script to start the VM. -- cgit 1.4.1