Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions ZAPAROO_FORK.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,16 @@ non-blocking spawn) are intentionally omitted.
| 37 | **Framebuffer geometry is always computed** | `video_fb_config()` records `fb_width`/`fb_height`/`brd_*` **before** deferring to `alt_launcher_handle_video_fb_config()`; the hook only replaces the enable and the kernel-module write. When the hook sat at the top of the function (`1d9c1e6`, beta 2/3), the menu process never assigned the geometry at all: `video_menu_bg()` built 0x0 wallpaper images (`Warning: bg1 is 0`), and the launch-time `video_fb_enable(0)` took `video_fb_set()`'s menu-background fallback and programmed a 0x0 framebuffer into the FPGA on the way into `fpga_load_rbf` → HDMI output died on every game launch from the frontend. A matching `video_fb_enable(0)` in `alt_launcher_shutdown()`'s no-child branch was tried and reverted: `app_restart()` calls that function a **second** time, after `fpga_load_rbf` has already loaded the game core, and `is_menu()` is a per-process cache of `orig_name` (`user_io.cpp:222`) so it is still true there. `video_fb_set()`'s menu-background fallback then flips the disable into `FB_EN` at menu geometry and writes it into the **new** core, killing every launch. Teardown video belongs on the live-child branch only, which runs before the reconfiguration | `video.cpp` (`video_fb_config`) |
| 38 | **gcdb probes the gamepad node, never a touchpad** | gcdb resolves a mapping's `bN` entries by enumerating the probed evdev node's key bits (`get_ctrl_index_maps`); `hN.x` hat entries are arithmetic. A DualSense contributes a gamepad node and a Touchpad node with the same Phys/Uniq, merged by `mergedevs()`, and `input_cb` loads the shared map from whichever node reaches it first, caching the result by vid/pid. Probed through the touchpad, every face button maps to a touchpad code while the d-pad keeps working (a beta report: "d-pad moves, Open/Options/View do nothing", only with keyboard dongles present, which reorder `/dev/input`). `zaparoo_gcdb_probe_dev()` swaps a `QUIRK_DS4TOUCH` probe for the group's `QUIRK_DS4` sibling, and the pre-warm (row 22) only feeds merge-base, non-touchpad nodes. The merge base is only the first of a group's nodes in scan order, so a pad whose receiver also exposes keyboard or mouse interfaces could still be probed through the wrong one (zaparoo-frontend#455): any probe node without `BTN_GAMEPAD`/`BTN_JOYSTICK` bits is swapped for the group's node that has them, and left alone when there is none. Two adjacent upstream hardenings: `get_ctrl_index_maps` bounds its loops to `btn_map`'s size, and `gcdb_controller_idx` skips zeroed cache slots (an all-zero id used to match slot 0 and return an all-zero map as a hit) | `support/zaparoo/launcher_input_detect.inc` (`zaparoo_gcdb_probe_dev`, `zaparoo_prewarm_device_maps`), `input.cpp` (`input_cb` map load, 2-line hook), `gamecontroller_db.cpp` |
| 39 | **`app_restart()` copies `exe` before the launcher teardown** | `user_io_init` honours a per-core `main=` (`[RA_*] main=MiSTer_RA`) with `app_restart(path, xml, getFullPath(cfg.main))`, and that pointer aliases file_io's single static `full_path`. `app_restart()` calls `alt_launcher_shutdown()` first, and `kill_stale_frontends()` (`getFullPath(s_launcher_path)`) plus a cold `alt_launcher_installed()` (`FileExists`) rewrite the buffer to `/media/fat/zaparoo/frontend`, so the `execl` re-launched Main **as the frontend binary**: no Main, black screen, `/tmp/CORENAME` stuck at `MENU`. `exe` is now copied to a private buffer before the teardown. Any pointer handed across `alt_launcher_shutdown()` must not alias `full_path` | `fpga_io.cpp` (`app_restart`, 3 lines beside the existing hook) |
| 40 | **Persistent Main log (`main.log`)** | Main's stdout goes to the console after a reboot, so the first-exit-after-boot slowness could not be captured with the `/tmp/mz.log` recipe (row 23). If `/media/fat/zaparoo/main.log` exists, a constructor dup2's it over stdout and stderr before `main()`, writes a start marker (pid, uptime, wall clock) per exec, rotates to `.old` above 8 MB, and starts a detached heartbeat thread that writes `[zt <uptime ms>]` every 250 ms so upstream's untimed lines can be placed against zlog's `t=`. Marker and heartbeat use `dprintf`, not `printf`: the `setvbuf` in `service_boot.cpp` may not have run yet and is only valid before the stream's first use. Touch the file to enable, delete it to disable; absent file, nothing runs | `support/zaparoo/main_log.cpp` (zero upstream hooks) |
| 40 | **Persistent Main log (`main.log`)** | Main's stdout goes to the console after a reboot, so the first-exit-after-boot slowness could not be captured with the `/tmp/mz.log` recipe (row 23). If `/media/fat/zaparoo/main.log` exists, a constructor dup2's it over stdout and stderr before `main()`, writes a start marker (pid, uptime, wall clock) per exec, rotates to `.old` above 8 MB, and starts a detached heartbeat thread that writes `[zt <uptime ms>]` at most every 250 ms, and only when the log has grown since the last stamp, so upstream's untimed lines can be placed against zlog's `t=` and an idle Main writes nothing to the SD card. Marker and heartbeat use `dprintf`, not `printf`: the `setvbuf` in `service_boot.cpp` may not have run yet and is only valid before the stream's first use. Touch the file to enable, delete it to disable; absent file, nothing runs | `support/zaparoo/main_log.cpp` (zero upstream hooks) |
| 41 | **Late-appearing display keeps the frontend on the fallback video mode** | `read_edid()` bails silently when the ADV7513 does not sense HPD + monitor sense, so a TV powering up alongside the DE10 leaves `video_init()` on the built-in default (1280x720) and the frontend probes its render size against that: full-res instead of half. The MENU core exposes no HDMI interrupt pin, so upstream's `video_poll()` hot-plug re-init never runs and the wrong mode sticks until the next core load (observed: 34 minutes). The single 500 ms pre-spawn retry now polls out a 3 s hold window, and if the spawn still happens on the fallback mode the launcher watches the transmitter's sense bits for 30 s behind the running child and restarts it once the display answers. `video_reinit()` is spent only on a link down->up edge and at most 3 times per init, so a display that genuinely has no EDID is not flickered. Sense bits are read through a private `i2c_open(0x39)` handle, as `hdmi_cec.cpp` already does for the same chip. If upstream subsequently obtains EDID after that watch expires, a child spawned without EDID is restarted once to reprobe its geometry | `support/zaparoo/alt_launcher.cpp` (zero upstream hooks) |
| 42 | **Physical-disc autorun** | Opt-in OSD setting (settings byte 3, off by default). While the menu core is active, a detached worker probes `/dev/sr0` through `/dev/sr7`. CDs use TOC and signature reads; any media accepted by `DVD_READ_STRUCT` is treated as DVD without mounting it. CD launch resolution has no extra config file: it probes known physical-CD provider binaries and uses each provider's MGL in its original directory (`MiSTer_Physical-CD` + `_Physical Disc Cores`, or `MiSTer-disc` + `_Disc_Cores`), preserving `same_dir="1"` behavior. DVDs launch the latest installed `DVD_YYYYMMDD.rbf`, falling back to `DVD_Player.rbf`. Audio and unknown discs are ignored. Detection stops outside the menu core, and the handled fingerprint prevents the same inserted disc relaunching after a return to menu until removal is observed. No physical-disc playback, mounting, or per-core support is included | `support/zaparoo/physical_cd_autorun.cpp/.h`, `support/zaparoo/settings.cpp/.h`, `support/zaparoo/launcher_pages.cpp/.h`, `scheduler.cpp` |
| 43 | **Core liveness watchdog** | While frontend is active, polls the existing Core PID file every 2 s. A retained PID that no longer exists or does not identify Core's cached service executable/script triggers a memory diagnostic and the idempotent service ensure through a detached helper. Core owns stale-PID cleanup under its start gate; PID-reuse recovery requires matching Core support. Missing PID files are ignored and attempts are throttled to 30 s; this is a liveness heuristic, not proof of OOM or another specific exit cause | `support/zaparoo/core_watchdog.cpp/.h`; called from `support/zaparoo/save.cpp`'s existing `zaparoo_poll()` fork hook |
| 44 | **Frontend scanout and black handoff** | Exact-qualified HDMI scanout uses a v2 inherited socket slot lease; Main proxies complete UIO packets and remains the sole bus writer, so OSD/video queries stay live. Mismatched handshakes fall back to fb0. Startup stays black through video probing, with bounded fb0 fallback and no live-owner timeout. Failed child stops abort core loads, re-exec and script handoffs. Native CRT and Direct Video retain their existing paths | `support/zaparoo/scanout.cpp/.h`, `bootstrap.h`, `alt_launcher.cpp/.h`, `SCANOUT.md`; surgical hooks in `fpga_io.cpp`, `menu.cpp`, `user_io.cpp`, `video.cpp` |
| 44 | **Frontend scanout and black handoff** | Exact-qualified HDMI scanout uses a v2 inherited socket slot lease; Main proxies complete UIO packets and remains the sole bus writer, so OSD/video queries stay live. Mismatched handshakes fall back to fb0. Startup stays black through video probing, with bounded fb0 fallback and no live-owner timeout. Failed child stops abort core loads, re-exec and script handoffs. Native CRT is offered the same socket in native mode: after the same gating Main answers `ZAPAROO-SCANOUT-2 NATIVE`, meaning the verified module is loaded and the frontend may map the native video window through it; nothing is proxied and `owned()` / `bus_owned()` stay false. HDMI under Direct Video gets no offer and no black bootstrap. Module profiles must carry `zaparoo-scanout-v2-native` | `support/zaparoo/scanout.cpp/.h`, `bootstrap.h`, `alt_launcher.cpp/.h`, `SCANOUT.md`; surgical hooks in `fpga_io.cpp`, `menu.cpp`, `user_io.cpp`, `video.cpp` |
| 45 | **Frontend input/FIFO liveness** | Noisy controllers cannot drain forever while the launcher is active; proxy mode uses nonblocking input polls. Stock Menu rumble diagnostics exclude the live frontend. Command FIFO parsing preserves fragmented lines and dispatches coalesced lines independently, discarding overlong/NUL-containing lines rather than executing truncations | `support/zaparoo/command_stream.h`, `tests/integration_test.cpp`; surgical `input.cpp` hooks |
| 46 | **Menu snow without a frontend** | The Zaparoo menu core holds its idle video black so a frontend start has no snow flash, and on its own only shows snow behind the OSD. Kiosk mode, the idle screensaver's first stage and a quit frontend all have the OSD closed, so the background went black (zaparoo-frontend#503). Main now sets menu `status[10]` whenever no frontend owns or is about to take the screen: `zaparoo_menu_bg_init()` writes it right after the saved menu status is loaded (F1 saves the whole status word, so a stale bit must not survive into a frontend start), and `zaparoo_menu_bg_poll()` follows `alt_launcher_menu_snow_allowed()`, which is `!alt_launcher_owns_screen()` and not waiting to resume after a script. **Set = snow, clear = black**: the core resets with status 0 before Main has spoken, so clear has to be the black state. Mismatched pairs behave as before the bit existed (black except behind the OSD). Bit 9 is avoided because the retired v1 native CRT contract used it | `support/zaparoo/menu_bg.cpp/.h`, `alt_launcher.cpp` (`alt_launcher_menu_snow_allowed`), `user_io.cpp` (menu init), `zaparoo_poll()`; core side `rtl/zaparoo_snow_enable.sv` in `Menu_MiSTer` |
| 47 | **Launcher VT reset on teardown** | The frontend is killed by signal on every core load and so never restores its VT: tty7 stays foreground in `KD_GRAPHICS`, and the kernel refuses to switch away from that, so a later `video_chvt()` blocks in `VT_WAITACTIVE` for good. Opening a manual from a game core's OSD froze Main (zaparoo-frontend#445). `alt_launcher_shutdown()` now calls `reset_launcher_tty()` in both branches, like every other teardown, and the doc viewer takes the same `alt_launcher_prepare_for_script()` / `alt_launcher_resume_after_script()` hand-off as `MENU_SCRIPTS_FB` | `alt_launcher.cpp` (`alt_launcher_shutdown`), `menu.cpp` `MENU_DOC_FILE_SELECTED` / `MENU_DOC_FILE_SELECTED_2` hooks |
| 48 | **No console text on Direct Video startup** | Under Direct Video `video_fb_set()` puts an enabled fb0 on the DAC through the VGA framebuffer mux, and the launcher re-asserts fb0 from queued startup onwards while another VT (boot text, a script) is still active. When the launcher VT is not active at `alt_launcher_init()` or `spawn()`, the launcher's own re-asserts keep fb0 enabled, so the child's `fb_cmd` is still accepted, but leave the mux off until `finalize_spawn()` has switched to tty7. Other callers of `video_fb_enable()` (OSD terminal, scripts, doc viewer, wallpaper) are untouched, as are HDMI and native CRT | `support/zaparoo/alt_launcher.cpp` (`arm_direct_video_hold`, `launcher_fb_reassert`, `finalize_spawn`), `video.cpp` (`video_fb_set` mux line) |
| 49 | **Held directions are checked against the axis** | `input_test` turns each axis into direction presses and keeps one edge per axis; only an event from that axis clears it, so a missed return to center leaves the direction held and the launcher repeating it (a beta device log: Down held 6.8 s after a tap, ended by the next d-pad press). While the launcher is active, an edge held past 200 ms is compared with the kernel's current value for that axis (`EVIOCGABS`), then every second. At rest: the direction is released and logged. Still deflected: one log line per hold, so a stuck device can be told from a held one. `SYN_DROPPED`, which upstream ignores, triggers the same check at once. A press is never synthesized; quirk devices and lightguns are skipped because `input_test` rewrites their ranges | `support/zaparoo/launcher_axis_resync.inc`, `input.cpp` (include plus 2 one-line hooks) |
| 28 | **Early service start** | A `__attribute__((constructor))` runs `/media/fat/Scripts/zaparoo.sh -service start` before `main()`, so ahead of the core-1 affinity pin (a child would inherit it) and ahead of `FindStorage()`'s 30s USB wait. Double fork + `setsid()` and **no** `PR_SET_PDEATHSIG`, the inverse of `exec_launcher_child`: the service must survive the `app_restart()` re-exec every core load performs. The detached ensure helper is also reused by the Core liveness watchdog, restoring the saved startup CPU-affinity mask and closing inherited Main descriptors before exec. No marker file, the script is an ensure | `support/zaparoo/service_boot.cpp/.h` (zero upstream hooks) |

---
Expand Down
3 changes: 3 additions & 0 deletions input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2954,6 +2954,7 @@ static void assign_player(int dev, int num, int force = 0)
// separate support/zaparoo/ file but #included here because it needs this TU's
// file-static device tables (input[]/pool[]/devInput/NUMDEV).
#include "support/zaparoo/launcher_input_detect.inc"
#include "support/zaparoo/launcher_axis_resync.inc"

static void input_cb(struct input_event *ev, struct input_absinfo *absinfo, int dev, bool menu_event)
{
Expand Down Expand Up @@ -5683,6 +5684,7 @@ int input_test(int getchar)
memset(&ev, 0, sizeof(ev));
if (read(pool[i].fd, &ev, sizeof(ev)) == sizeof(ev))
{
zaparoo_axis_note_event(i, &ev);
if (getchar)
{
if (ev.type == EV_KEY && ev.value >= 1)
Expand Down Expand Up @@ -6382,6 +6384,7 @@ int input_poll(int getchar)
if (getchar) return ret;

uinp_check_key();
zaparoo_axis_resync();

static int prev_dx = 0;
static int prev_dy = 0;
Expand Down
28 changes: 21 additions & 7 deletions support/zaparoo/SCANOUT.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,27 @@ without yielding inside a transaction. Its OSD, input and video queries can run
between packets. Do not remove `fpga_io.cpp`'s direct-owner guards or grant access
merely because an offer was exported or the child passed `--latch`.

Initial eligibility is HDMI (not Direct Video), with a profile matching both
Slot eligibility is HDMI (not Direct Video), with a profile matching both
the running kernel release and its GNU build ID. Frontend finishes vmode/output probes before requesting access.
Main waits for `finalize_spawn`, checks active mapping conflicts, optionally loads
`/media/fat/zaparoo/modules/<release>/<kernel-build-id>/zaparoo_scanout.ko`, then acknowledges
`ZAPAROO-SCANOUT-2` with `ZAPAROO-SCANOUT-2 PROXY` over the inherited
`SOCK_SEQPACKET` channel. Unknown kernels/native CRT receive no offer. Both old
`SOCK_SEQPACKET` channel. Unknown kernels receive no offer. Both old
Main/new frontend and new Main/old direct-MMIO frontend reject the mismatched
handshake and fall back to fb0. Kernel ABI and FPGA scanout commands are unchanged.
handshake and fall back to fb0. FPGA scanout commands are unchanged.

Native CRT (with or without Direct Video) gets the same socket in a distinct
native mode (`Offer::native`). The request, `finalize_spawn` wait, conflict scan
and module verification are identical; the acknowledgment is
`ZAPAROO-SCANOUT-2 NATIVE`. It tells the frontend the verified module is loaded,
so it may map the Menu core's native video window (`0x3A000000`, 3 MB) and use
the vblank wait through it instead of `/dev/mem`. It grants nothing else: no
slots, no proxy (packets are ignored, `ZAPAROO_SCANOUT_RASTER` is not exported),
and `owned()` / `bus_owned()` stay false, so no HDMI lease behavior switches on.
A denied or absent native offer leaves the frontend on its `/dev/mem` mapping.
Main keeps writing that window's control words through its own `/dev/mem`
mappings; its 3 MB blank after spawn completes before `finalize_spawn`, so
before any native grant. HDMI under Direct Video still receives no offer.

Each subsequent packet contains little-endian u16 magic `0x5A52`, sequence,
command, count and words. Only SET (`0x57`, 12 words), CAPS (`0x59`, 6 words), and
Expand Down Expand Up @@ -42,7 +55,8 @@ asynchronous insmod child; it never unloads a module. Parent-death signaling and
post-fork parent checks prevent frontend survival after Main.

Active `mem_wc`, MagiK, Zaparoo and overlapping `/dev/mem` checks are conservative
cooperative checks, not a security boundary. Raw mappers can race them;
cooperative checks, not a security boundary. The `/dev/mem` check covers the
slots and the native video window for either grant. Raw mappers can race them;
independent concurrent renderers remain unsupported.

Build with the existing ARM GNU toolchain and `make` or `./docker-build.sh`.
Expand All @@ -58,8 +72,9 @@ Local builds do not authorize deployment, force-loading or release-channel chang
`scanout_profile.cpp` reads the bounded ELF note stream from `/sys/kernel/notes`
and the seven-line `profile` file beside the selected module. The format is:
magic `ZAPAROO-SCANOUT-PROFILE-1`, release, kernel build ID, module build ID,
module SHA-256, kernel source revision, and `zaparoo-scanout-v1-1080p`, each
module SHA-256, kernel source revision, and `zaparoo-scanout-v2-native`, each
followed by a newline. Hex values are lowercase; no extra fields are accepted.
A v1 profile (`zaparoo-scanout-v1-1080p`) selects no module and gets no offer.

Module hashing runs in the asynchronous loader child using `sha256sum`; hashing
and insmod share an open file descriptor so renaming a package during update
Expand All @@ -71,5 +86,4 @@ also fails closed. These checks detect incompatible or damaged installations;
they do not authenticate packages against a privileged attacker.

MagiK's Main-window mapping device participates in the existing conflict check.
The Zaparoo module ABI, slot addresses, UIO protocol and ownership lifecycle
remain unchanged. Unknown builds and old flat module layouts receive no offer.
Slot addresses, UIO protocol and ownership lifecycle remain unchanged. Unknown builds and old flat module layouts receive no offer.
Loading