diff options
| author | Christian Breunig <christian@breunig.cc> | 2026-11-03 19:15:04 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-11-03 19:15:04 +0100 |
| commit | 6ea85bda82cc50809d73c6b422308dd4bc52fb6b (patch) | |
| tree | 8dd659021297bb7e23ca19ee19f28113966cf755 /python | |
| parent | a100a7f62325beac2c9c3a75778bca09da3e9d08 (diff) | |
| parent | 44d929a1b973d3f4131d25d7f9cd7b69c3cf3514 (diff) | |
| download | vyos-1x-6ea85bda82cc50809d73c6b422308dd4bc52fb6b.tar.gz vyos-1x-6ea85bda82cc50809d73c6b422308dd4bc52fb6b.zip | |
Merge pull request #5627 from c-po/T9567-serial-console-compat-migration
serial: T9567: honor booted serial console during 31 -> 32 migration
Diffstat (limited to 'python')
| -rw-r--r-- | python/vyos/utils/kernel.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/python/vyos/utils/kernel.py b/python/vyos/utils/kernel.py index 69574cefc..283dd8a9c 100644 --- a/python/vyos/utils/kernel.py +++ b/python/vyos/utils/kernel.py @@ -182,6 +182,40 @@ def get_kernel_serial_console() -> Tuple[Optional[str], Optional[str], Optional[ return (None, None, None) +def get_kernel_primary_console(cmdline: str | None = None) -> Tuple[Optional[str], Optional[str], Optional[str]]: + """ + Extract type, number and speed of the console the kernel uses as + /dev/console. With multiple console= arguments this is the last one, e.g. + "console=tty0 console=ttyS0,115200" boots on ttyS0 while + "console=ttyS0,115200 console=tty0" boots on tty0. + + Args: + cmdline: kernel command line to parse, defaults to /proc/cmdline + + Returns: + tuple: (console_type, console_num, console_speed), speed is None if + not specified. (None, None, None) if no console= is present. + """ + import re + + if cmdline is None: + cmdline = read_file(CMDLINE_PATH) + + # speed may carry parity/bits/flow suffixes, e.g. 115200n8 + console_re = re.compile( + r'console=(?P<console_type>[a-zA-Z]+)(?P<console_num>\d+)(?:,(?P<console_speed>\d+)\S*)?' + ) + for part in reversed(cmdline.split()): + if m := console_re.fullmatch(part): + return ( + m.group('console_type'), + m.group('console_num'), + m.group('console_speed'), + ) + + return (None, None, None) + + def get_kernel_boot_arg(argument=None) -> str | None: """Read and parse kernel boot arguments from the kernel command line. |
