Skip to content

Commit de3d524

Browse files
committed
UBootDriver: add strip_timestamp option
Some U-Boot configurations may prepend timestamps to the beginning of every line during early boot, and at the prompt, e.g.: |[ 2.397] Failed to get fastboot key config: -19 |[ 2.402] sdh@d4280000: 74 clk wait timeout(100) |[ 2.405] MMC: no card present |[ 2.408] mmc_init: -123, time 7 |[ 2.412] Net: RGMII interface |[ 2.414] eth0: ethernet@cac80000 |[ 2.420] Autoboot in 5 seconds |=> |=> [ 4.878] <INTERRUPT> |=> [ 5.920] <INTERRUPT> |=> [ 503.743] d<INTERRUPT> |=> [ 505.712] <INTERRUPT> Unfortunately, this means that strategies may not behave as expected when trying to run commands, as labgrid's console.expect() function will always find the timestamp in addition to the check strings it sends. Handle this by adding a strip_timestamp boolean option to the UBootDriver, which if enabled strips timestamps from received lines when found. Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
1 parent 38d41d5 commit de3d524

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

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)