Skip to content

Commit

Permalink
qemu: add option microvm.qemu.serialConsole
Browse files Browse the repository at this point in the history
For some applications like UART passthrough we want to
disable the default qemu virtual serial (-serial chardev:stdio).
With this flag in false we remove this virtual device and the
ttyAMA0/S0 kernel console.

Signed-off-by: Juan Pablo Ruiz <[email protected]>
  • Loading branch information
jpruiz84 authored and astro committed Jan 24, 2024
1 parent f07dd64 commit ce0d2e3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
21 changes: 17 additions & 4 deletions lib/runners/qemu.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ let
pkgs.qemu_kvm else pkgs.buildPackages.qemu_full);

inherit (microvmConfig) hostName cpu vcpu mem balloonMem user interfaces shares socket forwardPorts devices vsock graphics storeOnDisk kernel initrdPath storeDisk;
inherit (microvmConfig.qemu) extraArgs;
inherit (microvmConfig.qemu) extraArgs serialConsole;

inherit (import ../. { nixpkgs-lib = pkgs.lib; }) withDriveLetters;

Expand Down Expand Up @@ -121,6 +121,17 @@ let
writeQmp = data: ''
echo '${builtins.toJSON data}'
'';

kernelConsole =
if microvmConfig.qemu.serialConsole == false
then ""
else if system == "x86_64-linux"
then "earlyprintk=ttyS0 console=ttyS0"
else if system == "aarch64-linux"
then "console=ttyAMA0"
else "";


in {
inherit tapMultiQueue;

Expand All @@ -139,20 +150,22 @@ in {
"-initrd" initrdPath

"-chardev" "stdio,id=stdio,signal=off"
"-serial" "chardev:stdio"
"-device" "virtio-rng-${devType}"
] ++
lib.optionals serialConsole [
"-serial" "chardev:stdio"
] ++
lib.optionals (microvmConfig.cpu == null) [
"-enable-kvm"
] ++
cpuArgs ++
lib.optionals (system == "x86_64-linux") [
"-device" "i8042"

"-append" "earlyprintk=ttyS0 console=ttyS0 reboot=t panic=-1 ${toString microvmConfig.kernelParams}"
"-append" "${kernelConsole} reboot=t panic=-1 ${toString microvmConfig.kernelParams}"
] ++
lib.optionals (system == "aarch64-linux") [
"-append" "console=ttyAMA0 reboot=t panic=-1 ${toString microvmConfig.kernelParams}"
"-append" "${kernelConsole} reboot=t panic=-1 ${toString microvmConfig.kernelParams}"
] ++
lib.optionals storeOnDisk [
"-drive" "id=store,format=raw,read-only=on,file=${storeDisk},if=none,aio=io_uring"
Expand Down
8 changes: 8 additions & 0 deletions nixos-modules/microvm/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,14 @@ in
description = "Extra arguments to pass to qemu.";
};

qemu.serialConsole = mkOption {
type = types.bool;
default = true;
description = ''
Whether to enable the virtual serial console on qemu.
'';
};

crosvm.extraArgs = mkOption {
type = with types; listOf str;
default = [];
Expand Down

0 comments on commit ce0d2e3

Please sign in to comment.