Skip to content

Commit 5bac4c5

Browse files
committed
qemu: armv7l, aarch64: add pci-serial
On armv7l, dmesg is not shown in the default serial (ttyAMA0). On aarch64, dmesg is still shown but cloud-init logs are not shown. Add `pci-serial` device to enable ttyS0. The default ttyAMA0 is still kept to show UEFI logs. Signed-off-by: Akihiro Suda <[email protected]>
1 parent f134a34 commit 5bac4c5

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

docs/internal.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ VZ:
5151
- `vz-efi`: EFIVariable store file for a VM
5252

5353
Serial:
54-
- `serial.log`: legacy serial log (QEMU only), for debugging
55-
- `serial.sock`: legacy serial socket (QEMU only), for debugging (Usage: `socat -,echo=0,icanon=0 unix-connect:serial.sock`)
54+
- `serial.log`: default serial log (QEMU only), for debugging
55+
- `serial.sock`: default serial socket (QEMU only), for debugging (Usage: `socat -,echo=0,icanon=0 unix-connect:serial.sock`)
56+
- `serialp.log`: PCI serial log (QEMU (ARM) only), for debugging
57+
- `serialp.sock`: PCI serial socket (QEMU (ARM) only), for debugging (Usage: `socat -,echo=0,icanon=0 unix-connect:serialp.sock`)
5658
- `serialv.log`: virtio serial log, for debugging
5759
- `serialv.sock`: virtio serial socket (QEMU only), for debugging (Usage: `socat -,echo=0,icanon=0 unix-connect:serialv.sock`)
5860

pkg/qemu/qemu.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,8 @@ func Cmdline(cfg Config) (string, []string, error) {
800800
// Parallel
801801
args = append(args, "-parallel", "none")
802802

803-
// Serial (legacy)
803+
// Serial (default)
804+
// This is ttyS0 for Intel and RISC-V, ttyAMA0 for ARM.
804805
serialSock := filepath.Join(cfg.InstanceDir, filenames.SerialSock)
805806
if err := os.RemoveAll(serialSock); err != nil {
806807
return "", nil, err
@@ -813,6 +814,24 @@ func Cmdline(cfg Config) (string, []string, error) {
813814
args = append(args, "-chardev", fmt.Sprintf("socket,id=%s,path=%s,server=on,wait=off,logfile=%s", serialChardev, serialSock, serialLog))
814815
args = append(args, "-serial", "chardev:"+serialChardev)
815816

817+
// Serial (PCI, ARM only)
818+
// On ARM, the default serial is ttyAMA0, this PCI serial is ttyS0.
819+
// https://gitlab.com/qemu-project/qemu/-/issues/1801#note_1494720586
820+
switch *y.Arch {
821+
case limayaml.AARCH64, limayaml.ARMV7L:
822+
serialpSock := filepath.Join(cfg.InstanceDir, filenames.SerialPCISock)
823+
if err := os.RemoveAll(serialpSock); err != nil {
824+
return "", nil, err
825+
}
826+
serialpLog := filepath.Join(cfg.InstanceDir, filenames.SerialPCILog)
827+
if err := os.RemoveAll(serialpLog); err != nil {
828+
return "", nil, err
829+
}
830+
const serialpChardev = "char-serial-pci"
831+
args = append(args, "-chardev", fmt.Sprintf("socket,id=%s,path=%s,server=on,wait=off,logfile=%s", serialpChardev, serialpSock, serialpLog))
832+
args = append(args, "-device", "pci-serial,chardev="+serialpChardev)
833+
}
834+
816835
// Serial (virtio)
817836
serialvSock := filepath.Join(cfg.InstanceDir, filenames.SerialVirtioSock)
818837
if err := os.RemoveAll(serialvSock); err != nil {

pkg/store/filenames/filenames.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ const (
3434
KernelCmdline = "kernel.cmdline"
3535
Initrd = "initrd"
3636
QMPSock = "qmp.sock"
37-
SerialLog = "serial.log" // legacy
37+
SerialLog = "serial.log" // default serial (ttyS0, but ttyAMA0 on qemu-system-{arm,aarch64})
3838
SerialSock = "serial.sock"
39+
SerialPCILog = "serialp.log" // pci serial (ttyS0 on qemu-system-{arm,aarch64})
40+
SerialPCISock = "serialp.sock"
3941
SerialVirtioLog = "serialv.log" // virtio serial
4042
SerialVirtioSock = "serialv.sock"
4143
SSHSock = "ssh.sock"

0 commit comments

Comments
 (0)