fn establish()
Validate + configure the serial port (baud/framing/raw), probe it briefly, and record the `port` resource that later calls inherit config from. Fails loudly when the port is held by another process.
fn send(text: string, appendNewline: boolean, raw: boolean)
Write one line to the port (appends the line ending unless raw). Does not read a response.
| Argument | Type | Required | Description |
|---|
| text | string | yes | Text to send. |
| appendNewline | boolean | yes | Append the configured line ending. Set false with `raw` to send exact bytes. |
| raw | boolean | yes | Treat `text` as an exact payload (implies appendNewline=false). |
fn read()
Drain inbound bytes from the port until it goes idle or the cap is reached.
fn exec(command: string, prompt?: string, stripEcho: boolean)
Send a command line and capture the response until the prompt returns (if given) or the line goes idle. The console-shell primitive.
| Argument | Type | Required | Description |
|---|
| command | string | yes | Command line to send. |
| prompt? | string | no | Optional regex; stop reading once the response's tail matches it (e.g. the shell prompt). |
| stripEcho | boolean | yes | Strip the echoed command line from the captured output. |
fn login(username?: string, promptAfter?: string)
Answer a getty login (login:/Password:) using the vaulted credential, then confirm the shell prompt. The password is never written to the recorded transcript.
| Argument | Type | Required | Description |
|---|
| username? | string | no | Username; defaults to the model's `username` global. |
| promptAfter? | string | no | Optional regex for the shell prompt to expect after login (default matches a trailing $ , # , or > ). |
fn uboot_setenv(vars: record, save: boolean, verify: boolean, prompt: string)
At the U-Boot prompt (`=> `, not a getty), set one or more environment variables with `setenv`, optionally `saveenv` to persist them, and read each back with `printenv` to verify. Values are single-quoted so spaces/`;`/`${…}` are stored literally (U-Boot expands `${…}` at run time). Idempotent and reusable across boards — pass board-specific paths (DTB, grub EFI, partitions) as the variable values. Run against a live U-Boot; not for a booted OS shell.
| Argument | Type | Required | Description |
|---|
| vars | record | yes | U-Boot variables to set as name→value, applied in insertion order. Each becomes `setenv <name> '<value>'`. A value cannot contain a single quote or newline. |
| save | boolean | yes | Run `saveenv` after setting, persisting the env to the board's storage (eMMC/SPI). |
| verify | boolean | yes | Read each variable back with `printenv` and confirm the stored value matches. Robust even under capture (printenv output is newline-terminated). |
| prompt | string | yes | Regex for the U-Boot prompt. Matching a no-newline prompt over a capture session is best-effort; verification does not rely on it. |
fn session_start(capture: boolean, captureMaxBytes: number)
Start a persistent session holder: a detached `socat` opens the port once and bridges it to a PTY, so the logged-in shell survives across separate method runs. Later send/read/exec/login (and serial-cfgmgmt) calls automatically attach to the holder. With capture=true, also spawn a drainer that appends ALL console bytes to an on-disk ring, capturing output emitted while no client is attached (async printk, panic traces); read it with capture_read. Idempotency: errors if one is already live — stop
| Argument | Type | Required | Description |
|---|
| capture | boolean | yes | Also spawn a drainer that records all console bytes to a ring (read with capture_read). Note: while capturing, exec/login read responses via the ring and reliably return command OUTPUT, but matching the bare shell prompt is best-effort (a no-newline prompt flushes to a serial console only on the next write) — prefer a newline-terminated command-emitted sentinel and generous idleMs. The async/unattended capture path (capture_read) is unaffected. |
| captureMaxBytes | number | yes | Rotate when the CURRENT ring file crosses this many bytes (append + rotate-on-restart; the retained .1+current window is up to ~2x this). |
fn session_stop(keepCapture: boolean)
Stop the persistent session holder on the port (SIGTERM the capture drainer if any, then the socat holder, remove the PTY link). Removes the capture ring unless keepCapture=true. Safe to call when none is running.
| Argument | Type | Required | Description |
|---|
| keepCapture | boolean | yes | Keep the on-disk capture ring (and its .1) instead of removing it. |
fn session_status()
Report whether a persistent session holder is running on the port. Recomputes liveness from the holder pid + PTY link (a dead holder reads as not-live and I/O methods fall back to open/close).
fn capture_read(sinceOffset?: number, maxBytes: number)
Return console bytes captured to the ring since an offset and advance the saved cursor. Serial-port-instance-only: the offset thresholds live in the `session` resource, which a serial-cfgmgmt/* instance cannot read. Output `data` is base64 (console bytes are binary). Pages: pass sinceOffset / read nextOffset; maxBytes never returns the whole ring. Bounds the ring by rotating when it crosses captureMaxBytes.
| Argument | Type | Required | Description |
|---|
| sinceOffset? | number | no | Stream offset to read from; defaults to the saved cursor. An explicit value overrides the cursor for re-read/seek. |
| maxBytes | number | yes | Max bytes to return; page the rest with nextOffset. |
Resources
port(infinite)— The configured serial port and its probe capture.
sent(infinite)— Record of a send() write.
captured(infinite)— Output captured by read().
execResult(infinite)— Result of an exec() command/response round-trip.
loginResult(infinite)— Result of a login() attempt (password scrubbed).
session(infinite)— A persistent socat session holder for the port (pid + PTY link).
captureRead(infinite)— Result of a capture_read (base64 bytes + offset cursor).
ubootEnv(infinite)— Result of a uboot_setenv run (vars set, saveenv, and read-back verification).