Skip to content

Headset interface reference

TL;DR. Every name a headset may use in headset interface 2.0, overpressure.api.v2: its modules, and in each its functions and classes with their signatures, dataclass fields and constants, each with the first paragraph of its documentation. A headset imports only these (from overpressure.api.v2 import REPO, qualcomm, from overpressure.api.v2.headset import Headset, Step). The rules (a minor only adds, a break makes a new major) are in the headset interface, what each minor added in what a headset may use: a headset made for an older minor uses only what that minor had. The source links lead to the code, which says more than its first paragraph.

python scripts/api-reference.py writes this file from the code; a test fails when it is out of date.

Modules

Module What it is
overpressure.api.v2 Headset interface 2 (overpressure.headset.SUPPORTED names its newest minor): what a headset may use.
acceptance the acceptance runner's scaffolding
android adb and fastboot, fail-closed, each command naming the serial
assets a headset's assets out of its stock folder
avb Android Verified Boot footers and vbmeta
backup verified backups, their archives, and the window's words for them
bootimg Android boot images
compress the compressions images use
contract the headset runtime's contract on the PC's side
cpio cpio archives (ramdisks)
devcli a headset's development loop on the command line
devicecli a Qualcomm Android headset's device commands
doctor dependency checks
edl a Qualcomm Android headset's adb and EDL steps
evidence runs on the headset that record every step
ext4 ext4 images, read without mounting
fastboot flashing through fastboot, the RAM boot
fat FAT images, read without mounting
headset the headset, its steps, workflows and finished page
install the installer: stages, tasks, asks and the context a task runs in
kernelimage a boot image with another kernel
kernelinfo a kernel image's version and configuration
kernelpin a headset's pin of overpressure/linux and its contracts
localconfig a headset's settings in .env
look a look at a headset on USB without changing it
lp dynamic partitions: super's logical partitions, a new layout's metadata
ota a vendor's OTA: boot images and partitions, pinned members
pacman pacman's repositories on any host
payload Android A/B OTA payloads
power this computer's power, and the headset's battery before writes
prefetch a headset's downloads before an install
process bounded waits and running tools
progress progress lines
qualcomm Qualcomm: SoC ID, EDL, partition maps, verified writes
recovery a headset's own systems and USB modes, the executor's side
recovery_ramdisk an Alpine recovery in a stock boot image
roles the building blocks of a headset's workflows
runner a step's command line
ssh SSH with the project's key
storage the read-only storage policy
tools the pinned host tools
usbaccess USB access on Linux and Windows, a headset's USB modes
usblink a headset's USB network link on a Linux computer
web HTTPS downloads
wifi the owner's Wi-Fi for a headset's installed system
windows_ncm Windows' USB network link

overpressure.api.v2

The interface's package itself (source).

  • REPO: The data root: .env, the private, ignored folders (out/, cache/, assets/, backup/) and the headsets in devices/. In a checkout and a release's folder the same as CODE.

acceptance

overpressure.api.v2.acceptance: the acceptance runner's scaffolding (source).

  • MAX_HEADER_VERSION = 2: The boot image header versions whose fields the stock and test images are compared by.
  • IDENTITY_COMMANDS: What the maker's system shows to identify the headset, one line each.
  • RECOVERY_PROOF = (contract.TEST_RUN, "/sys/devices/soc0/serial_number"): What the recovery shows to prove it is this test run on this headset: the run ID and the SoC serial.
  • PROOF_COMMAND = "; ".join(f"cat {path}" for path in RECOVERY_PROOF)
  • prepare_image = recovery_ramdisk.prepare_image
  • proven(output: str, run_id: str, chip_id: int) -> bool: Tell whether the recovery's answer to PROOF_COMMAND is run @p run_id's on the headset with SoC ID @p chip_id.
  • validate_preflight(output: str) -> None: Refuse a preflight output without exactly one summary of only passed checks.
  • validate_report(data: bytes, run_id: str) -> None: Refuse a hardware report that lacks a member, or comes from another boot.
  • build_id(manifest: Path) -> str | None: Return a build's identity: its manifest's SHA-256 (the image's usr/share/PREFIX/userspace-build.sha256).
  • userspace_state(manifest: Path) -> dict: Return a build's identity and the features its manifest says the image contains.
  • prepare_restore_image(backup: Path, folder: Path, serial: str, identity: dict, image: Path) -> dict: Copy the verified stock boot image into the results, after checking the test image against it.
  • system_counted_read_only(mounts: str, storage: str, system: str) -> tuple[str, str]: Return /proc/mounts and the block inventory with the writable system image counted read-only.
  • class AcceptanceRunner(evidence.Runner): The bounded acceptance run on one headset: every step recorded, the headset always brought back.
  • FINGERPRINT: ClassVar[str] = r"\S+": The maker's system's fingerprint of this headset (a regular expression), its name and the headset's in words.
  • STOCK: ClassVar[str] = "the stock system"
  • NAME: ClassVar[str] = "the headset this runner checks"
  • PREFIX: ClassVar[str] = "overpressure": The headset's image prefix, the preflight (overpressure's) and the headset's hook for it (its own checks and facts: headset_checks, headset_facts), its status page's mark and the recovery's restart program.
  • PREFLIGHT_SCRIPT: ClassVar[Path] = CODE / "overpressure" / "preflight-device.sh"
  • PREFLIGHT_HOOK: ClassVar[Path | None] = None
  • STATUS_MARKER: ClassVar[bytes] = b"overpressure"
  • REBOOT: ClassVar[str] = "reboot"
  • authorization(self, chip_id: int) -> list[str]: Return the bootloader's per-session authorization for a write (fastboot's words); none by default.
  • adb(self, *words: str, timeout: float = 30) -> str: Run adb on the selected headset; return its output.
  • fastboot(self, *words: str, timeout: float = 30) -> str: Run fastboot on the selected headset; return its output.
  • ssh(self, command: str, timeout: float = 30) -> str: Run @p command on the recovery with this run's key, host keys pinned on first use; return its output.
  • identity(self, timeout: float = 30) -> dict[str, Any]: Return the identity of the booted the stock system: its fingerprint, OEM state and SoC ID.
  • preflight(self, rootfs: Path) -> None: Run the recovery root's programs on the stock system from adb shell, without root; remove them after.
  • prepare(self) -> None: Make this run's SSH key and configuration and its test boot image.
  • stock_identity(self) -> dict[str, Any]: Return the headset's identity from before the test, which every write is checked against.
  • prepare_restore(self) -> None: Pin the stock boot image and record the commands that flash it back by hand.
  • check_restore_image(self) -> None: Refuse to flash anything once the pinned stock boot image changed.
  • check_fastboot_unlock(self) -> None: Refuse a locked bootloader, or one whose state is unknown.
  • authorize_flash(self) -> None: Check the restore image, the unlock and the boot partition; then send the session's authorization.
  • enter_fastboot(self) -> None: Reboot the stock system into the bootloader and wait for an unlocked fastboot.
  • boot(self) -> None: Flash the test boot image, journalled first, and start it.
  • connect(self, timeout: float) -> None: Initialize the Windows NCM link once, then authenticate the recovery over SSH.
  • authenticate(self, timeout: float) -> None: Refuse an SSH endpoint that is not this run on this headset; cancel its connection deadline.
  • assertions(self, suffix: str = "") -> None: Check the running build, the root shell, read-only storage and, after a flash, the readback.
  • http(self, endpoint: str, timeout: float = 15) -> bytes: Fetch @p endpoint from the recovery's web server, bounded in time and size.
  • diagnostics(self) -> None: Fetch the recovery's status page, boot log and hardware report over HTTP, and its kernel log.
  • evidence(self, filename: str, command: str) -> None: Keep a command's output as evidence; best effort, the checks decide.
  • recover(self) -> None: Bring the headset back to the original the stock system, restoring stock boot if the flash touched it.
  • restore_boot(self) -> None: Flash the pinned stock boot image back once the headset is in fastboot.
  • execute(self) -> int: Run every step; whatever happens, bring the headset back and record the result. 0 when all passed.
  • main(runner: type[AcceptanceRunner], argv: list[str] | None = None, *, default_tools: Callable[[argparse.Namespace], None], rootfs: Callable[[], Path]) -> int: Run the acceptance runner's command line with @p runner: preflight or flash-run.

android

overpressure.api.v2.android: adb and fastboot, fail-closed, each command naming the serial (source).

  • DEVICE_ROW_FIELDS = 2: The fields of a devices line that matter: the serial and the state.
  • run(command: list[str], timeout: int = 60) -> str: Adb or fastboot, logged to stderr; a nonzero exit, FAILED or ERROR raises ValueError.
  • release_usb(adb: str, runner: Callable[[list[str]], object], platform: str | None = None) -> None: Stop the adb server (not on Windows), so that fastboot reaches the device.
  • device_rows(output: str, states: Sequence[str] = ("device", "unauthorized", "offline")) -> dict[str, str]: Return the serial and state of each device that adb's or fastboot's devices lists in @p states, in its order.
  • select_device(tool: str, serial: str | None, runner: Callable[[list[str]], str] | None = None) -> str: Return the serial to use: @p serial when it is attached and usable, else the only attached device.
  • unlocked(output: str, *, critical: bool = False) -> bool: Tell whether fastboot's device-info or getvar output reports the bootloader unlocked.
  • check_unlock(fastboot: str, serial: str, *, critical: bool = False, runner: Callable[[list[str]], str] | None = None) -> None: Raise unless the bootloader reports itself unlocked (and critical-unlocked when asked).
  • fastboot_value(output: str, name: str) -> str: One getvar variable's value; missing or repeated raises ValueError.
  • executable(name: str) -> str: Return the absolute path for a relative tool path; bare names stay PATH lookups.
  • partition_names(inventory: str, name: str) -> list[str]: Return the partitions named @p name, with or without a slot suffix, in fastboot's getvar all.
  • single_partition_size(inventory: str, name: str) -> int | None: Return the size of partition @p name from fastboot's getvar all, read as hexadecimal.
  • wait_booted(adb: str, serial: str, runner: Callable[..., str], clock: Timing, *, seconds: float = 300, system: str = "Android") -> str: Wait until Android (@p system names it in messages) has finished booting; return its build fingerprint.

assets

overpressure.api.v2.assets: a headset's assets out of its stock folder (source).

  • SCHEMA = 2
  • CHUNK = 1 << 22
  • POSIX_MODES = os.name == "posix": Whether files here carry POSIX permissions (Windows keeps only a read-only flag).
  • class AssetError(RuntimeError): A stock file is missing or not the one its manifest names, or an asset is not where it should be.
  • class StockFolder: A stock firmware folder: its manifest, its images checked against it, and readers for them.
  • check(self, *names: str) -> None: Check that each named file is there, not empty, and has the SHA-256 the manifest records.
  • ext4(self, name: str) -> Ext4: Return the checked ext4 image @p name, open for reading.
  • fat(self, name: str) -> Fat: Return the checked FAT image @p name, open for reading.
  • close(self) -> None: Close the open images.
  • class BackupFolder(StockFolder): A headset's backup in a stock folder's place: the same images, read out of its partitions.
  • check(self, *names: str) -> None: Check each image's partition file against the backup's manifest (once per folder object).
  • ext4(self, name: str) -> Ext4: Return the ext4 file system the image @p name names, open for reading.
  • fat(self, name: str) -> Fat: Return the FAT file system the image @p name names, open for reading.
  • close(self) -> None: Close the partition files.
  • dump(fs: Ext4, path: str, dest: Path) -> None: Copy @p path out of an ext4 image, as the extraction scripts' debugfs did.
  • copy_matching(fs: Fat, directory: str, patterns: Iterable[str], dest: Path) -> list[str]: Copy the files of @p directory that match each pattern into @p dest, as mcopy did; return their names.
  • widen_modes(folder: Path) -> None: Let everyone read @p folder's files and enter its directories, as chmod -R u+rwX,go+rX does.
  • manifest_files(output: Path) -> dict[str, str]: Return every file below @p output but the manifests, with its SHA-256, in path order.
  • write_manifest(output: Path, firmware: str | None, sources: Mapping[str, str]) -> int: Write @p output/manifest.json: the firmware, where each part came from, every file's SHA-256.

avb

overpressure.api.v2.avb: Android Verified Boot footers and vbmeta (source).

  • FOOTER = struct.Struct(">4sIIQQQ28x")
  • FOOTER_MAGIC = b"AVBf"
  • VBMETA_MAGIC = b"AVB0"
  • footer(partition: bytes) -> tuple[int, int, int]: Return (original image size, vbmeta offset, vbmeta size) of a partition image with a footer.
  • with_stock_vbmeta(stock_partition: bytes, image: bytes, block: int = 4096) -> bytes: Return a whole partition image: @p image and the stock partition's vbmeta after it.

backup

overpressure.api.v2.backup: verified backups, their archives, and the window's words for them (source).

  • ARCHIVE_META = "overpressure-backup.json": The archive's first member: what it holds and for which headset.
  • ARCHIVE_SCHEMA = 1
  • ARCHIVE_SUFFIX = ".overpressure-backup.tar": The suffix the window suggests for an export.
  • CHUNK = 1024 * 1024
  • HOW_TO_IMPORT
  • HOW_TO_EXPORT
  • missing(folder: Path, needed_for: str = "") -> str: Return the words for a backup that is not in @p folder on this computer, with how to import it.
  • digest(path: Path, count: Callable[[int], None] | None = None) -> dict: Return a file's size and SHA-256, as a manifest records them; an empty file raises.
  • save_new(path: Path, data: dict) -> None: Write DATA as JSON to PATH, which must not exist: a record is never overwritten.
  • verified_backup(folder: Path, count: Callable[[int], None] | None = None) -> dict: Return a backup's manifest once every file in it matches; a mismatch raises (@p count: as digest's).
  • verified_backup_shown(folder: Path, out: Callable[[str], None] | None = None) -> dict: Return verified_backup's manifest, printing progress lines (overpressure.progress) as it reads.
  • IMAGE_SUFFIXES = (".bin", ".img"): The suffixes of a partition's image in a backup, besides its GPT and rawprogram metadata.
  • partition_names(manifest: dict, name: str) -> list[str]: Return the files in a backup manifest that are images of partition @p name (exact, no slot).
  • partition_image(backup: Path, name: str) -> tuple[Path, dict]: Return the one image of partition @p name in a backup and its manifest entry.
  • verified_partition(backup: Path, name: str) -> tuple[Path, bytes]: Return the path and bytes of partition @p name's image in a backup, checked against its manifest.
  • class Kept (@dataclass(frozen=True)): A backup on this computer, as the list shows it.
  • name: str: its folder's name
  • folder: Path
  • size: int: the bytes of its files, as its manifest lists them
  • made: float: when it was finished here (its manifest's time, a POSIX timestamp): taken, or imported
  • ours: bool: of the headset the identity here names; another headset's is never the way back
  • active: bool: the way back: the one the headset's settings name (Headset.backup_set)
  • kept(here: BackupSet) -> list[Kept]: Return the backups beside the way back HERE names (in its folder's parent), the newest first.
  • use(here: BackupSet, name: str, say: Callable[[str], None] = print) -> BackupSet: Check the backup NAME whole and return it as the way back, for Headset.adopt_backup to name.
  • delete(here: BackupSet, name: str) -> Path: Delete the backup NAME for good; return its folder.
  • adopts(here: BackupSet, imported: BackupSet) -> bool: Tell whether an import becomes the way back: when the headset has none yet, or it is that one.
  • export_archive(bundle: BackupSet, codename: str, target: Path, say: Callable[[str], None] = print) -> dict: Write BUNDLE as one archive at TARGET (never over a file there); return its description.
  • read_meta(tar: tarfile.TarFile) -> dict: Return an archive's description; a file that is no backup archive raises.
  • check_archive(path: Path, manifest: dict | None = None, count: Callable[[int], None] | None = None) -> dict: Return the manifest an archive holds once every backup file in it matches it; a mismatch raises.
  • import_archive(source: Path, codename: str, here: BackupSet, say: Callable[[str], None] = print) -> BackupSet: Put the backup archive SOURCE onto this computer where HERE (the headset's settings now) says; return it.
  • compact(folder: Path, say: Callable[[str], None] | None = None) -> tuple[int, int]: Give the backup's zero runs back to the file system; return its bytes on disk before and after.
  • ACTIONS
  • main(headset: Headset, argv: list[str]) -> int: Run overpressure backup list|export|import|use|delete|compact.

bootimg

overpressure.api.v2.bootimg: Android boot images (source).

  • BOOT_MAGIC = b"ANDROID!"
  • BOOT_NAME_SIZE = 16
  • BOOT_ARGS_SIZE = 512
  • BOOT_EXTRA_ARGS_SIZE = 1024
  • BOOT_ID_SIZE = 32
  • V3_ARGS_SIZE = BOOT_ARGS_SIZE + BOOT_EXTRA_ARGS_SIZE
  • V3_PAGE_SIZE = 4096
  • HDR_SIZE = {0: 1632, 1: 1648, 2: 1660, 3: 1580, 4: 1584}
  • HEADER_RECOVERY_DTBO = 1
  • HEADER_DTB = 2
  • HEADER_V3 = 3
  • HEADER_SIGNATURE = 4
  • PAGE_SIZES = (2048, 4096, 8192, 16384)
  • class BootImage (@dataclass): A boot image's parts and header fields.
  • header_version: int
  • page_size: int
  • kernel: bytes
  • ramdisk: bytes
  • second: bytes = b""
  • recovery_dtbo: bytes = b""
  • dtb: bytes = b""
  • boot_signature: bytes = b""
  • cmdline: bytes = b""
  • extra_cmdline: bytes = b""
  • name: bytes = b""
  • os_version: int = 0
  • kernel_addr: int = 0
  • ramdisk_addr: int = 0
  • second_addr: int = 0
  • tags_addr: int = 0
  • dtb_addr: int = 0
  • id: bytes = b""
  • avb_footer: bool = False
  • property full_cmdline(self) -> str: Return the whole kernel command line.
  • property os_version_str(self) -> str: Return the OS version and patch level, readable.
  • with_cmdline(self, cmdline: str) -> BootImage: Return a copy with CMDLINE as the kernel command line, split across the fields as mkbootimg does.
  • compute_id(self) -> bytes: Return the SHA-1 image id exactly as AOSP mkbootimg computes it (v0-v2).
  • pack(self) -> bytes: Return the image as mkbootimg would write it.
  • parse(data: bytes) -> BootImage: Take a boot image apart.
  • ramdisk_tree(image: BootImage) -> cpio.Tree: Return the files of a boot image's ramdisk (any compression compress.decompress reads).
  • with_ramdisk(image: BootImage, tree: cpio.Tree, *, drop: tuple[str, ...] = (), add: Sequence[str] = (), failed: str = "the boot image failed validation") -> bytes: Return @p image with @p tree as its ramdisk (gzip) and a changed kernel command line.
  • decode_os_version(value: int) -> str: Return a header's packed OS version and patch level, readable.

compress

overpressure.api.v2.compress: the compressions images use (source).

  • LZ4_LEGACY_MAGIC = 0x184C2102
  • LZ4_LENGTH_MORE = 15
  • LZ4_BYTE_MORE = 255
  • LZ4_MIN_MATCH = 4
  • SIGNATURES
  • detect(data: bytes) -> str: Return the format of DATA by its magic: a name of SIGNATURES, "arm64-image" or "unknown".
  • decompress(data: bytes) -> tuple[bytes, bytes, str]: Decompress the first stream in data.
  • lz4_block_decompress(src: bytes | memoryview, out: bytearray) -> None: Append the decompressed contents of one raw LZ4 block to out.
  • lz4_legacy_decompress(data: bytes) -> tuple[bytes, bytes]: Return the data of a legacy LZ4 stream (the kernel's lz4 -l) and the bytes after it.
  • lz4_frame_decompress(data: bytes) -> tuple[bytes, bytes]: Return the data of an LZ4 frame and the bytes after it.
  • gzip_compress(data: bytes, level: int = 9) -> bytes: Deterministic gzip (mtime 0, no file name).

contract

overpressure.api.v2.contract: the headset runtime's contract on the PC's side (source).

  • RUN = "/run/overpressure": The runtime's state (tmpfs), its programs and its settings, on the headset.
  • LIB = "/usr/libexec/overpressure"
  • ETC = "/etc/overpressure"
  • CONTACT = f"{RUN}/host-contact": The uptime of the host's last command: the recovery's deadline counts from it (recovery-watch).
  • TEST_RUN = f"{ETC}/test-run": A test run's identity in its image, and the mark that its endpoint was proven (the deadline then stops).
  • TEST_AUTHENTICATED = f"{RUN}/test-authenticated"
  • TEST_CONNECT_TIMEOUT = f"{ETC}/test-connect-timeout": How long a test run waits for its first contact and runs at most (seconds, its image's files).
  • TEST_TIMEOUT = f"{ETC}/test-timeout"
  • BUILD_INFO = f"{ETC}/build-info": The recovery's build (JSON): its Alpine, its packages, its kernel.
  • HEADSET = f"{ETC}/headset": The headset's values the runtime sources (its name, its USB link, its programs).
  • WORD = "overpressure.": The word prefix the runtime reads on the kernel command line.
  • word(name: str, value: object = None) -> str: Return the kernel command line word overpressure.NAME, with =VALUE when one is given.

cpio

overpressure.api.v2.cpio: cpio archives (ramdisks) (source).

  • NEWC_MAGIC = b"070701"
  • NEWC_CRC_MAGIC = b"070702"
  • TRAILER = "TRAILER!!!"
  • MAX_SYMLINKS = 40
  • class Node (@dataclass): One filesystem object. mode holds the full st_mode (type + permissions).
  • mode: int
  • data: bytes = b""
  • uid: int = 0
  • gid: int = 0
  • rdev: tuple[int, int] = (0, 0)
  • mtime: int = 0
  • property is_dir(self) -> bool: Tell whether this is a directory.
  • property is_file(self) -> bool: Tell whether this is a regular file.
  • property is_symlink(self) -> bool: Tell whether this is a symbolic link.
  • class Tree (@dataclass): A root filesystem held in memory, keyed by relative POSIX path.
  • nodes: dict[str, Node] = field(default_factory=dict)
  • mtime: int = 0
  • mkdir(self, path: str, mode: int = 0o755, uid: int = 0, gid: int = 0) -> str: Create path (and parents). Returns the symlink-resolved path.
  • add_file(self, path: str, data: bytes, mode: int = 0o644, uid: int = 0, gid: int = 0) -> None: Add a regular file, its parent directories made.
  • add_symlink(self, path: str, target: str, uid: int = 0, gid: int = 0) -> None: Add a symbolic link to TARGET.
  • add_device(self, path: str, kind: str, major: int, minor: int, mode: int = 0o600) -> None: Add a device node: KIND "c" for a character, "b" for a block device.
  • get(self, path: str) -> Node | None: Return the node at PATH (symlinks not followed), None if there is none.
  • exists(self, path: str) -> bool: Tell whether there is a node at PATH (symlinks not followed).
  • resolve(self, path: str, _depth: int = 0) -> str: Resolve symlinks in path (inside the tree, never on the host).
  • to_tar(self, fileobj: IO[bytes]) -> None: Write the tree as an uncompressed tar without device nodes (handy for inspecting the rootfs).
  • to_cpio(self) -> bytes: Serialise as a newc cpio archive (parents always precede children).
  • read_cpio(data: bytes) -> list[tuple[str, Node]]: Parse a (possibly concatenated) newc cpio archive into (path, Node) entries.

devcli

overpressure.api.v2.devcli: a headset's development loop on the command line (source).

  • DESCRIPTION = __doc__: The command line's help: this module's own words.
  • class DevCommands: The development loop's command line: the generic commands, and a headset's own.
  • prog = "overpressure dev"
  • description = DESCRIPTION
  • PLAIN: tuple[str, ...]: The commands that take no arguments and are the client's method of that name (dashes: underscores).
  • make(self) -> Recovery: Return the headset's recovery client, with its settings.
  • add_own(self, sub: argparse._SubParsersAction) -> None: Add the headset's own commands to @p sub.
  • before_headset(self, args: argparse.Namespace) -> int | None: Run one of the headset's own commands that needs no headset; None when it is none.
  • run_own(self, dev: Recovery, args: argparse.Namespace) -> int | None: Run one of the headset's own commands; None when it is none.
  • parser(self) -> argparse.ArgumentParser: Return the command line's parser.
  • dispatch(self, dev: Recovery, args: argparse.Namespace) -> int: Run one command on @p dev; return its exit status.
  • main(self, argv: list[str] | None = None) -> int: Run the command line; errors end in a message and exit code 1.

devicecli

overpressure.api.v2.devicecli: a Qualcomm Android headset's device commands (source).

  • CLOCK: process.Timing = process.Clock(): The time the bootloader's waits use; tests replace it.
  • confirm(args: argparse.Namespace, identity: dict) -> None: Refuse to execute unless --confirm-device names the identity's serial.
  • restart_bootloader(fastboot: str, serial: str) -> None: Restart the headset into its bootloader and wait for its new session (macOS: Fastboot.restart_bootloader).
  • unlock_step(fastboot: str, serial: str, command: list[str]) -> None: Run one fastboot command of an unlock; a flashing command refused as done already counts.
  • run_dump(command: list[str], timeout: int = 60) -> str: Run an EDL dump as android.run does, the partition it reads shown as it goes (qualcomm.DumpProgress).
  • image_arg(text: str) -> tuple[str, Path]: Return restore-all's --image PARTITION=FILE as (partition, file).
  • restore_all(args: argparse.Namespace, manifest: dict) -> None: Write the whole verified backup back over EDL, each write read back (qualcomm.write_back); preview by default.
  • DESCRIPTION = __doc__: The command line's help: this module's own words.
  • class DeviceCommands: The device command line: the generic commands, and a headset's own (add_own, run_own).
  • prog = "overpressure device"
  • description = DESCRIPTION
  • MODEL_PROPERTIES: ClassVar[dict[str, str]] = {}: The properties the probe reads besides the fingerprint and the OEM state, by the identity's key.
  • IDENTITY: ClassVar[Path] = Path("backup/device.json"): Where the probe saves the identity by default.
  • STAGE_PARTITIONS = r"(?:abl|devinfo)(?:_[ab])?": The partitions stage and restore-abl may write over EDL (regular expressions).
  • RESTORE_PARTITIONS = r"abl(?:_[ab])?"
  • WITH_IDENTITY: ClassVar[tuple[str, ...]] = ("backup", "stage", "restore-abl", "restore-all"): The commands that read the saved identity and the backup (the headset's own may add to them).
  • settings(self) -> DeviceSettings: Return the headset's settings (its tools).
  • read_identity(self, path: Path) -> dict: Read the saved identity and refuse another headset (the headset's own checks).
  • add_own(self, sub: argparse._SubParsersAction) -> None: Add the headset's own commands to @p sub.
  • run_own(self, args: argparse.Namespace, identity: dict | None) -> bool: Run one of the headset's own commands; tell whether it was one (@p identity: read for WITH_IDENTITY).
  • parser(self) -> argparse.ArgumentParser: Return the device command line's parser.
  • static add_identity(p: argparse.ArgumentParser) -> None: Add what a command that reads the saved identity and the backup takes.
  • default_tools(self, args: argparse.Namespace) -> None: Fill an --adb, --fastboot or --edl not given with the settings' tool, as the installer runs it.
  • static require_client(args: argparse.Namespace) -> None: Refuse a run whose EDL client is not there, by name and with the fix, before anything is made or read.
  • dispatch(self, args: argparse.Namespace) -> None: Run one device command; previews unless --execute.
  • main(self, argv: list[str] | None = None) -> int: Run the device command line; errors end in a message and exit code 1.

doctor

overpressure.api.v2.doctor: dependency checks (source).

  • MARK
  • HEADSET = "working on the headset": What the checks of a headset's settings and tools are needed for, unless the headset names it.
  • EDL = "EDL"
  • FETCH = "overpressure tools": The fixes' common beginning: the pinned host tools.
  • BUILDS = "builds on this computer (build container)": What the build container's checks are needed for: builds on this computer, the owner's choice (a headset may build its own system, as the PICO 4 does), so they are never missing.
  • class Check (@dataclass(frozen=True)): One thing the workflow needs, and whether this host has it.
  • name: str
  • needed_for: str: the part of the workflow that needs it
  • status: str: ok, missing (needed), optional (missing, not needed), warning
  • detail: str = "": what was found, or why it is missing
  • fix: str = "": how to get it, when it is not ok
  • role: str = OWNER: whose it is: OWNER, INSTALLER or DEVELOPMENT
  • run_tool(argv: Sequence[str], timeout: float = 30) -> tuple[int, str]: Return a program's exit status and combined output; (127, reason) when it cannot start.
  • has_module(name: str) -> bool: Tell whether this Python can import the top-level module @p name, without importing it.
  • class Host (@dataclass): What the checks may ask of this host; tests pass fakes.
  • platform: str = sys.platform
  • run: Callable[[Sequence[str], float], tuple[int, str]] = run_tool
  • which: Callable[[str], str | None] = shutil.which
  • linux_cache: dict[str, dict[str, str]] = field(default_factory=dict)
  • has_module: Callable[[str], bool] = has_module
  • property engine(self) -> str: Return the container engine's program (overpressure/linux.py).
  • container_ready(self) -> bool: Tell whether the build container's image is built.
  • linux(self, script: str, timeout: float = 90) -> dict[str, str]: Return the KEY=VALUE lines that @p script prints in the build container (a probe: unnamed).
  • version_check(host: Host, name: str, argv: Sequence[str], needed_for: str, fix: str) -> Check: Check a program that answers a version query: its first output line, or how to get it.
  • env_check(root: Path = REPO, needed_for: str = HEADSET) -> Check: Check that overpressure has records of the headset (its serials), or a developer's .env names them.
  • serial_checks(settings: DeviceSettings, needed_for: str = HEADSET, edl_needed_for: str = EDL) -> list[Check]: Check that the headset's adb, fastboot and EDL serials are set.
  • backup_check(folder: Path, needed_for: str = HEADSET, fix: str = "overpressure device backup") -> Check: Check the EDL backup: its manifest, and every file in it present at its recorded size.
  • loader_check(settings: DeviceSettings, needed_for: str = EDL, fix: str = "the headset's signed Firehose loader") -> Check: Check that the Firehose loader the loader setting names is there.
  • edl_tool_check(host: Host, settings: DeviceSettings, needed_for: str = EDL) -> Check: Check that edl-ng is there: the edl setting's, the fetched one or one on PATH.
  • tool_checks(host: Host, settings: DeviceSettings, needed_for: str = HEADSET) -> list[Check]: Check adb and fastboot by their version queries.
  • ncm_checks(host: Host, settings: DeviceSettings) -> list[Check]: Windows only: the Python with pyusb and libusb-package, and UsbDk behind it.
  • link_check(host: Host, gadget: usblink.Gadget, needed_for: str = HEADSET, found: Sequence[usblink.Link] | None = None) -> list[Check]: Linux only, while the headset's own system is plugged in: its USB network link has the headset's lease.
  • usb_check(host: Host, modes: Sequence[usbaccess.UsbMode], needed_for: str = HEADSET, *, dirs: Sequence[Path] = usbaccess.RULE_DIRS, release: Path = usbaccess.OS_RELEASE, groups: Iterable[str] | None = None) -> list[Check]: Linux only: check that the installed udev rules let this user open each of the headset's USB @p modes.
  • driver_check(host: Host, modes: Sequence[usbaccess.UsbMode], needed_for: str = HEADSET, *, inf: Path | None = None) -> list[Check]: Windows only: check that a driver package is installed for each of the headset's USB @p modes that needs one.
  • PACKAGE_FIX: The pinned packages (pyproject.toml) and what works without them.
  • package_checks(host: Host) -> list[Check]: Check the pinned Python packages: brotli for the stock OTA, pyusb with libusb for EDL devices, truststore.
  • host_checks(host: Host, *, builds: bool = True) -> list[Check]: Return the checks every headset's workflow shares; @p builds False leaves out the build container's.
  • ENGINE = "Docker or Podman": The one fix for the builds' engine, whichever the owner picks and however it runs its containers.
  • ENGINE_FIX
  • BINFMT_FIX
  • ENGINE_MEMORY = 8 << 30: The memory the userspace build wants in the container: its C++ units take about 1.5 GiB a job.
  • MEMORY_FIX
  • engine_memory(info: str) -> int | None: Return the engine's memory in bytes from its info output, or None when it names none.
  • BINFMT_PROBE: The aarch64 handler by its ELF magic, whatever it is named, with its flags; the engine's architecture.
  • container_checks(host: Host) -> list[Check]: Check the build container, for builds on this computer: Docker or Podman answers, its image, the handler.
  • run(headset: Headset | None = None, host: Host | None = None, *, builds: bool = True) -> list[Check]: Run every check: the host's, then the headset's.
  • failed(checks: Iterable[Check]) -> list[Check]: Return the checks of what is needed and missing.
  • owners(checks: Iterable[Check]) -> list[Check]: Return the owner's checks: what this computer must have; the installer gets the rest itself.
  • report(checks: Sequence[Check], *, hidden: int = 0) -> str: Return the checks grouped by what they are needed for, the fixes below each missing one.

edl

overpressure.api.v2.edl: a Qualcomm Android headset's adb and EDL steps (source).

  • ADB_LIST_SECONDS = 5: How long a just-started adb server may list no device before none counts (adb_devices).
  • class QualcommHeadset[S: DeviceSettings]: Waits and adb/EDL steps of a Qualcomm Android headset; the headset's class names its modes and words.
  • usb_modes: ClassVar[Sequence[UsbMode]] = (): Its USB modes, and the ones adb and fastboot use (a tool that meets one this user may not open says how).
  • adb_mode: ClassVar[UsbMode | None] = None
  • fastboot_mode: ClassVar[UsbMode | None] = None
  • STOCK: ClassVar[str] = "the stock system": Its maker's system in words, and the way out of a stale EDL session.
  • EDL_RESTART: ClassVar[str]
  • tool_modes(self) -> dict[str, UsbMode]: Return the USB mode each tool opens, as usbaccess.guard takes them.
  • before_leaving_stock(self) -> None: Wait until the maker's system may be left (a headset's own: its MCU, say).
  • until(self, name: str, seconds: float, operation: Callable[[], T]) -> T: Retry @p operation until it succeeds, for at most @p seconds.
  • wait_stock(self, seconds: float = 300) -> str: Wait until the maker's system has finished booting; return its build fingerprint.
  • enter_edl(self) -> None: Bring the headset from the maker's system to EDL, unless it is the one EDL device already.
  • edl(self, *words: str | Path, log: str, timeout: float = 600) -> str: Run edl-ng with the headset's loader; its output goes to @p log.log in the evidence folder.
  • reset_to_stock(self, log: str) -> str: Reset from EDL (edl-ng's plain reset mode), then wait for the maker's system.
  • release_adb(self) -> None: Stop the adb server (not on Windows), so that fastboot reaches the headset.
  • drain(self) -> None: After a power command, read the headset's USB pipe until it leaves (qualcomm.drain_until_gone).
  • check_edl_serial(self, output: str) -> None: edl-ng reports the device serial when it connects: only the configured headset may be written.
  • identify(self) -> None: Identify the EDL device in a read-only session before anything is written: only the configured headset.
  • free_edl(self, log: str) -> None: Free the EDL device's loader and enter EDL mode afresh from what starts; nothing is written to storage.
  • again_in_edl(self) -> None: Enter EDL mode again after free_edl's normal restart: from the maker's system, through adb (enter_edl).
  • identity_chip(self) -> int | None: Return the SoC ID the headset's identity record holds, None without a readable one.
  • adb_devices(self) -> list[str]: Return the serials adb lists ready ("device"), oldest first as adb lists them.
  • stock_booted(self) -> str: Return the maker's system's build fingerprint once it has booted on this headset; raise while not (one look).
  • stock_partition(self, name: str) -> tuple[Path, dict]: Return a partition's image in the backup and its manifest entry.
  • stock_boot(self) -> tuple[Path, dict]: Return the stock boot image of the backup and its manifest entry.

evidence

overpressure.api.v2.evidence: runs on the headset that record every step (source).

  • HTTP_LIMIT = 32 * 1024 * 1024: What one HTTP fetch may return.
  • class NoRedirect(HTTPRedirectHandler): Follow no redirect: the headset's address is the only one a run talks to.
  • redirect_request(self, req: Request, fp: IO[bytes], code: int, msg: str, headers: Message, newurl: str) -> None: Refuse every redirect.
  • utc() -> str: Return the current time in UTC, as the result records it.
  • require(condition: object, message: str) -> None: Raise ValueError with @p message unless @p condition holds.
  • http_get(url: str, timeout: float = 15, limit: int = HTTP_LIMIT) -> bytes: Fetch @p url, bounded in time and size, without a proxy and without following a redirect.
  • class Runner: A run whose steps, commands and outputs are recorded in a new results folder.
  • save(self) -> None: Write the result file, replacing the last one whole.
  • command(self, argv: Sequence[str | os.PathLike[str]], timeout: float = 30) -> str: Run a host program, its command line and output kept as evidence; return its output.
  • step(self, name: str, operation: Callable[[], T]) -> T: Run one step of the run, recorded in the result whether it passes or fails.
  • wait(self, name: str, seconds: float, operation: Callable[[float], T]) -> T: Retry @p operation, given the time left for each attempt, until it succeeds or @p seconds pass.

ext4

overpressure.api.v2.ext4: ext4 images, read without mounting (source).

  • MAGIC = 0xEF53
  • SUPERBLOCK = 1024
  • ROOT_INODE = 2
  • EXTENT_MAGIC = 0xF30A
  • EXTENTS_FL = 0x80000
  • INLINE_DATA_FL = 0x10000000
  • INIT_MAX_LEN = 32768: An extent longer than this is uninitialized: it reads as zeros.
  • I_BLOCK = 60: The inode's i_block: 15 32-bit words, a fast symlink's target or the extent tree's root.
  • DIRECT_BLOCKS = 12
  • GOOD_OLD_INODE_SIZE = 128
  • MTIME_EXTRA_END = 12: i_mtime_extra's place after the 128-byte inode: it is there when i_extra_isize reaches it.
  • INCOMPAT_FILETYPE = 0x2
  • INCOMPAT_64BIT = 0x80
  • REFUSED: Incompatible features this reader refuses: they change where or how file data is stored.
  • CHUNK = 1 << 20
  • FILE_TYPES: Directory entry file types (with the filetype feature).
  • class Ext4Error(ValueError): The image is not ext4, uses what this reader refuses, or lacks what was asked for.
  • class Inode (@dataclass(frozen=True)): One inode: its type and permissions, owner, size, times and where its data is.
  • number: int
  • mode: int
  • uid: int
  • gid: int
  • size: int
  • mtime: int: seconds since the epoch
  • mtime_ns: int: nanoseconds within that second (0 without the extra fields)
  • links: int
  • flags: int
  • blocks: int: 512-byte sectors in use (i_blocks_lo)
  • file_acl: int
  • block: bytes: i_block: the extent tree's root, the block map or a fast symlink's target
  • property is_dir(self) -> bool: Tell whether this is a directory.
  • property is_file(self) -> bool: Tell whether this is a regular file.
  • property is_symlink(self) -> bool: Tell whether this is a symbolic link.
  • property permissions(self) -> int: Return the permission bits (with setuid, setgid and sticky).
  • class Run (@dataclass(frozen=True)): Contiguous file blocks: logical block, physical block (0: a hole), length, initialized.
  • logical: int
  • physical: int
  • length: int
  • initialized: bool = True
  • class Ext4: An ext4 (or ext2/ext3) image, read through a seekable binary file.
  • classmethod open(cls, path: str | os.PathLike[str]) -> Ext4: Open the image at @p path (closed with the reader).
  • close(self) -> None: Close the image's file when this reader opened it.
  • inode(self, number: int) -> Inode: Return inode @p number.
  • runs(self, inode: Inode) -> list[Run]: Return where @p inode's data blocks are, in logical order (holes left out).
  • chunks(self, inode: Inode, size: int = CHUNK) -> Iterator[bytes]: Yield @p inode's data in pieces of at most @p size bytes; holes give zeros.
  • data(self, inode: Inode) -> bytes: Return @p inode's whole data.
  • entries(self, inode: Inode) -> Iterator[tuple[str, int, str]]: Yield a directory's entries as (name, inode number, type), without "." and "..".
  • lookup(self, path: str) -> Inode: Return the inode at absolute @p path; symbolic links on the way are not followed.
  • exists(self, path: str) -> bool: Tell whether @p path is in the image.
  • listdir(self, path: str) -> list[str]: Return the names in the directory at @p path, in the directory's order.
  • read(self, path: str) -> bytes: Return the regular file at @p path.
  • link_target(self, inode: Inode) -> str: Return a symbolic link's target: in i_block when short (a fast link), else in its data.
  • readlink(self, path: str) -> str: Return the target of the symbolic link at @p path.
  • walk(self, path: str = "/") -> Iterator[tuple[str, Inode]]: Yield (path, inode) for @p path and everything below it, a directory before its contents.
  • main(argv: list[str] | None = None) -> int: Run the command line: cat IMAGE PATH writes the image's regular file PATH to stdout.

fastboot

overpressure.api.v2.fastboot: flashing through fastboot, the RAM boot (source).

  • NOT_IN_FASTBOOT: A wait for fastboot that ran out. A headset showing its fastboot screen is sometimes not seen by the computer after the reboot into it (the USB link does not come up); unplugging and plugging the cable in brings it.
  • REFUSED: How bootloaders say that they do not boot from RAM.
  • class Refused(RuntimeError): The bootloader has no fastboot boot (or refuses it): nothing was written.
  • run(argv: list[str], timeout: float) -> str: Return a program's combined output; a nonzero exit or a FAILED line raises RuntimeError with it.
  • DEVICE_ROW_FIELDS = 2: The fields of a fastboot devices line that matter: the serial and the state.
  • class Fastboot (@dataclass): fastboot for one headset: every command names its serial.
  • tool: str
  • serial: str
  • runner: Callable[[list[str], float], str] = run
  • present(self) -> bool: Tell whether the headset is in fastboot: listed with its serial, and nothing else is.
  • restart_bootloader(self, clock: Timing, leave: float = 30, back: float = 120) -> bool: Restart the headset into its bootloader; return once it has left fastboot and is listed again.
  • SPARSE_ABOVE = 64 << 20: Images above this size go to fastboot as sparse images: ABLs crash on large raw downloads (an engineering ABL on a 100 MiB recovery image).
  • flash(fastboot: Callable[..., str], partition: str, image: Path, *, above: int = SPARSE_ABOVE, sparse_path: Path | None = None) -> None: Write @p image to @p partition: as a sparse image above @p above bytes, else raw.
  • class RamBootTarget: What a headset supplies for a RAM boot (Headset.ram_boot).
  • boot_timeout: float = 180: Seconds for the transfer and the boot command, and for the image to come up.
  • up_timeout: float = 180
  • refused_hint: str = "": Said when the bootloader refuses: where this headset boots from instead.
  • property fastboot(self) -> Fastboot: Return fastboot for this headset.
  • image(self) -> Path: Return the image to boot when none is given.
  • enter(self) -> None: Bring the headset into fastboot (from Android, say); called when it is not there.
  • check_unlocked(self) -> None: Raise unless the bootloader reports a state that may boot an unsigned image.
  • reached(self) -> None: Raise until the booted image answers; return once it does.
  • ram_boot(target: RamBootTarget, image: Path | None = None, log: Callable[[str], None] = print, clock: Timing | None = None) -> None: Boot @p image (else the target's) from RAM and wait until it answers.

fat

overpressure.api.v2.fat: FAT images, read without mounting (source).

  • ENTRY = 32
  • ATTR_VOLUME = 0x08
  • ATTR_DIRECTORY = 0x10
  • ATTR_LFN = 0x0F
  • DELETED = 0xE5
  • FAT12_CLUSTERS = 4085: The FAT type follows from the number of data clusters (the specification's limits).
  • FAT16_CLUSTERS = 65525
  • LFN_LAST = 0x40: A long name entry's sequence number: the last (first stored) one has this bit.
  • LFN_CHARS = (1, 3, 5, 7, 9, 14, 16, 18, 20, 22, 24, 28, 30): The 13 UCS-2 characters of a long name entry, by their byte offsets.
  • class FatError(ValueError): The image is not FAT, is damaged, or lacks what was asked for.
  • class Entry (@dataclass(frozen=True)): A directory entry: its long (or 8.3) name, the 8.3 name, kind, first cluster, size and time.
  • name: str
  • short_name: str
  • is_dir: bool
  • cluster: int
  • size: int
  • mtime: dt.datetime | None: the write time, local time as FAT keeps it; None when not valid
  • class Fat: A FAT12, FAT16 or FAT32 image, read through a seekable binary file.
  • classmethod open(cls, path: str | os.PathLike[str]) -> Fat: Open the image at @p path (closed with the reader).
  • close(self) -> None: Close the image's file when this reader opened it.
  • next_cluster(self, cluster: int) -> int | None: Return the cluster after @p cluster in its chain, None at the chain's end.
  • chain(self, first: int) -> Iterator[int]: Yield the clusters of the chain that starts at @p first; a chain that comes back is refused.
  • chunks(self, entry: Entry) -> Iterator[bytes]: Yield a file's data, a cluster at a time.
  • read_entry(self, entry: Entry) -> bytes: Return a file's data.
  • entries(self, directory: Entry | None = None) -> Iterator[Entry]: Yield the entries of @p directory (None: the root), without ".", ".." and the volume label.
  • lookup(self, path: str) -> Entry | None: Return the entry at absolute @p path (None for the root directory).
  • listdir(self, path: str = "/") -> list[str]: Return the names in the directory at @p path, in the directory's order.
  • read(self, path: str) -> bytes: Return the file at @p path.
  • glob(self, path: str, pattern: str) -> list[Entry]: Return the files in the directory at @p path whose long or 8.3 name matches @p pattern.

headset

overpressure.api.v2.headset: the headset, its steps, workflows and finished page (source).

  • SUPPORTED: dict[int, int] = {2: 0}: The headset interface, MAJOR.MINOR (docs/develop/adding-a-headset.md#the-headset-interface): each major this overpressure runs, with its newest minor. A minor only adds to its major; a change that breaks one makes a new major, and the old one stays, as its module overpressure.api.vMAJOR, until it is retired (RETIRED).
  • API = f"{max(SUPPORTED)}.{SUPPORTED[max(SUPPORTED)]}": The newest interface: what a new headset is made for.
  • RETIRED: dict[int, str] = {1: "2026.11.0b1"}: The majors this overpressure no longer runs, each with the last overpressure version that ran it.
  • MANIFEST = "headset.json": A headset folder's description of itself: devices//headset.json.
  • RUNTIME_SINCE = (1, 8): The interface from which a headset runs on overpressure's runtime (docs/internals/runtime.md) unless it says otherwise: one made for an older interface brings its own /init, PID 1 and preinit.
  • class Info (@dataclass(frozen=True)): What names and describes a headset.
  • codename: str: devices/, also the --device name
  • name: str: the product's name
  • soc: str = ""
  • summary: str = ""
  • class Flavour (@dataclass(frozen=True)): A system the install can put on a headset (docs/develop/adding-a-headset.md#flavours).
  • key: str: the build's --flavour, the installed system's record (flavour= in its version file)
  • name: str: as the owner sees it
  • summary: str: what it is, in a sentence
  • available: bool = True: It can be installed. One that cannot yet is still offered, with its note, and never chosen.
  • note: str = ""
  • STEAMOS: Valve's SteamOS as on the Steam Frame: every headset's first flavour, and the one a headset.json without "flavours" has.
  • OVERPRESSURE_OS: Linux with open-source VR in place of Steam and SteamVR (overpressure/overpressure#40): not built yet.
  • FLAVOURS: dict[str, Flavour] = {f.key: f for f in (STEAMOS, OVERPRESSURE_OS)}: The flavours this overpressure knows, by key; a headset.json's "flavours" names which of them it offers.
  • flavours_of(data: dict) -> tuple[Flavour, ...]: Return the flavours a headset.json (@p data) offers, in its order: its known "flavours", else SteamOS alone.
  • class Command (@dataclass(frozen=True)): A command of the command line: a module whose main(argv) takes the rest of the words.
  • module: str
  • help: str
  • keep: bool = False
  • headset: bool | tuple[str, ...] = False
  • class Param (@dataclass(frozen=True)): A parameter of a step: its value goes into the command line in place of {name}.
  • name: str
  • label: str
  • default: str = ""
  • kind: str = "text": text, path (a file or folder), choice or flag
  • choices: tuple[str, ...] = ()
  • help: str = ""
  • option: str = "": A flag's word, given when the flag is on ("1"); for another kind, the option given before its value, both left out when the value is empty ("--flavour").
  • class Step (@dataclass(frozen=True)): One action of the workflow, as the window offers it.
  • key: str
  • title: str
  • group: str: "Setup", "Image" or "Headset"
  • argv: tuple[str, ...]
  • help: str = ""
  • params: tuple[Param, ...] = ()
  • script: bool = False: argv[0] is a program in the headset's folder
  • linux_root: bool = False: runs as root in the build container (overpressure/linux.py)
  • writes: bool = False: writes to the headset: the window asks first
  • command(self, values: dict[str, str]) -> list[str]: Return the command line with @p values in place of the parameters.
  • INSTALL = "install": The installer's workflow every headset with an installer has; its state stays where it always was.
  • class Workflow (@dataclass(frozen=True)): Something the installer does with a headset, chosen right after the headset: install, upgrade, restore.
  • key: str: the plan's name: install --workflow KEY
  • title: str: the window's card and the stepper's caption
  • summary: str: what it does and what it keeps or erases, in one or two sentences
  • erases: bool = False: it erases the headset's data
  • changes: bool = True: It changes the headset. One that only looks, such as a check, starts afresh every time and leaves the other workflows' progress, and the record of what was installed, as they are.
  • class Action (@dataclass(frozen=True)): A choice on the installer's finished page: another workflow, or Advanced mode at one of the headset's steps.
  • label: str
  • step: str = "": the key of the step Advanced mode opens at
  • workflow: str = "": the workflow it starts instead (its start page)
  • ABSENT = "absent": The states a look at the headset finds it in (Found.state).
  • MAKER = "maker": its maker's system runs (PICO OS, Horizon OS, ...)
  • OVERPRESSURE = "overpressure": overpressure's system runs: installed, or overpressure's recovery
  • BOOTLOADER = "bootloader": in its bootloader (fastboot)
  • MAKER_RECOVERY = "maker-recovery": its maker's recovery (PICO OS's, say): not overpressure's
  • EDL = "edl": the SoC's emergency download mode (Qualcomm EDL)
  • UNKNOWN = "unknown": there, but not readable: what it runs is not known
  • STATES
  • class Found (@dataclass(frozen=True)): What a look at the headset found, without changing it (Headset.assess).
  • state: str
  • system: str = ""
  • version: str = ""
  • facts: tuple[tuple[str, str], ...] = ()
  • workflows: tuple[str, ...] = ()
  • note: str = ""
  • class BackupSet (@dataclass(frozen=True)): A headset's backup on this computer: what an export carries and where an import puts it.
  • folder: Path
  • identity: Path
  • files: dict[str, Path] = field(default_factory=dict)
  • settings: dict[str, str] = field(default_factory=dict)
  • class AfterInstall (@dataclass(frozen=True)): What the installer's finished page says and offers: the generic window knows no headset's OS or store.
  • title: str = "Installed"
  • text: str = "Your headset is ready."
  • actions: tuple[Action, ...] = ()
  • tools_step() -> Step: Return the window's step for overpressure's tool fetcher.
  • ram_boot_step(image: str, help_text: str = "") -> Step: Return the window's step for overpressure's RAM boot, with the headset's default image.
  • class Headset(ABC): A supported headset.
  • info: Info
  • property root(self) -> Path: Its folder, devices/: where its tooling package was found (the data root's, or CODE's).
  • commands(self) -> dict[str, Command]: Its command line: command word -> module of its tooling package.
  • steps(self) -> Sequence[Step]: Its workflow for the window, in order: building its images, then working on it.
  • dependencies(self) -> Sequence[Callable]: Return its checks for overpressure doctor.
  • usb_modes(self) -> Sequence[UsbMode]: Return the ways it appears on USB that the host's tools open (adb, fastboot, EDL).
  • ram_boot(self) -> RamBootTarget | None: How it boots an image from RAM (overpressure ram-boot), or None.
  • install_plan(self) -> Sequence[Stage]: Return its installer's stages (overpressure install); empty: it has no installer.
  • workflows(self) -> Sequence[Workflow]: Return what its installer does, in the window's order: the install alone unless it has more.
  • plan(self, workflow: str) -> Sequence[Stage]: Return the stages of WORKFLOW (overpressure install --workflow WORKFLOW).
  • questions(self, workflow: str, found: Found | None = None) -> Sequence[Ask]: Return what WORKFLOW asks the owner, answered before it starts: none by default.
  • flavours(self) -> Sequence[Flavour]: Return the systems the install can put on this headset, the default first (headset.json's "flavours").
  • workflow_problem(self, workflow: str) -> str: Return why WORKFLOW cannot run now, in plain words, or "" when it can.
  • assess(self) -> Found | None: Look at the headset on USB without changing it: what it runs and what fits that.
  • after_install(self) -> AfterInstall: Return what the window's finished page says and offers once its installer has run.
  • finished_page(self, workflow: str) -> AfterInstall: Return what the window's finished page says and offers once WORKFLOW has run (the install: after_install).
  • backup_set(self) -> BackupSet | None: Return its backup on this computer as .env names it (overpressure backup), or None.
  • adopt_backup(self, imported: BackupSet) -> None: Make an imported backup this computer's: the .env settings that name it and its serials.
  • settle_files(self) -> None: Move its files from where an earlier release kept them, once; nothing by default.
  • support_files(self, folder: Path) -> None: Add the headset's own files for a bug report into FOLDER: its logs, its device's bundle.
  • support_masks(self) -> dict[str, str]: Return what else a bug report must not show, each value with what it becomes.
  • touches(self, argv: list[str]) -> bool: Tell whether the command line ARGV (argv[0] its command word) touches the headset; help never does.
  • main(self, argv: list[str]) -> int: Run a command of its command line (argv[0] is the command word).
  • class Registry (@dataclass): The headsets in devices/, by codename; refused: those this overpressure cannot run, and why.
  • headsets: dict[str, Headset] = field(default_factory=dict)
  • refused: dict[str, str] = field(default_factory=dict)
  • get(self, codename: str) -> Headset: Return the headset CODENAME; KeyError names the known ones, or why it was refused.
  • manifest(folder: Path) -> dict: Return a headset folder's headset.json (codename, name, version, api, commit, date), {} if missing or broken.
  • api_version(value: object) -> tuple[int, int] | None: Return a headset.json api ("1.2"; a bare 1 is 1.0) as (major, minor), None when it is none.
  • runs_on_runtime(folder: Path) -> bool: Return whether FOLDER's headset is made for an interface on overpressure's runtime (RUNTIME_SINCE).
  • runs() -> str: Return the interfaces this overpressure runs, in words.
  • api_problem(value: object) -> str: Return why this overpressure cannot run a headset made for interface VALUE, "" when it can.
  • refusal(codename: str, data: dict) -> str: Return why a headset folder with headset.json DATA cannot run here, or "" when it can.
  • import_fresh(name: str, files: Iterable[Path]) -> ModuleType: Import module NAME, anew when FILES changed since this process imported it.
  • settle(registry: Registry, *, checkout: bool = False) -> None: Let each headset of REGISTRY move its files from an earlier layout (Headset.settle_files).
  • discover() -> Registry: Every devices//tooling package that exports HEADSET, whose headset.json this interface runs.

install

overpressure.api.v2.install: the installer: stages, tasks, asks and the context a task runs in (source).

  • OUT = REPO / "out" / "install": Where the lock lives, and each headset's folder with its state and its tasks' logs.
  • STATE = "state.json"
  • SCHEMA = 1
  • UPGRADE = "upgrade": The upgrade workflow (overpressure upgrade runs it).
  • SYSTEM_WORKFLOWS = (INSTALL, UPGRADE): The workflows whose finished run leaves overpressure's system on the headset (installed_release).
  • COMPLETE = (DONE, SKIPPED): The statuses of a task that needs no run.
  • KINDS = ("confirm", "action", "form")
  • EXIT = {DONE: 0, FAILED: 1, STOPPED: 3}: The exit statuses: finished, failed, a usage error (or no installer), stopped.
  • EXIT_USAGE = 2
  • MASK = "***": What a secret value becomes wherever text leaves the engine.
  • TERMINATE_GRACE = 10: Seconds a stopped child that does not write gets to end before it is killed.
  • STOP_SLICE = 0.2: Seconds a wait through ctx.clock sleeps at most before it looks for a stop request.
  • STOPPED_BETWEEN: What a stopped run's finished event says (its where), in plain words.
  • STOPPED_NOTHING
  • STOPPED_AGAIN = "Start the installer again to continue where it stopped."
  • STOPPED_WROTE
  • STOPPED_UNWRITTEN = "This step had not written to the headset yet."
  • class Field (@dataclass(frozen=True)): A field of a form ask.
  • name: str
  • label: str
  • secret: bool = False: masked when typed, never written anywhere
  • optional: bool = False
  • setting: str = "": The owner's setting that fills it in and keeps it for later: wifi_ssid, wifi_password (kept protected) or ssh_public_key (the key's line); empty: none.
  • choice: bool = False: A yes or no, shown as a checkbox: its answer is "1" when ticked, else "". Always optional.
  • options: tuple[Option, ...] = (): One of these, shown as cards: its answer is the chosen one's value, the first available one until the owner chooses another. Never empty when it has options.
  • path: bool = False: A file's location, chosen with a file dialog or typed (never the file's content).
  • event(self) -> dict: Return the field as its ask event has it.
  • picked(self, value: object) -> str: Return the option @p value names when it may be chosen, else the first available one ("" for none).
  • class Option (@dataclass(frozen=True)): One answer of a field that takes one of several (Field.options).
  • value: str
  • label: str
  • text: str = "": what it is, in a sentence or two
  • available: bool = True: It may be chosen. One that may not is still shown, with its note (why not, or when it will be).
  • note: str = ""
  • fields: tuple[Field, ...] = (): Fields shown while it is chosen (the key file of a choice that takes one): their answers join the form's, and a field that is not optional is needed only while it is chosen.
  • event(self) -> dict: Return the option as its field's event has it.
  • FLAVOUR = "flavour": The install's question which system the headset gets (flavour_ask), and its field.
  • flavour_ask(flavours: Sequence[Flavour]) -> Ask | None: Return the question which of @p flavours the install puts on the headset; None with only one to offer.
  • chosen_flavour(flavours: Sequence[Flavour], values: dict[str, str]) -> str: Return the flavour's key the owner chose in @p values (flavour_ask's form, as Context.ask returns it).
  • class Ask (@dataclass(frozen=True)): A question to the owner: a consent (confirm), something to do (action) or a form.
  • id: str
  • kind: str: confirm, action or form
  • title: str
  • text: str
  • fields: tuple[Field, ...] = ()
  • accept: str = "": the accepting button; empty: "Done" for an action, "Continue" otherwise
  • decline: str = "Cancel"
  • consent: str = "": A consent asked before the start (Headset.questions): the sentence the start button agrees to, in the first person ("I agree that my headset and everything on it is erased."). Empty: the app words it.
  • every_field(self) -> tuple[Field, ...]: Return its fields and its options' fields, in order: every name its answer may hold.
  • needed(self, values: dict[str, str]) -> list[Field]: Return the fields @p values leave empty that it needs: its own, and the chosen options'.
  • event(self) -> dict: Return the ask as its event.
  • IMPORT_BACKUP = "import-backup": What a failure offers beside Retry, by name (the finished event's "offer"): the backup's import.
  • class Failed(RuntimeError): A task failed: the message says what, in plain words; where says the headset's state and what to do.
  • offer = "": What the window offers beside Retry (IMPORT_BACKUP), "" for nothing more.
  • class NoBackup(Failed): The headset's backup is not on this computer: the message says how to import it, the window offers it.
  • offer = IMPORT_BACKUP
  • class Stopped(Exception): The run stops: a declined ask, Ctrl-C or a closed window.
  • class StopClock: The clock tasks get (ctx.clock): a sleep looks for a stop request every STOP_SLICE s and ends in Stopped.
  • monotonic(self) -> float: Return the clock's time.
  • sleep(self, seconds: float, /) -> None: Wait @p seconds in slices; raise Stopped as soon as a stop is requested.
  • class Part (@dataclass(frozen=True)): A part of a task the owner sees on its own, in its order: its title and how long it takes.
  • title: str
  • estimate: str = "": in words, as a task's: its share of the task's bar
  • class Task (@dataclass(frozen=True)): One thing the install does, with the function that does it.
  • id: str: unique in the plan: the state's key and the log's name
  • title: str
  • run: Callable[[Context], None]
  • estimate: str = "": how long it takes, in words ("about 1 min")
  • writes: bool = False: writes to the headset: its children are never killed midway
  • done: Callable[[Context], bool] | None = None: True: its result is there, no run needed
  • where: str = "": after a failure: the headset's state and what to do next
  • parts: tuple[Part, ...] = (): Its parts, in order: the window shows them, one bar across them. The task tells which one begins (ctx.begin_part, or its program's progress.begin line); its progress then fills that part.
  • shown: bool = True: Listed in the plan. False for a task that only takes an answer the window asks before the start (a consent, a form, a plug-in): it runs in its place, asks there when nothing answered it early, and its notes and asks still show; its row and its progress do not.
  • part_spans(parts: Sequence[Part]) -> list[tuple[float, float]]: Return each part's (start, share) of its task's bar, by its estimate; one without counts as the others' mean.
  • class Stage (@dataclass(frozen=True)): A group of tasks the owner sees as one step, with one main button in the window.
  • id: str
  • title: str
  • summary: str
  • tasks: tuple[Task, ...]
  • class UI(Protocol): Where the events go and the answers come from: the window (JSON lines) or a terminal.
  • start(self, stop: Callable[[], None]) -> None: Begin a run; call @p stop when the other side wants the run to stop.
  • emit(self, event: dict) -> None: Show one event.
  • answer(self, ask: Ask) -> dict | None: Return the answer to @p ask ({"accepted": ..., "values": {...}}), None when the run must stop.
  • class JsonUI: The window's side: one JSON object per line on stdout, answers one per line on stdin.
  • start(self, stop: Callable[[], None]) -> None: Take the early answers (--early), then read answers on a thread from now on.
  • early(self, ask: Ask) -> dict | None: Return the answer the owner gave @p ask before the start, once; None when there is none.
  • emit(self, event: dict) -> None: Write @p event as one line with its time (seconds); a closed stdout stops the run.
  • answer(self, ask: Ask) -> dict | None: Wait for the answer to @p ask; None once stdin is closed.
  • class TextUI: A terminal: stage headings, a line per task status, the child programs' output indented.
  • MARKS: ClassVar[dict[str, str]]
  • start(self, stop: Callable[[], None]) -> None: Nothing to start: Ctrl-C stops the run.
  • say(self, text: str) -> None: Write one line.
  • emit(self, event: dict) -> None: Write @p event as text.
  • finished(self, event: dict) -> None: Write how the run ended.
  • answer(self, ask: Ask) -> dict | None: Ask in the terminal; None at the end of input.
  • pick(self, item: Field) -> str: Ask for one of @p item's options by its number; Enter takes the first available one.
  • class Lock: One engine at a time on this computer: an OS lock on out/install/lock, released when the process ends.
  • acquire(self) -> bool: Take the lock; False when another engine holds it.
  • release(self) -> None: Give the lock up.
  • Spawn: Runs a child program: (argv, stdin bytes or None, own process group, line handler) -> exit status.
  • Capture = Callable[[list[str], float], "tuple[int, str]"]: Runs a short program: (argv, timeout) -> (exit status, output).
  • workflow_folder(root: Path, codename: str, workflow: str) -> Path: Return where WORKFLOW keeps its state and logs: the install directly in the headset's folder.
  • installed_release(codename: str, root: Path = OUT) -> str: Return the headset's tooling (catalogue.identity) its last finished install or upgrade ran with, "" for none.
  • class Context: What a task gets: events, asks, child programs, the settings and the state.
  • property stopping(self) -> bool: Tell whether the run has been asked to stop.
  • log(self, line: str) -> None: Add a line to the task's log (the details view and out/install//.log).
  • progress(self, fraction: float | None, text: str = "") -> None: Show how far the task is: @p fraction from 0 to 1 (None: unknown) and a short text.
  • begin_part(self, index: int, text: str = "") -> None: Begin the task's part @p index (from 0, Task.parts): the earlier ones are done.
  • output_line(self, text: str, progress: Callable[[str], tuple[float | None, str] | None] | None = None) -> None: Log a line a program printed; a progress line, or one @p progress reads, shows how far.
  • note(self, text: str, level: str = "info") -> None: Tell the owner something in plain words: info, or a warning.
  • ask(self, ask: Ask) -> dict[str, str]: Ask the owner and wait; return a form's values. A declined ask stops the run.
  • choose(self, ask: Ask) -> bool: Ask a yes-or-no question whose no goes on (@p ask's decline); return True for its accept.
  • instruct_until[T](self, ask: Ask, what: str, seconds: float, operation: Callable[[], T]) -> T: Show @p ask's instruction and wait until @p operation returns, as process.until does.
  • run(self, argv: Sequence[str | os.PathLike[str]], *, stdin: bytes | None = None, progress: Callable[[str], tuple[float | None, str] | None] | None = None) -> str: Run a child program from the repository root, its output streamed to the log; return its output.
  • output(self, argv: Sequence[str | os.PathLike[str]], timeout: float = 60, *, check: bool = True) -> str: Run a short program (a poll, a query) without streaming; its output goes to the log file only.
  • settings(self, cls: type[S]) -> S: Return the settings of @p cls as they are now (earlier tasks may have recorded some).
  • set_setting(self, key: str, value: str) -> None: Record KEY=VALUE (localconfig.update): what the installer finds out (a serial), never a secret.
  • remember(self, choice: str, *, key: str = "") -> None: Record the owner's CHOICE for this task in the state (never a secret): a later run reads it back.
  • recall(self, task: str) -> str: Return the choice recorded under @p task (a task, or its own key), in this or an earlier run; "" for none.
  • completed(self, task: str) -> bool: Tell whether the task @p task is done or skipped, in this run or an earlier one.
  • replug(what: str, seconds: float) -> Ask: Return the ask after a wait for @p what that ran out after @p seconds: plug the headset in again.
  • link_ask(problem: str) -> Ask: Return the ask for a USB link that is up without the headset's address (usblink.problem's @p problem).
  • replug_until[T](ctx: Context, what: str, seconds: float, operation: Callable[[], T], *, modes: Sequence[usbaccess.UsbMode] = (), link: Callable[[], str] | None = None) -> T: Wait for @p what as process.until() does; when @p seconds run out, show how to replug, then wait anew.
  • class Engine: Runs a plan: events to a UI, the state file, the lock, the tasks' logs.
  • plan_event(self) -> dict: Return the plan as its event.
  • property state_path(self) -> Path: Return the state file.
  • load_state(self) -> None: Read the state file; a missing or unreadable one is a fresh start.
  • save_state(self) -> None: Write the state file whole.
  • status(self, task: str) -> str: Return a task's recorded status (pending when it has none).
  • set_status(self, stage: Stage, task: Task, status: str, *, record: bool = True) -> None: Show a task's status and record it in the state file.
  • forget_others(self) -> None: Forget what the other workflows had done: the headset is where this one left it, not where they did.
  • forget(self, stage_id: str) -> None: Forget what was done from stage @p stage_id on (--restart).
  • redact(self, text: str) -> str: Return @p text with every secret value masked.
  • check_argv(self, argv: Sequence[str]) -> None: Refuse a command line that carries a secret value: secrets go on stdin only.
  • emit(self, event: dict) -> None: Hand @p event to the UI; a hidden task's status and progress stay in its log (Task.shown).
  • write_log(self, task: Task, text: str) -> None: Append @p text to out/install//.log.
  • close_logs(self) -> None: Close the tasks' log files.
  • finish(self, status: str, task: Task | None, error: str = "", where: str = "", offer: str = "") -> str: Emit the finished event (with what the window offers beside Retry, OFFER); return @p status.
  • request_stop(self) -> None: Stop at the next wait; a running child that does not write to the headset is ended, one that writes not.
  • step(self, stage: Stage, task: Task) -> str | None: Run one task unless it needs no run; return the run's end status when it ends the run.
  • run(self, restart: str | None = None) -> str: Run the plan from where it stopped (from stage @p restart on, with it); return how it ended.
  • show_plan(self) -> None: Emit the plan and every task's recorded status (--plan): nothing runs.
  • stopped_where(task: Task, *, wrote: bool) -> str: Return what a run stopped in @p task says: the headset's state and what to do.
  • check_plan(stages: Sequence[Stage]) -> None: Refuse a plan whose stage or task ids repeat: the state and the logs are keyed by them.
  • main(headset: Headset, argv: list[str], *, stdin: IO[str] | None = None, stdout: IO[str] | None = None, root: Path = OUT) -> int: Run overpressure install for @p headset.
  • upgrade(headset: Headset, argv: list[str]) -> int: Run overpressure upgrade: the installer's upgrade.
  • restore(headset: Headset, argv: list[str]) -> int: Run overpressure restore: the installer's way back to the headset's own system.

kernelimage

overpressure.api.v2.kernelimage: a boot image with another kernel (source).

  • DEBUG: --debug: every driver probe logged (the RAM console then ends with the probe a stalled boot waits for), every task and CPU on a panic, msm's debug output, and a hard lockup a panic.
  • trace_words(function: str) -> tuple[str, ...]: Return the words that record the function graph below one kernel function and print it on a panic.
  • keyed_words(*groups: Iterable[str]) -> tuple[str, ...]: Merge command line words; a later word replaces an earlier one with its key.
  • command_line(stock: str, extra: Iterable[str], drop: tuple[str, ...], limit: int) -> str: Return @p stock's words without those @p extra replaces by key or that start with @p drop, then @p extra.
  • files_archive(files: dict[str, Path]) -> cpio.Tree: Archive each file at its path (the tree makes the parent directories).
  • appended(ramdisk: bytes, *trees: cpio.Tree) -> bytes: Append each archive to the ramdisk; the kernel unpacks them in order.
  • with_kernel(base: bootimg.BootImage, kernel: bytes, dtb: bytes, cmdline: str, ramdisk: bytes, *, recovery_dtbo: bool = True) -> bytes: Return @p base packed with @p kernel, @p dtb, @p cmdline and @p ramdisk, its signature cleared, checked.

kernelinfo

overpressure.api.v2.kernelinfo: a kernel image's version and configuration (source).

  • FDT_MAGIC = b"\xd0\x0d\xfe\xed"
  • FDT_HEADER_SIZE = 40
  • class KernelInfo (@dataclass): What a kernel image tells about itself.
  • compression: str
  • image_size: int
  • version: str = ""
  • config: dict[str, str] = field(default_factory=dict)
  • config_text: str = ""
  • appended_dtbs: list[bytes] = field(default_factory=list)
  • has_skip_initramfs: bool = False
  • arm64_magic: bool = False
  • opt(self, name: str) -> str | None: Return the value of CONFIG_ ("y", "m", a string) or None if unset/unknown.
  • enabled(self, name: str) -> bool | None: Tell whether an option is on: True/False if the config is known, None if no config was embedded.
  • analyse(kernel_blob: bytes) -> KernelInfo: Return what a (possibly compressed) kernel image tells about itself.
  • extract_ikconfig(image: bytes) -> str: Return the kernel's embedded config (CONFIG_IKCONFIG), or "" without one.
  • split_dtbs(blob: bytes) -> list[bytes]: Split concatenated flattened device trees.
  • dtb_summary(dtb: bytes) -> dict: Return model / compatible / qcom,msm-id / qcom,board-id of a DTB root node.

kernelpin

overpressure.api.v2.kernelpin: a headset's pin of overpressure/linux and its contracts (source).

  • Log = Callable[[str], None]
  • Opener = Callable[..., object]
  • IN_PACKAGES = "packages:": A contract path in overpressure/packages at the pinned commit, not in the headset's repository.
  • BUILD_DIFFERS = ("Image.gz",): What a build of the pinned commit gives that the release does not: Valve's configuration signs modules with a key each build generates and builds into Image.gz, so only the other files match the pin.
  • class Release (@dataclass(frozen=True)): A pinned release: overpressure/linux's (kernel.json) or overpressure/packages' (packages.json).
  • repository: str
  • tag: str
  • commit: str
  • image: str
  • files: dict[str, str]: name -> SHA-256
  • url(self, name: str) -> str: Return the download URL of the release's file @p name.
  • source_url(self, path: str) -> str: Return the URL of the pinned commit's file @p path (the tree as it is, no history).
  • pin_path(headset: Path) -> Path: Return the headset's kernel pin: its kernel.json, or an older headset's kernel/release.json.
  • release(path: Path) -> Release: Return the pin in @p path: a kernel.json (its build values aside), or a packages.json (no image, no files).
  • sha256(path: Path) -> str: Return @p path's SHA-256 (empty for an empty file, which no pin names).
  • mismatches(folder: Path, pin: Release, *, built: bool = False) -> list[str]: Return the files in @p folder that are missing or differ from the pin, as messages.
  • current(folder: Path, pin: Release) -> bool: Tell whether @p folder holds the pinned kernel's files.
  • fetch(folder: Path, pin: Release, *, log: Log = print, opener: Opener | None = None) -> list[str]: Download the pinned release's files into @p folder, each checked by hash; return their names.
  • STEP = "overpressure/build/build-kernel-step.sh": overpressure's kernel build step (build/build-kernel-step.sh HEADSET WORKDIR), as the build container runs it.
  • build_argv(step: str, work: str, *, headset: str = "") -> list[str]: Return the command line that runs the kernel build @p step (a script) here, in the build container.
  • build(step: str, work: str, pin: Release, call: Callable[..., int] = subprocess.call, *, headset: str = "") -> int: Build the pinned commit with @p step in the image the release was built with; return its exit status.
  • class Contract (@dataclass(frozen=True)): A name or path the headset uses and the kernel must provide.
  • name: str
  • kernel: tuple[tuple[str, str], ...]
  • here: tuple[tuple[str, str], ...]
  • kernel_value: Callable[[str], str] = field(default=lambda value: value)
  • here_value: Callable[[str], str] = field(default=lambda value: value)
  • numbered(name: str) -> str: Return a workqueue's name as the kernel formats it: ring0 -> ring%d.
  • values(text: str, pattern: str) -> list[str]: Return the first group of every match of @p pattern in @p text, split where a match lists several.
  • local_text(path: str, root: Path) -> str: Return a file under @p root, or every file of a folder, as text.
  • source_file(path: str, pin: Release, *, cache: Path, opener: Opener | None = None) -> str: Return the pinned commit's file @p path, kept in @p cache per commit.
  • check(contracts: tuple[Contract, ...], read: Callable[[str], str], root: Path, packages: Callable[[str], str]) -> list[str]: Return the broken contracts, each as one line that names both sides.

localconfig

overpressure.api.v2.localconfig: a headset's settings in .env (source).

  • ROOT = REPO
  • EXE = ".exe" if sys.platform == "win32" else ""
  • QUOTE_PAIR = 2
  • PLACE_PARTS = 2
  • RECORDS = Path("out") / "records.json": What overpressure found out (the serials, where the backup is), by key, in the root.
  • OWNER_FILE = Path("settings.json"): The owner's settings (the app's Settings page), in the root.
  • OWNER = ("ssh_public_key", "ssh_private_key"): The settings the owner sets, by name: the same for every headset (their keys any headset's).
  • DEVELOPER: Where a program or a private file comes from: a developer's override only, never recorded.
  • RETIRED = ".env.old": What a migrated .env is kept as.
  • SHARED = ("backup", "assets"): The folders of private files in which each headset has a folder of its own (CODENAME).
  • BACKUP_MARKS = ("manifest.json", "unfinished.json"): A folder in backup/ holding one of these is a backup (finished, or a capture under way), not a headset's folder.
  • class Settings (@dataclass): The settings every headset shares; a headset adds its own fields and PREFIX.
  • PREFIX: ClassVar[str] = "OVERPRESSURE_"
  • CODENAME: ClassVar[str] = "": Its codename: each default under backup/ or assets/ is in its own folder there. Empty: the places every headset shared before, which one headset alone can use.
  • platform_tools: str = ""
  • ssh: str = "ssh"
  • ssh_keygen: str = "ssh-keygen"
  • classmethod key(cls, name: str) -> str: Return the .env key of setting NAME: the prefix and the name in capitals.
  • path(self, name: str) -> Path: Return a path setting, relative to the repository root unless absolute.
  • tool(self, name: str) -> str: Return adb or fastboot to run.
  • require(self, *names: str) -> None: Raise unless every setting of NAMES is set, naming the missing keys.
  • class DeviceSettings(Settings) (@dataclass): The settings of a headset on a stock Android bootloader: its serials, its EDL backup, the EDL tools.
  • adb_serial: str = ""
  • fastboot_serial: str = ""
  • edl_serial: str = ""
  • identity: str = "backup/device.json"
  • backup: str = "backup/stock"
  • loader: str = "assets/firehose.elf"
  • edl: str = "": empty: the fetched edl-ng (overpressure tools)
  • ncm_python: str = "": empty: this Python on Windows, which has pyusb and libusb-package
  • ssh_public_key: str = "": the owner's own public key file, enrolled besides this PC's key
  • ssh_private_key: str = "": The owner's own private key file, by its location only (never read or copied): it reaches the installed system of a headset another computer installed, where the owner's public key was enrolled.
  • edl_program(self) -> Path: Return the edl setting when set, else the fetched edl-ng, else edl-ng on PATH.
  • ncm(self) -> Path | None: Return the Python for the Windows NCM initialization.
  • own_place(value: str, codename: str) -> str: Return the place VALUE under backup/ or assets/ in CODENAME's own folder there; any other as it is.
  • parse(text: str) -> dict: Return the KEY=VALUE lines; blank lines and # comments are skipped, quotes around a value removed.
  • records(root: Path | None = None) -> dict[str, str]: Return what overpressure recorded, by key.
  • owner_settings(root: Path | None = None) -> dict: Return the owner's settings file as it is (the app keeps its own settings there too).
  • save_owner_settings(values: Mapping[str, object], root: Path | None = None) -> None: Set VALUES in the owner's settings file, keeping the rest of it.
  • record(values: Mapping[str, str], root: Path | None = None) -> None: Record VALUES by key: an owner setting goes to the owner's settings, the rest to the records.
  • update(values: Mapping[str, str], path: Path | None = None, example: Path | None = None) -> None: Record VALUES (record()); given a .env PATH, set KEY=VALUE lines there instead, keeping the rest.
  • load[S: "Settings"](cls: type[S] = Settings, path: Path | None = None, environ: Mapping[str, str] | None = None) -> S: Return the settings of class @p cls: the defaults, the records, the owner's, then .env and the environment.
  • migrate(env: Path, root: Path | None = None) -> list[str]: Move what an earlier overpressure kept in the .env ENV into ROOT's records and owner's settings.
  • retire(root: Path | None = None) -> Path | None: Migrate the .env an earlier overpressure wrote in ROOT, once, and keep it as .env.old; return that.
  • take_over(cls: type[Settings], root: Path | None = None) -> list[str]: Move what an earlier release of the headset CLS kept in the shared backup/ and assets/ into its own folders.

look

overpressure.api.v2.look: a look at a headset on USB without changing it (source).

  • PORT_SECONDS = 1.5: How long our own system's SSH port may take to answer.
  • ANSWERED = "overpressure-look": What our own system is asked over SSH, after a line of its own (ANSWERED: what SSH itself prints, such as a refused key, comes before it or alone): its first process (systemd: the installed system), whether it was started from recovery (overpressure's recovery), its battery, and the installed image's commit and flavour.
  • DENIED = "Permission denied": What ssh says when the system refuses every key offered.
  • OWN_SYSTEM
  • BUILT = "commit=": The installed image's record of the headset's tree commit it was built from (build-userspace.sh's version file).
  • FLAVOUR = "flavour=": The installed image's flavour (headset.Flavour's key); an image built before flavours has none and is SteamOS.
  • REFUSED = "look_refused": The keys our system last refused (look.Look.own_system), in the work folder, and for how long the look does not offer them again: each refused login counts against this computer (OpenSSH's PerSourcePenalties: 5 s each, enforced from 15 s, up to 10 min), and a look every few seconds would soon have it refuse every connection, a key that gets in among them.
  • REFUSED_SECONDS = 600
  • NOT_ANSWERING
  • NO_TOOLS: A headset on USB on a computer without adb, whose download failed: the reason follows.
  • NO_KEY
  • OTHER_COMPUTER: A headset another computer installed, which the owner's own key (Settings) reaches: no upgrade from here.
  • EDL_WAY_OUT = "Hold the power button for about 10 s to restart it."
  • port_open(host: str, port: int, seconds: float) -> bool: Tell whether @p host accepts a TCP connection on @p port within @p seconds.
  • fetch_tool(tool: tools.Tool) -> object: Fetch the pinned host @p tool without a word (overpressure.tools.fetch): the look's default fetch.
  • DEFAULT_FETCH: Callable[[tools.Tool], object] = fetch_tool: The fetch a look uses unless it names its own (Look.fetch); the tests' stand-in downloads nothing.
  • class Look (@dataclass): One look at the headset @p settings name; tests pass fakes for the programs, the port and the bus.
  • settings: DeviceSettings
  • work: Path: this computer's SSH key for the headset (the recovery client's work folder)
  • out: Path: the installer's records (install.OUT): what this computer installed
  • codename: str
  • runner: Callable[..., str] = run
  • port_open: Callable[[str, int, float], bool] | None = None
  • bus: Callable[[int, int], int | None] = usb_count
  • listing: Callable[[], list[tuple[int, int]]] | None = usb_ids: This system's own listing of USB devices (vendor, product), where the bus cannot be read: read once a look.
  • backup_there: Callable[[], bool] = lambda: True: whether this computer has the headset's backup (Restore)
  • clock: Timing = time
  • host: str = "172.16.42.1": our own system's address on the USB link
  • fetch: Callable[[tools.Tool], object] | None = None: Fetches a pinned host tool (None: DEFAULT_FETCH): a fresh computer has adb only once something fetched it.
  • STOCK_WITHOUT_DEBUGGING: ClassVar[UsbMode | None] = None: The maker's system with USB debugging off (its setup), and what to do then; None: it shows no such mode.
  • TURN_ON_DEBUGGING: ClassVar[str] = ""
  • STOCK: ClassVar[str] = "the stock system"
  • maker_system(self) -> Found | None: Return the maker's system when it answers over adb; None when it does not.
  • bootloader(self) -> Found | None: Return the headset in its bootloader (fastboot); None when it does not answer there.
  • edl_workflows(self) -> tuple[str, ...]: Return what fits a headset in EDL mode: the restore with this computer's backup.
  • adb_problem(self) -> str: Fetch the pinned platform-tools when this computer has no adb of its own yet; return why it failed, or "".
  • found(self, modes: tuple[UsbMode, ...], edl: UsbMode) -> Found: Return what runs on the headset, and the workflows that fit (the headset's keys: install, upgrade, ...).
  • count(self, mode: UsbMode) -> int | None: Return how many devices of @p mode are on USB: the bus, else this system's own listing; None: neither.
  • keys(self) -> list[Path]: Return the keys the look offers: this computer's, then the owner's own private key Settings names.
  • answer(self, keys: list[Path]) -> list[str]: Return our system's answer to OWN_SYSTEM over @p keys, after its ANSWERED line; [] for none.
  • refused_lately(self, keys: list[Path]) -> bool: Tell whether our system refused these very @p keys within REFUSED_SECONDS (the work folder's REFUSED).
  • own_system(self) -> Found | None: Return our own system when it answers on the USB network: installed, or overpressure's recovery.
  • adb_rows(self, adb: str) -> dict[str, str]: Return adb's devices by serial with their state (device, unauthorized, recovery, sideload, ...).

lp

overpressure.api.v2.lp: dynamic partitions: super's logical partitions, a new layout's metadata (source).

  • SECTOR = 512
  • RESERVED = 4096
  • GEOMETRY_SIZE = 4096
  • GEOMETRY_MAGIC = 0x616C4467
  • HEADER_MAGIC = 0x414C5030
  • HEADER_MAJOR = 10
  • HEADER = struct.Struct("<IHHI32sI32s"): The header's fixed part, up to its table descriptors: magic, versions, size, checksum, tables' size and checksum.
  • DESCRIPTOR = struct.Struct("<III")
  • PARTITION = struct.Struct("<36sIIII")
  • EXTENT = struct.Struct("<QIQI")
  • class LpError(ValueError): Not a super image, or metadata this reader refuses to guess about.
  • class Extent (@dataclass(frozen=True)): A run of a logical partition: @p size bytes at @p start in super, or zeros.
  • start: int
  • size: int
  • zero: bool = False
  • partitions(file: IO[bytes]) -> dict[str, tuple[Extent, ...]]: Return the logical partitions of the super image in @p file (slot 0) and their extents.
  • class LogicalPartition(io.RawIOBase): A logical partition of a super image as one seekable read-only file.
  • readable(self) -> bool: Tell io that it reads.
  • seekable(self) -> bool: Tell io that it seeks.
  • tell(self) -> int: Return the position in the logical partition.
  • seek(self, offset: int, whence: int = io.SEEK_SET) -> int: Move to @p offset (from the start, the position or the end, as @p whence says).
  • readinto(self, buffer: bytearray | memoryview) -> int: Read into @p buffer from the position on, across extents; 0 at the end.
  • GEOMETRY = struct.Struct("<II32sIII")
  • GROUP = struct.Struct("<36sIQ")
  • BLOCK_DEVICE = struct.Struct("<QIIQ36sI")
  • HEADER_SIZE = HEADER.size + 4 * DESCRIPTOR.size
  • READONLY = 1: A partition's attribute: mounted read-only.
  • class Layout (@dataclass(frozen=True)): A super partition's fixed shape: its metadata, where its logical partitions may start, its size.
  • size: int: the super partition's size in bytes
  • alignment: int
  • alignment_offset: int
  • metadata_max_size: int = 65536
  • slots: int = 2
  • block_size: int = 4096
  • first_logical_sector: int = 2048: 1 MiB: the metadata's region and the first extent's lower bound
  • name: str = "super"
  • op_list(text: str) -> tuple[str, int, list[tuple[str, int]]]: Return a full OTA's dynamic_partitions_op_list as its group, the group's maximum and its partitions' sizes.
  • build(layout: Layout, group: str, maximum: int, sizes: list[tuple[str, int]]) -> tuple[bytes, dict[str, tuple[Extent, ...]]]: Lay out @p sizes (name, bytes, in order) in one group and return super's metadata region and the extents.

ota

overpressure.api.v2.ota: a vendor's OTA: boot images and partitions, pinned members (source).

  • CHUNK = 8 * 1024 * 1024
  • CONNECTIONS = 8: Range requests one member downloads with at once: PICO's server gives each connection about 3 MB/s.
  • DOWNLOADS = 0.85: The share of an extraction's progress its downloads stand for; rebuilding the block images has the rest.
  • BLOCK = 4096
  • TRANSFER_LIST_VERSIONS = range(1, 5): The transfer list versions AOSP's block OTAs write.
  • TRANSFER_LIST_STASH_VERSION = 2: From this version on, two more header lines count the stash.
  • load_catalog(path: str | os.PathLike[str]) -> dict: Return a headset's catalog of its vendor's builds: name -> {"url": ..., ...}.
  • PROBE = 4 << 20: How much of each host fastest() reads, from the archive's middle: enough to tell 3 MB/s from 20 MB/s.
  • PROBE_SECONDS = 15: How long a host may take to answer the probe at all.
  • sources(build: Mapping[str, Any]) -> list[str]: Return a catalog build's URLs: its url, then its mirrors (the same archive on the vendor's other hosts).
  • fastest(urls: Sequence[str], size: int, log: Callable[[str], None] = print, *, probe: int = PROBE, clock: Callable[[], float] = time.monotonic) -> str: Return the URL of @p urls that serves the archive fastest, by one range of @p probe bytes from its middle.
  • stream_member(src: payload.Source, info: zipfile.ZipInfo, out: IO[bytes], log: Callable[[str], None] = print, meter: progress.Meter | None = None) -> None: Write a zip member's data into @p out, checked against its CRC-32; @p meter counts what is downloaded.
  • zip_infos(src: payload.Source) -> dict[str, zipfile.ZipInfo]: Return a zip's members by name, from its central directory.
  • read_member(src: payload.Source, name: str, log: Callable[[str], None] = print) -> bytes: Return a zip member's data, checked against its CRC-32.
  • class PinnedMember (@dataclass(frozen=True)): One file in a vendor's remote zip, pinned by its size and SHA-256.
  • url: str
  • member: str
  • size: int
  • sha256: str
  • read_pinned(item: PinnedMember, log: Callable[[str], None] = print) -> bytes: Return a pinned member's data, read from its zip over HTTP ranges (CRC-32 checked, not yet the hash).
  • fetch_pinned[P: PinnedMember](item: P, path: Path, log: Callable[[str], None] = print, read: Callable[[P], bytes] | None = None) -> Path: Put a pinned member at @p path unless it is there already; return the path.
  • fetch_boot_image(location: str, cache_dir: str | None = None, log: Callable[[str], None] = print, partition: str = "boot") -> bytes: Return the raw stock boot.img, or another partition's image such as recovery's.
  • parse_rangeset(text: str) -> list[tuple[int, int]]: Return a transfer list's range set ("4,0,10,20,30": two ranges) as (first, end) block pairs.
  • apply_transfer_list(transfer_list: str, new_data: IO[bytes], out: IO[bytes]) -> int: Rebuild a partition image from a full OTA's transfer list and its decompressed new data.
  • member_ok(path: Path, info: zipfile.ZipInfo) -> bool: Tell whether PATH holds the member already: its size and CRC-32 match.
  • download_member(src: payload.Source, info: zipfile.ZipInfo, path: Path, log: Callable[[str], None] = print, meter: progress.Meter | None = None) -> None: Download one zip member into @p path, checked against its CRC-32; keep it if it is there.
  • class BrotliReader(io.RawIOBase): A brotli stream, decompressed as it is read: a few MB in memory whatever the image's size.
  • readable(self) -> bool: Tell io that this stream can be read.
  • read(self, size: int = -1) -> bytes: Return up to @p size decompressed bytes (all that is left for -1); b"" at the end.
  • brotli_module() -> Any | None: Return the brotli package, None when this Python lacks it (plain python without uv).
  • decompressed(path: Path, package: Callable[[], Any] = brotli_module, which: Callable[[str], str | None] = shutil.which) -> Generator[IO[bytes], None, None]: Yield @p path's brotli stream decompressed: by the brotli package, else by the brotli command.
  • rebuild_image(download: Path, name: str, out_path: Path, log: Callable[[str], None] = print, *, package: Callable[[], Any] = brotli_module, which: Callable[[str], str | None] = shutil.which) -> None: Rebuild an ext4 image from NAME.new.dat.br and NAME.transfer.list.
  • sha256(path: Path) -> str: Return a file's SHA-256, in hex.
  • members_needed(copied: Mapping[str, str], block_images: Mapping[str, str]) -> Iterable[str]: Yield the OTA members a set of copied files and block images needs.
  • extract(label: str, location: str, output: Path, copied: Mapping[str, str], block_images: Mapping[str, str], *, log: Callable[[str], None] = print) -> dict: Extract a full block OTA's files into @p output.

pacman

overpressure.api.v2.pacman: pacman's repositories on any host (source).

  • class Download (@dataclass(frozen=True)): One file: where it lies in the build folder, where it comes from, and how it is checked.
  • path: str
  • url: str
  • sha256: str = ""
  • size: int = 0
  • class Database (@dataclass): A pacman repository's database: its packages by name, what each provides, and its server.
  • name: str
  • server: str
  • packages: dict[str, dict[str, list[str]]]
  • arch: str = "aarch64"
  • classmethod parse(cls, name: str, server: str, data: bytes, arch: str = "aarch64") -> Database: Read a database: a tar archive (xz, gzip, zstd aside) of NAME-VERSION/desc files.
  • by_file(self) -> dict[str, dict[str, list[str]]]: Return the packages by their file name.
  • url(self, filename: str) -> str: Return where the server has @p filename.
  • download(self, fields: dict[str, list[str]], path: str) -> Download: Return the download of a package of this database into @p path, checked by the database's SHA-256.
  • bare(dependency: str) -> str: Return a dependency's name without its version: "glibc>=2.40" -> "glibc".
  • class Packages: The packages of @p databases by name or by what they provide, the first database's where several have one.
  • find(self, wanted: str) -> tuple[str, tuple[Database, dict[str, list[str]]] | None]: Return the package that satisfies @p wanted (its name, or a provider's) and where it is.
  • closure(names: list[str], databases: list[Database]) -> list[tuple[Database, dict[str, list[str]]]]: Return @p names and everything they depend on, from @p databases (the first that has one).
  • repositories(pacman_conf: str) -> list[tuple[str, str]]: Return pacman.conf's repositories that a server outside this build serves: (name, server).
  • lock(text: str) -> list[tuple[str, str]]: Return packages.lock's entries (and SHA256SUMS'): (SHA-256, file name).
  • latest(database: Database, name: str, version_prefix: str) -> dict[str, list[str]]: Return @p database's @p name if its version starts with @p version_prefix (protobuf 25), else fail.

payload

overpressure.api.v2.payload: Android A/B OTA payloads (source).

  • PAYLOAD_MAGIC = b"CrAU"
  • OP_NAMES
  • USER_AGENT = "overpressure-build/1.0 (+payload range reader)"
  • HTTP_PARTIAL_CONTENT = 206
  • HTTP_SERVER_ERROR = 500
  • ATTEMPTS = 5
  • class Source: Random access to the bytes of a file, local or remote.
  • size: int
  • parallel = False: Whether read_at may run in several threads at once (each HTTP request is its own connection).
  • read_at(self, offset: int, length: int) -> bytes: Return LENGTH bytes from OFFSET (fewer at the end).
  • class FileSource(Source): A local file.
  • read_at(self, offset: int, length: int) -> bytes: Return LENGTH bytes from OFFSET (fewer at the end).
  • class HttpSource(Source): Random access to a remote file through HTTP Range requests.
  • BLOCK = 256 * 1024
  • parallel = True
  • read_at(self, offset: int, length: int) -> bytes: Return LENGTH bytes from OFFSET (fewer at the end), small reads through a block cache.
  • class SourceFile(io.RawIOBase): Adapter so :mod:zipfile can read the central directory of a Source.
  • readable(self) -> bool: Return True: a Source is read.
  • seekable(self) -> bool: Return True: a Source has random access.
  • tell(self) -> int: Return the position.
  • seek(self, offset: int, whence: int = io.SEEK_SET) -> int: Move the position as file objects do.
  • readinto(self, b: WriteableBuffer) -> int: Read into B from the position; return the number of bytes read.
  • class SliceSource(Source): A range of another Source, such as a member stored in a zip.
  • read_at(self, offset: int, length: int) -> bytes: Return LENGTH bytes from OFFSET (fewer at the end).
  • open_source(location: str, log: Callable[[str], None] = print) -> Source: Open a local file, or an http(s) URL through range requests.
  • payload_from(location: str, log: Callable[[str], None] = print) -> Source: Return a Source for payload.bin inside an OTA zip (or a bare payload).
  • pb_decode(buf: bytes) -> dict[int, list]: Return a protobuf message's fields by number, each a list of its values in order.
  • class Operation (@dataclass): One install operation: what to do with a blob of the payload, and where it goes.
  • type: int
  • data_offset: int
  • data_length: int
  • dst_extents: list[tuple[int, int]]
  • data_sha256: bytes | None
  • class Partition (@dataclass): A partition's new size and hash, and the operations that write it.
  • name: str
  • size: int
  • sha256: bytes | None
  • operations: list[Operation] = field(default_factory=list)
  • class Payload (@dataclass): A payload's manifest: where its data begins, and its partitions.
  • src: Source
  • block_size: int
  • data_start: int
  • partitions: dict[str, Partition]
  • PAYLOAD_VERSION = 2
  • read_payload(src: Source) -> Payload: Read a payload's header and manifest.
  • extract_partition(payload: Payload, name: str, log: Callable[[str], None] = print) -> bytes: Return partition NAME's image, written by its operations and checked against its hash.

power

overpressure.api.v2.power: this computer's power, and the headset's battery before writes (source).

  • MIN_BATTERY = 30: The least battery charge a computer off mains may have for a run that touches the headset.
  • SYSFS = Path("/sys/class/power_supply")
  • UNKNOWN = 255
  • NO_BATTERY = 128
  • class Power (@dataclass(frozen=True)): What a computer runs on: a battery or not, mains or not (None: unknown), the battery's charge.
  • battery: bool = False
  • mains: bool | None = None
  • percent: int | None = None
  • from_windows(ac_line: int, flag: int, percent: int) -> Power: Return the power from GetSystemPowerStatus's ACLineStatus, BatteryFlag and BatteryLifePercent.
  • from_sysfs(root: Path = SYSFS) -> Power: Return the power from Linux's power supplies: a system battery (not a device's) and mains or USB online.
  • from_pmset(output: str) -> Power: Return the power from macOS's pmset -g batt.
  • read() -> Power: Return this computer's power; unknown parts stay None.
  • problem(found: Power, minimum: int = MIN_BATTERY) -> str: Return why FOUND is too little for a write to the headset, or "" when it is enough.
  • battery_problem() -> str: Return why this computer's power is too little for a write to the headset, or "".
  • MIN_HEADSET_WRITE = 20: The least charge a headset may have for partition writes when it does not charge.
  • headset_refusal(reading: str, minimum: int = MIN_HEADSET_WRITE) -> str: Return why partition writes may not start on a headset's battery @p reading, or "" if they may.

prefetch

overpressure.api.v2.prefetch: a headset's downloads before an install (source).

  • MANIFEST = "manifest.txt": The pin's files in a cache, one path per line: what an install sends.
  • PACKAGE_CACHE = "root/downloads/packages": The upstream packages, beside build-userspace.sh's environment, which a new environment's unpacking would empty: build-userspace.sh links them into its package cache (its --cachedir).
  • DATABASES = "root/downloads/databases": The image's package databases, for build-userspace.sh --databases.
  • HOST = "downloads/host": The build host's databases, packages and repository, for build-on-headset.sh.
  • CHUNK = 1 << 20
  • PARALLEL = 4: Downloads at once, as pacman.conf's ParallelDownloads.
  • RETRY_SECONDS = 120: A body that breaks off is tried again for as long as overpressure's downloads try (web.RETRY).
  • Log = Callable[[str], None]
  • Opener = Callable[..., IO[bytes]]
  • local(path: str) -> str: Return the name this computer keeps @p path under: a ":" (a package's epoch) is no file name's on Windows.
  • shell_value(script: str, name: str) -> str: Return the value packages.sh gives NAME (NAME=value), with $HOLO_SNAPSHOT filled in.
  • class Prefetch: A headset's downloads for its pins into @p cache, through @p opener (web's, the tests' fake).
  • small(self, path: str, url: str) -> bytes: Return the file @p path, downloaded from @p url unless it is there.
  • archive_file(self, archive: bytes, path: str) -> str: Return the file @p path of GitHub's archive of the pinned commit.
  • definition(self, archive: bytes) -> str: Return the folder of the flavour's image definition in the pinned commit (@p archive, GitHub's).
  • plan(self) -> list[Download]: Return every file the headset's build would download for the pin, the small ones fetched already.
  • write(self, path: str, data: bytes) -> None: Write @p data to @p path unless it holds that already.
  • whole(self, item: Download) -> bool: Tell whether @p item is there with its SHA-256.
  • fetch(self, item: Download, meter: progress.Meter) -> None: Download @p item through a .part file, checked; a body that breaks off is tried again.
  • sized(self, items: list[Download]) -> list[Download]: Return @p items, each of unknown size with its Content-Length (a HEAD request), for the progress.
  • run(self) -> list[str]: Download what is missing; return the pin's files (the manifest), the cache rid of others.
  • prune(self, keep: set[str]) -> None: Remove the files of earlier pins, and parts of downloads that stopped.
  • manifest(cache: Path) -> list[str]: Return the files the last prefetch left for the pin, or none: what an install sends.

process

overpressure.api.v2.process: bounded waits and running tools (source).

  • class Final(Exception): An error that waiting does not cure: until() raises it at once instead of retrying.
  • class CommandFailed(RuntimeError): A program that exited nonzero: the message ends with its output's last part, @p output holds all of it.
  • run(argv: Sequence[str | os.PathLike[str]], timeout: float = 60, stdin: int | IO[bytes] | None = None, *, check: bool = True, log: str | os.PathLike[str] | None = None, on_line: Callable[[str], None] | None = None) -> str: Run a program from the repository root; its output goes to LOG too.
  • run_streamed(argv: Sequence[str | os.PathLike[str]], timeout: float, on_line: Callable[[str], None], *, check: bool = True, stdin: IO[bytes] | None = None) -> str: Run a program as run() does, handing each line to @p on_line as it comes; return its output.
  • class Timing(Protocol): What a wait needs: the time module, a Clock or a test's fake.
  • monotonic(self) -> float: Return a clock that only moves forward, in seconds.
  • sleep(self, seconds: float, /) -> None: Wait SECONDS.
  • class Clock (@dataclass): The time a wait uses; tests pass a fake one.
  • monotonic: Callable[[], float] = time.monotonic
  • sleep: Callable[[float], None] = time.sleep
  • until[T](what: str, seconds: float, operation: Callable[[], T], clock: Timing, interval: float = 3) -> T: Return @p operation's result once it returns.

progress

overpressure.api.v2.progress: progress lines (source).

  • PREFIX = "progress"
  • CHUNK = 1 << 20
  • FEW = {1: 10, 60: 5, 3600: 3}: What "a few" stands for, by unit: a few seconds, minutes or hours.
  • line(text: str, fraction: float | None = None) -> str: Return the progress line for @p text at @p fraction (0 to 1; None: how far is unknown).
  • say(text: str, fraction: float | None = None) -> None: Print the progress line for @p text at @p fraction, at once (the installer reads it as it comes).
  • part_line(number: int, text: str = "") -> str: Return the line that begins the task's part @p number (1 for its first) with @p text.
  • begin(number: int, text: str = "") -> None: Print the line that begins the task's part @p number (1 for its first), at once.
  • parse_part(text: str) -> tuple[int, str] | None: Return (index from 0, text) of a line that begins a part; None for any other line.
  • parse(text: str) -> tuple[float | None, str] | None: Return (fraction, text) of a progress line; None for any other line.
  • estimate_seconds(words: str) -> float | None: Return the seconds an estimate in words stands for, its upper end ("1 to 3 h": 3 h); None without one.
  • clock(seconds: float) -> str: Return @p seconds as a clock reading: 0:05, 12:34, 1:02:03.
  • duration(seconds: float) -> str: Return @p seconds in rounded words: under a minute, 4 min, 1 h 20 min.
  • class Meter: Count bytes and print a progress line for each percent they advance (and the last).
  • property fraction(self) -> float: Return how far the task is, from start to end.
  • add(self, count: int) -> None: Count @p count more bytes; print a line when a new percent of the task is reached.
  • mib(done: int, total: int) -> str: Return a byte count of a total in MiB: "1200 of 2900 MiB".
  • feed(source: IO[bytes], meter: Meter) -> Generator[int, None, None]: Yield the read end of a pipe that carries @p source, for a child's stdin, counting on @p meter.

qualcomm

overpressure.api.v2.qualcomm: Qualcomm: SoC ID, EDL, partition maps, verified writes (source).

  • EDL_USB = ("05c6", "9008")
  • EDL_MODE: EDL as a USB mode: the device edl-ng opens, which Linux grants through a udev rule and Windows through Qualcomm's serial driver (its own has none for it).
  • U32_MAX = 0xFFFFFFFF
  • chip_id(value: str) -> int: Return the SoC ID (/sys/devices/soc0/serial_number), decimal or 0x-hexadecimal, as a 32-bit number.
  • usb_count(vendor: int, product: int) -> int | None: Return how many USB devices have @p vendor and @p product, None when pyusb or libusb is missing.
  • ioreg_count(output: str, vendor: int, product: int) -> int: Count the devices in macOS's ioreg -p IOUSB -l output with @p vendor and @p product.
  • sysfs_count(root: Path, vendor: int, product: int) -> int: Count the devices under Linux's /sys/bus/usb/devices with @p vendor and @p product.
  • usb_ids(*, platform: str = sys.platform, command: Callable[[list[str], float], str] = run, sysfs: Path = Path("/sys/bus/usb/devices")) -> list[tuple[int, int]]: Return the vendor and product of each USB device in this system's own listing.
  • edl_devices(*, platform: str = sys.platform, usb: Callable[[int, int], int | None] = usb_count, command: Callable[[list[str], float], str] = run, sysfs: Path = Path("/sys/bus/usb/devices")) -> int: Return the number of attached Qualcomm EDL (9008) devices.
  • edl_command(args: argparse.Namespace, *words: str, memory: str = "ufs") -> list[str]: Return an EDL command line for edl-ng or bkerler/edl, with the device's storage type.
  • NOT_KEPT = ("cache", "rawdump", "logdump"): Partitions a backup leaves out besides userdata: Android's cache and the crash-dump areas. No install or restore writes them back, and they hold nothing of the unit's own (2.7 GiB of a PICO 4's 12.5, 0.1 of it data).
  • skipped(*, include_userdata: bool) -> list[str]: Return the partitions a backup leaves out: NOT_KEPT, and userdata unless it is asked for.
  • backup_commands(args: argparse.Namespace, done: dict[int, list[str]] | None = None) -> list[list[str]]: Return the EDL command lines of a full backup (ARGS as edl_command's, with the backup's).
  • UNFINISHED = "unfinished.json": In a backup folder while its capture is unfinished: whose backup it is (the identity), so that a later try goes on with it. The manifest takes its place once the backup is complete.
  • unfinished(folder: Path) -> dict | None: Return the identity whose unfinished backup @p folder holds, None for anything else.
  • dumped(folder: Path, lun: int) -> list[str]: Return the partitions of @p lun a stopped edl-ng backup in @p folder read whole.
  • validate_native_dump(folder: Path, luns: list[int], *, include_userdata: bool) -> None: Reject missing or truncated files against each native client's rawprogram map.
  • REQUIRED_PARTITIONS = ("abl", "boot", "devinfo"): Partitions a backup must hold an image of (a slot suffix allowed), or no manifest is written.
  • class DumpProgress: Turn edl-ng's "Dumping NAME: P% ..." display into progress lines: the partition and each tenth of it.
  • capture_backup(folder: Path, commands: list[list[str]], identity: dict, *, backend: str, luns: list[int] | None, include_userdata: bool, runner: Callable[..., str], required: Sequence[str] = REQUIRED_PARTITIONS, resume: bool = False) -> dict: Take a full EDL backup into the new folder @p folder and write its manifest; return the manifest.
  • write_verified(write: list[str], read: Callable[[str], list[str]], image: Path, *, readback: Path, backup: Path, runner: Callable[..., str]) -> None: Write @p image to a partition through EDL, read it back and compare the bytes.
  • enter_edl(adb: str, serial: str, runner: Callable[..., str], clock: Timing, *, edl_count: Callable[[], int] = edl_devices, seconds: float = 30, modes: Sequence[UsbMode] = (EDL_MODE,), denied: Callable[[], bool] | None = None) -> None: Bring the headset @p serial from Android to EDL (adb reboot edl), unless it is the one EDL device already.
  • edl_ng(program: str | Path, loader: str | Path, *words: str | Path, memory: str = "Ufs") -> list[str | Path]: Return an edl-ng command line with the device's Firehose @p loader and storage type.
  • NO_ANSWER: What that means, in plain words: a device in EDL mode opens the conversation once, right after it appears.
  • LINK_LOST: What a broken link in the middle of edl-ng's session means: its loader keeps running, but answers no new session.
  • link_lost(output: str) -> bool: Tell whether edl-ng's @p output says the link broke mid-session: a timeout or a garbled reply.
  • failed_output(exc: BaseException) -> str: Return the whole output of the command behind @p exc: an output on it or on what caused it, else its text.
  • unanswered(output: str) -> bool: Tell whether edl-ng's @p output says the device in EDL mode did not answer (a stale EDL session).
  • HANDSHAKE_SERIAL = r"(?<!Device )Serial Number:\s*": The serial edl-ng names from the device's Sahara handshake, not the loader's log of the storage's own serial ("Device Serial Number: 0x..."), which edl-ng's debug level shows in every session.
  • FIRST_SESSION_TRIES = 3: How often a read-only first session that met a device not answering yet runs, and the seconds between.
  • FIRST_SESSION_WAIT = 5.0
  • too_early(output: str) -> bool: Tell whether edl-ng's @p output says it met the device before its handshake (Windows, just after it came).
  • no_session(output: str) -> bool: Tell whether edl-ng's @p output says it got no session: a lost link, no answer, or a handshake too early.
  • first_session(session: Callable[[], str], clock: Timing, *, tries: int = FIRST_SESSION_TRIES, wait: float = FIRST_SESSION_WAIT) -> str: Return the output of a read-only @p session, run again while it met the device too early (too_early).
  • serial_shown(output: str) -> bool: Tell whether edl-ng's @p output names the device's serial.
  • fresh_edl_argv(program: str | Path, loader: str | Path) -> list[str | Path]: Return the edl-ng command that restarts the device into a fresh EDL session (Firehose's reset_to_edl).
  • reboot_argv(program: str | Path, loader: str | Path) -> list[str | Path]: Return the edl-ng command that leaves EDL with a normal restart (Firehose's reset): Android starts.
  • RESTART_SECONDS = 60: Seconds a loader may take to carry out fresh_edl_argv's restart (the PICO 4's: about 12 s, whatever the delay asked).
  • class UsbReader: Read what a device's loader still sends on its USB pipe: a computer's reading lets it carry out a reset.
  • queued(self) -> int: Read what the device's loader still sends; return the bytes read (0: nothing, or the device is gone).
  • read(self) -> int | None: Read the device's pipe until a read times out; return the bytes read, None once it has left USB.
  • drain_until_gone(clock: Timing, *, seconds: float = 60, reader: Callable[[], bool] | None = None, platform: str = sys.platform) -> bool: After a power command, read the device's pipe until it leaves USB; return whether it left in @p seconds.
  • QUIET_SECONDS = 3.0: Seconds a broken session's loader may stay silent before what it still sends counts as read (drain_session).
  • DRAIN_SECONDS = 300.0: The most a broken session's loader is read: a whole partition's readback is at most a few hundred MB.
  • com_port(output: str) -> str: Return the COM port in Get-PnpDevice's FriendlyName output ("Qualcomm HS-USB QDLoader 9008 (COM8)"), or "".
  • class ComReader: Windows: read what an EDL device's loader still sends, through Qualcomm's serial driver (its COM port).
  • find(self) -> str: Return the EDL device's COM port, or "" when Windows lists none.
  • drain_session(read: Callable[[], int], clock: Timing, *, quiet: float = QUIET_SECONDS, seconds: float = DRAIN_SECONDS) -> int: Read what a broken session's loader still sends until it stays @p quiet seconds; return the bytes read.
  • unstick(program: str | Path, loader: str | Path, runner: Callable[[list[str | Path], float], str], clock: Timing, *, read: Callable[[], int] | None = None, platform: str = sys.platform) -> int: Free a loader that a broken session left mid-transfer, and restart the device normally (reboot_argv).
  • wait_fresh_edl(edl_count: Callable[[], int], clock: Timing, *, seconds: float = RESTART_SECONDS) -> None: Wait until the device restarted by fresh_edl_argv has left USB, then is back as the one EDL device.
  • check_edl_serial(output: str, serial: str) -> None: Raise unless edl-ng's @p output names @p serial: only the configured headset may be written.
  • partition_size(backup: Path, label: str) -> int: Return a partition's size from the backup's rawprogram maps.
  • WIPED = ("userdata", "metadata"): The partitions a write-back zeroes at their start instead of writing them from the backup, as an Android restore leaves them: the system makes its data anew. userdata is not in a backup; metadata belongs to the data that is gone.
  • WIPE_BYTES = 64 << 20: How much of a WIPED partition's start is zeroed (all of a smaller one).
  • class Write (@dataclass(frozen=True)): One write of a backup's write-back: an image at a start sector of a LUN.
  • lun: int
  • label: str
  • start: int
  • sectors: int
  • sector_size: int
  • image: Path | None
  • property size(self) -> int: Return the write's size in bytes.
  • backup_lun_sectors(folder: Path, lun: int) -> int: Return a backup LUN's size in sectors from its primary GPT: the backup header's position, plus one.
  • write_back_plan(folder: Path, manifest: dict) -> list[Write]: Return a verified backup's write-back: LUN by LUN in the backup's order, each in its map's order.
  • with_images(plan: Sequence[Write], images: dict[str, Path], work: Path) -> list[Write]: Return @p plan with @p images (partition label: file) in place of the backup's images of those partitions.
  • storage_sectors(output: str) -> dict[int, int]: Return each LUN's size in sectors as the loader reports it (getstorageinfo) in edl-ng's debug output.
  • check_storage(backup: dict[int, int], device: dict[int, int]) -> None: Refuse a device whose LUNs differ from the backup's in number or size.
  • write_back(plan: Sequence[Write], program: str | Path, loader: str | Path, work: Path, runner: Callable[[list[str | Path], float], object]) -> None: Write @p plan through edl-ng (write-sector), each write read back into @p work and compared before the next.
  • edl_serial(output: str) -> str: Return the serial number edl-ng reports when it connects, or empty.
  • edl_luns(output: str) -> list[int]: Return the LUNs edl-ng's printgpt shows, the firmware LUNs first and LUN 0 (userdata's) last.

recovery

overpressure.api.v2.recovery: a headset's own systems and USB modes, the executor's side (source).

  • SSH_PORT = 22: The port the headset's own systems take SSH on.
  • ACCEPTED_KEY = "Server accepts key:": What ssh -v says of the key the headset took (refuses_this_computer).
  • REACHED = "reachable": What the headset echoes when it answers over SSH, and how long it may take to (a system that is still starting).
  • REACH_SECONDS = 60.0
  • INSTALLED = "installed.json": Written by an install: the maker's system and data are gone, a restore brings them back.
  • BUILDING = "building.json": Written as an install's build starts, before it formats the data partition and writes the system partition: a build that fails leaves the maker's system gone too, so a restore must bring all of it back.
  • INSTALL_ID = "/etc/overpressure/install-id": The installed system's identity file (on the data partition, overpressure-install keys).
  • PART_MARK = "overpressure.part=": Command-line word naming the partition a recovery image was written for (overpressure.part=recovery).
  • BOOT_ID = "/proc/sys/kernel/random/boot_id": This boot's random ID: a reboot is over once another one answers.
  • INSTALLED_PROOF: What the installed system shows: PID 1's name, its install ID and the SoC serial.
  • PREFIX_BYTES = 1 << 20: The start of an image that tells whether a partition may hold it (write_partition).
  • BUILD_SECONDS = 7200: How long the headset's build may take, and the headset's loopback port where this PC's connection is meanwhile: a SOCKS proxy (ssh -R).
  • PROXY_PORT = 1080
  • DOWNLOAD_HOSTS: What a headset's build downloads from, through this PC: the project's releases, Holo, the Frame's packages.
  • BATTERY = "/sys/class/power_supply/battery": The battery as overpressure's systems show it; below MIN_WRITE_PERCENT an install or a restore starts only on a charging battery: a headset that switches off halfway is recoverable, the write is lost.
  • MIN_WRITE_PERCENT = 20
  • RECOVERY_IMAGE = "dev-recovery.img": The recovery image a headset's image step makes in its work folder, and its record (recovery_sha256).
  • RECOVERY_RECORD = "dev-image.json"
  • BOOT_PARTITIONS = ("boot", "recovery"): Boot images written through fastboot: the recovery image to recovery, stock boot back.
  • RESTORABLE = ("boot", "recovery", "misc"): Partitions written back from the backup through fastboot.
  • RESTORE_PARTS = ("system", "data", "recovery"): The parts of an installed system's restore, in order, and the backup's images each writes.
  • RESTORE_IMAGES: dict[str, tuple[str, ...]]
  • EDL_SECONDS = 90.0: How long the headset has to show up in EDL mode after our system's restart into it, and why not.
  • EDL_NOT_REACHED
  • LINK_RETRY_SECONDS = 60: Seconds without an answer after a restart before the link gets what it needs once (link_retry).
  • SYSTEM_PART = "super": The partition the system's file system goes to (overpressure-install's OP_SYSTEM_PART).
  • installed_flavour(work: Path) -> str: Return the flavour this computer's last install into the headset's @p work folder built (INSTALLED).
  • class Profile (@dataclass(frozen=True)): A headset's names and paths for its own systems: what overpressure's runtime holds as its values.
  • stock: str: its maker's system in words ("PICO OS")
  • image_prefix: str: PREFIX in its userspace/build.sh: the label PREFIX-system, PREFIX-userspace.manifest.json
  • headset_dir: str: its folder in the build tree, as the build reads it ("devices/phoenix")
  • build_tree: tuple[str, ...]: what its build reads: overpressure's paths, then its own under headset_dir
  • host: str = "172.16.42.1": its address on the USB link (OP_IP)
  • installer: str = "overpressure-install": The recovery's writer
  • reboot: str = "reboot": The recovery's restart program (OP_REBOOT)
  • session_unit: str = "": unused: the build runs in overpressure's recovery only
  • data_part: str = "userdata"
  • data_label: str = "overpressure-data"
  • wipe_parts: tuple[str, ...] = ("userdata", "metadata"): what the way back wipes
  • run_id: str = "dev-loop": the install ID it writes, as its recovery image's run
  • download_hosts: tuple[str, ...] = DOWNLOAD_HOSTS
  • property codename(self) -> str: Return the headset's codename: its folder's name.
  • property build_dir(self) -> str: Return where the headset builds its own system: its data partition's /var/tmp.
  • class UnreachableError(RuntimeError, process.Final): The headset answers over USB neither in its maker's system, in fastboot nor in its own; the message says why.
  • unanswered(stock: str, host: str, *, linux: bool | None = None) -> str: Return why the headset cannot be restarted into fastboot, and what to check, in the owner's words.
  • unreachable(urls: Sequence[str] = DOWNLOAD_HOSTS) -> list[str]: Return the hosts of @p urls this PC gets no answer from, each with why.
  • class Modes[S: DeviceSettings]: Moves between a headset's USB modes: its bootloader (fastboot), its maker's system (adb) and our own (SSH).
  • s: S
  • clock: Timing
  • usb_modes: ClassVar[Sequence[UsbMode]] = (): Its USB modes (usbaccess), and the one of its bootloader.
  • fastboot_mode: ClassVar[UsbMode | None] = None
  • profile: Profile
  • run(self, argv: list, timeout: float = 60, *, stdin: int | IO[bytes] | None = None, check: bool = True) -> str: Run @p argv; return its output (the headset's class does).
  • until(self, name: str, seconds: float, operation: Callable[[], T]) -> T: Retry @p operation until it returns, for up to @p seconds (the headset's class does).
  • release_adb(self) -> None: Stop the adb server, which on Linux holds a headset in fastboot (the headset's class may).
  • before_leaving_stock(self) -> None: Wait until the maker's system may be left, before its restart into the bootloader (a headset's own).
  • reach(self, seconds: float = REACH_SECONDS) -> None: Return once the headset's own system answers (Recovery).
  • ssh_reboot(self, command: str) -> None: Restart the headset through its own system (Recovery).
  • in_fastboot(self) -> bool: Tell whether fastboot lists the configured headset now.
  • fastboot_listed(self) -> bool: Tell whether fastboot lists the headset now, by its whole serial.
  • start_from_fastboot(self) -> bool: Start the headset's normal boot when it waits in fastboot; tell whether it did.
  • learn_fastboot_serial(self, serial: str) -> None: Take @p serial, the one device in fastboot, as the headset's; the installer also writes it to .env.
  • fastboot(self, *words: str | Path, timeout: float = 60) -> str: Run fastboot on the configured headset; return its output. Without its serial it refuses.
  • to_fastboot(self) -> None: From the maker's system (ADB, once before_leaving_stock allows) or our own (SSH) into the bootloader.
  • class Recovery[S: DeviceSettings](Modes[S]): A headset's own systems over its USB link: SSH, the waits for them, the install, the build, the way back.
  • work: Path: this computer's key, known hosts, images and records for the headset
  • out: Path: the data root's out/: where the headset's build manifest goes
  • authenticate(self) -> None: Refuse an SSH endpoint that is not overpressure's recovery on this headset; mark it authenticated.
  • same_headset(self, serial: str) -> bool: Tell whether the SoC serial the installed system shows is this headset's.
  • partition_size(self, name: str) -> int: Return the size of partition @p name, as the headset's backup has it.
  • prepare_stock(self) -> str: Make the archive of the stock system's files (work/stock-files.tar.gz); return its manifest's SHA-256.
  • before_login(self) -> None: Do what the recovery's link needs before a login (a headset's own, after a start).
  • link_retry(self) -> None: Do what the link needs when nothing answered for a while after a restart (a headset's own).
  • check_before_install(self) -> None: Refuse an install on what the headset's running recovery shows (a headset's own).
  • installed_started(self) -> None: Record what the installed system that answers now was built from (a headset's own).
  • build_epoch(self) -> int: Return the build's time, SOURCE_DATE_EPOCH (the headset's commit's).
  • build_commit(self) -> str: Return the headset's commit as the build records it.
  • headset_folder(self) -> Path: Return the headset's folder on this computer (its tooling's parent): what Profile.headset_dir stands for.
  • build_source(self, name: str) -> Path: Return where the build tree's NAME is here: the headset's in its folder, overpressure's in CODE.
  • prefetch_cache(self) -> Path: Return this computer's copy of the headset's downloads (prefetch), laid out as its build folder.
  • owner_key(self) -> tuple[Path | None, str]: Return the owner's own public key file (None: none), and the settings key that names it.
  • recovery_ramdisk_image(self) -> Path: Return the headset's recovery ramdisk image (the runtime on its stock kernel): what image() starts from.
  • with_kernel(self, recovery: bytes, stock_path: Path) -> bytes: Return the recovery image @p recovery with the headset's own kernel for it; as it is by default.
  • kernel_record(self) -> dict[str, str]: Return what the recovery image's record says of its kernel (with_kernel's).
  • stock_recovery(self) -> tuple[Path, bytes]: Return the stock recovery partition's image from the backup, checked against its manifest.
  • authorize_fastboot(self) -> None: Send the bootloader's per-session authorization for a write, where the headset's needs one.
  • stock_partition(self, name: str) -> tuple[Path, dict]: Return a partition's image in the backup and its manifest entry.
  • stock_boot(self) -> tuple[Path, dict]: Return the stock boot image of the backup and its manifest entry.
  • wait_stock(self, seconds: float = 300) -> str: Wait until the maker's system has booted; return its build fingerprint (edl.QualcommHeadset).
  • first_start_boot(self, stock: Path) -> Path: Return the boot image of the stock system's debug start after a restore, made from its own @p stock one.
  • enter_edl(self) -> None: Bring the headset from the maker's system into EDL mode (edl.QualcommHeadset).
  • edl_count(self) -> int: Return how many EDL devices are on USB (edl.QualcommHeadset's).
  • image(self) -> None: Build the recovery image for recovery (dev-recovery.img) and the test boot image in the work folder.
  • ssh_argv(self, command: str) -> list: Return the ssh command line that runs @p command on the headset.
  • ssh_keys(self) -> list[Path]: Return the keys SSH offers: this computer's, then the owner's own private key that Settings names.
  • refuses_this_computer(self) -> bool: Tell whether the headset's own system answers on its link but takes no key of this computer's.
  • ssh(self, command: str, timeout: float = 30, stdin: int | IO[bytes] | None = None, *, check: bool = True) -> str: Run @p command on the headset; return its output.
  • ssh_reboot(self, command: str) -> None: Run @p command, which restarts the headset; the USB link goes down with it.
  • answers(self) -> bool: Tell whether the headset's own system (the recovery or the installed system) answers over SSH now.
  • reach(self, seconds: float = REACH_SECONDS) -> None: Return once the headset's own system answers over SSH, for a restart through it.
  • installed_running(self) -> bool: Tell whether the installed system answers over SSH now: its PID 1 is systemd (the recovery's is not).
  • enrolled_keys(self) -> bytes: Return the installed system's authorized_keys.
  • write_keys(self) -> None: Write the enrolled keys and the install ID to the data partition (the installer keys).
  • write_stock(self, want: str | None = None) -> None: Write the stock system's files to the data partition (the installer's stock) unless it holds them already.
  • connect(self, *, flashed: bool = True) -> str: Log in to the running recovery; return the partition it started from, checked by readback.
  • holds_dev_image(self) -> bool: Tell whether recovery holds out/dev's current dev image, read back from the running recovery.
  • check_battery(self) -> None: Refuse partition writes on an almost empty battery that does not charge (power.headset_refusal).
  • write_partition(self, name: str, image: Path, timeout: int, meter: progress.Meter | None = None) -> None: Stream an image (the installed system's boot image) to its partition through overpressure's recovery.
  • build_tree(self, target: IO[bytes], packages: Path | None = None, prefetched: Sequence[str] = (), cache: Path | None = None, flavour: str = "") -> None: Write what the headset's build reads (Profile.build_tree, build_source) as a gzip-compressed tar.
  • prefetched(self, cache: Path | None = None) -> list[str]: Return this PC's downloads for the headset (prefetch_cache): all of them go with the build.
  • tree_stream(self, packages: Path | None, prefetched: Sequence[str], cache: Path | None = None, flavour: str = "") -> Generator[IO[bytes], None, None]: Yield the read end of a pipe that carries build_tree's tar, written as it is read: no copy on disk.
  • build_on_headset(self, packages: Path | None = None, *, send_downloads: bool = True, flavour: str = "") -> dict: Build the system on the headset itself, from overpressure's recovery, and put it in super.
  • install_inputs(self, boot: Path) -> None: Check what the install needs from this PC before anything is written: the boot image, the downloads.
  • half_inputs(self, boot: Path, only: str) -> None: Check what install's half @p only needs before anything is written (the whole: install_inputs).
  • format_userdata(self, *, always: bool) -> None: Format userdata from overpressure's recovery when it holds no data yet, or @p always.
  • install(self, *, format_data: bool = False, boot: Path | None = None, packages: Path | None = None, send_downloads: bool = True, only: str = "", flavour: str = "") -> None: Install from overpressure's recovery, then start the installed system.
  • installed_flavour(self) -> str: Return the flavour this computer's last install built (installed_flavour).
  • build_system(self, *, format_data: bool, packages: Path | None, send_downloads: bool, flavour: str = "") -> None: Build the system on the headset into super and record it (INSTALLED): the install's first half.
  • remove_build(self) -> None: Remove the headset's build folder, once the installed system runs: the install leaves nothing of it.
  • normal(self) -> None: From overpressure's recovery into the installed system: clear the recovery request.
  • installed(self) -> None: Connect to the running installed system (after a reboot, or a power-on away from the PC).
  • recovery(self) -> None: Start overpressure's recovery, which then stays until "dev normal".
  • wait_installed(self, previous_boot: str = "") -> None: Wait for the installed system's systemd, reached over the USB link.
  • boot_id(self) -> str: Return the running boot's random ID.
  • started(self, previous_boot: str = "") -> str: Return what started after a reboot of an installed headset.
  • wipe_data(self) -> None: Wipe the data partitions (Profile.wipe_parts), then clear misc's recovery request (a restore's data part).
  • recovery_running(self) -> bool: Tell whether this computer's recovery answers now, started from the recovery partition and authenticated.
  • to_edl(self) -> None: From the stock system (ADB, as enter_edl) or our own (SSH) into EDL mode, as the one EDL device there.
  • again_in_edl(self) -> None: Enter EDL mode again after free_edl's normal restart, from the stock system or our own systems (to_edl).
  • check_boot_partition(self, image: Path, name: str = "boot") -> None: Run the acceptance runner's checks before it writes a boot image.
  • flash_boot(self, image: Path, name: str = "boot") -> None: Write a boot image to boot or recovery, then start that partition's image.
  • restore_partition(self, name: str, *, reboot: bool = True) -> None: Write a partition back from the backup through fastboot.
  • flash(self) -> None: Write the dev image to recovery, where it starts as overpressure's recovery.
  • reboot(self) -> None: Reboot the headset, also from fastboot, where a device deadline leaves it; no flash needed.
  • restore(self, *, installed: bool = False, only: str | None = None, debug_start: bool = False) -> None: Leave the loop: the backup's stock boot image, then the stock system. ABL stays engineering.
  • restore_installed(self, only: str | None = None, *, debug_start: bool = False) -> None: Bring back the stock system as the backup has it, from overpressure's recovery.
  • class QualcommRecovery[S: DeviceSettings](edl.QualcommHeadset[S], Recovery[S]): A Qualcomm headset's recovery client: its adb and EDL steps (edl.QualcommHeadset) with its own systems.
  • again_in_edl(self) -> None: Enter EDL mode again after free_edl's normal restart, from the stock system or our own (Recovery's).
  • class InRun[S: DeviceSettings](Modes[S]): A headset's recovery client inside an installer task: replug asks, the serials it learns recorded.
  • ctx: install.Context
  • WAITS: ClassVar[dict[str, str]]: The client's waits in the owner's words.
  • link_problem(self) -> str: Return why the headset's USB link is up without its address, and the fix; empty when it is not.
  • until(self, name: str, seconds: float, operation: Callable[[], T]) -> T: Wait as install.replug_until does: a replug asked for when it runs out.
  • learn_fastboot_serial(self, serial: str) -> None: Take the one device in fastboot as the headset, and record its serial.

recovery_ramdisk

overpressure.api.v2.recovery_ramdisk: an Alpine recovery in a stock boot image (source).

  • RUNTIME = Path(__file__).resolve().parent / "runtime": overpressure's headset runtime: the files a recovery takes under its headset's overlay (Spec.runtime).
  • REQUIRED_CONFIG: Kernel options every recovery relies on (checked against the stock kernel's IKCONFIG).
  • BOOT_HEADER_V3 = 3: The first boot image header version without the SHA-1 id mkbootimg writes.
  • BUSYBOX_EXTRAS_APPLETS: busybox-extras' applet links, normally created by its post-install script.
  • class Spec (@dataclass(frozen=True)): What a headset's recovery is made of.
  • overlay: Path: the headset's files for the root (its initramfs/)
  • packages: Sequence[str] = (): Alpine packages, resolved with their dependencies
  • files: Mapping[str, Path] = field(default_factory=dict): root path -> prebuilt executable
  • required_config: Mapping[str, str] = field(default_factory=lambda: dict(REQUIRED_CONFIG))
  • alpine_branch: str = "v3.24"
  • alpine_version: str = "3.24.2"
  • alpine_repos: tuple[str, ...] = ("main", "community")
  • arch: str = "aarch64"
  • runtime: bool | None = None: overpressure's runtime (RUNTIME) under the overlay: the recovery's /init, PID 1, services, USB gadget, block policy, recovery deadline and shared library. The headset's overlay then gives its own files and its values in etc/overpressure/headset (docs/internals/runtime.md). None: as the headset's interface has it (on from 1.8, headset.RUNTIME_SINCE, by the headset.json at or above the overlay); True or False decides.
  • takes_runtime(spec: Spec) -> bool: Return whether SPEC's the recovery takes overpressure's runtime: as it says, else by its headset's interface.
  • analyse(label: str, data: bytes, interesting_config: Iterable[str] = ()) -> tuple[dict, bootimg.BootImage, kernelinfo.KernelInfo, list[tuple[str, cpio.Node]]]: Return (report dict, BootImage, KernelInfo, stock ramdisk cpio entries).
  • print_report(rep: dict, log: Callable[[str], None] = print) -> None: Log the summary of a report of analyse().
  • check_requirements(kinfo: kernelinfo.KernelInfo, required: Mapping[str, str]) -> list[str]: Return what the stock kernel lacks of REQUIRED ("A|B" accepts either option).
  • build_rootfs(spec: Spec, cache: str, stock_entries: Iterable[tuple[str, cpio.Node]], build_info: dict, *, minimal: bool = False, log: Callable[[str], None] = print) -> cpio.Tree: Build the recovery root.
  • kernel_cmdline(stock: bootimg.BootImage, cmdline_append: Iterable[str]) -> list[str]: Return the stock kernel arguments with @p cmdline_append added (each once).
  • assemble(stock: bootimg.BootImage, ramdisk: bytes, cmdline_append: Iterable[str]) -> bytes: Return the stock boot image with the new ramdisk and the kernel arguments appended.
  • add_overlay(tree: cpio.Tree, root: str | os.PathLike[str]) -> None: Add a directory's files to the tree.
  • prepare_image(source: Path, folder: Path, run_id: str, public_key: bytes, *, connect_timeout: int = 210, test_timeout: int = 900) -> dict: Write the test boot image: the recovery ramdisk image with this run's key, ID and device deadlines.

roles

overpressure.api.v2.roles: the building blocks of a headset's workflows (source).

  • NOTHING_CHANGED = "Nothing was changed on your headset.": What a failure in a task that changes nothing says, unless it says more itself.
  • AGAIN = "Start the installer again to go on where it stopped."
  • UNCHANGED = NOTHING_CHANGED + " " + AGAIN
  • CHECK_WHERE: Where a check that failed leaves the headset.
  • PLUG_IN_SECONDS = 600: How long the owner has to plug in and allow USB debugging, and to set the maker's system up again.
  • SETUP_SECONDS = 1800
  • EDL_WHERE: Where a failure over EDL leaves the headset, in the stock system's words (a headset words its own).
  • STALE_EDL_WHERE
  • LINK_LOST_WHERE
  • part_task(part: str) -> str: Return the id of the restore's task that writes its @p part (dev restore --only PART).
  • STOCK_RAN = "pico-os": What the restore's task that starts overpressure's recovery remembers of where it found the headset: the stock system ran (its writes are not needed), it could not start it (its stock bootloader first), only EDL mode (the whole backup over EDL); and what the stock bootloader's first write records.
  • STOCK_STUCK = "pico-os-stuck"
  • EDL_ONLY = "edl"
  • BOOTLOADER_WRITTEN = "written"
  • OWNER_KEY = "owner-key.pub": The owner's own SSH public key, as the install keeps it in the work folder (Settings names it).
  • computer_problems(found: Sequence[Check]) -> str: Return the doctor's failed checks as one message with their fixes.
  • newer(output: Path, *inputs: Path) -> bool: Tell whether @p output is there and not older than any of @p inputs that are there (folders: their files).
  • reach_ask() -> Ask: Return the restore's question how it reaches a headset another computer installed: a key, or by hand.
  • class Roles[S: DeviceSettings]: The tasks a headset's plan shares; the headset's plan derives from it and names what is its own.
  • settings_class: type[S]: The headset's settings class (its .env keys), its USB modes and its maker's system's adb mode.
  • usb_modes: Sequence[UsbMode] = ()
  • adb_mode: UsbMode | None = None
  • PROVIDED: ClassVar[set[str]] = {".env"}: What the installer finds out and writes itself, so the doctor's check of it does not count; what the installer does not need of the doctor's checks.
  • NOT_INSTALLED: ClassVar[set[str]] = {doctor.BUILDS}
  • PLUG_IN: ClassVar[Ask | None] = None: The ask find waits on, and the maker's system's name in its words.
  • STOCK: ClassVar[str] = "the stock system"
  • EDL_WHERE: ClassVar[str] = EDL_WHERE: What a failure over EDL says of where the headset is (EDL_WHERE and the others), in the headset's words.
  • STALE_EDL_WHERE: ClassVar[str] = STALE_EDL_WHERE
  • LINK_LOST_WHERE: ClassVar[str] = LINK_LOST_WHERE
  • RESTORE_PLUG_IN: ClassVar[Ask | None] = None: The restore's ask to plug in, what it tells of a headset an install left early, one that cannot start the stock system and one in EDL mode only; the ask to enter EDL mode by hand; how long it waits for each.
  • STOPPED_EARLY: ClassVar[str]
  • STUCK: ClassVar[str]
  • EDL_RESTORE: ClassVar[str]
  • EDL_BY_HAND: ClassVar[Ask | None] = None
  • LEAVE_FASTBOOT_SECONDS: ClassVar[float] = 30
  • BACK_IN_FASTBOOT_SECONDS: ClassVar[float] = 120
  • EDL_SECONDS: ClassVar[float] = 180
  • newer = staticmethod(newer)
  • client(self, ctx: Context) -> Recovery: Return the headset's recovery client for a task's @p ctx: its waits ask for a replug (InRun).
  • link(self, ctx: Context) -> Recovery: Return the headset's recovery client for one command over its link, without a task's waits.
  • before_edl(self, ctx: Context, settings: S) -> None: Wait until the maker's system may leave for EDL mode (a headset's own: its MCU, say).
  • saved_identity(self, ctx: Context) -> dict: Return the headset's saved identity record (its probe's), which a backup's manifest names.
  • backup_there(self, ctx: Context) -> bool: Tell whether the settings name a complete backup of this headset.
  • capture_backup(self, ctx: Context, settings: S, folder: Path, luns: list[int], *, resume: bool = False) -> None: Read every partition but userdata of @p luns into @p folder; @p resume goes on.
  • verify_backup(self, ctx: Context, folder: Path) -> None: Check every file of the backup in @p folder against its manifest.
  • step_values(self, ctx: Context, key: str) -> dict[str, str]: Return the values of the headset's step @p key as this run sets them (its parameters' defaults else).
  • argv(self, ctx: Context, key: str) -> list[str]: Return the headset's step @p key as this host runs it.
  • command(self, *words: str | Path) -> list[str]: Return a command of the headset's command line (one that is no step of the window).
  • step_task(self, key: str, title: str, estimate: str, *, done: Callable[[Context], bool] | None = None, where: str = "", parts: tuple = ()) -> Task: Return a task that runs the headset's step @p key (it writes to the headset when the step does).
  • run_step(self, ctx: Context, key: str) -> None: Run the headset's step @p key.
  • out(self, *parts: str) -> Path: Return a path under the data root's out/.
  • static tools_there(_ctx: Context) -> bool: Tell whether this host's pinned tools are fetched.
  • check_computer(self, ctx: Context) -> None: Run the doctor's checks; what the installer does not provide itself and fails stops the run.
  • find(self, ctx: Context, ask: Ask | None = None, *, instruct: bool = False, waiting: str = "") -> None: Ask the owner to plug in (@p ask, PLUG_IN); wait for exactly one adb device and record its serial.
  • static consented(ctx: Context, later: Sequence[str]) -> bool: Tell whether the consent is needed no more: every write it covers is done.
  • prepared(self, ctx: Context) -> bool: Tell whether the headset was prepared before this run: this computer's recovery answers on it.
  • flashed(self, ctx: Context) -> bool: Tell whether the flash is done: the headset was prepared and recovery holds this run's recovery image.
  • flash_task(self, title: str, where: str) -> Task: Return the task that writes this version's recovery to recovery and starts it (the flash step).
  • start_recovery_task(self, title: str, where: str) -> Task: Return the flash and the login as one task: this version's recovery, started.
  • connect_task(self, where: str) -> Task: Return the task that logs in to overpressure's recovery the flash started, here; it only reads.
  • static wifi(ctx: Context) -> None: Ask for Wi-Fi now, so the owner can leave during the install: the answer in memory, a skip in the state.
  • ssh_key(self, ctx: Context) -> None: Ask for the owner's own SSH public key: a file the settings name, which the install adds to its keys.
  • wifi_profile(self, ctx: Context) -> None: Write the Wi-Fi profile to the installed system over SSH: the keyfile on stdin, never in an argv.
  • check_part_task(self, part: str, title: str, estimate: str) -> Task: Return one row of the check workflow's checklist: the check step's @p part.
  • check_part(self, ctx: Context, part: str) -> None: Run the check step's @p part as the installer's check; show the warnings its result records.
  • acceptance_checks(self, ctx: Context) -> None: Run the check step whole as the installer's check; show the warnings its result records.
  • static warnings(run: Path) -> list[str]: Return the warnings a check run's result.json records.
  • enter_edl(self, ctx: Context, settings: S) -> None: Bring the headset from the stock system to EDL, unless it is the one EDL device already.
  • free_edl(self, ctx: Context, settings: S) -> None: Free the EDL device's loader, restart into the stock system and enter EDL mode afresh; nothing is written.
  • backup(self, ctx: Context) -> None: EDL, its partition table for the LUNs and the serial, then a full backup without userdata, verified.
  • backup_folder(self, ctx: Context) -> bool: Choose the backup's folder: this headset's unfinished one goes on (True), any other stays as it is.
  • unfinished_here(self, ctx: Context) -> bool: Tell whether .env's backup folder holds this headset's unfinished backup, which can go on.
  • stock_running(self, ctx: Context) -> bool: Tell whether the headset .env names answers adb now: the stock system runs, its system is stock already.
  • restore_start_recovery(self, ctx: Context) -> None: Start overpressure's recovery from wherever the headset is, for the restore's writes (dev recovery).
  • reach_in_edl(self, ctx: Context, dev: Recovery) -> None: Bring a headset another computer installed into EDL mode, for the whole backup over EDL.
  • back_in_fastboot(self, ctx: Context, dev: Recovery) -> bool: Tell whether the headset, started from fastboot, comes back to it instead of starting the stock system.
  • edl_by_hand(self, ctx: Context) -> None: Have the owner put the headset into EDL mode, unless it is the one EDL device already; wait for it.
  • install_stopped_early(self) -> bool: Tell whether this computer's install stopped before it wrote overpressure's recovery, and none finished.
  • recovery_started(self, ctx: Context) -> bool: Tell whether the restore needs no recovery (done, or the stock system is there) or one runs.
  • restore_part(self, part: str, *options: str) -> Callable[[Context], None]: Return the task that writes the restore's @p part from the backup (dev restore --only PART @p options).
  • static restore_written(part: str) -> Callable[[Context], bool]: Return the done check of the restore's @p part: written in an earlier run, or not needed (stock, EDL).

runner

overpressure.api.v2.runner: a step's command line (source).

  • process(headset: Headset, step: Step, values: dict[str, str], *, python: str = sys.executable) -> list[str]: Return the argv that runs @p step with @p values; its working directory is the repository.
  • stop(proc: subprocess.Popen, argv: list[str]) -> None: End a step's program @p proc; a build's container first, which outlives a client that is killed.
  • display(argv: list[str], platform: str = sys.platform) -> str: Return the command line as one would type it in this host's terminal.
  • run(argv: list[str], output: Callable[[str], None], started: Callable[[subprocess.Popen], None] | None = None) -> int: Run @p argv from the repository root, handing each line of its output to @p output; return its exit status.

ssh

overpressure.api.v2.ssh: SSH with the project's key (source).

  • argv(ssh: str, key: Path | Sequence[Path], known_hosts: Path, target: str, command: str, *, connect_timeout: int = 5) -> list: Return the ssh command line that runs @p command on @p target (user@host), batch mode, keys only.
  • PRIVATE_KEY_MOST = 64 << 10: The most a private key file holds (a 16384-bit RSA key in OpenSSH's format is under 13 kB).
  • private_key_problem(path: Path) -> str: Return why @p path cannot be the owner's private key file, or "": by its location alone, never read.
  • is_public_key(line: bytes) -> bool: Tell whether LINE is one OpenSSH public key (not a private one): what authorized_keys takes.
  • authorized_keys(this_pc: bytes, extra: Path | None, setting: str) -> bytes: Return the authorized_keys a headset's image enrolls: this PC's key, and those of @p extra.
  • PUBLIC_KEY: The ask for the owner's own public key, which a headset's install enrolls beside this computer's.
  • NO_PUBLIC_KEY
  • ask_public_key(ctx: Context) -> str: Ask for the owner's own public key until the answer is one; return its line, empty for none.

storage

overpressure.api.v2.storage: the read-only storage policy (source).

  • BLOCK_FIELDS = 3: A row of the storage inventory: BLOCK, the device's name and its read-only flag.
  • MOUNT_FIELDS = 6: A row of /proc/mounts: device, mount point, type, options, dump and pass.
  • MOUNT_POINT = 1
  • DATA = "/data": Where an installed system mounts its data partition.
  • validate_storage(output: str, data: str = "") -> None: Require every physical block device read-only, except the installed system's data partition.
  • data_device(mounts: str, mount_point: str = DATA) -> str: Return the block device (sda16) mounted at @p mount_point, or empty.
  • validate_mounts(output: str, *, installed: bool = False, data: str = DATA) -> None: Refuse a writable device-backed mount: the recovery runs from RAM, the installed system read-only.

tools

overpressure.api.v2.tools: the pinned host tools (source).

  • CACHE = REPO / "cache" / "tools"
  • EXE = ".exe" if sys.platform == "win32" else ""
  • class Archive (@dataclass(frozen=True)): A tool's archive for one host, pinned by its SHA-256.
  • url: str
  • sha256: str
  • class Tool (@dataclass(frozen=True)): A pinned host tool: its archive per host and the programs in it.
  • name: str
  • version: str
  • archives: dict[str, Archive]: host key (see host_key) -> archive
  • programs: dict[str, str]: program name -> path inside the unpacked archive
  • archive(self, host: str | None = None) -> Archive | None: Return the archive for HOST (this host by default), None if there is none.
  • property folder(self) -> Path: Return where the tool is unpacked.
  • host_key() -> str: windows-x86_64, linux-aarch64, darwin-arm64, ...: the archive a tool needs here.
  • PLATFORM_TOOLS
  • EDL_NG
  • ARCHIVE_TOOLS = {tool.name: tool for tool in (PLATFORM_TOOLS, EDL_NG)}
  • installed(tool: Tool) -> bool: Tell whether TOOL is unpacked from this host's pinned archive.
  • program(name: str) -> Path | None: Return a fetched program (adb, fastboot, edl-ng), or None when it is not fetched.
  • download(url: str, sha256: str, log: Callable[[str], None] = print, opener: Callable = web.open_once) -> bytes: @p url's content, which must hash to @p sha256 (else ValueError; nothing is kept).
  • fetch(tool: Tool, log: Callable[[str], None] = print, opener: Callable = web.open_once) -> Path: Download and unpack @p tool for this host unless it is there; return its folder.
  • main(argv: list[str] | None = None) -> int: Fetch the named tools (this host's by default).

usbaccess

overpressure.api.v2.usbaccess: USB access on Linux and Windows, a headset's USB modes (source).

  • RULE_DIRS: Where udev reads rules; a file in an earlier folder hides one of the same name in a later one.
  • SEAT_LATE = "73-seat-late.rules": uaccess takes effect only when tagged before this file, which turns the tag into the user's access.
  • SYSFS = Path("/sys/bus/usb/devices")
  • DEV = Path("/dev/bus/usb")
  • OS_RELEASE = Path("/etc/os-release")
  • NO_PERMISSIONS = "no permissions": What adb and fastboot print for a device they may not open.
  • TRIGGER = "sudo udevadm trigger": Applies the rules to devices that are already connected.
  • GRACE = 6.0: Seconds a device may stay without access after it appears: udev grants it a moment later.
  • PACKAGES: The Android udev rules by distribution (os-release ID or ID_LIKE): the package and the file it installs.
  • OWN_RULES = "/etc/udev/rules.d/70-overpressure.rules": Where the fix's own rule goes when no package covers a mode.
  • class UsbMode (@dataclass(frozen=True)): One way a headset appears on USB: a name for the owner, its vendor and product IDs (hex).
  • name: str
  • vendor: str
  • product: str
  • access: bool = True
  • storage: bool = False
  • label: str = ""
  • driver: str = ""
  • rule(self) -> str: Return the udev rule that grants the logged-in user this mode's device.
  • storage_rule(self) -> str: Return the udev rule that turns off udev's watch on this mode's drives.
  • class NoAccessError(PermissionError, Final): The user may not use a connected device of the headset; the message says what to install.
  • rule_files(dirs: Sequence[Path] = RULE_DIRS) -> list[Path]: Return the rule files udev reads, in its order: by name, an earlier folder's file hiding a later one's.
  • granted(mode: UsbMode, files: Iterable[Path], groups: Iterable[str] = ()) -> bool: Tell whether the rules in @p files let this user open @p mode's device.
  • unwatched(mode: UsbMode, files: Iterable[Path]) -> bool: Tell whether the rules in @p files turn off udev's watch on @p mode's drives.
  • user_groups() -> list[str]: Return the names of this process's groups; none where there are no POSIX groups (Windows).
  • distribution(path: Path = OS_RELEASE) -> list[str]: Return this system's distribution and the ones it is like (os-release ID, then ID_LIKE).
  • fix(missing: Sequence[UsbMode], *, release: Path = OS_RELEASE, files: Sequence[Path] = (), watched: Sequence[UsbMode] = ()) -> str: Return what the owner runs so that @p missing modes are granted and @p watched modes' drives unwatched.
  • missing_modes(modes: Sequence[UsbMode], *, dirs: Sequence[Path] = RULE_DIRS, groups: Iterable[str] | None = None) -> tuple[list[UsbMode], list[Path]]: Return the modes a tool opens that no installed rule grants this user, and the rule files read.
  • watched_modes(modes: Sequence[UsbMode], files: Iterable[Path]) -> list[UsbMode]: Return the modes carrying a drive whose udev watch no installed rule turns off.
  • device_files(vendor: str, product: str, sysfs: Path = SYSFS, dev: Path = DEV) -> list[Path]: Return the device files of the connected USB devices with @p vendor and @p product (Linux).
  • denied(mode: UsbMode, *, sysfs: Path = SYSFS, dev: Path = DEV, access: Callable[[Path], bool] | None = None) -> list[Path]: Return the connected devices of @p mode this user may not write (always none off Linux).
  • listing_denied(output: str) -> bool: Tell whether adb's or fastboot's device list shows a device it may not open.
  • unusable(output: str, mode: UsbMode) -> bool: Tell whether adb's or fastboot's listing (@p output) leaves out a device of @p mode this user may not use.
  • seen(modes: Sequence[UsbMode], *, platform: str = sys.platform, sysfs: Path = SYSFS, dev: Path = DEV) -> str: Return what this computer's USB bus holds of a headset's @p modes (Linux), for a log; else empty.
  • message(mode: UsbMode, modes: Sequence[UsbMode], *, dirs: Sequence[Path] = RULE_DIRS, release: Path = OS_RELEASE) -> str: Return why a connected device of @p mode cannot be used, and the fix, in plain words.
  • guard(runner: Callable[..., str], modes: Sequence[UsbMode], tools: dict[str, UsbMode], clock: Timing, grace: float = GRACE) -> Callable[..., str]: Return @p runner, with adb's and fastboot's "no permissions" turned into NoAccessError.
  • class Denial (@dataclass): A device without access, said only once it has stayed so for GRACE s (udev grants a moment late).
  • clock: Timing
  • grace: float = GRACE
  • since: float | None = None
  • see(self, is_denied: bool, text: Callable[[], str]) -> None: Record whether the device is denied now; raise NoAccessError with @p text once it stayed so.
  • require(mode: UsbMode, modes: Sequence[UsbMode], clock: Timing, *, grace: float = GRACE, denied_now: Callable[[], bool] | None = None) -> None: Return once a connected device of @p mode may be used; raise NoAccessError if it stays denied for @p grace s.
  • INF_DIR = Path(os.environ.get("WINDIR", "C:/Windows")) / "INF": Where Windows keeps the driver packages installed beside its own, each as oem.inf.
  • hardware_id(mode: UsbMode) -> str: Return the hardware ID Windows matches a driver to for @p mode's device: USB, then VID_xxxx&PID_yyyy.
  • inf_text(path: Path) -> str: Return an INF file's text: UTF-16 after its byte order mark, else read byte by byte (IDs are ASCII).
  • missing_drivers(modes: Sequence[UsbMode], *, inf: Path | None = None) -> list[UsbMode]: Return the modes that need a driver (UsbMode.driver) and that no installed driver package names (Windows).
  • LISTING: Callable[[list[str], float], str] = run: What runs Windows' device listing (PowerShell's Get-PnpDevice) for driverless; the tests list no device.
  • driverless(mode: UsbMode, *, platform: str = sys.platform, command: Callable[[list[str], float], str] | None = None) -> int: Return how many connected devices of @p mode Windows holds without a working driver; 0 elsewhere.
  • driver_message(mode: UsbMode) -> str: Return, in plain words, that Windows has no driver for the headset in @p mode, and the fix.

overpressure.api.v2.usblink: a headset's USB network link on a Linux computer (source).

  • SYS_NET = Path("/sys/class/net")
  • Run = Callable[[Sequence[str]], "tuple[int, str]"]: Runs a program and returns its exit status and output; tests pass a fake.
  • class Gadget (@dataclass(frozen=True)): A headset's USB network gadget: its IDs and product string, its network, the lease, the fix's profile.
  • vendor: str: hex, as sysfs writes it ("1d6b")
  • product: str
  • label: str: the USB product string, which narrows generic IDs to the headset
  • network: str: the headset's network ("172.16.42.0/24")
  • host_ip: str: the one lease it hands this computer
  • profile: str: NetworkManager's profile the fix adds ("overpressure-CODENAME")
  • in_network(self, address: str) -> bool: Tell whether @p address (with its prefix) lies in the headset's network.
  • run_quietly(argv: Sequence[str]) -> tuple[int, str]: Run a query (ip, nmcli) for at most 10 s; return its exit status and output, (127, "") when it cannot run.
  • class Link (@dataclass(frozen=True)): The headset's network interface on this computer: its name, MAC, IPv4 addresses, NetworkManager's profile.
  • name: str
  • mac: str
  • addresses: tuple[str, ...]
  • profile: str: the profile NetworkManager put on it; empty when none, or without NetworkManager
  • usb_device(interface: Path) -> Path: Return the USB device folder of the network interface folder @p interface (its device is a USB interface).
  • interfaces(gadget: Gadget, net: Path = SYS_NET, device: Callable[[Path], Path] = usb_device) -> list[str]: Return the network interfaces of @p gadget, by name (Linux; none elsewhere).
  • addresses(name: str, run: Run) -> tuple[str, ...]: Return @p name's IPv4 addresses with their prefix (ip -j), empty when there are none or ip cannot tell.
  • profile(name: str, run: Run) -> str: Return the NetworkManager profile active on @p name, empty when none or without NetworkManager.
  • links(gadget: Gadget, net: Path = SYS_NET, run: Run = run_quietly, device: Callable[[Path], Path] = usb_device) -> list[Link]: Return @p gadget's network interfaces on this computer, each with its addresses and profile.
  • fix(gadget: Gadget, link: Link, *, nmcli: bool) -> str: Return the commands that give @p link the headset's lease, for a terminal.
  • problem(gadget: Gadget, found: Sequence[Link] | None = None, *, platform: str = sys.platform, nmcli: bool | None = None) -> str: Return why the headset's USB link is up without its address, and the fix, in the owner's words; else empty.

web

overpressure.api.v2.web: HTTPS downloads (source).

  • USER_AGENT = "overpressure"
  • RETRY_SECONDS = 120: How long a short outage is tried again before a download fails, and the waits between the tries.
  • FIRST_WAIT = 2
  • LONGEST_WAIT = 30
  • TRANSIENT_STATUS = frozenset({408, 429, 500, 502, 503, 504}): Answers that a later try may not get: a timeout, too many requests, the server's own trouble.
  • Opener = Callable[..., IO[bytes]]
  • Request = urllib.request.Request: The request type, so that a caller needs no urllib of its own.
  • class DownloadError(OSError): A request that failed for good: the message names its URL and why; status is the HTTP status, if any.
  • context() -> ssl.SSLContext: Return the TLS context of every request: the system's verifier through truststore, else Python's.
  • system_verifier() -> bool: Tell whether TLS is verified by the system's own verifier (truststore), for the dependency check.
  • open_once(request: str | urllib.request.Request, timeout: float = 60) -> http.client.HTTPResponse: Open @p request (a URL or a Request, http or https) once, TLS verified by context(); urllib's errors.
  • describe(exc: BaseException) -> str: Return in a few words why a request failed: the HTTP status, TLS, the name, a timeout, the connection.
  • transient(exc: BaseException) -> bool: Tell whether a later try may succeed: any failure of the connection, or an answer of TRANSIENT_STATUS.
  • class Retry (@dataclass(frozen=True)): How a request is tried again: for @p seconds, each try again logged; the clock is the tests'.
  • seconds: float = RETRY_SECONDS
  • log: Callable[[str], None] = print
  • sleep: Callable[[float], None] = time.sleep
  • clock: Callable[[], float] = time.monotonic
  • RETRY = Retry(): The default: two minutes, logged to the output.
  • urlopen(request: str | urllib.request.Request, timeout: float = 60, retry: Retry = RETRY, opener: Opener = open_once) -> IO[bytes]: Open @p request, a transient failure tried again (Retry); a failure for good raises DownloadError.
  • read(request: str | urllib.request.Request, timeout: float = 60, retry: Retry = RETRY, opener: Opener = open_once) -> bytes: Return the body of @p request, a transient failure (also of the body) tried again; else DownloadError.
  • answers(url: str, timeout: float = 15) -> str: Return "" when this computer gets an answer from @p url (any HTTP status is one), else why not.

wifi

overpressure.api.v2.wifi: the owner's Wi-Fi for a headset's installed system (source).

  • FILE: Where the keyfile goes on the installed system, and the command that puts it there from SSH's stdin.
  • COMMAND
  • SSID_BYTES = 32
  • PSK_LENGTHS = (8, 63)
  • PSK_HEX = 64
  • ASK
  • problem(ssid: str, password: str) -> str: Return what is wrong with a Wi-Fi answer, in plain words; empty when it can be used.
  • keyfile(ssid: str, password: str, connection: str) -> bytes: Return a NetworkManager keyfile for @p ssid: WPA-PSK with @p password, an open network without one.
  • ask(ctx: Context) -> tuple[str, str]: Ask for the Wi-Fi network until the answer can be used; empty: no Wi-Fi.
  • remember(ctx: Context) -> None: Ask for the Wi-Fi now, so the owner can leave during the install: the answer in memory, a skip in the state.
  • held(ctx: Context, task: str = "wifi") -> tuple[str, str]: Return the answer remember() kept; a skip in an earlier run is not asked twice, a lost password is asked again.

windows_ncm

overpressure.api.v2.windows_ncm: Windows' USB network link (source).

  • SCRIPT = Path(__file__).resolve()
  • USB_CLASS_CDC = 2
  • CDC_SUBCLASS_NCM = 0x0D
  • command(python: str | os.PathLike[str], serial: str | None = None) -> list: Return this script's command line for @p python, a Python with pyusb and libusb-package.
  • initialize(devices: list, serial: str, dispose: Callable[..., object]) -> dict: Initialize the one gadget in DEVICES (PyUSB devices) if its serial is SERIAL; release it after.
  • backend() -> tuple: Return libusb's backend on UsbDk, the loaded UsbDk helper, and PyUSB's core and util.
  • main(argv: list[str] | None = None) -> int: Initialize the gadget or check the dependencies; print the result as JSON.