Files
JIANT/tests/layout_packing_test.py
Claude c4e04dd749 The second code segment (flash 0xC8000..0xCFFFF), ported from JIANT BYTE (e807224d): 31.8 KB out of the app slot
FM's reserve 0xC8000..0xD7FFF (storage.c FL_SAMPLES, written by nothing) now holds, in its first half, cold main-loop
code run in place through the plain XIP window as the Bluetooth segment is. 0xD0000.. stays reserved; JAM's takes at
0xDA000 / 0xDB000 untouched.

- Build: app.ld C2SEG (XIP 0x020C4000), section .c2 (c2_head first, then .c2.text / .c2.rodata); core.h C2_FN / C2_IN /
  C2_RO; src/seg2.c (header, c2_want, c2_seg_ok). tools/build.py writes build/c2.bin (JBC2, length, CRC-32) and patches
  c2_want as bt_want; c2_check: nothing an interrupt, core 1 or RAM code reaches is in it, every call in from the slot
  comes from a hand-checked gate (C2_GATES), no segment address stored as data.
- Moved: the editor protocol's commands and pushes (ed_command, ed_sync, their helpers, FM's ed_fm6_handle; INFO, the
  backup and the project library stay in the slot), GEN's generators (gen_make, gen_parts, gen_pitched, gcpu_fit,
  gen_sound, gen_kit, gen_mix, gl_write, gsong, gplan, grich, gls_prep, gen_arp, trackgen_run ...). FM differs from
  BYTE: gen_make / gen_parts are slot code here (BYTE: Bluetooth segment), so they moved too, gen_go a gate;
  gen_evolve and gx_comps stay in the slot (gen_post calls them); gen_rs_apply was already in the Bluetooth segment;
  no dice_seq. Slot: 583660 -> 551828 B (676 -> 32508 B free). Segment: 31660 of 32768 B (1108 B free).
- Sound: every pinned / recorded audio function and table at its address (layout unchanged, no repin); audio flash
  code identical but for immediates; RAM code +36 B (the flash driver's range check, FL_RANGE_OK). The merged
  constants' floor (build/layout_cst.ld) is the first pool's start as laid out (FM's pools have UI constants before
  the sound's first). seq_steps always inline (no out-of-line copy for the segment's calls).
- Runtime: bt_hw_seg() checks both segments once at power-on; missing / torn / another build's: FLASH PART MISSING /
  REINSTALL at power-on and on GEN; the editor answers INFO ('X' 2), the backup and the project library only.
- Package / loader: fourth UFW entry c2.bin (type 201), checked before anything is erased, all of [0xC8000, 0xD0000)
  written (0xFF past the code), never 0xD0000 and up. FL_STORE_OK / FL_RANGE_OK leave the segment out (static asserts).
- Tests: ldr_test (c2 written, rest erased, damaged c2 refused, 0xD0000.. untouched), editor_test (segments missing),
  storage map assert, layout packing test. Manuals and EDITOR_PROTOCOL: FLASH PART MISSING.

Needs a hardware test on the FM-1 before any release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KMHk6yH4XbP1xxHYKCo9Mh
2026-12-04 22:33:34 +00:00

35 lines
1.7 KiB
Python

"""Only movable main-loop code may fill gaps before pinned audio runs."""
import sys
from pathlib import Path
from tempfile import TemporaryDirectory
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "tools"))
import build
build.size_fns.size_names = lambda: {"song_erase_parts", "gen_go", "old_ui", "audio_fn", "radio_fn"}
build.late_fns = lambda: {"gen_go"}
base = build.APP_XIP
rows = [(64, "@", "audio_fn"), (70, "-", "old_ui"), (128, "@", "audio_next")]
symbols = {"_lay_gap0": base + 16, "_lay_gap1": base + 80}
inputs = [(".rodata.n.label", base + 1000, 12, "build/felucca.o"),
(".text.song_erase_parts", base + 2000, 24, "build/felucca.o"),
(".text.gen_go", base + 2100, 20, "build/felucca.o"),
(".text.audio_fn", base + 64, 24, "build/felucca.o"),
(".text.old_ui", base + 70, 24, "build/felucca.o"),
(".text.radio_fn", base + 2200, 24, "build/bt_seg.o")]
fills, gap, padding = build.layout_fills(rows, symbols, inputs, {"label": 1}, {"audio_fn"})
items = [item for values in fills.values() for item in values]
assert set(items) == {"label", "@song_erase_parts", "@gen_go"}
assert len(items) == len(set(items)) and gap == 96 and padding == 40
with TemporaryDirectory() as tmp:
build.LAYOUT_LD = Path(tmp) / "layout.ld"
build.LAYOUT_CST = Path(tmp) / "layout_cst.ld"
build.layout_ld(rows, fills)
text = build.LAYOUT_LD.read_text()
assert "*(.text.song_erase_parts)" in text and "*(.rodata.n.label)" in text
assert text.count("*(.text.audio_fn)") == 1
assert text.count("*(.text.old_ui)") == 1
assert "radio_fn" not in text
assert ". = 0x40;" in text and ". = 0x80;" in text
print("PASS gap packing: IRQ code, recorded UI and radio object excluded; audio anchors unchanged")