From 7b55a19c6316a2b6e5fb41c1aab8e5bf007e55e9 Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Mon, 8 Aug 2022 14:34:04 +0200 Subject: [PATCH] driver/ubootdriver: deprecate boot_expression attribute Checking the U-Boot output for a expression is problematic for cases where the driver is activated while U-Boot's auto boot is already interrupted. This is the case if a strategy wants to force() a U-Boot state. A similar check happened to be in the BareboxDriver, but it was dropped in a refactoring [1]. As a first step in harmonizing BareboxDriver and UBootDriver, deprecate the boot_expression attribute and do not check for it in _await_prompt() anymore. [1] 016f605c ("bareboxdriver: refactor login expect loop and add password support") Signed-off-by: Bastian Krause --- CHANGES.rst | 3 +++ doc/configuration.rst | 2 +- labgrid/driver/smallubootdriver.py | 1 + labgrid/driver/ubootdriver.py | 9 ++++++--- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index c23b5a79f..5269818f9 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -45,6 +45,9 @@ Breaking changes in 0.5.0 ~~~~~~~~~~~~~~~~~~~~~~~~~ - ``Config``'s ``get_option()``/``get_target_option()`` convert non-string options no longer to strings. +- `UBootDriver`'s ``boot_expression`` attribute is deprecated, it will no + longer check for the string during U-Boot boot. This allows activating the + driver on an already running U-Boot. Known issues in 0.5.0 ~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/doc/configuration.rst b/doc/configuration.rst index 3e652c6cf..2d0298f66 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -1447,7 +1447,6 @@ Arguments: - init_commands (tuple): optional, tuple of commands to execute after matching the prompt - password_prompt (str, default="enter Password: "): regex to match the U-Boot password prompt - - boot_expression (str, default="U-Boot 20\\d+"): regex to match the U-Boot start string - bootstring (str): optional, regex to match on Linux Kernel boot - boot_command (str, default="run bootcmd"): boot command for booting target - login_timeout (int, default=30): timeout for login prompt detection in seconds @@ -1498,6 +1497,7 @@ Implements: boot_secret: "tpl" Arguments: + - boot_expression (str, default="U-Boot 20\\d+"): regex to match the U-Boot start string - boot_secret (str, default="a"): secret used to unlock prompt - login_timeout (int, default=60): timeout for password/login prompt detection - for other arguments, see `UBootDriver`_ diff --git a/labgrid/driver/smallubootdriver.py b/labgrid/driver/smallubootdriver.py index 57e26e6c3..541915436 100644 --- a/labgrid/driver/smallubootdriver.py +++ b/labgrid/driver/smallubootdriver.py @@ -46,6 +46,7 @@ class SmallUBootDriver(UBootDriver): login_timeout (int): optional, timeout for login prompt detection, """ + boot_expression = attr.ib(default=r"U-Boot 20\d+", validator=attr.validators.instance_of(str)) boot_secret = attr.ib(default="a", validator=attr.validators.instance_of(str)) boot_secret_nolf = attr.ib(default=False, validator=attr.validators.instance_of(bool)) login_timeout = attr.ib(default=60, validator=attr.validators.instance_of(int)) diff --git a/labgrid/driver/ubootdriver.py b/labgrid/driver/ubootdriver.py index 68e92b9e1..af94e08b3 100644 --- a/labgrid/driver/ubootdriver.py +++ b/labgrid/driver/ubootdriver.py @@ -27,7 +27,7 @@ class UBootDriver(CommandMixin, Driver, CommandProtocol, LinuxBootProtocol): autoboot (str): optional, string to search for to interrupt autoboot interrupt (str): optional, character to interrupt autoboot and go to prompt password_prompt (str): optional, string to detect the password prompt - boot_expression (str): optional, string to search for on U-Boot start + boot_expression (str): optional, deprecated bootstring (str): optional, string that indicates that the Kernel is booting boot_command (str): optional boot command to boot target login_timeout (int): optional, timeout for login prompt detection @@ -41,7 +41,7 @@ class UBootDriver(CommandMixin, Driver, CommandProtocol, LinuxBootProtocol): interrupt = attr.ib(default="\n", validator=attr.validators.instance_of(str)) init_commands = attr.ib(default=attr.Factory(tuple), converter=tuple) password_prompt = attr.ib(default="enter Password:", validator=attr.validators.instance_of(str)) - boot_expression = attr.ib(default=r"U-Boot 20\d+", validator=attr.validators.instance_of(str)) + boot_expression = attr.ib(default="", validator=attr.validators.instance_of(str)) bootstring = attr.ib(default=r"Linux version \d", validator=attr.validators.instance_of(str)) boot_command = attr.ib(default="run bootcmd", validator=attr.validators.instance_of(str)) login_timeout = attr.ib(default=30, validator=attr.validators.instance_of(int)) @@ -55,6 +55,10 @@ def __attrs_post_init__(self): self.logger = logging.getLogger(f"{self}:{self.target}") self._status = 0 + if self.boot_expression: + import warnings + warnings.warn("boot_expression is deprecated and will be ignored", DeprecationWarning) + def on_activate(self): """Activate the UBootDriver @@ -146,7 +150,6 @@ def _await_prompt(self): """Await autoboot line and stop it to get to the prompt, optionally enter the password. """ - self.console.expect(self.boot_expression, timeout=self.login_timeout) while True: index, _, _, _ = self.console.expect( [self.prompt, self.autoboot, self.password_prompt]