The temporary page buffer is write-once per word, so a page filled over one an earlier writer left dirty programs the stale words. The same datasheet clause carries the cure: the buffer auto-erases after a page write (§26.2.1; §19.2 on the tinies), so the corruption clears itself by happening, and rewriting the page programs correctly. The loader therefore clears the buffer nowhere. The tinies' CTPB and the m48s' RWWSRE discard are gone; the boot-sectioned megas keep only the trailing RWWSRE they need anyway to re-enable the RWW section for read-back, which discards the buffer as a side effect and keeps them off the path entirely. 434 B on the tiny13s, 438-442 on the tiny25/45/85, 430 on the m48s; the megas are unchanged, the 1284s still 506. The host takes over the guarantee: a flash page that reads back wrong is rewritten up to RETRIES times before the run stops. Both read-back paths repair — verify_pages for programming, and write_differing, which is the loader-update path where a page left wrong is a half-written loader slot. That one is not hypothetical: deleting the discard made attiny85 pureboot.rehome fail deterministically there, the only flow still assuming the old contract. Protocol-visible, so README's W command says it: one W may program the wrong bytes after a refused page, or after an application that self-programmed entered without a reset, and a host that programs without reading back cannot trust it. Tests: pureboot.dirty drives the case the loader declines to guard — the fixture application dirties every buffer word and jumps in with no reset (hardware forbids that on a boot-sectioned mega, but simavr dispatches SPM from anywhere, which is what makes it constructible) — and asserts a bare verify sees the corruption, the repairing verify fixes it in one rewrite, and it stays fixed. pbreloc asserts the same shape after a refusal. test_planner covers the bound against a fake device: one bad write repaired in a single rewrite, a page that never comes good stopping after exactly three. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
55 lines
1.9 KiB
Python
55 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Position-independence lint for the pureboot image.
|
|
|
|
The self-staging design lets the identical binary run from any 512-byte
|
|
slot, which holds only if nothing in the image addresses itself absolutely.
|
|
Two link-time facts guarantee it, both asserted here from the built ELF:
|
|
|
|
1. No absolute jmp/call opcodes — all control flow is PC-relative
|
|
(rjmp/rcall/ijmp/icall). -mrelax normally guarantees this; a code
|
|
change that grows a branch out of relaxation range would break it
|
|
silently.
|
|
2. The info block sits within the image's first 256 bytes: the 'b'
|
|
command rebuilds its address as (running slot high byte : low byte of
|
|
the link address), which needs the offset to fit that low byte.
|
|
|
|
Usage: check_pi.py <objdump> <nm> <elf> <text_start_hex>
|
|
"""
|
|
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
|
|
|
|
def main():
|
|
objdump, nm, elf, text_start = sys.argv[1:]
|
|
text_start = int(text_start, 0)
|
|
|
|
listing = subprocess.run([objdump, "-d", elf], capture_output=True, text=True, check=True).stdout
|
|
absolute = [
|
|
line
|
|
for line in listing.splitlines()
|
|
if re.search(r"\t(jmp|call)\t", line)
|
|
]
|
|
if absolute:
|
|
print("FAIL: absolute control flow in the image:")
|
|
print("\n".join(absolute))
|
|
sys.exit(1)
|
|
|
|
symbols = subprocess.run([nm, "-C", elf], capture_output=True, text=True, check=True).stdout
|
|
info = [line for line in symbols.splitlines() if "flash_table" in line and "::storage" in line]
|
|
if len(info) != 1:
|
|
print(f"FAIL: expected one info-block storage symbol, found {len(info)}")
|
|
sys.exit(1)
|
|
address = int(info[0].split()[0], 16)
|
|
offset = address - text_start
|
|
if not 0 <= offset < 256:
|
|
print(f"FAIL: info block at image offset {offset:#x}, must sit in the first 256 bytes")
|
|
sys.exit(1)
|
|
|
|
print(f"PI lint: control flow PC-relative, info block at offset {offset:#x}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|