Skip to content

Commit

Permalink
machine: u-boot: Add a hacky workaround for the crc32 command
Browse files Browse the repository at this point in the history
The `crc32` command in U-Boot unfortunately prints the character
sequence `=> ` as part of its output.  This character sequence is an
often used U-Boot prompt, which means tbot's prompt-searching code gets
confused by `crc32` output.

Unfortunately, there is no real solution to this.  At least none that
works universally.  So to at least ease the pain a bit for people
running into this, attempt automatically applying a workaround for this
specific situation.

Signed-off-by: Rahix <[email protected]>
  • Loading branch information
Rahix committed Nov 1, 2024
1 parent dbf1486 commit edb2d5b
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions tbot/machine/board/uboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,29 @@ def exec(self, *args: ArgTypes) -> typing.Tuple[int, str]:
"""
cmd = self.escape(*args)

# There is an ugly ugly problem with no great solution: The `crc32`
# command in U-Boot prints the string `=> ` as part of its output.
# This is a commonly used prompt string which means that tbot gets
# completely thrown off by this situation. As a stopgap solution,
# let's special case this here to make people's lives a bit easier...
if args[0] == "crc32" and self.ch.prompt in ("=> ", b"=> "):
tbot.log.warning(
"Applying workaround for `crc32` command in U-Boot!\n"
+ " See https://github.com/rahix/tbot/issues/111 for details."
)
override_prompt = "\n=> "
else:
override_prompt = None

with tbot.log_event.command(self.name, cmd) as ev:
self.ch.sendline(cmd, read_back=True)
with self.ch.with_stream(ev, show_prompt=False):
out = self.ch.read_until_prompt()
with self.ch.with_prompt(override_prompt):
with self.ch.with_stream(ev, show_prompt=False):
out = self.ch.read_until_prompt(prompt=override_prompt)
if override_prompt == "\n=> ":
# The overridden prompt ate the trailing '\n'
ev.write("\n")
out += "\n"
ev.data["stdout"] = out

self.ch.sendline("echo $?", read_back=True)
Expand Down

0 comments on commit edb2d5b

Please sign in to comment.