Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1925,6 +1925,7 @@ Arguments:
- boot_commands (dict, default={}): boot commands by name for LinuxBootProtocol boot command
- login_timeout (int, default=30): timeout for login prompt detection in seconds
- boot_timeout (int, default=30): timeout for initial Linux Kernel version detection
- strip_timestamp (bool, default=False): strip timestamps prepended to console when present

SmallUBootDriver
~~~~~~~~~~~~~~~~
Expand Down
9 changes: 8 additions & 1 deletion labgrid/driver/ubootdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from ..factory import target_factory
from ..protocol import CommandProtocol, ConsoleProtocol, LinuxBootProtocol
from ..util import gen_marker, Timeout, re_vt100
from ..util import gen_marker, re_uboot_timestamp, re_vt100, Timeout
from ..step import step
from .common import Driver
from .commandmixin import CommandMixin
Expand All @@ -28,6 +28,7 @@ class UBootDriver(CommandMixin, Driver, CommandProtocol, LinuxBootProtocol):
boot_command (str): optional boot command to boot target
login_timeout (int): optional, timeout for login prompt detection
boot_timeout (int): optional, timeout for initial Linux Kernel version detection
strip_timestamp (bool, default=False): strip timestamps prepended to console when present

"""
bindings = {"console": ConsoleProtocol, }
Expand All @@ -43,6 +44,7 @@ class UBootDriver(CommandMixin, Driver, CommandProtocol, LinuxBootProtocol):
boot_commands = attr.ib(default=attr.Factory(dict), validator=attr.validators.instance_of(dict))
login_timeout = attr.ib(default=30, validator=attr.validators.instance_of(int))
boot_timeout = attr.ib(default=30, validator=attr.validators.instance_of(int))
strip_timestamp = attr.ib(default=False, validator=attr.validators.instance_of(bool))

def __attrs_post_init__(self):
super().__attrs_post_init__()
Expand Down Expand Up @@ -79,6 +81,11 @@ def _run(self, cmd: str, *, timeout: int = 30, codec: str = "utf-8", decodeerror
data = re_vt100.sub(
'', before.decode('utf-8'), count=1000000
).replace("\r", "").split("\n")

# Strip possible U-Boot timestamps from the line
if self.strip_timestamp:
data = [re_uboot_timestamp.sub('', line) for line in data]

self.logger.debug("Received Data: %s", data)
# Remove first element, the invoked cmd
data = data[data.index(marker) + 1:]
Expand Down
2 changes: 1 addition & 1 deletion labgrid/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
from .marker import gen_marker
from .yaml import load, dump
from .ssh import sshmanager
from .helper import get_free_port, get_user, re_vt100
from .helper import get_free_port, get_user, re_uboot_timestamp, re_vt100
from .version import labgrid_version
1 change: 1 addition & 0 deletions labgrid/util/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from ..step import step

re_vt100 = re.compile(r"(\x1b\[|\x9b)[^@-_a-z]*[@-_a-z]|\x1b[@-_a-z]")
re_uboot_timestamp = re.compile(r"^\[\s+\d+\.\d+\]\s*")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is specific to U-Boot, just place it in ubootdriver at the top level.


def get_free_port():
"""Helper function to always return an unused port."""
Expand Down
Loading