Skip to content

Commit

Permalink
driver/ubootdriver: deprecate boot_expression attribute
Browse files Browse the repository at this point in the history
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] 016f605 ("bareboxdriver: refactor login expect loop and add password support")

Signed-off-by: Bastian Krause <bst@pengutronix.de>
  • Loading branch information
Bastian-Krause committed Aug 8, 2022
1 parent d0fc794 commit 7b55a19
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`_
Expand Down
1 change: 1 addition & 0 deletions labgrid/driver/smallubootdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
9 changes: 6 additions & 3 deletions labgrid/driver/ubootdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 7b55a19

Please sign in to comment.