From e6c58969d6a19448f4fbedf2cd41529a2c4b4d97 Mon Sep 17 00:00:00 2001 From: Trevor Gamblin Date: Tue, 3 Feb 2026 13:56:03 -0500 Subject: [PATCH 1/2] UBootDriver: add strip_timestamps 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] |=> [ 5.920] |=> [ 503.743] d |=> [ 505.712] 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_timestamps boolean option to the UBootDriver, which if enabled strips timestamps from received lines when found. Signed-off-by: Trevor Gamblin --- labgrid/driver/ubootdriver.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/labgrid/driver/ubootdriver.py b/labgrid/driver/ubootdriver.py index cc1cd0d4b..e558d81da 100644 --- a/labgrid/driver/ubootdriver.py +++ b/labgrid/driver/ubootdriver.py @@ -1,14 +1,16 @@ """The U-Boot Module contains the UBootDriver""" import attr +import re from pexpect import TIMEOUT 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_vt100, Timeout from ..step import step from .common import Driver from .commandmixin import CommandMixin +re_uboot_timestamp = re.compile(r"^\[\s+\d+\.\d+\]\s*") @target_factory.reg_driver @attr.s(eq=False) @@ -28,6 +30,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, } @@ -43,6 +46,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__() @@ -79,6 +83,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:] From 05c35cfa71c85d4696ca6d8329e854fb4c79f6cb Mon Sep 17 00:00:00 2001 From: Trevor Gamblin Date: Tue, 3 Feb 2026 15:17:12 -0500 Subject: [PATCH 2/2] doc/configuration: add strip_timestamp to UBootDriver Signed-off-by: Trevor Gamblin --- doc/configuration.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/configuration.rst b/doc/configuration.rst index 9303d1eed..50df7588a 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -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 ~~~~~~~~~~~~~~~~