Skip to content

realtek: rtl930x: add TP-Link TL-ST5008 - #20337

Open
balika011 wants to merge 2 commits into
openwrt:mainfrom
balika011:main
Open

balika011 wants to merge 2 commits into
openwrt:mainfrom
balika011:main

Conversation

@balika011

@balika011 balika011 commented Oct 7, 2025 •

Copy link
Copy Markdown
Contributor

To run openwrt you need to install a patched uboot.
Luckily there's a bug in the uboot tftp update implementation that can be exploited to do just that.
Will be documented on the wiki.

Depends: #20450

@github-actions github-actions Bot added the target/realtek pull request/issue for realtek target label Oct 7, 2025
@Djfe

Djfe commented Oct 7, 2025 •

Copy link
Copy Markdown
Contributor

Please explain in the commit message, why this commit is required? what does it correct/fix?
realtek: rtl930x: add tx/rx poarlity swap support

Please add more info on the device into the commit (specs, how to flash the device etc.):
examples:
62d50fb
c7c54f3


You need to adjust your local git config in order for the CI to pass "Test Formalities". Though this only affects the older commit 2ddf19e

instructions in-case you need them:
since your second commit has the correct author: maybe a simple git rebase -i HEAD~3 is enough.
Edit the 1st commit during rebase and then run git commit --amend -s to fix the author name for the 1st commit. Then git rebase --continue

If your git config is wrong:
git config --local --add user.name "Balázs Triszka"

Alternatively run this as global instead of local, if you want to change the config for everything and not just your local fork of openwrt. (this repo)
git config --global --add user.name "Balázs Triszka"

git config --list shows every config entry (you can limit it further with parameters like --local or --global

@balika011

Copy link
Copy Markdown
Contributor Author

Please explain in the commit message, why this commit is required? what does it correct/fix? realtek: rtl930x: add tx/rx poarlity swap support

This device needs tx/rx be swapped to make the 8x RTL8261N phys work.
Without this, it's simply unable to communicate, but still links up at 10G.

see: d5b8207#diff-8e20253e585ff25e2c12c86ebaee6d99c4802091609d3dd81ec4b7789a4637f6R452-R482

@balika011
balika011 force-pushed the main branch 3 times, most recently from 5e86315 to 4bd5ee0 Compare October 7, 2025 21:56
@balika011

balika011 commented Oct 7, 2025 •

Copy link
Copy Markdown
Contributor Author

Please add more info on the device into the commit (specs, how to flash the device etc.):

Added some specs.

I'm yet to make a guide on how to exploit tftp update in TP-LINK BOOTUTIL.
In short: The memory range that they called tftpboot with includes the stack of uboot...

Official updates and signed and encrypted.
I'll also add a script to decrypt the update.
Also made one for TL-SX3008F, but I don't own the device.

@balika011
balika011 force-pushed the main branch 2 times, most recently from 4bd5ee0 to 7c61fd0 Compare October 7, 2025 23:47
@Djfe

Djfe commented Oct 8, 2025 •

Copy link
Copy Markdown
Contributor

poarlity > polarity (commit title)

edit: and the 2nd swap_tx_polarity needs to be rx in the commit message

the device commit still has a few copy&paste issues from the example, I linked (it says xikestore at the beginning for example)

what is "after unlocking"? (regarding UART speeds)
does patching/exploiting uboot change the UART speed? if so why don't you keep it to the default uart speed of stock so it's universally the same?

@Djfe

Djfe commented Oct 8, 2025 •

Copy link
Copy Markdown
Contributor

This device needs tx/rx be swapped to make the 8x RTL8261N phys work. Without this, it's simply unable to communicate, but still links up at 10G.

see: d5b8207#diff-8e20253e585ff25e2c12c86ebaee6d99c4802091609d3dd81ec4b7789a4637f6R452-R482

Is this something that affects all RTL8261N phys or just the ones in this particular switch?
if it affects all RTL8261N phys then it probably should be fixed in that driver instead, I assume. (I'm not an expert by any means)

@jonasjelonek

Copy link
Copy Markdown
Member

Is this something that affects all RTL8261N phys or just the ones in this particular switch? if it affects all RTL8261N phys then it probably should be fixed in that driver instead, I assume. (I'm not an expert by any means)

This is subject to the individual board design. Though I'm not an expert on this, afaik it deals with signal integrity/quality. In Realtek SDK this can also be configured in the hardware profile. So it's good to have that configurable for us too.

@balika011

Copy link
Copy Markdown
Contributor Author

what is "after unlocking"? (regarding UART speeds) does patching/exploiting uboot change the UART speed? if so why don't you keep it to the default uart speed of stock so it's universally the same?

All other rtl930x switch uses the faster 115200 baud

};

&ethernet0 {
nvmem-cells = <&factory_macaddr>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
nvmem-cells = <&factory_macaddr>;
nvmem-cells = <&factory_macaddr 0>;

And you are missing the same for the switch ports (just with the correct offsets instead of 0)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it only has one mac, just like on other tp-link switches. they aren't missing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at other tp-link switches, they are done like this. are you sure this is not correct this way?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default in OpenWrt seems to be that every switch port gets its own MAC address, and this is usually calculated (increment by 1) from the MAC that is assigned to the switch on the label, in U-Boot env or some different vendor data partition. So far, this is done with the 02_network script in board files but we may slowly move to assign it via the DT.

I'm not arguing on that. But in this concrete case, you define the following in the DT.

nvmem-layout {
	compatible = "fixed-layout";
	#address-cells = <1>;
	#size-cells = <1>;

	factory_macaddr: macaddr@fdff4 {
		reg = <0xfdff4 0x6>;
	};
};

And since you have #address-cells = <1> and #size-cells = <1>, you need to define it like @ecsv suggested.

@balika011 balika011 Oct 9, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrewjlamarche

Copy link
Copy Markdown
Contributor

This device needs tx/rx be swapped to make the 8x RTL8261N phys work. Without this, it's simply unable to communicate, but still links up at 10G.
see: d5b8207#diff-8e20253e585ff25e2c12c86ebaee6d99c4802091609d3dd81ec4b7789a4637f6R452-R482

Is this something that affects all RTL8261N phys or just the ones in this particular switch? if it affects all RTL8261N phys then it probably should be fixed in that driver instead, I assume. (I'm not an expert by any means)

ddb0cd2

I think this was already committed directly to the driver.

@balika011

balika011 commented Oct 8, 2025 •

Copy link
Copy Markdown
Contributor Author

This device needs tx/rx be swapped to make the 8x RTL8261N phys work. Without this, it's simply unable to communicate, but still links up at 10G.
see: d5b8207#diff-8e20253e585ff25e2c12c86ebaee6d99c4802091609d3dd81ec4b7789a4637f6R452-R482

Is this something that affects all RTL8261N phys or just the ones in this particular switch? if it affects all RTL8261N phys then it probably should be fixed in that driver instead, I assume. (I'm not an expert by any means)

ddb0cd2

I think this was already committed directly to the driver.

That's on the other side of the bus. Here we swap on the cpu side, not the phy.
Also, not compiled into the driver if you build for realtek.

@balika011
balika011 force-pushed the main branch 11 times, most recently from a576bd4 to f1f3f3f Compare October 9, 2025 04:28
pinctrl-0 = <&pinmux_disable_sys_led>;
pinctrl-1 = <&pinmux_enable_usb_led>;

led_master_green: led-master-green {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

led_master_green is still defined as label but not used anywhere.

@balika011
balika011 force-pushed the main branch 5 times, most recently from 5ad173c to 1e26d5a Compare October 9, 2025 15:36
@balika011
balika011 force-pushed the main branch 3 times, most recently from 6efa35a to 4754c97 Compare October 9, 2025 18:00
Adds swap_tx_polarity / swap_rx_polarity to the rtl930x serdes dt.

Signed-off-by: Balázs Triszka <[email protected]>
TP-Link TL-ST5008 is a 8 ports Multi-Gig switch, based on
RTL9303.

Specifications:

- SoC              : Realtek RTL9303
- RAM              : DDR3 512 MiB
- Flash            : SPI-NOR 32 MiB (XMC XM25QH256B)
- Ethernet         : 8x 1/2.5/10 Gbps (8x Realtek RTL8261N RJ45)
- LEDs/Keys (GPIO) : green for 10Gbps on left/green-amber for 1/2.5Gbps on the right
- UART             : "Console" port on the front panel
  - type           : USB
  - connector      : USB-C
  - settings       : 38400 8N1 / 115200 8N1 after installing the patched uboot
- Power            : 100-240 V (IEC C13)

To run openwrt you need to install a patched uboot.
Luckily there's a bug in the uboot tftp update implementation that can be exploited to do just that.
Will be documented on the wiki.

Signed-off-by: Balázs Triszka <[email protected]>
@jonasjelonek

jonasjelonek commented Oct 10, 2025 •

Copy link
Copy Markdown
Member

Before I approve, I'd like to see the mentioned wiki documentation for installation and patching U-boot.

I'm rather in favor of having instructions in the commit message so they can't get lost but if it's too much, it probably better fits into the wiki.

@balika011

Copy link
Copy Markdown
Contributor Author

@balika011

Copy link
Copy Markdown
Contributor Author

Before I approve, I'd like to see the mentioned wiki documentation for installation and patching U-boot.

I'm rather in favor of having instructions in the commit message so they can't get lost but if it's too much, it probably better fits into the wiki.

I created the pages on wiki, but didn't do the how-to yet.
Instead I worked on then RTL8261N driver.
I finally got it working without the need to enable the network in uboot first.
I'll need to do some more work on it, but i'll send in a pr for that soon.
I hate how i did it, but i have no idea how it could be done better.
I will need more input for that.

@balika011

balika011 commented Oct 13, 2025 •

Copy link
Copy Markdown
Contributor Author

i'll send in a pr for that soon

the pr: #20392

@balika011

Copy link
Copy Markdown
Contributor Author

@jonasjelonek Should I add code that builds a version that directly flashes both the bootloader and system when loaded in bootutil?

@jonasjelonek

Copy link
Copy Markdown
Member

I'm not in the position to decide this but I can give my opinion:

Afaik it's rather disregarded having to run something which auto-magically does a lot of things, especially reflashing the bootloader. I haven't seen a guide yet if you published it somewhere but I guess most of the steps can be done manually? Then I'd rather have a clear, small-step HowTo where I actually can see what I'm doing to my device. And most importantly, I can stop at every step and add additional steps, e.g. dumping the bootloader before it's flashed.

@balika011

balika011 commented Oct 27, 2025 •

Copy link
Copy Markdown
Contributor Author

I haven't seen a guide yet

I didn't write any guides yet, as even the pr that needs to be merged in first isn't in yet.

dumping the bootloader before it's flashed.

IMO. there's no need for dumping here. Let me explain:
TP-Link only released a single firmware for this device: version 1.0.1. direct link mirror
As far as i can tell all switches were sold with this firmware on them.
You can use this script to decrypt and extract it.
The output will contain the same uboot.bin that's already on the device from the factory.

To install the patched uboot you have to select firmware update in BOOTUTIL, so it makes since to update it all in one go. At least it does for me. However this update is a funky one. It doesn't pass the signature checks, it gains code execution due to a bug and flashes itself. Also it only work on that 1.0.1 firmware.

@jonasjelonek

Copy link
Copy Markdown
Member

Personally, I prefer having a small guide telling me:

  1. here is the patched u-boot (in best case you link a repo or something like that where users can see what you actually patched)
  2. use firmware update in BOOTUTIL to flash that
  3. reboot and proceed with "usual" flashing
  4. ...

In a wiki you can offer more things for people preferring other ways. But this is all optional and therefore to be put in the wiki. For the device support here, it's a no-go to include any code in a binary/image that auto-magically flashes bootloader, firmware and possibly more things within one run. At least in my opinion and I've seen similar opinions in several discussions. For example, Banana Pi R3/R4 and FritzBox 7530 involve some bootloader flashing too. And they provide detailed guides to go through this so that almost nothing can accidentally go wrong.

@jonasjelonek

Copy link
Copy Markdown
Member

@balika011 I've lost track of the SerDes swapping stuff here with the RTL8261 driver... In #20648, I submitted my version of this, done in the new PCS driver and also for RTL931X. You may drop the commit from your PR then.

@Neustradamus

Copy link
Copy Markdown

@ecsv

ecsv commented May 21, 2026

Copy link
Copy Markdown
Contributor

@balika011 this needs to be rebased on main for the the current RTL8261N support in the main branch.

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit checks

  • 28596116 "realtek: rtl930x: add tx/rx polarity swap support" — the change itself matches the subject, but the commit is obsolete against current main: it adds a parallel polarity-swap implementation in the old DSA driver under files-6.12/, while main (now on kernel 6.18, files-6.18/) already gained this in the PCS driver via #20648. The directory it touches no longer exists on main. Recommend dropping this commit — see the inline comment for details.
  • 7645a9a0 "realtek: rtl930x: add TP-Link TL-ST5008" — diff matches the subject, but the commit message is missing the Flash-instructions and MAC-address-layout sections expected for new device support (inline comment on rtl930x.mk).

The PR also currently does not merge cleanly (mergeable_state: dirty) and is based on a main snapshot from January; a rebase onto current main is needed, after which the DTS polarity properties should switch to tx-polarity/rx-polarity and the driver commit can be dropped.


Generated by Claude Code

}

if (pcs_node) {
priv->ports[pn].swap_rx_polarity = of_property_read_bool(pcs_node, "realtek,pnswap-rx");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire commit (realtek: rtl930x: add tx/rx polarity swap support) appears to be obsolete against current main and should likely be dropped:

  • SerDes tx/rx polarity swap was already implemented upstream in the new PCS driver via #20648 (merged) — see pcs-rtl-otto.c polarity handling. The maintainer explicitly asked for this commit to be dropped (PR comment 3488222469).
  • This commit modifies target/linux/realtek/files-6.12/..., but the realtek target has moved to kernel 6.18 — files-6.12/ no longer exists on main (it is now files-6.18/). As ecsv noted in the most recent PR comment, the PR needs a rebase onto current main.

After rebasing, the polarity swap is configured purely via DTS (tx-polarity/rx-polarity, see the comment on the .dts file), so no driver change is needed in this PR.


Generated by Claude Code

Comment on lines +459 to +460
&serdes2 {
realtek,pnswap-tx;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The realtek,pnswap-tx / realtek,pnswap-rx boolean properties used on &serdes2..&serdes9 only work together with this PR's files-6.12 driver change. Current main (kernel 6.18, PCS driver from #20648) instead expects value-based tx-polarity / rx-polarity properties using the PHY_POL_INVERT / PHY_POL_NORMAL constants — see e.g. rtl9313_zyxel_xs1930-12f.dts and rtl9311_linksys_lgs352c.dts.

After rebasing onto main, the per-port realtek,pnswap-tx; becomes tx-polarity = <PHY_POL_INVERT>; and realtek,pnswap-rx; becomes rx-polarity = <PHY_POL_INVERT>;, which removes the need for the separate driver commit.


Generated by Claude Code

endef
TARGET_DEVICES += tplink_tl-st1008f-v2

define Device/tplink_tl-st5008

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new-device commit message for tplink_tl-st5008 is missing two of the sections OpenWrt expects for new device support:

  • Flash instructions — the message only says "you need to install a patched uboot ... Will be documented on the wiki." A reviewer (and a user) cannot flash the device from the commit message. It needs at least one fully-described install path with verbatim steps: which image to use, how to get into the flashable state (BOOTUTIL menu entry, TFTP server IP, etc.), and reverting to stock. This is also what jonasjelonek asked for in PR comments 3389370700 / 3453433535.
  • MAC address layout — there is no section describing where the MAC comes from. The DTS reads it from factory_macaddr (the para partition at offset 0xfdff4); state this explicitly, one line per interface, using xx:xx:xx for the unit-specific bytes.

The hardware-specification section is present and well-formed.


Generated by Claude Code

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit checks

  • 2ddf19e "realtek: rtl930x: add tx/rx polarity swap support" — this commit is obsolete against current main. It modifies target/linux/realtek/files-6.12/..., but the realtek target has moved to kernel 6.18 (files-6.18/), and SerDes pn-swap support already landed via PR #20648 in the rewritten PCS driver (pcs-rtl-otto.c), which consumes the standard upstream tx-polarity/rx-polarity DT properties. The maintainer explicitly asked for this commit to be dropped. The PR needs a rebase onto main, after which the driver commit can be removed and the &serdesN DTS overrides reworked to the upstream polarity bindings.

See inline comments for details on the affected files. Note: realtek: rtl930x: add TP-Link TL-ST5008 is also missing the Flash instructions and MAC address layout sections required for new device support — see the inline comment on rtl930x.mk.


Generated by Claude Code

return -ENODEV;
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added blank line contains trailing whitespace (two tab characters), which will be flagged by checkpatch and the "Test Formalities" CI step. Make it an empty line.

Suggested change

Generated by Claude Code

Comment on lines +386 to 393
if (pcs_node) {
priv->ports[pn].swap_rx_polarity = of_property_read_bool(pcs_node, "realtek,pnswap-rx");
priv->ports[pn].swap_tx_polarity = of_property_read_bool(pcs_node, "realtek,pnswap-tx");
} else {
priv->ports[pn].swap_rx_polarity = false;
priv->ports[pn].swap_tx_polarity = false;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole commit modifies target/linux/realtek/files-6.12/..., but main has moved the realtek target to kernel 6.18 — the driver tree is now target/linux/realtek/files-6.18/ and files-6.12 no longer exists. Additionally, SerDes pn-swap support has already landed on main (PR #20648) in the rewritten PCS driver pcs-rtl-otto.c, via rtpcs_sds_config_polarity() which reads the standard upstream tx-polarity/rx-polarity DT properties (phy_get_manual_tx_polarity/phy_get_manual_rx_polarity), not custom realtek,pnswap-* properties.

As @jonasjelonek noted in a PR comment and @ecsv in another, this commit should be dropped and the PR rebased onto current main. The &serdesN { realtek,pnswap-tx; } blocks in the new DTS need to be reworked to the upstream tx-polarity/rx-polarity bindings the merged PCS driver consumes.


Generated by Claude Code

Comment on lines +459 to +489
&serdes2 {
realtek,pnswap-tx;
};

&serdes3 {
realtek,pnswap-rx;
};

&serdes4 {
realtek,pnswap-tx;
};

&serdes5 {
realtek,pnswap-rx;
};

&serdes6 {
realtek,pnswap-tx;
};

&serdes7 {
realtek,pnswap-rx;
};

&serdes8 {
realtek,pnswap-tx;
};

&serdes9 {
realtek,pnswap-rx;
};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The custom realtek,pnswap-tx / realtek,pnswap-rx properties are introduced by commit 1 of this PR, which is now obsolete (see the comment on common.c). The merged PCS driver on main reads polarity from the standard upstream tx-polarity/rx-polarity properties via rtpcs_sds_config_polarity(). After rebasing onto main, these &serdesN overrides need to be converted to that binding.


Generated by Claude Code

@Neustradamus

Copy link
Copy Markdown

@ecsv: The @balika011 mailbox is full :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

target/realtek pull request/issue for realtek target

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants