Skip to content

Commit a3ae148

Browse files
committed
ports/litex: run_hw.py — drive serialboot from BIOS console, no race window.
Old flow tried to ack the BIOS's serialboot magic during the 5-s auto-boot window. Two failure modes in the wild: - The magic was matched as `b\"sL5DdSMmkekro\\n\"` but the BIOS uses CRLF, so on most consoles (with CRLF line endings) the match never fired and we hung until the 30-s timeout. - Even when the match worked it required openFPGALoader + Python startup + scheduler latency to all fit inside 5 s. Slow filesystem / first-boot caches blew the budget. New flow (per the user's suggestion): 1. Load the bitstream. 2. Wait up to 60 s for the BIOS to exhaust serialboot → networkboot → flashboot → sdcardboot and drop into its `litex>` console (matched on the bare \"litex\" substring, since the prompt is wrapped in ANSI colour codes). 3. Send `serialboot\\n` ourselves. The BIOS re-enters serialboot and prints the magic — no time pressure. 4. Match the magic on the bare \"sL5DdSMmkekro\" substring (works regardless of \\n vs \\r\\n trailing bytes). 5. ACK + SFL upload as before. Verified on real Arty: load bitstream → BIOS auto-boot fails over ~5 s → console prompt appears → we send serialboot → magic → upload → MicroPython REPL → test_hw_arty.py prints all five sections + DHCP + DNS + HTTP GET OK → [run_hw] OK: 1/1.
1 parent 2dcb5dc commit a3ae148

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

‎ports/litex/tools/run_hw.py‎

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@
3030

3131
PORT_DIR = Path(__file__).resolve().parent.parent
3232

33-
# LiteX BIOS serialboot magic string and our reply (note trailing
34-
# newlines — both directions). Matches litex/tools/litex_term.py.
35-
SFL_MAGIC_REQ = b"sL5DdSMmkekro\n"
33+
# SFL ACK we send back when we see the BIOS's "sL5DdSMmkekro" magic.
34+
# (litex/tools/litex_term.py uses the matching pair.)
3635
SFL_MAGIC_ACK = b"z6IHG7cYDID6o\n"
3736
# SFL (Serial File Loader) command codes.
3837
SFL_FRAME_LOAD = 0x01
@@ -227,10 +226,24 @@ def main():
227226
sys.exit(f"openFPGALoader failed (exit {rc})")
228227

229228
if args.firmware:
230-
print(f"[run_hw] waiting for BIOS serialboot prompt", file=sys.stderr)
231-
if read_until(s, SFL_MAGIC_REQ, timeout=30, log=log) is None:
232-
sys.exit("[run_hw] BIOS serialboot magic not seen — did the bitstream load?")
233-
# Acknowledge and start uploading.
229+
# Don't race the BIOS's 5-second auto-serialboot window. Wait
230+
# for it to fall through every boot method and land in its
231+
# interactive `litex>` console — at that point we can issue
232+
# `serialboot` ourselves whenever we're ready, with no race
233+
# and no \r\n vs \n parsing fragility.
234+
print("[run_hw] waiting for BIOS console prompt", file=sys.stderr)
235+
# The console prompt is ANSI-coloured (`\x1b[92;1mlitex\x1b[0m>`),
236+
# so match the bare "litex" substring instead of "litex>".
237+
if read_until(s, b"litex", timeout=60, log=log) is None:
238+
sys.exit("[run_hw] BIOS console prompt not seen — bitstream loaded?")
239+
# Tiny pause so the prompt's `>` byte arrives before we type.
240+
time.sleep(0.2)
241+
print("[run_hw] sending `serialboot`", file=sys.stderr)
242+
s.write(b"serialboot\n")
243+
# BIOS replies with the SFL magic; match on a substring that's
244+
# present whether the BIOS uses \n or \r\n.
245+
if read_until(s, b"sL5DdSMmkekro", timeout=15, log=log) is None:
246+
sys.exit("[run_hw] BIOS did not enter serialboot")
234247
s.write(SFL_MAGIC_ACK)
235248
firmware_bytes = open(args.firmware, "rb").read()
236249
if not upload_firmware(s, firmware_bytes, args.kernel_adr, log):

0 commit comments

Comments
 (0)