Skip to content

Commit 228e2e0

Browse files
authored
Merge pull request labgrid-project#1816 from threexc/tgamblin/strip-uboot-timestamps
ubootdriver: optionally strip timestamps
2 parents 38d41d5 + cde25ad commit 228e2e0

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

doc/configuration.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,6 +1925,7 @@ Arguments:
19251925
- boot_commands (dict, default={}): boot commands by name for LinuxBootProtocol boot command
19261926
- login_timeout (int, default=30): timeout for login prompt detection in seconds
19271927
- boot_timeout (int, default=30): timeout for initial Linux Kernel version detection
1928+
- strip_timestamp (bool, default=False): strip timestamps prepended to console when present
19281929

19291930
SmallUBootDriver
19301931
~~~~~~~~~~~~~~~~

labgrid/driver/ubootdriver.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
"""The U-Boot Module contains the UBootDriver"""
2+
import re
23
import attr
34
from pexpect import TIMEOUT
45

56
from ..factory import target_factory
67
from ..protocol import CommandProtocol, ConsoleProtocol, LinuxBootProtocol
7-
from ..util import gen_marker, Timeout, re_vt100
8+
from ..util import gen_marker, re_vt100, Timeout
89
from ..step import step
910
from .common import Driver
1011
from .commandmixin import CommandMixin
1112

13+
re_uboot_timestamp = re.compile(r"^\[\s+\d+\.\d+\]\s*")
1214

1315
@target_factory.reg_driver
1416
@attr.s(eq=False)
@@ -28,6 +30,7 @@ class UBootDriver(CommandMixin, Driver, CommandProtocol, LinuxBootProtocol):
2830
boot_command (str): optional boot command to boot target
2931
login_timeout (int): optional, timeout for login prompt detection
3032
boot_timeout (int): optional, timeout for initial Linux Kernel version detection
33+
strip_timestamp (bool, default=False): strip timestamps prepended to console when present
3134
3235
"""
3336
bindings = {"console": ConsoleProtocol, }
@@ -43,6 +46,7 @@ class UBootDriver(CommandMixin, Driver, CommandProtocol, LinuxBootProtocol):
4346
boot_commands = attr.ib(default=attr.Factory(dict), validator=attr.validators.instance_of(dict))
4447
login_timeout = attr.ib(default=30, validator=attr.validators.instance_of(int))
4548
boot_timeout = attr.ib(default=30, validator=attr.validators.instance_of(int))
49+
strip_timestamp = attr.ib(default=False, validator=attr.validators.instance_of(bool))
4650

4751
def __attrs_post_init__(self):
4852
super().__attrs_post_init__()
@@ -79,6 +83,11 @@ def _run(self, cmd: str, *, timeout: int = 30, codec: str = "utf-8", decodeerror
7983
data = re_vt100.sub(
8084
'', before.decode('utf-8'), count=1000000
8185
).replace("\r", "").split("\n")
86+
87+
# Strip possible U-Boot timestamps from the line
88+
if self.strip_timestamp:
89+
data = [re_uboot_timestamp.sub('', line) for line in data]
90+
8291
self.logger.debug("Received Data: %s", data)
8392
# Remove first element, the invoked cmd
8493
data = data[data.index(marker) + 1:]

0 commit comments

Comments
 (0)