#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-3.0-only # Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant) # (after Melodee's tests/smk_pkg_test.py, Copyright (C) 2026 M. Geisler (genkigenki/makkuro)) """An SMK-37 package (tools/build.py --board smk37): its identity, flash.bin the stock PRCT size (0x9D000), the app area carrying the stock v016 region table exactly (VM, PRCT, BTIF, USRTRIM, USRFLASH, USR), app.bin the build's felucca.bin, the encrypted region ending inside flash.bin, JIANT's own update loader, and no update-record look-alike. With a stock M-VAVE v016 package (read only, never linked or copied) the region table's bytes at flash 0x4060..0x411F are compared with the stock one's too: the bytes the SMK build's board check (ota.c) and a later return to stock rely on. smk_pkg_test.py PACKAGE.fwsc PRODUCT APP.bin [STOCK.fwsc]""" 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 RT_OFF, RT_LEN = 0x4060, 0xC0 # the region table in flash.bin (ota.c OTA_RT_OFF / OTA_RT_LEN) STOCK_TABLE = [(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)] def ok(cond, what): global failed print(f"smk pkg: {what:<84} {'ok' if cond else 'FAIL'}") failed += not cond def entries(image): """the UFW entry list: [(type, offset, length, crc16)]""" hdr = bytearray(image[:0x40]) M.enc(hdr, 0, 0x40) n = struct.unpack_from(" 4: # the stock M-VAVE v016 package of the same model: data only, read here sraw = Path(sys.argv[4]).read_bytes() _, _, sflash, _ = flash_of(sraw) _, sents = area_entries(sflash) ok(len(sflash) == len(flash), f"stock {Path(sys.argv[4]).name}: flash.bin {len(sflash):#x} B, the same size") ok(sents[2:] == STOCK_TABLE, "stock package: its region table decodes to the table this test expects") ok(sflash[RT_OFF:RT_OFF + RT_LEN] == flash[RT_OFF:RT_OFF + RT_LEN], "flash 0x4060..0x411F byte for byte the stock package's (the SFC-enciphered region table)") print("SMK PACKAGE TEST FAILED" if failed else "smk package test passed") sys.exit(1 if failed else 0)