Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

U-Boot boot commands Support #1082

Merged
merged 2 commits into from Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/configuration.rst
Expand Up @@ -1507,6 +1507,9 @@ Implements:

UBootDriver:
prompt: 'Uboot> '
boot_commands:
net: run netboot
spi: run spiboot

Arguments:
- prompt (regex, default=""): U-Boot prompt to match
Expand All @@ -1518,6 +1521,7 @@ Arguments:
- password_prompt (str, default="enter Password: "): regex to match the U-Boot password prompt
- bootstring (str): optional, regex to match on Linux Kernel boot
- boot_command (str, default="run bootcmd"): boot command for booting target
- 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

Expand Down
8 changes: 6 additions & 2 deletions labgrid/driver/ubootdriver.py
Expand Up @@ -43,6 +43,7 @@ class UBootDriver(CommandMixin, Driver, CommandProtocol, LinuxBootProtocol):
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))
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))

Expand Down Expand Up @@ -207,12 +208,15 @@ def await_boot(self):

@Driver.check_active
@step(args=['name'])
def boot(self, name):
def boot(self, name: str = ""):
"""Boot the default or a specific boot entry

Args:
name (str): name of the entry to boot"""
if name:
self.console.sendline(f"boot -v {name}")
try:
self.console.sendline(self.boot_commands[name])
except KeyError as e:
raise Exception(f"{name} not found in boot_commands") from e
else:
self.console.sendline(self.boot_command)
15 changes: 13 additions & 2 deletions tests/test_ubootdriver.py
Expand Up @@ -18,7 +18,7 @@ def test_create(self):

def test_uboot_run(self, target_with_fakeconsole, mocker):
t = target_with_fakeconsole
d = UBootDriver(t, "barebox")
d = UBootDriver(t, "uboot")
d.console.rxq.append(b"U-Boot 2019\n")
d = t.get_driver(UBootDriver)
d._run = mocker.MagicMock(return_value=(['success'], [], 0))
Expand All @@ -32,7 +32,7 @@ def test_uboot_run(self, target_with_fakeconsole, mocker):

def test_uboot_run_error(self, target_with_fakeconsole, mocker):
t = target_with_fakeconsole
d = UBootDriver(t, "barebox")
d = UBootDriver(t, "uboot")
d.console.rxq.append(b"U-Boot 2019\n")
d = t.get_driver(UBootDriver)
d._run = mocker.MagicMock(return_value=(['error'], [], 1))
Expand All @@ -43,3 +43,14 @@ def test_uboot_run_error(self, target_with_fakeconsole, mocker):
res = d.run("test")
assert res == (['error'], [], 1)
d._run.assert_called_once_with("test", timeout=30)

def test_uboot_boot(self, target_with_fakeconsole):
t = target_with_fakeconsole
d = UBootDriver(t, "uboot", boot_command='run bootcmd', boot_commands = {"foo": "bar"})
d = t.get_driver(UBootDriver)
d.boot()
assert d.console.txq.pop() == b"run bootcmd\n"
d.boot('foo')
assert d.console.txq.pop() == b"bar\n"
with pytest.raises(Exception):
d.boot('nop')