11"""The U-Boot Module contains the UBootDriver"""
2+ import re
23import attr
34from pexpect import TIMEOUT
45
56from ..factory import target_factory
67from ..protocol import CommandProtocol , ConsoleProtocol , LinuxBootProtocol
7- from ..util import gen_marker , Timeout , re_vt100
8+ from ..util import gen_marker , re_vt100 , Timeout
89from ..step import step
910from .common import Driver
1011from .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