blob: aace2863c145227c2a2f9f96cb0a2619819c15a2 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# ex:ts=4:sw=4:sts=4:et
2# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
3#
4# This program is free software; you can redistribute it and/or modify it
5# under the terms of the GNU General Public License as published by the Free
6# Software Foundation; version 2 of the License
7#
8# This program is distributed in the hope that it will be useful, but
9# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11# for more details.
12#
13# You should have received a copy of the GNU General Public License along
14# with this program; if not, write to the Free Software Foundation, Inc., 59
15# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16#
17# AUTHOR
18# Adrian Freihofer <adrian.freihofer (at] neratec.com>
19
20
21import re
22from wic import msger
23
24
25def serial_console_form_kargs(kernel_args):
26 """
27 Create SERIAL... line from kernel parameters
28
29 syslinux needs a line SERIAL port [baudrate [flowcontrol]]
30 in the syslinux.cfg file. The config line is generated based
31 on kernel boot parameters. The the parameters of the first
32 ttyS console are considered for syslinux config.
33 @param kernel_args kernel command line
34 @return line for syslinux config file e.g. "SERIAL 0 115200"
35 """
36 syslinux_conf = ""
37 for param in kernel_args.split():
38 param_match = re.match("console=ttyS([0-9]+),?([0-9]*)([noe]?)([0-9]?)(r?)", param)
39 if param_match:
40 syslinux_conf += "SERIAL " + param_match.group(1)
41 # baudrate
42 if param_match.group(2):
43 syslinux_conf += " " + param_match.group(2)
44 # parity
45 if param_match.group(3) and param_match.group(3) != 'n':
46 msger.warning("syslinux does not support parity for console. {} is ignored."
47 .format(param_match.group(3)))
48 # number of bits
49 if param_match.group(4) and param_match.group(4) != '8':
50 msger.warning("syslinux supports 8 bit console configuration only. {} is ignored."
51 .format(param_match.group(4)))
52 # flow control
53 if param_match.group(5) and param_match.group(5) != '':
54 msger.warning("syslinux console flowcontrol configuration. {} is ignored."
55 .format(param_match.group(5)))
56 break
57
58 return syslinux_conf