The pin crosses libavr's phase 6 - the renamed system surface, the named serial configs, the receiver-tolerance table, the paged SPM receipts - and every loader image comes out size-identical: the full matrix on six representative chips (the exhaustive cross product on three of them), the stock and autobaud columns untouched, the four tsb tiers back on their recorded floors at 510/526/638/836. Byte parity was not free, and the two libavr defects it surfaced were fixed there rather than absorbed here. The EEPROM write procedure's step 2 - the SPMEN spin - had landed unconditionally and cost every build six bytes for a wait a polled loader can never take; it is scoped now, and the loaders state the datasheet's own omission clause (spm_interlock::omitted, DS40002061B 8.6.3). The blocking page erase/write grew an internal wait the tiers' settle() already provides, so the tiers issue the command form and pureboot keeps its host-driven sp_spm path. What the port states rather than inherits: the stock 115200 at 16 MHz sits +2.1 % past the receiver-tolerance table libavr now holds rates to, so the hardware links say .allow_baud_error = true - the same 2.5 % envelope pureboot_baud_feasible() has always enforced, proven on silicon across the fleet. rx_ready() reads readable() now. Alongside the pin: rule 33's ASCII sweep over every source (docs keep their typography), rule 34's InsertBraces in .clang-format with the tree reformatted, std::array over the simavr runners' raw buffers, and the stale Studio size in ide/README.md replaced by the claim its check-flags gate actually holds. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
72 lines
2.6 KiB
Python
72 lines
2.6 KiB
Python
"""Shared simavr harness for the pureboot tests: spawn the device runner,
|
|
hand out its pty, restart it from a flash dump (the power-fail path), and
|
|
keep its chatter out of undrained pipes."""
|
|
|
|
import os
|
|
import signal
|
|
import subprocess
|
|
|
|
|
|
class Device:
|
|
def __init__(self, binary, elf, mcu, hz, base_hex, page, baud, dump, reset_hex=None, resume=None, link=None,
|
|
window=False):
|
|
cmd = [binary]
|
|
if link:
|
|
cmd += ["-l", link]
|
|
if window:
|
|
cmd.append("-w") # report the first-transmit cycle, free-run idle
|
|
cmd += [elf, mcu, hz, base_hex, str(page), str(baud), dump]
|
|
if reset_hex is not None or resume is not None:
|
|
# Chips without a hardware boot section - the tinies and the
|
|
# m48s - reset to address 0 like silicon; the boot-sectioned
|
|
# megas re-vector to the loader base (BOOTRST).
|
|
patch = not mcu.startswith("atmega") or mcu.startswith("atmega48")
|
|
cmd.append(reset_hex if reset_hex is not None else ("0" if patch else base_hex))
|
|
if resume is not None:
|
|
cmd.append(resume)
|
|
self.log = open(dump + ".log", "a")
|
|
self.proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=self.log, text=True)
|
|
self.dump = dump
|
|
self.pty = None
|
|
for _ in range(50):
|
|
line = self.proc.stdout.readline()
|
|
if not line:
|
|
break
|
|
if line.startswith("PB_PTY"):
|
|
self.pty = line.split()[1]
|
|
break
|
|
if not self.pty:
|
|
self.stop()
|
|
raise RuntimeError("device did not report a pty")
|
|
|
|
def reset(self):
|
|
"""The external reset line: SIGUSR1 re-enters at the reset vector."""
|
|
self.proc.send_signal(signal.SIGUSR1)
|
|
|
|
def power_fail(self):
|
|
"""SIGTERM: the runner dumps its flash and exits - the image a
|
|
restart resumes from."""
|
|
self.stop()
|
|
return self.dump
|
|
|
|
def stop(self):
|
|
self.proc.terminate()
|
|
try:
|
|
self.proc.wait(timeout=5)
|
|
except subprocess.TimeoutExpired:
|
|
self.proc.kill()
|
|
self.log.close()
|
|
|
|
|
|
def run_tool(tool, pty, baud, *args, timeout=180):
|
|
result = subprocess.run(
|
|
[os.environ.get("PYTHON", "python3"), tool, "--port", pty, "--baud", str(baud), "--wait", "25", *args],
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=timeout,
|
|
)
|
|
print(result.stdout, end="")
|
|
if result.returncode != 0:
|
|
raise RuntimeError(f"tool exited {result.returncode}: {result.stderr.strip()}")
|
|
return result.stdout
|