# brennoo/rtl51 architecture

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

- Interactive diagram: https://gitdiagram.com/brennoo/rtl51
- Repository: https://github.com/brennoo/rtl51

## Overview

rtl51 is a pure-Go emulator for Realtek RTL837x switch SoCs. The principal workflow is to load a vendor firmware image, construct and run the emulated CPU, flash and switching hardware, then expose serial and network access to the running firmware. Separate CLI commands inspect and patch images and generate OTP data. The README also documents board mapping, UDP port tunnels, and pcapng capture. Some internal wiring is supported only by the README and source index; unverified links are omitted or dashed.

Main entry points: [`pkg/rtl837x/soc.go`](https://github.com/brennoo/rtl51/blob/main/pkg/rtl837x/soc.go) (RTL837x SoC), [`cmd/rtl51/boot.go`](https://github.com/brennoo/rtl51/blob/main/cmd/rtl51/boot.go) (Boot orchestration), [`cmd/rtl51/main.go`](https://github.com/brennoo/rtl51/blob/main/cmd/rtl51/main.go) (CLI commands), [`pkg/mcs51/cpu.go`](https://github.com/brennoo/rtl51/blob/main/pkg/mcs51/cpu.go) (DW8051 CPU)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI and firmware"]
  node_cli["CLI commands<br/>[main.go]"]
  node_boot["Boot orchestration<br/>[boot.go]"]
  node_firmware["Image and OTP<br/>[image.go]"]
end

subgraph group_emulation["SoC emulation"]
  node_soc["RTL837x SoC<br/>[soc.go]"]
  node_cpu["DW8051 CPU<br/>[cpu.go]"]
  node_flash["SPI flash and OTP<br/>[flash.go]"]
  node_asic["ASIC registers<br/>[asic.go]"]
  node_nic["CPU NIC DMA<br/>[nic.go]"]
end

subgraph group_switching["Switch fabric"]
  node_boards["Board profiles<br/>[boards.go]"]
  node_switch["L2 forwarding<br/>[switch.go]"]
  node_capture["Port capture<br/>[pcap.go]"]
end

subgraph group_connectivity["Host connectivity"]
  node_bridge["Host netstack<br/>[netbridge.go]"]
  node_portlink["UDP port tunnels<br/>[portlink.go]"]
end

node_user(("Operator"))
node_image["Firmware image"]
node_host(("Host clients"))

node_user -->|"invokes"| node_cli
node_image -->|"supplies"| node_cli
node_cli -->|"inspects or patches"| node_firmware
node_cli -.->|"dispatches boot"| node_boot
node_cli -->|"initializes emulator"| node_soc
node_boot -->|"runs and configures"| node_soc
node_boot -->|"sets port map"| node_boards
node_boot -->|"starts management bridge"| node_bridge
node_boot -->|"starts UDP links"| node_portlink
node_boot -->|"opens capture"| node_capture
node_soc -->|"expands update image"| node_firmware
node_soc -->|"steps CPU"| node_cpu
node_soc -.->|"coordinates hardware"| node_asic
node_soc -->|"routes frames"| node_switch
node_soc -.->|"emulates SPI storage"| node_flash
node_asic -->|"hooks CPU registers"| node_cpu
node_flash -->|"hooks flash commands"| node_cpu
node_nic -->|"uses register file"| node_asic
node_nic -->|"hooks DMA registers"| node_cpu
node_boards -.->|"maps front ports"| node_soc
node_bridge -->|"attaches management port"| node_soc
node_portlink -->|"attaches switch ports"| node_soc
node_host -->|"accesses Web UI"| node_bridge
node_host -->|"sends Ethernet datagrams"| node_portlink
node_switch -.->|"exports port frames"| node_capture
node_soc -->|"streams serial console"| node_host

click node_cli "https://github.com/brennoo/rtl51/blob/main/cmd/rtl51/main.go"
click node_boot "https://github.com/brennoo/rtl51/blob/main/cmd/rtl51/boot.go"
click node_firmware "https://github.com/brennoo/rtl51/blob/main/pkg/firmware/image.go"
click node_soc "https://github.com/brennoo/rtl51/blob/main/pkg/rtl837x/soc.go"
click node_cpu "https://github.com/brennoo/rtl51/blob/main/pkg/mcs51/cpu.go"
click node_flash "https://github.com/brennoo/rtl51/blob/main/pkg/rtl837x/flash.go"
click node_asic "https://github.com/brennoo/rtl51/blob/main/pkg/rtl837x/asic.go"
click node_nic "https://github.com/brennoo/rtl51/blob/main/pkg/rtl837x/nic.go"
click node_boards "https://github.com/brennoo/rtl51/blob/main/pkg/rtl837x/boards.go"
click node_switch "https://github.com/brennoo/rtl51/blob/main/pkg/rtl837x/switch.go"
click node_capture "https://github.com/brennoo/rtl51/blob/main/pkg/rtl837x/pcap.go"
click node_bridge "https://github.com/brennoo/rtl51/blob/main/pkg/netbridge/netbridge.go"
click node_portlink "https://github.com/brennoo/rtl51/blob/main/pkg/netbridge/portlink.go"

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_cli,node_boot,node_firmware,node_host toneBlue
class node_soc,node_cpu,node_flash,node_asic,node_nic toneAmber
class node_boards,node_switch,node_capture toneMint
class node_bridge,node_portlink toneRose
class node_user,node_image toneIndigo
```

## Components

### CLI and firmware

- [CLI commands](https://github.com/brennoo/rtl51/blob/main/cmd/rtl51/main.go): `cmd/rtl51/main.go`
- [Boot orchestration](https://github.com/brennoo/rtl51/blob/main/cmd/rtl51/boot.go): `cmd/rtl51/boot.go`
- [Image and OTP](https://github.com/brennoo/rtl51/blob/main/pkg/firmware/image.go): `pkg/firmware/image.go`

### SoC emulation

- [RTL837x SoC](https://github.com/brennoo/rtl51/blob/main/pkg/rtl837x/soc.go): `pkg/rtl837x/soc.go`
- [DW8051 CPU](https://github.com/brennoo/rtl51/blob/main/pkg/mcs51/cpu.go): `pkg/mcs51/cpu.go`
- [SPI flash and OTP](https://github.com/brennoo/rtl51/blob/main/pkg/rtl837x/flash.go): `pkg/rtl837x/flash.go`
- [ASIC registers](https://github.com/brennoo/rtl51/blob/main/pkg/rtl837x/asic.go): `pkg/rtl837x/asic.go`
- [CPU NIC DMA](https://github.com/brennoo/rtl51/blob/main/pkg/rtl837x/nic.go): `pkg/rtl837x/nic.go`

### Switch fabric

- [Board profiles](https://github.com/brennoo/rtl51/blob/main/pkg/rtl837x/boards.go): `pkg/rtl837x/boards.go`
- [L2 forwarding](https://github.com/brennoo/rtl51/blob/main/pkg/rtl837x/switch.go): `pkg/rtl837x/switch.go`
- [Port capture](https://github.com/brennoo/rtl51/blob/main/pkg/rtl837x/pcap.go): `pkg/rtl837x/pcap.go`

### Host connectivity

- [Host netstack](https://github.com/brennoo/rtl51/blob/main/pkg/netbridge/netbridge.go): `pkg/netbridge/netbridge.go`
- [UDP port tunnels](https://github.com/brennoo/rtl51/blob/main/pkg/netbridge/portlink.go): `pkg/netbridge/portlink.go`

### Other components

- **Operator**
- **Firmware image**
- **Host clients**

## Connections

- Operator → CLI commands: invokes (evidence: `README.md`)
- Firmware image → CLI commands: supplies (evidence: `README.md`)
- CLI commands → Image and OTP: inspects or patches (evidence: `cmd/rtl51/main.go`)
- CLI commands → Boot orchestration: dispatches boot
- CLI commands → RTL837x SoC: initializes emulator (evidence: `cmd/rtl51/main.go`)
- Boot orchestration → RTL837x SoC: runs and configures (evidence: `cmd/rtl51/boot.go`)
- Boot orchestration → Board profiles: sets port map (evidence: `cmd/rtl51/boot.go`)
- Boot orchestration → Host netstack: starts management bridge (evidence: `cmd/rtl51/boot.go`)
- Boot orchestration → UDP port tunnels: starts UDP links (evidence: `cmd/rtl51/boot.go`)
- Boot orchestration → Port capture: opens capture (evidence: `cmd/rtl51/boot.go`)
- RTL837x SoC → Image and OTP: expands update image (evidence: `pkg/rtl837x/soc.go`)
- RTL837x SoC → DW8051 CPU: steps CPU (evidence: `pkg/rtl837x/soc.go`)
- RTL837x SoC → ASIC registers: coordinates hardware
- RTL837x SoC → L2 forwarding: routes frames (evidence: `README.md`)
- RTL837x SoC → SPI flash and OTP: emulates SPI storage
- ASIC registers → DW8051 CPU: hooks CPU registers (evidence: `pkg/rtl837x/asic.go`)
- SPI flash and OTP → DW8051 CPU: hooks flash commands (evidence: `pkg/rtl837x/flash.go`)
- CPU NIC DMA → ASIC registers: uses register file (evidence: `pkg/rtl837x/nic.go`)
- CPU NIC DMA → DW8051 CPU: hooks DMA registers (evidence: `pkg/rtl837x/nic.go`)
- Board profiles → RTL837x SoC: maps front ports
- Host netstack → RTL837x SoC: attaches management port (evidence: `pkg/netbridge/netbridge.go`)
- UDP port tunnels → RTL837x SoC: attaches switch ports (evidence: `pkg/netbridge/portlink.go`)
- Host clients → Host netstack: accesses Web UI (evidence: `README.md`)
- Host clients → UDP port tunnels: sends Ethernet datagrams (evidence: `README.md`)
- L2 forwarding → Port capture: exports port frames
- RTL837x SoC → Host clients: streams serial console (evidence: `README.md`)
