Skip to content

Commit ce0d2e3

Browse files
jpruiz84astro
authored andcommitted
qemu: add option microvm.qemu.serialConsole
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]>
1 parent f07dd64 commit ce0d2e3

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

lib/runners/qemu.nix

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ let
3939
pkgs.qemu_kvm else pkgs.buildPackages.qemu_full);
4040

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

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

@@ -121,6 +121,17 @@ let
121121
writeQmp = data: ''
122122
echo '${builtins.toJSON data}'
123123
'';
124+
125+
kernelConsole =
126+
if microvmConfig.qemu.serialConsole == false
127+
then ""
128+
else if system == "x86_64-linux"
129+
then "earlyprintk=ttyS0 console=ttyS0"
130+
else if system == "aarch64-linux"
131+
then "console=ttyAMA0"
132+
else "";
133+
134+
124135
in {
125136
inherit tapMultiQueue;
126137

@@ -139,20 +150,22 @@ in {
139150
"-initrd" initrdPath
140151

141152
"-chardev" "stdio,id=stdio,signal=off"
142-
"-serial" "chardev:stdio"
143153
"-device" "virtio-rng-${devType}"
144154
] ++
155+
lib.optionals serialConsole [
156+
"-serial" "chardev:stdio"
157+
] ++
145158
lib.optionals (microvmConfig.cpu == null) [
146159
"-enable-kvm"
147160
] ++
148161
cpuArgs ++
149162
lib.optionals (system == "x86_64-linux") [
150163
"-device" "i8042"
151164

152-
"-append" "earlyprintk=ttyS0 console=ttyS0 reboot=t panic=-1 ${toString microvmConfig.kernelParams}"
165+
"-append" "${kernelConsole} reboot=t panic=-1 ${toString microvmConfig.kernelParams}"
153166
] ++
154167
lib.optionals (system == "aarch64-linux") [
155-
"-append" "console=ttyAMA0 reboot=t panic=-1 ${toString microvmConfig.kernelParams}"
168+
"-append" "${kernelConsole} reboot=t panic=-1 ${toString microvmConfig.kernelParams}"
156169
] ++
157170
lib.optionals storeOnDisk [
158171
"-drive" "id=store,format=raw,read-only=on,file=${storeDisk},if=none,aio=io_uring"

nixos-modules/microvm/options.nix

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,14 @@ in
394394
description = "Extra arguments to pass to qemu.";
395395
};
396396

397+
qemu.serialConsole = mkOption {
398+
type = types.bool;
399+
default = true;
400+
description = ''
401+
Whether to enable the virtual serial console on qemu.
402+
'';
403+
};
404+
397405
crosvm.extraArgs = mkOption {
398406
type = with types; listOf str;
399407
default = [];

0 commit comments

Comments
 (0)