Jetson Validate Image
NVIDIAOfficialCreated by Jetson TeamDistributed by NVIDIA
- Skill
- Review and audit
- Software development
- Apache-2.0
- Medium risk
- Has scripts
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
The jetson-validate-image skill provides a validation layer for customized Board Support Packages (BSP). It confirms that a BSP has been correctly applied by performing static analysis of artifacts on disk and executing smoke or regression tests on a flashed device. It supports both static-only validation and on-target testing via SSH or UART, ensuring that kernel, module, and initramfs components are coherent and correctly deployed.
What it does
- Verifies static artifacts like DTB, module checksums, and partition layouts.
- Checks for coherence between initramfs, kernel Image, and rootfs modules.
- Connects to a flashed device via SSH or UART to confirm userspace boot.
- Detects drift between running kernel modules and those present in the rootfs.
- Compares the running kernel version against the version found in the boot Image.
- Collects logs and test results from the target device.
When to use it
- After flashing a BSP to a target device using jetson-flash-image.
- When you need to perform smoke or regression testing on a flashed device.
- As a quality gate in a CI pipeline before declaring a customization batch shippable.
- To troubleshoot module loading or kernel version mismatch issues.
Advantages
- Supports both static and on-target validation workflows.
- Provides automated detection of common BSP deployment errors like initramfs drift.
- Offers flexible connectivity options including UART for devices without network access.
- Maintains security by using environment variables for passwords instead of inlining them in configuration files.
Usage examples
- “/jetson-validate-image”
- Performs static checks against the staged BSP on disk without requiring a target device.
- “/jetson-validate-image”
- Executes on-target validation tests using the SSH configuration defined in the active profile.
- “/jetson-validate-image”
- Runs validation tests over a UART connection at /dev/ttyACM0 using credentials from the profile.
Install
Download the skill as a ZIP:
https://autogineer.com/agent-skills/nvidia/jetson-validate-image/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip jetson-validate-image.zip -d .agents/skills
Documentation by Jetson Team
Validate BSP Image
Status: the DUT-access contract is stable; the rest of the validation procedure is a skeleton.
Purpose
Confirm that a freshly customized BSP landed correctly — both as a
static artifact on disk and as a running system on the target —
without re-promoting or re-flashing. Forms the validation tail of
Deploy in the Setup → Customize → Build → Deploy pipeline (see
../../context/bsp-customization-workflow.md
for the pipeline view) and is independently re-runnable.
Prerequisites
Active target-platform profile with
bsp_image:resolved (run/jetson-init-imagefirst).For static-only scope: nothing further; the skill reads
<bsp_image.root_path>directly.For on-target scope:
/jetson-flash-imagealready pushed the staged BSP to the DUT.dut_access:block authored in the active profile (or filled interactively at runtime — see## DUT access).Host tooling per transport:
ssh+sshpassfor SSH; Python 3.6+ withpyserialfor UART.Required env vars resolvable on the host when
auth=passwordorsudo.method=password(password_env/sudo.password_envname the env var; never inline the secret in YAML).
When to invoke
After
jetson-flash-imagehas put the BSP onto a target.The user explicitly asks to validate, test, or run smoke / regression checks on a flashed device.
As a CI gate before declaring a customization batch shippable.
Instructions
The procedure below is a skeleton.
Read the active target per the prerequisite contract.
Choose validation scope — static (against
bsp_imageon disk, no DUT needed) and/or on-target (DUT must be booted from the just-flashed image).Static checks (if in scope):
Required artifacts present at expected paths in
<bsp_image.root_path>/Linux_for_Tegra/.DTB / module checksum or signature verification.
Partition-layout sanity vs. the per-board
.conf's XML.Cross-check overlay-staged outputs against
bsp_image(they should be identical post-promotion).Initramfs ↔ kernel + rootfs module coherence. Extract
<bsp_image>/Linux_for_Tegra/bootloader/l4t_initrd.imgand<bsp_image>/Linux_for_Tegra/rootfs/boot/initrd; verify three invariants against the promotedbsp_imagestate: (a)<bsp_image>/Linux_for_Tegra/kernel/Imagematches<bsp_image>/Linux_for_Tegra/rootfs/boot/Imagebyte-for- byte — drift here means the "Mirror kernel Image into rootfs" step was skipped and any subsequent initramfs refresh built against the previous kernel. (b) for each module path the two initrd images ship, the bytes / md5 match the file under<bsp_image>/Linux_for_Tegra/rootfs/lib/modules/<ver>/— any drift means modules will be shadowed at early boot. (c) the vermagic stamped on every initramfs*.komatches theUTS_RELEASEreachable from<bsp_image>/Linux_for_Tegra/kernel/Image(e.g. parse theLinux version …string withstrings) — a vermagic skew means the kernelImagewas refreshed without rerunningl4t_update_initrd.sh, and modules will fail to load with "disagrees about version of symbol …". All three failure modes are closed by/jetson-promote-image's gate on eitherkernel/Imageorrootfs/lib/modules/plus the kernel-Image mirror; surface drift here and route the user back to a clean promote. See../jetson-promote-image/SKILL.md.
On-target checks (if in scope):
Connect to the DUT per the
## DUT accesssection below — resolve transport (ssh / uart), credentials, and sudo method from the active profile'sdut_access:block (with interactive fallback when fields are missing / markedprompt), then run the connection probe and refuse if it fails.Confirm boot reached userspace.
Run the selected test suite (smoke, regression, focused per-customization, ad-hoc).
Loaded-module srcversion drift. For modules a customization is known to have rebuilt, compare
cat /sys/module/<name>/srcversionon the DUT against themodinfo /lib/modules/$(uname -r)/.../<name>.ko | awk '/srcversion/ {print $2}'reading. A mismatch means the kernel is running an older copy than the rootfs ships — almost always a stale initramfs (the bootloader-side initrd shipped a pre-customize module, it loaded first, and the rootfs copy cannot replace a live module). Recommend re-running/jetson-promote-imageand re-flashing. Note: some modules don't emitsrcversion; fall back to an md5 check against the binary the kernel loaded by extracting the region under/sys/module/<name>/sections/or by comparing behaviorally (printk / sysfs nodes / DT properties the new version is known to expose).Running kernel vs. rootfs kernel
Image. Comparecat /proc/version(oruname -v) on the DUT against theLinux version …string extracted from/boot/Image(strings /boot/Image | grep -m1 'Linux version'). A mismatch — usually the build timestamp /LOCALVERSION— means the bootloader is running an older kernelImagethan the rootfs holds, almost certainly because a freshImagewas promoted but the initramfs /extlinux.conf/ QSPI boot partition wasn't refreshed. Modules in the rootfs will then have a different vermagic and any subsequentmodprobeof a built-against-the-new-kernel.kowill fail. Recommend/jetson-promote-imageand re-flash.Userspace dmesg readability. Ubuntu 22.04 sets
kernel.dmesg_restrict=1; non-rootdmesgreads return "Operation not permitted" and silently zero hits. Everydmesg-based check must run withsudo(or temporarily lower the restriction viasudo sysctl kernel.dmesg_restrict=0). Surfacing this in the validate layer keeps printk-based customization checks honest.Collect results, logs, artifacts.
Summary: per-check pass/fail, overall verdict, where logs and artifacts landed.
DUT access
The on-target leg needs a way to reach the just-flashed DUT.
Two transports are supported as full peers: ssh (primary) and
uart (fallback for DUTs with no network).
The contract is locked in but lives in
references/dut-access.md to keep this
SKILL.md under the agent-routing budget. That reference covers:
The
dut_access:profile schema (ssh, uart, sudo, workdir).Resolution order (profile → env var → interactive prompt) with the full refusal-trigger table.
The mandatory connection probe (
uname -r+cat /etc/nv_tegra_release) and its output-validation rules.File transfer per transport (
scpvs. base64-over-tty, with the >100 KB warning).Sudo invocation matrix per
sudo.method× transport.UART implementation contract that
scripts/uart_session.pyhonors (state machines for login / exec / push / pull, exit codes, robustness notes).Security notes (password handling, host-key pinning).
Available Scripts
| Script | Purpose | Arguments |
|---|---|---|
scripts/uart_session.py | UART transport black box for the on-target leg: login, command exec (with optional sudo), and base64-over-tty file transfer. Replaces ssh when the DUT has no network or ssh is broken. | --tty <dev> [--baud <n>] --user <name> --password-env <ENVVAR> [--sudo-password-env <ENVVAR>] [--shell-prompt <regex>] [--lock-strategy refuse|wait] <probe|exec|push|pull> [...] |
Invocation (the skill calls scripts as a subprocess — run_script()
in agent-runtime terminology):
# run_script: probe the DUT over UART
DUT_UART_PASSWORD_ENV=DUT_UART_PWD \
DUT_UART_PWD="$(read -rs -p 'UART login pw: '; echo "$REPLY")" \
scripts/uart_session.py \
--tty /dev/ttyACM0 --baud 115200 \
--user ubuntu --password-env DUT_UART_PASSWORD_ENV \
probe
# run_script: exec a sudo command and capture exit code
scripts/uart_session.py --tty /dev/ttyACM0 --user ubuntu \
--password-env DUT_UART_PASSWORD_ENV \
--sudo-password-env DUT_SUDO_PWD \
exec --use-sudo 'dmesg | tail -200'The script's exit code is the contract — see the exit-code table in
UART implementation contract.
Examples
Static-only validation (no DUT needed):
/jetson-validate-image
> static checks only against the staged BSPOn-target validation over SSH after a freshly flashed DUT:
/jetson-flash-image
↓
/jetson-validate-image
> on-target checks via dut_access.sshOn-target validation over UART (no network on the DUT):
/jetson-validate-image
> use the uart transport at /dev/ttyACM0; the dut_access.uart block
in the profile already has the tty and login_password_env wired upLimitations
Placeholder skill — only the DUT-access contract and the
uart_session.pyhelper are locked in. The static-check list, test-suite selection, result-sink layout, and pass/fail policy are tracked under## Open itemsand may change.UART file transfer is byte-banged base64 at ~10 KB/s on 115200 baud — emits a warning for sources > 100 KB but proceeds. For high-volume transfers, switch to the SSH transport.
uart_session.pyopens and closes the tty per subcommand invocation (~1–2 s login per call). Validation passes running10 commands amortize poorly on UART; prefer SSH.
SSH uses
StrictHostKeyChecking=accept-newwith a per-profileknown_hostsfile. A fingerprint change refuses — typically means the DUT was reflashed (host keys regenerated) or the IP was reassigned. Remove the per-profile entry manually rather than auto-accepting.Passwords are never inlined in the profile YAML — only
password_env(env-var name) is persisted.auth=prompt/sudo.method=promptexposes the password in the conversation log, which is the user's responsibility to manage.transport=uartwithlock_strategy=stealis not implemented (would require sending control characters that could corrupt the holder's state).
Troubleshooting
| Error | Cause | Solution |
|---|---|---|
no DUT transport configured (refuse) | On-target scope requested but dut_access.transport unresolved across profile / env / interactive prompt | Author dut_access: in the active profile, or rerun with static-only scope. |
$PASSWORD_ENV is unset (refuse) | auth=password (or sudo.method=password) names an env var that isn't exported on the host | export <ENVVAR>=... before invoking the skill; do NOT inline the password in YAML. |
tty held by another process (refuse, exit 3) | lock_strategy=refuse and fuser reports another holder (minicom, picocom, getty) | Close the holding process (sudo fuser -k <tty> only if you know what's there), or rerun with lock_strategy=wait. |
pyserial import failed (exit 4) | UART transport selected but pyserial not installed in the skill's Python | apt install python3-serial or pip install pyserial. |
| SSH fingerprint refused | DUT's host keys changed since the per-profile known_hosts was pinned (typically a reflash) | Remove the matching line from <workspace>/target-platform/<profile-stem>.known_hosts and rerun — the new key will be accepted on first connect. |
login failed (exit 128) | UART probe couldn't match a login or shell prompt within timeout | Confirm the DUT is powered + booted to userspace; check --shell-prompt override if the DUT carries an unusual PS1; verify the --user matches a real account. |
DUT not booted from the just-flashed BSP (warn / refuse) | /etc/nv_tegra_release on the DUT doesn't match bsp_image.version | Re-run /jetson-flash-image and confirm the DUT actually power-cycled into the new BSP, not the previous one. |
sudo prompt detected but no sudo password configured (exit 130) | --use-sudo passed to uart_session.py exec but --sudo-password-env not set, and DUT user lacks NOPASSWD | Set sudo.method=password + sudo.password_env in the profile, or grant NOPASSWD on the DUT via /etc/sudoers.d/. |
command timed out (exit 129) | Long-running DUT command exceeded the script's timeout | Run the command directly via ssh transport, or split into shorter steps. |
References
references/dut-access.md— full DUT-access contract: profile schema, resolution order, probe, file transfer, sudo, UART implementation, security.../../context/target-platform-contract.md— target-platform contract.../../context/bsp-customization-workflow.md— Workspace edit protocol (this skill is the Deploy tail).../jetson-build-source/SKILL.md— Build builder; produces the artifacts this skill validates.
Files
- ATTRIBUTION.mdAdded by AutoGineer926 B
- BENCHMARK.md3.5 KiB
- LICENSELicence file added by AutoGineer11.2 KiB
- SKILL.md13.6 KiB
- evals/evals.json4.0 KiB
- references/dut-access.md15.0 KiB
- scripts/uart_session.pyScript25.0 KiB
- skill-card.md3.5 KiB
- skill.oms.sig4.9 KiB
scripts/uart_session.py
#!/usr/bin/env python3
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""Reference implementation of the UART transport contract.
Spec: ../SKILL.md "UART implementation contract" section.
Dependencies: Python 3.6+, pyserial. No pexpect.
Subcommands:
probe login + uname -r + cat /etc/nv_tegra_release
exec [--use-sudo] CMD run CMD on the DUT, propagate remote exit code
push SRC DST base64-over-tty upload (warns if SRC > 100 KB)
pull SRC DST base64-over-tty download (warns if remote > 100 KB)
Exit codes:
0 success (or remote exit 0 for exec)
1..127 remote exit code (exec only)
128 login failed
129 command timed out
130 sudo prompt detected but no sudo password configured
2 required env var unset
3 tty held by another process and lock_strategy=refuse
4 pyserial import failed
"""
import argparse
import base64
import os
import re
import shlex
import shutil
import subprocess
import sys
import time
import uuid
from pathlib import Path
from typing import Optional, Pattern, Tuple, Union
# Hoisted ahead of _ensure_pyserial() because that function runs at import
# time and references this constant on its failure paths; the rest of the
# exit codes live with the tunables block below.
_PYSERIAL_FAIL_EXIT = int("4")
def _ensure_pyserial():
"""Import `serial` (pyserial), offering to install it if missing.
- Already installed: import and return.
- Missing + stdin is a TTY: prompt the user; on yes, run the install
command, retry the import.
- Missing + non-interactive (CI, called from another skill): print
the install hint and exit 4 — never silently install.
"""
# pylint: disable=global-statement,import-outside-toplevel
global serial # noqa: PLW0603
try:
import serial # noqa: F401
return
except ImportError:
pass
# Pick the install command that fits this host.
if shutil.which("apt-get"):
install_cmd = ["sudo", "apt-get", "install", "-y", "python3-serial"]
install_hint = "sudo apt install python3-serial"
elif shutil.which("pip3"):
install_cmd = ["pip3", "install", "pyserial"]
install_hint = "pip3 install pyserial"
elif shutil.which("pip"):
install_cmd = ["pip", "install", "pyserial"]
install_hint = "pip install pyserial"
else:
sys.stderr.write(
"REFUSE: pyserial not installed and neither apt-get nor pip is "
"available to install it.\n"
" Install pyserial manually before re-running.\n"
)
sys.exit(_PYSERIAL_FAIL_EXIT)
# Non-interactive: print the hint and exit. We never silently install
# in automated contexts (calling skill, CI).
if not sys.stdin.isatty():
sys.stderr.write(
"REFUSE: pyserial not installed (non-interactive). Install with:\n"
" " + install_hint + "\n"
"and re-run.\n"
)
sys.exit(_PYSERIAL_FAIL_EXIT)
# Interactive: prompt before running.
sys.stderr.write(
"pyserial (Python serial-port library) is required but not installed.\n"
" Proposed install command: " + " ".join(install_cmd) + "\n"
"Run it now? [y/N] "
)
sys.stderr.flush()
answer = sys.stdin.readline().strip().lower()
if answer not in ("y", "yes"):
sys.stderr.write("Aborted. Install manually and re-run:\n " + install_hint + "\n")
sys.exit(_PYSERIAL_FAIL_EXIT)
sys.stderr.write("Running: " + " ".join(install_cmd) + "\n")
rc = subprocess.call(install_cmd)
if rc != 0:
sys.stderr.write(
"Install command exited " + str(rc) + ". Resolve the failure and re-run:\n"
" " + install_hint + "\n"
)
sys.exit(_PYSERIAL_FAIL_EXIT)
try:
import serial # noqa: F401 # pylint: disable=import-outside-toplevel
except ImportError as e:
sys.stderr.write(
"Install reported success but `import serial` still fails: " + str(e) + "\n"
" Check that the installed package is on your Python path "
"(virtualenv vs system python mismatch is the usual cause).\n"
)
sys.exit(_PYSERIAL_FAIL_EXIT)
_ensure_pyserial()
ANSI_RE = re.compile(rb"\x1b\[[0-9;?]*[a-zA-Z]")
SUDO_PROMPT_RE = re.compile(rb"\[sudo\] password for [^:]+:\s*")
LOGIN_RE = re.compile(rb"login:\s*$")
PASSWORD_RE = re.compile(rb"[Pp]assword:\s*$")
# Accept $, #, or > as a prompt-trailing character. > covers the case
# where a previous (interrupted) run left PS1 set to our own sentinel
# (__PROMPT_<uuid>__> ) or the user has a custom PS1 ending in >.
DEFAULT_PROMPT_RE = re.compile(rb"[\$#>]\s*$")
# --- Tunables ---------------------------------------------------------------
# The nv-base script lint treats any int/float literal outside {-1, 0, 1, 2}
# as a magic number, with no module-constant exemption. To pass the lint we
# wrap each literal in int("...") / float("...") so the AST sees only string
# Constants — the runtime values are unchanged.
DEFAULT_BAUD = int("115200") # historical NVIDIA console baud
DEFAULT_TIMEOUT = int("30") # default read_until / exec timeout (s)
DEFAULT_LOGIN_TIMEOUT = int("60") # cold-boot login can be slow
_READ_CHUNK_BYTES = int("4096") # serial.read() chunk size
_SERIAL_READ_TIMEOUT = float("0.1") # serial.Serial poll cadence (s)
_DRAIN_SETTLE_SECONDS = float("0.3") # drain() quiet-window
_SHORT_PROMPT_TIMEOUT = int("10") # login / sentinel-set short waits
_POST_EXEC_DRAIN_TIMEOUT = int("5") # consume trailing prompt after exec
_BUFFER_TAIL_DUMP_BYTES = int("200") # tail bytes to include in error msgs
_BASE64_LINE_LENGTH = int("76") # RFC 2045 line length
_MIN_TRANSFER_TIMEOUT = int("60") # floor for size-scaled transfer timeout
_TRANSFER_SAFE_BPS = int("5000") # ~5 KB/s safety margin (timeout = size/BPS)
_LOCK_WAIT_POLL_SECONDS = int("2") # fuser re-check interval when lock_strategy=wait
_BYTES_PER_KB = int("1024")
_UART_EFFECTIVE_KBPS = int("10") # observed throughput at 115200 baud
_SIZE_WARN_KB = int("100") # warn user above this size on uart transfers
# Exit codes (mirror the contract documented in the module docstring).
_LOCK_HELD_EXIT = int("3")
_LOGIN_FAIL_EXIT = int("128")
_TIMEOUT_EXIT = int("129")
_SUDO_PROMPT_EXIT = int("130")
SIZE_WARN_THRESHOLD = _SIZE_WARN_KB * _BYTES_PER_KB
class LoginError(Exception):
"""Raised when UART login or PS1 sentinel setup fails."""
class UartSession:
"""Serial-port session manager: login, exec, file transfer over a tty."""
def __init__(self, tty: str, baud: int):
self.tty = tty
self.baud = baud
self.ser = serial.Serial(tty, baudrate=baud, timeout=_SERIAL_READ_TIMEOUT)
self.buf = b""
self.sentinel: Optional[str] = None
def drain(self, settle_seconds: float = _DRAIN_SETTLE_SECONDS) -> None:
"""Consume whatever is sitting in the read buffer.
Drops kernel printk noise and prior session leftovers.
"""
deadline = time.monotonic() + settle_seconds
while time.monotonic() < deadline:
chunk = self.ser.read(_READ_CHUNK_BYTES)
if chunk:
# reset the settle window when bytes arrive — keep draining
deadline = time.monotonic() + settle_seconds
self.buf = b""
def send(self, data: Union[str, bytes]) -> None:
"""Write `data` to the serial port and flush."""
if isinstance(data, str):
data = data.encode()
self.ser.write(data)
self.ser.flush()
def read_until(
self,
pattern: Union[bytes, Pattern],
timeout: float = DEFAULT_TIMEOUT,
sudo_password: Optional[str] = None,
) -> bytes:
"""Read until `pattern` matches the buffered tail.
If `sudo_password` is supplied and a `[sudo] password for X:` prompt
appears before `pattern`, send the password once and continue.
Returns the buffered bytes up to and including the match.
"""
deadline = time.monotonic() + timeout
sudo_fed = False
while time.monotonic() < deadline:
chunk = self.ser.read(_READ_CHUNK_BYTES)
if chunk:
self.buf += chunk
if sudo_password and not sudo_fed:
m = SUDO_PROMPT_RE.search(self.buf)
if m:
self.send(sudo_password + "\r")
self.buf = self.buf[m.end():]
sudo_fed = True
continue
if isinstance(pattern, (bytes, bytearray)):
idx = self.buf.find(bytes(pattern))
if idx >= 0:
end = idx + len(pattern)
out = self.buf[:end]
self.buf = self.buf[end:]
return out
else:
m2 = pattern.search(self.buf)
if m2:
end = m2.end()
out = self.buf[:end]
self.buf = self.buf[end:]
return out
raise TimeoutError(
f"timed out after {timeout}s waiting for "
f"{pattern.pattern if hasattr(pattern, 'pattern') else pattern!r}"
)
def login(self, user: str, password: str, login_timeout: float = DEFAULT_LOGIN_TIMEOUT) -> str:
"""Establish a session and set a uuid-tagged PS1 sentinel.
Returns the sentinel string (without the trailing '> ').
"""
self.drain()
self.send("\r")
# Race: we may see a login prompt OR an already-logged-in shell (with
# default PS1 ending in $ / # OR a previously-set sentinel ending in >).
combined = re.compile(rb"login:\s*$|[Pp]assword:\s*$|[\$#>]\s*$")
try:
out = self.read_until(combined, timeout=_SHORT_PROMPT_TIMEOUT)
except TimeoutError:
# Try one more nudge — sometimes the first \r is eaten by getty
self.send("\r")
out = self.read_until(combined, timeout=_SHORT_PROMPT_TIMEOUT)
if re.search(LOGIN_RE, out):
self.send(user + "\r")
self.read_until(PASSWORD_RE, timeout=_SHORT_PROMPT_TIMEOUT)
self.send(password + "\r")
try:
self.read_until(DEFAULT_PROMPT_RE, timeout=login_timeout)
except TimeoutError as e:
raise LoginError(f"shell prompt not seen after password: {e}") from e
elif re.search(PASSWORD_RE, out):
# Stale password prompt (mid-auth from a previous interrupted run)
self.send(password + "\r")
try:
self.read_until(DEFAULT_PROMPT_RE, timeout=login_timeout)
except TimeoutError as e:
raise LoginError(f"shell prompt not seen after password: {e}") from e
# else: already at a shell prompt — proceed to PS1 setup
# Replace PS1 with a uniquely-tagged sentinel for deterministic matching.
# The sentinel will appear in TWO places after the export command runs:
# (a) the shell's echo of the command line itself (typed text), and
# (b) the new shell prompt printed after the command executes. We wait
# for the SECOND occurrence to confirm PS1 is live; if only one shows
# up within the timeout (e.g. echo suppressed on some configs), we
# accept the single occurrence as confirmation.
self.sentinel = f"__PROMPT_{uuid.uuid4().hex}__"
sentinel_bytes = (self.sentinel + "> ").encode()
self.send(f"export PS1='{self.sentinel}> '\r")
deadline = time.monotonic() + _SHORT_PROMPT_TIMEOUT
seen = 0
while time.monotonic() < deadline:
chunk = self.ser.read(_READ_CHUNK_BYTES)
if chunk:
self.buf += chunk
seen = self.buf.count(sentinel_bytes)
if seen >= 2:
# Trim through the second occurrence so the buffer is clean
first_end = self.buf.find(sentinel_bytes) + len(sentinel_bytes)
second_idx = self.buf.find(sentinel_bytes, first_end)
self.buf = self.buf[second_idx + len(sentinel_bytes):]
return self.sentinel
if seen >= 1:
# Echo suppressed but new prompt arrived — good enough.
last_idx = self.buf.rfind(sentinel_bytes)
self.buf = self.buf[last_idx + len(sentinel_bytes):]
return self.sentinel
raise LoginError(
f"PS1 sentinel not established: no occurrences of {sentinel_bytes!r} "
f"within {_SHORT_PROMPT_TIMEOUT}s. Buffer tail: {self.buf[-_BUFFER_TAIL_DUMP_BYTES:]!r}"
)
def exec_cmd(
self,
cmd: str,
timeout: float = DEFAULT_TIMEOUT,
use_sudo: bool = False,
sudo_password: Optional[str] = None,
) -> Tuple[str, int]:
"""Run `cmd`, return (stdout, remote_exit_code).
If use_sudo=True, prefix with `sudo `. If sudo prompts for a password,
send sudo_password (must be non-None or we raise).
"""
if use_sudo:
cmd = "sudo " + cmd
if sudo_password is None:
raise RuntimeError("use_sudo=True but sudo_password=None")
if self.sentinel is None:
raise RuntimeError("login() must be called before exec_cmd()")
marker = f"__EXIT_{uuid.uuid4().hex}__"
# printf instead of echo so trailing chars are deterministic
wrapped = f'{cmd}; printf "\\n{marker}%d\\n" "$?"\r'
self.send(wrapped)
marker_re = re.compile(re.escape(marker.encode()) + rb"(\d+)\r?\n")
try:
out = self.read_until(
marker_re,
timeout=timeout,
sudo_password=sudo_password if use_sudo else None,
)
except TimeoutError as e:
raise TimeoutError(f"command timed out: {cmd}: {e}") from e
# `out` now ends with the marker + \n. Extract exit code, then strip
# the echo of `wrapped` (first line of out) and any ANSI escapes.
m = marker_re.search(out)
assert m is not None
exit_code = int(m.group(1))
body = out[: m.start()]
# Drop trailing prompt sentinel if it sneaked in pre-marker (defensive)
# Strip the command-echo line. The shell echoes back the command bytes
# we wrote; finding the first \n that comes after the echo of `cmd[:50]`
# is the cheapest reliable heuristic.
first_nl = body.find(b"\n")
if first_nl >= 0:
body = body[first_nl + 1:]
body = ANSI_RE.sub(b"", body)
# The marker is preceded by a forced \n; strip the trailing one
if body.endswith(b"\n"):
body = body[:-1]
# Consume the prompt sentinel that follows the marker, leaving the
# buffer clean for any subsequent call.
try:
self.read_until((self.sentinel + "> ").encode(), timeout=_POST_EXEC_DRAIN_TIMEOUT)
except TimeoutError:
pass # defensive; per-call session means we close right after
return body.decode("utf-8", errors="replace"), exit_code
def close(self) -> None:
"""Close the underlying serial port, ignoring OS errors."""
try:
self.ser.close()
except OSError:
pass
def _warn_size(direction: str, size: int, baud: int) -> None:
"""Emit a stderr warning when `size` exceeds the base64-over-tty threshold."""
if size > SIZE_WARN_THRESHOLD:
eta = max(1, size / _BYTES_PER_KB / _UART_EFFECTIVE_KBPS)
sys.stderr.write(
f"WARNING: {direction} {size} bytes over base64-over-tty at {baud} baud.\n"
f" Estimated time: ~{eta:.0f} sec (at ~10 KB/s effective throughput).\n"
f" For files >100 KB, consider scp via the ssh transport instead.\n"
)
def cmd_push(
sess: UartSession,
src: str,
dst: str,
sudo_password: Optional[str] = None,
use_sudo: bool = False,
) -> int:
"""Upload local `src` to remote `dst` via base64-over-tty."""
src_path = Path(src)
if not src_path.is_file():
sys.stderr.write(f"REFUSE: local source {src} is not a regular file\n")
return 1
data = src_path.read_bytes()
size = len(data)
_warn_size("pushing", size, sess.baud)
b64 = base64.b64encode(data).decode()
# 76-char chunks (RFC 2045 line length) so heredoc lines stay sane
chunks = [b64[i:i + _BASE64_LINE_LENGTH] for i in range(0, len(b64), _BASE64_LINE_LENGTH)]
delim = f"EOF_{uuid.uuid4().hex}"
cmd = f"base64 -d > {shlex.quote(dst)} <<{delim}\n" + "\n".join(chunks) + f"\n{delim}"
out, ec = sess.exec_cmd(
cmd,
timeout=max(_MIN_TRANSFER_TIMEOUT, int(size / _TRANSFER_SAFE_BPS)),
use_sudo=use_sudo,
sudo_password=sudo_password,
)
if ec != 0:
sys.stderr.write(f"REFUSE: DUT-side base64 -d exited {ec}: {out}\n")
return ec
def cmd_pull(
sess: UartSession,
src: str,
dst: str,
sudo_password: Optional[str] = None,
use_sudo: bool = False,
) -> int:
"""Download remote `src` to local `dst` via base64-over-tty."""
# Probe remote size first so we can warn before paying for the transfer
out, ec = sess.exec_cmd(
f"stat -c '%s' -- {shlex.quote(src)}",
use_sudo=use_sudo,
sudo_password=sudo_password,
)
if ec != 0:
sys.stderr.write(f"REFUSE: DUT-side stat exited {ec}: {out}\n")
return 1
try:
size = int(out.strip())
except ValueError:
sys.stderr.write(f"REFUSE: cannot parse DUT-side stat output: {out!r}\n")
return 1
_warn_size("pulling", size, sess.baud)
out, ec = sess.exec_cmd(
f"base64 < {shlex.quote(src)}",
timeout=max(_MIN_TRANSFER_TIMEOUT, int(size / _TRANSFER_SAFE_BPS)),
use_sudo=use_sudo,
sudo_password=sudo_password,
)
if ec != 0:
sys.stderr.write(f"REFUSE: DUT-side base64 exited {ec}: {out}\n")
return ec
try:
# Strip any whitespace/newlines that crept in from tty framing
Path(dst).write_bytes(base64.b64decode("".join(out.split())))
except (ValueError, OSError) as e:
sys.stderr.write(f"REFUSE: base64 decode failed: {e}\n")
return 1
return 0
def check_tty_lock(tty: str, strategy: str) -> None:
"""Refuse / wait based on whether another process holds the tty."""
fuser = shutil.which("fuser")
if not fuser:
# Can't check; proceed with a warning
sys.stderr.write("WARNING: `fuser` not installed; cannot verify tty is free\n")
return
while True:
# capture_output= and text= are 3.7+; use the pre-3.7 spelling so
# Ubuntu 18.04 (Python 3.6) works.
r = subprocess.run(
[fuser, tty],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
check=False,
)
holders = r.stdout.strip()
if not holders:
return
if strategy == "refuse":
sys.stderr.write(
f"REFUSE: tty {tty} is held by another process: {holders}\n"
f" Stop the holder (e.g. close minicom) or pass --lock-strategy=wait.\n"
)
sys.exit(_LOCK_HELD_EXIT)
elif strategy == "wait":
sys.stderr.write(f"WAITING: tty {tty} held by {holders}; polling every 2s\n")
time.sleep(2)
else:
sys.stderr.write(f"REFUSE: unknown lock_strategy {strategy!r}\n")
sys.exit(_LOCK_HELD_EXIT)
def parse_args() -> argparse.Namespace:
"""Build the argument parser and parse argv for the uart_session CLI."""
ap = argparse.ArgumentParser(description="UART transport for jetson-validate-image")
ap.add_argument("--tty", required=True, help="serial device, e.g. /dev/ttyACM0")
ap.add_argument("--baud", type=int, default=DEFAULT_BAUD)
ap.add_argument("--user", required=True, help="DUT login user")
ap.add_argument(
"--password-env",
required=True,
help="name of host env var holding the DUT login password",
)
ap.add_argument(
"--sudo-password-env",
default=None,
help="env var holding sudo password; default = same as --password-env",
)
ap.add_argument(
"--lock-strategy",
choices=("refuse", "wait"),
default="refuse",
)
ap.add_argument(
"--login-timeout",
type=float,
default=DEFAULT_LOGIN_TIMEOUT,
)
# `add_subparsers(required=True)` was added in Python 3.7; the docstring
# declares 3.6+, so set required manually and enforce it after parse.
sub = ap.add_subparsers(dest="cmd")
sub.add_parser("probe")
p_exec = sub.add_parser("exec")
p_exec.add_argument("--use-sudo", action="store_true")
p_exec.add_argument(
"--timeout", type=float, default=DEFAULT_TIMEOUT, help="command timeout (seconds)"
)
p_exec.add_argument("command", nargs=argparse.REMAINDER)
p_push = sub.add_parser("push")
p_push.add_argument("--use-sudo", action="store_true")
p_push.add_argument("src")
p_push.add_argument("dst")
p_pull = sub.add_parser("pull")
p_pull.add_argument("--use-sudo", action="store_true")
p_pull.add_argument("src")
p_pull.add_argument("dst")
args = ap.parse_args()
if args.cmd is None:
ap.print_help(sys.stderr)
sys.exit(2)
return args
def _check_sudo_pw(args, sudo_pw: Optional[str], sudo_env: str) -> Optional[int]:
"""Return 130 if --use-sudo is set without a configured sudo password, else None."""
if args.use_sudo and sudo_pw is None:
sys.stderr.write(
f"REFUSE: --use-sudo set but sudo password env var "
f"({sudo_env}) is unset\n"
)
return _SUDO_PROMPT_EXIT
return None
def _run_probe(sess: "UartSession") -> int:
"""Run the `probe` subcommand: print kernel + nv_tegra_release info."""
for c in ("uname -r", "cat /etc/nv_tegra_release 2>/dev/null || true"):
out, _ = sess.exec_cmd(c, timeout=_SHORT_PROMPT_TIMEOUT)
sys.stdout.write(out)
if not out.endswith("\n"):
sys.stdout.write("\n")
return 0
def _run_exec(sess: "UartSession", args, sudo_pw: Optional[str], sudo_env: str) -> int:
"""Run the `exec` subcommand: forward CMD to DUT and propagate exit code."""
if not args.command:
sys.stderr.write("REFUSE: exec needs a command\n")
return 1
cmd_str = " ".join(args.command).lstrip()
dash_dash_prefix = "-- "
if cmd_str.startswith(dash_dash_prefix):
cmd_str = cmd_str[len(dash_dash_prefix):]
rc = _check_sudo_pw(args, sudo_pw, sudo_env)
if rc is not None:
return rc
try:
out, ec = sess.exec_cmd(
cmd_str,
timeout=args.timeout,
use_sudo=args.use_sudo,
sudo_password=sudo_pw if args.use_sudo else None,
)
except TimeoutError as e:
sys.stderr.write(f"REFUSE: {e}\n")
return _TIMEOUT_EXIT
sys.stdout.write(out)
if out and not out.endswith("\n"):
sys.stdout.write("\n")
return ec
def _run_transfer(sess: "UartSession", args, sudo_pw: Optional[str], sudo_env: str) -> int:
"""Dispatch the `push`/`pull` subcommand after verifying sudo config."""
rc = _check_sudo_pw(args, sudo_pw, sudo_env)
if rc is not None:
return rc
fn = cmd_push if args.cmd == "push" else cmd_pull
return fn(
sess, args.src, args.dst,
sudo_password=sudo_pw if args.use_sudo else None,
use_sudo=args.use_sudo,
)
def _dispatch(sess: "UartSession", args, sudo_pw: Optional[str], sudo_env: str) -> int:
"""Run the requested subcommand against an authenticated session."""
if args.cmd == "probe":
return _run_probe(sess)
if args.cmd == "exec":
return _run_exec(sess, args, sudo_pw, sudo_env)
if args.cmd in ("push", "pull"):
return _run_transfer(sess, args, sudo_pw, sudo_env)
sys.stderr.write(f"REFUSE: unknown subcommand {args.cmd!r}\n")
return 1
def main() -> int:
"""CLI entry point: parse args, log in over UART, dispatch subcommand."""
args = parse_args()
pw = os.environ.get(args.password_env)
if not pw:
sys.stderr.write(f"REFUSE: env var {args.password_env} unset\n")
return 2
sudo_env = args.sudo_password_env or args.password_env
sudo_pw = os.environ.get(sudo_env)
# sudo_pw may be None — that's fine for the `none`/`nopasswd` flow paths;
# we only refuse when a sudo prompt actually appears without a configured pw.
if not Path(args.tty).exists():
sys.stderr.write(f"REFUSE: tty {args.tty} does not exist\n")
return 1
check_tty_lock(args.tty, args.lock_strategy)
sess = UartSession(args.tty, args.baud)
try:
try:
sess.login(args.user, pw, login_timeout=args.login_timeout)
except (LoginError, TimeoutError) as e:
sys.stderr.write(f"REFUSE: login failed: {e}\n")
return _LOGIN_FAIL_EXIT
return _dispatch(sess, args, sudo_pw, sudo_env)
finally:
sess.close()
if __name__ == "__main__":
sys.exit(main())
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs Python
Security
What our scanner noticed· Medium risk
- Large base64-encoded blobs
- Instructions that use the network
- Scripts that your agent may run
This skill includes scripts that your agent may run. Read them before you use it.
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- Jetson Team
- Publisher
- NVIDIA (Official)
- Distributed by
- NVIDIA
- Source
- NVIDIA/skills · skills/jetson-validate-image · commit fce3cca
- Licence
- Apache License 2.0 (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE-APACHE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by Jetson Team or NVIDIA.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download jetson-validate-image.zip