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>
89 lines
3.3 KiB
Python
89 lines
3.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Dirty-page-buffer acceptance test: with no discard in the loader, a page
|
|
filled over words an earlier writer left takes those instead. The whole
|
|
contract is asserted - a bare verify sees the corruption, the repairing
|
|
verify fixes it in one rewrite, and it stays fixed.
|
|
|
|
The state is reached the one way the loader cannot prevent: an application
|
|
dirties the buffer and jumps in with no reset between. Boot-sectioned megas
|
|
forbid that outright (SPM runs only from the boot section, Atmel-8271 section 26.2),
|
|
but simavr dispatches SPM from anywhere, which is what makes it constructible.
|
|
|
|
Usage: pbdirty.py <device_bin> <pureboot_elf> <mcu> <hz> <base_hex> <page>
|
|
<baud> <app_bin> <tool_py> <workdir>
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
|
|
|
|
def fail(message):
|
|
print(f"FAIL: {message}")
|
|
sys.exit(1)
|
|
|
|
|
|
def main():
|
|
device_bin, elf, mcu, hz, base_hex, page, baud, app_bin, tool, workdir = sys.argv[1:]
|
|
page, baud = int(page), int(baud)
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(tool)))
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
import pbsim
|
|
import pureboot as pb
|
|
|
|
os.makedirs(workdir, exist_ok=True)
|
|
dump = os.path.join(workdir, "dump.bin")
|
|
|
|
# Reset boots the application on a BOOTRST-unprogrammed mega; its 'L' is
|
|
# the loader entry this test needs, reached without a reset.
|
|
device = pbsim.Device(device_bin, elf, mcu, hz, base_hex, page, baud, dump, reset_hex="0")
|
|
try:
|
|
port = pb.Port(device.pty, baud)
|
|
loader = pb.Loader(port)
|
|
loader.connect(25)
|
|
|
|
# Install the application and hand over to it.
|
|
pb.op_flash(loader, app_bin, erase=False, verify=True)
|
|
loader.run_application()
|
|
if port.read_exact(3, 5.0) != b"APP":
|
|
fail("the application did not start")
|
|
|
|
port.write(b"D")
|
|
if port.read_exact(1, 5.0) != b"D":
|
|
fail("the application did not acknowledge dirtying the page buffer")
|
|
port.write(b"L")
|
|
loader = pb.Loader(port)
|
|
loader.connect(25)
|
|
|
|
# Program by hand, so the corruption is observable before anything
|
|
# repairs it.
|
|
pages = pb.plan_flash(open(app_bin, "rb").read(), loader.info)
|
|
for address in sorted(pages):
|
|
loader.write_page(address, pages[address])
|
|
try:
|
|
pb.verify_pages(loader, pages)
|
|
except pb.Error as error:
|
|
if "verify failed" not in str(error):
|
|
fail(f"the read-back failed, but not at verify: {error}")
|
|
else:
|
|
# Either the fixture no longer dirties the buffer, or the loader
|
|
# clears it again - in which case this test's premise is gone.
|
|
fail("programming over a dirty page buffer came back clean")
|
|
|
|
# What the programming path uses: one rewrite settles it, and it stays
|
|
# settled.
|
|
pb.verify_pages(loader, pages, repair=True)
|
|
pb.verify_pages(loader, pages)
|
|
|
|
# Ground truth beyond the loader's own read-back.
|
|
loader.run_application()
|
|
if port.read_exact(3, 5.0) != b"APP":
|
|
fail("the application did not start after the recovered write")
|
|
port.close()
|
|
finally:
|
|
device.stop()
|
|
print("pbdirty: a dirty page buffer is caught by verify and cleared by the retry")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|