]> git.ipfire.org Git - thirdparty/openwrt.git/commit
realtek: add support for Ubiquiti UniFi USW Pro XG 8 PoE 24010/head
authorJonas Jelonek <jelonek.jonas@gmail.com>
Fri, 26 Jun 2026 18:06:22 +0000 (18:06 +0000)
committerJonas Jelonek <jelonek.jonas@gmail.com>
Mon, 6 Jul 2026 20:38:13 +0000 (22:38 +0200)
commitf03899aef44055682fb93ff10473a2fc99071153
tree92985af9d50ba626f10065d195edd68b94f13bf8
parent4d75424ae291413bd7e24f1cecec5630b9717296
realtek: add support for Ubiquiti UniFi USW Pro XG 8 PoE

Add support for RTL9313-based Ubiquiti UniFi USW Pro XG 8 PoE switch
with 8x 10G RJ45 and 2x SFP+ ports.

Hardware
========

  - RTL9313 switch SoC
  - 512 MiB RAM
  - 32 MiB SPI-NOR flash
  - 8x 100M/1G/2.5G/5G/10G RJ45 ports via 2x RTL8264B
  - PoE: 8x 802.3bt, 60W per port, 155W total budget
  - 2x 1G/2.5G/10G SFP+ ports
  - Buttons: 1x Reset
  - LEDs:
    - System LED white/blue
    - RGBW LED per port
  - Console: TTL 3.3V, 115200 8N1, populated 4-pin header
    (device must be opened to access header)
  - Etherlighting feature (lighting patterns and color control)
  - Vendor firmware: U-Boot + LEDE-based Ubiquiti OS

MAC address
===========

Single MAC address in EEPROM partition, applied to all ports.

Known issues
============

  - PoE not available, depends on WIP Realtek PSE MCU driver
  - Etherlighting not controllable, driver WIP. Port LEDs for link work
    though. By default, the controller keeps the LEDs in a breathing
    state, gated by the link state delivered by the Realtek SoC.

Disclaimer
==========

Stock firmware uses a dual-bank layout (kernel0/kernel1, ~15 MiB each).
OpenWrt replaces both banks with a single contiguous firmware partition.
Flashing OpenWrt overwrites both stock kernel slots; U-Boot remains
intact and can be used for recovery.

Installation
============

1. Enable SSH on the stock UniFi OS and log in with user account.

(at this stage you may make backups of the flash, just to be sure)

2. Copy the OpenWrt sysupgrade image to /tmp on the switch (e.g. via
   scp).

3. Adjust IMG below to point at the copied file, then run the block as a
   whole. It writes kernel0, splits into kernel1 if the image is larger
   than that slot (otherwise invalidates kernel1 so U-Boot cannot pick
   a stale bank), and reboots:

   IMG=/tmp/openwrt-realtek-rtl931x-ubnt_usw-pro-xg-8-poe-squashfs-sysupgrade.bin
   K0_BLOCKS=$((0xec0000 / 0x10000))

   dd if="$IMG" of=/dev/mtdblock2 bs=64k count=$K0_BLOCKS conv=fsync
   if [ "$(wc -c < "$IMG")" -gt $((0xec0000)) ]; then
       dd if="$IMG" of=/dev/mtdblock3 bs=64k skip=$K0_BLOCKS conv=fsync
   else
       dd if=/dev/zero of=/dev/mtdblock3 bs=64k count=1 conv=fsync
   fi
   sync

   Then reboot the switch, it comes up in OpenWrt after reboot.

   You may also install the image in any other way, just make sure to
   write it to the kernel0 partition and if the image is larger than
   16MiB, write the rest to the kernel1 partition, otherwise invalidate
   it so U-Boot cannot boot from the second bank.

4. It is recommended to modify the bootcmd to speedup the boot and prevent
   any issues due to the dual-boot selection. Since U-Boot by default
   uses bootubnt which does a lot of (unneeded) RTK initialization,
   quite some time passes until Linux is started. Additionally, the
   U-boot logic fiddles with some bits on flash which causes JFFS2
   errors in OpenWrt. While this doesn't seem to cause issues yet, be
   defensive and set the bootcmd to:

     bootm 0xb4150000

   This directly boots the uImage from flash, without doing all the
   initialization. OpenWrt is able to bootstrap the networking completely
   on its own.

It does not matter which bank stock booted from when the dd block
runs: both banks are touched in the same pass (kernel0 written, kernel1
either written or invalidated). With kernel1 invalidated, U-Boot's
internal fallback kicks in and permanently switches to kernel0 on the
next boot, so the device stays on OpenWrt as long as kernel0 is
bootable.

Recovery
========

Since the installation procedure invalidates or partially overwrites
the second bank, recovery requires serial console access (see Hardware
above for pinout).

1. Interrupt U-Boot autoboot by spamming a key during early boot to
   drop into the U-Boot prompt.

2. Bring up networking:

   rtk network on

3. Transfer an OpenWrt initramfs image via TFTP and boot it:

   tftpboot 0x82000000 <server>:<initramfs.bin>
   bootm 0x82000000

4. From the running initramfs OpenWrt, do a sysupgrade to reflash
   OpenWrt or whatever you want to recover. There is no need for the
   complicated procedure from installation since OpenWrt sees the
   firmware partition already as a whole.

Return to stock firmware
========================

There is no fully-supported revert path. The stock firmware blob is a
Ubiquiti UBNT archive (header + parts, see firmware-utils' fw.h) that
embeds a u-boot and a kernel0 uImage payload; only the latter is
relevant when writing back to the kernel partitions.

The snippet below extracts the kernel0 uImage from such a blob by
locating the uImage magic and using the size carried in the uImage
header itself, without parsing any UBNT framing. It is provided as a
best-effort starting point; verify the result before flashing,
otherwise you're on your own:

   BLOB=US3.rtl93xx_7.4.1+X.Y.Z.bin
   OFF=$(grep -aboF $'\x27\x05\x19\x56' "$BLOB" | head -1 | cut -d: -f1)
   SIZE=$(( $(dd if="$BLOB" bs=1 skip=$((OFF + 12)) count=4 2>/dev/null \
               | hexdump -e '1/4 "%u"') + 64 ))
   dd if="$BLOB" of=kernel0.uImage bs=1 skip="$OFF" count="$SIZE"

Once you have a clean uImage, it can be written to the kernel partition
from within OpenWrt. If you adjusted the bootcmd during installation,
make sure to restore it to the default "bootcmd=bootubnt". After a reboot,
Ubiquiti's firmware should boot.

Or, if you did backups of the flash before, just write the backup to the
flash.

Link: https://github.com/openwrt/openwrt/pull/24010
Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
target/linux/realtek/base-files/etc/board.d/02_network
target/linux/realtek/dts/rtl9313_ubnt_usw-pro-xg-8-poe.dts [new file with mode: 0644]
target/linux/realtek/image/rtl931x.mk