Files
firmware/tools/replica/sim-boot-screen.py
Oleksandr ShyshatskyiandClaude Opus 5 b98552386b No FlashForge component ships; patch.sh is payload.sh
The software component existed to give the mod one exec hook. It is not needed
for that any more, so a release now carries our installer and our payload and
nothing else: 26MB smaller, 21MB of which was FlashForge's own firmwareExe
travelling back to the partition it was already on, along with their klippy
tree, their wifi module and their configs.

WHAT IT GIVES BACK. /usr/prog/PROGRAM/software is no longer rewritten, so the
version directory there stays FlashForge's with their genuine firmwareExe
inside it -- and app_startup.sh's five-second watchdog, which copies one out of
that directory when nothing by that name is running, has something to copy
again. A printer whose payload fails to install now comes up on the stock UI
instead of a blank screen. That recovery has been broken since we started
deleting their binary out of a component we shipped; docs/how-it-works.md
claimed it worked throughout.

THE ROOT PASSWORD moves with it, because it used to ride in the component's
shadow file. bin/pack.sh bakes ROOT_PW_HASH into the installer, single-quoted
-- an unquoted $6$... would have the printer's shell expand $6 as a positional
parameter and ship a truncated hash -- and the installer writes it to
/usr/prog/etc/shadow. The random-password path asks one question instead of
four: FlashForge ship the same root hash on every machine, so a live shadow
still carrying it means nobody has set a password and it is ours to set. The
.prev-root-hash recording, the shipped-vs-live comparison and the restore-it-
afterwards step were all machinery for surviving a file that nothing overwrites
any more, and are gone. pack.sh checks the hardcoded constant against the stock
package it built from, because getting it wrong is silent and total: every
printer would read as "already set" and none would ever get a password.

bin/patch.sh is bin/payload.sh. It patched nothing any more -- no splice, no
shadow edit, no firmwareExe deletion -- and what is left is the payload: the
feed installed by the printer's own opkg, the seeded config, the manifest. Its
sections are renumbered 1-5 with no gaps, and the five tombstone comments
marking where removed sections used to be are gone with them.

test_recipe_layout.py loses six of its nine tests. Each compared the tree
against a description of the tree -- no fourth directory kind, each kind still
used, 3rdparty carries no files of ours, installer/ holds exactly two named
files -- and none could go red for a reason a printer would notice, while all
six went red the moment the layout legitimately changed. The two that bite are
kept: a payload/ path escaping $MODDIR, and a recipe name at both levels, which
makes pkg_dir silently build the wrong package.

SW_VER is deleted from config.env.example and both workflows: it stamped a
component that is not built.

Gates: 112 static tests pass. The generated installer is verified after
substitution -- all four lines present, and `sh -n` over the result, because a
hash with a stray character in it would otherwise reach a printer as a syntax
error whose only symptom is a package that installs nothing.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CH7Yb4wuPhnppHAB25UX7e
2026-08-30 15:38:25 +03:00

75 lines
2.6 KiB
Python
Executable File

#!/usr/bin/env python3
"""Draw the first-boot screen in the replica and write it out as PNGs.
./tools/replica/sim-boot-screen.py [--out DIR]
ffscreen.py packs pixels by hand, and the only honest way to review that is to
look at the result -- rendered by the interpreter that will really run it.
This drives case-boot-screen-dump.sh, which draws every phase inside the
replica using our own cross-built CPython 3.13 (FF_PYTHON) on MIPS, and
decodes the base64 PNGs it prints back into files.
`make boot-screen` renders the same list on the host in a fraction of the time
and needs no docker; the two are expected to agree byte for byte, and this is
what establishes that they do.
"""
import argparse
import base64
import re
import sys
from pathlib import Path
for _p in Path(__file__).resolve().parents:
if (_p / "bin" / "common.sh").is_file():
ROOT = _p
sys.path.insert(0, str(_p / "tools" / "replica"))
break
from ffsim import cli # noqa: E402
from ffsim.config import Config # noqa: E402
from ffsim.replica import Replica # noqa: E402
from ffsim.gates import _python_tarball # noqa: E402
CASE = ("tools", "replica", "printer", "case-boot-screen-dump.sh")
FRAME = re.compile(r"PNGSTART (\S+)\n(.*?)\nPNGEND", re.S)
def run():
ap = argparse.ArgumentParser(description=__doc__)
ap.add_argument("--out", default=str(ROOT / "work" / "boot-screen-sim"))
args = ap.parse_args()
config = Config.load()
tree = _python_tarball(config)
if not tree:
raise SystemExit("nothing in work/pkg/python -- run ./bin/payload.sh first")
replica = Replica.start(config)
# The frames come back on stdout as base64, so this body is the payload --
# not just a log. It is deliberately not echoed.
body = replica.run_case(str(ROOT.joinpath(*CASE)), packages={"py.tgz": tree})
out = Path(args.out)
out.mkdir(parents=True, exist_ok=True)
# Same reason as the host preview: never leave a stale frame behind.
for stale in out.glob("*.png"):
stale.unlink()
found = 0
for name, blob in FRAME.findall(body):
png = base64.b64decode("".join(blob.split()))
path = out / ("%s.png" % name)
path.write_bytes(png)
_echo("%-18s %s (%d bytes)" % (name, path, len(png)))
found += 1
if not found:
raise SystemExit("the replica printed no frames:\n%s" % body[-2000:])
_echo("\n%d frames in %s" % (found, out))
def _echo(text):
sys.stdout.write(str(text).rstrip("\n") + "\n")
sys.stdout.flush()
if __name__ == "__main__":
sys.exit(cli.main(run))