Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Commit 5edf06a

Browse files
committed
Document uboot driver
1 parent eb9fcc1 commit 5edf06a

4 files changed

Lines changed: 75 additions & 0 deletions

File tree

docs/source/api-reference/drivers/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ sdwire.md
2020
shell.md
2121
snmp.md
2222
tftp.md
23+
uboot.md
2324
ustreamer.md
2425
yepkit.md
2526
```
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# U-Boot driver
2+
3+
The U-Boot driver is a driver for interacting with the U-Boot bootloader.
4+
This driver does not interact with the DUT directly, instead it should be
5+
configured with backing power and serial drivers.
6+
7+
## Driver configuration
8+
9+
```{literalinclude} uboot.yaml
10+
:language: yaml
11+
```
12+
13+
```{doctest}
14+
:hide:
15+
>>> from jumpstarter.config import ExporterConfigV1Alpha1DriverInstance
16+
>>> ExporterConfigV1Alpha1DriverInstance.from_path("source/api-reference/drivers/uboot.yaml").instantiate()
17+
UbootConsole(...)
18+
```
19+
20+
## Client API
21+
22+
```{eval-rst}
23+
.. autoclass:: jumpstarter_driver_uboot.client.UbootConsoleClient()
24+
:members:
25+
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
type: "jumpstarter_driver_uboot.driver.UbootConsole"
2+
children:
3+
power:
4+
type: "jumpstarter_driver_power.driver.MockPower"
5+
config: {} # omitted, power driver configuration
6+
serial:
7+
type: "jumpstarter_driver_pyserial.driver.PySerial"
8+
config: # omitted, serial driver configuration
9+
url: "loop://"
10+
# instead of configuring the power and serial driver inline
11+
# other drivers configured on the exporter can also be referenced
12+
# power:
13+
# ref: "dutlink.power"
14+
# serial:
15+
# ref: "dutlink.console"
16+
config:
17+
prompt: "=>" # the u-boot command prompt to expect, defaults to "=>"

packages/jumpstarter-driver-uboot/jumpstarter_driver_uboot/client.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
class UbootConsoleClient(CompositeClient):
1212
@cached_property
1313
def prompt(self) -> str:
14+
"""
15+
U-Boot prompt to expect
16+
"""
17+
1418
return self.call("get_prompt")
1519

1620
@contextmanager
@@ -19,6 +23,14 @@ def reboot_to_console(self, *, debug=False) -> None:
1923
Reboot to U-Boot console
2024
2125
Power cycle the target and wait for the U-Boot prompt
26+
27+
Must be used as a context manager, other methods can only be
28+
used within the reboot_to_console context
29+
30+
>>> with uboot.reboot_to_console(debug=True): # doctest: +SKIP
31+
... uboot.set_env("foo", "bar")
32+
... uboot.setup_dhcp()
33+
>>> # uboot.set_env("foo", "baz") # invalid use
2234
"""
2335

2436
self.logger.info("Power cycling target...")
@@ -48,6 +60,10 @@ def reboot_to_console(self, *, debug=False) -> None:
4860
delattr(self, "p")
4961

5062
def run_command(self, cmd: str, timeout: int = 60, *, _internal_log=True) -> bytes:
63+
"""
64+
Run raw command in the U-Boot console
65+
"""
66+
5167
if _internal_log:
5268
self.logger.info(f"Running command: {cmd}")
5369
if not hasattr(self, "p"):
@@ -59,6 +75,10 @@ def run_command(self, cmd: str, timeout: int = 60, *, _internal_log=True) -> byt
5975
return self.p.before
6076

6177
def run_command_checked(self, cmd: str, timeout: int = 60, check=True) -> list[str]:
78+
"""
79+
Run command in the U-Boot console and check the exit code
80+
"""
81+
6282
self.logger.info(f"Running command checked: {cmd}")
6383
output = self.run_command("{}; echo $?".format(cmd), _internal_log=False)
6484
parsed = output.strip().decode().splitlines()
@@ -77,6 +97,10 @@ def run_command_checked(self, cmd: str, timeout: int = 60, check=True) -> list[s
7797
return parsed[1:-1]
7898

7999
def setup_dhcp(self, timeout: int = 60) -> DhcpInfo:
100+
"""
101+
Setup dhcp in U-Boot
102+
"""
103+
80104
self.logger.info("Running DHCP to obtain network configuration...")
81105

82106
autoload = self.get_env("autoload", timeout=timeout)
@@ -120,6 +144,10 @@ def get_env(self, key: str, timeout: int = 5) -> str | None:
120144
raise TimeoutError(f"Timed out getting var {key}") from err
121145

122146
def set_env(self, key: str, value: str | None, timeout: int = 5) -> None:
147+
"""
148+
Set U-Boot environment variable value
149+
"""
150+
123151
if value is not None:
124152
cmd = "setenv {} '{}'".format(key, value)
125153
else:
@@ -131,5 +159,9 @@ def set_env(self, key: str, value: str | None, timeout: int = 5) -> None:
131159
raise TimeoutError(f"Timed out setting var {key}") from err
132160

133161
def set_env_dict(self, env: dict[str, str | None]) -> None:
162+
"""
163+
Set multiple U-Boot environment variable value
164+
"""
165+
134166
for key, value in env.items():
135167
self.set_env(key, value)

0 commit comments

Comments
 (0)