Files
fmini-1/tests/smk_pkg_test.py
T
Claude 1b0b5c6b1c SMK-37 port: the board layer (genkigenki/Felucca smk37, b67312c) on FMini-1
The SMK-37 target from github.com/genkigenki/Felucca branch smk37 (commit
b67312c on Felucca 1.6.1, = hugelton/Felucca#237; the fm1-to-smk37 kit's
Felucca layer), applied to FMini-1, whose firmware/hal and firmware/loader are
Felucca 1.6.1's:

- BOARD=smk37 / MODEL=pro|elite|mke (tools/build.py, build.sh), the SMK flash
  map with its protected ranges (fm1_flash_map.h), the update path and its
  size checks (ota.c, ldr_core.c), the SMK input HAL, LCD and pad LEDs, the
  owner tag of the store, installers and tests.
- Conflicts resolved for FMini-1: packages fmini-1-fm1-<version>.fwsc and
  fmini-1-smk37[-elite|-mke]-<version>.fwsc; FL_JEDEC_OK keeps the UC25HQ80
  (0xB36014) on the FM-1 and accepts it on the SMK too; the official V16
  length stays FM-1 only; the sample slots stay gone (FMini-1 has no SAMPLE
  engine: the layer's eng_sample.c and editor sample hunks are not taken);
  main.c keeps FMini-1's UI_* hooks with the SMK calls around them.
- The FM-1 build is byte-identical to 2.5.0 (app, package and loader
  hashes). The SMK build does not link yet: FMini-1's preset objects need
  places in the SMK store, and fmini_app.c's LED code is FM-1 sized.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QUF6pQ1NkTwmBC8SR8AK94
2026-11-09 12:46:23 -03:00

56 lines
2.5 KiB
Python

#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-only
# Felucca on the SMK-37 Pro (BOARD_SMK37)
"""An SMK-37 Pro package from fm1pkg_make.py --board smk37: flash.bin is the stock PRCT size (0x9D000) and
its app area carries the stock v016 region table exactly, so the SDK
and a later stock rollback see the same VM / BTIF / USRTRIM / USRFLASH / USR regions.
smk_pkg_test.py PACKAGE.fwsc [PRODUCT]"""
import struct
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "tools"))
import fm1_install as I # noqa: E402
import fm1pkg_make as M # noqa: E402
failed = 0
def ok(cond, what):
global failed
print(f"smk pkg: {what:<70} {'ok' if cond else 'FAIL'}")
failed += not cond
raw = Path(sys.argv[1]).read_bytes()
want_product = sys.argv[2] if len(sys.argv) > 2 else "SMK-37 Pro_900"
image, n = I.deinterleave(raw), I.block_count(raw)
ok(n == 20 and I.product_of(raw) == want_product and I.files_ok(image),
f"identity {I.product_of(raw)}, 20 blocks, CRCs ok")
hdr = I._dec(image[:0x40])
e0 = I._dec(image[0x40:0x90])
off, size = struct.unpack_from("<II", e0, 8)
ok(struct.unpack_from("<H", e0, 0)[0] == 0 and size == 0x9D000, f"flash.bin {size:#x} B (stock PRCT 0x9D000)")
flash = bytearray(image[off:off + size])
area = bytearray(flash[0x4000:0x4000 + 0x400])
M.sfc(area, 0, len(area), 0, M.KEY)
ents = []
for k in range(1, 12):
e = bytes(area[k * 32:(k + 1) * 32])
if M.crc16(e[2:]) != struct.unpack_from("<H", e)[0]:
break
dcrc, eoff, esize, flags, resvd, index = struct.unpack_from("<HIIBBH", e, 2)
ents.append((eoff, esize, flags, resvd, index, e[16:32]))
want = [(0x9D000, 0x23000, 0x12, 0x81, 0, bytes.fromhex("564d00ffffffffffffffffff00800000")),
(0, 0x9D000, 0x92, 0x82, 0, bytes.fromhex("5052435400ffffffffffffff434f4445")),
(0xC0000, 0x1000, 0x92, 0x82, 0, bytes.fromhex("4254494600ffffffffffffff4155544f")),
(0xC1000, 0x1000, 0x92, 0x81, 0, bytes.fromhex("5553525452494d00ffffffffffffffff")),
(0xC2000, 0x29000, 0x92, 0x81, 0, bytes.fromhex("555352464c41534800ffffffffffffff")),
(0xF4000, 0xA000, 0x92, 0x81, 1, b"USR\0" + b"\xff" * 12)]
ok([e[5][:7] for e in ents[:2]] == [b"app.bin", b"cfg_too"], "app.bin, cfg_tool.bin first")
ok(ents[2:] == want, "region table == stock v016 (VM, PRCT, BTIF, USRTRIM, USRFLASH, USR)")
ok(flash[:0x4000] != b"\xff" * 0x4000, "head present (never written by the loader, checked against the device)")
print("SMK PACKAGE TEST FAILED" if failed else "smk package test passed")
sys.exit(1 if failed else 0)