The word-addressed 1284s were the one family deploying in a 1 KiB slot, because the far-flash machinery (ELPM reads, RAMPZ page commands, a word-addressed wire) did not fit 512 B. It does now: 478 B stock, 494 B in the heaviest configuration the build can produce. They take the 644s' geometry, where the smallest boot section holds the resident slot and its staging slot together. The loader's version goes to 3; the host tool did not change, so its own version stays 2 and only the window it speaks widens. Most of the saving is one restructure. The info block and a flash read are the same act, so giving all four streamed commands one address-and-count path leaves exactly one call site for the flash streamer: it inlines into the never-returning command loop and its 24-bit cursor stops being saved and restored around every transmit. Around it, the ack byte moved out of line, the wire's byte pair is bit_cast into the word it already is, the fuse loop ends on its count, the info block's in-slot offset is taken as the one-byte relocation it is, and -fno-expensive-optimizations gives way to -fno-move-loop-invariants -fno-tree-ter. Every chip shrank 14-18 B. The size matrix grew the axes it was missing: the USART1 instance across the whole clock ladder, and the shape a slow baud gives a software UART — past 255 delay iterations libavr takes the 16-bit delay loop, which the ladder default never selects and which was 4 B over the 1284's slot the first time it was built. The protocol fixture stopped deriving the loader entry from the flash size; on the 1284s it had been jumping a slot low and reaching the loader only because erased flash walked it up. Docs and comments were consolidated across the port in the same pass: the README carries a per-chip size table instead of prose, and prose that restated the code is gone — 190 lines, no behaviour with it. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
49 lines
1.6 KiB
Python
49 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Position-independence lint: the two link-time facts that let the identical
|
|
image run from any slot, asserted from the built ELF.
|
|
|
|
1. No absolute jmp/call — -mrelax normally guarantees it, but a branch that
|
|
grows out of relaxation range would break it silently.
|
|
2. The info block within the image's first 256 bytes: 'b' rebuilds its
|
|
address as (running slot high byte : link address 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()
|