1111class 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