Skip to content
brennooPublic

About

Pure-Go emulator for Realtek RTL83XX 2.5GbE/10GbE switches (DW8051). Boots unmodified SPI flash dumps and web-upgrade firmwares.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

15 Commits

Folders and files

Repository files navigation

rtl51

CI Release License: MIT

Pure-Go SoC & L2 switch emulator for Realtek RTL8372 / RTL8372N / RTL8373 2.5GbE/10GbE switches.

Boot unmodified vendor DW8051 firmware (HRUI, Horaco, Sodola, Hasivo, Sirivision) on your laptop in ~2 seconds — serial console, Web UI, L2 switching fabric, UDP port tunnels, and Wireshark pcapng capture included. Zero root, zero TAP devices, zero hardware.

          firmware.bin (SPI NOR dump or web-upgrade .bin)
                                 │
                                 ▼
┌──────────────────────────────────────────────────────────────────┐
│  DW8051 CPU (32-bank Keil C51)  ◄────►  SPI NOR Flash + OTP      │
│        │                  │                                      │
│      UART            Switchcore ASIC + L2 Forwarding Engine      │
│        │             (VLAN, STP, LACP, IGMP, RLDP, I2C PoE)      │
└────────┼──────────────────────┬───────────────────┬──────────────┘
         ▼                      ▼                   ▼
  stdin / stdout         gVisor netstack     UDP port tunnels
   (serial CLI)      http://127.0.0.1:8080   & per-port pcapng

Quick Start

Grab a prebuilt binary from Releases, install via Go, or build from source:

git clone https://github.com/brennoo/rtl51.git && cd rtl51
go build ./cmd/rtl51
# you need a firmware image: see firmwares/firmwares.txt
./rtl51 boot ./firmwares/SWTG118AS-v2.0.bin

Or install just the CLI:

go install github.com/brennoo/rtl51/cmd/rtl51@latest

Once booted:

  • Serial console is attached to stdin/stdout (Ctrl+C to exit; password shown by rtl51 inspect).
  • Web UI is forwarded to http://127.0.0.1:8080 (default credentials: admin / admin).
  • Read-only by default: input images are never modified; pass -write-flash out.bin to persist NVRAM/config changes on exit.

CLI & Lab Recipes

Inspect, Checksum & SPI OTP

# Inspect image layout, chip ID, checksums, OTP algo, default IP/MAC, and serial password
./rtl51 inspect ./firmwares/SWTG118AS-v2.0.bin

# Verify or recalculate 0x12345678 runtime header & payload checksums
./rtl51 checksum ./firmwares/HRRF_V200.2.5_ZX310S-4T2XH_0422.bin
./rtl51 checksum -o patched.bin modified.bin

# Generate SPI Flash Security Register (0x48) payload for a flash chip UID
./rtl51 otp -a v1         10093f3010093f30
./rtl51 otp -a 1          e6632c25a344b330   # v2-algo1 (-a 2 for v2-algo2, -a sirivision)

Multi-Switch Labs & Wireshark Capture

Attach front-panel ports to UDP datagram tunnels (GNS3/QEMU NIO_UDP wire format — 1 datagram = 1 raw Ethernet frame, works with Scapy or another rtl51 instance) and dump every port + the 0x8899-tagged CPU interface (cpu9) to pcapng:

# Cable port 2 on Switch A to port 2 on Switch B and capture Switch A's fabric
./rtl51 boot -http 127.0.0.1:8081 -pcap switch-a.pcapng \
  -port 2=127.0.0.1:10001,peer=127.0.0.1:10002 ./firmwares/SWTG118AS-v2.0.bin

./rtl51 boot -http 127.0.0.1:8082 -mac 02:00:00:00:00:02 \
  -port 2=127.0.0.1:10002,peer=127.0.0.1:10001 ./firmwares/SWTG118AS-v2.0.bin

Use -mac <addr> to assign distinct hardware MACs when booting multiple copies of the same image, and -portmap 4,5,6,7,8,3 / -mgmt-port <N> for custom board layouts.

What's Emulated

  • pkg/mcs51 — Machine-cycle-accurate DW8051 core, 32-bank Keil C51 code banking (PSBANK / 0xBB hardware LIFO), MOV Direct, Direct operand ordering, Timers 0/1/2, and 2-level IP interrupt preemption.
  • pkg/rtl837x — Copy-on-write SPI NOR flash with automatic 0x48 Security Register calibration (v1, v2-algo1, v2-algo2, sirivision); 4096-entry VLAN & L2 tables with learning/aging; L2 forwarding engine (802.1Q, STP/RSTP, LACP/LAG, IGMP/MLD snooping, RLDP loop detection, port isolation); Clause 45 MDIO/SerDes; 4-port I2C PoE PSE telemetry; CPU NIC DMA (0x8899 tags); per-port pcapng writer.
  • pkg/netbridge — In-process gVisor netstack auto-learning the switch IP (across static & DHCP changes), HTTP proxy for the Web UI, and UDP port tunnels.
  • pkg/firmware — Content-based image inspector, checksum patcher, and standalone web-upgrade .bin unpacker (synthesizes a 2 MB flash image + interrupt vector stubs in memory so update files boot without a SPI dump).

Reference Firmwares

The repo doesn't carry vendor firmware. firmwares/firmwares.txt lists where the images I test against can be found, as URL,name,sha256, and firmwares/README.md says what each one is. Any compatible image you already have works too.

Testing

# drop reference images into firmwares/ first; tests that need a missing image skip
go test ./...
go test -race -short ./...

The test suite boots the reference firmware images end-to-end and verifies Web UI endpoints, NVRAM/IP changes, VLANs, STP, LACP, IGMP, RLDP, UDP port tunnels, and pcapng output.

License & Credits

  • rtl51 source code is released under the MIT License.
  • Firmware binaries aren't in this repo and aren't mine or MIT-licensed; they belong to their vendors.
  • Credits: Builds on foundational RTL837x firmware, register, flash layout, and OTP (encuid / encuid2) reverse-engineering work from up-n-atom/SWTG118AS, JiaY-shi/rtl83xx, and the ServeTheHome community, as well as board port profiles from logicog/RTLPlayground (MIT).

About

Pure-Go emulator for Realtek RTL83XX 2.5GbE/10GbE switches (DW8051). Boots unmodified SPI flash dumps and web-upgrade firmwares.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages