# firmwire/firmwire architecture

> Architecture diagram of the GitHub repository firmwire/firmwire, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/firmwire/firmwire
- Repository: https://github.com/firmwire/firmwire

## Overview

FirmWire is a two-part system: a Python host framework that models and drives modem firmware, and a separate C “modkit” tree that is compiled into target-side helpers/fuzzers for specific baseband families.

1. **Entry point and packaging**
   - `firmwire.py` is the top-level CLI entry point.
   - The `firmwire/` package contains the runtime framework; `README.md` positions it as a full-system analysis platform for Samsung and MediaTek baseband firmware.

2. **Workspace and configuration boundary**
   - `firmwire/workspace.py` is the project-level state manager: it likely ties together firmware images, vendor selection, paths, and analysis artifacts.
   - `firmwire/vendor/` holds vendor-specific data and is the main boundary where generic framework code becomes device-family aware.

3. **Firmware ingestion and address layout**
   - `firmwire/loader.py` loads firmware images into the analysis environment.
   - `firmwire/memory_map.py` describes how firmware is placed and accessed in memory, which is central for symbol resolution, MMIO modeling, and debugger-style reasoning.

4. **Emulation orchestration**
   - `firmwire/emulator/firmwire.py` is the core runtime coordinator.
   - Supporting modules split responsibilities: `init.py` for bootstrapping, `snapshot.py` for saved/restored state, `guestlogs.py` for collecting guest output, and `patterndb.py` for matching/recognizing recurring firmware behaviors.

5. **Hardware modeling layer**
   - `firmwire/hw/` contains the synthetic hardware that the firmware interacts with.
   - `soc.py` defines SoC-level composition, `peripheral.py` provides the base peripheral abstraction, and `fifo.py`/`glink.py` model communication channels used by modem software.
   - This is the main boundary between guest firmware execution and host-side simulation.

6. **Analysis and symbol utilities**
   - `firmwire/util/` provides cross-cutting helpers: logging, parameter handling, symbol lookup, port management, hex formatting, and ARM stack unwinding.
   - `util/panda.py` suggests integration helpers for a PANDA/QEMU-style execution backend, which is likely the low-level execution engine beneath the Python orchestration.

7. **Modkit: target-side support code**
   - `modkit/` is a separate build tree with its own `Makefile`s and `README`.
   - It contains C runtimes, task abstractions, AFL-style fuzzing hooks, and firmware-facing helpers for two families: `modkit/mtk` and `modkit/shannon`.

8. **Protocol- and vendor-specific fuzzing**
   - Under each modkit family are example fuzzers such as LTE RRC, GSM MM/SM, and test payloads.
   - These are not host-side tests; they are firmware-adjacent programs that exercise modem logic through the modkit runtime and communication primitives.

9. **Data flow through the system**
   - Typical flow is: CLI → workspace/vendor selection → firmware loading/memory mapping → emulator initialization → synthetic SoC/peripheral handling → guest execution → logs/snapshots/pattern matches.
   - The modkit side feeds inputs into that execution environment, often through channels like GLINK/FIFO or family-specific task abstractions.

10. **Tooling and reproducibility**
   - `Dockerfile`, `requirements.txt`, and GitHub Actions workflow indicate the repo is meant to be built and tested reproducibly.
   - `tests/test_vendor_basic.py` is a lightweight guard around vendor configuration/selection rather than a broad functional test suite.

For an architecture diagram, the most important boundaries are: host Python framework vs. target-side C modkit, generic framework vs. vendor-specific extensions, and firmware execution vs. modeled hardware/peripheral interfaces.

Main entry points: [`firmwire/emulator/firmwire.py`](https://github.com/firmwire/firmwire/blob/main/firmwire/emulator/firmwire.py) (Emulator), [`firmwire/hw/soc.py`](https://github.com/firmwire/firmwire/blob/main/firmwire/hw/soc.py) (SoC), [`firmwire/workspace.py`](https://github.com/firmwire/firmwire/blob/main/firmwire/workspace.py) (Workspace), [`modkit/mtk/modkit.c`](https://github.com/firmwire/firmwire/blob/main/modkit/mtk/modkit.c) (MTK modkit)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_host["Python host"]
  node_firmwire_cli["firmwire.py<br/>cli entry<br/>[firmwire.py]"]
  node_workspace["Workspace<br/>state mgmt<br/>[workspace.py]"]
  node_loader["Loader<br/>[loader.py]"]
  node_memory_map["Memory map<br/>layout model<br/>[memory_map.py]"]
  node_emulator_core["Emulator<br/>orchestrator<br/>[firmwire.py]"]
  node_emu_init["Init<br/>bootstrap<br/>[init.py]"]
  node_emu_snapshot["Snapshot<br/>state save<br/>[snapshot.py]"]
  node_emu_guestlogs["Guest logs<br/>output capture<br/>[guestlogs.py]"]
  node_emu_patterndb["Pattern DB<br/>recognizer<br/>[patterndb.py]"]
  node_soc["SoC<br/>hw composition<br/>[soc.py]"]
  node_peripheral["Peripheral<br/>hw base<br/>[peripheral.py]"]
  node_fifo["FIFO<br/>channel model<br/>[fifo.py]"]
  node_glink["GLINK<br/>channel model<br/>[glink.py]"]
  node_util["Utilities<br/>helpers<br/>[__init__.py]"]
  node_panda["PANDA bridge<br/>backend glue<br/>[panda.py]"]
  node_vendor["Vendor data<br/>vendor boundary"]
end

subgraph group_modkit["Target modkit"]
  node_modkit_root["Modkit<br/>c runtime<br/>[README.md]"]
  node_mtk_modkit["MTK modkit<br/>family runtime<br/>[modkit.c]"]
  node_shannon_modkit["Shannon modkit<br/>family runtime<br/>[modkit.c]"]
  node_mtk_fuzzer["MTK fuzzers<br/>payloads<br/>[lte_rrc.c]"]
  node_shannon_fuzzers["Shannon fuzzers<br/>payloads<br/>[gsm_mm.c]"]
end

subgraph group_tooling["Tooling"]
  node_build["Build files<br/>packaging"]
end

node_firmwire_cli -->|"selects"| node_workspace
node_workspace -->|"uses"| node_vendor
node_workspace -->|"loads"| node_loader
node_loader -->|"lays out"| node_memory_map
node_memory_map -->|"feeds"| node_emulator_core
node_emulator_core -->|"boots"| node_emu_init
node_emulator_core -->|"persists"| node_emu_snapshot
node_emulator_core -->|"captures"| node_emu_guestlogs
node_emulator_core -->|"matches"| node_emu_patterndb
node_emulator_core -->|"runs on"| node_soc
node_soc -->|"composes"| node_peripheral
node_soc -->|"connects"| node_fifo
node_soc -->|"connects"| node_glink
node_peripheral -->|"serves"| node_emulator_core
node_util -->|"integrates"| node_panda
node_firmwire_cli -->|"uses"| node_util
node_modkit_root -->|"contains"| node_mtk_modkit
node_modkit_root -->|"contains"| node_shannon_modkit
node_mtk_modkit -->|"ships"| node_mtk_fuzzer
node_shannon_modkit -->|"ships"| node_shannon_fuzzers
node_mtk_modkit -.->|"inputs"| node_emulator_core
node_shannon_modkit -.->|"inputs"| node_emulator_core
node_build -->|"packages"| node_firmwire_cli
node_build -->|"builds"| node_modkit_root

click node_firmwire_cli "https://github.com/firmwire/firmwire/blob/main/firmwire.py"
click node_workspace "https://github.com/firmwire/firmwire/blob/main/firmwire/workspace.py"
click node_loader "https://github.com/firmwire/firmwire/blob/main/firmwire/loader.py"
click node_memory_map "https://github.com/firmwire/firmwire/blob/main/firmwire/memory_map.py"
click node_emulator_core "https://github.com/firmwire/firmwire/blob/main/firmwire/emulator/firmwire.py"
click node_emu_init "https://github.com/firmwire/firmwire/blob/main/firmwire/emulator/init.py"
click node_emu_snapshot "https://github.com/firmwire/firmwire/blob/main/firmwire/emulator/snapshot.py"
click node_emu_guestlogs "https://github.com/firmwire/firmwire/blob/main/firmwire/emulator/guestlogs.py"
click node_emu_patterndb "https://github.com/firmwire/firmwire/blob/main/firmwire/emulator/patterndb.py"
click node_soc "https://github.com/firmwire/firmwire/blob/main/firmwire/hw/soc.py"
click node_peripheral "https://github.com/firmwire/firmwire/blob/main/firmwire/hw/peripheral.py"
click node_fifo "https://github.com/firmwire/firmwire/blob/main/firmwire/hw/fifo.py"
click node_glink "https://github.com/firmwire/firmwire/blob/main/firmwire/hw/glink.py"
click node_util "https://github.com/firmwire/firmwire/blob/main/firmwire/util/__init__.py"
click node_panda "https://github.com/firmwire/firmwire/blob/main/firmwire/util/panda.py"
click node_vendor "https://github.com/firmwire/firmwire/tree/main/firmwire/vendor"
click node_modkit_root "https://github.com/firmwire/firmwire/blob/main/modkit/README.md"
click node_mtk_modkit "https://github.com/firmwire/firmwire/blob/main/modkit/mtk/modkit.c"
click node_shannon_modkit "https://github.com/firmwire/firmwire/blob/main/modkit/shannon/modkit.c"
click node_mtk_fuzzer "https://github.com/firmwire/firmwire/blob/main/modkit/mtk/fuzzers/lte_rrc.c"
click node_shannon_fuzzers "https://github.com/firmwire/firmwire/blob/main/modkit/shannon/fuzzers/gsm_mm.c"
click node_build "https://github.com/firmwire/firmwire/tree/main/Dockerfile"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_firmwire_cli,node_workspace,node_loader,node_memory_map,node_emulator_core,node_emu_init,node_emu_snapshot,node_emu_guestlogs,node_emu_patterndb,node_soc,node_peripheral,node_fifo,node_glink,node_util,node_panda,node_vendor toneBlue
class node_modkit_root,node_mtk_modkit,node_shannon_modkit,node_mtk_fuzzer,node_shannon_fuzzers toneAmber
class node_build toneMint
```

## Components

### Python host

Runtime framework that loads, emulates, and observes modem firmware.

- [firmwire.py](https://github.com/firmwire/firmwire/blob/main/firmwire.py): cli entry · Top-level command-line entry point. · `firmwire.py`
- [Workspace](https://github.com/firmwire/firmwire/blob/main/firmwire/workspace.py): state mgmt · Tracks firmware selection, paths, and analysis state. · `firmwire/workspace.py`
- [Loader](https://github.com/firmwire/firmwire/blob/main/firmwire/loader.py): image loader · Ingests firmware images into the analysis environment. · `firmwire/loader.py`
- [Memory map](https://github.com/firmwire/firmwire/blob/main/firmwire/memory_map.py): layout model · Defines firmware placement and address translation. · `firmwire/memory_map.py`
- [Emulator](https://github.com/firmwire/firmwire/blob/main/firmwire/emulator/firmwire.py): orchestrator · Coordinates boot, execution, and runtime services. · `firmwire/emulator/firmwire.py`
- [Init](https://github.com/firmwire/firmwire/blob/main/firmwire/emulator/init.py): bootstrap · Bootstraps emulator setup and guest start conditions. · `firmwire/emulator/init.py`
- [Snapshot](https://github.com/firmwire/firmwire/blob/main/firmwire/emulator/snapshot.py): state save · Captures and restores emulator state. · `firmwire/emulator/snapshot.py`
- [Guest logs](https://github.com/firmwire/firmwire/blob/main/firmwire/emulator/guestlogs.py): output capture · Collects guest-side output and traces. · `firmwire/emulator/guestlogs.py`
- [Pattern DB](https://github.com/firmwire/firmwire/blob/main/firmwire/emulator/patterndb.py): recognizer · Matches recurring firmware behaviors and signatures. · `firmwire/emulator/patterndb.py`
- [SoC](https://github.com/firmwire/firmwire/blob/main/firmwire/hw/soc.py): hw composition · Composes the synthetic system presented to firmware. · `firmwire/hw/soc.py`
- [Peripheral](https://github.com/firmwire/firmwire/blob/main/firmwire/hw/peripheral.py): hw base · Base abstraction for modeled devices. · `firmwire/hw/peripheral.py`
- [FIFO](https://github.com/firmwire/firmwire/blob/main/firmwire/hw/fifo.py): channel model · Models queued communication paths used by modem software. · `firmwire/hw/fifo.py`
- [GLINK](https://github.com/firmwire/firmwire/blob/main/firmwire/hw/glink.py): channel model · Models GLINK-style interprocessor communication. · `firmwire/hw/glink.py`
- [Utilities](https://github.com/firmwire/firmwire/blob/main/firmwire/util/__init__.py): helpers · Cross-cutting helpers for symbols, ports, logging, and analysis. · `firmwire/util/__init__.py`
- [PANDA bridge](https://github.com/firmwire/firmwire/blob/main/firmwire/util/panda.py): backend glue · Integration helpers for the execution backend. · `firmwire/util/panda.py`
- [Vendor data](https://github.com/firmwire/firmwire/tree/main/firmwire/vendor): vendor boundary · Device-family-specific extensions and configuration. · `firmwire/vendor`

### Target modkit

C build tree compiled into firmware-adjacent helpers and fuzzers.

- [Modkit](https://github.com/firmwire/firmwire/blob/main/modkit/README.md): c runtime · Separate target-side support tree for firmware-facing helpers and fuzzers. · `modkit/README.md`
- [MTK modkit](https://github.com/firmwire/firmwire/blob/main/modkit/mtk/modkit.c): family runtime · MediaTek-specific support code and fuzzers. · `modkit/mtk/modkit.c`
- [Shannon modkit](https://github.com/firmwire/firmwire/blob/main/modkit/shannon/modkit.c): family runtime · Shannon-specific support code and fuzzers. · `modkit/shannon/modkit.c`
- [MTK fuzzers](https://github.com/firmwire/firmwire/blob/main/modkit/mtk/fuzzers/lte_rrc.c): payloads · Example firmware-adjacent inputs such as LTE RRC and message injection. · `modkit/mtk/fuzzers/lte_rrc.c`
- [Shannon fuzzers](https://github.com/firmwire/firmwire/blob/main/modkit/shannon/fuzzers/gsm_mm.c): payloads · Example firmware-adjacent fuzzers for GSM and LTE protocols. · `modkit/shannon/fuzzers/gsm_mm.c`

### Tooling

Packaging and reproducibility boundary.

- [Build files](https://github.com/firmwire/firmwire/tree/main/Dockerfile): packaging · Reproducible build and container setup. · `Dockerfile`

## Connections

- firmwire.py → Workspace: selects · CLI drives workspace selection and analysis context.
- Workspace → Vendor data: uses · Workspace binds vendor-specific configuration.
- Workspace → Loader: loads · Workspace initiates firmware ingestion.
- Loader → Memory map: lays out · Loaded firmware is mapped into modeled memory.
- Memory map → Emulator: feeds · Address layout is consumed by the emulator runtime.
- Emulator → Init: boots · Core runtime delegates startup sequencing.
- Emulator → Snapshot: persists · Runtime can save and restore state.
- Emulator → Guest logs: captures · Runtime collects guest output.
- Emulator → Pattern DB: matches · Runtime consults pattern recognition during execution.
- Emulator → SoC: runs on · Firmware executes against the modeled SoC.
- SoC → Peripheral: composes · SoC is built from peripheral abstractions.
- SoC → FIFO: connects · SoC exposes queued communication channels.
- SoC → GLINK: connects · SoC exposes GLINK-style channels.
- Peripheral → Emulator: serves · Peripherals mediate guest/host interaction.
- Utilities → PANDA bridge: integrates · Utility layer includes backend-specific glue.
- firmwire.py → Utilities: uses · CLI and runtime rely on shared helpers.
- Modkit → MTK modkit: contains · Modkit splits into family-specific builds.
- Modkit → Shannon modkit: contains · Modkit splits into family-specific builds.
- MTK modkit → MTK fuzzers: ships · MTK tree includes example fuzzers and payloads.
- Shannon modkit → Shannon fuzzers: ships · Shannon tree includes example fuzzers and payloads.
- MTK modkit → Emulator: inputs · Target-side code feeds data into the host execution environment.
- Shannon modkit → Emulator: inputs · Target-side code feeds data into the host execution environment.
- Build files → firmwire.py: packages · Container and dependency setup support the host framework.
- Build files → Modkit: builds · Tooling supports reproducible modkit builds.
