Class: Bootloader::SerialConsole
- Inherits:
-
Object
- Object
- Bootloader::SerialConsole
- Defined in:
- src/lib/bootloader/serial_console.rb
Overview
Represents parameters for console. Its main intention is easy parsing serial console parameters parameters for grub or kernel and generate it to keep it in sync.
Constant Summary collapse
- PARITY_MAP =
{ "n" => "no", "o" => "odd", "e" => "even" }.freeze
- SPEED_DEFAULT =
9600
- PARITY_DEFAULT =
"no"
- WORD_DEFAULT =
""
- KERNEL_PARAM_REGEXP =
REGEXP that separate usefull parts of kernel parameter for serial console matching groups are:
- serial console device
- console unit
- speed of serial console ( baud rate )
- parity of serial console ( just first letter )
- word length for serial console
For details see https://en.wikipedia.org/wiki/Serial_port
/(ttyS|ttyAMA)([[:digit:]]*),?([[:digit:]]*)([noe]*)([[:digit:]]*)/.freeze
Class Method Summary collapse
-
.load_from_console_args(console_args) ⇒ Bootloader::SerialConsole?
Loads serial console configuration from parameters passed to grub.
-
.load_from_kernel_args(kernel_params) ⇒ Bootloader::SerialConsole?
Loads serial console configuration from parameters passed to kernel.
Instance Method Summary collapse
-
#console_args ⇒ Object
generates serial command for grub2 GRUB_SERIAL_COMMAND.
-
#initialize(unit, speed = SPEED_DEFAULT, parity = PARITY_DEFAULT, word = WORD_DEFAULT) ⇒ SerialConsole
constructor
constuctor.
-
#kernel_args ⇒ Object
generates kernel argument usable for passing it with
console=<result>
. -
#xen_hypervisor_args ⇒ Object
generates serial console parameters for grub2 GRUB_CMDLINE_XEN_DEFAULT.
-
#xen_kernel_args ⇒ Object
generates serial console parameters for grub2 GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT.
Constructor Details
#initialize(unit, speed = SPEED_DEFAULT, parity = PARITY_DEFAULT, word = WORD_DEFAULT) ⇒ SerialConsole
constuctor
87 88 89 90 91 92 93 |
# File 'src/lib/bootloader/serial_console.rb', line 87 def initialize(unit, speed = SPEED_DEFAULT, parity = PARITY_DEFAULT, word = WORD_DEFAULT) @unit = unit @speed = speed @parity = parity @word = word end |
Class Method Details
.load_from_console_args(console_args) ⇒ Bootloader::SerialConsole?
Loads serial console configuration from parameters passed to grub
70 71 72 73 74 75 76 77 78 79 |
# File 'src/lib/bootloader/serial_console.rb', line 70 def self.load_from_console_args(console_args) unit = console_args[/--unit=(\S+)/, 1] return nil unless unit speed = console_args[/--speed=(\S+)/, 1] || SPEED_DEFAULT parity = console_args[/--parity=(\S+)/, 1] || PARITY_DEFAULT word = console_args[/--word=(\S+)/, 1] || WORD_DEFAULT new(unit, speed, parity, word) end |
.load_from_kernel_args(kernel_params) ⇒ Bootloader::SerialConsole?
Loads serial console configuration from parameters passed to kernel
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'src/lib/bootloader/serial_console.rb', line 41 def self.load_from_kernel_args(kernel_params) console_parameters = kernel_params.parameter("console") return nil unless console_parameters console_parameters = Array(console_parameters) # use only the last parameter (bnc#870514) serial_console = console_parameters.last return nil if serial_console !~ /ttyS/ && serial_console !~ /ttyAMA/ unit = serial_console[KERNEL_PARAM_REGEXP, 2] return nil if unit.empty? speed = serial_console[KERNEL_PARAM_REGEXP, 3] speed = SPEED_DEFAULT if speed.empty? parity = serial_console[KERNEL_PARAM_REGEXP, 4] parity = PARITY_DEFAULT[0] if parity.empty? parity = PARITY_MAP[parity] word = serial_console[KERNEL_PARAM_REGEXP, 5] new(unit, speed, parity, word) end |
Instance Method Details
#console_args ⇒ Object
generates serial command for grub2 GRUB_SERIAL_COMMAND
103 104 105 106 107 108 |
# File 'src/lib/bootloader/serial_console.rb', line 103 def console_args res = "serial --unit=#{@unit} --speed=#{@speed} --parity=#{@parity}" res += " --word=#{@word}" unless @word.empty? res end |
#kernel_args ⇒ Object
generates kernel argument usable for passing it with console=<result>
96 97 98 99 100 |
# File 'src/lib/bootloader/serial_console.rb', line 96 def kernel_args serial_console = Yast::Arch.aarch64 ? "ttyAMA" : "ttyS" "#{serial_console}#{@unit},#{@speed}#{@parity[0]}#{@word}" end |
#xen_hypervisor_args ⇒ Object
generates serial console parameters for grub2 GRUB_CMDLINE_XEN_DEFAULT
119 120 121 122 123 |
# File 'src/lib/bootloader/serial_console.rb', line 119 def xen_hypervisor_args # Notice that this is always com1, even if the host uses another serial tty. # See also https://wiki.xenproject.org/wiki/Xen_Serial_Console "console=com1 com1=#{@speed}" end |
#xen_kernel_args ⇒ Object
generates serial console parameters for grub2 GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT
112 113 114 115 |
# File 'src/lib/bootloader/serial_console.rb', line 112 def xen_kernel_args # This is always hvc0 (for HyperVisor Console). "console=hvc0" end |